vscripts/xscreensaver-companion

52 lines
1.1 KiB
Text
Raw Permalink Normal View History

#!/usr/bin/env zsh
2019-10-21 17:28:37 +03:00
pidfile=${XDG_RUNTIME_DIR-/run/user/$UID}/xscreensaver-companion.pid
trap "rm -f $pidfile" INT KILL
2020-02-11 14:10:03 +02:00
function check_start
{
# check if the service is running and, if not, start it in the background
# and detach
if pgrep -u $USER $1 >/dev/null; then
return 0
else
$* &>/dev/null </dev/null & disown
fi
}
2019-10-21 17:28:37 +03:00
function init_pidfile
{
local pid
if read pid < $pidfile; then
if kill -0 $pid; then
echo 'I am already running!' >&2
exit 1
else
echo 'Remove stale lock file.' >&2
rm $pidfile
fi
fi
echo $$ > $pidfile
}
function parse_actions
{
while read action _; do
case $action in
(LOCK|BLANK)
2020-02-11 14:10:03 +02:00
setxkbmap us -option
2021-06-08 20:27:36 +03:00
dunstctl set-paused true
;;
(UNBLANK)
2020-02-11 14:10:03 +02:00
check_start gxkb
$HOME/git/mine/vscripts/mykblayouts
2020-02-11 14:10:03 +02:00
$HOME/.local/bin/touchpad-config
2021-06-08 20:27:36 +03:00
dunstctl set-paused false
;;
esac
done
}
2019-10-21 17:28:37 +03:00
init_pidfile
2020-02-11 14:10:03 +02:00
xscreensaver-command -watch | parse_actions