Monday, September 23, 2013

Finding Button IDs for xsetwacom for Wacom Bamboo Fun Pen & Touch 2

Again, it took me a while to figure this out, so I'm writing it down.

Short story

Up to Fedora 19, Gnome Control Center and libwacom do not allow to configure all 4 express keys of this tablet for some unknown reason. One must use xsetwacom. And one must know the ids of each express key which can be retreived using xinput test-xi2, pressing the keys and writing down the "detail: N" line that is printed to the console.


Gnome Control Center and Libwacom

I've been trying to convice Gnome Control Center (3.8) to let me map actions to my tablet's express keys. At first it didn't recognize the tablet as a tablet with buttons. The reason is that it relies on libwacom and that libwacom uses *.tablet files that describe how tablets look like. Mine was identified as a generic wacom. So I started writing a description for my tablet.

I created /usr/share/libwacom/bamboo-wireless-16fg-6x8.tablet like this:
# Wacom
# Bamboo Wireless Fun Pen&Touch Medium
# CTH-670S


[Device]
Name=Wacom Wireless Bamboo Fun Pen & Touch 6x8
DeviceMatch=usb:056a:0084
#Class=Bamboo2
Width=8
Height=6
Layout=bamboo-2fg-6x8.svg


[Features]
Reversible=True
Stylus=True
Buttons=4
Touch=True

[Buttons]
Left=A;B;C;D

Then I reset the stored configuration (this is kind of brute-force):
$>dconf reset -f /org/gnome/settings-daemon/peripherals/wacom/

Then Gnome Control Center lets me configure my buttons... wait... only 3 of them! If I map them to A, B, C and D keystrokes and press the express keys from top to bottom in a console, I get "ADC". Notice the strange order and the lack of B? Time to start digging xsetwacom, xinput, etc...

xev

I ran xev and to see if it was aware of express key events. It detected "A", "D" and "C". I guess xev receives events once they've been digested by Xorg/DisplayManager...

xsetwacom

I first reset all wacom-related dconf settings like shown above. Then I na├»vely ran 
xsetwacom --set "Wacom Wireless Receiver Finger pad" Button 1 "key A"
xsetwacom --set "Wacom Wireless Receiver Finger pad" Button 2 "key B"
xsetwacom --set "Wacom Wireless Receiver Finger pad" Button 3 "key C"
xsetwacom --set "Wacom Wireless Receiver Finger pad" Button 4 "key D"
Unsupported offset into 'Wacom Button Actions' property.

What? Dude I'm quite sure I have 4 buttons! I pressed buttons and only got "AC"... The button numbering is definitely weird!

xinput

I turned the tablet off and back on so that xsetwacom forgets the settings.
I used "xinput test-xi2" and noticed that all four express keys triggered events when pressed! Hurray!

The output looks like this when pressing express keys from top to bottom:
EVENT type 15 (RawButtonPress)
    device: 2 (16)
    detail: 1
    valuators:
    flags: 
          3: 0.00 (0.00)
          4: 0.00 (0.00)
          5: 0.00 (0.00)

EVENT type 15 (RawButtonPress)
    device: 2 (16)
    detail: 9
    valuators:
    flags: 
          3: 0.00 (0.00)
          4: 0.00 (0.00)
          5: 0.00 (0.00)

EVENT type 15 (RawButtonPress)
    device: 2 (16)
    detail: 8
    valuators:
    flags: 
          3: 0.00 (0.00)
          4: 0.00 (0.00)
          5: 0.00 (0.00)

EVENT type 15 (RawButtonPress)
    device: 2 (16)
    detail: 3
    valuators:
    flags: 
          3: 0.00 (0.00)
          4: 0.00 (0.00)
          5: 0.00 (0.00)

And tadaaa, the "detail" line for the first and fourth button match the behaviour observed when using xsetwacom. This is the id that you must use with the "xsetwacom --set device_id Button N" command.

This lets one tie actions to express keys. However, the setting is forgotten when the device is turned off or unplugged. A script might help. Or some udev rule. But it would be good if the Gnome Control Center could do this for me. I'm still investigating.

2 comments:

  1. thanks this was really helpful in solving a problem with the wacom settings panel (GUI) that comes with Ubuntu, not allowing mapping ctrl and shift keys to a button on the intuos 4. This also helped https://github.com/linuxmint/cinnamon-control-center/issues/76

    ReplyDelete
  2. Good god, what in the world? Thank you so much, no idea how I would have figured these button numbers out on my own

    ReplyDelete