[Wayland] Focus state breaking for globally active X.Org clients in focus-on-hover mode
Affected version
The problem is reproducible on Ubuntu 23.04 (Mutter 44.3) and Fedora Rawhide (Mutter 45.0), but not on Ubuntu 22.04 (Mutter 42.9). The problem is observed in Wayland session, but not in XOrg session.
Bug summary
In certain circumstances, focus state might become broken for an X.Org application, using globally active input model, running in a Wayland session. The application is sent a notification about receiving keyboard focus (and so it presents this information to user as e.g. a blinking caret), but keyboard events are routed to a completely different application. The problem was originally investigated for a JetBrains IDE, but I believe it's affecting all Java AWT/Swing applications which use undecorated windows.
Steps to reproduce
Two reproducers are attached to the ticket - one is a minimal Java sample app, and another is a minimal C app using Xlib. For both of them the following steps represent a 100% reproducible scenario on my machine.
- Enable 'Focus on Hover' mode in gnome-tweaks
- Add GNOME's standard text editor app to the GNOME dock/dash
- Launch the sample app
- Launch text editor from dock/dash. Click inside text editor area, and type some text
- Hover mouse over the sample app and type some text
What happened
Sample app looks focused at this point, but the text continues to be entered in text editor.
What did you expect to happen
It's expected that text is entered into the sample app.
Sample apps
Java sample app is attached as Undecorated.java file to the ticket. To launch it, Java runtime of version 11 or later
(e.g. 'openjdk-17-jre' on Ubuntu) should be installed in the system. The app is launched from terminal as java Undecorated.java
.
It opens a window with an area, accepting text input. When the app is having focus it displays a blinking caret. The app can be closed with
Alt+F4.
Native sample app is attached as undecorated.c file. It can be compiled and launched from terminal as
gcc undecorated.c -lX11; ./a.out
. The app shows a window which indicates in its background color, whether it has focus (black means focused,
and white means not). The app can be closed by pressing Esc.