dwm

my heavily-patched and customized dwm build
git clone git://git.kocotian.pl/dwm.git
Log | Files | Refs | README | LICENSE

commit 56fed4f66501102eace0f20ec73e44456542c88b
parent 2486485fd23c01ea7c3dae4e112914a9d74957f3
Author: kocotian <kocotian@kocotian.pl>
Date:   Sat, 12 Dec 2020 12:22:11 +0100

attach direction, fixborders

Diffstat:
Mconfig.def.h | 1+
Mconfig.def.h.orig | 7+++++--
Mdrw.c | 2++
Cdrw.c -> drw.c.orig | 0
Mdwm.c | 146++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
Mdwm.c.orig | 147+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
Mpatches/dwm-attachdirection-6.2.diff | 0
Mpatches/dwm-fixborders-6.2.diff | 0
8 files changed, 295 insertions(+), 8 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -45,6 +45,7 @@ static const Rule rules[] = { static const float mfact = 0.55; /* factor of master area size [0.05..0.95] */ static const int nmaster = 1; /* number of clients in master area */ static const int resizehints = 1; /* 1 means respect size hints in tiled resizals */ +static const int attachdirection = 0; /* 0 default, 1 above, 2 aside, 3 below, 4 bottom, 5 top */ static const Layout layouts[] = { /* symbol arrange function */ diff --git a/config.def.h.orig b/config.def.h.orig @@ -49,10 +49,12 @@ static const int resizehints = 1; /* 1 means respect size hints in tiled resi static const Layout layouts[] = { /* symbol arrange function */ { "[]=", tile }, /* first entry is default */ - { "><>", NULL }, /* no layout function means floating behavior */ - { "[M]", monocle }, { "TTT", bstack }, { "===", bstackhoriz }, + { "[M]", monocle }, + { "|M|", centeredmaster }, + { ">M>", centeredfloatingmaster }, + { "><>", NULL }, /* no layout function means floating behavior */ }; /* key definitions */ @@ -81,6 +83,7 @@ static Key keys[] = { { MODKEY, XK_y, setlayout, {.v = &layouts[2]} }, { MODKEY|ShiftMask, XK_y, setlayout, {.v = &layouts[3]} }, { MODKEY, XK_u, setlayout, {.v = &layouts[4]} }, + { MODKEY|ShiftMask, XK_u, setlayout, {.v = &layouts[5]} }, { MODKEY, XK_o, incnmaster, {.i = +1 } }, { MODKEY|ShiftMask, XK_o, incnmaster, {.i = -1 } }, diff --git a/drw.c b/drw.c @@ -203,6 +203,8 @@ drw_clr_create(Drw *drw, Clr *dest, const char *clrname) DefaultColormap(drw->dpy, drw->screen), clrname, dest)) die("error, cannot allocate color '%s'", clrname); + + dest->pixel |= 0xff << 24; } /* Wrapper to create color schemes. The caller has to call free(3) on the diff --git a/drw.c b/drw.c.orig diff --git a/dwm.c b/dwm.c @@ -49,7 +49,8 @@ #define CLEANMASK(mask) (mask & ~(numlockmask|LockMask) & (ShiftMask|ControlMask|Mod1Mask|Mod2Mask|Mod3Mask|Mod4Mask|Mod5Mask)) #define INTERSECT(x,y,w,h,m) (MAX(0, MIN((x)+(w),(m)->wx+(m)->ww) - MAX((x),(m)->wx)) \ * MAX(0, MIN((y)+(h),(m)->wy+(m)->wh) - MAX((y),(m)->wy))) -#define ISVISIBLE(C) ((C->tags & C->mon->tagset[C->mon->seltags])) +#define ISVISIBLEONTAG(C, T) ((C->tags & T)) +#define ISVISIBLE(C) ISVISIBLEONTAG(C, C->mon->tagset[C->mon->seltags]) #define LENGTH(X) (sizeof X / sizeof X[0]) #define MOUSEMASK (BUTTONMASK|PointerMotionMask) #define WIDTH(X) ((X)->w + 2 * (X)->bw) @@ -148,6 +149,11 @@ static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interac static void arrange(Monitor *m); static void arrangemon(Monitor *m); static void attach(Client *c); +static void attachabove(Client *c); +static void attachaside(Client *c); +static void attachbelow(Client *c); +static void attachbottom(Client *c); +static void attachtop(Client *c); static void attachstack(Client *c); static void bstack(Monitor *m); static void bstackhoriz(Monitor *m); @@ -189,6 +195,7 @@ static void maprequest(XEvent *e); static void monocle(Monitor *m); static void motionnotify(XEvent *e); static void movemouse(const Arg *arg); +static Client *nexttagged(Client *c); static Client *nexttiled(Client *c); static void pop(Client *); static void propertynotify(XEvent *e); @@ -417,6 +424,73 @@ attach(Client *c) } void +attachabove(Client *c) +{ + if (c->mon->sel == NULL || c->mon->sel == c->mon->clients || c->mon->sel->isfloating) { + attach(c); + return; + } + + Client *at; + for (at = c->mon->clients; at->next != c->mon->sel; at = at->next); + c->next = at->next; + at->next = c; +} + +void +attachaside(Client *c) { + Client *at = nexttagged(c); + if(!at) { + attach(c); + return; + } + c->next = at->next; + at->next = c; +} + +void +attachbelow(Client *c) +{ + if(c->mon->sel == NULL || c->mon->sel == c || c->mon->sel->isfloating) { + attach(c); + return; + } + c->next = c->mon->sel->next; + c->mon->sel->next = c; +} + +void +attachbottom(Client *c) +{ + Client *below = c->mon->clients; + for (; below && below->next; below = below->next); + c->next = NULL; + if (below) + below->next = c; + else + c->mon->clients = c; +} + +void +attachtop(Client *c) +{ + int n; + Monitor *m = selmon; + Client *below; + + for (n = 1, below = c->mon->clients; + below && below->next && (below->isfloating || !ISVISIBLEONTAG(below, c->tags) || n != m->nmaster); + n = below->isfloating || !ISVISIBLEONTAG(below, c->tags) ? n + 0 : n + 1, below = below->next); + c->next = NULL; + if (below) { + c->next = below->next; + below->next = c; + } + else + c->mon->clients = c; +} + +void attachstack(Client *c) { c->snext = c->mon->stack; @@ -1073,7 +1147,25 @@ manage(Window w, XWindowAttributes *wa) c->isfloating = c->oldstate = trans != None || c->isfixed; if (c->isfloating) XRaiseWindow(dpy, c->win); - attach(c); + switch(attachdirection){ + case 1: + attachabove(c); + break; + case 2: + attachaside(c); + break; + case 3: + attachbelow(c); + break; + case 4: + attachbottom(c); + break; + case 5: + attachtop(c); + break; + default: + attach(c); + } attachstack(c); XChangeProperty(dpy, root, netatom[NetClientList], XA_WINDOW, 32, PropModeAppend, (unsigned char *) &(c->win), 1); @@ -1204,6 +1296,16 @@ movemouse(const Arg *arg) } Client * +nexttagged(Client *c) { + Client *walked = c->mon->clients; + for(; + walked && (walked->isfloating || !ISVISIBLEONTAG(walked, c->tags)); + walked = walked->next + ); + return walked; +} + +Client * nexttiled(Client *c) { for (; c && (c->isfloating || !ISVISIBLE(c)); c = c->next); @@ -1429,7 +1531,25 @@ sendmon(Client *c, Monitor *m) detachstack(c); c->mon = m; c->tags = m->tagset[m->seltags]; /* assign tags of target monitor */ - attach(c); + switch(attachdirection){ + case 1: + attachabove(c); + break; + case 2: + attachaside(c); + break; + case 3: + attachbelow(c); + break; + case 4: + attachbottom(c); + break; + case 5: + attachtop(c); + break; + default: + attach(c); + } attachstack(c); focus(NULL); arrange(NULL); @@ -1953,7 +2073,25 @@ updategeom(void) m->clients = c->next; detachstack(c); c->mon = mons; - attach(c); + switch(attachdirection){ + case 1: + attachabove(c); + break; + case 2: + attachaside(c); + break; + case 3: + attachbelow(c); + break; + case 4: + attachbottom(c); + break; + case 5: + attachtop(c); + break; + default: + attach(c); + } attachstack(c); } if (m == selmon) diff --git a/dwm.c.orig b/dwm.c.orig @@ -149,7 +149,11 @@ static void arrange(Monitor *m); static void arrangemon(Monitor *m); static void attach(Client *c); static void attachstack(Client *c); +static void bstack(Monitor *m); +static void bstackhoriz(Monitor *m); static void buttonpress(XEvent *e); +static void centeredmaster(Monitor *m); +static void centeredfloatingmaster(Monitor *m); static void checkotherwm(void); static void cleanup(void); static void cleanupmon(Monitor *mon); @@ -238,8 +242,6 @@ 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 bstack(Monitor *m); -static void bstackhoriz(Monitor *m); /* variables */ static const char broken[] = "broken"; @@ -2286,3 +2288,144 @@ bstackhoriz(Monitor *m) sfacts -= c->cfact; } } + +void +centeredmaster(Monitor *m) +{ + unsigned int i, n, h, mw, mx, my, oty, ety, tw; + float mfacts = 0, lfacts = 0, rfacts = 0; + 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 < m->nmaster) + mfacts += c->cfact; + else if ((n - m->nmaster) % 2) + lfacts += c->cfact; + else + rfacts += c->cfact; + } + if (n == 0) + return; + if(n == 1){ + c = nexttiled(m->clients); + resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, 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) * (c->cfact / mfacts); + resize(c, m->wx + mx, m->wy + my, mw - 2*c->bw, + h - 2*c->bw, 0); + if(my + HEIGHT(c) < m->mh) + my += HEIGHT(c); + mfacts -= c->cfact; + } else { + /* stack clients are stacked vertically */ + if ((i - m->nmaster) % 2) { + h = (m->wh - ety) * (c->cfact / lfacts); + if(m->nmaster == 0) + resize(c, m->wx, m->wy + ety, tw - 2*c->bw, + h - 2*c->bw, 0); + else + resize(c, m->wx, m->wy + ety, tw - 2*c->bw, + h - 2*c->bw, 0); + if(ety + HEIGHT(c) < m->mh) + ety += HEIGHT(c); + lfacts -= c->cfact; + } else { + h = (m->wh - oty) * (c->cfact / rfacts); + resize(c, m->wx + mx + mw, m->wy + oty, + tw - 2*c->bw, h - 2*c->bw, 0); + if(oty + HEIGHT(c) < m->mh) + oty += HEIGHT(c); + rfacts -= c->cfact; + } + } +} + +void +centeredfloatingmaster(Monitor *m) +{ + unsigned int i, n, w, mh, mw, mx, mxo, my, myo, tx; + float mfacts = 0, sfacts = 0; + 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 < m->nmaster) + mfacts += c->cfact; + else + sfacts += c->cfact; + } + if (n == 0) + return; + if(n == 1){ + c = nexttiled(m->clients); + resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, 0); + return; + } + + /* initialize nmaster area */ + if (n > m->nmaster) { + /* go mfact box in the center if more than nmaster clients */ + if (m->ww > m->wh) { + mw = m->nmaster ? m->ww * m->mfact : 0; + mh = m->nmaster ? m->wh * 0.9 : 0; + } else { + mh = m->nmaster ? m->wh * m->mfact : 0; + mw = m->nmaster ? m->ww * 0.9 : 0; + } + mx = mxo = (m->ww - mw) / 2; + my = myo = (m->wh - mh) / 2; + } else { + /* go fullscreen if all clients are in the master area */ + mh = m->wh; + mw = m->ww; + mx = mxo = 0; + my = myo = 0; + } + + for(i = tx = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) + if (i < m->nmaster) { + /* nmaster clients are stacked horizontally, in the center + * of the screen */ + w = (mw + mxo - mx) * (c->cfact / mfacts); + resize(c, m->wx + mx, m->wy + my, w - 2*c->bw, + mh - 2*c->bw, 0); + if(mx + WIDTH(c) < m->mw) + mx += WIDTH(c); + mfacts -= c->cfact; + } else { + /* stack clients are stacked horizontally */ + w = (m->ww - tx) * (c->cfact / sfacts); + resize(c, m->wx + tx, m->wy, w - 2*c->bw, + m->wh - 2*c->bw, 0); + if(tx + WIDTH(c) < m->mw) + tx += WIDTH(c); + sfacts -= c->cfact; + } +} diff --git a/patches/dwm-attachdirection-6.2.diff b/patches/dwm-attachdirection-6.2.diff diff --git a/patches/dwm-fixborders-6.2.diff b/patches/dwm-fixborders-6.2.diff