This commit is contained in:
Liam Waldron 2023-09-14 14:14:44 -04:00
commit 5b7f65ba34
5 changed files with 97 additions and 0 deletions

8
Makefile Normal file
View File

@ -0,0 +1,8 @@
include config.mk
all:
@echo Run \'make install\'.
install:
install src/tsw $(PREFIX)/bin
install src/tsw.conf $(HOME)/.config

12
README Normal file
View File

@ -0,0 +1,12 @@
+ tsw
A small bash script to switch between tablet mode and laptop mode
+ Installation
Run 'make install' as root
+ Usage
tsw relies totally on user intervention to run. For example, I use i3blocks on my setup, and I have
two different blocks that switch between laptop mode and tablet mode.

2
config.mk Normal file
View File

@ -0,0 +1,2 @@
PREFIX = /usr
HOME = /home/arco

64
src/tsw Executable file
View File

@ -0,0 +1,64 @@
#!/bin/bash
# tsw - tablet switcher
# Load tsw configuration file
if [ ! -f "$HOME/.config/tsw.conf" ]; then
printf "no configuration file exists, tsw will not run without it\n"
printf "please ensure $HOME/.config/tsw.conf exists and is readable\n"
exit 1
else
source $HOME/.config/tsw.conf
fi
LOGFILE="/tmp/tsw.log"
ENABLE=$(xinput enable)
DISABLE=$(xinput disable)
laptop_mode() {
ERROR_COUNT=0
$ENABLE $KEYBOARD_DEVICE
if [ "$?" != 0 ]; then
echo "error enabling keyboard device" > $LOGFILE
echo "most likely the specified device ID does not exist" > $LOGFILE
ERROR_COUNT=$((ERROR_COUNT+1))
fi
$ENABLE $TRACKPAD_DEVICE
if [ "$?" != 0 ]; then
echo "error enabling keyboard device" > $LOGFILE
echo "most likely the specified device ID does not exist" > $LOGFILE
ERROR_COUNT=$((ERROR_COUNT+1))
fi
}
tablet_mode() {
ERROR_COUNT=0
$DISABLE $KEYBOARD_DEVICE
if [ "$?" != 0 ]; then
echo "error disabling keyboard device" > $LOGFILE
echo "most likely the specified device ID does not exist" > $LOGFILE
ERROR_COUNT=$((ERROR_COUNT+1))
fi
$DISABLE $TRACKPAD_DEVICE
if [ "$?" != 0 ]; then
echo "error disabling trackpad device" > $LOGFILE
echo "most likely the specified device ID does not exist" > $LOGFILE
ERROR_COUNT=$((ERROR_COUNT+1))
fi
echo "total errors enabling tablet mode: $ERROR_COUNT" > $LOGFILE
}
case $1 in
laptop)
laptop_mode "$@"
;;
tablet)
tablet_mode "$@"
;;
*)
printf "usage: ${0} [laptop] [tablet\n]"
exit 1
esac
printf "usage: ${0} [laptop] [tablet]\n"
exit 1

11
src/tsw.conf Normal file
View File

@ -0,0 +1,11 @@
#
# tsw.conf
#
# Run 'xinput' to find device IDs
# Keyboard device ID
KEYBOARD_DEVICE="13"
# Trackpad device ID
TRACKPAD_DEVICE="12"