PyWinCtl icon indicating copy to clipboard operation
PyWinCtl copied to clipboard

getAllWindows() returned non-zero exit status 1

Open Metalloriff opened this issue 10 months ago • 3 comments

When running getAllWindows() on the latest version of KDE Plasma Wayland, I get this error.

Exception has occurred: CalledProcessError
Command 'gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval "global.get_window_actors().map(a=>a.meta_window).map(w=>({class: w.get_wm_class(), title: w.get_title(), active: w.has_focus(), id: w.get_description(), id2: w.get_id(), id3: w.get_pid()}))"' returned non-zero exit status 1.
  File "/PATH_TO_PYTHON_PROJECT/__main__.py", line 3, in <module>
    active_window = pywinctl.getAllWindows()
subprocess.CalledProcessError: Command 'gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval "global.get_window_actors().map(a=>a.meta_window).map(w=>({class: w.get_wm_class(), title: w.get_title(), active: w.has_focus(), id: w.get_description(), id2: w.get_id(), id3: w.get_pid()}))"' returned non-zero exit status 1.

It seems to think I'm using Gnome, but I'm using Plasma?

Metalloriff avatar Apr 16 '25 04:04 Metalloriff

Hi there!

The problem is not Plasma, but Wayland.

Unfortunately, in Wayland the developers intentionally decided to disallow things like retrieving the active window or the list of open windows, so PyWinCtl's getActiveWindow() and getAllWindows() will not likely work.

There is a sort of workaround by enabling unsafe-mode (otherwise you receive the error you're attaching). Enabling it will allow using gdbus command, which may help with some windows, but not them all. Even though unsafe-mode is enabled, many apps, including built-in and "official" applications, do not populate their Xid nor their X-Window object, making it impossible to find and handle.

In short, no module including PyWinCtl is able to properly work with Wayland windows. You can try enabling unsafe-mode to check if it meets your needs, but this is not suitable if you intend to distribute your app/module to others (they should enable unsafe-mode in their PCs too...).

Kalmat avatar Apr 16 '25 07:04 Kalmat

Thank you for the response.

So there isn't a reliable way to get the position/size of an active window on Wayland? Even with commands or other libraries/software?

Metalloriff avatar Apr 16 '25 21:04 Metalloriff

Hi again!

In short, no. Sorry to be bearer of bad news, but Wayland doesn't allow to address the active window, so there is no way (or I was not able to find any) to reliably find it or control it.

Kalmat avatar Apr 20 '25 14:04 Kalmat