Skip to content

Instantly share code, notes, and snippets.

@languitar
Created January 22, 2021 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save languitar/37ea5903bd66270d97813c3f24442c5d to your computer and use it in GitHub Desktop.
Save languitar/37ea5903bd66270d97813c3f24442c5d to your computer and use it in GitHub Desktop.
Script for fixing the aspect ratio of a wacom table using xsetwacom
#!/bin/bash
set -e
screen_width="$(xrandr | grep current | cut -d ' ' -f 8)"
screen_height="$(xrandr | grep current | cut -d ' ' -f 10 | cut -d , -f 1)"
dev_id="$(xsetwacom list | grep STYLUS | head -n 1 | sed -r 's/^.*id: ([0-9]*) *.*$/\1/')"
xsetwacom set "${dev_id}" ResetArea
device_width="$(xsetwacom get "${dev_id}" Area | cut -d ' ' -f 3)"
device_height="$(xsetwacom get "${dev_id}" Area | cut -d ' ' -f 4)"
new_height="$(echo "${device_width} * ${screen_height} / ${screen_width}" | bc -l | cut -d . -f 1)"
offset=$(( (device_height - new_height) / 2 ))
xsetwacom list | grep -e STYLUS -e ERASER | while IFS="" read -r line || [ -n "$line" ]
do
dev_id="$(echo "${line}" | sed -r 's/^.*id: ([0-9]*) *.*$/\1/')"
xsetwacom set "${dev_id}" Area 0 "${offset}" "${device_width}" "$(( new_height + offset ))"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment