TLDR: Go to patching
Plasma 6
I recently updated to Kde Plasma 6, and it's great except for one minor annoyance: the overview effect is triggered on the touchpad with a 4-finger swipe, and I'd prefer to trigger it with a 3-finger swipe instead.
Problem is, the value is hardcoded in the C++ code
There is an issue about making it configurable but without someone assigned to it. If you want to help implement it, you can get involved
Today, I want an easy win, and it seems easy enough to patch the binary, so let's try.
Analysis
Using objdump -D /usr/bin/kwin_wayland | grep -i touchpad we can find that the method addTouchpadSwipeGesture
is indeed in the kwin_wayland binary with the mangled name _ZN4KWin22EffectTogglableGesture23addTouchpadSwipeGestureENS_14SwipeDirectionEj.
We find exactly 3 calls to it, corresponding to the source code.
We want to keep the hex representation of the instructions that make up the call, specifically the hex of the 3 mov instructions before the call.
With:
d7b58: 48 89 ef mov %rbp,%rdi
d7b5b: ba 04 00 00 00 mov $0x4,%edx
d7b60: be 03 00 00 00 mov $0x3,%esi
d7b65: e8 06 dd f7 ff call 55870 <_ZN4KWin22EffectTogglableGesture23addTouchpadSwipeGestureENS_14SwipeDirectionEj@plt>we want 4889efba04000000be03000000e8
There are 2 fingerprints for the 3 calls
4889efba04000000be03000000e8
and
4889efba04000000be01000000e8
To enable a 3-finger gesture, we'll replace the second parameter 4 with 3 in the hex:
4889efba03000000be03000000e8
4889efba03000000be01000000e8
For peace of mind, we can check that it doesn't match anything else
$ xxd -p -c 0 /usr/bin/kwin_wayland | tr -d '[:space:]' | grep -Eo '4889efba04000000be0[3,1]000000e8'
4889efba04000000be03000000e8
4889efba04000000be03000000e8
4889efba04000000be01000000e8We got 3 entries corresponding to the 3 calls so we're good!
Patching
Now that we have our fingerprints, we can patch the binary. To have a 3-finger gesture instead of 4, we can replace mov $0x4,%edx with mov $0x3,%edx using sed and xxd. Here's the process:
# backup original
sudo cp -a /usr/bin/kwin_wayland /usr/bin/kwin_wayland.bak
# patch ba04 to ba03
xxd -p -c 0 /usr/bin/kwin_wayland | tr -d '[:space:]' | sed 's|4889efba04000000be0\(.\)000000e8|4889efba03000000be0\1000000e8|g' | xxd -r -p > kwin_wayland_patched
# replace binary
sudo mv kwin_wayland_patched /usr/bin/kwin_wayland && sudo chmod 755 /usr/bin/kwin_wayland && sudo chown root:root /usr/bin/kwin_waylandEdit Ubuntu 24.04:
# backup original
sudo cp -a /usr/bin/kwin_wayland /usr/bin/kwin_wayland.bak
# patch ba04 to ba03
xxd -p -c 0 /usr/bin/kwin_wayland | tr -d '[:space:]' | sed 's|4c89e7ba04000000be0\(.\)000000e8|4c89e7ba03000000be0\1000000e8|g' | xxd -r -p > kwin_wayland_patched
# replace binary
sudo mv kwin_wayland_patched /usr/bin/kwin_wayland && sudo chmod 755 /usr/bin/kwin_wayland && sudo chown root:root /usr/bin/kwin_waylandReboot and enjoy!