Wacom Intuos 5 M configuration script for Linux Mint

Introduction

As an indie developer that goes solo, I have a drawing tablet which I mostly use to draw textures. The one I have is very good and from a reputable brand, it’s a Wacom Intuos 5 M tablet.
intuos5Med

Unfortunately this hardware device doesn’t have official support for Linux. There are, however, community maintained drivers, but it can be a little bit difficult to make them work properly. Linux Mint 17.3 (or rather, Cinnamon) comes bundled with a tablet configuration tool. Unfortunately it doesn’t seem to work properly for me.

The device sports 8 button for shortcuts, and a wheel with 4 different functions which can be used to zoom in or out, rotate left and right or increase and decrease the brush’s size. It also comes with a pen that has 2 buttons, a tip for drawing and another one that acts as an eraser. Both tips have pressure sensitivity.

Now the pen works great, both tips and the pressure I apply are registered properly. What doesn’t work is the buttons and wheel on the pad. I want to be able to achieve the following :

  • For the eight buttons
    • Button 1 : Help Button (press F1)
    • Button 2 : Save (press Ctrl + S)
    • Button 3 : Redo (press Ctrl + Shift + Z)
    • Button 4 : Undo (press Ctrl + Z)
    • Button 5 : Add a new layer (Press Insert)
    • Button 6 : Cut (press Ctrl + X)
    • Button 7 : Copy (press Ctrl + C)
    • Button 8 : Paste (press Ctrl + V)
  • For the wheel
    • The central button has to switch between the different modes, the LED has to swap when pressed and a visual CUE has to appear on-screen when the mode changes
    • The four different modes are
      • Zoom In/out (Ctrl + + and Ctrl + -)
      • Increase/Decrease Brush Size ( [ and ] )
      • Rotate Left/Right ( Ctrl + [ and Ctrl + ])
      • Change Layer (PageUp and PageDown)

xev and xsetwacom

I use a spanish keyboard, so some of the keys I require need of a modifier key, like Control or AltGr. As an example, in order to get [ I need to hold AltGr while pressing the key.

teclatESP

In order to find out the name the X server gives to those keys I can use xev which is a tool that displays all X events, and amongst them, input events. I simply fire up the program in a terminal and I press the buttons that I need to check.

$ xev -event keyboard
Outer window is 0x4c00001, inner window is 0x4c00002

KeymapNotify event, serial 24, synthetic NO, window 0x0,
keys: 0 0 0 0 16 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

KeyRelease event, serial 25, synthetic NO, window 0x4c00001,
root 0x2eb, subw 0x0, time 14632163, (-721,140), root:(141,594),
state 0x10, keycode 36 (keysym 0xff0d, Return), same_screen YES,
" XLookupString gives 1 bytes: (0d) "
XFilterEvent returns: False

KeyPress event, serial 28, synthetic NO, window 0x4c00001,
root 0x2eb, subw 0x0, time 14635907, (-122,416), root:(740,870),
state 0x10, keycode 108 (keysym 0xfe03, ISO_Level3_Shift), same_screen YES,
XKeysymToKeycode returns keycode: 92
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False

KeyRelease event, serial 28, synthetic NO, window 0x4c00001,
root 0x2eb, subw 0x0, time 14636051, (-122,416), root:(740,870),
state 0x90, keycode 108 (keysym 0xfe03, ISO_Level3_Shift), same_screen YES,
XKeysymToKeycode returns keycode: 92
XLookupString gives 0 bytes:
XFilterEvent returns: False

So that modifier key is known as ISO_Level3_Shift.

Now, xsetwacom is the tool that is used to configure your tablet. We can check if the device is recognized by our machine by simply running.

$ xsetwacom --list devices
Wacom Intuos5 M Pen stylus id: 11 type: STYLUS
Wacom Intuos5 M Pad pad id: 12 type: PAD
Wacom Intuos5 M Pen eraser id: 17 type: ERASER
Wacom Intuos5 M Pen cursor id: 18 type: CURSOR

I have here four devices, but here I’m only interested on the second one, my pad which is called Wacom Intuos5 M Pad pad. We can also get a full list of parameters that can be defined with this tool, but I’ll only be using three of them : Button (a button press), AbsWheelUp (the wheel scrool counter-clockwise) and AbsWheelDown (the wheel scrool clockwise). Buttons are numbered 1 to 3 then 8 to 13, I don’t know why this order is used. Button 1 is my wheel modifier. So in order to have my Button 2 perform a Paste the following command would be used.

$ xsetwacom set "$DEVICE" Button 2 "key +Ctrl C -Ctrl"

The key description can be interpreted as “press and hold control, then press C, then release Control”.

LED change and intensity

The LED can be swapped and its intensity can be modified. This is achieved with two files :

  • status_led0_select swaps the LED, it goes from 0 to 3
  • status0_luminance swaps the intensity, goes from 0 to 255

Both files are under /sys/bus/hid/devices/*/wacom_led

Of course, these files are read-only for any user other than root, so we either have to change this in /etc/rc.local or we’ll have to be elevate our rights everytime we need to change it with sudo or something similar.

Editing /etc/rc.local

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
/bin/chmod 666 /sys/bus/usb/devices/*/wacom_led/status_led0_select
/bin/chmod 666 /sys/bus/usb/devices/*/wacom_led/status0_luminance
exit 0

And in case we have never used rc.local before we need to give it execution rights. These changes will be effective after a reboot.

$ sudo chmod +x /etc/rc.local

The script

I have adapted a script I found online to automate the whole process. This script is heavily based off this post on Ubuntu Forums.

#!/bin/bash

## Touch ring toggle script
##
## Bind Button 1 (button center of touch ring) to the script.
##
## To allow script to select mode status LEDs edit rc.local to change root
## only permissions on the sysfs status_led0_select file:
## gksudo gedit /etc/rc.local
## Add the following comment and command (before 'exit 0'):
## # Change permissions on status_led0_select file so being root isn't
## # required to switch Wacom touch ring mode status LEDs.
## /bin/chmod 666 /sys/bus/usb/devices/*/wacom_led/status_led0_select
##
## Intuos - status_led0_select file = the left (only) ring status LEDs.
## Cintiq - status_led1_select = the left ring; status_led0_select =
## the right ring status LEDs. Same for the touchstrips.
##
## For mode state notification use:
## sudo apt-get install libnotify-bin
## Otherwise comment (#) out the notify-send lines. If libnotify-bin
## installed see 'man notify-send' for details.

# check if mode_state file exists, if not create it and set to 0
if [ ! -f /tmp/mode_state ]; then
echo 0 > /tmp/mode_state
fi

# read mode state value from temporary file
MODE=`cat /tmp/mode_state`

# select touch ring mode status LED for current mode state
LED_FILE=`find -H /sys/bus/hid/devices/* |grep status_led0_select`
if [ ! -w "$LED_FILE" ]
then
gksudo chmod 666 "$LED_FILE"
fi

LED_INTENSITY=`find -H /sys/bus/hid/devices/* |grep status0_luminance`
if [ ! -w "$LED_INTENSITY" ]
then
gksudo chmod 666 "$LED_INTENSITY"
fi

echo $MODE > $LED_FILE
echo 255 > $LED_INTENSITY

# for DEVICE use the pad "device name" from 'xinput list'
DEVICE="Wacom Intuos5 M Pad pad"

xsetwacom set "$DEVICE" Button 1 "key Ctrl shift Alt w"
xsetwacom set "$DEVICE" Button 2 "key F1"
xsetwacom set "$DEVICE" Button 3 "key Ctrl s"
xsetwacom set "$DEVICE" Button 8 "key Ctrl shift z"
xsetwacom set "$DEVICE" Button 9 "key Ctrl z"
xsetwacom set "$DEVICE" Button 9 "key Ctrl z"
xsetwacom set "$DEVICE" Button 10 "key Insert"
xsetwacom set "$DEVICE" Button 11 "key Ctrl x"
xsetwacom set "$DEVICE" Button 12 "key Ctrl c"
xsetwacom set "$DEVICE" Button 13 "key Ctrl v"

# set touch ring function option and notification for the 4 toggled modes
if [ "$MODE" == 0 ]; then
xsetwacom set "$DEVICE" AbsWheelUp "key Ctrl -" # zoom in
xsetwacom set "$DEVICE" AbsWheelDown "key Ctrl +" # zoom out
notify-send -t 1500 "Mode 1: Zoom In/Out"
elif [ "$MODE" == 1 ]; then
xsetwacom set "$DEVICE" AbsWheelUp "Key +ISO_Level3_Shift dead_grave -ISO_Level3_Shift" # increase brush radius (must be mapped in GIMP)
xsetwacom set "$DEVICE" AbsWheelDown "Key +ISO_Level3_Shift plus -ISO_Level3_Shift" # decrease brush radius (must be mapped in GIMP)
notify-send -t 1500 "Mode 2: Increase or decrease brush size"
elif [ "$MODE" == 2 ]; then
xsetwacom set "$DEVICE" AbsWheelUp "Key Ctrl +ISO_Level3_Shift dead_grave -ISO_Level3_Shift" # rotate right
xsetwacom set "$DEVICE" AbsWheelDown "Key Ctrl +ISO_Level3_Shift plus -ISO_Level3_Shift" # rotate left
notify-send -t 1500 "Mode 3: Rotate Left/Right"
elif [ "$MODE" == 3 ]; then
xsetwacom set "$DEVICE" AbsWheelUp "key PgUp" # select previous layer
xsetwacom set "$DEVICE" AbsWheelDown "key PgDn" # select next layer
notify-send -t 1500 "Mode 4: Select previous or next layer"
fi

# toggle button increment counter
MODE=$((MODE += 1))

# set next mode state
if (( "$MODE" > 3 )); then # roll over to 0, only 4 mode states available
echo 0 > /tmp/mode_state
else
echo $MODE > /tmp/mode_state
fi

When the button 1 (the wheel button) is pressed, the key combination Ctrl+Shift+Alt+W is pressed. I have mapped this key combination to the execution of the script itself, so in order to initialise my configuration I can either set this script to run on XInit or by doing that key combination. Every time it’s pressed the wheel mode is swapped, and a little notification appears.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*