Top level window on X Window System
I want to print on the screen the information about Top level w开发者_如何学编程indows under Linux.
I use the xlib functions. I successfully recurse from the root window to print all the informations about all the element on display.
But I need only the Top-Level window. I don't find any good way to filter.
From wikipedia :
The top-level windows are exactly the direct subwindows of the root window.
With that definition , I have some windows like: gnome-session, seahorse-daemon,notify-osd or icons, on my list and i don't want them.
I also find a function : XmuClientWindow, but I don't understand its goal.
Let's see if I understand correctly what you want. The top level windows are the direct children of the root window, or with some window managers of a virtual root window - see Root Window (Wikipedia), which you seem to have found already. That article also tells you how to find the list of virtual root windows. You can use XQueryTree on the root or a virtual root to find the list of child windows.
Once you have that list you will probably need to apply lots of nasty heuristics to find the windows which interest you. XmuClientWindow will tell you which application window (if any) is associated with your top-level window. Applications create windows, and window managers reparent them to be children of a top-level window which they create to hold window decorations and things (maximise button, close button, resize handles). Reading the extended window manager hints from the client/application window can tell you things like whether you are dealing with a special window (dock, panel, whatever). You may also want to look at the window manager hints on the application window (XGetWMHints(3), XGetWMNormalHints(3), XGetWMSizeHints(3)) to decide whether it interests you or not - Window managers create a lot of transient windows that you probably don't care about.
See the seamless code in the VirtualBox Guest Additions for an example of looking through top-level windows.
wmctrl -l
This simple command will list all toplevel windows under root.
精彩评论