Search code examples
c++cx11xlib

I need to get the list of all the windows displayed or hidden in the desktop


I'm trying to code something using X11 related libraries such as Xlib and Xrandr.

At first I was expecting a full coverage of the real basic functions such as retrieving the refresh rate from the monitors from Xlib alone, later on I find out that I need Xrandr for that.

Now I need to get the list of all the windows displayed or hidden in the desktop, I'm not thinking about using Gnome/KDE/XFCE ... extensions because I know that those are just decorators for X11, but I can't really find a function or a macro that is able to enumerate the open windows in the X server. I also need to get the ID/name of the window that is under focus.

My question is: Xlib alone is capable of doing this ? Because from the terminology that Xlib adopts, I have my doubts that this functions could possibly even exist.


Solution

  • You can get a list of child windows with XQueryTree

    XQueryTree - query window tree information
    
    Status XQueryTree(Display *display, Window w, Window *root_return, Window *parent_return, Window **children_return, unsigned int *nchildren_return);
    

    So, to get a complete list, you'll have to start with the root window and recursively call it for all the children of each window.