瀏覽代碼

dispvm: close only visible windows during DispVM preparation

Closing some invisible window can cause e.g. Firefox crash. Send the
message to visible windows and others should be cleaned up by the
application.
Marek Marczykowski-Górecki 9 年之前
父節點
當前提交
5c4e88a765
共有 1 個文件被更改,包括 12 次插入1 次删除
  1. 12 1
      misc/close-window.c

+ 12 - 1
misc/close-window.c

@@ -15,15 +15,26 @@ int close_window(Display *d, XID window) {
 	return XSendEvent(ev.display, ev.window, True, 0, (XEvent *) & ev);
 }
 
+int is_window_visible(Display *d, XID window) {
+    XWindowAttributes xwa;
+
+    if (!XGetWindowAttributes(d, window, &xwa))
+        return 0;
+    return xwa.map_state == IsViewable;
+}
+
 int main(int argc, char **argv) {
 	int i;
 	Display *d;
+	XID w;
 
 	d = XOpenDisplay(NULL);
 	if (!d)
 		exit(1);
 	for (i=1; i<argc; i++) {
-		close_window(d, strtoul(argv[i], NULL, 0));
+        w = strtoul(argv[i], NULL, 0);
+        if (is_window_visible(d, w))
+                close_window(d, w);
 	}
 	XSync(d, False);
 	XCloseDisplay(d);