Bug 489001

Summary: "Activate application launcher" bound to `Meta` is triggered when pressing `Meta+Shift`, before releasing `Meta` when layout switching is set to Both Shifts
Product: [Plasma] plasmashell Reporter: bastimeyer123
Component: Application Launcher (Kickoff) widgetAssignee: Plasma Bugs List <plasma-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: fanzhuyifan, mikel5764, noahadvs
Priority: NOR    
Version First Reported In: 6.1.0   
Target Milestone: 1.0   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed/Implemented In: 6.1.3
Sentry Crash Report:
Attachments: Kickoff launch via Meta+Shift
kwin debug console
xmodmap -pke

Description bastimeyer123 2024-06-22 19:02:23 UTC
SUMMARY
This is probably the wrong bug category and most likely caused by a change in kwin's shortcut handling, but I'm not sure, so apologies if this is the wrong place.

Since 6.1.0, there's an issue with the application launcher's activation shortcut. When bound to `Meta`, the launcher now incorrectly opens after pressing `Shift` while the `Meta` key is being held down, preventing other shortcut keybindings to work.

For example, if you have bound kwin's "Move Window One Screen (to the Left|to the Right|Top|Down)" action to `Meta+Shift+(Left|Right|Top|Down)`, then these shortcuts won't work anymore, because the just opened application launcher now will have focus as soon as `Shift` is pressed, and it is moved instead of the intended window.

STEPS TO REPRODUCE
1. Have "Activate application launcher" bound to `Meta`
2. Have "Move Window One Screen to the Left" bound to `Meta+Shift+Left`, etc.
3. Try to move a random window by holding `Meta`, then holding `Shift` and then pressing `Left`

OBSERVED RESULT
The application launcher is activated as soon as `Shift` is being pressed while `Meta` is held down, stealing focus of the current window.

EXPECTED RESULT
The application launcher should only be activated when releasing the `Meta` key and no other modifier key was pressed.

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Arch Linux
KDE Plasma Version: 6.1.0
KDE Frameworks Version: 6.3.0
Qt Version: 6.7.1
Comment 1 fanzhuyifan 2024-06-23 00:43:43 UTC
fwiw can't reproduce on master, wayland. Are you seeing this on x11 or wayland?
Comment 2 bastimeyer123 2024-06-23 01:22:48 UTC
(In reply to fanzhuyifan from comment #1)
> fwiw can't reproduce on master, wayland. Are you seeing this on x11 or
> wayland?

I'm on wayland where this is happening reliably. Also just checked X11, and the issue does not occur there.

```
$ pacman -Q kwin plasma-workspace
kwin 6.1.0-3
plasma-workspace 6.1.0-1
```
Comment 3 bastimeyer123 2024-06-23 11:09:28 UTC
Here are the full contents of my `kglobalshortcutsrc` and `kwinrc`:
https://gist.github.com/bastimeyer/a1e064aaf3e138b1cf9ecdc1183e99ed

Relevant stuff from `kwinrc`:
> [ModifierOnlyShortcuts]
> Meta=org.kde.plasmashell,/PlasmaShell,org.kde.PlasmaShell,activateLauncherMenu

Relevant stuff from `kglobalshortcutsrc`:
> [plasmashell]
> _k_friendly_name=plasmashell
> activate application launcher=Meta,Meta\tAlt+F1,Activate Application Launcher
> activate widget 4=none,none,Activate Application Launcher Widget
> activate widget 45=Alt+F1,none,Activate Application Launcher Widget

Let me also quickly add a short video showing the problem with `evtest` log output...
Comment 4 bastimeyer123 2024-06-23 11:10:06 UTC
Created attachment 170859 [details]
Kickoff launch via Meta+Shift
Comment 5 fanzhuyifan 2024-06-23 16:46:14 UTC
Hi, thank you for the update.

The section in kwinrc is no longer used as of 6.1.

Your kglobalshortcutsrc section seems correct.

The events reported by your evtest seem correct -- left meta press, left meta hold, left shift press, left shift hold... The modifier-only shortcuts trigger on release, and so there the application launcher shouldn't trigger at all. I also get the same evtest event sequence on git master, and on 6.1, arch linux, wayland. But I cannot reproduce the issue on either version.

To further debug the issue, could you open krunner, and search for "kwin debug console"? Then, go to Input Events, and vertically enlarge the window so that more events are visible. Could you reproduce the issue and upload a screencast? Thanks!

A wild guess: what keymap are you using? What is the output of `xmodmap -pke | grep Meta`? Does the issue occur with a default keymap?
For me the output of `xmodmap -pke | grep Meta` is

keycode  64 = Alt_L Meta_L Alt_L Meta_L
keycode 108 = Alt_R Meta_R Alt_R Meta_R
keycode 205 = NoSymbol Meta_L NoSymbol Meta_L
Comment 6 bastimeyer123 2024-06-23 17:22:21 UTC
Created attachment 170873 [details]
kwin debug console

(In reply to fanzhuyifan from comment #5)
> To further debug the issue, could you open krunner, and search for "kwin debug console"? Then, go to Input Events, and vertically enlarge the window so that more events are visible. Could you reproduce the issue and upload a screencast? Thanks!
Done, see new attachment...

> what keymap are you using?
Default keymap on a Logitech g710+ (German layout), with the "en_US Intl with dead keys" layout selected in the Plasma keyboard settings

> Does the issue occur with a default keymap?
It does also occur when using the regular en_US layout

> What is the output of `xmodmap -pke | grep Meta`?
```
$ xmodmap -pke | grep Meta
keycode  64 = Alt_L Meta_L Alt_L Meta_L
keycode 205 = NoSymbol Meta_L NoSymbol Meta_L
```
Comment 7 fanzhuyifan 2024-06-23 19:29:55 UTC
When you press the shift key, kwin reports a keypress with scancode 42, and keycode 65043 (0xFE13, which is XKB_KEY_ISO_Level5_Lock), with modifiers Shift and Meta. It has no mapped Qt keycode. I suspect this might be causing the problem, but haven't been able to reproduce that on my end. Do you know why it's reporting XKB_KEY_ISO_Level5_Lock instead of the ordinary shift keys?

For reference, could you also attach the complete output of `xmodmap -pke`? Thanks.
Comment 8 bastimeyer123 2024-06-23 19:56:54 UTC
Created attachment 170878 [details]
xmodmap -pke

I found the cause of this.

As hinted, I've set up two different keyboard layouts, "en_US International with dead keys" and the regular "en_US" one. In the "Keyboard -> Key Bindings" settings menu, I have "Both Shifts together" set in the "Switching to another layout" category.

When disabling this double-shift-press behavior, the issue does not occur.

With the option, pressing shift results in:
Scan code: 42
Xkb symbol: 65034
With the option, releasing shift results in:
Scan code: 42
Xkb symbol: 65505

Without the option, pressing shift results in:
Scan code: 42
Xkb symbol: 65505
Without the option, releasing shift results in:
Scan code: 42
Xkb symbol: 65505
Comment 9 Bug Janitor Service 2024-06-23 22:32:34 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kglobalacceld/-/merge_requests/54
Comment 10 fanzhuyifan 2024-07-02 21:41:04 UTC
Git commit b06bda34e060a4614d594a1691e720edabaf85e1 by Yifan Zhu.
Committed on 02/07/2024 at 17:26.
Pushed by fanzhuyifan into branch 'master'.

explicitly process invalid keycodes

Since dd36387c1fe704914cf41dd1e7333bac703e8ca7 in kwin, key events with
invalid key codes are also passed to kglobalacceld. The code mistakenly
triggers the corresponding modifier-only shortcut.
FIXED-IN: 6.1.3

M  +3    -0    autotests/shortcutstest.cpp
M  +9    -5    src/globalshortcutsregistry.cpp

https://invent.kde.org/plasma/kglobalacceld/-/commit/b06bda34e060a4614d594a1691e720edabaf85e1
Comment 11 fanzhuyifan 2024-07-02 21:43:32 UTC
Git commit 8643077d0422c97ad12dc052202c9e1348e99b23 by Yifan Zhu.
Committed on 02/07/2024 at 21:41.
Pushed by fanzhuyifan into branch 'Plasma/6.1'.

explicitly process invalid keycodes

Since dd36387c1fe704914cf41dd1e7333bac703e8ca7 in kwin, key events with
invalid key codes are also passed to kglobalacceld. The code mistakenly
triggers the corresponding modifier-only shortcut.
FIXED-IN: 6.1.3


(cherry picked from commit b06bda34e060a4614d594a1691e720edabaf85e1)

Co-authored-by: Yifan Zhu <fanzhuyifan@gmail.com>

M  +3    -0    autotests/shortcutstest.cpp
M  +9    -5    src/globalshortcutsregistry.cpp

https://invent.kde.org/plasma/kglobalacceld/-/commit/8643077d0422c97ad12dc052202c9e1348e99b23