Looking at your screenshot, my guess is you are looking for a way to achieve it in python.
Get the z-order of windows
If you are on X, you can use (in any language that has bindings to - ) Wnck. Wnck does not work on Wayland though. The snippet below shows how it's done in python. The order of the output list is in the order of the window z-order.
Note that the output of Wnck.get_windows_stacked()
should not be modified. You can of course work with the data, retrieved from it, get the order of the windows and their properties. In the snippet, I only used to get the xid and name of the window, but a lot is possible.
Example
#!/usr/bin/env python3
import gi
gi.require_version("Wnck", "3.0")
from gi.repository import Wnck
def get_stack():
z_order_list = []
scr = Wnck.Screen.get_default()
# if Wnck is not called from withing a Gtk loop, we need:
scr.force_update()
for w in scr.get_windows_stacked():
# most likely, we only work with normal windows (no panels or desktop)
if w.get_window_type() == Wnck.WindowType.NORMAL:
# only adding xid and name here, but anything is possible
z_order_list.append([w.get_xid(), w.get_name()])
z_order_list.reverse()
return z_order_list
wlist = get_stack()
for w in wlist:
print(w[0], w[1])
Example output:
92306612 *IDLE Shell 3.8.10*
92274937 zorder.py - /home/jacob/Bureaublad/zorder.py (3.8.10)
96468995 Get the order of applictaions on GUI - Ask Ubuntu - Mozilla Firefox
98568913 Geen titel 1 - LibreOffice Writer
98566678 Rooster Jacob 2021-2022.ods - LibreOffice Calc
94371847 Tilix: jacob@jacob-ZN220IC-K:~
where the first is the most recent window, because I reversed the list.
Note that Gdk has similar method.