Reputation: 1
I am trying to get the number of top level windows aka children of the root window in Xlib using XQuerytree.
It is just working fine when only experimenting with basic X utilities such as Xterm or Xeyes but the num_top_level_windows
contains a completely wrong number for apps using GTK or QT frameworks (e.g. with only KeepassXC open, i apparently have 5 top level windows).
Here is the relevant code snippet
Window returned_root, returned_parent;
Window* top_level_windows;
unsigned int num_top_level_windows;
XQueryTree(
display_,
root_,
&returned_root,
&returned_parent,
&top_level_windows,
&num_top_level_windows);
printf("\n\n N: %d\n", num_top_level_windows);
root_
and display_
are references to the root window and the display (obtained via XOpenDisplay and DefaultRootWindow(display_) and should be working fine.
I am using a nested Xephyr X server session on gentoo linux. I really wonder why this "error" occurs and how can i get the true number of children windows.
Thank you in advance!
Upvotes: 0
Views: 103
Reputation: 1
XQueryTree() returns any child window from the specified 'w' field, created by XWindows, including override-redirect windows and Unmapped/Unviewable windows.
To filter out these windows you need to query their properties using XGetWindowAttributes(), checking if the window is override_redirect or if the map_state is not set to IsViewable.
That should be sufficient, but you may also need to query the WM_STATE of a window to check if its IconicState or WithdrawnState, depending on how your environment is set up.
You can refer to the dwm source code, specifically "dwm.c, scan()" to see how they implemented their way of managing windows, or in this case seeing which are "top level".
Upvotes: 0