diff options
author | Ben Hutchings <ben@decadent.org.uk> | 2009-02-16 19:04:10 -0500 |
---|---|---|
committer | Adam Jackson <ajax@redhat.com> | 2009-02-16 19:04:10 -0500 |
commit | 5152f193534886796827cf54a36471b679348642 (patch) | |
tree | 03189b8c001042f810a1159cdfa0beb46e5dd5e6 /xprop.c | |
parent | be665ef592f24ccc93a46dc938c3a101d6668cdf (diff) |
Exit cleanly when the target window is destroyed. (#19381)
Diffstat (limited to 'xprop.c')
-rw-r--r-- | xprop.c | 23 |
1 files changed, 22 insertions, 1 deletions
@@ -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; |