Xinput button mapping and middle button emulation

Peter Hutterer peter.hutterer at who-t.net
Thu Oct 13 08:33:03 UTC 2016


On Mon, Oct 10, 2016 at 12:35:42PM +0200, Tobia Conforto wrote:
> 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. I'm using Xorg 1:7.7+13ubuntu3 on Linux Mint 18, kernel
> 4.4.0-38-generic.
> 
> Buttons A and B work out of the box as primary (button 1) and right
> click (button 3). Pressing A + B together triggers the middle button
> emulation (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 xinput button-map, I get this mapping:
> 
> 1 A
> 2 C
> 3 B
> 4
> 5
> 6
> 7 D
> ...
> 
> If I try to map button C to 8 and D to 9, with `xinput set-button-map
> "..." 1 8 3 0 0 0 9`, then button C is mapped to 8, but the middle
> button emulation (A+B) gets mapped to button 8 too!
> 
> 1 A
> 8 C, but also A+B!
> 3 B
> 0
> 0
> 0
> 9 D
> 
> How can I map button C to an arbitrary button number (such as 8) while
> keeping the A+B emulation as button 2? Can it be done at the Xinput
> level at all?

not really. middle button emulation is done at the driver level (evdev or
libinput), the button mapping you're changing is handled by the server once
the driver sends an event. the server doesn't know whether you're pressing
the physical button or doing the emulation.

I think with evdev you could use the ButtonMapping option to remap button 2
to some other button but that definitely won't work in libinput.

> 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
> 
> If Xinput cannot do it, does anybody know if I can change the mapping
> between MSC_SCAN and BTN_* without writing a kernel driver?

there isn't anything to remap short of putting a uinput device in between,
but that's a bit excessive.

Cheers,
   Peter


More information about the xorg mailing list