2024-02-24 17:37:23 -05:00
|
|
|
#!/bin/sh
|
|
|
|
|
2024-02-25 11:06:26 -05:00
|
|
|
if test -n "$XDG_STATE_HOME"; then
|
|
|
|
log_file=$XDG_STATE_HOME/idle.log
|
|
|
|
else
|
|
|
|
log_file=$HOME/.local/state/idle.log
|
|
|
|
fi
|
|
|
|
echo "--- $(date +"%Y-%m-%d %T") ---" > "$log_file"
|
2024-02-24 17:37:23 -05:00
|
|
|
|
|
|
|
# kill process if already running
|
|
|
|
user=$(id -u)
|
2024-02-25 11:06:26 -05:00
|
|
|
pid=$(ps -o pid,comm -u "$user" | awk '$2=="swayidle" {print $1}')
|
2024-02-24 17:37:23 -05:00
|
|
|
if [ "$pid" != "" ]; then
|
2024-02-25 11:06:26 -05:00
|
|
|
echo "Restarting... Sending SIGTERM." >> "$log_file"
|
2024-02-24 17:37:23 -05:00
|
|
|
kill "$pid"
|
|
|
|
sleep 1
|
|
|
|
fi
|
|
|
|
|
2024-02-25 11:06:26 -05:00
|
|
|
pid=$(ps -o pid,comm -p "$pid" | awk '$2=="swayidle" {print $1}')
|
2024-02-24 17:37:23 -05:00
|
|
|
if [ "$pid" != "" ]; then
|
2024-02-25 11:06:26 -05:00
|
|
|
echo "Restarting... Sending SIGKILL." >> "$log_file"
|
2024-02-24 17:37:23 -05:00
|
|
|
kill -9 "$pid"
|
|
|
|
sleep 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
{{ if eq .chezmoi.hostname "helix" -}}
|
|
|
|
# dim: 2m, lock: 5m, display: 15m, suspend: 1h
|
|
|
|
brightness="/sys/class/backlight/amdgpu_bl1/brightness"
|
|
|
|
prev_brightness="${XDG_STATE_HOME}/prev_brightness"
|
|
|
|
swayidle -w \
|
2024-02-25 11:06:26 -05:00
|
|
|
timeout 120 "cat $brightness > $prev_brightness && echo 0 > $brightness" \
|
2024-02-24 17:37:23 -05:00
|
|
|
resume "cat $prev_brightness > $brightness" \
|
|
|
|
timeout 300 'waylock-launcher' \
|
|
|
|
resume "cat $prev_brightness > $brightness" \
|
|
|
|
timeout 900 "cat $prev_brightness > $brightness && wlr-randr --output eDP-1 --off" \
|
2024-02-25 11:06:26 -05:00
|
|
|
resume "wlr-randr --output eDP-1 --on && kanshictl reload" \
|
2024-02-24 17:37:23 -05:00
|
|
|
timeout 3600 "loginctl suspend-then-hibernate" \
|
|
|
|
resume "wlr-randr --output eDP-1 --on && kanshictl reload" \
|
|
|
|
lock "waylock-launcher" \
|
|
|
|
before-sleep "waylock-launcher" \
|
|
|
|
2>&1 | tee -a "$log_file" &
|
|
|
|
{{- else if eq .chezmoi.hostname "hydrus" }}
|
|
|
|
# lock: 5m, display: 15m
|
|
|
|
swayidle -w \
|
|
|
|
timeout 300 'waylock-launcher' \
|
|
|
|
timeout 900 'kanshictl switch dual-off' \
|
|
|
|
resume 'kanshictl switch dual' \
|
|
|
|
lock 'waylock-launcher' \
|
|
|
|
before-sleep 'waylock-launcher' \
|
|
|
|
2>&1 | tee -a "$log_file" &
|
|
|
|
{{- else }}
|
|
|
|
# lock after 5m
|
|
|
|
swayidle -w \
|
|
|
|
timeout 300 'waylock-launcher' \
|
|
|
|
2>&1 | tee -a "$log_file" &
|
|
|
|
{{ end }}
|