From f5c5fd74a8223aee7f49ece1db020d7495296047 Mon Sep 17 00:00:00 2001 From: Marco Peereboom Date: Thu, 23 Jun 2011 12:13:19 +0000 Subject: [PATCH] work around apps that dont set _NET_WM_PID and roll new version number --- scrotwm.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/scrotwm.c b/scrotwm.c index 499ee6d..4e9ecfd 100644 --- a/scrotwm.c +++ b/scrotwm.c @@ -54,7 +54,7 @@ static const char *cvstag = "$scrotwm$"; -#define SWM_VERSION "0.9.31" +#define SWM_VERSION "0.9.32" #include #include @@ -4766,22 +4766,41 @@ window_get_pid(Window win) unsigned long bytes_after_return = 0; long *pid = NULL; long ret = 0; + const char *errstr; + unsigned char *prop = NULL; if (XGetWindowProperty(display, win, XInternAtom(display, "_NET_WM_PID", False), 0, 1, False, XA_CARDINAL, &actual_type_return, &actual_format_return, &nitems_return, &bytes_after_return, (unsigned char**)(void*)&pid) != Success) - return (0); + goto tryharder; if (actual_type_return != XA_CARDINAL) - return (0); + goto tryharder; if (pid == NULL) - return (0); + goto tryharder; ret = *pid; XFree(pid); return (ret); + +tryharder: + if (XGetWindowProperty(display, win, + XInternAtom(display, "_SWM_PID", False), 0, SWM_PROPLEN, False, + XA_STRING, &actual_type_return, &actual_format_return, + &nitems_return, &bytes_after_return, &prop) != Success) + return (0); + if (actual_type_return != XA_STRING) + return (0); + if (prop == NULL) + return (0); + + ret = strtonum(prop, 0, UINT_MAX, &errstr); + /* ignore error because strtonum returns 0 anyway */ + XFree(prop); + + return (ret); } struct ws_win * -- 1.7.10.4