pmaports/main/ttyescape/togglevt.sh
Caleb Connolly 029cf83cf1
main/ttyescape: upgrade to hkdm/buffyboard (MR 2713)
This upgrades ttyescape to use buffyboard, a new fbkeyboard replacement
by @Cherrypicker. It adds a lot of missing keys and uses the same layout
as Phosh's Squeekboard, so should feel much more like home for Phosh
users.

This also switches to the new HKDM daemon for hotkey handling, replacing
triggerhappy.

[ci:skip-build] already passed
2021-12-16 02:32:16 +00:00

78 lines
2.1 KiB
Bash

#!/bin/sh
# Toggle between tty1 and tty2, launching $KEYBOARD when on tty2
# THIS SCRIPT MUST BE RUN AS ROOT
# usage:
# togglevt.sh <state>
# where <state> is an optional arg to require that a counter be incremented before the action
# is performed. The default configuration will perform the switch when the power button has
# been pressed 3 times whilst the volume down button is being held.
# if no arguments are specified the switch will occur immediately.
[ "$(whoami)" != root ] && echo "This must be run as root" && exit 1
# shellcheck disable=SC1091
test -f /etc/conf.d/ttyescape.conf && . /etc/conf.d/ttyescape.conf
# default font, override this by setting it in /etc/conf.d/ttyescape.conf
FONT="${FONT:-/usr/share/consolefonts/ter-128n.psf.gz}"
# amount of times power must be pressed to trigger
PRESSCOUNT="${PRESSCOUNT:-3}"
TMPFILE="${TMPFILE:-/tmp/ttyescape.tmp}"
KEYBOARD="${KEYBOARD:-buffyboard}"
if [ ! -e /dev/uinput ]; then
if ! modprobe -q uinput; then
echo "uinput module not available, please enable it in your kernel"
fi
fi
switchtty() {
currentvt=$(cat /sys/devices/virtual/tty/tty0/active)
if [ "$currentvt" = "tty2" ]; then # switch to tty1 with normal UI
chvt 1
killall "$KEYBOARD"
else # Switch to tty2 with $KEYBOARD
setfont "$FONT" -C /dev/tty2
chvt 2
# sometimes they keyboard can be running already, we shouldn't start it in that case
[ "$(pgrep "$KEYBOARD")" ] || nohup "$KEYBOARD" -r "$(cat /sys/class/graphics/fbcon/rotate)" &
fi
}
# If we receive a command that isn't start
# and we don't have the file used to count
# then we should do nothing
if [ -n "$1" ] && [ "$1" != "start" ] && [ ! -f "$TMPFILE" ]; then
exit 0
fi
case "$1" in
# No args means just DO IT
"")
switchtty
;;
# Start counting, this should
# run when voldown is pressed
"start")
echo "0" > "$TMPFILE"
;;
# Run when voldown releases
"reset")
rm "$TMPFILE"
;;
# Run when power pressed while
# voldown is pressed
"inc")
val="$(cat "$TMPFILE")"
val=$((val+1))
if [ $val -eq "$PRESSCOUNT" ]; then
rm "$TMPFILE"
switchtty
else
echo "$val" > "$TMPFILE"
fi
;;
*)
esac