4

Many apps need the functionality to retrieve the title and app of the active window. With XProp this was not problem.

xprop -root _NET_ACTIVE_WINDOW

Even with wayland it used to work by using the following script

!/usr/bin/env python3

import subprocess

if name == "main": while 1 == 1:

    print('---------------')
    print('global.get_window_actors...')
    app_command = ("gdbus call -e -d org.gnome.Shell -o /org/gnome/Shell -m org.gnome.Shell.Eval global.get_window_actors\(\)[`gdbus call -e -d org.gnome.Shell -o /org/gnome/Shell -m org.gnome.Shell.Eval global.get_window_actors\(\).findIndex\(a\=\>a.meta_window.has_focus\(\)===true\) | cut -d\"'\" -f 2`].get_meta_window\(\).get_wm_class\(\)")
    app_process = subprocess.Popen(app_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    app_retval = app_process.stdout.read()
    app_retcode = app_process.wait()
    actorsApp = app_retval.decode('utf-8').strip()
    print(actorsApp)

    time.sleep(1)

However the gnome solution has become obsolete as they removed the possiblity in its newer version.

So at the moment (25.04.2022) it is not possible to retrieve the active window name with the latest LTS version of Ubuntu.

So my question is: What is the correct way get the current window and retrieve app name und window title?

Silve2611
  • 141
  • 4

1 Answers1

2

I believe you have to create a Shell extension that communicates with your application over Dbus.

This is a major flaw in Wayland that several applications are still trying to work out. You can see one such major discussion here.

Glyph
  • 233