Bug 484992 - Xwayland apps get Tab keyboard events even when they should be filtered out by event filter
Summary: Xwayland apps get Tab keyboard events even when they should be filtered out b...
Status: RESOLVED FIXED
Alias: None
Product: kwin
Classification: Plasma
Component: input (show other bugs)
Version: 6.0.3
Platform: Neon Linux
: HI normal
Target Milestone: ---
Assignee: KWin default assignee
URL:
Keywords: regression
: 486263 489325 489382 489609 489631 489757 490754 491287 492037 492116 492272 492361 492491 493221 493386 493956 (view as bug list)
Depends on:
Blocks:
 
Reported: 2024-04-03 16:23 UTC by mailport+kdebugs
Modified: 2024-11-14 15:37 UTC (History)
39 users (show)

See Also:
Latest Commit:
Version Fixed In: 6.2.0
Sentry Crash Report:


Attachments
Video of a window receiving TAB characters while cycling windows. (460.45 KB, video/x-matroska)
2024-07-02 21:31 UTC, figueroa628
Details

Note You need to log in before you can comment on or make changes to this bug.
Description mailport+kdebugs 2024-04-03 16:23:06 UTC
# SUMMARY

When the current focus in in an XWayland application/windows and I switch to the over-next window (by pressing Alt+Tab+Tab) the second tab will also be registered inside the application

# STEPS TO REPRODUCE

1. Open a xwayland application (preferably one with a textarea input - for easier debugging).
2. Set the input focus into the textarea.
3. Press Alt+Tab+Tab to switch two windows further (aka HOLD-ALT PRESS-TAG PRESS-TAB RELEASE-ALT)
4. Go back to the original window and observe that one tab was pressed 

# OBSERVED RESULT

The second tab of the Alt-Tab-Tab was forwarded (?) to the original window

# EXPECTED RESULT

The task-switcher should "swallow" the key presses (the first tab seems to be swallowed, but not all further presses)

# SOFTWARE/OS VERSIONS

KDE Plasma Version:  6.0.3
KDE Frameworks Version:  6.0.0
Qt Version:  6.6.3
Kernel Version: 6.8.2-arch2-1 (64-bit)
Graphics Platform: Wayland

# ADDITIONAL OBSERVATIONS

 - This only works in XWayland windows (confirmed in IntelliJ Goland, Webstorm, Bitwarden, MongoDB Compass, non-wayland-VSCodium)

 - In native Wayland applications I can't reproduce it (aka firefox, Dolphin, Konsole, ....)

 - The bug is not specific to the tab key, If I [HOLD-ALT] [Tab] [ARROW-DOWN] [ARROW-DOWN] [RELEASE-ALT], then the two arrow presses do also appear in the original application

 - The task-switcher behaves completely normal during all this - meaning both applications (teh task-switcher and the originally focused window) receive the key press

 - Does not happen when I switch to X11

 - Does happen independent which task switcher I chose in the settings (tested "Modern Informative", Compact, "Thumbnail Grid")

 - It happens consistently, I can reproduce it every time I try
Comment 1 Zamundaaa 2024-04-22 14:13:09 UTC
Can confirm, though it only happens if you set X11 apps to always be able to read all keystrokes
Comment 2 mailport+kdebugs 2024-04-22 14:22:01 UTC
(In reply to Zamundaaa from comment #1)
> Can confirm, though it only happens if you set X11 apps to always be able to
> read all keystrokes

Wow - thanks Zamundaaa. That actually fixes my problem (even though I had the option "Any key typed while Control/Alt/Meta are pressed" selected). But switching to "Never" completely fixes it.

You can't believe how annoying the last week was, I think in every project of mine are now random tabs committed.
Really thank you - lol, send me you postal address and I'll mail you a box of chocolate.
Comment 3 Kevin Schier 2024-04-25 12:53:30 UTC
Also happens for me when using the overview feature or desktop grid. First input gets properly intercepted while all following keys "leak" through.
Comment 4 Zamundaaa 2024-04-28 23:10:29 UTC
*** Bug 486263 has been marked as a duplicate of this bug. ***
Comment 5 Nate Graham 2024-06-29 17:54:23 UTC
Trivial way to reproduce: Focus an XWayland window and Alt+Tab with default XWayland snooping settings. The app gets sent tab keys.
Comment 6 Nate Graham 2024-06-29 17:54:30 UTC
*** Bug 489325 has been marked as a duplicate of this bug. ***
Comment 7 Nate Graham 2024-06-29 20:15:48 UTC
*** Bug 489382 has been marked as a duplicate of this bug. ***
Comment 8 Nate Graham 2024-06-29 20:16:15 UTC
*** Bug 488870 has been marked as a duplicate of this bug. ***
Comment 9 Nate Graham 2024-06-29 20:16:46 UTC
This was exposed by changing the XWayland snooping move away from "Never".
Comment 10 Divyanshu 2024-07-02 14:16:10 UTC
*** Bug 489609 has been marked as a duplicate of this bug. ***
Comment 11 Zamundaaa 2024-07-02 19:18:18 UTC
*** Bug 489631 has been marked as a duplicate of this bug. ***
Comment 12 figueroa628 2024-07-02 21:31:05 UTC
Created attachment 171308 [details]
Video of a window receiving TAB characters while cycling windows.
Comment 13 s3bbarg 2024-07-03 11:20:09 UTC
I see it as well. Here is a simple way to reproduce using vscode (it affects chrome as well, but is very easy to see in vscode)

1. Settings -> Task Switcher: disable "show selected window" (makes it easier to see what is happening)
2. start vscode with an empty document
3. press alt-tab repeatedly and observe the tab character "bleeds through" to vscode.
Comment 14 Zamundaaa 2024-07-04 22:35:15 UTC
*** Bug 489757 has been marked as a duplicate of this bug. ***
Comment 15 JC 2024-07-08 17:06:44 UTC
Add backtick to the list: when pressing Alt+` + ` (backtick twice) the original window gets the backtick.
Comment 16 Bug Janitor Service 2024-07-09 13:42:19 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/6074
Comment 17 David Edmundson 2024-07-24 12:50:52 UTC
*** Bug 490754 has been marked as a duplicate of this bug. ***
Comment 18 elman 2024-07-26 02:19:13 UTC
I actually started to report new bug when I stumbled upon this one, so here is my description which seems pretty much like what is described here:

When I use Alt+Tab to switch windows, keystrokes are sent to last active window and appear as spaces. For example, I use RubyMine, have code `<MessageBox messages={messages}/>` and I leave cursor between `=` and `{`. Then I use Alt+Tab to loop through all open windows (13 window) and get back to RubyMine, I have code `<MessageBox messages=                         {messages}/>` so 25 spaces are added.

So far I have seen this issue with RubyMine, Typora.

Slack and Spotify act as if they are receiving Tab keystrokes.

All of these applications are xclients.
Comment 19 David Edmundson 2024-08-02 09:40:42 UTC
Git commit 8fd4476ff1848ce7ce4d3573224fc4893ae8339d by David Edmundson.
Committed on 02/08/2024 at 09:31.
Pushed by davidedmundson into branch 'master'.

wayland: Move XWayland key forwarding into a filter

We optionally send some keys to xwayland through the filter when no x11
client has focus. This allows shortcut handling in X11 apps to work.

When kwin is grabbing keys we don't necessarily want X11 to sniff these
keys as things can get out of sync. A key place is the tabbox. The X11
client sill has focus, but xwayland is not active. This means we pass
tab keys to X which then go to application incorrectly.

Part of this patch changes the tabbox filter to not intercept the alt
key release event. This ensures xwayland's concept of pressed modifiers
stays in sync.

M  +36   -0    autotests/integration/x11keyread.cpp
M  +1    -0    src/input.cpp
M  +1    -0    src/input.h
M  +50   -49   src/xwayland/xwayland.cpp
M  +2    -2    src/xwayland/xwayland.h

https://invent.kde.org/plasma/kwin/-/commit/8fd4476ff1848ce7ce4d3573224fc4893ae8339d
Comment 20 fanzhuyifan 2024-08-05 04:51:40 UTC
*** Bug 491287 has been marked as a duplicate of this bug. ***
Comment 21 ⭐️NINIKA⭐️ 2024-08-08 09:21:52 UTC
 I see that it "Version fixed in" says 6.2.0, the next major release, which is still some time off.

Would it be possible to cherry-pick it into some of the 6.1 bugfix releases?
Comment 22 elman 2024-08-08 22:21:23 UTC
(In reply to ⭐️NINIKA⭐️ from comment #21)
>  I see that it "Version fixed in" says 6.2.0, the next major release, which
> is still some time off.
> 
> Would it be possible to cherry-pick it into some of the 6.1 bugfix releases?

At Nate's blog I noticed that this only happens with default setting "When Alt+Tabbing through windows, tab keystrokes no longer leak into XWayland-using apps when using default XWayland app keyboard snooping setting". So I just went to settings and selected to never send any keystrokes to X11 apps and that works for me. I don't use any X11 app that would need those keystrokes.
Comment 23 duha.bugs 2024-08-27 14:47:03 UTC
*** Bug 492272 has been marked as a duplicate of this bug. ***
Comment 24 Nate Graham 2024-08-27 20:01:52 UTC
*** Bug 492116 has been marked as a duplicate of this bug. ***
Comment 25 Nate Graham 2024-08-27 20:01:55 UTC
*** Bug 492037 has been marked as a duplicate of this bug. ***
Comment 26 Ricardo J. Barberis 2024-08-28 01:30:23 UTC
(In reply to elman from comment #22)
> (In reply to ⭐️NINIKA⭐️ from comment #21)
> >  I see that it "Version fixed in" says 6.2.0, the next major release, which
> > is still some time off.
> > 
> > Would it be possible to cherry-pick it into some of the 6.1 bugfix releases?

Please KDE devs, if it's not too invasive it'd be nice to have this backported to 6.1.x
 
> At Nate's blog I noticed that this only happens with default setting "When
> Alt+Tabbing through windows, tab keystrokes no longer leak into
> XWayland-using apps when using default XWayland app keyboard snooping
> setting". So I just went to settings and selected to never send any
> keystrokes to X11 apps and that works for me. I don't use any X11 app that
> would need those keystrokes.

Thanks for pointing out that workaround!
It never occurred to me to go looking through the settings.

I don't know what side effects this setting might have but at least I won't lose my mind now 😁
Comment 27 Zamundaaa 2024-09-01 22:46:55 UTC
*** Bug 492491 has been marked as a duplicate of this bug. ***
Comment 28 Zamundaaa 2024-10-02 14:27:10 UTC
*** Bug 493956 has been marked as a duplicate of this bug. ***
Comment 29 Nate Graham 2024-10-04 23:36:22 UTC
*** Bug 492361 has been marked as a duplicate of this bug. ***
Comment 30 Nate Graham 2024-10-04 23:36:25 UTC
*** Bug 493221 has been marked as a duplicate of this bug. ***
Comment 31 Nate Graham 2024-10-04 23:36:28 UTC
*** Bug 493386 has been marked as a duplicate of this bug. ***
Comment 32 Bryan Moore 2024-11-14 15:37:10 UTC
This does not appear fixed in 6.2.3 on Fedora 41.