config.phundrak.com/.local/bin/xsetwacom-my-preferences

92 lines
2.6 KiB
Plaintext
Raw Normal View History

#!/usr/bin/fish
2019-07-21 01:27:31 +00:00
#
# Inspired from:
2019-07-21 01:27:31 +00:00
# https://bitbucket.org/denilsonsa/small_scripts/src/default/xsetwacom_my_preferences.sh
#
#
# Configuration
function set_device
set -g DEVICE "Wacom USB Bamboo PAD Pen stylus"
set -g DEVICETOUCH "Wacom USB Bamboo PAD Finger touch"
set -g WACOMPROPTOUCHSPEED "Device Accel Velocity Scaling"
xsetwacom set "$DEVICE" ResetArea
set AREATOT (xsetwacom get "$DEVICE" Area)
set -g AREAX (echo $AREATOT | awk '{print $3}')
set -g AREAY (echo $AREATOT | awk '{print $4}')
end
function print_help
echo "This script configures a Wacom tablet to one specific monitor,"
echo "or to the entire desktop. In addition, it also redues the tablet"
echo "area in order to keep the same aspect ration as the monitor."
echo
echo "How to run this script? Run one of the following lines:"
set CONNECTED_DISPLAYS (xrandr -q --current | sed -n 's/^\([^ ]\+\) connected .*/\1/p')
set EXEC_NAME (basename (status -f))
for d in $CONNECTED_DISPLAYS
echo " $EXEC_NAME $d"
end
echo " $EXEC_NAME desktop"
exit
end
function set_screen
if count $argv > /dev/null
switch $argv[1]
case "--help"
print_help
case "-h"
print_help
case "-help"
print_help
case '*'
set -g SCREEN $argv[1]
end
else
if test (xrandr --listmonitors | grep "HDMI-1")
set -g SCREEN "HDMI-1"
else
print_help
end
end
if [ "$SCREEN" = "desktop" ]
set -g LINE (xrandr -q --current | sed -n 's/^Screen 0:.*, current \([0-9]\+\) x \([0-9]\+\),.*/\1 \2/p')
else
set -g LINE (xrandr -q --current | sed -n "s/^$SCREEN"' connected \([0-9]\+\)x\([0-9]\+\)+.*/\1 \2/p')
end
echo $LINE | read WIDTH HEIGHT
set -g WIDTH $WIDTH
set -g HEIGHT $HEIGHT
if test -z $WIDTH || test -z $HEIGHT
exit 1
end
end
function adjust_device
set RATIOAREAY (math ceil \($AREAX \* $HEIGHT \/ $WIDTH\))
set RATIOAREAX (math ceil \($AREAY \* $WIDTH \/ $HEIGHT\))
if test $AREAY -gt $RATIOAREAY
set -g NEWAREAX $AREAX
set -g NEWAREAY $RATIOAREAY
else
set -g NEWAREAX $RATIOAREAX
set -g NEWAREAY $AREAY
end
xsetwacom set "$DEVICE" Area 0 0 $NEWAREAX $NEWAREAY
xsetwacom set "$DEVICE" MapToOutput "$SCREEN"
# slow down touchpad
xinput set-float-prop $DEVICETOUCH $WACOMPROPTOUCHSPEED 0.5
# slow down scrolling speed
xsetwacom set $DEVICETOUCH "ScrollDistance" "90"
end
set_device
set_screen
adjust_device