dwm

my dwm build
Log | Files | Refs | LICENSE

commit fa4f193f333b2daea066b11aa5e011be37244b76
parent 53ffa3196dab82e0a3db1d93a21e25740c37a3a1
Author: ssnf <ssnf@ssnf.xyz>
Date:   Mon, 19 Sep 2022 15:33:00 +0000

eh

Diffstat:
D.clang-format | 68--------------------------------------------------------------------
D.config | 2--
MMakefile | 3---
Mconfig.h | 208++++++++++++++++++++++++++++++++++++++++++-------------------------------------
Mconfig.mk | 6+++---
Mdrw.c | 117+++++++++++++++++++++++++++++++++++++-------------------------------------------
Mdrw.h | 56++++++++++++++++++++++++++++----------------------------
Mdwm.c | 1425++++++++++++++++++++++++++++++++++++++++++++-----------------------------------
Dmake | 3---
Mutil.c | 11++++++-----
Mutil.h | 4++++
11 files changed, 993 insertions(+), 910 deletions(-)

diff --git a/.clang-format b/.clang-format @@ -1,68 +0,0 @@ ---- -BasedOnStyle: LLVM -AccessModifierOffset: '-2' -AlignAfterOpenBracket: AlwaysBreak -AlignConsecutiveAssignments: 'true' -AlignConsecutiveDeclarations: 'true' -AlignEscapedNewlines: Left -AlignOperands: 'false' -AlignTrailingComments: 'true' -AllowAllParametersOfDeclarationOnNextLine: 'true' -AllowShortBlocksOnASingleLine: 'true' -AllowShortCaseLabelsOnASingleLine: 'true' -AllowShortFunctionsOnASingleLine: None -AllowShortIfStatementsOnASingleLine: Always -AllowShortLoopsOnASingleLine: 'true' -AlwaysBreakAfterReturnType: None -AlwaysBreakBeforeMultilineStrings: 'true' -AlwaysBreakTemplateDeclarations: 'No' -BinPackArguments: 'true' -BinPackParameters: 'true' -BreakBeforeBinaryOperators: None -BreakBeforeBraces: Custom -BreakBeforeTernaryOperators: 'true' -BreakConstructorInitializers: AfterColon -BreakInheritanceList: AfterColon -BreakStringLiterals: 'false' -ColumnLimit: '120' -CompactNamespaces: 'false' -ConstructorInitializerAllOnOneLineOrOnePerLine: 'true' -ConstructorInitializerIndentWidth: '1' -ContinuationIndentWidth: '0' -Cpp11BracedListStyle: 'false' -DerivePointerAlignment: 'false' -DisableFormat: 'false' -FixNamespaceComments: 'false' -IndentCaseLabels: 'true' -IndentPPDirectives: None -IndentWidth: '4' -IndentWrappedFunctionNames: 'false' -KeepEmptyLinesAtTheStartOfBlocks: 'false' -Language: Cpp -MaxEmptyLinesToKeep: '1' -NamespaceIndentation: All -PointerAlignment: Left -ReflowComments: 'true' -SortIncludes: 'false' -SortUsingDeclarations: 'true' -SpaceAfterCStyleCast: 'false' -SpaceAfterLogicalNot: 'false' -SpaceAfterTemplateKeyword: 'false' -SpaceBeforeAssignmentOperators: 'true' -SpaceBeforeCpp11BracedList: 'false' -SpaceBeforeCtorInitializerColon: 'true' -SpaceBeforeInheritanceColon: 'true' -SpaceBeforeParens: ControlStatements -SpaceBeforeRangeBasedForLoopColon: 'true' -SpaceInEmptyParentheses: 'false' -SpacesBeforeTrailingComments: '8' -SpacesInAngles: 'false' -SpacesInCStyleCastParentheses: 'false' -SpacesInContainerLiterals: 'false' -SpacesInParentheses: 'false' -SpacesInSquareBrackets: 'false' -Standard: Auto -TabWidth: '4' -UseTab: Always - -... diff --git a/.config b/.config @@ -1,2 +0,0 @@ -let g:ale_c_gcc_options = '-Wall -Wextra -pedantic -I/usr/X11R6/include -I/usr/include/freetype2 -L/usr/X11R6/lib -lX11 -lfontconfig -lXft -lX11-xcb -lxcb -lxcb-res -std=c89 ' -let g:ale_cpp_gcc_options = '-Wall -Wextra -pedantic -I/usr/X11R6/include -I/usr/include/freetype2 -L/usr/X11R6/lib -lX11 -lfontconfig -lXft -lX11-xcb -lxcb -lxcb-res -std=c89' diff --git a/Makefile b/Makefile @@ -19,9 +19,6 @@ options: ${OBJ}: config.h config.mk -config.h: - cp config.def.h $@ - dwm: ${OBJ} ${CC} -o $@ ${OBJ} ${LDFLAGS} diff --git a/config.h b/config.h @@ -1,22 +1,15 @@ -/* See LICENSE file for copyright and license details. */ - /* appearance */ -static const unsigned int borderpx = 1; /* border pixel of windows */ -static const unsigned int snap = 32; /* snap pixel */ -static const int swallowfloating = 0; /* 1 means swallow floating windows by default */ -static const int showbar = 1; /* 0 means no bar */ -static const int topbar = 1; /* 0 means bottom bar */ -static const char *fonts[] = { "monospace:size=10" }; -static const char dmenufont[] = "monospace:size=10"; -static const char col_gray1[] = "#222222"; -static const char col_gray2[] = "#444444"; -static const char col_gray3[] = "#bbbbbb"; -static const char col_gray4[] = "#eeeeee"; -static const char col_cyan[] = "#005577"; -static const char *colors[][3] = { - /* fg bg border */ - [SchemeNorm] = { col_gray3, col_gray1, col_gray2 }, - [SchemeSel] = { col_gray4, col_cyan, col_cyan }, +static const uint borderpx = 3; /* border pixel of windows */ +static const uint snap = 20; /* snap pixel */ +static const int showbar = 0; /* 0 means no bar */ +static const int topbar = 1; /* 0 means bottom bar */ +static const char *fonts[] = { "hack:size=12" }; +static const char col_fg[] = "#454138"; +static const char col_bg[] = "#d1cdb7"; +static const char *colors[][3] = { + /* fg bg border */ + [SchemeNorm] = { col_bg, col_fg, col_fg }, + [SchemeSel] = { col_fg, col_bg, col_bg }, }; /* tagging */ @@ -24,106 +17,125 @@ static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; static const Rule rules[] = { /* xprop(1): - * WM_CLASS(STRING) = instance, class - * WM_NAME(STRING) = title + * WM_CLASS(STRING) = instance, class + * WM_NAME(STRING) = title */ - /* class instance title tags mask isfloating isterminal noswallow monitor */ - { "St", NULL, NULL, 0, 0, 1, 0, -1 }, - { NULL, NULL, "Event Tester", 0, 1, 0, 1, -1 }, /* xev */ + /* class instance title tags mask isfloating isterminal noswallow monitor */ + { "st", NULL, NULL, 0, 0, 1, 0, -1 }, + { NULL, NULL, "Event Tester", 0, 0, 0, 1, -1 }, /* xev */ + { NULL, NULL, "Origin", 0, 1, 0, 0, -1 }, }; /* layout(s) */ static const float mfact = 0.5; /* factor of master area size [0.05..0.95] */ -static const int nmaster = 1; /* number of clients in master area */ -static const int resizehints = 0; /* 1 means respect size hints in tiled resizals */ +static const int nmaster = 2; /* number of clients in master area */ +static const int resizehints = 0; /* 1 means respect size hints in tiled resizals */ -static const struct Layout layouts[] = { - /* symbol arrange function */ - { "[\\]", fibonacci }, /* first entry is default */ - { NULL, NULL }, +static const Layout layouts[] = { + /* symbol arrange function */ + { "[\\]", fibonacci }, /* first entry is default */ + { NULL, NULL }, }; /* key definitions */ -#define MODKEY Mod4Mask +#define MOD Mod4Mask +#define SHIFT ShiftMask +#define CTRL ControlMask + #define TAGKEYS(KEY,TAG) \ - { MODKEY, KEY, view, {.ui = 1 << TAG} }, \ - { MODKEY|ControlMask, KEY, toggleview, {.ui = 1 << TAG} }, \ - { MODKEY|ShiftMask, KEY, tag, {.ui = 1 << TAG} }, \ - { MODKEY|ControlMask|ShiftMask, KEY, toggletag, {.ui = 1 << TAG} }, + { MOD, KEY, view, {.ui = 1 << TAG} }, \ + { MOD|CTRL, KEY, toggleview, {.ui = 1 << TAG} }, \ + { MOD|SHIFT, KEY, tag, {.ui = 1 << TAG} }, \ + { MOD|CTRL|SHIFT, KEY, toggletag, {.ui = 1 << TAG} }, /* helper for spawning shell commands in the pre dwm-5.0 fashion */ #define SHCMD(cmd) { .v = (const char*[]){ "/bin/sh", "-c", cmd, NULL } } /* commands */ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() */ -static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL }; -static const char *termcmd[] = { "st", NULL }; -static const char *browser[] = { "/bin/sh", "-c", "$BROWSER", NULL }; +/*static const char* dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_black1, "-nf", col_green1, "-sb", col_green1, "-sf", col_black3, NULL };*/ +static const char* browser[] = { "browser", NULL }; +static const char* caps[] = { "setxkbmap", "-option", "caps:super", NULL }; +static const char* color[] = { "colorpick", NULL }; +static const char* compositor[] = { "compositor", NULL }; +static const char* dmenucmd[] = { "dmenu_run", "-m", dmenumon, NULL }; +static const char* lock[] = { "lock", NULL }; +static const char* mict[] = { "mict", NULL }; +static const char* mont[] = { "mont", NULL }; +static const char* news[] = { "st", "-e", "newsboat", NULL }; +static const char* pass[] = { "passd", NULL }; +static const char* spkrd[] = { "pamixer", "-d", "5", NULL }; +static const char* spkri[] = { "pamixer", "-i", "5", NULL }; +static const char* spkrt[] = { "pamixer", "-t", NULL }; +static const char* status[] = { "status", NULL }; +static const char* stopdwm[] = { "stopdwm", NULL }; +static const char* termcmd[] = { "st", NULL }; #include <X11/XF86keysym.h> -static struct Key keys[] = { - /* modifier key function argument */ - { MODKEY, XK_d, spawn, {.v = dmenucmd } }, - { MODKEY, XK_Return, spawn, {.v = termcmd } }, - { MODKEY, XK_w, spawn, {.v = browser } }, - { MODKEY, XK_b, togglebar, {0} }, - { MODKEY, XK_j, focusstack, {.i = +1 } }, - { MODKEY, XK_k, focusstack, {.i = 0 } }, - { MODKEY, XK_h, setmfact, {.f = -0.05} }, - { MODKEY, XK_l, setmfact, {.f = +0.05} }, - { MODKEY, XK_i, incnmaster, {.i = +1 } }, - { MODKEY, XK_u, incnmaster, {.i = -1 } }, - { MODKEY, XK_space, zoom, {0} }, - { MODKEY, XK_Tab, view, {0} }, - { MODKEY, XK_q, killclient, {0} }, - { MODKEY, 0x005d, cyclelayout, {.i = +1 } }, - { MODKEY, XK_0, view, {.ui = ~0 } }, - { MODKEY|ShiftMask, XK_0, tag, {.ui = ~0 } }, - { MODKEY, XK_f, togglefullscr, {0} }, - { MODKEY, XK_comma, focusmon, {.i = -1 } }, - { MODKEY, XK_period, focusmon, {.i = +1 } }, - { MODKEY|ShiftMask, XK_comma, tagmon, {.i = -1 } }, - { MODKEY|ShiftMask, XK_period, tagmon, {.i = +1 } }, - TAGKEYS( XK_1, 0) - TAGKEYS( XK_2, 1) - TAGKEYS( XK_3, 2) - TAGKEYS( XK_4, 3) - TAGKEYS( XK_5, 4) - TAGKEYS( XK_6, 5) - TAGKEYS( XK_7, 6) - TAGKEYS( XK_8, 7) - TAGKEYS( XK_9, 8) - { MODKEY|ShiftMask, XK_q, quit, {0} }, - - { MODKEY, XK_F4, spawn, SHCMD("prompt 'Hibernate computer?' 'sudo systemctl suspend'") }, - { MODKEY|ShiftMask, XK_x, spawn, SHCMD("prompt 'Shutdown computer?' 'sudo -A shutdown -h now'") }, - { MODKEY, XK_r, spawn, SHCMD("st -e lf") }, - { MODKEY, XK_n, spawn, SHCMD("st -e newsboat") }, - { MODKEY, XK_m, spawn, SHCMD("st -e neomutt") }, - { MODKEY, XK_i, spawn, SHCMD("st -e htop") }, - { MODKEY, XK_c, spawn, SHCMD("st -e calcurse") }, - { MODKEY, XK_p, spawn, SHCMD("pop-video") }, - { MODKEY|ShiftMask, XK_p, spawn, SHCMD("push-video") }, - { MODKEY|ShiftMask, XK_w, spawn, SHCMD("sudo wireshark") }, - - { 0, XF86XK_AudioMute, spawn, SHCMD("pamixer -t; kill -44 $(pidof dwmblocks)") }, - { 0, XF86XK_AudioRaiseVolume, spawn, SHCMD("pamixer --allow-boost -i 3; kill -44 $(pidof dwmblocks)") }, - { 0, XF86XK_AudioLowerVolume, spawn, SHCMD("pamixer --allow-boost -d 3; kill -44 $(pidof dwmblocks)") }, +static Key keys[] = { + /* modifier key function argument */ + { MOD|SHIFT, XK_i, spawn, {.v = color} }, + { MOD, XK_c, spawn, {.v = compositor} }, + { MOD, XK_x, spawn, {.v = lock} }, + { 0, XF86XK_ScreenSaver, spawn, {.v = lock} }, + { 0, XF86XK_Suspend, spawn, {.v = lock} }, + { 0, XF86XK_Sleep, spawn, {.v = lock} }, + { MOD, XK_n, spawn, {.v = news} }, + { MOD, XK_o, spawn, {.v = pass} }, + { 0, XF86XK_AudioMute, spawn, {.v = spkrt} }, + { MOD, XK_KP_Multiply, spawn, {.v = spkrt} }, + { 0, XF86XK_AudioRaiseVolume, spawn, {.v = spkri} }, + { MOD, XK_KP_Add, spawn, {.v = spkri} }, + { 0, XF86XK_AudioLowerVolume, spawn, {.v = spkrd} }, + { MOD, XK_KP_Subtract, spawn, {.v = spkrd} }, + { MOD, XK_u, spawn, {.v = status} }, + { 0, XF86XK_Launch1, spawn, {.v = mict} }, + { MOD, XK_Pause, spawn, {.v = mict} }, + { 0, XF86XK_Display, spawn, {.v = mont} }, + { CTRL|SHIFT, XK_Escape, spawn, {.v = caps} }, + { MOD, XK_d, spawn, {.v = dmenucmd } }, + { MOD, XK_Return, spawn, {.v = termcmd } }, + { MOD, XK_w, spawn, {.v = browser } }, + { MOD, XK_b, togglebar, {0} }, + { MOD, XK_j, focusstack, {.i = +1 } }, + { MOD, XK_k, focusstack, {.i = 0 } }, + { MOD, XK_h, setmfact, {.f = -0.05} }, + { MOD, XK_l, setmfact, {.f = +0.05} }, + { MOD, XK_space, zoom, {0} }, + { MOD, XK_q, killclient, {0} }, + { MOD, XK_0, view, {.ui = ~0 } }, + { MOD|SHIFT, XK_0, tag, {.ui = ~0 } }, + { MOD, XK_f, togglefullscr, {0} }, + { MOD, XK_comma, focusmon, {.i = -1 } }, + { MOD, XK_period, focusmon, {.i = +1 } }, + { MOD|SHIFT, XK_comma, tagmon, {.i = -1 } }, + { MOD|SHIFT, XK_period, tagmon, {.i = +1 } }, + { MOD|SHIFT, XK_q, quit, {0} }, + { MOD|CTRL|SHIFT, XK_q, spawn, {.v = stopdwm} }, + TAGKEYS( XK_1, 0) + TAGKEYS( XK_2, 1) + TAGKEYS( XK_3, 2) + TAGKEYS( XK_4, 3) + TAGKEYS( XK_5, 4) + TAGKEYS( XK_6, 5) + TAGKEYS( XK_7, 6) + TAGKEYS( XK_8, 7) + TAGKEYS( XK_9, 8) }; /* button definitions */ /* click can be ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */ -static struct Button buttons[] = { - /* click event mask button function argument */ - { ClkLtSymbol, 0, Button1, setlayout, {0} }, - { ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} }, - { ClkWinTitle, 0, Button2, zoom, {0} }, - { ClkStatusText, 0, Button2, spawn, {.v = termcmd } }, - { ClkClientWin, MODKEY, Button1, movemouse, {0} }, - { ClkClientWin, MODKEY, Button2, togglefloating, {0} }, - { ClkClientWin, MODKEY, Button3, resizemouse, {0} }, - { ClkTagBar, 0, Button1, view, {0} }, - { ClkTagBar, 0, Button3, toggleview, {0} }, - { ClkTagBar, MODKEY, Button1, tag, {0} }, - { ClkTagBar, MODKEY, Button3, toggletag, {0} }, +static Button buttons[] = { + /* click event mask button function argument */ + { ClkLtSymbol, 0, Button1, setlayout, {0} }, + { ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} }, + { ClkWinTitle, 0, Button2, zoom, {0} }, + { ClkStatusText, 0, Button2, spawn, {.v = termcmd } }, + { ClkClientWin, MOD, Button1, movemouse, {0} }, + { ClkClientWin, MOD, Button2, togglefloating, {0} }, + { ClkClientWin, MOD, Button3, resizemouse, {0} }, + { ClkTagBar, 0, Button1, view, {0} }, + { ClkTagBar, 0, Button3, toggleview, {0} }, + { ClkTagBar, MOD, Button1, tag, {0} }, + { ClkTagBar, MOD, Button3, toggletag, {0} }, }; diff --git a/config.mk b/config.mk @@ -4,15 +4,15 @@ VERSION = 6.2 # Customize below to fit your system # paths -PREFIX = /usr/local +PREFIX = ~/.local MANPREFIX = ${PREFIX}/share/man X11INC = /usr/X11R6/include X11LIB = /usr/X11R6/lib # Xinerama, comment if you don't want it -#XINERAMALIBS = -lXinerama -#XINERAMAFLAGS = -DXINERAMA +XINERAMALIBS = -lXinerama +XINERAMAFLAGS = -DXINERAMA # freetype FREETYPELIBS = -lfontconfig -lXft diff --git a/drw.c b/drw.c @@ -1,4 +1,3 @@ -/* See LICENSE file for copyright and license details. */ #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -11,32 +10,31 @@ #define UTF_INVALID 0xFFFD #define UTF_SIZ 4 -static const unsigned char utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0}; -static const unsigned char utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8}; +static const uchar utfbyte[UTF_SIZ + 1] = {0x80, 0, 0xC0, 0xE0, 0xF0}; +static const uchar utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8}; static const long utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000}; static const long utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF}; static long -utf8decodebyte(const char c, size_t *i) +utf8decodebyte(const char c, size_t* i) { for (*i = 0; *i < (UTF_SIZ + 1); ++(*i)) - if (((unsigned char)c & utfmask[*i]) == utfbyte[*i]) - return (unsigned char)c & ~utfmask[*i]; + if (((uchar)c & utfmask[*i]) == utfbyte[*i]) + return (uchar)c & ~utfmask[*i]; return 0; } static size_t -utf8validate(long *u, size_t i) +utf8validate(long* u, size_t i) { if (!BETWEEN(*u, utfmin[i], utfmax[i]) || BETWEEN(*u, 0xD800, 0xDFFF)) *u = UTF_INVALID; - for (i = 1; *u > utfmax[i]; ++i) - ; + for (i = 1; *u > utfmax[i]; ++i); return i; } static size_t -utf8decode(const char *c, long *u, size_t clen) +utf8decode(const char* c, long* u, size_t clen) { size_t i, j, len, type; long udecoded; @@ -60,10 +58,10 @@ utf8decode(const char *c, long *u, size_t clen) return len; } -Drw * -drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h) +Drw* +drw_create(Display* dpy, int screen, Window root, uint w, uint h) { - Drw *drw = ecalloc(1, sizeof(Drw)); + Drw* drw = ecalloc(1, sizeof(Drw)); drw->dpy = dpy; drw->screen = screen; @@ -78,11 +76,10 @@ drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h } void -drw_resize(Drw *drw, unsigned int w, unsigned int h) +drw_resize(Drw* drw, uint w, uint h) { if (!drw) return; - drw->w = w; drw->h = h; if (drw->drawable) @@ -91,7 +88,7 @@ drw_resize(Drw *drw, unsigned int w, unsigned int h) } void -drw_free(Drw *drw) +drw_free(Drw* drw) { XFreePixmap(drw->dpy, drw->drawable); XFreeGC(drw->dpy, drw->gc); @@ -101,12 +98,12 @@ drw_free(Drw *drw) /* This function is an implementation detail. Library users should use * drw_fontset_create instead. */ -static Fnt * -xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern) +static Fnt* +xfont_create(Drw* drw, const char* fontname, FcPattern* fontpattern) { - Fnt *font; - XftFont *xfont = NULL; - FcPattern *pattern = NULL; + Fnt* font; + XftFont* xfont = NULL; + FcPattern* pattern = NULL; if (fontname) { /* Using the pattern found at font->xfont->pattern does not yield the @@ -118,7 +115,7 @@ xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern) fprintf(stderr, "error, cannot load font from name: '%s'\n", fontname); return NULL; } - if (!(pattern = FcNameParse((FcChar8 *) fontname))) { + if (!(pattern = FcNameParse((FcChar8*) fontname))) { fprintf(stderr, "error, cannot parse font name to pattern: '%s'\n", fontname); XftFontClose(drw->dpy, xfont); return NULL; @@ -155,7 +152,7 @@ xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern) } static void -xfont_free(Fnt *font) +xfont_free(Fnt* font) { if (!font) return; @@ -166,9 +163,9 @@ xfont_free(Fnt *font) } Fnt* -drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount) +drw_fontset_create(Drw* drw, const char* fonts[], size_t fontcount) { - Fnt *cur, *ret = NULL; + Fnt* cur, *ret = NULL; size_t i; if (!drw || !fonts) @@ -184,7 +181,7 @@ drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount) } void -drw_fontset_free(Fnt *font) +drw_fontset_free(Fnt* font) { if (font) { drw_fontset_free(font->next); @@ -193,50 +190,47 @@ drw_fontset_free(Fnt *font) } void -drw_clr_create(Drw *drw, Clr *dest, const char *clrname) +drw_clr_create(Drw* drw, Color* dest, const char* color_name) { - if (!drw || !dest || !clrname) + if (!drw || !dest || !color_name) return; - - if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen), - DefaultColormap(drw->dpy, drw->screen), - clrname, dest)) - die("error, cannot allocate color '%s'", clrname); + if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen), DefaultColormap(drw->dpy, drw->screen), color_name, dest)) + die("error, cannot allocate color '%s'", color_name); } /* Wrapper to create color schemes. The caller has to call free(3) on the * returned color scheme when done using it. */ -Clr * -drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount) +Color* +drw_scm_create(Drw* drw, const char* color_names[], size_t color_count) { size_t i; - Clr *ret; + Color* ret; /* need at least two colors for a scheme */ - if (!drw || !clrnames || clrcount < 2 || !(ret = ecalloc(clrcount, sizeof(XftColor)))) + if (!drw || !color_names || color_count < 2 || !(ret = ecalloc(color_count, sizeof(XftColor)))) return NULL; - for (i = 0; i < clrcount; i++) - drw_clr_create(drw, &ret[i], clrnames[i]); + for (i = 0; i < color_count; i++) + drw_clr_create(drw, &ret[i], color_names[i]); return ret; } void -drw_setfontset(Drw *drw, Fnt *set) +drw_setfontset(Drw* drw, Fnt* set) { if (drw) drw->fonts = set; } void -drw_setscheme(Drw *drw, Clr *scm) +drw_setscheme(Drw* drw, Color* scm) { if (drw) drw->scheme = scm; } void -drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert) +drw_rect(Drw* drw, int x, int y, uint w, uint h, int filled, int invert) { if (!drw || !drw->scheme) return; @@ -248,20 +242,20 @@ drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int } int -drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert) +drw_text(Drw* drw, int x, int y, uint w, uint h, uint lpad, const char* text, int invert) { char buf[1024]; int ty; - unsigned int ew; - XftDraw *d = NULL; - Fnt *usedfont, *curfont, *nextfont; + uint ew; + XftDraw* d = NULL; + Fnt* usedfont, *curfont, *nextfont; size_t i, len; int utf8strlen, utf8charlen, render = x || y || w || h; long utf8codepoint = 0; - const char *utf8str; - FcCharSet *fccharset; - FcPattern *fcpattern; - FcPattern *match; + const char* utf8str; + FcCharSet* fccharset; + FcPattern* fcpattern; + FcPattern* match; XftResult result; int charexists = 0; @@ -322,7 +316,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp if (render) { ty = y + (h - usedfont->h) / 2 + usedfont->xfont->ascent; XftDrawStringUtf8(d, &drw->scheme[invert ? ColBg : ColFg], - usedfont->xfont, x, ty, (XftChar8 *)buf, len); + usedfont->xfont, x, ty, (XftChar8*)buf, len); } x += ew; w -= ew; @@ -379,7 +373,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp } void -drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h) +drw_map(Drw* drw, Window win, int x, int y, uint w, uint h) { if (!drw) return; @@ -388,8 +382,8 @@ drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h) XSync(drw->dpy, False); } -unsigned int -drw_fontset_getwidth(Drw *drw, const char *text) +uint +drw_fontset_getwidth(Drw* drw, const char* text) { if (!drw || !drw->fonts || !text) return 0; @@ -397,39 +391,36 @@ drw_fontset_getwidth(Drw *drw, const char *text) } void -drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h) +drw_font_getexts(Fnt* font, const char* text, uint len, uint* w, uint* h) { XGlyphInfo ext; if (!font || !text) return; - XftTextExtentsUtf8(font->dpy, font->xfont, (XftChar8 *)text, len, &ext); + XftTextExtentsUtf8(font->dpy, font->xfont, (XftChar8*)text, len, &ext); if (w) *w = ext.xOff; if (h) *h = font->h; } -Cur * -drw_cur_create(Drw *drw, int shape) +Cur* +drw_cur_create(Drw* drw, int shape) { - Cur *cur; + Cur* cur; if (!drw || !(cur = ecalloc(1, sizeof(Cur)))) return NULL; - cur->cursor = XCreateFontCursor(drw->dpy, shape); - return cur; } void -drw_cur_free(Drw *drw, Cur *cursor) +drw_cur_free(Drw* drw, Cur* cursor) { if (!cursor) return; - XFreeCursor(drw->dpy, cursor->cursor); free(cursor); } diff --git a/drw.h b/drw.h @@ -3,53 +3,53 @@ typedef struct { } Cur; typedef struct Fnt { - Display *dpy; - unsigned int h; - XftFont *xfont; - FcPattern *pattern; - struct Fnt *next; + Display* dpy; + uint h; + XftFont* xfont; + FcPattern* pattern; + struct Fnt* next; } Fnt; -enum { ColFg, ColBg, ColBorder }; /* Clr scheme index */ -typedef XftColor Clr; +enum { ColFg, ColBg, ColBorder }; /* Color scheme index */ +typedef XftColor Color; typedef struct { - unsigned int w, h; - Display *dpy; - int screen; - Window root; + uint w, h; + Display* dpy; + int screen; + Window root; Drawable drawable; - GC gc; - Clr *scheme; - Fnt *fonts; + GC gc; + Color* scheme; + Fnt* fonts; } Drw; /* Drawable abstraction */ -Drw *drw_create(Display *dpy, int screen, Window win, unsigned int w, unsigned int h); -void drw_resize(Drw *drw, unsigned int w, unsigned int h); +Drw* drw_create(Display *dpy, int screen, Window win, uint w, uint h); +void drw_resize(Drw *drw, uint w, uint h); void drw_free(Drw *drw); /* Fnt abstraction */ -Fnt *drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount); +Fnt* drw_fontset_create(Drw* drw, const char* fonts[], size_t fontcount); void drw_fontset_free(Fnt* set); -unsigned int drw_fontset_getwidth(Drw *drw, const char *text); -void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h); +uint drw_fontset_getwidth(Drw* drw, const char* text); +void drw_font_getexts(Fnt* font, const char* text, uint len, uint* w, uint* h); /* Colorscheme abstraction */ -void drw_clr_create(Drw *drw, Clr *dest, const char *clrname); -Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount); +void drw_clr_create(Drw* drw, Color* dest, const char* clrname); +Color* drw_scm_create(Drw* drw, const char* clrnames[], size_t clrcount); /* Cursor abstraction */ -Cur *drw_cur_create(Drw *drw, int shape); -void drw_cur_free(Drw *drw, Cur *cursor); +Cur* drw_cur_create(Drw* drw, int shape); +void drw_cur_free(Drw* drw, Cur* cursor); /* Drawing context manipulation */ -void drw_setfontset(Drw *drw, Fnt *set); -void drw_setscheme(Drw *drw, Clr *scm); +void drw_setfontset(Drw* drw, Fnt* set); +void drw_setscheme(Drw* drw, Color* scm); /* Drawing functions */ -void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert); -int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert); +void drw_rect(Drw* drw, int x, int y, uint w, uint h, int filled, int invert); +int drw_text(Drw* drw, int x, int y, uint w, uint h, uint lpad, const char* text, int invert); /* Map functions */ -void drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h); +void drw_map(Drw* drw, Window win, int x, int y, uint w, uint h); diff --git a/dwm.c b/dwm.c @@ -82,76 +82,75 @@ enum { /* clicks */ ClkLast }; -union Arg{ +typedef union { int i; - unsigned int ui; + uint ui; float f; const void* v; -}; - -struct Button { - unsigned int click; - unsigned int mask; - unsigned int button; - void (*func)(const union Arg* arg); - const union Arg arg; -}; +} Arg; -struct Client { - char name[256]; - float mina, maxa; - int x, y, w, h; - int oldx, oldy, oldw, oldh; - int basew, baseh, incw, inch, maxw, maxh, minw, minh; - int bw, oldbw; - unsigned int tags; - int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen, isterminal, noswallow; - pid_t pid; - struct Client* next; - struct Client* snext; - struct Client* swallowing; - struct Monitor* mon; - Window win; -}; +typedef struct { + uint click; + uint mask; + uint button; + void (*func)(const Arg* arg); + const Arg arg; +} Button; + +typedef struct Client { + char name[256]; + float mina, maxa; + int x, y, w, h; + int oldx, oldy, oldw, oldh; + int basew, baseh, incw, inch, maxw, maxh, minw, minh; + int bw, oldbw; + uint tags; + int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen, isterminal, noswallow; + pid_t pid; + struct Client* next; + struct Client* snext; + struct Client* swallowing; + struct Monitor* mon; + Window win; +} Client; -struct Key { - unsigned int mod; +typedef struct { + uint mod; KeySym keysym; - void (*func)(const union Arg*); - const union Arg arg; -}; + void (*func)(const Arg*); + const Arg arg; +} Key; -struct Layout { +typedef struct { const char* symbol; void (*arrange)(struct Monitor*); -}; - -struct Monitor { - char ltsymbol[16]; - float mfact; - int nmaster; - int num; - int by; /* bar geometry */ - int mx, my, mw, mh; /* screen size */ - int wx, wy, ww, wh; /* window area */ - unsigned int seltags; - unsigned int sellt; - unsigned int tagset[2]; - int showbar; - int topbar; - struct Client* clients; - struct Client* sel; - struct Client* stack; - struct Monitor* next; - Window barwin; - const struct Layout* lt[2]; -}; +} Layout; + +typedef struct Monitor { + float mfact; + int nmaster; + int num; + int by; /* bar geometry */ + int mx, my, mw, mh; /* screen size */ + int wx, wy, ww, wh; /* window area */ + uint seltags; + uint sellt; + uint tagset[2]; + int showbar; + int topbar; + Client* clients; + Client* selcli; + Client* stack; + struct Monitor* next; + Window barwin; + const Layout* lt[2]; +} Monitor; typedef struct { const char* class; const char* instance; const char* title; - unsigned int tags; + uint tags; int isfloating; int isterminal; int noswallow; @@ -159,106 +158,104 @@ typedef struct { } Rule; /* function declarations */ -static void applyrules(struct Client* c); -static int applysizehints(struct Client* c, int* x, int* y, int* w, int* h, int interact); -static void arrange(struct Monitor* m); -static void arrangemon(struct Monitor* m); -static void attach(struct Client* c); -static void attachstack(struct Client* c); -static void buttonpress(XEvent* e); -static void checkotherwm(void); -static void cleanup(void); -static void cleanupmon(struct Monitor* mon); -static void clientmessage(XEvent* e); -static void configure(struct Client* c); -static void configurenotify(XEvent* e); -static void configurerequest(XEvent* e); -static struct Monitor* createmon(void); -static void cyclelayout(const union Arg* arg); -static void destroynotify(XEvent* e); -static void detach(struct Client* c); -static void detachstack(struct Client* c); -static struct Monitor* dirtomon(int dir); -static void drawbar(struct Monitor* m); -static void drawbars(void); -static void enternotify(XEvent* e); -static void expose(XEvent* e); -static void fibonacci(struct Monitor* mon); -static void focus(struct Client* c); -static void focusin(XEvent* e); -static void focusmon(const union Arg* arg); -static void focusstack(const union Arg* arg); -static Atom getatomprop(struct Client* c, Atom prop); -static int getrootptr(int* x, int* y); -static long getstate(Window w); -static int gettextprop(Window w, Atom atom, char* text, unsigned int size); -static void grabbuttons(struct Client* c, int focused); -static void grabkeys(void); -static void incnmaster(const union Arg* arg); -static void keypress(XEvent* e); -static void killclient(const union Arg* arg); -static void manage(Window w, XWindowAttributes* wa); -static void mappingnotify(XEvent* e); -static void maprequest(XEvent* e); -static void motionnotify(XEvent* e); -static void movemouse(const union Arg* arg); -static struct Client* nexttiled(struct Client* c); -static void pop(struct Client*); -static void propertynotify(XEvent* e); -static void quit(const union Arg* arg); -static struct Monitor* recttomon(int x, int y, int w, int h); -static void resize(struct Client* c, int x, int y, int w, int h, int interact); -static void resizeclient(struct Client* c, int x, int y, int w, int h); -static void resizemouse(const union Arg* arg); -static void restack(struct Monitor* m); -static void run(void); -static void scan(void); -static int sendevent(struct Client* c, Atom proto); -static void sendmon(struct Client* c, struct Monitor* m); -static void setbar(int value); -static void setclientstate(struct Client* c, long state); -static void setfocus(struct Client* c); -static void setfullscreen(struct Client* c, int fullscreen); -static void setlayout(const union Arg* arg); -static void setmfact(const union Arg* arg); -static void setup(void); -static void seturgent(struct Client* c, int urg); -static void showhide(struct Client* c); -static void sigchld(int unused); -static void spawn(const union Arg* arg); -static void tag(const union Arg* arg); -static void tagmon(const union Arg* arg); -static void togglebar(const union Arg* arg); -static void togglefloating(const union Arg* arg); -static void togglefullscr(const union Arg* arg); -static void toggletag(const union Arg* arg); -static void toggleview(const union Arg* arg); -static void unfocus(struct Client* c, int setfocus); -static void unmanage(struct Client* c, int destroyed); -static void unmapnotify(XEvent* e); -static void updatebarpos(struct Monitor* m); -static void updatebars(void); -static void updateclientlist(void); -static int updategeom(void); -static void updatenumlockmask(void); -static void updatesizehints(struct Client* c); -static void updatestatus(void); -static void updatetitle(struct Client* c); -static void updatewindowtype(struct Client* c); -static void updatewmhints(struct Client* c); -static void view(const union Arg* arg); -static struct Client* wintoclient(Window w); -static struct Monitor* wintomon(Window w); -static int xerror(Display* dpy, XErrorEvent* ee); -static int xerrordummy(Display* dpy, XErrorEvent* ee); -static int xerrorstart(Display* dpy, XErrorEvent* ee); -static void zoom(const union Arg* arg); - -static pid_t getparentprocess(pid_t p); -static int isdescprocess(pid_t p, pid_t c); -static struct Client* swallowingclient(Window w); -static struct Client* termforwin(const struct Client* c); -static pid_t winpid(Window w); +static void applyrules(Client* c); +static int applysizehints(Client* c, int* x, int* y, int* w, int* h, int interact); +static void arrange(Monitor* m); +static void arrangemon(Monitor* m); +static void attach(Client* c); +static void attachstack(Client* c); +static void buttonpress(XEvent* e); +static void checkotherwm(void); +static void cleanup(void); +static void cleanupmon(Monitor* mon); +static void clientmessage(XEvent* e); +static void configure(Client* c); +static void configurenotify(XEvent* e); +static void configurerequest(XEvent* e); +static Monitor* createmon(void); +static void destroynotify(XEvent* e); +static void detach(Client* c); +static void detachstack(Client* c); +static Monitor* dirtomon(int dir); +static void drawbar(Monitor* m); +static void drawbars(void); +static void enternotify(XEvent* e); +static void expose(XEvent* e); +static void fibonacci(Monitor* mon); +static void focus(Client* c); +static void focusin(XEvent* e); +static void focusmon(const Arg* arg); +static void focusstack(const Arg* arg); +static Atom getatomprop(Client* c, Atom prop); +static int getrootptr(int* x, int* y); +static long getstate(Window w); +static int gettextprop(Window w, Atom atom, char* text, uint size); +static void grabbuttons(Client* c, int focused); +static void grabkeys(void); +static void keypress(XEvent* e); +static void killclient(const Arg* arg); +static void manage(Window w, XWindowAttributes* wa); +static void mappingnotify(XEvent* e); +static void maprequest(XEvent* e); +static void motionnotify(XEvent* e); +static void movemouse(const Arg* arg); +static Client* nexttiled(Client* c); +static void pop(Client*); +static void propertynotify(XEvent* e); +static void quit(const Arg* arg); +static Monitor* recttomon(int x, int y, int w, int h); +static void resize(Client* c, int x, int y, int w, int h, int interact); +static void resizeclient(Client* c, int x, int y, int w, int h); +static void resizemouse(const Arg* arg); +static void restack(Monitor* m); +static void run(void); +static void scan(void); +static int sendevent(Client* c, Atom proto); +static void sendmon(Client* c, Monitor* m); +static void setclientstate(Client* c, long state); +static void setfocus(Client* c); +static void setfullscreen(Client* c, int fullscreen); +static void setlayout(const Arg* arg); +static void setmfact(const Arg* arg); +static void setup(void); +static void seturgent(Client* c, int urg); +static void showhide(Client* c); +static void sigchld(int unused); +static void spawn(const Arg* arg); +static void tag(const Arg* arg); +static void tagmon(const Arg* arg); +static void togglebar(const Arg* arg); +static void togglefloating(const Arg* arg); +static void togglefullscr(const Arg* arg); +static void toggletag(const Arg* arg); +static void toggleview(const Arg* arg); +static void unfocus(Client* c, int setfocus); +static void unmanage(Client* c, int destroyed); +static void unmapnotify(XEvent* e); +static void updatebarpos(Monitor* m); +static void updatebars(void); +static void updateclientlist(void); +static int updategeom(void); +static void updatenumlockmask(void); +static void updatesizehints(Client* c); +static void updatestatus(void); +static void updatetitle(Client* c); +static void updatewindowtype(Client* c); +static void updatewmhints(Client* c); +static void view(const Arg* arg); +static Client* wintoclient(Window w); +static Monitor* wintomon(Window w); +static int xerror(Display* dpy, XErrorEvent* error_event); +static int xerrordummy(Display* dpy, XErrorEvent* error_event); +static int xerrorstart(Display* dpy, XErrorEvent* error_event); +static void zoom(const Arg* arg); + +/* swallow */ +static pid_t getparentprocess(pid_t p); +static int isdescprocess(pid_t p, pid_t c); +static Client* swallowingclient(Window w); +static Client* termforwin(const Client* c); +static pid_t winpid(Window w); /* variables */ static const char broken[] = "broken"; @@ -268,8 +265,8 @@ static int screen; static int sw, sh; /* X display screen geometry width, height */ static int bh, blw = 0; /* bar geometry */ static int lrpad; /* sum of left and right padding for text */ -static int (*xerrorxlib)(Display*, XErrorEvent*); -static unsigned int numlockmask = 0; +static int (*xerrorxlib)(Display*, XErrorEvent*); +static uint numlockmask = 0; static void (*handler[LASTEvent])(XEvent*) = { [ButtonPress] = buttonpress, [ClientMessage] = clientmessage, [ConfigureRequest] = configurerequest, @@ -284,63 +281,57 @@ static void (*handler[LASTEvent])(XEvent*) = { [ButtonPress] = buttonpress, [MotionNotify] = motionnotify, [PropertyNotify] = propertynotify, [UnmapNotify] = unmapnotify }; -static Atom wmatom[WMLast], netatom[NetLast]; -static int running = 1; -static Cur* cursor[CurLast]; -static Clr** scheme; +static Atom wmatom[WMLast], netatom[NetLast]; +static int running = 1; +static Cur* cursor[CurLast]; +static Color** scheme; static Display* dpy; -static Drw* drw; -static struct Monitor *mons, *selmon; -static Window root, wmcheckwin; +static Drw* drw; +static Monitor *mons, *selmon; +static Window root, wmcheckwin; static xcb_connection_t* xcon; /* configuration, allows nested code to access above variables */ #include "config.h" -/* compile-time check if all tags fit into an unsigned int bit array. */ +/* compile-time check if all tags fit into an uint bit array. */ struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; }; /* function implementations */ -void swallow(struct Client* p, struct Client* c) { - struct Client* s; - - if (c->noswallow > 0 || c->isterminal) return; - if (c->noswallow < 0 && !swallowfloating && c->isfloating) return; +void +swallow(Client* p, Client* c) +{ + Window win; + if (c->noswallow || c->isterminal) + return; detach(c); detachstack(c); - setclientstate(c, WithdrawnState); XUnmapWindow(dpy, p->win); - - p->swallowing = c; - c->mon = p->mon; - - Window w = p->win; - p->win = c->win; - c->win = w; - - XChangeProperty(dpy, c->win, netatom[NetClientList], XA_WINDOW, 32, PropModeReplace, (unsigned char*)&(p->win), 1); - + p->swallowing = c; + c->mon = p->mon; + win = p->win; + p->win = c->win; + c->win = win; updatetitle(p); - s = scanner ? c : p; - XMoveResizeWindow(dpy, p->win, s->x, s->y, s->w, s->h); + XMoveResizeWindow(dpy, p->win, p->x, p->y, p->w, p->h); arrange(p->mon); configure(p); updateclientlist(); } -void unswallow(struct Client* c) { +void +unswallow(Client* c) +{ c->win = c->swallowing->win; free(c->swallowing); c->swallowing = NULL; - XDeleteProperty(dpy, c->win, netatom[NetClientList]); - /* unfullscreen the client */ setfullscreen(c, 0); updatetitle(c); @@ -352,17 +343,20 @@ void unswallow(struct Client* c) { arrange(c->mon); } -void applyrules(struct Client* c) { - const char* class, *instance; - unsigned int i; - const Rule* r; - struct Monitor* m; - XClassHint ch = { NULL, NULL }; +void +applyrules(Client* c) +{ + const char* class, *instance; + uint i; + const Rule* r; + Monitor* m; + XClassHint ch = { NULL, NULL }; /* rule matching */ - c->noswallow = -1; - c->isfloating = 0; - c->tags = 0; + c->isfloating = 0; + c->isterminal = 0; + c->noswallow = 0; + c->tags = 0; XGetClassHint(dpy, c->win, &ch); class = ch.res_class ? ch.res_class : broken; instance = ch.res_name ? ch.res_name : broken; @@ -386,9 +380,10 @@ void applyrules(struct Client* c) { c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags]; } -int applysizehints(struct Client* c, int* x, int* y, int* w, int* h, int interact) { - int baseismin; - struct Monitor* m = c->mon; +int applysizehints(Client* c, int* x, int* y, int* w, int* h, int interact) +{ + int baseismin; + Monitor* m = c->mon; /* set minimum possible */ *w = MAX(1, *w); @@ -435,7 +430,9 @@ int applysizehints(struct Client* c, int* x, int* y, int* w, int* h, int interac return *x != c->x || *y != c->y || *w != c->w || *h != c->h; } -void arrange(struct Monitor* m) { +void +arrange(Monitor* m) +{ if (m) showhide(m->stack); else for (m = mons; m; m = m->next) showhide(m->stack); @@ -446,32 +443,39 @@ void arrange(struct Monitor* m) { for (m = mons; m; m = m->next) arrangemon(m); } -void arrangemon(struct Monitor* m) { - strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof m->ltsymbol); +void +arrangemon(Monitor* m) +{ if (m->lt[m->sellt]->arrange) m->lt[m->sellt]->arrange(m); } -void attach(struct Client* c) { +void +attach(Client* c) +{ c->next = c->mon->clients; c->mon->clients = c; } -void attachstack(struct Client* c) { +void +attachstack(Client* c) +{ c->snext = c->mon->stack; c->mon->stack = c; } -void buttonpress(XEvent* e) { - unsigned int i, x, click; - union Arg arg = { 0 }; - struct Client* c; - struct Monitor* m; +void +buttonpress(XEvent* e) +{ + uint i, x, click; + Arg arg = { 0 }; + Client* c; + Monitor* m; XButtonPressedEvent* ev = &e->xbutton; click = ClkRootWin; /* focus monitor if necessary */ if ((m = wintomon(ev->window)) && m != selmon) { - unfocus(selmon->sel, 1); + unfocus(selmon->selcli, 1); selmon = m; focus(NULL); } @@ -502,7 +506,9 @@ void buttonpress(XEvent* e) { buttons[i].func(click == ClkTagBar && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg); } -void checkotherwm(void) { +void +checkotherwm(void) +{ xerrorxlib = XSetErrorHandler(xerrorstart); /* this causes an error if some other window manager is running */ XSelectInput(dpy, DefaultRootWindow(dpy), SubstructureRedirectMask); @@ -511,11 +517,13 @@ void checkotherwm(void) { XSync(dpy, False); } -void cleanup(void) { - union Arg a = { .ui = ~0 }; - struct Layout foo = { "", NULL }; - struct Monitor* m; - size_t i; +void +cleanup(void) +{ + Arg a = { .ui = ~0 }; + Layout foo = { "", NULL }; + Monitor* m; + size_t i; view(&a); selmon->lt[selmon->sellt] = &foo; @@ -523,8 +531,10 @@ void cleanup(void) { while (m->stack) unmanage(m->stack, 0); XUngrabKey(dpy, AnyKey, AnyModifier, root); while (mons) cleanupmon(mons); - for (i = 0; i < CurLast; i++) drw_cur_free(drw, cursor[i]); - for (i = 0; i < LENGTH(colors); i++) free(scheme[i]); + for (i = 0; i < CurLast; i++) + drw_cur_free(drw, cursor[i]); + for (i = 0; i < LENGTH(colors); i++) + free(scheme[i]); XDestroyWindow(dpy, wmcheckwin); drw_free(drw); XSync(dpy, False); @@ -532,8 +542,10 @@ void cleanup(void) { XDeleteProperty(dpy, root, netatom[NetActiveWindow]); } -void cleanupmon(struct Monitor* mon) { - struct Monitor* m; +void +cleanupmon(Monitor* mon) +{ + Monitor* m; if (mon == mons) mons = mons->next; else { @@ -546,24 +558,26 @@ void cleanupmon(struct Monitor* mon) { free(mon); } -void clientmessage(XEvent* e) { +void +clientmessage(XEvent* e) +{ XClientMessageEvent* cme = &e->xclient; - struct Client* c = wintoclient(cme->window); + Client* c = wintoclient(cme->window); if (!c) return; if (cme->message_type == netatom[NetWMState]) { if (cme->data.l[1] == netatom[NetWMFullscreen] || cme->data.l[2] == netatom[NetWMFullscreen]) - setfullscreen( - c, - ( - cme->data.l[0] == 1 /* _NET_WM_STATE_ADD */ || - (cme->data.l[0] == 2 /* _NET_WM_STATE_TOGGLE */ && !c->isfullscreen))); + setfullscreen(c, ( + cme->data.l[0] == 1 /* _NET_WM_STATE_ADD */ || + (cme->data.l[0] == 2 /* _NET_WM_STATE_TOGGLE */ && !c->isfullscreen))); } else if (cme->message_type == netatom[NetActiveWindow]) { - if (c != selmon->sel && !c->isurgent) seturgent(c, 1); + if (c != selmon->selcli && !c->isurgent) seturgent(c, 1); } } -void configure(struct Client* c) { +void +configure(Client* c) +{ XConfigureEvent ce; ce.type = ConfigureNotify; @@ -580,9 +594,11 @@ void configure(struct Client* c) { XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent*)&ce); } -void configurenotify(XEvent* e) { - struct Monitor* m; - struct Client* c; +void +configurenotify(XEvent* e) +{ + Monitor* m; + Client* c; XConfigureEvent* ev = &e->xconfigure; int dirty; @@ -605,9 +621,11 @@ void configurenotify(XEvent* e) { } } -void configurerequest(XEvent* e) { - struct Client* c; - struct Monitor* m; +void +configurerequest(XEvent* e) +{ + Client* c; + Monitor* m; XConfigureRequestEvent* ev = &e->xconfigurerequest; XWindowChanges wc; @@ -636,7 +654,8 @@ void configurerequest(XEvent* e) { if ((c->y + c->h) > m->my + m->mh && c->isfloating) c->y = m->my + (m->mh / 2 - HEIGHT(c) / 2); /* center in y direction */ if ((ev->value_mask & (CWX | CWY)) && !(ev->value_mask & (CWWidth | CWHeight))) configure(c); - if (ISVISIBLE(c)) XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); + if (ISVISIBLE(c)) + XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); } else configure(c); } else { @@ -652,38 +671,26 @@ void configurerequest(XEvent* e) { XSync(dpy, False); } -struct Monitor* createmon(void) { - struct Monitor* m; +Monitor* +createmon() +{ + Monitor* m; - m = ecalloc(1, sizeof(struct Monitor)); + m = ecalloc(1, sizeof(Monitor)); m->tagset[0] = m->tagset[1] = 1; - m->mfact = mfact; - m->nmaster = nmaster; - m->showbar = showbar; - m->topbar = topbar; - m->lt[0] = &layouts[0]; - m->lt[1] = &layouts[1 % LENGTH(layouts)]; - strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol); + m->mfact = mfact; + m->nmaster = nmaster; + m->showbar = showbar; + m->topbar = topbar; + m->lt[0] = &layouts[0]; + m->lt[1] = &layouts[1 % LENGTH(layouts)]; return m; } -void cyclelayout(const union Arg* arg) { - struct Layout* l; - for (l = (struct Layout*)layouts; l != selmon->lt[selmon->sellt]; ++l) - ; - if (arg->i > 0) { - if (l->symbol && (l + 1)->symbol) setlayout(&((union Arg){ .v = (l + 1) })); - else - setlayout(&((union Arg){ .v = layouts })); - } else { - if (l != layouts && (l - 1)->symbol) setlayout(&((union Arg){ .v = (l - 1) })); - else - setlayout(&((union Arg){ .v = &layouts[LENGTH(layouts) - 2] })); - } -} - -void destroynotify(XEvent* e) { - struct Client* c; +void +destroynotify(XEvent* e) +{ + Client* c; XDestroyWindowEvent* ev = &e->xdestroywindow; if ((c = wintoclient(ev->window))) unmanage(c, 1); @@ -691,30 +698,35 @@ void destroynotify(XEvent* e) { unmanage(c->swallowing, 1); } -void detach(struct Client* c) { - struct Client** tc; +void +detach(Client* c) +{ + Client** tc; for (tc = &c->mon->clients; *tc && *tc != c; tc = &(*tc)->next) ; *tc = c->next; } -void detachstack(struct Client* c) { - struct Client **tc, *t; +void +detachstack(Client* c) +{ + Client **tc, *t; for (tc = &c->mon->stack; *tc && *tc != c; tc = &(*tc)->snext) ; *tc = c->snext; - if (c == c->mon->sel) { + if (c == c->mon->selcli) { for (t = c->mon->stack; t && !ISVISIBLE(t); t = t->snext) ; - c->mon->sel = t; + c->mon->selcli = t; } } -struct Monitor* dirtomon(int dir) { - struct Monitor* m = NULL; +Monitor* dirtomon(int dir) +{ + Monitor* m = NULL; if (dir > 0) { if (!(m = selmon->next)) m = mons; @@ -727,12 +739,14 @@ struct Monitor* dirtomon(int dir) { return m; } -void drawbar(struct Monitor* m) { - int x, w, tw = 0; - int boxs = drw->fonts->h / 9; - int boxw = drw->fonts->h / 6 + 2; - unsigned int i, occ = 0, urg = 0; - struct Client* c; +void +drawbar(Monitor* m) +{ + int x, w, tw = 0; + int boxs = drw->fonts->h / 9; + int boxw = drw->fonts->h / 6 + 2; + uint i, occ = 0, urg = 0; + Client* c; /* draw status first so it can be overdrawn by tags later */ if (m == selmon) { /* status is only drawn on selected monitor */ @@ -751,19 +765,16 @@ void drawbar(struct Monitor* m) { drw_setscheme(drw, scheme[m->tagset[m->seltags] & 1 << i ? SchemeSel : SchemeNorm]); drw_text(drw, x, 0, w, bh, lrpad / 2, tags[i], urg & 1 << i); if (occ & 1 << i) - drw_rect( - drw, x + boxs, boxs, boxw, boxw, m == selmon && selmon->sel && selmon->sel->tags & 1 << i, urg & 1 << i); + drw_rect(drw, x + boxs, boxs, boxw, boxw, m == selmon && selmon->selcli && selmon->selcli->tags & 1 << i, urg & 1 << i); x += w; } - w = blw = TEXTW(m->ltsymbol); drw_setscheme(drw, scheme[SchemeNorm]); - x = drw_text(drw, x, 0, w, bh, lrpad / 2, m->ltsymbol, 0); if ((w = m->ww - tw - x) > bh) { - if (m->sel) { + if (m->selcli) { drw_setscheme(drw, scheme[m == selmon ? SchemeSel : SchemeNorm]); - drw_text(drw, x, 0, w, bh, lrpad / 2, m->sel->name, 0); - if (m->sel->isfloating) drw_rect(drw, x + boxs, boxs, boxw, boxw, m->sel->isfixed, 0); + drw_text(drw, x, 0, w, bh, lrpad / 2, m->selcli->name, 0); + if (m->selcli->isfloating) drw_rect(drw, x + boxs, boxs, boxw, boxw, m->selcli->isfixed, 0); } else { drw_setscheme(drw, scheme[SchemeNorm]); drw_rect(drw, x, 0, w, bh, 1, 1); @@ -772,40 +783,49 @@ void drawbar(struct Monitor* m) { drw_map(drw, m->barwin, 0, 0, m->ww, bh); } -void drawbars(void) { - struct Monitor* m; +void +drawbars(void) +{ + Monitor* m; for (m = mons; m; m = m->next) drawbar(m); } -void enternotify(XEvent* e) { - struct Client* c; - struct Monitor* m; +void +enternotify(XEvent* e) +{ + Client* c; + Monitor* m; XCrossingEvent* ev = &e->xcrossing; if ((ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root) return; c = wintoclient(ev->window); m = c ? c->mon : wintomon(ev->window); if (m != selmon) { - unfocus(selmon->sel, 1); + unfocus(selmon->selcli, 1); selmon = m; - } else if (!c || c == selmon->sel) + } else if (!c || c == selmon->selcli) return; focus(c); } -void expose(XEvent* e) { - struct Monitor* m; - XExposeEvent* ev = &e->xexpose; +void +expose(XEvent* e) +{ + Monitor* m; + XExposeEvent* ev = &e->xexpose; if (ev->count == 0 && (m = wintomon(ev->window))) drawbar(m); } -void fibonacci(struct Monitor* mon) { - unsigned int i, n, nx, ny, nw, nh; - struct Client* c; +void +fibonacci(Monitor* mon) +{ + uint i, n, nx, ny, nw, nh; + Client* c; - for (n = 0, c = nexttiled(mon->clients); c; c = nexttiled(c->next), ++n); + for (n = 0, c = nexttiled(mon->clients); c; c = nexttiled(c->next), ++n) + ; if (n == 0) return; nx = mon->wx; @@ -816,33 +836,39 @@ void fibonacci(struct Monitor* mon) { for (i = 0, c = nexttiled(mon->clients); c; c = nexttiled(c->next)) { if ((i % 2 && nh / 2 > 2 * c->bw) || (!(i % 2) && nw / 2 > 2 * c->bw)) { if (i < n - 1) { - if (i % 2) nh /= 2; - else nw /= 2; + if (i % 2) nh /= 2; + else + nw /= 2; } if ((i % 4) == 0) { ny += nh; } - else if ((i % 4) == 1) nx += nw; - else if ((i % 4) == 2) ny += nh; - else if ((i % 4) == 3) nx += nw; + else if ((i % 4) == 1) + nx += nw; + else if ((i % 4) == 2) + ny += nh; + else if ((i % 4) == 3) + nx += nw; if (i == 0) { if (n != 1) nw = mon->ww * mon->mfact; ny = mon->wy; - } - else if (i == 1) nw = mon->ww - nw; + } else if (i == 1) + nw = mon->ww - nw; i++; } resize(c, nx, ny, nw - 2 * c->bw, nh - 2 * c->bw, False); } } -void focus(struct Client* c) { +void +focus(Client* c) +{ if (!c || !ISVISIBLE(c)) for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snext) ; - if (selmon->sel && selmon->sel != c) unfocus(selmon->sel, 0); + if (selmon->selcli && selmon->selcli != c) unfocus(selmon->selcli, 0); if (c) { if (c->mon != selmon) selmon = c->mon; if (c->isurgent) seturgent(c, 0); @@ -855,40 +881,46 @@ void focus(struct Client* c) { XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); XDeleteProperty(dpy, root, netatom[NetActiveWindow]); } - selmon->sel = c; + selmon->selcli = c; drawbars(); } /* there are some broken focus acquiring clients needing extra handling */ -void focusin(XEvent* e) { +void +focusin(XEvent* e) +{ XFocusChangeEvent* ev = &e->xfocus; - if (selmon->sel && ev->window != selmon->sel->win) setfocus(selmon->sel); + if (selmon->selcli && ev->window != selmon->selcli->win) setfocus(selmon->selcli); } -void focusmon(const union Arg* arg) { - struct Monitor* m; +void +focusmon(const Arg* arg) +{ + Monitor* m; if (!mons->next) return; if ((m = dirtomon(arg->i)) == selmon) return; - unfocus(selmon->sel, 0); + unfocus(selmon->selcli, 0); selmon = m; focus(NULL); } -void focusstack(const union Arg* arg) { - struct Client *c = NULL, *i; +void +focusstack(const Arg* arg) +{ + Client *c = NULL, *i; - if (!selmon->sel) return; + if (!selmon->selcli) return; if (arg->i > sizeof(arg)) return; if (arg->i > 0) { - for (c = selmon->sel->next; c && !ISVISIBLE(c); c = c->next) + for (c = selmon->selcli->next; c && !ISVISIBLE(c); c = c->next) ; if (!c) for (c = selmon->clients; c && !ISVISIBLE(c); c = c->next) ; } else { - for (i = selmon->clients; i != selmon->sel; i = i->next) + for (i = selmon->clients; i != selmon->selcli; i = i->next) if (ISVISIBLE(i)) c = i; if (!c) for (; i; i = i->next) @@ -900,12 +932,15 @@ void focusstack(const union Arg* arg) { } } -Atom getatomprop(struct Client* c, Atom prop) { - int di; - unsigned long dl; - unsigned char* p = NULL; - Atom da, atom = None; +Atom getatomprop(Client* c, Atom prop) +{ + int di; + unsigned long dl; + uchar* p; + Atom da, atom; + p = NULL; + atom = None; if ( XGetWindowProperty(dpy, c->win, prop, 0L, sizeof atom, False, XA_ATOM, &da, &di, &dl, &dl, &p) == Success && p) { atom = *(Atom*)p; @@ -914,24 +949,26 @@ Atom getatomprop(struct Client* c, Atom prop) { return atom; } -int getrootptr(int* x, int* y) { +int getrootptr(int* x, int* y) +{ int di; - unsigned int dui; + uint dui; Window dummy; return XQueryPointer(dpy, root, &dummy, &dummy, x, y, &di, &di, &dui); } -long getstate(Window w) { +long getstate(Window w) +{ int format; long result = -1; - unsigned char* p = NULL; + uchar* p = NULL; unsigned long n, extra; Atom real; if ( XGetWindowProperty( - dpy, w, wmatom[WMState], 0L, 2L, False, wmatom[WMState], &real, &format, &n, &extra, (unsigned char**)&p) != + dpy, w, wmatom[WMState], 0L, 2L, False, wmatom[WMState], &real, &format, &n, &extra, (uchar**)&p) != Success) return -1; if (n != 0) result = *p; @@ -939,7 +976,8 @@ long getstate(Window w) { return result; } -int gettextprop(Window w, Atom atom, char* text, unsigned int size) { +int gettextprop(Window w, Atom atom, char* text, uint size) +{ char** list = NULL; int n; XTextProperty name; @@ -959,11 +997,13 @@ int gettextprop(Window w, Atom atom, char* text, unsigned int size) { return 1; } -void grabbuttons(struct Client* c, int focused) { +void +grabbuttons(Client* c, int focused) +{ updatenumlockmask(); { - unsigned int i, j; - unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask | LockMask }; + uint i, j; + uint modifiers[] = { 0, LockMask, numlockmask, numlockmask | LockMask }; XUngrabButton(dpy, AnyButton, AnyModifier, c->win); if (!focused) XGrabButton(dpy, AnyButton, AnyModifier, c->win, False, BUTTONMASK, GrabModeSync, GrabModeSync, None, None); @@ -976,11 +1016,13 @@ void grabbuttons(struct Client* c, int focused) { } } -void grabkeys(void) { +void +grabkeys(void) +{ updatenumlockmask(); { - unsigned int i, j; - unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask | LockMask }; + uint i, j; + uint modifiers[] = { 0, LockMask, numlockmask, numlockmask | LockMask }; KeyCode code; XUngrabKey(dpy, AnyKey, AnyModifier, root); @@ -991,26 +1033,25 @@ void grabkeys(void) { } } -void incnmaster(const union Arg* arg) { - selmon->nmaster = MAX(selmon->nmaster + arg->i, 0); - arrange(selmon); -} - #ifdef XINERAMA -static int isuniquegeom(XineramaScreenInfo* unique, size_t n, XineramaScreenInfo* info) { - while (n--) - if ( - unique[n].x_org == info->x_org && unique[n].y_org == info->y_org && unique[n].width == info->width && - unique[n].height == info->height) +static int isuniquegeom(XineramaScreenInfo* unique, size_t n, XineramaScreenInfo* info) +{ + for (;n--;) + if (unique[n].x_org == info->x_org && + unique[n].y_org == info->y_org && + unique[n].width == info->width && + unique[n].height == info->height) return 0; return 1; } #endif /* XINERAMA */ -void keypress(XEvent* e) { - unsigned int i; - KeySym keysym; - XKeyEvent* ev; +void +keypress(XEvent* e) +{ + uint i; + KeySym keysym; + XKeyEvent* ev; ev = &e->xkey; keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0); @@ -1019,27 +1060,33 @@ void keypress(XEvent* e) { keys[i].func(&(keys[i].arg)); } -void killclient(const union Arg* arg) { - if (!selmon->sel) return; - if (!sendevent(selmon->sel, wmatom[WMDelete])) { +void +killclient(const Arg* arg) +{ + if (!selmon->selcli) return; + if (!sendevent(selmon->selcli, wmatom[WMDelete])) { XGrabServer(dpy); XSetErrorHandler(xerrordummy); XSetCloseDownMode(dpy, DestroyAll); - XKillClient(dpy, selmon->sel->win); + XKillClient(dpy, selmon->selcli->win); XSync(dpy, False); XSetErrorHandler(xerror); XUngrabServer(dpy); } } -void manage(Window w, XWindowAttributes* wa) { - struct Client * c, *t = NULL, *term = NULL; +void +manage(Window w, XWindowAttributes* wa) +{ + Client *c, *t, *term; Window trans = None; XWindowChanges wc; - c = ecalloc(1, sizeof(struct Client)); - c->win = w; - c->pid = winpid(w); + t = NULL; + term = NULL; + c = ecalloc(1, sizeof(Client)); + c->win = w; + c->pid = winpid(w); /* geometry */ c->x = c->oldx = wa->x; c->y = c->oldy = wa->y; @@ -1077,29 +1124,35 @@ void manage(Window w, XWindowAttributes* wa) { updatewmhints(c); XSelectInput(dpy, w, EnterWindowMask | FocusChangeMask | PropertyChangeMask | StructureNotifyMask); grabbuttons(c, 0); - if (!c->isfloating) c->isfloating = c->oldstate = trans != None || c->isfixed; - if (c->isfloating) XRaiseWindow(dpy, c->win); + if (!c->isfloating) + c->isfloating = c->oldstate = trans != None || c->isfixed; + if (c->isfloating) + XRaiseWindow(dpy, c->win); attach(c); attachstack(c); - XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend, (unsigned char*)&(c->win), 1); + XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend, (uchar*)&(c->win), 1); XMoveResizeWindow(dpy, c->win, c->x + 2 * sw, c->y, c->w, c->h); /* some windows require this */ setclientstate(c, NormalState); - if (c->mon == selmon) unfocus(selmon->sel, 0); - c->mon->sel = c; + if (c->mon == selmon) unfocus(selmon->selcli, 0); + c->mon->selcli = c; arrange(c->mon); XMapWindow(dpy, c->win); if (term) swallow(term, c); focus(NULL); } -void mappingnotify(XEvent* e) { +void +mappingnotify(XEvent* e) +{ XMappingEvent* ev = &e->xmapping; XRefreshKeyboardMapping(ev); if (ev->request == MappingKeyboard) grabkeys(); } -void maprequest(XEvent* e) { +void +maprequest(XEvent* e) +{ static XWindowAttributes wa; XMapRequestEvent* ev = &e->xmaprequest; @@ -1108,40 +1161,32 @@ void maprequest(XEvent* e) { if (!wintoclient(ev->window)) manage(ev->window, &wa); } -void monocle(struct Monitor* m) { - unsigned int n = 0; - struct Client* c; - - for (c = m->clients; c; c = c->next) - if (ISVISIBLE(c)) n++; - if (n > 0) /* override layout symbol */ - snprintf(m->ltsymbol, sizeof m->ltsymbol, "[%d]", n); - for (c = nexttiled(m->clients); c; c = nexttiled(c->next)) - resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, 0); -} - -void motionnotify(XEvent* e) { - static struct Monitor* mon = NULL; - struct Monitor* m; - XMotionEvent* ev = &e->xmotion; +void +motionnotify(XEvent* e) +{ + static Monitor* mon = NULL; + Monitor* m; + XMotionEvent* ev = &e->xmotion; if (ev->window != root) return; if ((m = recttomon(ev->x_root, ev->y_root, 1, 1)) != mon && mon) { - unfocus(selmon->sel, 1); + unfocus(selmon->selcli, 1); selmon = m; focus(NULL); } mon = m; } -void movemouse(const union Arg* arg) { - int x, y, ocx, ocy, nx, ny; - struct Client* c; - struct Monitor* m; - XEvent ev; - Time lasttime = 0; +void +movemouse(const Arg* arg) +{ + int x, y, ocx, ocy, nx, ny; + Client* c; + Monitor* m; + XEvent ev; + Time lasttime = 0; - if (!(c = selmon->sel)) return; + if (!(c = selmon->selcli)) return; if (c->isfullscreen) /* no support moving fullscreen windows by mouse */ return; restack(selmon); @@ -1187,34 +1232,38 @@ void movemouse(const union Arg* arg) { } } -struct Client* nexttiled(struct Client* c) { +Client* nexttiled(Client* c) +{ for (; c && (c->isfloating || !ISVISIBLE(c)); c = c->next) ; return c; } -void pop(struct Client* c) { +void +pop(Client* c) +{ detach(c); attach(c); focus(c); arrange(c->mon); } -void propertynotify(XEvent* e) { - struct Client* c; +void +propertynotify(XEvent* e) +{ + Client* c; Window trans; XPropertyEvent* ev = &e->xproperty; if ((ev->window == root) && (ev->atom == XA_WM_NAME)) updatestatus(); - else if (ev->state == PropertyDelete) - return; /* ignore */ + else if (ev->state == PropertyDelete) return; else if ((c = wintoclient(ev->window))) { switch (ev->atom) { default: break; case XA_WM_TRANSIENT_FOR: - if ( - !c->isfloating && (XGetTransientForHint(dpy, c->win, &trans)) && - (c->isfloating = (wintoclient(trans)) != NULL)) + if ( !c->isfloating && + (XGetTransientForHint(dpy, c->win, &trans)) && + (c->isfloating = (wintoclient(trans)) != NULL)) arrange(c->mon); break; case XA_WM_NORMAL_HINTS: updatesizehints(c); break; @@ -1225,19 +1274,22 @@ void propertynotify(XEvent* e) { } if (ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) { updatetitle(c); - if (c == c->mon->sel) drawbar(c->mon); + if (c == c->mon->selcli) drawbar(c->mon); } if (ev->atom == netatom[NetWMWindowType]) updatewindowtype(c); } } -void quit(const union Arg* arg) { +void +quit(const Arg* arg) +{ running = 0; } -struct Monitor* recttomon(int x, int y, int w, int h) { - struct Monitor *m, *r = selmon; - int a, area = 0; +Monitor* recttomon(int x, int y, int w, int h) +{ + Monitor *m, *r = selmon; + int a, area = 0; for (m = mons; m; m = m->next) if ((a = INTERSECT(x, y, w, h, m)) > area) { @@ -1247,11 +1299,15 @@ struct Monitor* recttomon(int x, int y, int w, int h) { return r; } -void resize(struct Client* c, int x, int y, int w, int h, int interact) { +void +resize(Client* c, int x, int y, int w, int h, int interact) +{ if (applysizehints(c, &x, &y, &w, &h, interact)) resizeclient(c, x, y, w, h); } -void resizeclient(struct Client* c, int x, int y, int w, int h) { +void +resizeclient(Client* c, int x, int y, int w, int h) +{ XWindowChanges wc; c->oldx = c->x; @@ -1268,14 +1324,16 @@ void resizeclient(struct Client* c, int x, int y, int w, int h) { XSync(dpy, False); } -void resizemouse(const union Arg* arg) { - int ocx, ocy, nw, nh; - struct Client* c; - struct Monitor* m; - XEvent ev; - Time lasttime = 0; +void +resizemouse(const Arg* arg) +{ + int ocx, ocy, nw, nh; + Client* c; + Monitor* m; + XEvent ev; + Time lasttime = 0; - if (!(c = selmon->sel)) return; + if (!(c = selmon->selcli)) return; if (c->isfullscreen) /* no support resizing fullscreen windows by mouse */ return; restack(selmon); @@ -1322,14 +1380,16 @@ void resizemouse(const union Arg* arg) { } } -void restack(struct Monitor* m) { - struct Client* c; +void +restack(Monitor* m) +{ + Client* c; XEvent ev; XWindowChanges wc; drawbar(m); - if (!m->sel) return; - if (m->sel->isfloating || !m->lt[m->sellt]->arrange) XRaiseWindow(dpy, m->sel->win); + if (!m->selcli) return; + if (m->selcli->isfloating || !m->lt[m->sellt]->arrange) XRaiseWindow(dpy, m->selcli->win); if (m->lt[m->sellt]->arrange) { wc.stack_mode = Below; wc.sibling = m->barwin; @@ -1344,17 +1404,22 @@ void restack(struct Monitor* m) { ; } -void run(void) { +void +run(void) +{ XEvent ev; - /* main event loop */ + XSync(dpy, False); while (running && !XNextEvent(dpy, &ev)) - if (handler[ev.type]) handler[ev.type](&ev); /* call handler */ + if (handler[ev.type]) + handler[ev.type](&ev); } -void scan(void) { +void +scan() +{ scanner = 1; - unsigned int i, num; + uint i, num; char swin[256]; Window d1, d2, *wins = NULL; XWindowAttributes wa; @@ -1379,7 +1444,9 @@ void scan(void) { scanner = 0; } -void sendmon(struct Client* c, struct Monitor* m) { +void +sendmon(Client* c, Monitor* m) +{ if (c->mon == m) return; unfocus(c, 1); detach(c); @@ -1392,20 +1459,17 @@ void sendmon(struct Client* c, struct Monitor* m) { arrange(NULL); } -void setbar(int value) { - selmon->showbar = value; - updatebarpos(selmon); - XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh); - arrange(selmon); -} - -void setclientstate(struct Client* c, long state) { +void +setclientstate(Client* c, long state) +{ long data[] = { state, None }; - XChangeProperty(dpy, c->win, wmatom[WMState], wmatom[WMState], 32, PropModeReplace, (unsigned char*)data, 2); + XChangeProperty(dpy, c->win, wmatom[WMState], wmatom[WMState], 32, PropModeReplace, (uchar*)data, 2); } -int sendevent(struct Client* c, Atom proto) { +int +sendevent(Client* c, Atom proto) +{ int n; Atom* protocols; int exists = 0; @@ -1427,51 +1491,60 @@ int sendevent(struct Client* c, Atom proto) { return exists; } -void setfocus(struct Client* c) { +void +setfocus(Client* c) +{ if (!c->neverfocus) { XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); XChangeProperty( - dpy, root, netatom[NetActiveWindow], XA_WINDOW, 32, PropModeReplace, (unsigned char*)&(c->win), 1); + dpy, root, netatom[NetActiveWindow], XA_WINDOW, 32, PropModeReplace, (uchar*)&(c->win), 1); } sendevent(c, wmatom[WMTakeFocus]); } -void setfullscreen(struct Client* c, int fullscreen) { - if (fullscreen && !c->isfullscreen) { - XChangeProperty( - dpy, c->win, netatom[NetWMState], XA_ATOM, 32, PropModeReplace, (unsigned char*)&netatom[NetWMFullscreen], 1); - c->isfullscreen = 1; - c->oldstate = c->isfloating; - c->oldbw = c->bw; - c->bw = 0; - c->isfloating = 1; - resizeclient(c, c->mon->mx, c->mon->my, c->mon->mw, c->mon->mh); - XRaiseWindow(dpy, c->win); - } else if (!fullscreen && c->isfullscreen) { - XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32, PropModeReplace, (unsigned char*)0, 0); - c->isfullscreen = 0; - c->isfloating = c->oldstate; - c->bw = c->oldbw; - c->x = c->oldx; - c->y = c->oldy; - c->w = c->oldw; - c->h = c->oldh; - resizeclient(c, c->x, c->y, c->w, c->h); - arrange(c->mon); +void +setfullscreen(Client* client, int fullscreen) +{ + if (fullscreen && !client->isfullscreen) { + XChangeProperty(dpy, client->win, netatom[NetWMState], XA_ATOM, 32, PropModeReplace, (uchar*)&netatom[NetWMFullscreen], 1); + client->isfullscreen = 1; + client->oldstate = client->isfloating; + client->oldbw = client->bw; + client->bw = 0; + client->isfloating = 1; + resizeclient(client, client->mon->mx, client->mon->my, client->mon->mw, client->mon->mh); + XRaiseWindow(dpy, client->win); + } else if (!fullscreen && client->isfullscreen) { + XChangeProperty(dpy, client->win, netatom[NetWMState], XA_ATOM, 32, PropModeReplace, (uchar*)0, 0); + client->isfullscreen = 0; + client->isfloating = client->oldstate; + client->bw = client->oldbw; + client->x = client->oldx; + client->y = client->oldy; + client->w = client->oldw; + client->h = client->oldh; + resizeclient(client, client->x, client->y, client->w, client->h); + arrange(client->mon); } } -void setlayout(const union Arg* arg) { - if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt]) selmon->sellt ^= 1; - if (arg && arg->v) selmon->lt[selmon->sellt] = (struct Layout*)arg->v; - strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol); - if (selmon->sel) arrange(selmon); +void +setlayout(const Arg* arg) +{ + if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt]) + selmon->sellt ^= 1; + if (arg && arg->v) + selmon->lt[selmon->sellt] = (Layout*)arg->v; + if (selmon->selcli) + arrange(selmon); else drawbar(selmon); } /* arg > 1.0 will set mfact absolutely */ -void setmfact(const union Arg* arg) { +void +setmfact(const Arg* arg) +{ float f; if (!arg || !selmon->lt[selmon->sellt]->arrange) return; @@ -1481,9 +1554,11 @@ void setmfact(const union Arg* arg) { arrange(selmon); } -void setup(void) { - int i; +void +setup() +{ XSetWindowAttributes wa; + int i; Atom utf8string; /* clean up any zombies immediately */ @@ -1495,10 +1570,12 @@ void setup(void) { sh = DisplayHeight(dpy, screen); root = RootWindow(dpy, screen); drw = drw_create(dpy, screen, root, sw, sh); - if (!drw_fontset_create(drw, fonts, LENGTH(fonts))) die("no fonts could be loaded."); + if (!drw_fontset_create(drw, fonts, LENGTH(fonts))) + die("no fonts could be loaded."); lrpad = drw->fonts->h; bh = drw->fonts->h + 2; updategeom(); + /* init atoms */ utf8string = XInternAtom(dpy, "UTF8_STRING", False); wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); @@ -1514,36 +1591,44 @@ void setup(void) { netatom[NetWMWindowType] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False); netatom[NetWMWindowTypeDialog] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False); netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False); + /* init cursors */ cursor[CurNormal] = drw_cur_create(drw, XC_left_ptr); cursor[CurResize] = drw_cur_create(drw, XC_sizing); cursor[CurMove] = drw_cur_create(drw, XC_fleur); + /* init appearance */ - scheme = ecalloc(LENGTH(colors), sizeof(Clr*)); - for (i = 0; i < LENGTH(colors); i++) scheme[i] = drw_scm_create(drw, colors[i], 3); + scheme = ecalloc(LENGTH(colors), sizeof(Color*)); + for (i = 0; i < LENGTH(colors); ++i) + scheme[i] = drw_scm_create(drw, colors[i], 3); + /* init bars */ updatebars(); updatestatus(); + /* supporting window for NetWMCheck */ wmcheckwin = XCreateSimpleWindow(dpy, root, 0, 0, 1, 1, 0, 0, 0); XChangeProperty( - dpy, wmcheckwin, netatom[NetWMCheck], XA_WINDOW, 32, PropModeReplace, (unsigned char*)&wmcheckwin, 1); - XChangeProperty(dpy, wmcheckwin, netatom[NetWMName], utf8string, 8, PropModeReplace, (unsigned char*)"dwm", 3); - XChangeProperty(dpy, root, netatom[NetWMCheck], XA_WINDOW, 32, PropModeReplace, (unsigned char*)&wmcheckwin, 1); + dpy, wmcheckwin, netatom[NetWMCheck], XA_WINDOW, 32, PropModeReplace, (uchar*)&wmcheckwin, 1); + XChangeProperty(dpy, wmcheckwin, netatom[NetWMName], utf8string, 8, PropModeReplace, (uchar*)"dwm", 3); + XChangeProperty(dpy, root, netatom[NetWMCheck], XA_WINDOW, 32, PropModeReplace, (uchar*)&wmcheckwin, 1); + /* EWMH support per view */ - XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32, PropModeReplace, (unsigned char*)netatom, NetLast); + XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32, PropModeReplace, (uchar*)netatom, NetLast); XDeleteProperty(dpy, root, netatom[NetClientList]); + /* select events */ wa.cursor = cursor[CurNormal]->cursor; - wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask | ButtonPressMask | PointerMotionMask | - EnterWindowMask | LeaveWindowMask | StructureNotifyMask | PropertyChangeMask; + wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask | ButtonPressMask | PointerMotionMask | EnterWindowMask | LeaveWindowMask | StructureNotifyMask | PropertyChangeMask; XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); XSelectInput(dpy, root, wa.event_mask); grabkeys(); focus(NULL); } -void seturgent(struct Client* c, int urg) { +void +seturgent(Client* c, int urg) +{ XWMHints* wmh; c->isurgent = urg; @@ -1553,7 +1638,9 @@ void seturgent(struct Client* c, int urg) { XFree(wmh); } -void showhide(struct Client* c) { +void +showhide(Client* c) +{ if (!c) return; if (ISVISIBLE(c)) { /* show clients top down */ @@ -1568,16 +1655,21 @@ void showhide(struct Client* c) { } } -void sigchld(int unused) { - if (signal(SIGCHLD, sigchld) == SIG_ERR) die("can't install SIGCHLD handler:"); - while (0 < waitpid(-1, NULL, WNOHANG)) - ; +void +sigchld(int unused) +{ + if (signal(SIGCHLD, sigchld) == SIG_ERR) + die("can't install SIGCHLD handler:"); + while (0 < waitpid(-1, NULL, WNOHANG)); } -void spawn(const union Arg* arg) { +void +spawn(const Arg* arg) +{ if (arg->v == dmenucmd) dmenumon[0] = '0' + selmon->num; if (fork() == 0) { - if (dpy) close(ConnectionNumber(dpy)); + if (dpy) + close(ConnectionNumber(dpy)); setsid(); execvp(((char**)arg->v)[0], (char**)arg->v); fprintf(stderr, "dwm: execvp %s", ((char**)arg->v)[0]); @@ -1586,57 +1678,70 @@ void spawn(const union Arg* arg) { } } -void tag(const union Arg* arg) { - if (selmon->sel && arg->ui & TAGMASK) { - selmon->sel->tags = arg->ui & TAGMASK; +void +tag(const Arg* arg) +{ + if (selmon->selcli && arg->ui & TAGMASK) { + selmon->selcli->tags = arg->ui & TAGMASK; focus(NULL); arrange(selmon); } } -void tagmon(const union Arg* arg) { - if (!selmon->sel || !mons->next) return; - sendmon(selmon->sel, dirtomon(arg->i)); +void +tagmon(const Arg* arg) +{ + if (!selmon->selcli || !mons->next) return; + sendmon(selmon->selcli, dirtomon(arg->i)); } -void togglebar(const union Arg* arg) { +void +togglebar(const Arg* arg) +{ selmon->showbar = !selmon->showbar; updatebarpos(selmon); XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh); arrange(selmon); } -void togglefloating(const union Arg* arg) { - if (!selmon->sel) return; - if (selmon->sel->isfullscreen) /* no support for fullscreen windows */ +void +togglefloating(const Arg* arg) +{ + if (!selmon->selcli) return; - selmon->sel->isfloating = !selmon->sel->isfloating || selmon->sel->isfixed; - if (selmon->sel->isfloating) resize(selmon->sel, selmon->sel->x, selmon->sel->y, selmon->sel->w, selmon->sel->h, 0); + if (selmon->selcli->isfullscreen) + return; /* no support for fullscreen windows */ + selmon->selcli->isfloating = !selmon->selcli->isfloating || selmon->selcli->isfixed; + if (selmon->selcli->isfloating) + resize(selmon->selcli, selmon->selcli->x, selmon->selcli->y, selmon->selcli->w, selmon->selcli->h, 0); arrange(selmon); } -void togglefullscr(const union Arg* arg) { - if (selmon->sel->isfullscreen) - setbar(1); - else - setbar(0); - setfullscreen(selmon->sel, !selmon->sel->isfullscreen); +void +togglefullscr(const Arg* arg) +{ + if (selmon->selcli) + setfullscreen(selmon->selcli, !selmon->selcli->isfullscreen); } -void toggletag(const union Arg* arg) { - unsigned int newtags; +void +toggletag(const Arg* arg) +{ + uint newtags; - if (!selmon->sel) return; - newtags = selmon->sel->tags ^ (arg->ui & TAGMASK); + if (!selmon->selcli) return; + newtags = selmon->selcli->tags ^ (arg->ui & TAGMASK); if (newtags) { - selmon->sel->tags = newtags; + selmon->selcli->tags = newtags; focus(NULL); arrange(selmon); } } -void toggleview(const union Arg* arg) { - unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK); +void +toggleview(const Arg* arg) +{ + uint newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK); if (newtagset) { selmon->tagset[selmon->seltags] = newtagset; @@ -1645,7 +1750,9 @@ void toggleview(const union Arg* arg) { } } -void unfocus(struct Client* c, int setfocus) { +void +unfocus(Client* c, int setfocus) +{ if (!c) return; grabbuttons(c, 0); XSetWindowBorder(dpy, c->win, scheme[SchemeNorm][ColBorder].pixel); @@ -1655,16 +1762,19 @@ void unfocus(struct Client* c, int setfocus) { } } -void unmanage(struct Client* c, int destroyed) { - struct Monitor* m = c->mon; - XWindowChanges wc; +void +unmanage(Client* c, int destroyed) +{ + Monitor* m; + Client* s; + XWindowChanges wc; + m = c->mon; if (c->swallowing) { unswallow(c); return; } - - struct Client* s = swallowingclient(c->win); + s = swallowingclient(c->win); if (s) { free(s->swallowing); s->swallowing = NULL; @@ -1672,7 +1782,6 @@ void unmanage(struct Client* c, int destroyed) { focus(NULL); return; } - detach(c); detachstack(c); if (!destroyed) { @@ -1687,10 +1796,6 @@ void unmanage(struct Client* c, int destroyed) { XUngrabServer(dpy); } free(c); - focus(NULL); - updateclientlist(); - arrange(m); - if (!s) { arrange(m); focus(NULL); @@ -1698,9 +1803,11 @@ void unmanage(struct Client* c, int destroyed) { } } -void unmapnotify(XEvent* e) { - struct Client* c; - XUnmapEvent* ev = &e->xunmap; +void +unmapnotify(XEvent* e) +{ + Client* c; + XUnmapEvent* ev = &e->xunmap; if ((c = wintoclient(ev->window))) { if (ev->send_event) setclientstate(c, WithdrawnState); @@ -1709,24 +1816,24 @@ void unmapnotify(XEvent* e) { } } -void updatebars(void) { - struct Monitor* m; - XSetWindowAttributes wa = { .override_redirect = True, - .background_pixmap = ParentRelative, - .event_mask = ButtonPressMask | ExposureMask }; +void +updatebars() +{ + Monitor* m; + XSetWindowAttributes wa = { .override_redirect = True, .background_pixmap = ParentRelative, .event_mask = ButtonPressMask | ExposureMask }; XClassHint ch = { "dwm", "dwm" }; for (m = mons; m; m = m->next) { if (m->barwin) continue; - m->barwin = XCreateWindow( - dpy, root, m->wx, m->by, m->ww, bh, 0, DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen), - CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); + m->barwin = XCreateWindow(dpy, root, m->wx, m->by, m->ww, bh, 0, DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen), CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); XDefineCursor(dpy, m->barwin, cursor[CurNormal]->cursor); XMapRaised(dpy, m->barwin); XSetClassHint(dpy, m->barwin, &ch); } } -void updatebarpos(struct Monitor* m) { +void +updatebarpos(Monitor* m) +{ m->wy = m->my; m->wh = m->mh; if (m->showbar) { @@ -1737,47 +1844,55 @@ void updatebarpos(struct Monitor* m) { m->by = -bh; } -void updateclientlist() { - struct Client* c; - struct Monitor* m; +void +updateclientlist() +{ + Client* c; + Monitor* m; XDeleteProperty(dpy, root, netatom[NetClientList]); for (m = mons; m; m = m->next) for (c = m->clients; c; c = c->next) XChangeProperty( - dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend, (unsigned char*)&(c->win), 1); + dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend, (uchar*)&(c->win), 1); } -int updategeom(void) { +int +updategeom() +{ int dirty = 0; #ifdef XINERAMA if (XineramaIsActive(dpy)) { int i, j, n, nn; - struct Client* c; - struct Monitor* m; - XineramaScreenInfo* info = XineramaQueryScreens(dpy, &nn); - XineramaScreenInfo* unique = NULL; - - for (n = 0, m = mons; m; m = m->next, n++) - ; + Client* c; + Monitor* m; + XineramaScreenInfo* info; + XineramaScreenInfo* unique; + + info = XineramaQueryScreens(dpy, &nn); + unique = NULL; + for (n = 0, m = mons; m; m = m->next, n++); /* only consider unique geometries as separate screens */ unique = ecalloc(nn, sizeof(XineramaScreenInfo)); - for (i = 0, j = 0; i < nn; i++) - if (isuniquegeom(unique, j, &info[i])) memcpy(&unique[j++], &info[i], sizeof(XineramaScreenInfo)); + for (i = 0, j = 0; i < nn; ++i) + if (isuniquegeom(unique, j, &info[i])) + memcpy(&unique[j++], &info[i], sizeof(XineramaScreenInfo)); XFree(info); nn = j; - if (n <= nn) { /* new monitors available */ + if (n <= nn) { /* new mons available */ for (i = 0; i < (nn - n); i++) { - for (m = mons; m && m->next; m = m->next) - ; + for (m = mons; m && m->next; m = m->next); if (m) m->next = createmon(); else mons = createmon(); } for (i = 0, m = mons; i < nn && m; m = m->next, i++) if ( - i >= n || unique[i].x_org != m->mx || unique[i].y_org != m->my || unique[i].width != m->mw || + i >= n || + unique[i].x_org != m->mx || + unique[i].y_org != m->my || + unique[i].width != m->mw || unique[i].height != m->mh) { dirty = 1; m->num = i; @@ -1787,10 +1902,9 @@ int updategeom(void) { m->mh = m->wh = unique[i].height; updatebarpos(m); } - } else { /* less monitors available nn < n */ + } else { /* less mons available nn < n */ for (i = nn; i < n; i++) { - for (m = mons; m && m->next; m = m->next) - ; + for (m = mons; m && m->next; m = m->next); while ((c = m->clients)) { dirty = 1; m->clients = c->next; @@ -1799,7 +1913,8 @@ int updategeom(void) { attach(c); attachstack(c); } - if (m == selmon) selmon = mons; + if (m == selmon) + selmon = mons; cleanupmon(m); } } @@ -1807,7 +1922,8 @@ int updategeom(void) { } else #endif /* XINERAMA */ { /* default monitor setup */ - if (!mons) mons = createmon(); + if (!mons) + mons = createmon(); if (mons->mw != sw || mons->mh != sh) { dirty = 1; mons->mw = mons->ww = sw; @@ -1822,8 +1938,10 @@ int updategeom(void) { return dirty; } -void updatenumlockmask(void) { - unsigned int i, j; +void +updatenumlockmask(void) +{ + uint i, j; XModifierKeymap* modmap; numlockmask = 0; @@ -1835,7 +1953,9 @@ void updatenumlockmask(void) { XFreeModifiermap(modmap); } -void updatesizehints(struct Client* c) { +void +updatesizehints(Client* c) +{ long msize; XSizeHints size; @@ -1875,31 +1995,41 @@ void updatesizehints(struct Client* c) { c->isfixed = (c->maxw && c->maxh && c->maxw == c->minw && c->maxh == c->minh); } -void updatestatus(void) { - if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext))) strcpy(stext, "dwm-" VERSION); +void +updatestatus() +{ + if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext))) strcpy(stext, "dwm-6.2"); drawbar(selmon); } -void updatetitle(struct Client* c) { +void +updatetitle(Client* c) +{ if (!gettextprop(c->win, netatom[NetWMName], c->name, sizeof c->name)) gettextprop(c->win, XA_WM_NAME, c->name, sizeof c->name); if (c->name[0] == '\0') /* hack to mark broken clients */ strcpy(c->name, broken); } -void updatewindowtype(struct Client* c) { +void +updatewindowtype(Client* c) +{ Atom state = getatomprop(c, netatom[NetWMState]); Atom wtype = getatomprop(c, netatom[NetWMWindowType]); - if (state == netatom[NetWMFullscreen]) setfullscreen(c, 1); - if (wtype == netatom[NetWMWindowTypeDialog]) c->isfloating = 1; + if (state == netatom[NetWMFullscreen]) + setfullscreen(c, 1); + if (wtype == netatom[NetWMWindowTypeDialog]) + c->isfloating = 1; } -void updatewmhints(struct Client* c) { +void +updatewmhints(Client* c) +{ XWMHints* wmh; if ((wmh = XGetWMHints(dpy, c->win))) { - if (c == selmon->sel && wmh->flags & XUrgencyHint) { + if (c == selmon->selcli && wmh->flags & XUrgencyHint) { wmh->flags &= ~XUrgencyHint; XSetWMHints(dpy, c->win, wmh); } else @@ -1911,33 +2041,43 @@ void updatewmhints(struct Client* c) { } } -void view(const union Arg* arg) { - if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags]) return; - selmon->seltags ^= 1; /* toggle sel tagset */ +void +view(const Arg* arg) +{ + if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags]) + return; + selmon->seltags ^= 1; /* toggle selcli tagset */ if (arg->ui & TAGMASK) selmon->tagset[selmon->seltags] = arg->ui & TAGMASK; focus(NULL); arrange(selmon); } -pid_t winpid(Window w) { - pid_t result = 0; - - xcb_res_client_id_spec_t spec = { 0 }; - spec.client = w; - spec.mask = XCB_RES_CLIENT_ID_MASK_LOCAL_CLIENT_PID; +pid_t +winpid(Window w) +{ + xcb_res_client_id_spec_t spec; + xcb_res_query_client_ids_cookie_t c; + xcb_generic_error_t *e; + xcb_res_query_client_ids_reply_t *r; + xcb_res_client_id_value_iterator_t i; + pid_t result; + ulong *t; - xcb_generic_error_t* e = NULL; - xcb_res_query_client_ids_cookie_t c = xcb_res_query_client_ids(xcon, 1, &spec); - xcb_res_query_client_ids_reply_t* r = xcb_res_query_client_ids_reply(xcon, c, &e); + spec.client = w; + spec.mask = XCB_RES_CLIENT_ID_MASK_LOCAL_CLIENT_PID; + c = xcb_res_query_client_ids(xcon, 1, &spec); + e = NULL; + r = xcb_res_query_client_ids_reply(xcon, c, &e); - if (!r) return (pid_t)0; + if (!r) return 0; - xcb_res_client_id_value_iterator_t i = xcb_res_query_client_ids_ids_iterator(r); + i = xcb_res_query_client_ids_ids_iterator(r); + result = 0; for (; i.rem; xcb_res_client_id_value_next(&i)) { spec = i.data->spec; if (spec.mask & XCB_RES_CLIENT_ID_MASK_LOCAL_CLIENT_PID) { - uint32_t* t = xcb_res_client_id_value_value(i.data); - result = *t; + t = (ulong*)xcb_res_client_id_value_value(i.data); + result = *t; break; } } @@ -1948,57 +2088,57 @@ pid_t winpid(Window w) { return result; } -pid_t getparentprocess(pid_t p) { - unsigned int v = 0; +pid_t +getparentprocess(pid_t p) +{ + FILE *f; + char buf[256]; + uint v; - FILE* f; - char buf[256]; - snprintf(buf, sizeof(buf) - 1, "/proc/%u/stat", (unsigned)p); - - if (!(f = fopen(buf, "r"))) return (pid_t)0; - - if (fscanf(f, "%*u %*s %*c %u", (unsigned*)&v) != 1) v = (pid_t)0; + snprintf(buf, sizeof(buf) - 1, "/proc/%u/stat", (uint)p); + if (!(f = fopen(buf, "r"))) return 0; + v = 0; ++ fscanf(f, "%*u %*s %*c %u", &v); fclose(f); return (pid_t)v; } -int isdescprocess(pid_t p, pid_t c) { - while (p != c && c != 0) c = getparentprocess(c); - +int +isdescprocess(pid_t p, pid_t c) +{ + for (;p != c && c; c = getparentprocess(c)); return (int)c; } -struct Client* termforwin(const struct Client* w) { - struct Client* c; - struct Monitor* m; +Client* +termforwin(const Client* w) +{ + Client* c; + Monitor* m; if (!w->pid || w->isterminal) return NULL; - for (m = mons; m; m = m->next) { - for (c = m->clients; c; c = c->next) { + for (m = mons; m; m = m->next) + for (c = m->clients; c; c = c->next) if (c->isterminal && !c->swallowing && c->pid && isdescprocess(c->pid, w->pid)) return c; - } - } - return NULL; } -struct Client* swallowingclient(Window w) { - struct Client* c; - struct Monitor* m; +Client* +swallowingclient(Window w) +{ + Client* c; + Monitor* m; - for (m = mons; m; m = m->next) { - for (c = m->clients; c; c = c->next) { + for (m = mons; m; m = m->next) + for (c = m->clients; c; c = c->next) if (c->swallowing && c->swallowing->win == w) return c; - } - } - return NULL; } -struct Client* wintoclient(Window w) { - struct Client* c; - struct Monitor* m; +Client* wintoclient(Window w) { + Client* c; + Monitor* m; for (m = mons; m; m = m->next) for (c = m->clients; c; c = c->next) @@ -2006,10 +2146,10 @@ struct Client* wintoclient(Window w) { return NULL; } -struct Monitor* wintomon(Window w) { - int x, y; - struct Client* c; - struct Monitor* m; +Monitor* wintomon(Window w) { + int x, y; + Client* c; + Monitor* m; if (w == root && getrootptr(&x, &y)) return recttomon(x, y, 1, 1); for (m = mons; m; m = m->next) @@ -2021,48 +2161,59 @@ struct Monitor* wintomon(Window w) { /* There's no way to check accesses to destroyed windows, thus those cases are * ignored (especially on UnmapNotify's). Other types of errors call Xlibs * default error handler, which may call exit. */ -int xerror(Display* dpy, XErrorEvent* ee) { +int +xerror(Display* dpy, XErrorEvent* error_event) +{ if ( - ee->error_code == BadWindow || (ee->request_code == X_SetInputFocus && ee->error_code == BadMatch) || - (ee->request_code == X_PolyText8 && ee->error_code == BadDrawable) || - (ee->request_code == X_PolyFillRectangle && ee->error_code == BadDrawable) || - (ee->request_code == X_PolySegment && ee->error_code == BadDrawable) || - (ee->request_code == X_ConfigureWindow && ee->error_code == BadMatch) || - (ee->request_code == X_GrabButton && ee->error_code == BadAccess) || - (ee->request_code == X_GrabKey && ee->error_code == BadAccess) || - (ee->request_code == X_CopyArea && ee->error_code == BadDrawable)) + error_event->error_code == BadWindow + || (error_event->request_code == X_SetInputFocus && error_event->error_code == BadMatch) + || (error_event->request_code == X_PolyText8 && error_event->error_code == BadDrawable) + || (error_event->request_code == X_PolyFillRectangle && error_event->error_code == BadDrawable) + || (error_event->request_code == X_PolySegment && error_event->error_code == BadDrawable) + || (error_event->request_code == X_ConfigureWindow && error_event->error_code == BadMatch) + || (error_event->request_code == X_GrabButton && error_event->error_code == BadAccess) + || (error_event->request_code == X_GrabKey && error_event->error_code == BadAccess) + || (error_event->request_code == X_CopyArea && error_event->error_code == BadDrawable) + ) return 0; - fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n", ee->request_code, ee->error_code); - return xerrorxlib(dpy, ee); /* may call exit */ + fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n", error_event->request_code, error_event->error_code); + return xerrorxlib(dpy, error_event); /* may call exit */ } -int xerrordummy(Display* dpy, XErrorEvent* ee) { +int +xerrordummy(Display* dpy, XErrorEvent* error_event) { return 0; } /* Startup Error handler to check if another window manager * is already running. */ -int xerrorstart(Display* dpy, XErrorEvent* ee) { +int +xerrorstart(Display* dpy, XErrorEvent* error_event) +{ die("dwm: another window manager is already running"); return -1; } -void zoom(const union Arg* arg) { - struct Client* c = selmon->sel; +void +zoom(const Arg* arg) +{ + Client* c = selmon->selcli; - if (!selmon->lt[selmon->sellt]->arrange || (selmon->sel && selmon->sel->isfloating)) return; + if (!selmon->lt[selmon->sellt]->arrange || (selmon->selcli && selmon->selcli->isfloating)) return; if (c == nexttiled(selmon->clients)) if (!c || !(c = nexttiled(c->next))) return; pop(c); } -int main(int argc, char* argv[]) { - if (argc == 2 && !strcmp("-v", argv[1])) die("dwm-" VERSION); - else if (argc != 1) - die("usage: dwm [-v]"); - if (!setlocale(LC_CTYPE, "") || !XSupportsLocale()) fputs("warning: no locale support\n", stderr); - if (!(dpy = XOpenDisplay(NULL))) die("dwm: cannot open display"); - if (!(xcon = XGetXCBConnection(dpy))) die("dwm: cannot get xcb connection\n"); +int +main(int argc, char* argv[]) +{ + if (!setlocale(LC_CTYPE, "") || !XSupportsLocale()) + fputs("warning: no locale support\n", stderr); + if (!(dpy = XOpenDisplay(NULL))) + die("dwm: cannot open dpy"); + if (!(xcon = XGetXCBConnection(dpy))) + die("dwm: cannot get xcb connection\n"); checkotherwm(); setup(); scan(); diff --git a/make b/make @@ -1,3 +0,0 @@ -#!/bin/sh - -sudo make clean install diff --git a/util.c b/util.c @@ -1,4 +1,3 @@ -/* See LICENSE file for copyright and license details. */ #include <stdarg.h> #include <stdio.h> #include <stdlib.h> @@ -6,7 +5,9 @@ #include "util.h" -void* ecalloc(size_t nmemb, size_t size) { +void* +ecalloc(size_t nmemb, size_t size) +{ void* p; if (!(p = calloc(nmemb, size))) @@ -14,19 +15,19 @@ void* ecalloc(size_t nmemb, size_t size) { return p; } -void die(const char* fmt, ...) { +void +die(const char* fmt, ...) +{ va_list ap; va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); - if (fmt[0] && fmt[strlen(fmt) - 1] == ':') { fputc(' ', stderr); perror(NULL); } else { fputc('\n', stderr); } - exit(1); } diff --git a/util.h b/util.h @@ -2,5 +2,9 @@ #define MIN(A, B) ((A) < (B) ? (A) : (B)) #define BETWEEN(X, A, B) ((A) <= (X) && (X) <= (B)) +typedef unsigned char uchar; +typedef unsigned int uint; +typedef unsigned long ulong; + void die(const char* fmt, ...); void* ecalloc(size_t nmemb, size_t size);