答案1
看看你的螢幕截圖,我猜你正在尋找一種用 python 實現它的方法。
取得視窗的 z 順序
如果你在X,您可以使用(在任何綁定到 - 的語言中)Wnck。但 Wnck 在 Wayland 上不起作用。下面的程式碼片段展示了它是如何在 python 中完成的。輸出列表的順序按照視窗 z 順序的順序。
請注意,輸出Wnck.get_windows_stacked()
不應修改。您當然可以使用從中檢索的數據,以取得視窗的順序及其屬性。在程式碼片段中,我只用來取得視窗的 xid 和名稱,但是很多都是可能的。
例子
#!/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])
輸出範例:
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:~
其中第一個是最近的窗口,因為我顛倒了清單。
請注意 Gdk有類似的方法。