Don’t focus newly mapped windows unconditionally
Currently, on Wayland window activates any newly mapped toplevel, since apps typically only use XDG activation (which has logic for preventing stealing input, among other things) for handover but not on initial window show.
While this makes the system behave as expected in many cases (app gets launched, window gets focus) it can also cause Windows to steal focus from the user while typing or cause unexpected windows (such as the desktop window when plasma starts, cf. !4349 ) to get focus.
This issue collects places where focus breaks if KWin never automatically focusses any windows, so the issues can be fixed and eventually KWin gets full control over when to activate windows.
Issues
-
For real-world testing, an “xdg activation only” mode in KWin shall be added where windows will never automatically get focussed in Workspace::addWaylandWindow
: !4659 (merged)
- Most logically, this can be tied to “focus stealing prevention”, e.g. setting it to “Extreme” (4)
-
Patch QWaylandWindow
torequestActivate
on window show (unlessQt::WA_ShowWithoutActivating
is set): https://codereview.qt-project.org/c/qt/qtwayland/+/519444
- Many platforms do this implicitly or have heuristics on their own, but on Wayland we have to request activation ourselves.
-
KWin refuses the aforementioned activation in XdgToplevelWindow::takeFocus()
because!readyForPainting()
. The activation token situation all works, though, otherwise we wouldn’t even get totakeFocus()
. -
KRunner thinks it’s activated, blinking cursor and all, even though it didn’t actually get activated
- KRunner activates successfully through global shortcut with the above QtWayland patch, though, so not that big of a deal.
-
No way to launch an application with a token from terminal -
GTK 4 apps try to activate themselves on launch (only tested the Calculator) but KWin refuses to grant a token
-
Shouldn’t they be using the token they got on launch from
XDG_ACTIVATION_TOKEN
? -
Qt also mentions a GTK “quirk” where apps need to request xdg activation regardless?!
// At least GNOME requires to request the token in order to get the` // focus stealing prevention indication, so requestXdgActivationToken call // is still necessary in that case.
-
GTK 3 / Qt 5.15 = ¯\_(ツ)_/¯
What works then
Assuming the aforementioned QtWayland patch and KWin fixed, windows correctly get focus when:
-
Opening new windows from themselves in response to user interaction (e.g. properties dialog, save prompts, even “open new window”)
- Opening plasmoid popups from
plasmawindowed
works, too, didn’t test yet how it behaves with a real panel (which doesn’t accept focus)
-
Launch application through KRunner/Kickoff
- Systemsettings seems to work even without the Qt change, perhaps because of DBus-activation /
KDBusService
-
Launch application through global shortcut -
Context menus, they aren’t toplevels -
Chrome also properly passes focus to new browswer windows and popups (e.g. developer console)
Notes
- Stacking order is entirely unaffected, so a new window can still open and completely cover the window that currently has the focus