Combine xf86-input-evdev middle button + wheel emulation, Kensington Orbit Trackball

This “mouse” is the best thing since sliced bread. No more wrist bending carpal tunnel syndrome inducing table mice for me. Witness the awesomeness for yourself:

In the interest of keeping price low and functions simple, this thing only has two buttons. I now happened to run into a situation where Xorg’s standard wheel and middle button emulation configuration didn’t cut it, because evdev (as of 2.7.3) doesn’t support wheel emulation on top of middle button emulation.

My previous configuration consisted of having the right button do wheel emulation: holding it down and moving the trackball would scroll the document up and down. Single click gives the regular context menu popup etc. Apparently this works for about 99% of the time because I didn’t have a problem until I needed the right button held down for a Tcl/Tk application context menu (hi git gui!).

After finding out I can’t just hold both buttons down (middle button emulation) and scroll with it (wheel emulation on top of middle button emulation) — see above –, doing plenty of remapping logic exercises finally resulted in a configuration that works. Enter third button emulation into the picture, which will replace middle button emulation.

Here’s the final configuration (replace 11 with your device id from “xinput list”):

$ xinput list-props 11
Device 'Kensington      Kensington USB/PS2 Orbit':
	Device Enabled (134):	1
	Coordinate Transformation Matrix (136):	1.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 1.000000
	Device Accel Profile (261):	0
	Device Accel Constant Deceleration (262):	1.000000
	Device Accel Adaptive Deceleration (263):	1.000000
	Device Accel Velocity Scaling (264):	10.000000
	Device Product ID (252):	1149, 4130
	Device Node (253):	"/dev/input/event6"
	Evdev Axis Inversion (560):	0, 0
	Evdev Axes Swap (562):	0
	Axis Labels (563):	"Rel X" (144), "Rel Y" (145)
	Button Labels (564):	"Button Left" (137), "Button Unknown" (559), "Button Right" (139), "Button Wheel Up" (140), "Button Wheel Down" (141)

We disable middle button emulation, because when enabling third button emulation there is no more use for it.

	Evdev Middle Button Emulation (565):	0
	Evdev Middle Button Timeout (566):	50

Hello third button emulation. Because right mouse button will be occupied for wheel emulation, which requires a real non-emulated button, this will be our new right-click that can be held down. Thing to watch out here for is the timeout. I’m finding 400ms delay is about right. Default of 1000ms was definitely annoyingly long. 200ms is too short, you will have trouble selecting text without getting a right-click.

Notice I’m setting the emulated button to “2”. This is for getting apps to keep functioning in a regular expected way.

	Evdev Third Button Emulation (567):	1
	Evdev Third Button Emulation Timeout (568):	400
	Evdev Third Button Emulation Button (569):	2
	Evdev Third Button Emulation Threshold (570):	20

Wheel emulation is all regular stuff, except for setting the emulated button to “3”.

	Evdev Wheel Emulation (571):	1
	Evdev Wheel Emulation Axes (572):	0, 0, 4, 5
	Evdev Wheel Emulation Inertia (573):	10
	Evdev Wheel Emulation Timeout (574):	200
	Evdev Wheel Emulation Button (575):	3
	Evdev Drag Lock Buttons (576):	0

And here’s the final piece of the puzzle, reversing buttons “2” and “3” mapping. This makes sure the wheel emulation ends up on the real, non-emulated button.

leho@s9 ~ $ xinput get-button-map 11
1 3 2 4 5 

To sum it all up, problem solved here is getting a right-click that can be held, while still maintaining wheel emulation, with a 2-button mouse.

Everything in terms of /etc/X11/xorg.conf.d:

leho@s9 ~ $ cat /etc/X11/xorg.conf.d/51-kensington.conf
Section "InputClass"
    Identifier "My Kensington Orbit Trackball"
    Driver "evdev"
    Option "ButtonMapping" "1 3 2 4 5"
    Option "EmulateMiddleButton" "False"
    Option "EmulateThirdButton" "True"
    Option "EmulateThirdButtonButton" "2"
    Option "EmulateThirdButtonMoveThreshold" "0"
    Option "EmulateThirdButtonTimeout" "400"
    Option "EmulateWheel" "True"
    Option "EmulateWheelButton" "3"
    MatchProduct "Kensington USB/PS2 Orbit"
EndSection

EDIT

One more parameter needs to be tuned. Default setting of EmulateThirdButtonMoveThreshold 20 disturbs selecting text and drag-n-dropping stuff with the left. You can safely set the threshold to 0, since with a trackball there is pretty much no involuntary movement of the cursor after clicking, like there can be with the regular mouse connected to the whole palm of your hand. 51-kensington.conf has been updated accordingly.

UPDATE Jun 18th, 2015

I’m still happily rolling with the Orbit today, on xorg-server-1.16.4, evdev-2.9.1. Future proof, yeah baby yeah.