Bug 508819 - X11 override-redirect window retain focus after switching to Wayland-native window
Summary: X11 override-redirect window retain focus after switching to Wayland-native w...
Status: REPORTED
Alias: None
Product: kwin
Classification: Plasma
Component: input (other bugs)
Version First Reported In: 6.4.4
Platform: Fedora RPMs Linux
: NOR normal
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-08-27 19:32 UTC by Marek Marczykowski-Górecki
Modified: 2025-09-11 08:16 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments
Reproducer (1.47 KB, text/x-csrc)
2025-09-09 02:33 UTC, Marek Marczykowski-Górecki
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Marek Marczykowski-Górecki 2025-08-27 19:32:46 UTC
XWayland under KDE keeps focus on an X11 (override-redirect) window even after switching to a Wayland-native window. This is not the case after switching to another X11 window, or if the original window didn't have override-redirect flag.
With "Allow legacy X11 apps to read keystrokes typed in all apps" enabled (the default), it means the input is duplicated into two applications, possibly executing unintended actions.

STEPS TO REPRODUCE
1. Take any override-redirect X11 window that takes input. Example: `WAYLAND_DISPLAY="" nm-applet` (and click on the icon)
2. Switch to a native Wayland application (like Konsole)
3. Try to type something or use arrows in the Wayland application

OBSERVED RESULT
Both applications act on key events.
`xdotool getwindowfocus` reports nm-applet window still in focus.

EXPECTED RESULT
Only application in focus (Konsole in this example) acts on key events.
Note this behaves correctly if the original X11 window didn't have override-redirect flag. In that case switching focus to native Wayland window also switches focus on the X11 side to a (dummy?) 1x1 window with no name (0x200000 in my case, but I believe this ID is dynamic).

SOFTWARE/OS VERSIONS
(available in the Info Center app, or by running `kinfo` in a terminal window)
Linux/KDE Plasma: 
KDE Plasma Version: 6.4.4
KDE Frameworks Version: 6.17.0
Qt Version: 6.8.3

ADDITIONAL INFORMATION
Comment 1 TraceyC 2025-09-03 21:23:17 UTC
I'm not able to reproduce this on git-master 

nm-applet isn't available for Solus, where I have git-master installed; I tested with Xournal++ with and without the provided environment variable.

Are there other applications you are able to reproduce this with?

Note: In Solus and Fedora, the default is not "Always allowed" but "As above, plus any key pressed while Ctr, Alt or Meta is also pressed.
Comment 2 Marek Marczykowski-Górecki 2025-09-09 02:29:20 UTC
> Note: In Solus and Fedora, the default is not "Always allowed" but "As above, plus any key pressed while Ctr, Alt or Meta is also pressed.

That's correct. But that still in practice passes all arrows, F-keys etc, even if no modifier is pressed. TBH, I'm not sure if that's intentional.

As for the reproducer, I'll prepare minimal example.
But also, it appears to affect not only override-redirect windows, but also status icons (via xembed). Specifically, even after closing menu of the status icon (still nm-applet here), Enter key will open the menu again.

And one more observation: the problem appears directly after switching from X11 window to Wayland window. But then after switching from one native Wayland window to yet another focus the problem disappears.
Comment 3 Marek Marczykowski-Górecki 2025-09-09 02:33:33 UTC
Created attachment 184827 [details]
Reproducer

Compile with `gcc window-focus.c -lX11 -o window-focus`

It creates a simple override-redirect window and prints any key events it receives. In the problematic situation, it gets events (arrows, F-keys, Enter etc) that should be sent only to another (native Wayland) app.