Bug 482847

Summary: Additional mouse button bindings no longer work since commit bf1ce854748bfd2433c336a9ee972883cb8617ab
Product: [Plasma] kwin Reporter: Prajna Sariputra <putr4.s>
Component: inputAssignee: KWin default assignee <kwin-bugs-null>
Status: RESOLVED FIXED    
Severity: major CC: aleixpol, cavendish.qi, fanzhuyifan, kde, nate, wolfgangmcq+acct-bugs.kde.org
Priority: NOR Keywords: regression
Version First Reported In: master   
Target Milestone: ---   
Platform: Compiled Sources   
OS: Linux   
Latest Commit: Version Fixed In: 6.1
Sentry Crash Report:

Description Prajna Sariputra 2024-03-08 10:37:00 UTC
SUMMARY
With Plasma 6.1 from git master, I noticed that the bindings I have set up for the additional buttons on my mouse no longer work, they just end up doing the default action bound to them. In my case the buttons are recognized by libinput as `BTN_EXTRA (276)` and `BTN_SIDE (275)`.

If I revert the part of commit bf1ce854748bfd2433c336a9ee972883cb8617ab (Make it possible to build KWin without libxcb) that applies to the buttonrebinds plugin then the bindings work again, and reverting KWin to the commit before that also works.

In the system logs, these messages appeared when I pressed the mouse buttons (two of these messages appear for every button press):

> kwin_wayland[42047]: kwin_buttonrebinds: Could not convert QKeySequence("Meta+G") syms:  QList(285212743) to keycode
> kwin_wayland[42047]: kwin_buttonrebinds: Could not convert QKeySequence("Meta+G") syms:  QList(285212743) to keycode
> kwin_wayland[42047]: kwin_buttonrebinds: Could not convert QKeySequence("Alt+F1") syms:  QList(150994992) to keycode
> kwin_wayland[42047]: kwin_buttonrebinds: Could not convert QKeySequence("Alt+F1") syms:  QList(150994992) to keycode



STEPS TO REPRODUCE
1. Have a mouse with extra buttons that can be configured via the "Re-bind Additional Mouse Buttons..." page in the Mouse KCM (mine is just a random "gaming" mouse I picked up in a nearby store, with two side buttons)
2. Set up a binding for one of those mouse buttons (I used Meta+G and Alt+F1 for the desktop grid and app launcher)
3. Press the mouse button with the binding

OBSERVED RESULT
The button acts as if no binding was set and just performs the default action (for me the buttons act like forward and back buttons of some sort out of the box).

EXPECTED RESULT
The keyboard shortcut bound to the button should be triggered.

SOFTWARE/OS VERSIONS
Operating System: Arch Linux 
KDE Plasma Version: 6.0.80
KDE Frameworks Version: 6.0.0
Qt Version: 6.6.2
Kernel Version: 6.7.8-arch1-1 (64-bit)
Graphics Platform: Wayland
Comment 1 Bug Janitor Service 2024-03-10 21:17:20 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/5409
Comment 2 fanzhuyifan 2024-03-10 21:25:32 UTC
Two issues here: 

1. We need to remove the modifiers. This is handled by the the MR above.
2. QXkbCommon::toKeysym sometimes only returns one key sym even when there are multiple matching key syms. (https://github.com/qt/qtbase/blob/dev/src/gui/platform/unix/qxkbcommon.cpp#L455)
E.g., the Qt::Key_Delete maps to both XKB_KEY_Delete and XKB_KEY_Clear, but QXkbCommon::toKeysym only returns XKB_KEY_Clear...
I will try to upstream a patch for that
Comment 4 fanzhuyifan 2024-03-14 21:48:56 UTC
Git commit 6c4551ff46b1b2ed26dd3d3ab5601da8dd2cb19d by Yifan Zhu.
Committed on 14/03/2024 at 21:37.
Pushed by fanzhuyifan into branch 'master'.

plugins/buttonrebinds: remove modifiers before keysym conversion

QXkbCommon::toKeysym can't handle modifiers in key.

M  +1    -1    src/plugins/buttonrebinds/buttonrebindsfilter.cpp

https://invent.kde.org/plasma/kwin/-/commit/6c4551ff46b1b2ed26dd3d3ab5601da8dd2cb19d
Comment 6 Bug Janitor Service 2024-04-20 23:19:26 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/kwin/-/merge_requests/5628
Comment 7 fanzhuyifan 2024-05-27 18:41:46 UTC
Git commit 09d4f3fda3e381c016605092f773af994ba4d7f0 by Yifan Zhu.
Committed on 27/05/2024 at 18:27.
Pushed by fanzhuyifan into branch 'master'.

xkb: support converting Qt keys to keysyms

QXkbCommon::toKeysym doesn't correctly handle the case where a single Qt
key map to multiple keysyms.

M  +0    -2    autotests/integration/buttonrebind_test.cpp
M  +26   -0    autotests/test_xkb.cpp
M  +1    -2    src/inputmethod.cpp
M  +5    -3    src/plugins/buttonrebinds/buttonrebindsfilter.cpp
M  +410  -0    src/xkb.cpp
M  +7    -0    src/xkb.h

https://invent.kde.org/plasma/kwin/-/commit/09d4f3fda3e381c016605092f773af994ba4d7f0
Comment 8 fanzhuyifan 2024-05-27 19:25:59 UTC
Git commit 0c1f545d6be2c4d4a5de7364c9f87f6193898027 by Yifan Zhu.
Committed on 27/05/2024 at 18:43.
Pushed by fanzhuyifan into branch 'Plasma/6.1'.

xkb: support converting Qt keys to keysyms

QXkbCommon::toKeysym doesn't correctly handle the case where a single Qt
key map to multiple keysyms.


(cherry picked from commit 09d4f3fda3e381c016605092f773af994ba4d7f0)

M  +0    -2    autotests/integration/buttonrebind_test.cpp
M  +26   -0    autotests/test_xkb.cpp
M  +1    -2    src/inputmethod.cpp
M  +5    -3    src/plugins/buttonrebinds/buttonrebindsfilter.cpp
M  +410  -0    src/xkb.cpp
M  +7    -0    src/xkb.h

https://invent.kde.org/plasma/kwin/-/commit/0c1f545d6be2c4d4a5de7364c9f87f6193898027