From 5e6baa665ba23f33a05fb5b4d50edb440ec72259 Mon Sep 17 00:00:00 2001 From: Juha Lintula Date: Mon, 16 May 2011 09:57:47 +0300 Subject: [PATCH] Fixes: NB#250404 - Unable to create non-native single-instance applications with /usr/bin/single-instance or /usr/bin/invoker RevBy: Pertti Kellomaki --- debian/changelog | 3 ++- src/single-instance/main.cpp | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/debian/changelog b/debian/changelog index d0f50f7..90dcac4 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,7 +1,8 @@ -applauncherd (0.29.7) unstable; urgency=low +applauncherd (0.29.7) stable; urgency=low * Changes: Refactoring of testability plug-in loading * Changes: Corrected path names in documentation + * Fixes: NB#250404 - Unable to create non-native single-instance applications with /usr/bin/single-instance or /usr/bin/invoker -- Alexey Shilov Thu, 12 May 2011 16:43:38 +0300 diff --git a/src/single-instance/main.cpp b/src/single-instance/main.cpp index bdbaf91..51a8c82 100644 --- a/src/single-instance/main.cpp +++ b/src/single-instance/main.cpp @@ -189,8 +189,9 @@ void raiseWindow(Display *dpy, Window window) * * This method first fetches _NET_CLIENT_LIST for window candidates, * and then finds the matching binary using /proc/[pid]/cmdline. - * Proc fs is used, because we cannot trust WM_COMMAND window property. - * It might not be even set. + * Proc fs is primarily used, because we cannot trust WM_COMMAND window property + * in all cases. Anyhow we check also WM_COMMAND because proc fs does not work + * with scripts (python etc.). * * \param dpy The X11 display. * \param binaryName Full path to the binary. @@ -207,6 +208,8 @@ Window windowIdForBinary(Display *dpy, const char *binaryName) unsigned long nItems; unsigned long bytesAfter; unsigned char *prop = 0; + char **wmCommand = NULL; + int wmCommandCount = 0; // Get the client list of the root window if(XGetWindowProperty(dpy, XDefaultRootWindow(dpy), netClientListAtom, @@ -216,11 +219,17 @@ Window windowIdForBinary(Display *dpy, const char *binaryName) Window * clients = reinterpret_cast(prop); for (unsigned long i = 0; i < nItems; i++) { - if (binaryNameForPid(windowPid(dpy, clients[i])) == binaryName) + if (binaryNameForPid(windowPid(dpy, clients[i])) == binaryName || + (XGetCommand (dpy, clients[i], &wmCommand, &wmCommandCount) != 0 && + wmCommandCount > 0 && strcmp(wmCommand[0], binaryName) == 0)) { retValue = clients[i]; break; } + + if (wmCommand) { + XFreeStringList(wmCommand); + } } XFree(prop);