/* * xsingleinstance * * Program to ensure that a single instance of an X window program * exists on the screen. * * Copyright (c) 2000, Merle F. McClelland for CompanionLink * Portions of this code, such as TryChildren and ClientWindow, are * based upon routines in the Xmu library, which is Copyright 1989, 1998, * The Open Group. All Rights Reserved. * * 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. * * See the files COPYRIGHT and LICENSE for distribution information. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define FALSE 0 #define TRUE 1 Atom wm_state_atom = 0; /* * Window_With_Name: routine to locate a window with a given name on a display. * If no window with the given name is found, 0 is returned. * If more than one window has the given name, the first * one found will be returned. Only top and its subwindows * are looked at. Normally, top should be the RootWindow. */ Window Window_With_Name(dpy, top, name) Display *dpy; Window top; char *name; { Window *children, dummy; unsigned int nchildren; int i; Window w=0; char *window_name; /* debugging: */ if (XFetchName(dpy, top, &window_name)) { printf ("checking window of name '%s' (looking for '%s')\n", window_name, name); XFree(window_name); } /* else printf ("ignoring window, no name set\n"); */ if (XFetchName(dpy, top, &window_name) && !strcmp(window_name, name)) { XFree(window_name); printf ("(choosing this window)\n"); return(top); } if (!XQueryTree(dpy, top, &dummy, &dummy, &children, &nchildren)) return(0); for (i=0; i