rewrote xsetwacom-my-preferences to fish, automatic detection of HDMI-1
This commit is contained in:
parent
790dfcef0f
commit
4b336fc4e2
@ -1,89 +1,91 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/fish
|
||||
#
|
||||
# From:
|
||||
# Inspired from:
|
||||
# https://bitbucket.org/denilsonsa/small_scripts/src/default/xsetwacom_my_preferences.sh
|
||||
#
|
||||
# CONFIGURATION
|
||||
|
||||
# Set this to your (stylus) device. Find it by running:
|
||||
# xsetwacom --list devices
|
||||
DEVICE='Wacom USB Bamboo PAD Pen stylus'
|
||||
|
||||
# These numbers are specific for each device. Get them by running:
|
||||
# xsetwacom --set "Your device name here" ResetArea
|
||||
# xsetwacom --get "Your device name here" Area
|
||||
AREAX=10690
|
||||
AREAY=6680
|
||||
|
||||
# END OF CONFIGURATION
|
||||
|
||||
|
||||
SCREEN="$1"
|
||||
|
||||
if [ -z "$SCREEN" -o "$SCREEN" = "--help" -o "$SCREEN" = "-help" -o "$SCREEN" = "-h" ]; then
|
||||
echo 'This script configures a Wacom tablet to one specific monitor, or to '
|
||||
echo 'the entire desktop. In addition, it also reduces the tablet area in '
|
||||
echo 'order to keep the same aspect ratio as the monitor.'
|
||||
echo
|
||||
echo 'How to run this script? Run one of the following lines:'
|
||||
CONNECTED_DISPLAYS=`xrandr -q --current | sed -n 's/^\([^ ]\+\) connected .*/\1/p'`
|
||||
for d in desktop $CONNECTED_DISPLAYS; do
|
||||
echo " $0 $d"
|
||||
done
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ "$SCREEN" = "desktop" ]; then
|
||||
# Sample xrandr line:
|
||||
# Screen 0: minimum 320 x 200, current 3286 x 1080, maximum 32767 x 32767
|
||||
|
||||
LINE=`xrandr -q --current | sed -n 's/^Screen 0:.*, current \([0-9]\+\) x \([0-9]\+\),.*/\1 \2/p'`
|
||||
read WIDTH HEIGHT <<< "$LINE"
|
||||
else
|
||||
# Sample xrandr lines:
|
||||
# LVDS1 connected 1366x768+0+312 (normal left inverted right x axis y axis) 309mm x 174mm
|
||||
# VGA1 disconnected (normal left inverted right x axis y axis)
|
||||
# HDMI1 connected 1920x1080+1366+0 (normal left inverted right x axis y axis) 509mm x 286mm
|
||||
|
||||
LINE=`xrandr -q --current | sed -n "s/^${SCREEN}"' connected \([0-9]\+\)x\([0-9]\+\)+.*/\1 \2/p'`
|
||||
read WIDTH HEIGHT <<< "$LINE"
|
||||
fi
|
||||
|
||||
if [ -z "$WIDTH" -o -z "$HEIGHT" ]; then
|
||||
echo "Aborting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# New values respecint aspect ratio:
|
||||
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"
|
||||
xsetwacom --set "$DEVICE" MapToOutput "$SCREEN"
|
||||
|
||||
|
||||
# $ xsetwacom --list devices
|
||||
# Wacom Graphire4 6x8 stylus id: 9 type: STYLUS
|
||||
# Wacom Graphire4 6x8 eraser id: 10 type: ERASER
|
||||
# Wacom Graphire4 6x8 cursor id: 11 type: CURSOR
|
||||
# Wacom Graphire4 6x8 pad id: 12 type: PAD
|
||||
|
||||
# Button mappings only apply to the "pad" device.
|
||||
# The wheel on Graphire4 acts as mouse buttons 4 and 5 (as a mouse wheel)
|
||||
# The buttons on Graphire4 act as mouse buttons 8 and 9
|
||||
|
||||
# Default Area: 0 0 16704 12064
|
||||
# ResetArea
|
||||
#
|
||||
# Other potentially useful parameters:
|
||||
# * Mode: absolute or relative
|
||||
# * Rotate: none, cw, ccw, half
|
||||
# * MapToOutput: "next" (but is buggy), "desktop", or a name from xrandr
|
||||
|
||||
# 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
|
||||
|
Loading…
Reference in New Issue
Block a user