smartborders - dwm - dynamic window manager HTML git clone https://git.parazyd.org/dwm DIR Log DIR Files DIR Refs DIR README DIR LICENSE --- DIR commit ab128d39306091645ffa318cd8baab08d1128bd8 DIR parent 5581ad51344486680d377831ab21dd1d0190b2d5 HTML Author: parazyd <parazyd@dyne.org> Date: Sun, 24 Apr 2022 11:50:18 +0200 smartborders Diffstat: M dwm.c | 80 +++++++++++++++++++------------ 1 file changed, 49 insertions(+), 31 deletions(-) --- DIR diff --git a/dwm.c b/dwm.c @@ -166,7 +166,7 @@ struct Systray { /* function declarations */ static void applyrules(Client *c); -static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact); +static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int *bw, int interact); static void arrange(Monitor *m); static void arrangemon(Monitor *m); static void attach(Client *c); @@ -215,9 +215,9 @@ static void propertynotify(XEvent *e); static void quit(const Arg *arg); static Monitor *recttomon(int x, int y, int w, int h); static void removesystrayicon(Client *i); -static void resize(Client *c, int x, int y, int w, int h, int interact); +static void resize(Client *c, int x, int y, int w, int h, int bw, int interact); static void resizebarwin(Monitor *m); -static void resizeclient(Client *c, int x, int y, int w, int h); +static void resizeclient(Client *c, int x, int y, int w, int h, int bw); static void resizemouse(const Arg *arg); static void resizerequest(XEvent *e); static void restack(Monitor *m); @@ -359,7 +359,7 @@ applyrules(Client *c) } int -applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact) +applysizehints(Client *c, int *x, int *y, int *w, int *h, int *bw, int interact) { int baseismin; Monitor *m = c->mon; @@ -372,18 +372,18 @@ applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact) *x = sw - WIDTH(c); if (*y > sh) *y = sh - HEIGHT(c); - if (*x + *w + 2 * c->bw < 0) + if (*x + *w + 2 * *bw < 0) *x = 0; - if (*y + *h + 2 * c->bw < 0) + if (*y + *h + 2 * *bw < 0) *y = 0; } else { if (*x >= m->wx + m->ww) *x = m->wx + m->ww - WIDTH(c); if (*y >= m->wy + m->wh) *y = m->wy + m->wh - HEIGHT(c); - if (*x + *w + 2 * c->bw <= m->wx) + if (*x + *w + 2 * *bw <= m->wx) *x = m->wx; - if (*y + *h + 2 * c->bw <= m->wy) + if (*y + *h + 2 * *bw <= m->wy) *y = m->wy; } if (*h < bh) @@ -423,7 +423,7 @@ applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact) if (c->maxh) *h = MIN(*h, c->maxh); } - return *x != c->x || *y != c->y || *w != c->w || *h != c->h; + return *x != c->x || *y != c->y || *w != c->w || *h != c->h || *bw != c->bw; } void @@ -443,9 +443,17 @@ arrange(Monitor *m) void arrangemon(Monitor *m) { + Client *c; + strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof m->ltsymbol); if (m->lt[m->sellt]->arrange) m->lt[m->sellt]->arrange(m); + else + /* <>< case; rather than providing an arrange function and upsetting + * other logic that tests for its presence, simply add borders here */ + for (c = selmon->clients; c; c = c->next) + if (ISVISIBLE(c) && c->bw == 0) + resize(c, c->x, c->y, c->w - 2*borderpx, c->h - 2*borderpx, borderpx, 0); } void @@ -686,7 +694,7 @@ configurenotify(XEvent *e) for (m = mons; m; m = m->next) { for (c = m->clients; c; c = c->next) if (c->isfullscreen) - resizeclient(c, m->mx, m->my, m->mw, m->mh); + resizeclient(c, m->mx, m->my, m->mw, m->mh, 0); resizebarwin(m); } focus(NULL); @@ -1301,7 +1309,7 @@ monocle(Monitor *m) 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); + resize(c, m->wx, m->wy, m->ww, m->wh, 0, 0); } void @@ -1369,7 +1377,7 @@ movemouse(const Arg *arg) && (abs(nx - c->x) > snap || abs(ny - c->y) > snap)) togglefloating(NULL); if (!selmon->lt[selmon->sellt]->arrange || c->isfloating) - resize(c, nx, ny, c->w, c->h, 1); + resize(c, nx, ny, c->w, c->h, c->bw, 1); break; } } while (ev.type != ButtonRelease); @@ -1479,10 +1487,10 @@ removesystrayicon(Client *i) } void -resize(Client *c, int x, int y, int w, int h, int interact) +resize(Client *c, int x, int y, int w, int h, int bw, int interact) { - if (applysizehints(c, &x, &y, &w, &h, interact)) - resizeclient(c, x, y, w, h); + if (applysizehints(c, &x, &y, &w, &h, &bw, interact)) + resizeclient(c, x, y, w, h, bw); } void @@ -1494,7 +1502,7 @@ resizebarwin(Monitor *m) { } void -resizeclient(Client *c, int x, int y, int w, int h) +resizeclient(Client *c, int x, int y, int w, int h, int bw) { XWindowChanges wc; @@ -1502,7 +1510,7 @@ resizeclient(Client *c, int x, int y, int w, int h) c->oldy = c->y; c->y = wc.y = y; c->oldw = c->w; c->w = wc.width = w; c->oldh = c->h; c->h = wc.height = h; - wc.border_width = c->bw; + c->oldbw = c->bw; c->bw = wc.border_width = bw; XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc); configure(c); XSync(dpy, False); @@ -1551,7 +1559,7 @@ resizemouse(const Arg *arg) togglefloating(NULL); } if (!selmon->lt[selmon->sellt]->arrange || c->isfloating) - resize(c, c->x, c->y, nw, nh, 1); + resize(c, c->x, c->y, nw, nh, c->bw, 1); break; } } while (ev.type != ButtonRelease); @@ -1722,22 +1730,20 @@ setfullscreen(Client *c, int fullscreen) 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); + resizeclient(c, c->mon->mx, c->mon->my, c->mon->mw, c->mon->mh, 0); 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); + c->bw = c->oldbw; + resizeclient(c, c->x, c->y, c->w, c->h, c->bw); arrange(c->mon); } } @@ -1972,13 +1978,18 @@ tagmon(const Arg *arg) void col(Monitor *m) { - unsigned int i, n, h, w, x, y, mw; + unsigned int i, n, h, w, x, y, mw, bw; Client *c; for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); if (n == 0) return; + if (n == 1) + bw = 0; + else + bw = borderpx; + if (n > m->nmaster) mw = m->nmaster ? m->ww * m->mfact : 0; else @@ -1986,11 +1997,11 @@ col(Monitor *m) for (i = x = y = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) if (i < m->nmaster) { w = (mw - x) / (MIN(n, m->nmaster) - i); - resize(c, x + m->wx, m->wy, w - (2 * c->bw), m->wh - (2 * c->bw), 0); + resize(c, x + m->wx, m->wy, w - (2 * c->bw), m->wh - (2 * c->bw), bw, 0); x += WIDTH(c); } else { h = (m->wh - y) / (n - i); - resize(c, x + m->wx, m->wy + y, m->ww - x - (2 * c->bw), h - (2 * c->bw), 0); + resize(c, x + m->wx, m->wy + y, m->ww - x - (2 * c->bw), h - (2 * c->bw), bw, 0); y += HEIGHT(c); } } @@ -1998,13 +2009,18 @@ col(Monitor *m) void tile(Monitor *m) { - unsigned int i, n, h, mw, my, ty; + unsigned int i, n, h, mw, my, ty, bw; Client *c; for (n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), n++); if (n == 0) return; + if (n == 1) + bw = 0; + else + bw = borderpx; + if (n > m->nmaster) mw = m->nmaster ? m->ww * m->mfact : 0; else @@ -2012,12 +2028,12 @@ tile(Monitor *m) for (i = my = ty = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) if (i < m->nmaster) { h = (m->wh - my) / (MIN(n, m->nmaster) - i); - resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), 0); + resize(c, m->wx, m->wy + my, mw - 2*bw, h - 2*bw, bw, 0); if (my + HEIGHT(c) < m->wh) my += HEIGHT(c); } else { h = (m->wh - ty) / (n - i); - resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), 0); + resize(c, m->wx + mw, m->wy + ty, m->ww - mw - 2*bw, h - 2*bw, bw, 0); if (ty + HEIGHT(c) < m->wh) ty += HEIGHT(c); } @@ -2053,7 +2069,9 @@ togglefloating(const Arg *arg) 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); + selmon->sel->w - 2 * (borderpx - selmon->sel->bw), + selmon->sel->h - 2 * (borderpx - selmon->sel->bw), + borderpx, 0); arrange(selmon); } @@ -2403,7 +2421,7 @@ updatesystrayicongeom(Client *i, int w, int h) i->w = w; else i->w = (int) ((float)bh * ((float)w / (float)h)); - applysizehints(i, &(i->x), &(i->y), &(i->w), &(i->h), False); + applysizehints(i, &(i->x), &(i->y), &(i->w), &(i->h), &(i->bw), False); /* force icons into the systray dimensions if they don't want to */ if (i->h > bh) { if (i->w == i->h)