Score:0

Get the order of applictaions on GUI

ru flag

Is there a command to show the order of application shows on GUI?

enter image description here

user535733 avatar
cn flag
Are you asking for a different version of ALT+TAB?
王柏翔 avatar
ru flag
No, I am asking a command that shows the order of applications on GUI. Use the picture as an example, the command windows is on top of GUI, so the order is 1.
Jacob Vlijm avatar
by flag
Could you explain about the use case?
vanadium avatar
cn flag
May not be possible if your window manager does not explicitly expose a way to query this: see https://stackoverflow.com/questions/37214093/get-window-list-sorted-by-most-recent-access-bash
Jacob Vlijm avatar
by flag
Speaking of, what is your window manager? Wayland? Mutter?
Jacob Vlijm avatar
by flag
Hi 王柏翔 curious if a) this is what you mean, and b) if you need any help?
Score:0
by flag

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.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.