From 16e537884f404572272200ae70cefdf8562ff939 Mon Sep 17 00:00:00 2001 From: bakkeby Date: Wed, 27 Jan 2021 14:55:14 +0100 Subject: [PATCH] Center clients within their allocated tile based on size hints --- dwm.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/dwm.c b/dwm.c index 4465af1..d1c84cd 100644 --- a/dwm.c +++ b/dwm.c @@ -190,6 +190,7 @@ 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 resizeclientpad(Client *c, int x, int y, int w, int h, int xpad, int ypad); static void resizemouse(const Arg *arg); static void restack(Monitor *m); static void run(void); @@ -1229,6 +1230,7 @@ propertynotify(XEvent *e) break; case XA_WM_NORMAL_HINTS: updatesizehints(c); + arrangemon(c->mon); break; case XA_WM_HINTS: updatewmhints(c); @@ -1268,19 +1270,41 @@ recttomon(int x, int y, int w, int h) 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); + int xh = x, yh = y, wh = w, hh = h, a; + + a = applysizehints(c, &xh, &yh, &wh, &hh, interact); + if (a || w != wh || h != hh) + resizeclientpad(c, xh, yh, wh, hh, w, h); } +/* This wrapper is just for compatibility with other patches that may call resizeclient */ void resizeclient(Client *c, int x, int y, int w, int h) { - XWindowChanges wc; + resizeclientpad(c, x, y, w, h, w, h); +} +/* This is essentially the resizeclient function renamed with two + * additional parameters, tw and th (for tile width and height). */ +void +resizeclientpad(Client *c, int x, int y, int w, int h, int tw, int th) +{ + XWindowChanges wc; c->oldx = c->x; c->x = wc.x = x; 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; + if (!c->isfloating) { + if (w != tw) { + wc.x += (tw - w) / 2; + c->w = tw; + } + if (h != th) { + wc.y += (th - h) / 2; + c->h = th; + } + } + wc.border_width = c->bw; XConfigureWindow(dpy, c->win, CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc); configure(c); -- 2.19.1