Get an X window ID

eberrocal at laurel.datsi.fi.upm.es eberrocal at laurel.datsi.fi.upm.es
Wed May 23 08:35:45 PDT 2007


Hi list.

I wrote a question few days ago about how to get a window ID (type Window)
of an any window.

I have thought a solution but I have problems.

1) OBTAIN THE ROOT WINDOW ID

XGetGeometry(display, RootWindow(display, screen_num), &root_win,
		&x, &y, &width, &height, &border_width, &depth)

In root_win I have the ID of the root window

2) CREATE A NEW WINDOW (but do not print, only create)
REALLY, I EXECUTE MY FORK/EXEC OF AN ANY X APPLICATION

win = XCreateSimpleWindow(display, RootWindow(display, screen_num),
		x, y, width, height, border_width,
		BlackPixel(display, screen_num), WhitePixel(display, screen_num));

3) OBTAIN THE WINDOWS TREE OF THE ROOT WINDOW (all the windows)

XQueryTree(display, root_win, &root_win, &parent_win, children_return,
		&n_children)

In children_return (Window **) I have all the windows IDs in execution.

4) I NEED TO SEARCH MY NEW WINDOW IN THIS VECTOR OF POINTERS TO WINDOWS.

I can obtain the first or the last of this vector. I do not know where the
Xlib put the new window. But for example:

winid_ext = **children_return;

if (winid_ext == win)
	fprintf(stdout, "ok !! good !!\n");

In winid_ext I have the new window ID and, if this is equal to win, this
method works fine. But I have a problem when I execute.

$ ./giveMeId
Segment fault

I have read that the problem can be in the function XQueryTree() when
there are windows outside the display, this is true ?.




More information about the xorg mailing list