Configuring Kensington Slimblade in Linux

A few minutes after I post the question I found the answer. Here goes in case anyone needs it (configuration for Mint 18/Ubuntu 16.04):

xinput set-int-prop "Kensington Kensington Slimblade Trackball" "Evdev Middle Button Emulation" 8 0
7 8 9 
xinput set-button-map "Kensington Kensington Slimblade Trackball" 1 8 2 4 5 6 7 3 2
xinput set-int-prop "Kensington Kensington Slimblade Trackball" "Evdev Wheel Emulation" 8 1
xinput set-int-prop "Kensington Kensington Slimblade Trackball" "Evdev Wheel Emulation Button" 8 8
xinput set-int-prop "Kensington Kensington Slimblade Trackball" "Evdev Wheel Emulation Axes" 8 6 7 4 5
xinput set-int-prop "Kensington Kensington Slimblade Trackball" "Evdev Wheel Emulation Timeout" 16 300

Edit

After upgrading for Mint 19 (at home) and Ubuntu 18.04 (at office) I found the configuration above doesn't work. 18.04 uses a different library for these kind of devices (libinput) and even if I reinstalled Evdev some options don't work. After a painful search I found the solution. Create a a file with .conf extension in /usr/share/X11/xorg.conf.d/ folder. In my case I named it 10-slimblade.conf. Put this configuration inside the file:

Section "InputClass"
        Identifier "Kensington Kensington Slimblade Trackball"
        MatchProduct "Kensington Kensington Slimblade Trackball"
        MatchIsPointer "on"
        MatchDevicePath "/dev/input/event*"
        Driver "libinput"
        Option "ButtonMapping" "1 8 2 4 5 6 7 3 2"
        Option "ScrollButton" "8"
        Option "ScrollMethod" "button"
        Option "MiddleEmulation" "on"
EndSection

Restart session, and that's it.


Thanks so much! Just to add on a bit, I was able to find that these are how the buttons are on the trackball:

---------
| 2 | 8 |
---------
| 1 | 3 |
---------

And this is the order they are in the ButtonMapping string:

LeftClick MiddleClick RightClick ScrollUp ScrollDown ? ? Back ?

So, for me, I just wanted right and left on the bottom row, with back top left and middle top right:

Section "InputClass"
    Identifier "Kensington Kensington Slimblade Trackball"
    MatchProduct "Kensington Kensington Slimblade Trackball"
    MatchIsPointer "on"
    MatchDevicePath "/dev/input/event*"
    Driver "libinput"
    Option "ButtonMapping" "1 8 3 4 5 6 7 2 9"
    Option "ScrollButton" "8"
    Option "ScrollMethod" "button"
EndSection

The documentation here is non-existent, so this is what I could piece together by running xev -event mouse.