/* Code mostly from: * 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. * * GNU General Public License for more details. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static Display *display; static int screen; static Atom wm_state_atom = 0; struct window_info *window_info_new (Window xid, char *name) { struct window_info *w; w = (struct window_info *) malloc (sizeof (struct window_info)); w->xid = xid; w->name = strdup(name); return w; } void window_info_free (struct window_info *w) { g_assert (w != NULL); if (w->name) free (w->name); free (w); } GList *get_windows_with_name_in (Display *dpy, Window top, char *name) { Window *children, dummy; unsigned int nchildren; int i; char *window_name; GList *l=NULL; if (XFetchName(dpy, top, &window_name) && !fnmatch(name, window_name, FNM_PERIOD)) l = g_list_append (l, window_info_new (top, window_name)); if (!XQueryTree(dpy, top, &dummy, &dummy, &children, &nchildren)) return(0); for (i=0; idisplay_name); raise_window(display, xid); } return 0; }