Skip to content

Instantly share code, notes, and snippets.

@badjano
Created November 23, 2021 00:00
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 badjano/e8c369043993a13a88500cfc6f56ad1b to your computer and use it in GitHub Desktop.
Save badjano/e8c369043993a13a88500cfc6f56ad1b to your computer and use it in GitHub Desktop.
Make wacom tablet preserve aspect ratio
SIZE=`xdpyinfo | grep dimensions | sed -r 's/^[^0-9]*([0-9]+x[0-9]+).*$/\1/'`
WIDTH=${SIZE%x*}
HEIGHT=${SIZE#*x}
echo "SIZE: $SIZE"
echo "WIDTH: $WIDTH"
echo "HEIGHT: $HEIGHT"
echo
WACOM_SIZE=`xsetwacom get 11 Area`
IFS=' ' read -r -a WACOM_SIZE_ARRAY <<< "$WACOM_SIZE"
echo $WACOM_SIZE
WACOM_WIDTH=${WACOM_SIZE_ARRAY[2]}
WACOM_HEIGHT=${WACOM_SIZE_ARRAY[3]}
echo "WACOM_WIDTH: $WACOM_WIDTH"
echo "WACOM_HEIGHT: $WACOM_HEIGHT"
echo
S=8
RATIO=$(bc <<< "scale=$S;$HEIGHT/$WIDTH")
echo "RATIO: $RATIO"
echo
NEW_HEIGHT=$(bc <<< "scale=$S;$WACOM_WIDTH*$RATIO")
echo "NEW_HEIGHT: $NEW_HEIGHT"
NEW_Y=$(bc <<< "scale=$S;$WACOM_HEIGHT-$NEW_HEIGHT")
echo "NEW_Y: $NEW_Y"
round_function () {
ret=$( echo "$1" |
awk '{
x=$1
ival = int(x)
# see if fractional part
if (ival == x)
print ival
else {
if (x < 0) {
aval = -x
ival = int(aval)
fraction = aval - ival
if (fraction >= .5)
print int(x) - 1
else
print int(x)
} else {
fraction = x - ival
if (fraction >= .5)
print ival + 1
else
print ival
}
}
}'
)
echo "$ret"
}
ROUND_NEW_Y="$(round_function $NEW_Y)"
echo "ROUND_NEW_Y: $ROUND_NEW_Y"
# xsetwacom set 11 Area 0 24607 65024 40640
xsetwacom set 11 Area 0 $ROUND_NEW_Y $WACOM_WIDTH $WACOM_HEIGHT # 11 is stylus, use "xsetwacom list devices" to get stylus id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment