aboutsummaryrefslogtreecommitdiff
path: root/bin/idlechecker
blob: 197d534edb5563a9f4b69ca76a453b35eed1d2ab (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
#!/bin/sh
LOCKFILE="$HOME/.local/state/algo/swayidle.lock"
LOCKDIR="$(dirname "$LOCKFILE")"

# Ensure the directory exists
mkdir -p "$LOCKDIR"

# Check if lockfile exists and process is running
if [ -e "$LOCKFILE" ]; then
    LOCKPID=$(cat "$LOCKFILE")
    if kill -0 "$LOCKPID" 2>/dev/null; then
        echo "swayidle is already running with PID $LOCKPID"
        exit 1
    else
        echo "Stale lockfile found. Removing."
        rm -f "$LOCKFILE"
    fi
fi

# Create lockfile with current PID
echo $$ > "$LOCKFILE"

# Function to clean up on exit
cleanup() {
    rm -f "$LOCKFILE"
}
trap cleanup EXIT



# xss-lock -- ./pretty-lock &
swayidle -w \
	timeout 300 '~/bin/pretty-lock' \
  timeout 500 'swaymsg "output * dpms off"' \
  resume 'swaymsg "output * dpms on"' \
  before-sleep 'swaymsg "output * dpms off"' \
  before-sleep '~/bin/pretty-lock'