X-Git-Url: https://git.xinqibao.xyz/dwm.git/blobdiff_plain/86953bd68249662b5d7a9ae6741744ab8bf30aa1..36672d0401299a5230b516ca4575365d9f45dd35:/main.c?ds=sidebyside

diff --git a/main.c b/main.c
index 0ae288c..338fed4 100644
--- a/main.c
+++ b/main.c
@@ -20,7 +20,7 @@ int screen, sx, sy, sw, sh, wax, way, waw, wah;
 unsigned int bh, ntags;
 unsigned int bpos = BARPOS;
 unsigned int numlockmask = 0;
-Atom dwmconfig, wmatom[WMLast], netatom[NetLast];
+Atom wmatom[WMLast], netatom[NetLast];
 Bool *seltags;
 Bool selscreen = True;
 Client *clients = NULL;
@@ -42,7 +42,7 @@ cleanup(void) {
 	close(STDIN_FILENO);
 	while(stack) {
 		unban(stack);
-		unmanage(stack, NormalState);
+		unmanage(stack);
 	}
 	if(dc.font.set)
 		XFreeFontSet(dpy, dc.font.set);
@@ -111,6 +111,24 @@ initfont(const char *fontstr) {
 	dc.font.height = dc.font.ascent + dc.font.descent;
 }
 
+static long
+getstate(Window w) {
+	int format, status;
+	long result = -1;
+	unsigned char *p = NULL;
+	unsigned long n, extra;
+	Atom real;
+
+	status = XGetWindowProperty(dpy, w, wmatom[WMState], 0L, 2L, False, wmatom[WMState],
+			&real, &format, &n, &extra, (unsigned char **)&p);
+	if(status != Success)
+		return -1;
+	if(n != 0)
+		result = *p;
+	XFree(p);
+	return result;
+}
+
 static void
 scan(void) {
 	unsigned int i, num;
@@ -123,7 +141,14 @@ scan(void) {
 			if(!XGetWindowAttributes(dpy, wins[i], &wa)
 			|| wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1))
 				continue;
-			if(wa.map_state == IsViewable)
+			if(wa.map_state == IsViewable || getstate(wins[i]) == IconicState)
+				manage(wins[i], &wa);
+		}
+		for(i = 0; i < num; i++) { /* now the transients */
+			if(!XGetWindowAttributes(dpy, wins[i], &wa))
+				continue;
+			if(XGetTransientForHint(dpy, wins[i], &d1)
+			&& (wa.map_state == IsViewable || getstate(wins[i]) == IconicState))
 				manage(wins[i], &wa);
 		}
 	}
@@ -140,9 +165,9 @@ setup(void) {
 	XSetWindowAttributes wa;
 
 	/* init atoms */
-	dwmconfig = XInternAtom(dpy, "_DWM_CONFIG", False);
 	wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
 	wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
+	wmatom[WMName] = XInternAtom(dpy, "WM_NAME", False);
 	wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False);
 	netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
 	netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
@@ -219,35 +244,36 @@ xerrorstart(Display *dsply, XErrorEvent *ee) {
 
 /* extern */
 
-void
-quit(const char *arg) {
-	readin = running = False;
+Bool
+gettextprop(Window w, Atom atom, char *text, unsigned int size) {
+	char **list = NULL;
+	int n;
+	XTextProperty name;
+
+	if(!text || size == 0)
+		return False;
+	text[0] = '\0';
+	XGetTextProperty(dpy, w, &name, atom);
+	if(!name.nitems)
+		return False;
+	if(name.encoding == XA_STRING)
+		strncpy(text, (char *)name.value, size - 1);
+	else {
+		if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
+		&& n > 0 && *list)
+		{
+			strncpy(text, *list, size - 1);
+			XFreeStringList(list);
+		}
+	}
+	text[size - 1] = '\0';
+	XFree(name.value);
+	return True;
 }
 
 void
-updatebarpos(void) {
-	XEvent ev;
-
-	wax = sx;
-	way = sy;
-	wah = sh;
-	waw = sw;
-	switch(bpos) {
-	default:
-		wah -= bh;
-		way += bh;
-		XMoveWindow(dpy, barwin, sx, sy);
-		break;
-	case BarBot:
-		wah -= bh;
-		XMoveWindow(dpy, barwin, sx, sy + wah);
-		break;
-	case BarOff:
-		XMoveWindow(dpy, barwin, sx, sy - bh);
-		break;
-	}
-	XSync(dpy, False);
-	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
+quit(const char *arg) {
+	readin = running = False;
 }
 
 /* There's no way to check accesses to destroyed windows, thus those cases are