How to get the current active window in Ubuntu 22.04?

Asked by Tim McCabe

I need to be able to get the current active Window's app name and page title in Ubuntu 22.04, with Wayland desktop, no matter what the app is. I'll be implementing it in python, so something friendly to that environment would be wonderful!

The ways that work for me in previous versions of Ubuntu don't seem to work properly in 22.04. The ways that work in other Linux distros also don't seem to work in 22.04.

Rather than copying all the details here, I'll link to my post on askubuntu.com:
https://askubuntu.com/questions/1402702/how-to-get-the-current-active-window-in-ubuntu-22-04

Basically, a few methods (like `xprop -root _NET_ACTIVE_WINDOW`) get me info about the current active window as long as it is a web browser, but not if it's anything else. Some methods don't work at all, and pyatspi, which (alone) gets all the information for me, keeps freezing when a new window is opened.

Any help or suggestions would be much appreciated!

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Manfred Hampl (m-hampl) said :
#1

"Ubuntu 22" does not exist. Release numbers in Ubuntu have two pairs of numbers.
There currently is a release 22.04 in development, and there will most probably be a release 22.10 in October. They are different.

I assume that the effect that you see is not caused by the release, but is caused by XOrg versus Wayland.
My understanding was that Wayland is designed with security in mind and clear segregation between different windows, such that it does not allow accessing a window and its features from another window.

Revision history for this message
Tim McCabe (tmccabe) said :
#2

Given that some apps are found and some are not, it seems difficult to believe that this is the expected behavior. Additionally, all apps are found in pyatspi, but pyatspi tends to freeze frequently in certain circumstances. If no apps are supposed to be able to know what's going on in other apps, is AT-SPI dead? If it's dead, why does it still work?

Regardless, I still need some way to know the current focused window app and title. Any help or suggestions are still welcome!

Revision history for this message
Manfred Hampl (m-hampl) said :
#3

The fact that this works for some applications may have the cause that these are running in x11 mode with xwayland and not in native wayland mode.

Can you help with this problem?

Provide an answer of your own, or ask Tim McCabe for more information if necessary.

To post a message you must log in.