Skip to content

Instantly share code, notes, and snippets.

@jigpu
Last active September 21, 2020 17:19
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jigpu/fde784840ba5731726e7382952b0d5ed to your computer and use it in GitHub Desktop.
Save jigpu/fde784840ba5731726e7382952b0d5ed to your computer and use it in GitHub Desktop.
Script to remap pad buttons on consumer (Bamboo) Wacom devices to be compatible with GNOME
#!/bin/bash
# Consumer Wacom devices (i.e. most Bamboo devices like the Bamboo Pen & Touch,
# Bamboo Fun, Bamboo Connect; and the newer non-pro Intuos devices like the
# Intuos Draw and Intuos Art) have a hardware button mapping that is incompatible
# with GNOME. This incompatibility prevents the GNOME Control Center's Wacom panel
# from working properly, and often also prevents at least one button from working
# entirely.
#
# This script can be used to discover a software mapping that can be applied by
# the xf86-input-wacom driver to allow these devices to work peroperly. When
# run with the ID of a Bamboo pad device (use xsetwacom list if unsure), it will
# reset any mapping that may be present and then ask you to press each tablet
# button in turn followed by 'q' to quit. After pressing all the buttons and
# pressing 'q', the buttons will be remapped and the script will display what
# xsetwacom commands were necessary. The buttons should work properly within
# the GNOME Control Center now.
#
# The changes made by this script are temporary and will be undone if the tablet
# is disconnected and reconnected or if the X server is restarted. To make the
# changes more permanant, you should copy/paste the displayed xorg.conf.d
# configuration snippet into a new file at the listed path so that it can be
# automatically applied whenever the tablet is connected or when the X server
# restarts.
#
# For more information, please visit the following URL:
# http://linuxwacom.sourceforge.net/wiki/index.php?title=Consumer_Tablet_ExpressKey_Mapping_Issue
if [[ $# -ne 1 ]]; then
echo "Usage: $0 <pad device id>"
exit 1
fi
ID=$1
NAME=$(xsetwacom list | grep "id: $ID" | awk 'BEGIN {FS="[a-z]+: "} {gsub(/[ \t]+$/,"",$1); print $1}')
TYPE=$(xsetwacom list | grep "id: $ID" | awk 'BEGIN {FS="[a-z]+: "} {gsub(/[ \t]+$/,"",$3); print $3}')
if [[ "$NAME" == "" ]]; then
echo "No wacom device with id '${ID}' known."
exit 2
elif [[ "$TYPE" != "PAD" ]]; then
echo "'${NAME}' is not a wacom pad device (${TYPE})."
exit 3
fi
echo "Overriding default mapping..."
for B in {1..9}; do
xsetwacom set "$NAME" button $B key $B 2> /dev/null
done
N=1
MAP=()
while true; do
echo "Press button ${N} on ${NAME} or 'q' when finished"
read -s -n 1 X > /dev/null
if [[ "$X" == 'q' ]]; then
break
fi
MAP[$N]=$X
N=$(($N+1))
done
echo
echo "Setting up a GNOME-compatible mapping with the following commands:"
for PHYSICAL in ${!MAP[*]}; do
LOGICAL=${MAP[$PHYSICAL]}
echo "xsetwacom set \"$NAME\" button ${LOGICAL} button +${PHYSICAL}"
xsetwacom set "$NAME" button ${LOGICAL} button +${PHYSICAL}
done
echo
echo "To have these settings apply automatically, please add the following"
echo "to /etc/X11/xorg.conf.d/52-wacom-options.conf and then logout:"
echo "---------- [ cut here ] ----------"
echo "Section \"InputClass\""
echo " Identifier \"$NAME GNOME compatibility\""
echo " MatchDriver \"wacom\""
echo " MatchProduct \"$NAME\""
echo
for PHYSICAL in ${!MAP[*]}; do
LOGICAL=${MAP[$PHYSICAL]}
# wacom option syntax uses semi-physical button numbers
# so we need to convert the logical numbers first
if [[ $LOGICAL -ge 4 ]]; then
LOGICAL=$(($LOGICAL - 4))
fi
echo " Option \"Button${LOGICAL}\" \"${PHYSICAL}\""
done
echo "EndSection"
echo "---------- [ cut here ] ----------"
@OMGChase
Copy link

Hello.

I'm very new to Linux and trying to get my Wacom Intuos Draw (Labelled as "Wacom Intuos S 2 Pad pad" in xsetwacom) to work with the correct buttons in GNOME. I can set buttons with xsetwacom, but for some reason, cannot set the button as " [ " (which in most programs changes the brush size), but it sets it fine in the GNOME interface which is why I'm trying your script.

My question is how do i run this code with my Wacom ID? If i just execute the .sh i get the following error which i guess is it trying to find the ID which I don't know how to input:

wacom-gnome-compat.sh: 29: [[: not found
wacom-gnome-compat.sh: 38: [[: not found
wacom-gnome-compat.sh: 41: [[: not found
Overriding default mapping...
wacom-gnome-compat.sh: 52: Syntax error: "(" unexpected

I read the sh file and it says "run with the ID of a Bamboo pad device" but not sure how to do that and searching for it doesn't bring me any results I need.

Sorry if this is a dumb question, but I'm trying to switch from Windows to Linux and not used to having to run everything through the terminal.

Thanks

@jigpu
Copy link
Author

jigpu commented Sep 21, 2020

The various [[: not found errors that you're seeing indicate that you are somehow running the script with the wrong shell. If you are using something like sh wacom-gnome-compat.sh to run the script, that would explain the problem. This script is not compatible with the "sh" shell -- it must be run with the "bash" shell instead. The recommended way to run any shell script (to avoid this problem) is to use the chmod command to mark the script as executable, and then omit the "sh", "bash", "python", etc. prefix entirely -- the OS will automatically use whatever shell the script mentions on its very first line (you'll notice this script's first line indicates bash).

Please try the following instructions:

  1. Run chmod +x wacom-gnome-compat.sh to mark the script as executable
  2. Run xsetwacom list to see a list of connected tablets and their IDs. Take note of the ID number for the pad device. For example, on my system, I would remember the number 15:
$ xsetwacom list
Wacom Intuos Pro M Pen stylus   	id: 12	type: STYLUS    
Wacom Intuos Pro M Pen eraser   	id: 13	type: ERASER    
Wacom Intuos Pro M Pen cursor   	id: 14	type: CURSOR    
Wacom Intuos Pro M Pad pad      	id: 15	type: PAD       
Wacom Intuos Pro M Finger touch 	id: 16	type: TOUCH 
  1. Run ./wacom-gnome-compat.sh 15 (obviously replacing "15" with whatever number you got above)

That should get things up and running 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment