summaryrefslogtreecommitdiff
path: root/xscreensaver-companion
blob: 3d23176bbc1686d9b34da575c74417e62b06e01b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env zsh

pidfile=${XDG_RUNTIME_DIR-/run/user/$UID}/xscreensaver-companion.pid
trap "rm -f $pidfile" INT KILL

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
}

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)
                setxkbmap us -option
                dunstctl set-paused true
                ;;
            (UNBLANK)
                check_start gxkb
                $HOME/git/mine/vscripts/mykblayouts
                $HOME/.local/bin/touchpad-config
                dunstctl set-paused false
                ;;
        esac
    done
}

init_pidfile
xscreensaver-command -watch | parse_actions