Posted by
jdp on
Jan 11, 2011; 11:44pm
URL: https://forum.jogamp.org/Root-win-tp2219141p2237909.html
well, i can present this bit of a review for X11
a classic example is
xearth. it demonstrates what the
wm_spec calls virtual roots.
from
xearth//x11.c
...
/*
* (taken nearly verbatim from the june 1993 comp.windows.x FAQ, item 148)
*/
static Window GetVRoot(dpy)
Display *dpy;
{
int i;
Window rootReturn, parentReturn, *children;
unsigned int numChildren;
Atom __SWM_VROOT = None;
Window rslt = root;
__SWM_VROOT = XInternAtom(dpy, "__SWM_VROOT", False);
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 = NULL;
/* item 148 in the FAQ neglects to mention that there is a race
* condition here; consider a child of the root window that
* existed when XQueryTree() was called, but has disappeared
* before XGetWindowProperty() gets called for that window ...
*/
if ((XGetWindowProperty(dpy, children[i], __SWM_VROOT, 0, 1,
False, XA_WINDOW, &actual_type,
&actual_format, &nitems, &bytesafter,
(unsigned char **) &newRoot) == Success)
&& newRoot)
{
rslt = *newRoot;
break;
}
}
/* item 148 in the FAQ also neglects to mention that we probably
* want to free the list of children after we're done with it ...
*/
XFree((void *) children);
return rslt;
}
it's using a funny atom,
__SWM_VROOT
that differs from the expected
_NET_VIRTUAL_ROOTS
.
however, we see the same elsewhere as well
//www.mail-archive.com/xorg-devel@lists.x.org/msg06346.html
from
vroot.h
...
static Window VirtualRootWindowOfScreen(Screen *screen)
{
static Screen *save_screen = (Screen *)0;
static Window root = (Window)0;
if (screen != save_screen) {
Display *dpy = DisplayOfScreen(screen);
Atom __SWM_VROOT = None;
int i;
Window rootReturn, parentReturn, *children;
unsigned int numChildren;
/* first check for a hex or decimal window ID in the environment */
const char *xss_id = getenv("XSCREENSAVER_WINDOW");
if (xss_id && *xss_id) {
unsigned long id = 0;
char c;
if (1 == sscanf (xss_id, " 0x%lx %c", &id, &c) ||
1 == sscanf (xss_id, " %lu %c", &id, &c)) {
root = (Window) id;
save_screen = screen;
return root;
}
}
root = RootWindowOfScreen(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;
unsigned char *newRoot = 0;
if (XGetWindowProperty(dpy, children[i],
__SWM_VROOT, 0, 1, False, XA_WINDOW,
&actual_type, &actual_format,
&nitems, &bytesafter,
&newRoot) == Success
&& newRoot) {
root = *((Window *) newRoot);
break;
}
}
if (children)
XFree((char *)children);
}
save_screen = screen;
}
return root;
}