问题
So far I've found two approaches:
For each root window (default screen, specific screen, all screens, etc), list each immediate child. Search each immediate child recursively for a window with the
WM_STATE
property; that window becomes the top-level application window of the immediate child and all recursion can stop. If no window within the hierarchy of the immediate child has theWM_STATE
property, assume the immediate child is itself the top-level application window.Use
xcb_get_property
, andxcb_query_tree
(which despite the name lists only immediate children).This is what xlsclients uses, via XCB (same algorithm as above, more or less).
Requirements: requires ICCCM (window manager) support for
WM_STATE
.
For each root window (default screen, specific screen, all screens, etc), get "_NET_CLIENT_LIST" property which lists all the top-level application windows managed by the window manager.
Use
xcb_get_property
.This is what wmctrl uses, via Xlib.
Requires the window manager to maintain the list. Some windows seem to escape the list.
Requirements: EWMH (window manager) support for
_NET_CLIENT_LIST
or_WIN_CLIENT_LIST
(I have no idea what the second one is; I can't find any documentation).
Questions:
Are there any other approaches? Are there any approaches that do not depend on external mechanisms such as ICCCM or EWMH?
Which approach is the most resilient?
- EWMH. I've found some reports (linked above) that certain applications don't become listed in
_NET_CLIENT_LIST
. Why is this? - ICCCM. This approach seems more flexible, but won't otherwise windowless applications be matched by assuming the immediate child of hierarchies lacking
WM_STATE
is a top-level application window? Even worse, won't it break horribly under virtual root windows? For example, the virtual root window becomes the only immediate child, and recursion will stop on the first application window withWM_STATE
; only a single window will be matched. Against this eventuality,xlsclients
does not include any checks for virtual root windows... so why does it work with GNOME (which uses virtual root windows)?
- EWMH. I've found some reports (linked above) that certain applications don't become listed in
来源:https://stackoverflow.com/questions/37359063/x11-list-top-level-windows