dwm

my dwm build
Log | Files | Refs | LICENSE

commit 53ffa3196dab82e0a3db1d93a21e25740c37a3a1
parent 2fd7cc32b0f02583c1b6951a308df609cf24f02f
Author: ssnf <ssnf@ssnf.xyz>
Date:   Tue,  4 Aug 2020 12:47:51 +0000

general cleanup

Diffstat:
M.config | 4++--
Dconfig.def.h | 119-------------------------------------------------------------------------------
Mconfig.h | 13++++++-------
Mconfig.mk | 2--
Mdwm.c | 511++++++++++++++++++++++++++++++++++++++-----------------------------------------
Dfibonacci.c | 51---------------------------------------------------
6 files changed, 256 insertions(+), 444 deletions(-)

diff --git a/.config b/.config @@ -1,2 +1,2 @@ -let g:ale_c_gcc_options = '-Wall -Wextra -pedantic -std=c89 ' -let g:ale_cpp_gcc_options = '-Wall -Wextra -pedantic -std=c89' +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/config.def.h b/config.def.h @@ -1,119 +0,0 @@ -/* 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 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 }, -}; - -/* tagging */ -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 - */ - /* class instance title tags mask isfloating monitor */ - { "Gimp", NULL, NULL, 0, 1, -1 }, - { "Firefox", NULL, NULL, 1 << 8, 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 */ - -#include "fibonacci.c" -static const Layout layouts[] = { - /* symbol arrange function */ - { "[\\]", dwindle }, /* first entry is default */ - { "[M]=", centeredmaster }, - { NULL, NULL }, -}; - -/* key definitions */ -#define MODKEY Mod4Mask -#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} }, - -/* 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 }; - -#include <X11/XF86keysym.h> -static Key keys[] = { - /* modifier key function argument */ - { MODKEY, XK_d, spawn, {.v = dmenucmd } }, - { MODKEY, XK_Return, spawn, {.v = termcmd } }, - { MODKEY, XK_b, togglebar, {0} }, - { MODKEY, XK_j, focusstack, {.i = +1 } }, - { MODKEY, XK_k, focusstack, {.i = -1 } }, - { MODKEY, XK_i, incnmaster, {.i = +1 } }, - { MODKEY, XK_u, incnmaster, {.i = -1 } }, - { MODKEY, XK_h, setmfact, {.f = -0.05} }, - { MODKEY, XK_l, setmfact, {.f = +0.05} }, - { MODKEY, XK_space, zoom, {0} }, - { MODKEY, XK_Tab, view, {0} }, - { MODKEY, XK_q, killclient, {0} }, - { MODKEY, XK_bracketright, 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, XK_p, spawn, SHCMD("push-video") }, - - { 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)") }, -}; - -/* button definitions */ -/* click can be ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */ -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, 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} }, -}https://www.youtube.com/watch?v=NVWVHiLx1sU; diff --git a/config.h b/config.h @@ -37,11 +37,9 @@ 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 */ -#include "fibonacci.c" -static const Layout layouts[] = { +static const struct Layout layouts[] = { /* symbol arrange function */ - { "[\\]", dwindle }, /* first entry is default */ - { "[M]=", centeredmaster }, + { "[\\]", fibonacci }, /* first entry is default */ { NULL, NULL }, }; @@ -60,12 +58,14 @@ static const Layout layouts[] = { 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 }; #include <X11/XF86keysym.h> -static Key keys[] = { +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 } }, @@ -98,7 +98,6 @@ static Key keys[] = { { 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_w, spawn, SHCMD("$BROWSER") }, { MODKEY, XK_n, spawn, SHCMD("st -e newsboat") }, { MODKEY, XK_m, spawn, SHCMD("st -e neomutt") }, { MODKEY, XK_i, spawn, SHCMD("st -e htop") }, @@ -114,7 +113,7 @@ static Key keys[] = { /* button definitions */ /* click can be ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, ClkClientWin, or ClkRootWin */ -static Button buttons[] = { +static struct Button buttons[] = { /* click event mask button function argument */ { ClkLtSymbol, 0, Button1, setlayout, {0} }, { ClkLtSymbol, 0, Button3, setlayout, {.v = &layouts[2]} }, diff --git a/config.mk b/config.mk @@ -17,8 +17,6 @@ X11LIB = /usr/X11R6/lib # freetype FREETYPELIBS = -lfontconfig -lXft FREETYPEINC = /usr/include/freetype2 -# OpenBSD (uncomment) -#FREETYPEINC = ${X11INC}/freetype2 # includes and libs INCS = -I${X11INC} -I${FREETYPEINC} diff --git a/dwm.c b/dwm.c @@ -82,23 +82,21 @@ enum { /* clicks */ ClkLast }; -typedef union { +union Arg{ int i; unsigned int ui; float f; const void* v; -} Arg; +}; -typedef struct { +struct Button { unsigned int click; unsigned int mask; unsigned int button; - void (*func)(const Arg* arg); - const Arg arg; -} Button; + void (*func)(const union Arg* arg); + const union Arg arg; +}; -typedef struct Monitor Monitor; -typedef struct Client Client; struct Client { char name[256]; float mina, maxa; @@ -109,24 +107,24 @@ struct Client { unsigned int tags; int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen, isterminal, noswallow; pid_t pid; - Client* next; - Client* snext; - Client* swallowing; - Monitor* mon; + struct Client* next; + struct Client* snext; + struct Client* swallowing; + struct Monitor* mon; Window win; }; -typedef struct { +struct Key { unsigned int mod; KeySym keysym; - void (*func)(const Arg*); - const Arg arg; -} Key; + void (*func)(const union Arg*); + const union Arg arg; +}; -typedef struct { +struct Layout { const char* symbol; - void (*arrange)(Monitor*); -} Layout; + void (*arrange)(struct Monitor*); +}; struct Monitor { char ltsymbol[16]; @@ -141,12 +139,12 @@ struct Monitor { unsigned int tagset[2]; int showbar; int topbar; - Client* clients; - Client* sel; - Client* stack; - Monitor* next; + struct Client* clients; + struct Client* sel; + struct Client* stack; + struct Monitor* next; Window barwin; - const Layout* lt[2]; + const struct Layout* lt[2]; }; typedef struct { @@ -161,105 +159,105 @@ typedef struct { } Rule; /* function declarations */ -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 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 centeredmaster(Monitor* m); static void checkotherwm(void); static void cleanup(void); -static void cleanupmon(Monitor* mon); +static void cleanupmon(struct Monitor* mon); static void clientmessage(XEvent* e); -static void configure(Client* c); +static void configure(struct Client* c); static void configurenotify(XEvent* e); static void configurerequest(XEvent* e); -static Monitor* createmon(void); -static void cyclelayout(const Arg* arg); +static struct Monitor* createmon(void); +static void cyclelayout(const union Arg* arg); 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 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 focus(Client* c); +static void fibonacci(struct Monitor* mon); +static void focus(struct 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 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(Client* c, int focused); +static void grabbuttons(struct Client* c, int focused); static void grabkeys(void); -static void incnmaster(const Arg* arg); +static void incnmaster(const union Arg* arg); static void keypress(XEvent* e); -static void killclient(const Arg* arg); +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 Arg* arg); -static Client* nexttiled(Client* c); -static void pop(Client*); +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 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 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(Client* c, Atom proto); -static void sendmon(Client* c, Monitor* m); +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(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 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(Client* c, int urg); -static void showhide(Client* c); +static void seturgent(struct Client* c, int urg); +static void showhide(struct 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 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(Monitor* m); +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(Client* c); +static void updatesizehints(struct 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 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 Arg* arg); +static void zoom(const union Arg* arg); 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 struct Client* swallowingclient(Window w); +static struct Client* termforwin(const struct Client* c); static pid_t winpid(Window w); /* variables */ @@ -292,7 +290,7 @@ static Cur* cursor[CurLast]; static Clr** scheme; static Display* dpy; static Drw* drw; -static Monitor *mons, *selmon; +static struct Monitor *mons, *selmon; static Window root, wmcheckwin; static xcb_connection_t* xcon; @@ -306,8 +304,8 @@ struct NumTags { }; /* function implementations */ -void swallow(Client* p, Client* c) { - Client* s; +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; @@ -335,7 +333,7 @@ void swallow(Client* p, Client* c) { updateclientlist(); } -void unswallow(Client* c) { +void unswallow(struct Client* c) { c->win = c->swallowing->win; free(c->swallowing); @@ -354,11 +352,11 @@ void unswallow(Client* c) { arrange(c->mon); } -void applyrules(Client* c) { +void applyrules(struct Client* c) { const char* class, *instance; unsigned int i; const Rule* r; - Monitor* m; + struct Monitor* m; XClassHint ch = { NULL, NULL }; /* rule matching */ @@ -388,9 +386,9 @@ void applyrules(Client* c) { c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags]; } -int applysizehints(Client* c, int* x, int* y, int* w, int* h, int interact) { +int applysizehints(struct Client* c, int* x, int* y, int* w, int* h, int interact) { int baseismin; - Monitor* m = c->mon; + struct Monitor* m = c->mon; /* set minimum possible */ *w = MAX(1, *w); @@ -437,7 +435,7 @@ int applysizehints(Client* c, int* x, int* y, int* w, int* h, int interact) { return *x != c->x || *y != c->y || *w != c->w || *h != c->h; } -void arrange(Monitor* m) { +void arrange(struct Monitor* m) { if (m) showhide(m->stack); else for (m = mons; m; m = m->next) showhide(m->stack); @@ -448,26 +446,26 @@ void arrange(Monitor* m) { for (m = mons; m; m = m->next) arrangemon(m); } -void arrangemon(Monitor* m) { +void arrangemon(struct Monitor* m) { strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof m->ltsymbol); if (m->lt[m->sellt]->arrange) m->lt[m->sellt]->arrange(m); } -void attach(Client* c) { +void attach(struct Client* c) { c->next = c->mon->clients; c->mon->clients = c; } -void attachstack(Client* c) { +void attachstack(struct Client* c) { c->snext = c->mon->stack; c->mon->stack = c; } void buttonpress(XEvent* e) { unsigned int i, x, click; - Arg arg = { 0 }; - Client* c; - Monitor* m; + union Arg arg = { 0 }; + struct Client* c; + struct Monitor* m; XButtonPressedEvent* ev = &e->xbutton; click = ClkRootWin; @@ -504,56 +502,6 @@ void buttonpress(XEvent* e) { buttons[i].func(click == ClkTagBar && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg); } -void centeredmaster(Monitor* m) { - unsigned int i, n, h, mw, mx, my, oty, ety, tw; - Client* c; - - /* count number of clients in the selected monitor */ - for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++) - ; - if (n == 0) return; - - /* initialize areas */ - mw = m->ww; - mx = 0; - my = 0; - tw = mw; - - if (n > m->nmaster) { - /* go mfact box in the center if more than nmaster clients */ - mw = m->nmaster ? m->ww * m->mfact : 0; - tw = m->ww - mw; - - if (n - m->nmaster > 1) { - /* only one client */ - mx = (m->ww - mw) / 2; - tw = (m->ww - mw) / 2; - } - } - - oty = 0; - ety = 0; - for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) - if (i < m->nmaster) { - /* nmaster clients are stacked vertically, in the center - * of the screen */ - h = (m->wh - my) / (MIN(n, m->nmaster) - i); - resize(c, m->wx + mx, m->wy + my, mw - (2 * c->bw), h - (2 * c->bw), 0); - my += HEIGHT(c); - } else { - /* stack clients are stacked vertically */ - if ((i - m->nmaster) % 2) { - h = (m->wh - ety) / ((1 + n - i) / 2); - resize(c, m->wx, m->wy + ety, tw - (2 * c->bw), h - (2 * c->bw), 0); - ety += HEIGHT(c); - } else { - h = (m->wh - oty) / ((1 + n - i) / 2); - resize(c, m->wx + mx + mw, m->wy + oty, tw - (2 * c->bw), h - (2 * c->bw), 0); - oty += HEIGHT(c); - } - } -} - void checkotherwm(void) { xerrorxlib = XSetErrorHandler(xerrorstart); /* this causes an error if some other window manager is running */ @@ -564,9 +512,9 @@ void checkotherwm(void) { } void cleanup(void) { - Arg a = { .ui = ~0 }; - Layout foo = { "", NULL }; - Monitor* m; + union Arg a = { .ui = ~0 }; + struct Layout foo = { "", NULL }; + struct Monitor* m; size_t i; view(&a); @@ -584,8 +532,8 @@ void cleanup(void) { XDeleteProperty(dpy, root, netatom[NetActiveWindow]); } -void cleanupmon(Monitor* mon) { - Monitor* m; +void cleanupmon(struct Monitor* mon) { + struct Monitor* m; if (mon == mons) mons = mons->next; else { @@ -600,7 +548,7 @@ void cleanupmon(Monitor* mon) { void clientmessage(XEvent* e) { XClientMessageEvent* cme = &e->xclient; - Client* c = wintoclient(cme->window); + struct Client* c = wintoclient(cme->window); if (!c) return; if (cme->message_type == netatom[NetWMState]) { @@ -615,7 +563,7 @@ void clientmessage(XEvent* e) { } } -void configure(Client* c) { +void configure(struct Client* c) { XConfigureEvent ce; ce.type = ConfigureNotify; @@ -633,8 +581,8 @@ void configure(Client* c) { } void configurenotify(XEvent* e) { - Monitor* m; - Client* c; + struct Monitor* m; + struct Client* c; XConfigureEvent* ev = &e->xconfigure; int dirty; @@ -658,8 +606,8 @@ void configurenotify(XEvent* e) { } void configurerequest(XEvent* e) { - Client* c; - Monitor* m; + struct Client* c; + struct Monitor* m; XConfigureRequestEvent* ev = &e->xconfigurerequest; XWindowChanges wc; @@ -704,10 +652,10 @@ void configurerequest(XEvent* e) { XSync(dpy, False); } -Monitor* createmon(void) { - Monitor* m; +struct Monitor* createmon(void) { + struct Monitor* m; - m = ecalloc(1, sizeof(Monitor)); + m = ecalloc(1, sizeof(struct Monitor)); m->tagset[0] = m->tagset[1] = 1; m->mfact = mfact; m->nmaster = nmaster; @@ -719,23 +667,23 @@ Monitor* createmon(void) { return m; } -void cyclelayout(const Arg* arg) { - Layout* l; - for (l = (Layout*)layouts; l != selmon->lt[selmon->sellt]; ++l) +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(&((Arg){ .v = (l + 1) })); + if (l->symbol && (l + 1)->symbol) setlayout(&((union Arg){ .v = (l + 1) })); else - setlayout(&((Arg){ .v = layouts })); + setlayout(&((union Arg){ .v = layouts })); } else { - if (l != layouts && (l - 1)->symbol) setlayout(&((Arg){ .v = (l - 1) })); + if (l != layouts && (l - 1)->symbol) setlayout(&((union Arg){ .v = (l - 1) })); else - setlayout(&((Arg){ .v = &layouts[LENGTH(layouts) - 2] })); + setlayout(&((union Arg){ .v = &layouts[LENGTH(layouts) - 2] })); } } void destroynotify(XEvent* e) { - Client* c; + struct Client* c; XDestroyWindowEvent* ev = &e->xdestroywindow; if ((c = wintoclient(ev->window))) unmanage(c, 1); @@ -743,16 +691,16 @@ void destroynotify(XEvent* e) { unmanage(c->swallowing, 1); } -void detach(Client* c) { - Client** tc; +void detach(struct Client* c) { + struct Client** tc; for (tc = &c->mon->clients; *tc && *tc != c; tc = &(*tc)->next) ; *tc = c->next; } -void detachstack(Client* c) { - Client **tc, *t; +void detachstack(struct Client* c) { + struct Client **tc, *t; for (tc = &c->mon->stack; *tc && *tc != c; tc = &(*tc)->snext) ; @@ -765,8 +713,8 @@ void detachstack(Client* c) { } } -Monitor* dirtomon(int dir) { - Monitor* m = NULL; +struct Monitor* dirtomon(int dir) { + struct Monitor* m = NULL; if (dir > 0) { if (!(m = selmon->next)) m = mons; @@ -779,12 +727,12 @@ Monitor* dirtomon(int dir) { return m; } -void drawbar(Monitor* 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; - Client* c; + struct Client* c; /* draw status first so it can be overdrawn by tags later */ if (m == selmon) { /* status is only drawn on selected monitor */ @@ -825,14 +773,14 @@ void drawbar(Monitor* m) { } void drawbars(void) { - Monitor* m; + struct Monitor* m; for (m = mons; m; m = m->next) drawbar(m); } void enternotify(XEvent* e) { - Client* c; - Monitor* m; + struct Client* c; + struct Monitor* m; XCrossingEvent* ev = &e->xcrossing; if ((ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root) return; @@ -847,13 +795,50 @@ void enternotify(XEvent* e) { } void expose(XEvent* e) { - Monitor* m; + struct Monitor* m; XExposeEvent* ev = &e->xexpose; if (ev->count == 0 && (m = wintomon(ev->window))) drawbar(m); } -void focus(Client* c) { +void fibonacci(struct Monitor* mon) { + unsigned int i, n, nx, ny, nw, nh; + struct Client* c; + + for (n = 0, c = nexttiled(mon->clients); c; c = nexttiled(c->next), ++n); + if (n == 0) return; + + nx = mon->wx; + ny = 0; + nw = mon->ww; + nh = mon->wh; + + 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 % 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; + + if (i == 0) { + if (n != 1) nw = mon->ww * mon->mfact; + ny = mon->wy; + } + 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) { if (!c || !ISVISIBLE(c)) for (c = selmon->stack; c && !ISVISIBLE(c); c = c->snext) ; @@ -881,8 +866,8 @@ void focusin(XEvent* e) { if (selmon->sel && ev->window != selmon->sel->win) setfocus(selmon->sel); } -void focusmon(const Arg* arg) { - Monitor* m; +void focusmon(const union Arg* arg) { + struct Monitor* m; if (!mons->next) return; if ((m = dirtomon(arg->i)) == selmon) return; @@ -891,8 +876,8 @@ void focusmon(const Arg* arg) { focus(NULL); } -void focusstack(const Arg* arg) { - Client *c = NULL, *i; +void focusstack(const union Arg* arg) { + struct Client *c = NULL, *i; if (!selmon->sel) return; if (arg->i > sizeof(arg)) return; @@ -915,7 +900,7 @@ void focusstack(const Arg* arg) { } } -Atom getatomprop(Client* c, Atom prop) { +Atom getatomprop(struct Client* c, Atom prop) { int di; unsigned long dl; unsigned char* p = NULL; @@ -974,7 +959,7 @@ int gettextprop(Window w, Atom atom, char* text, unsigned int size) { return 1; } -void grabbuttons(Client* c, int focused) { +void grabbuttons(struct Client* c, int focused) { updatenumlockmask(); { unsigned int i, j; @@ -1006,7 +991,7 @@ void grabkeys(void) { } } -void incnmaster(const Arg* arg) { +void incnmaster(const union Arg* arg) { selmon->nmaster = MAX(selmon->nmaster + arg->i, 0); arrange(selmon); } @@ -1034,7 +1019,7 @@ void keypress(XEvent* e) { keys[i].func(&(keys[i].arg)); } -void killclient(const Arg* arg) { +void killclient(const union Arg* arg) { if (!selmon->sel) return; if (!sendevent(selmon->sel, wmatom[WMDelete])) { XGrabServer(dpy); @@ -1048,11 +1033,11 @@ void killclient(const Arg* arg) { } void manage(Window w, XWindowAttributes* wa) { - Client * c, *t = NULL, *term = NULL; + struct Client * c, *t = NULL, *term = NULL; Window trans = None; XWindowChanges wc; - c = ecalloc(1, sizeof(Client)); + c = ecalloc(1, sizeof(struct Client)); c->win = w; c->pid = winpid(w); /* geometry */ @@ -1123,9 +1108,9 @@ void maprequest(XEvent* e) { if (!wintoclient(ev->window)) manage(ev->window, &wa); } -void monocle(Monitor* m) { +void monocle(struct Monitor* m) { unsigned int n = 0; - Client* c; + struct Client* c; for (c = m->clients; c; c = c->next) if (ISVISIBLE(c)) n++; @@ -1136,8 +1121,8 @@ void monocle(Monitor* m) { } void motionnotify(XEvent* e) { - static Monitor* mon = NULL; - Monitor* m; + static struct Monitor* mon = NULL; + struct Monitor* m; XMotionEvent* ev = &e->xmotion; if (ev->window != root) return; @@ -1149,10 +1134,10 @@ void motionnotify(XEvent* e) { mon = m; } -void movemouse(const Arg* arg) { +void movemouse(const union Arg* arg) { int x, y, ocx, ocy, nx, ny; - Client* c; - Monitor* m; + struct Client* c; + struct Monitor* m; XEvent ev; Time lasttime = 0; @@ -1202,13 +1187,13 @@ void movemouse(const Arg* arg) { } } -Client* nexttiled(Client* c) { +struct Client* nexttiled(struct Client* c) { for (; c && (c->isfloating || !ISVISIBLE(c)); c = c->next) ; return c; } -void pop(Client* c) { +void pop(struct Client* c) { detach(c); attach(c); focus(c); @@ -1216,7 +1201,7 @@ void pop(Client* c) { } void propertynotify(XEvent* e) { - Client* c; + struct Client* c; Window trans; XPropertyEvent* ev = &e->xproperty; @@ -1246,12 +1231,12 @@ void propertynotify(XEvent* e) { } } -void quit(const Arg* arg) { +void quit(const union Arg* arg) { running = 0; } -Monitor* recttomon(int x, int y, int w, int h) { - Monitor *m, *r = selmon; +struct Monitor* recttomon(int x, int y, int w, int h) { + struct Monitor *m, *r = selmon; int a, area = 0; for (m = mons; m; m = m->next) @@ -1262,11 +1247,11 @@ Monitor* recttomon(int x, int y, int w, int h) { return r; } -void resize(Client* c, int x, int y, int w, int h, int interact) { +void resize(struct 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(Client* c, int x, int y, int w, int h) { +void resizeclient(struct Client* c, int x, int y, int w, int h) { XWindowChanges wc; c->oldx = c->x; @@ -1283,10 +1268,10 @@ void resizeclient(Client* c, int x, int y, int w, int h) { XSync(dpy, False); } -void resizemouse(const Arg* arg) { +void resizemouse(const union Arg* arg) { int ocx, ocy, nw, nh; - Client* c; - Monitor* m; + struct Client* c; + struct Monitor* m; XEvent ev; Time lasttime = 0; @@ -1337,8 +1322,8 @@ void resizemouse(const Arg* arg) { } } -void restack(Monitor* m) { - Client* c; +void restack(struct Monitor* m) { + struct Client* c; XEvent ev; XWindowChanges wc; @@ -1394,7 +1379,7 @@ void scan(void) { scanner = 0; } -void sendmon(Client* c, Monitor* m) { +void sendmon(struct Client* c, struct Monitor* m) { if (c->mon == m) return; unfocus(c, 1); detach(c); @@ -1414,13 +1399,13 @@ void setbar(int value) { arrange(selmon); } -void setclientstate(Client* c, long state) { +void setclientstate(struct Client* c, long state) { long data[] = { state, None }; XChangeProperty(dpy, c->win, wmatom[WMState], wmatom[WMState], 32, PropModeReplace, (unsigned char*)data, 2); } -int sendevent(Client* c, Atom proto) { +int sendevent(struct Client* c, Atom proto) { int n; Atom* protocols; int exists = 0; @@ -1442,7 +1427,7 @@ int sendevent(Client* c, Atom proto) { return exists; } -void setfocus(Client* c) { +void setfocus(struct Client* c) { if (!c->neverfocus) { XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); XChangeProperty( @@ -1451,7 +1436,7 @@ void setfocus(Client* c) { sendevent(c, wmatom[WMTakeFocus]); } -void setfullscreen(Client* c, int fullscreen) { +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); @@ -1476,9 +1461,9 @@ void setfullscreen(Client* c, int fullscreen) { } } -void setlayout(const Arg* arg) { +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] = (Layout*)arg->v; + 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); else @@ -1486,7 +1471,7 @@ void setlayout(const Arg* arg) { } /* arg > 1.0 will set mfact absolutely */ -void setmfact(const Arg* arg) { +void setmfact(const union Arg* arg) { float f; if (!arg || !selmon->lt[selmon->sellt]->arrange) return; @@ -1558,7 +1543,7 @@ void setup(void) { focus(NULL); } -void seturgent(Client* c, int urg) { +void seturgent(struct Client* c, int urg) { XWMHints* wmh; c->isurgent = urg; @@ -1568,7 +1553,7 @@ void seturgent(Client* c, int urg) { XFree(wmh); } -void showhide(Client* c) { +void showhide(struct Client* c) { if (!c) return; if (ISVISIBLE(c)) { /* show clients top down */ @@ -1589,7 +1574,7 @@ void sigchld(int unused) { ; } -void spawn(const Arg* arg) { +void spawn(const union Arg* arg) { if (arg->v == dmenucmd) dmenumon[0] = '0' + selmon->num; if (fork() == 0) { if (dpy) close(ConnectionNumber(dpy)); @@ -1601,7 +1586,7 @@ void spawn(const Arg* arg) { } } -void tag(const Arg* arg) { +void tag(const union Arg* arg) { if (selmon->sel && arg->ui & TAGMASK) { selmon->sel->tags = arg->ui & TAGMASK; focus(NULL); @@ -1609,19 +1594,19 @@ void tag(const Arg* arg) { } } -void tagmon(const Arg* arg) { +void tagmon(const union Arg* arg) { if (!selmon->sel || !mons->next) return; sendmon(selmon->sel, dirtomon(arg->i)); } -void togglebar(const Arg* arg) { +void togglebar(const union Arg* arg) { selmon->showbar = !selmon->showbar; updatebarpos(selmon); XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh); arrange(selmon); } -void togglefloating(const Arg* arg) { +void togglefloating(const union Arg* arg) { if (!selmon->sel) return; if (selmon->sel->isfullscreen) /* no support for fullscreen windows */ return; @@ -1630,7 +1615,7 @@ void togglefloating(const Arg* arg) { arrange(selmon); } -void togglefullscr(const Arg* arg) { +void togglefullscr(const union Arg* arg) { if (selmon->sel->isfullscreen) setbar(1); else @@ -1638,7 +1623,7 @@ void togglefullscr(const Arg* arg) { setfullscreen(selmon->sel, !selmon->sel->isfullscreen); } -void toggletag(const Arg* arg) { +void toggletag(const union Arg* arg) { unsigned int newtags; if (!selmon->sel) return; @@ -1650,7 +1635,7 @@ void toggletag(const Arg* arg) { } } -void toggleview(const Arg* arg) { +void toggleview(const union Arg* arg) { unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK); if (newtagset) { @@ -1660,7 +1645,7 @@ void toggleview(const Arg* arg) { } } -void unfocus(Client* c, int setfocus) { +void unfocus(struct Client* c, int setfocus) { if (!c) return; grabbuttons(c, 0); XSetWindowBorder(dpy, c->win, scheme[SchemeNorm][ColBorder].pixel); @@ -1670,8 +1655,8 @@ void unfocus(Client* c, int setfocus) { } } -void unmanage(Client* c, int destroyed) { - Monitor* m = c->mon; +void unmanage(struct Client* c, int destroyed) { + struct Monitor* m = c->mon; XWindowChanges wc; if (c->swallowing) { @@ -1679,7 +1664,7 @@ void unmanage(Client* c, int destroyed) { return; } - Client* s = swallowingclient(c->win); + struct Client* s = swallowingclient(c->win); if (s) { free(s->swallowing); s->swallowing = NULL; @@ -1714,7 +1699,7 @@ void unmanage(Client* c, int destroyed) { } void unmapnotify(XEvent* e) { - Client* c; + struct Client* c; XUnmapEvent* ev = &e->xunmap; if ((c = wintoclient(ev->window))) { @@ -1725,7 +1710,7 @@ void unmapnotify(XEvent* e) { } void updatebars(void) { - Monitor* m; + struct Monitor* m; XSetWindowAttributes wa = { .override_redirect = True, .background_pixmap = ParentRelative, .event_mask = ButtonPressMask | ExposureMask }; @@ -1741,7 +1726,7 @@ void updatebars(void) { } } -void updatebarpos(Monitor* m) { +void updatebarpos(struct Monitor* m) { m->wy = m->my; m->wh = m->mh; if (m->showbar) { @@ -1753,8 +1738,8 @@ void updatebarpos(Monitor* m) { } void updateclientlist() { - Client* c; - Monitor* m; + struct Client* c; + struct Monitor* m; XDeleteProperty(dpy, root, netatom[NetClientList]); for (m = mons; m; m = m->next) @@ -1769,8 +1754,8 @@ int updategeom(void) { #ifdef XINERAMA if (XineramaIsActive(dpy)) { int i, j, n, nn; - Client* c; - Monitor* m; + struct Client* c; + struct Monitor* m; XineramaScreenInfo* info = XineramaQueryScreens(dpy, &nn); XineramaScreenInfo* unique = NULL; @@ -1850,7 +1835,7 @@ void updatenumlockmask(void) { XFreeModifiermap(modmap); } -void updatesizehints(Client* c) { +void updatesizehints(struct Client* c) { long msize; XSizeHints size; @@ -1895,14 +1880,14 @@ void updatestatus(void) { drawbar(selmon); } -void updatetitle(Client* c) { +void updatetitle(struct 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(Client* c) { +void updatewindowtype(struct Client* c) { Atom state = getatomprop(c, netatom[NetWMState]); Atom wtype = getatomprop(c, netatom[NetWMWindowType]); @@ -1910,7 +1895,7 @@ void updatewindowtype(Client* c) { if (wtype == netatom[NetWMWindowTypeDialog]) c->isfloating = 1; } -void updatewmhints(Client* c) { +void updatewmhints(struct Client* c) { XWMHints* wmh; if ((wmh = XGetWMHints(dpy, c->win))) { @@ -1926,7 +1911,7 @@ void updatewmhints(Client* c) { } } -void view(const Arg* arg) { +void view(const union Arg* arg) { if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags]) return; selmon->seltags ^= 1; /* toggle sel tagset */ if (arg->ui & TAGMASK) selmon->tagset[selmon->seltags] = arg->ui & TAGMASK; @@ -1983,9 +1968,9 @@ int isdescprocess(pid_t p, pid_t c) { return (int)c; } -Client* termforwin(const Client* w) { - Client* c; - Monitor* m; +struct Client* termforwin(const struct Client* w) { + struct Client* c; + struct Monitor* m; if (!w->pid || w->isterminal) return NULL; @@ -1998,9 +1983,9 @@ Client* termforwin(const Client* w) { return NULL; } -Client* swallowingclient(Window w) { - Client* c; - Monitor* m; +struct Client* swallowingclient(Window w) { + struct Client* c; + struct Monitor* m; for (m = mons; m; m = m->next) { for (c = m->clients; c; c = c->next) { @@ -2011,9 +1996,9 @@ Client* swallowingclient(Window w) { return NULL; } -Client* wintoclient(Window w) { - Client* c; - Monitor* m; +struct Client* wintoclient(Window w) { + struct Client* c; + struct Monitor* m; for (m = mons; m; m = m->next) for (c = m->clients; c; c = c->next) @@ -2021,10 +2006,10 @@ Client* wintoclient(Window w) { return NULL; } -Monitor* wintomon(Window w) { +struct Monitor* wintomon(Window w) { int x, y; - Client* c; - Monitor* m; + struct Client* c; + struct Monitor* m; if (w == root && getrootptr(&x, &y)) return recttomon(x, y, 1, 1); for (m = mons; m; m = m->next) @@ -2062,8 +2047,8 @@ int xerrorstart(Display* dpy, XErrorEvent* ee) { return -1; } -void zoom(const Arg* arg) { - Client* c = selmon->sel; +void zoom(const union Arg* arg) { + struct Client* c = selmon->sel; if (!selmon->lt[selmon->sellt]->arrange || (selmon->sel && selmon->sel->isfloating)) return; if (c == nexttiled(selmon->clients)) diff --git a/fibonacci.c b/fibonacci.c @@ -1,51 +0,0 @@ -void fibonacci(Monitor* mon, int s) { - unsigned int i, n, nx, ny, nw, nh; - Client* c; - - for (n = 0, c = nexttiled(mon->clients); c; c = nexttiled(c->next), ++n); - if (n == 0) return; - - nx = mon->wx; - ny = 0; - nw = mon->ww; - nh = mon->wh; - - 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 % 4) == 2 && !s) nx += nw; - else if ((i % 4) == 3 && !s) ny += nh; - } - if ((i % 4) == 0) { - if (s) ny += nh; - else ny -= nh; - } - - else if ((i % 4) == 1) nx += nw; - else if ((i % 4) == 2) ny += nh; - else if ((i % 4) == 3) { - if (s) nx += nw; - else nx -= nw; - } - - if (i == 0) { - if (n != 1) nw = mon->ww * mon->mfact; - ny = mon->wy; - } - else if (i == 1) nw = mon->ww - nw; - i++; - } - resize(c, nx, ny, nw - 2 * c->bw, nh - 2 * c->bw, False); - } -} - -void dwindle(Monitor* mon) { - fibonacci(mon, 1); -} - -void spiral(Monitor* mon) { - fibonacci(mon, 0); -}