2
0
mirror of https://github.com/bakkeby/patches synced 2024-11-17 15:29:53 +00:00
patches/dwm/dwm-centeredsizehints-6.3.diff
2022-01-10 14:53:38 +01:00

80 lines
2.3 KiB
Diff

From b38b2f665b587add976cd9572ad0bfb748f1b143 Mon Sep 17 00:00:00 2001
From: Bakkeby <bakkeby@gmail.com>
Date: Mon, 10 Jan 2022 11:19:17 +0100
Subject: [PATCH] Center clients within their allocated tile based on size
hints
---
dwm.c | 30 ++++++++++++++++++++++++++----
1 file changed, 26 insertions(+), 4 deletions(-)
diff --git a/dwm.c b/dwm.c
index a96f33c..bc7c7ef 100644
--- a/dwm.c
+++ b/dwm.c
@@ -191,6 +191,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);
@@ -1233,6 +1234,7 @@ propertynotify(XEvent *e)
break;
case XA_WM_NORMAL_HINTS:
updatesizehints(c);
+ arrangemon(c->mon);
break;
case XA_WM_HINTS:
updatewmhints(c);
@@ -1270,21 +1272,41 @@ recttomon(int x, int y, int w, int h)
}
void
-resize(Client *c, int x, int y, int w, int h, int interact)
+resize(Client *c, int tx, int ty, int tw, int th, int interact)
{
- if (applysizehints(c, &x, &y, &w, &h, interact))
- resizeclient(c, x, y, w, h);
+ int wh = tw, hh = th;
+ if (applysizehints(c, &tx, &ty, &wh, &hh, interact))
+ resizeclientpad(c, tx, ty, wh, hh, tw, th);
}
+/* 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