I want to monitor all the open windows under X11. Currently, I\'m doing this as follows:
X11 is a remote protocol. This means when you query the X server for any information, you always get your own copy. Your copy never changes when the X server updates its internal data structures.
This means the tree won't suddenly change while you traverse it but when you use the information in it (like examining a window), that information might be stale (someone might have closed the window). That is why you need to do proper error handling.
I believe that grabbing the X server (XGrabServer(3)) will prevent changes to the window hierarchy. It is a bit heavy handed though, so you should probably only do it if you really need it.
For an example of code that walks the window hierarchy, builds up a tree, uses window events to keep it up to date, and ignores X protocol errors which are unavoidable due to races, see the file src/VBox/Additions/x11/VBoxClient/seamless-x11.cpp in the source code for VirtualBox.
Have a look at xwininfo
.
You might also like xprop
and xspy
for getting more info.
Update: Yep. Try using xwininfo
and -root
with either -tree
or -children
to get all windows involved.
And changes can be tracked with xprop -spy
.