Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save filviu/32af238c4f5a4230ba2676d697c665af to your computer and use it in GitHub Desktop.
Save filviu/32af238c4f5a4230ba2676d697c665af to your computer and use it in GitHub Desktop.
Remapping Kensington Expert Trackball Buttons with wayland
# Button remap for Kensington Expert Wireless Trackball to:
# BACK MIDDLE
# O
# LEFT RIGHT
# save this file under '/etc/udev/hwdb.d/90-kensington-expert-trackball-remap.hwdb'
# run `sudo systemd-hwdb update` and reboot
#
# source: https://askubuntu.com/questions/1145057/remapping-mouse-buttons-to-keyboard-keys
# and: https://gist.github.com/dnlvgl/d16fd822bc90dcdaaae262a76fad884e
#
# /sys/class/input/event11/device/id/bustype:0003
# /sys/class/input/event11/device/id/product:8018
# /sys/class/input/event11/device/id/vendor:047d
# /sys/class/input/event11/device/id/version:0111
evdev:input:b0003v047Dp8018e0111*
ID_INPUT_KEY=1
KEYBOARD_KEY_90001=272
KEYBOARD_KEY_90002=273
KEYBOARD_KEY_90003=275
KEYBOARD_KEY_90004=274

You only need one:

  • 90-kensington-expert-trackball-remap.hwdb is for wayland
  • Kensington_Expert_Setup.sh for X11

The x11 script at least on kubunt has a weird effect - it reverts scroll direction. If I go to KDE settings and switch to invert, apply, normal, apply it returns to normal.

#!/usr/bin/env bash
# for x11
# source: https://github.com/ArtiomSu/kensington-expert-trackball-linux-config.
#
# xinput list
# Default layout
# "Button Middle" "Button Wheel Up" "Button Horiz Wheel Left" "Button Side"
# 2 4 6 8 "Button Extra"
# 9
# "Button Left" "Button Wheel Down" "Button Horiz Wheel Right" "Button Right"
# 1 5 7 3
# "Button Left" "Button Middle" "Button Right" "Button Wheel Up" "Button Wheel Down" "Button Horiz Wheel Left" "Button Horiz Wheel Right" "Button Side" "Button Extra"
# 1 2 3 4 5 6 7 8 9
#
mouse_name="Kensington Expert Wireless TB Mouse"
check=$(xinput | grep "$mouse_name")
if [[ ! -z "$check" ]]; then
mouse_id=$(xinput | grep "$mouse_name" | sed 's/^.*id=\([0-9]*\)[ \t].*$/\1/')
# swap right and back button then swap middle and back button
xinput set-button-map $mouse_id 1 8 3 4 5 6 7 2 9
# enable better scrolling
xinput set-prop $mouse_id "libinput Natural Scrolling Enabled" 1
# disable acceliration for the ball
xinput set-prop $mouse_id "libinput Accel Profile Enabled" 0, 1
# allow scrolling by holding middle mouse button and using the ball to scroll ( really smooth and fast ).
xinput set-prop $mouse_id "libinput Scroll Method Enabled" 0, 0, 1
# allow the remmaped middle mouse to be used for middle mouse scroll
xinput set-prop $mouse_id "libinput Button Scrolling Button" 3
fi
# read more here https://askubuntu.com/questions/492744/how-do-i-automatically-remap-buttons-on-my-mouse-at-startup
# Default properties, so if you change yours around alot you can refer here for default config.
# xinput list-props
# Device 'Kensington Expert Wireless TB Mouse':
# Device Enabled (153): 1
# Coordinate Transformation Matrix (155): 1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
# libinput Natural Scrolling Enabled (289): 0
# libinput Natural Scrolling Enabled Default (290): 0
# libinput Scroll Methods Available (291): 0, 0, 1
# libinput Scroll Method Enabled (292): 0, 0, 0
# libinput Scroll Method Enabled Default (293): 0, 0, 0
# libinput Button Scrolling Button (294): 2
# libinput Button Scrolling Button Default (295): 2
# libinput Button Scrolling Button Lock Enabled (296): 0
# libinput Button Scrolling Button Lock Enabled Default (297): 0
# libinput Middle Emulation Enabled (298): 0
# libinput Middle Emulation Enabled Default (299): 0
# libinput Accel Speed (300): 0.000000
# libinput Accel Speed Default (301): 0.000000
# libinput Accel Profiles Available (302): 1, 1
# libinput Accel Profile Enabled (303): 1, 0
# libinput Accel Profile Enabled Default (304): 1, 0
# libinput Left Handed Enabled (305): 0
# libinput Left Handed Enabled Default (306): 0
# libinput Send Events Modes Available (274): 1, 0
# libinput Send Events Mode Enabled (275): 0, 0
# libinput Send Events Mode Enabled Default (276): 0, 0
# Device Node (277): "/dev/input/event9"
# Device Product ID (278): 1149, 32792
# libinput Drag Lock Buttons (307): <no items>
# libinput Horizontal Scroll Enabled (308): 1
@filviu
Copy link
Author

filviu commented Apr 25, 2024

90003   90004
      O
90001   90002

BTN_LEFT - 272
BTN_RIGHT - 273

then

BTN_MIDDLE - 274
BTN_SIDE - 275 (back)

@filviu
Copy link
Author

filviu commented Apr 25, 2024

Either run sudo systemd-hwdb update and reboot (or run sudo udevadm control --reload-rules && sudo udevadm trigger).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment