summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Hutchings <ben@decadent.org.uk>2009-02-16 19:04:10 -0500
committerAdam Jackson <ajax@redhat.com>2009-02-16 19:04:10 -0500
commit5152f193534886796827cf54a36471b679348642 (patch)
tree03189b8c001042f810a1159cdfa0beb46e5dd5e6
parentbe665ef592f24ccc93a46dc938c3a101d6668cdf (diff)
Exit cleanly when the target window is destroyed. (#19381)
-rw-r--r--xprop.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/xprop.c b/xprop.c
index 6e2d067..7ada23f 100644
--- a/xprop.c
+++ b/xprop.c
@@ -1596,6 +1596,22 @@ Parse_Format_Mapping (int *argc, char ***argv)
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 */
+ puts("");
+ exit(0);
+ }
+
+ if (old_error_handler)
+ return old_error_handler(dpy, ev);
+
+ return 0;
+}
+
int
main (int argc, char **argv)
{
@@ -1738,10 +1754,15 @@ main (int argc, char **argv)
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 (;;) {
fflush(stdout);
XNextEvent(dpy, &event);
+ if (event.type == DestroyNotify)
+ break;
+ if (event.type != PropertyNotify)
+ continue;
format = dformat = NULL;
if (props) {
int i;