[comp.windows.x] XQueryTree call illegal on RootWindow ?

gildea@expo.lcs.mit.EDU (Stephen Gildea) (04/12/91)

    Date: 12 Apr 91 02:39:52 GMT
    From: ramakris@bloss.cs.vt.edu (S Ramakrishnan)

    Is it illegal to XQueryTree on the root window ?

    ...

No, it is perfectly legal.  In fact, "xwininfo -root -tree" does it.

However, your sample program declares two variables with the same
name, "children".  This is more likely to be your problem.

 < Stephen
   MIT X Consortium

mouse@lightning.mcrcim.mcgill.EDU (der Mouse) (04/13/91)

> Is it illegal to XQueryTree on the root window ?

No.

> If so, why ? My QueryTree call on the rootwindow consistently yields
> a memory fault :  in the function XrmStringToQuark :

> {
>  Display *dpy;Window rootw,parent, root, *children;
>  register status, screen; int children;

You should get an error from your compiler for trying to declare two
variables called "children" with different types in the same scope.

>  dpy = XOpenDisplay("");
>  rootw = RootWindow(dpy, DefaultScreen(dpy));
>  status = XQueryTree(dpy, rootw, &root, &parent, &children, &nchildren);

You should get another error here for using an undeclared variable
nchildren, unless you have a global by that name.

> }

I tried your code here (after adding #includes for <X11/X.h> and
<X11/Xlib.h> and a main() header) and the compiler said

"z.c", line 7: redeclaration of children
"z.c", line 11: nchildren undefined

Changing "int children" to "int nchildren" instead, it compiles and
runs.  I even added "XCloseDisplay(dpy);" just before the end to make
sure that no errors were being generated but not seen, and it still
runs fine.

> When I do the same thing with a child of the rootwindow, it works
> fine.

I conjecture this has something to do with precisely what sort of
garbage happens to be lying around on the stack.  Without more
information (a real code sample, say) I can't say much more.

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu