Last active
June 28, 2020 08:27
-
-
Save StollD/52383a9e67a2dc8738348a8fb926db42 to your computer and use it in GitHub Desktop.
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/sh | |
# Check if IPTS driver is loaded | |
if [ ! -d "/sys/module/ipts" ]; then | |
echo "ERROR: IPTS module not loaded!" | |
exit -19 | |
fi | |
usage() { | |
echo "Usage: $0 [OPTION]..." | |
echo "Control the mode of an IPTS touchscreen." | |
echo | |
echo "Options:" | |
echo " -h This help message" | |
echo " -s Set the touchscreen to stylus mode" | |
echo " -t Set the touchscreen to touch mode" | |
echo " -c Cycle between touchscreen modes" | |
exit | |
} | |
notify() { | |
if [ "$SUDO_USER" = "" ]; then | |
notify-send -i utilities-terminal "IPTS" "$1" | |
return | |
fi | |
ID=$(id -u $SUDO_USER) | |
sudo -u $SUDO_USER \ | |
DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$ID/bus" \ | |
notify-send -i utilities-terminal "IPTS" "$1" | |
} | |
get_mode() { | |
MODE=$(sudo cat /sys/module/ipts/parameters/singletouch) | |
if [ "$MODE" = "N" ]; then | |
echo 0 | |
else | |
echo 1 | |
fi | |
} | |
set_mode() { | |
sudo modprobe -r ipts | |
sudo modprobe ipts singletouch=$1 | |
if [ "$1" = "0" ]; then | |
notify "Touchscreen set to stylus mode" | |
else | |
notify "Touchscreen set to touch mode" | |
fi | |
} | |
while getopts ":hstc" args; do | |
case "$args" in | |
s) | |
set_mode 0 | |
;; | |
t) | |
set_mode 1 | |
;; | |
c) | |
set_mode $((1 - $(get_mode))) | |
;; | |
*) | |
usage | |
;; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment