diff options
author | npmccallum <npmccallum@c587cffe-e639-0410-9787-d7902ae8ed56> | 2007-12-14 03:20:45 +0000 |
---|---|---|
committer | npmccallum <npmccallum@c587cffe-e639-0410-9787-d7902ae8ed56> | 2007-12-14 03:20:45 +0000 |
commit | 895bc2875eb83d4223e00169d2f52f29c6978755 (patch) | |
tree | 49e9fccdf6ec5d90134e5175c35746b4be7ff9be | |
parent | 2d96e3bf0d10dbead3ac549d7729312502ff8825 (diff) | |
download | libproxy-git-895bc2875eb83d4223e00169d2f52f29c6978755.tar.gz |
move x_has_client() out of gnome/kde into its own file
-rw-r--r-- | src/plugins/Makefile.am | 4 | ||||
-rw-r--r-- | src/plugins/gnome.c | 89 | ||||
-rw-r--r-- | src/plugins/kde.c | 85 | ||||
-rw-r--r-- | src/plugins/xhasclient.c | 95 |
4 files changed, 101 insertions, 172 deletions
diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index acbcc51..5e5d18c 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am @@ -34,13 +34,13 @@ file_la_LIBADD = ../lib/libproxy.la file_la_LDFLAGS = -module -avoid-version # GConf/GNOME Config Plugin -gnome_la_SOURCES = gnome.c +gnome_la_SOURCES = gnome.c xhasclient.c gnome_la_CFLAGS = -I$(top_srcdir)/src/lib @GNOME_CFLAGS@ gnome_la_LIBADD = ../lib/libproxy.la gnome_la_LDFLAGS = -module -avoid-version @GNOME_LIBS@ # KDE Config Plugin -kde_la_SOURCES = kde.c +kde_la_SOURCES = kde.c xhasclient.c kde_la_CFLAGS = -I$(top_srcdir)/src/lib @KDE_CFLAGS@ kde_la_LIBADD = ../lib/libproxy.la kde_la_LDFLAGS = -module -avoid-version @KDE_LIBS@ diff --git a/src/plugins/gnome.c b/src/plugins/gnome.c index b1bf4a7..0581452 100644 --- a/src/plugins/gnome.c +++ b/src/plugins/gnome.c @@ -19,99 +19,14 @@ #include <stdlib.h> #include <string.h> -#include <stdarg.h> #include <misc.h> #include <proxy_factory.h> #include <gconf/gconf-client.h> -#include <X11/Xlib.h> -#include <X11/Xmu/WinUtil.h> - -// This function is shamelessly stolen from xlsclient... :) -/* - * - * -Copyright 1989, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - * * - * Author: Jim Fulton, MIT X Consortium - */ -bool -x_has_client(char *prog, ...) -{ - va_list ap; - - // Open display - Display *display = XOpenDisplay(NULL); - if (!display) - return false; - - // For each screen... - for (int i=0; i < ScreenCount(display); i++) - { - Window dummy, *children = NULL; - unsigned int nchildren = 0; - - // Get the root window's children - if (!XQueryTree(display, RootWindow(display, i), &dummy, &dummy, &children, &nchildren)) - continue; - - // For each child on the screen... - for (int j=0; j < nchildren; j++) - { - // If we can get their client info... - Window client; - if ((client = XmuClientWindow(display, children[j])) != None) - { - int argc; - char **argv; - - // ... and if we can find out their command ... - if (!XGetCommand (display, client, &argv, &argc) || argc == 0) - continue; - - // ... check the commands against our list - va_start(ap, prog); - for (char *s = prog ; s ; s = va_arg(ap, char *)) - { - // We've found a match, return... - if (!strcmp(argv[0], s)) - { - va_end(ap); - XCloseDisplay(display); - return true; - } - } - va_end(ap); - } - } - } - - // Close the display - XCloseDisplay(display); - return false; -} +// From xhasclient.c +bool x_has_client(char *prog, ...); pxConfig * gconf_config_cb(pxProxyFactory *self) diff --git a/src/plugins/kde.c b/src/plugins/kde.c index c704aa7..e897677 100644 --- a/src/plugins/kde.c +++ b/src/plugins/kde.c @@ -28,89 +28,8 @@ #include <X11/Xlib.h> #include <X11/Xmu/WinUtil.h> -// This function is shamelessly stolen from xlsclient... :) -/* - * - * -Copyright 1989, 1998 The Open Group - -Permission to use, copy, modify, distribute, and sell this software and its -documentation for any purpose is hereby granted without fee, provided that -the above copyright notice appear in all copies and that both that -copyright notice and this permission notice appear in supporting -documentation. - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN -AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -Except as contained in this notice, the name of The Open Group shall not be -used in advertising or otherwise to promote the sale, use or other dealings -in this Software without prior written authorization from The Open Group. - * * - * Author: Jim Fulton, MIT X Consortium - */ -bool -x_has_client(char *prog, ...) -{ - va_list ap; - - // Open display - Display *display = XOpenDisplay(NULL); - if (!display) - return false; - - // For each screen... - for (int i=0; i < ScreenCount(display); i++) - { - Window dummy, *children = NULL; - unsigned int nchildren = 0; - - // Get the root window's children - if (!XQueryTree(display, RootWindow(display, i), &dummy, &dummy, &children, &nchildren)) - continue; - - // For each child on the screen... - for (int j=0; j < nchildren; j++) - { - // If we can get their client info... - Window client; - if ((client = XmuClientWindow(display, children[j])) != None) - { - int argc; - char **argv; - - // ... and if we can find out their command ... - if (!XGetCommand (display, client, &argv, &argc) || argc == 0) - continue; - - // ... check the commands against our list - va_start(ap, prog); - for (char *s = prog ; s ; s = va_arg(ap, char *)) - { - // We've found a match, return... - if (!strcmp(argv[0], s)) - { - va_end(ap); - XCloseDisplay(display); - return true; - } - } - va_end(ap); - } - } - } - - // Close the display - XCloseDisplay(display); - return false; -} +// From xhasclient.c +bool x_has_client(char *prog, ...); pxConfig * kde_config_cb(pxProxyFactory *self) diff --git a/src/plugins/xhasclient.c b/src/plugins/xhasclient.c new file mode 100644 index 0000000..85c563a --- /dev/null +++ b/src/plugins/xhasclient.c @@ -0,0 +1,95 @@ +/* + * + * +Copyright 1989, 1998 The Open Group + +Permission to use, copy, modify, distribute, and sell this software and its +documentation for any purpose is hereby granted without fee, provided that +the above copyright notice appear in all copies and that both that +copyright notice and this permission notice appear in supporting +documentation. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of The Open Group shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from The Open Group. + * * + * Author: Jim Fulton, MIT X Consortium + */ + +/* + * Concept and some basic code shamelessly stolen from xlsclients... :) + * Reworked by Nathaniel McCallum, 2007 + */ + +#include <stdbool.h> +#include <stdarg.h> +#include <string.h> + +#include <X11/Xlib.h> +#include <X11/Xmu/WinUtil.h> + +bool +x_has_client(char *prog, ...) +{ + va_list ap; + + // Open display + Display *display = XOpenDisplay(NULL); + if (!display) + return false; + + // For each screen... + for (int i=0; i < ScreenCount(display); i++) + { + Window dummy, *children = NULL; + unsigned int nchildren = 0; + + // Get the root window's children + if (!XQueryTree(display, RootWindow(display, i), &dummy, &dummy, &children, &nchildren)) + continue; + + // For each child on the screen... + for (int j=0; j < nchildren; j++) + { + // If we can get their client info... + Window client; + if ((client = XmuClientWindow(display, children[j])) != None) + { + int argc; + char **argv; + + // ... and if we can find out their command ... + if (!XGetCommand (display, client, &argv, &argc) || argc == 0) + continue; + + // ... check the commands against our list + va_start(ap, prog); + for (char *s = prog ; s ; s = va_arg(ap, char *)) + { + // We've found a match, return... + if (!strcmp(argv[0], s)) + { + va_end(ap); + XCloseDisplay(display); + return true; + } + } + va_end(ap); + } + } + } + + // Close the display + XCloseDisplay(display); + return false; +} |