Skip to content

Instantly share code, notes, and snippets.

@Fantailed
Created January 8, 2022 17:34
Show Gist options
  • Select an option

  • Save Fantailed/be5cc5c0076cbfb8e36223681a677f1c to your computer and use it in GitHub Desktop.

Select an option

Save Fantailed/be5cc5c0076cbfb8e36223681a677f1c to your computer and use it in GitHub Desktop.
#! /usr/bin/env bash
tabletId='056A:006D' # check in your tabletprofilesrc
deviceName='HUION Huion Tablet_HS611 Pad pad' # check with `xsetwacom list`
profilerc="$HOME/.config/tabletprofilesrc"
wacomtabletrc="$HOME/.config/wacomtablet-kderc"
# Map parameter names from kcm-wacomtablet config to xsetwacom notation
# Source: https://github.com/KDE/wacomtablet/blob/master/src/kded/xsetwacomproperty.cpp
# You may need to add more.
declare -A param_adaptor=(
['Button1']='Button 1'
['Button2']='Button 2'
['Button3']='Button 3'
['Button4']='Button 8'
['Button5']='Button 9'
['Button6']='Button 10'
['Button7']='Button 11'
['Button8']='Button 12'
['Button9']='Button 13'
['Button10']='Button 14'
['StripLeftUp']='StripLeftUp'
['StripLeftDown']='StripLeftDown'
)
function current_profile() {
awk -F = '/'$tabletId'/ {print $2}' $wacomtabletrc
}
# Get config section for pad (device where express buttons are)
function pad_settings() {
# Get section starting from header until empty line, skip header
hdr="\[$tabletId\]\[$(current_profile)\]\[pad\]"
awk '/'$hdr'/ {found=1}
{
if(found){
ct++;
if(ct==1){next} else {print}
}
}
/^$/{found=0}
' $profilerc
}
function set_pad_settings() {
# For each setting in config block
pad_settings | while read line ; do
# Skip empty line at the end
if [ -z "$line" ]; then
continue
fi
# Read and convert entries
IFS="=" read key value <<< $line
param=${param_adaptor[$key]}
# Set the configs
xsetwacom --set "$deviceName" $param $value
done
notify_profile_change
}
function check_tablet_available() {
[[ $(xsetwacom list) =~ ($deviceName) ]]
}
function notify_profile_change() {
notify-send --icon="input-tablet" --app-name="Tablet Configurator" "Tablet Profile set/updated: $(current_profile)"
}
# ==============================================================================
function main() {
dbus-monitor --profile "type='signal',sender='org.kde.Wacom',interface='org.kde.Wacom'" |
while read -r line; do
if $(check_tablet_available) ; then
set_pad_settings
fi
done
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment