Well yes, I had to find a shorter title for this post, but it is what it is. The Kensington Expert Trackball, once you try it you'll never come back to use those funky ergonomic and/or gaming mice which now I hated so much by my wrist.
And I use GNU/Linux. So, I gotta say goodbye to KensingtonWorks™, the customization software of my favorite input device, therefore, I had to deal with two problems:
Button remapping: the factory configuration is just not for me, I had to fix that.
Configuration volatility: I decided to use the Bluetooth connection instead of relying on the RF dongle connection. I realized that whenever you lose the connection (i.e. sending the laptop asleep) the configuration is lost. I had to trigger the remapping process once the connection is established again.
Button remapping
Thanks to ArtiomSu we have a solution that runs out of the box with the Kensington Expert Trackball on X11 and using the dongle. I'll go straight to the point. This is the mapping applied after launching the script (which makes use of xinput).
So, the point here that's we have to do a quick adjustment, if you connect the device using bluetooth, the device identifier name is not "Kensington Expert Wireless TB Mouse" but it is "Expert Wireless TB Mouse". See xinput output:
'mkay, just change that, run the script, and if you're on X11 everything will go fine.
Stick with the remapping
First thing first, we have to find the event we want to use to run the mapping script. We will use udevadm for that, including the --environment flag to get also the preset device environment variables:
$ udevadm monitor --environment --udev
And we will go through a lot of udev add events, because our device is using several subsystems (input, bluetooth hid).
see that second entry? We can investigate a specific device and walk back up to the chain on parent devices:
$ udevadm info -ap /devices/virtual/misc/uhid/0005:047D:8019.002E/input/input142/event24
Here's the output and look, there's our mouse:
What matters at this point is the latest binding event, which is what makes our device ready to be used with the Operating System through the bluetooth stack:
Time to write down the udev rule, but first, we need to modify again our script. Udev runs as root, so we have to tell the script to run the commands using the session of the user currently logged in, right? You have to add the env variables XAUTHORITY, DISPLAY and DBUS_SESSION_BUS_ADDRESS replacing the values YOUR_USER (mimnix) and YOUR_USER_UID (1000).
#!/bin/bash
export XAUTHORITY=/home/YOUR_USER/.Xauthority
export DISPLAY=:0
export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/YOUR_USER_UID/bus"
mouse_name="Expert Wireless TB Mouse"
check=$(xinput | grep "$mouse_name")
notify-send "$mouse_name connected!"
if [[ ! -z "$check" ]]; then
echo lol
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 2 4 5 6 7 3 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
xinput set-prop $mouse_id "libinput Middle Emulation Enabled" 1
# xinput set-prop $mouse_id "libinput Drag Lock Buttons" 2
fi
To add some fashion, let's send a cool notification using notify-send. Save and quit, save the script as /usr/local/bin/Kensington_Expert_Setup.sh, chmod +x it.
Let's write the udev rule according to the binding event (remember to replace the YOUR_USER placeholder with your username):
Save it on /etc/udev/rules.d/80-kensington_expert.rules
Run the following command to apply the changes to udev:
$ sudo udevadm control --reload
From now on, enjoy your productivity.
Next steps
I'm a wayland user... I have to abandon xinput and configure the same device using libinput. When I'm done you'll find another Fix'nChips article in this blog. >_