commit 5b7f65ba34200586b83713cf292142d3e5f417a5 Author: Liam Waldron Date: Thu Sep 14 14:14:44 2023 -0400 a diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8e2d57c --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +include config.mk + +all: + @echo Run \'make install\'. + +install: + install src/tsw $(PREFIX)/bin + install src/tsw.conf $(HOME)/.config diff --git a/README b/README new file mode 100644 index 0000000..dddedee --- /dev/null +++ b/README @@ -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. diff --git a/config.mk b/config.mk new file mode 100644 index 0000000..415e97f --- /dev/null +++ b/config.mk @@ -0,0 +1,2 @@ +PREFIX = /usr +HOME = /home/arco diff --git a/src/tsw b/src/tsw new file mode 100755 index 0000000..df3a37f --- /dev/null +++ b/src/tsw @@ -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 diff --git a/src/tsw.conf b/src/tsw.conf new file mode 100644 index 0000000..32fc3e6 --- /dev/null +++ b/src/tsw.conf @@ -0,0 +1,11 @@ +# +# tsw.conf +# + +# Run 'xinput' to find device IDs + +# Keyboard device ID +KEYBOARD_DEVICE="13" + +# Trackpad device ID +TRACKPAD_DEVICE="12"