https://bugs.kde.org/show_bug.cgi?id=484992

--- Comment #34 from nyanpasu64 <nyanpas...@tuta.io> ---
Created attachment 177983
  --> https://bugs.kde.org/attachment.cgi?id=177983&action=edit
Video of a key being sent to a XWayland app after it's released in Wayland.

I'm still getting this bug on KDE Plasma 6.2.5 on Fedora 41. To understand why
the bug happens, I installed screenkey, a X11-based program which displays
keystrokes on-screen. Since it's a X11 app running under XWayland, it only sees
keystrokes delivered to XWayland apps. 

## Reproduction

To set up keystroke visualization, in Screenkey settings I checked "Persistent
window", and under KDE "Special Application Settings" I set all windows from
Screenkey to be above other windows. Then I restarted screenkey, dragged the
window to a convenient location, then opened a Wayland app (Firefox) and an X11
app (Obsidian Flatpak).

To reproduce the bug, I typed into Wayland Firefox while watching screenkey to
see what keystrokes it's receiving. I also moved my mouse in circles over X11
Obsidian, which makes XWayland send events to screenkey more quickly. I used
GPU Screen Recorder in replay mode to record the screen while I looked for
bugs, and in recording mode to capture a screencast of the bug happening. My
findings:

## Behavior

- Enter, Backspace, Tab, and arrow/Home/End/Page Up/Down keystrokes are
delivered to screenkey immediately. If you're not moving the mouse, they get
delayed until the next modifier keystroke (like Ctrl or Shift) or a periodic
timer.
- Modifier shortcuts (like Ctrl+A) are delivered to screenkey immediately. If
you're not moving the mouse, they're delayed until you release Ctrl.
- If I release Ctrl before A, XWayland usually enters a state where it sends an
endless string of A keystrokes to screenkey (which refreshes faster if you're
moving your mouse over a X11 app); I think the key repeats forever because
kwin_wayland fails to deliver the A key release to XWayland. While the key is
repeating, if I mouse-click into a X11 (XWayland) app, there is a 10-50% chance
that an erroneous A key gets delivered to the app. I think this happens if a
key repeat gets delivered to the app before XWayland realizes A is no longer
being pressed.

I've reproduced this bug with alphabetic and symbol keys (like ; semicolon).
I'm not sure this bug happens with *tab* events after Plasma 6.2; Tab is always
sent to XWayland (so letting go of a modifier does *not* cause the key release
to not be sent), Alt+Tab does not appear on Screenkey at all, and Ctrl+Tab does
not trigger endless repeats on screenkey if I release Ctrl before Tab (I think
the endless repeats are what causes stray keystrokes).

In any case I'm still posting this report under this bug; I reported the issue
with alphabetic keys instead of Tab at Bug 493956, but that got closed as a
duplicate of this.

## Fix

I'm guessing the fix is that if the user presses Ctrl+A, the A keypress
"belongs to a shortcut" and the key release is unconditionally delivered to
XWayland, even if Ctrl has been released already. Also, if the user presses A
and it's not delivered to XWayland, then presses Ctrl and releases A, it may
not be necessary to deliver the key release if you don't deliver key-held
events; I don't know if you do or not, or what behavior is ideal.

I think this behavior is a result of KDE's implementation of "Allow legacy X11
apps to read keystrokes typed in all apps:" "As above, plus any key typed while
the Control, Alt, or Meta keys are pressed" option. Unfortunately this is the
default value of the setting.

Hopefully this analysis helps find out *why* stray keys are sent to XWayland
apps, and fix keys being stuck on repeat on XWayland and being sent to apps
when focused. I wonder if there's a similar bug where if you hold Ctrl+A on a
Wayland app and click on a X11 app, KWin sends a stray Ctrl+A to the app. I
don't think this bug exists, since when you click on a X11 app, screenkey
reports a single A keystroke (not a Ctrl+A) and spends a second before
repeating Ctrl+A presses. I also tried this procedure 20+ times and did not see
the bug.

Operating System: Fedora Linux 41
KDE Plasma Version: 6.2.5
KDE Frameworks Version: 6.10.0
Qt Version: 6.8.1
Kernel Version: 6.12.9-200.fc41.x86_64 (64-bit)
Graphics Platform: Wayland
Processors: 4 × Intel® Core™ i5-3570K CPU @ 3.40GHz
Memory: 7.6 GiB of RAM
Graphics Processor: Mesa Intel® HD Graphics 4000
Manufacturer: M&A Technology
Product Name: DB75EN__

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to