[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#508126: x11-utils: xprop -spy does not handle destruction properly



This patch seems to do the job.  Firstly we listen for destroy events.
However, since window destruction is asynchronous with other clients, we
may receive a BadWindow (or BadMatch, due to id reuse) error while
reporting a property change.  So secondly we catch these errors.
Possibly we should print a new-line before exiting in this case, since
the error received when we have generated partial output for a property
change.

Ben.

diff -Nru x11-utils.orig/xprop/xprop.c x11-utils/xprop/xprop.c
--- x11-utils.orig/xprop/xprop.c
+++ x11-utils/xprop/xprop.c
@@ -1596,6 +1596,18 @@
 
 static int spy = 0;
 
+static int (*old_error_handler)(Display *dpy, XErrorEvent *ev);
+
+static int spy_error_handler(Display *dpy, XErrorEvent *ev)
+{
+    if (ev->error_code == BadWindow || ev->error_code == BadMatch) {
+	/* Window was destroyed */
+	exit(0);
+    }
+
+    return old_error_handler(dpy, ev);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -1738,9 +1750,14 @@
 	XEvent event;
 	const char *format, *dformat;
 	
-	XSelectInput(dpy, target_win, PropertyChangeMask);
+	XSelectInput(dpy, target_win, PropertyChangeMask | StructureNotifyMask);
+	old_error_handler = XSetErrorHandler(spy_error_handler);
 	for (;;) {
 	    XNextEvent(dpy, &event);
+	    if (event.type == DestroyNotify)
+		break;
+	    if (event.type != PropertyNotify)
+		continue;
 	    format = dformat = NULL;
 	    if (props) {
 		int i;
--- END ---

-- 
Ben Hutchings
All the simple programs have been written, and all the good names taken.

Attachment: signature.asc
Description: This is a digitally signed message part


Reply to: