Created
December 23, 2019 22:47
-
-
Save odysseywestra/22036d55a0fa6d6f4cfa22dfba1e874f to your computer and use it in GitHub Desktop.
Device Setup script for HP x360 Envy 15-cp0xxx
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 | |
# Script to automate devices settings. | |
#: | |
#: Usage: bash ./set-devices [Options] | |
#: | |
#: Options: | |
#: --help Show this message and exit. | |
#: --rotate Rotate Screen to the options below. | |
#: left Rotate Screen left: Disables Keyboard and Touchpad. | |
#: right Rotate Screen Right: Disables Keyboard and Touchpad. | |
#: inverted Rotate Screen Upsidedown: DIsables Keyboard and Touchpad. | |
#: normal Rotate Screen Normal: Enables Keyboard and Touchpad | |
#: --toggle Toggles devices on or off. | |
#: keyboard Toggles Keyboard. | |
#: touchpad Toggles Touchpad. | |
#: touchscreen Toggles Touchscreen. | |
#: --pen Set Pen settings: Used during startup. | |
#: --reset Re-enables all devices and resets screen orintation to Normal | |
#: | |
#: Script written by Albert Westra([email protected]) | |
#: Liscense: CC-0/Public Domain license | |
#: | |
# Stylus Pens | |
stylus="ELAN0732:00 04F3:2650 stylus" | |
eraser="ELAN0732:00 04F3:2650 eraser" | |
# Built-in Peripherals | |
keyboard="AT Translated Set 2 keyboard" | |
touchpad="SynPS/2 Synaptics TouchPad" | |
touchscreen="ELAN0732:00 04F3:2650" | |
#screen | |
screen="eDP" | |
#Script Icon | |
icon="/usr/share/icons/Pop/scalable/devices/video-display-symbolic.svg" | |
set_pen(){ | |
xsetwacom --set $stylus Suppress 15 | |
xsetwacom --set $eraser Suppress 15 | |
} | |
toogle_peripherals(){ | |
device="$2" | |
name="$1" | |
if [ -f "/tmp/device-disable-$device" ]; then | |
xinput enable "$device" | |
rm "/tmp/device-disable-$device" | |
device_notify "$name is enabled" | |
else | |
xinput disable "$device" | |
touch "/tmp/device-disable-$device" | |
device_notify "$name is disabled" | |
fi | |
} | |
device_notify(){ | |
echo "$1" | |
notify-send -i "$icon" "Devices Settings" "$1" | |
} | |
#normal,inverted,left,right | |
rotate_screen(){ | |
echo "$keyboard" | |
echo "$touchpad" | |
rotation=$1 | |
if [ $rotation = "normal" ]; then | |
device_notify "Rotating Screen $rotation" | |
xrandr --output $screen --rotate $rotation | |
device_notify "Keybaord and Touchpad Enabled" | |
xinput enable "$keyboard" | |
xinput enable "$touchpad" | |
elif [ $rotation = "inverted" ]; then | |
device_notify "Rotating Screen $rotation" | |
xrandr --output $screen --rotate $rotation | |
device_notify "Keybaord and Touchpad Disabled" | |
xinput disable "$keyboard" | |
xinput disable "$touchpad" | |
elif [ $rotation = "left" ]; then | |
device_notify "Rotating Screen $rotation" | |
xrandr --output $screen --rotate $rotation | |
device_notify "Keybaord and Touchpad Disabled" | |
xinput disable "$keyboard" | |
xinput disable "$touchpad" | |
elif [ $rotation = "right" ]; then | |
device_notify "Rotating Screen $rotation" | |
xrandr --output $screen --rotate $rotation | |
device_notify "Keybaord and Touchpad Disabled" | |
xinput disable "$keyboard" | |
xinput disable "$touchpad" | |
else | |
device_notify "No Parameters given." | |
fi | |
} | |
case $1 in | |
--help*) | |
grep '^#:' $0 | cut -d ':' -f 2-100 | |
exit 0 | |
;; | |
--rotate*) | |
case $2 in | |
left*) | |
rotate_screen $2 | |
;; | |
right*) | |
rotate_screen $2 | |
;; | |
inverted*) | |
rotate_screen $2 | |
;; | |
normal*) | |
rotate_screen $2 | |
;; | |
esac | |
;; | |
--toggle*) | |
case $2 in | |
keyboard*) | |
toogle_peripherals "Keyboard" "$keyboard" | |
;; | |
touchpad*) | |
toogle_peripherals "Touchpad" "$touchpad" | |
;; | |
touchscreen*) | |
echo "$touchscreen" | |
toogle_peripherals "Touchscreen" "$touchscreen" | |
;; | |
esac | |
;; | |
--pen*) | |
set_pen | |
;; | |
--reset*) | |
device_notify "Resetting devices" | |
rm "/tmp/device-disable-*" | |
xrandr --output $screen --rotation normal | |
xinput enable "$keyboard" | |
xinput enable "$touchpad" | |
xinput enable "$touchscreen" | |
;; | |
*) | |
grep '^#:' $0 | cut -d ':' -f 2-100 | |
exit 0 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment