GUIでアプリケーションの順序を取得する

GUIでアプリケーションの順序を取得する

GUI に表示されるアプリケーションの順序を表示するコマンドはありますか?

ここに画像の説明を入力してください

答え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に注意してください同様の方法がある

関連情報