[hackers] [tabbed][PATCH] Fixed crash when window height was less or equal to bar height

From: <mikau_AT_aaathats3as.com>
Date: Tue, 12 May 2020 17:09:01 +0200

From a29a0142ede7ea8ae7cd2fad351789512789ddef Mon Sep 17 00:00:00 2001
From: Mikau <mikau_AT_aaathats3as.com>
Date: Tue, 12 May 2020 15:35:48 +0200
Subject: [tabbed][PATCH] Fixed crash when window height was less or equal to
 bar height
To: hackers_AT_suckless.org

When resizing, the embedded client is being resized to (height = wh - bh),
which is (<= 0) if (wh <= bh). This generates a
BadValue Error leading to a crash.
This patch fixes that by hiding the tab bar if the window height is too
small, and also sets a min_height WM hint to prevent that situation from
happening in the first place.
---
 tabbed.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/tabbed.c b/tabbed.c
index ff3ada0..d1f087b 100644
--- a/tabbed.c
+++ b/tabbed.c
_AT_@ -152,7 +152,7 @@ static void (*handler[LASTEvent]) (const XEvent *) = {
 	[MapRequest] = maprequest,
 	[PropertyNotify] = propertynotify,
 };
-static int bh, wx, wy, ww, wh;
+static int bh, obh, wx, wy, ww, wh;
 static unsigned int numlockmask;
 static Bool running = True, nextfocus, doinitspawn = True,
             fillagain = False, closelastclient = False,
_AT_@ -256,6 +256,16 @@ configurenotify(const XEvent *e)
 		XFreePixmap(dpy, dc.drawable);
 		dc.drawable = XCreatePixmap(dpy, root, ww, wh,
 		              DefaultDepth(dpy, screen));
+
+		if(!obh && (wh <= bh)) {
+			obh = bh;
+			bh = 0;
+		}
+		else if (!bh && (wh > obh)) {
+			bh = obh;
+			obh = 0;
+		}
+
 		if (sel > -1)
 			resize(sel, ww, wh - bh);
 		XSync(dpy, False);
_AT_@ -872,7 +882,7 @@ resize(int c, int w, int h)
 	XWindowChanges wc;
 
 	ce.x = 0;
-	ce.y = bh;
+	ce.y = wc.y = bh;
 	ce.width = wc.width = w;
 	ce.height = wc.height = h;
 	ce.type = ConfigureNotify;
_AT_@ -883,7 +893,7 @@ resize(int c, int w, int h)
 	ce.override_redirect = False;
 	ce.border_width = 0;
 
-	XConfigureWindow(dpy, clients[c]->win, CWWidth | CWHeight, &wc);
+	XConfigureWindow(dpy, clients[c]->win, CWY | CWWidth | CWHeight, &wc);
 	XSendEvent(dpy, clients[c]->win, False, StructureNotifyMask,
 	           (XEvent *)&ce);
 }
_AT_@ -1046,9 +1056,10 @@ setup(void)
 
 	size_hint = XAllocSizeHints();
 	if (!isfixed) {
-		size_hint->flags = PSize;
+		size_hint->flags = PSize | PMinSize;
 		size_hint->height = wh;
 		size_hint->width = ww;
+		size_hint->min_height = bh + 1;
 	} else {
 		size_hint->flags = PMaxSize | PMinSize;
 		size_hint->min_width = size_hint->max_width = ww;
-- 
2.26.2
Received on Tue May 12 2020 - 17:09:01 CEST

This archive was generated by hypermail 2.3.0 : Tue May 12 2020 - 17:12:39 CEST