3

I have a mouse with 4 physical buttons (Kensington Slimblade Trackball), let's call them A B C D, plus 3 axes: mouse X, Y, and scroll wheel.

Buttons A and B work out of the box as primary (button 1) and right click (button 3). Pressing A + B together generates a middle click (button 2), which is also great.

Now I'd like to map buttons C and D for my own purposes, but I cannot find how to map button C separately from the A+B emulation.

With the default button map, I get this mapping:

physical buttons:   A C B         D
xinput button-map:  1 2 3 4 5 6 7 8 9 10 11 12 

If I try to map button C to 8 and D to 9, with xinput set-button-map, then pressing A+B is mapped to button 8 too!

physical buttons:   A C B         D
xinput button-map:  1 8 3 0 0 0 0 9
                      ^
                      A+B emulation becomes 8 too!

How can I map button C to an arbitrary button number, while keeping the A+B emulation as button 2?

Should I work on a lower level than Xinput? How? Should I use a different Xinput setting?

Edit: here are the evtest codes for the 4 buttons:

A:
type 4 (EV_MSC), code 4 (MSC_SCAN), value 90001
type 1 (EV_KEY), code 272 (BTN_LEFT), value 1

B:
type 4 (EV_MSC), code 4 (MSC_SCAN), value 90002
type 1 (EV_KEY), code 273 (BTN_RIGHT), value 1

C:
type 4 (EV_MSC), code 4 (MSC_SCAN), value ff000001
type 1 (EV_KEY), code 274 (BTN_MIDDLE), value 1

D:
type 4 (EV_MSC), code 4 (MSC_SCAN), value ff000002
type 1 (EV_KEY), code 275 (BTN_SIDE), value 1
1

1 Answer 1

2

I ended up patching the Xorg evdev driver to add an Emulate3Button option, that configures the button number emitted by the middle button emulation. (I submitted the patch to the mailing list, it should be merged sooner or later.)

Then I added this piece of config:

Section "InputClass"
    Identifier  "SlimBlade Trackball"
    Driver      "evdev"

    Option      "ButtonMapping" "1 8 3 4 5 6 7 9 0 2"
    Option      "Emulate3Button" "10"
EndSection

This makes the middle button emulation emit button number 10, then it maps button C to 8, D to 9, and 10 to 2. Voila.

2
  • How did you do that? I'm having a related issue that might require me, also, to use patch the Xorg driver. Commented Jun 26, 2020 at 7:09
  • If you mean the Emulate3Button (singular) option, my patch was accepted into Xorg, so you can just use it. If you mean how I patched Xorg, I just cloned the sources from GitHub, made my change (in my case adding the Emulate3Button option) and built my custom Deb package. After that, I added documentation to the man page, created a Git patch, and sent it to their mailing list.
    – Tobia
    Commented Jun 27, 2020 at 10:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .