I'm looking to give some Linux command a window id as obtained by xprop
or wmctrl
or similar and have something tell me where in the "z-wards" stacking order that window currently is.
For example, if window C is visually behind window B (as in B is clipping C, if they overlap each other), and window A is in front of both them, some command would tell me something like 0
for window A, 1
for B, and 2
for C. Perhaps the "front" number is bigger than the "back" number; that's unimportant to me.
Best Answer
What you're looking for is not a window property but a side-effect of the way X displays windows. Looking for details on
XRaiseWindow
leads toXRestackWindows
and seeing that it reorders a list of the windows (which given that it changes the order in which the X server displays them, controls the apparent stacking order).The
xwininfo
command can return a list of child-windows for any window, and a tree of windows. That's presented in the same order (it usesXQueryTree
, whose description says that it lists the children in current stacking order), you could (with some effort) make a script that analyzed that and relate it to the windows that you care about (not all windows are interesting).Window-ids aren't that useful, but you can use those as a parameter to
xprop
and find the window-titles that correspond. Not all windows have titles, and there are some quirks to account for along the way.(The solution is neither bash- or linux-specific, and predates both of those).
Someone alluded to EWMH's
_NET_CLIENT_LIST
:In a quick check, that illustrates the quirks to explore.
I have 3 windows, and the stacking lists one twice. Also, which window is the parent of the visible clients can differ according to the window manager in use.
And of course, there are still window managers which don't follow EWMH. Even within EWMH, you have to appreciate that "SHOULD". It doesn't guarantee success.
For comparison, of course: