Last active
August 29, 2015 14:17
-
-
Save tom-galvin/bf47184e95a8535ecb2e to your computer and use it in GitHub Desktop.
Improved xsetwacom preferences helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $# -eq 0 -o "$1" == "--help" ]; then | |
echo "Usage: $(basename $0) device screen [-q]" | |
echo "device The device to set the screen for." | |
echo " Possible devices:" | |
xsetwacom --list devices | sed -n 's/\(.*\)id:.*/ * \1/p' | |
echo "screen The screen to set the given device's region to." | |
echo " Possible screens:" | |
echo " * screen (the entire display)" | |
xrandr -q --current | sed -n 's/^\([^ ]\+\) connected.*/ * \1/p' | |
echo " -q Device and display information are not printed." | |
exit | |
fi | |
DEVICE="$1" | |
SCREEN="$2" | |
ARGS="${@:3}" | |
xsetwacom --set "${DEVICE}" ResetArea | |
read AREASX AREASY AREAX AREAY <<< `xsetwacom --get "${DEVICE}" Area` | |
QUIET=0 | |
for ARG in $ARGS; do | |
case $ARG in | |
-q) | |
QUIET=1 | |
;; | |
esac | |
done | |
[ $QUIET -eq 0 ] && echo "Device '${DEVICE}' area ${AREAX}x${AREAY}." | |
if [ "$SCREEN" = "desktop" ]; then | |
LINE=`xrandr -q --current | sed -n 's/^Screen 0:.*, current \([0-9]\+\) x \([0-9]\+\),.*/\1 \2/p'` | |
read WIDTH HEIGHT <<< "$LINE" | |
else | |
LINE=`xrandr -q --current | sed -n "s/^${SCREEN}"' connected.* \([0-9]\+x[0-9]\++[0-9]\++[0-9]\+\).*/\1/p'` | |
read WIDTH HEIGHT <<< `echo "${LINE}" | sed -n 's/\([0-9]\+\)x\([0-9]\+\)+\([0-9]\+\)+\([0-9]\+\)/\1 \2/p'` | |
fi | |
[ $QUIET -eq 0 ] && echo "Screen '${SCREEN}' size ${WIDTH}x${HEIGHT}." | |
RATIOAREAY=$(( AREAX * HEIGHT / WIDTH )) | |
RATIOAREAX=$(( AREAY * WIDTH / HEIGHT )) | |
if [ "$AREAY" -gt "$RATIOAREAY" ]; then | |
NEWAREAX="$AREAX" | |
NEWAREAY="$RATIOAREAY" | |
else | |
NEWAREAX="$RATIOAREAX" | |
NEWAREAY="$AREAY" | |
fi | |
xsetwacom --set "$DEVICE" Area 0 0 "$NEWAREAX" "$NEWAREAY" | |
if [ "$SCREEN" = "desktop" ]; then | |
xsetwacom --set "$DEVICE" MapToOutput "desktop" | |
else | |
xsetwacom --set "$DEVICE" MapToOutput "$LINE" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment