Configuring Kensington Slimblade in Linux

EDIT: recently I bought another trackball (ProtoArc EM03) and had to do this configuration again. So I thought in writing a detailed guide on how to configure any pointing device in Ubuntu based distros that organized the information in this question better. So I did I and as this post is viewed a lot by people trying to configure their pointing devices I thought in sharing it here. You can access it in this link: https://www.reddit.com/r/Trackballs/comments/1fp7upa/how_to_configure_any_pointing_device_on_ubuntu/

—Original question below—

I just got a Kensigton Slimblade Trackball and I’m trying to configure it. I’m adapting it from my old Logitech Marble configuration.

I want the configuration to be:

  • Left-Bottom: Left click
  • Left-Top: Backward
  • Right-Top: Right click and ball scroll lock
  • Right-Bottom: Middle click

The configuration I could set until now is:

  • Left-Bottom: Left click
  • Left-Top: Middle click
  • Right-Top: Right click and ball scroll lock
  • Right-Bottom: Backward

This is my configuration script:

xinput set-int-prop "Kensington Kensington Slimblade Trackball" "Evdev Middle Button Emulation" 8 1   

xinput set-button-map "Kensington Kensington Slimblade Trackball" 1 2 8 4 5 6 7 

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

Before running this script, xev reports button numbers as:

Left-Bottom: 1, Left-Top: 2, Right-Top: 8, Right-Botom: 3

After running this script:

Left-Bottom: 1, Left-Top: 2, Right-Top: 8, Right-Botom: 8

So AFAIK, xinput set-button-map changes button order. In this page, I learned that the 2nd value corresponds to the middle mouse button, and the 8th to the Thumb1 (normally related to backward function). So I thought I should just use number 3 as the 2nd element and 2 as the 8th element like this:

xinput set-button-map "Kensington Kensington Slimblade Trackball" 1 3 8 4 5 6 7 2

but now the top-left button has right-click function and left-bottom is disabled. xev now reports

Left-Bottom: 1, Left-Top: 3, Right-Top: 2, Right-Botom: 8. 

Anyone knows how I set the configuration as I intend ? I’m using Ubuntu 16.04. Thanks.