2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /*****************************************************************************/
24 /** Copyright 1991 by Andreas Stolcke **/
25 /** Copyright 1990 by Solbourne Computer Inc. **/
26 /** Longmont, Colorado **/
28 /** All Rights Reserved **/
30 /** Permission to use, copy, modify, and distribute this software and **/
31 /** its documentation for any purpose and without fee is hereby **/
32 /** granted, provided that the above copyright notice appear in all **/
33 /** copies and that both that copyright notice and this permis- **/
34 /** sion notice appear in supporting documentation, and that the **/
35 /** name of Solbourne not be used in advertising **/
36 /** in publicity pertaining to distribution of the software without **/
37 /** specific, written prior permission. **/
39 /** ANDREAS STOLCKE AND SOLBOURNE COMPUTER INC. DISCLAIMS ALL WARRANTIES **/
40 /** WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF **/
41 /** MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL ANDREAS STOLCKE **/
42 /** OR SOLBOURNE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL **/
43 /** DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA **/
44 /** OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER **/
45 /** TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE **/
46 /** OR PERFORMANCE OF THIS SOFTWARE. **/
47 /*****************************************************************************/
49 * vroot.h -- Virtual Root Window handling header file
51 * This header file redefines the X11 macros RootWindow and DefaultRootWindow,
52 * making them look for a virtual root window as provided by certain `virtual'
53 * window managers like swm and tvtwm. If none is found, the ordinary root
54 * window is returned, thus retaining backward compatibility with standard
56 * The function implementing the virtual root lookup remembers the result of
57 * its last invocation to avoid overhead in the case of repeated calls
58 * on the same display and screen arguments.
59 * The lookup code itself is taken from Tom LaStrange's ssetroot program.
61 * Most simple root window changing X programs can be converted to using
62 * virtual roots by just including
64 * #include <X11/vroot.h>
66 * after all the X11 header files. It has been tested on such popular
67 * X clients as xphoon, xfroot, xloadimage, and xaqua.
68 * It also works with the core clients xprop, xwininfo, xwd, and editres
69 * (and is necessary to get those clients working under tvtwm).
70 * It does NOT work with xsetroot; get the xsetroot replacement included in
71 * the tvtwm distribution instead.
73 * Andreas Stolcke <stolcke@ICSI.Berkeley.EDU>, 9/7/90
74 * - replaced all NULL's with properly cast 0's, 5/6/91
75 * - free children list (suggested by Mark Martin <mmm@cetia.fr>), 5/16/91
76 * - include X11/Xlib.h and support RootWindowOfScreen, too 9/17/91
82 #if !defined(lint) && !defined(SABER)
83 static char vroot_rcsid[] = "$XConsortium: vroot.h /main/3 1996/06/11 16:30:45 cde-hal $";
87 #include <X11/Xatom.h>
91 VirtualRootWindowOfScreen(Screen *screen)
93 static Screen *save_screen = NULL;
94 static Window root = None;
96 if (screen != save_screen)
98 Display *dpy = DisplayOfScreen(screen);
99 Atom __SWM_VROOT = None;
101 Window rootReturn, parentReturn, *children;
102 unsigned int numChildren;
104 root = RootWindowOfScreen(screen);
106 /* go look for a virtual root */
107 /* we're in deep shit if a window dies during this loop */
108 __SWM_VROOT = XInternAtom(dpy, "__SWM_VROOT", False);
109 if (XQueryTree(dpy, root, &rootReturn, &parentReturn,
110 &children, &numChildren))
112 for (i = 0; i < numChildren; i++)
116 unsigned long nitems, bytesafter;
117 Window *newRoot = NULL;
121 XGetWindowProperty(dpy, children[i],
122 __SWM_VROOT, 0, 1, False, XA_WINDOW,
123 &actual_type, &actual_format,
124 &nitems, &bytesafter,
125 (unsigned char **) &newRoot);
127 if (status == Success && newRoot != NULL)
133 if (children != NULL)
134 XFree((char *) children);
137 save_screen = screen;
144 /* Need original macros to figure out if there is a virtual root. */
147 #undef RootWindowOfScreen
148 #define RootWindowOfScreen(s) VirtualRootWindowOfScreen(s)
151 #define RootWindow(dpy,screen) VirtualRootWindowOfScreen(ScreenOfDisplay(dpy,screen))
153 #undef DefaultRootWindow
154 #define DefaultRootWindow(dpy) VirtualRootWindowOfScreen(DefaultScreenOfDisplay(dpy))
158 #define VRootWindowOfScreen(s) VirtualRootWindowOfScreen(s)
160 #define VRootWindow(dpy,screen) VirtualRootWindowOfScreen(ScreenOfDisplay(dpy,screen))
162 #define VDefaultRootWindow(dpy) VirtualRootWindowOfScreen(DefaultScreenOfDisplay(dpy))
165 #endif /* _VROOT_H_ */