1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
/*
* Article 12523 of comp.windows.x:
* From: stolcke@ICSI.Berkeley.EDU (Andreas Stolcke)
* Subject: Converting programs to virtual root
* Date: 8 Sep 90 02:26:14 GMT
*
* Andreas Stolcke
* International Computer Science Institute stolcke@icsi.Berkeley.EDU
* 1957 Center St., Suite 600, Berkeley, CA 94704 (415) 642-4274 ext. 126
*
* vroot.h -- Virtual Root Window handling header file
*
* This header file redefines the X11 macros RootWindow and DefaultRootWindow,
* making them look for a virtual root window as provided by certain `virtual'
* window managers like swm and tvtwm. If none is found, the ordinary root
* window is returned, thus retaining backward compatibility with standard
* window managers.
* The function implementing the virtual root lookup remembers the result of
* its last invocation to avoid overhead in the case of repeated calls
* on the same display and screen arguments.
* The lookup code itself is taken from Tom LaStrange's ssetroot program.
*
* Most simple root window changing X programs can be converted to using
* virtual roots by just including
*
* #include "vroot.h"
*
* after all the X11 header files. It has been tested on such popular
* X clients as xphoon, xfroot, xloadimage, and xaqua.
*
* Andreas Stolcke <stolcke@ICSI.Berkeley.EDU>, 9/7/90
* - replaced all NULL's with properly cast 0's, 5/6/91
* - free children list (suggested by Mark Martin <mmm@cetia.fr>), 5/16/91
*/
#define DONTOPTIMISE /* unclutter needs to search from scratch each time */
#include <X11/X.h>
#include <X11/Xatom.h>
static Window
VirtualRootWindow(dpy, screen)
Display *dpy;
{
static Display *save_dpy = (Display *)0;
static int save_screen = -1;
static Window root = (Window)0;
#ifdef DONTOPTIMISE
{
#else
if (dpy != save_dpy || screen != save_screen) {
#endif
Atom __SWM_VROOT = None;
int i;
Window rootReturn, parentReturn, *children;
unsigned int numChildren;
root = RootWindow(dpy, screen);
/* go look for a virtual root */
__SWM_VROOT = XInternAtom(dpy, "__SWM_VROOT", False);
if (XQueryTree(dpy, root, &rootReturn, &parentReturn,
&children, &numChildren)) {
for (i = 0; i < numChildren; i++) {
Atom actual_type;
int actual_format;
unsigned long nitems, bytesafter;
Window *newRoot = (Window *)0;
if (XGetWindowProperty(dpy, children[i],
__SWM_VROOT, 0, 1, False, XA_WINDOW,
&actual_type, &actual_format,
&nitems, &bytesafter,
(unsigned char **) &newRoot) == Success
&& newRoot) {
root = *newRoot;
break;
}
}
if (children)
XFree((char *)children);
}
save_dpy = dpy;
save_screen = screen;
}
return root;
}
#undef DefaultRootWindow
#define DefaultRootWindow(dpy) RootWindow(dpy, DefaultScreen(dpy))
#undef RootWindow
#define RootWindow(dpy,screen) VirtualRootWindow(dpy,screen)
|