mirror of
https://codeberg.org/andyscott/dotfiles.git
synced 2024-12-22 01:43:10 -05:00
Nest 2nd check for pid to avoid ps misfire and enable swayidle debug logging
This commit is contained in:
parent
6ee3946a3d
commit
ebe5de26c9
1 changed files with 18 additions and 17 deletions
|
@ -1,33 +1,34 @@
|
|||
#!/bin/sh
|
||||
|
||||
if test -n "$XDG_STATE_HOME"; then
|
||||
log_file=$XDG_STATE_HOME/idle.log
|
||||
log_dir=$XDG_STATE_HOME
|
||||
else
|
||||
log_file=$HOME/.local/state/idle.log
|
||||
log_dir=$HOME/.local/state
|
||||
fi
|
||||
echo "--- $(date +"%Y-%m-%d %T") ---" > "$log_file"
|
||||
|
||||
log_file=$log_dir/idle.log
|
||||
echo "--- idle-launcher $(date +"%Y-%m-%d %T") ---" > "$log_file"
|
||||
|
||||
# kill process if already running
|
||||
user=$(id -u)
|
||||
pid=$(ps -o pid,comm -u "$user" | awk '$2=="swayidle" {print $1}')
|
||||
if [ "$pid" != "" ]; then
|
||||
echo "Restarting... Sending SIGTERM." >> "$log_file"
|
||||
echo "$(date +"%Y-%m-%d %T") - idle-launcher: Sending SIGTERM" >> "$log_file"
|
||||
kill "$pid"
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
pid=$(ps -o pid,comm -p "$pid" | awk '$2=="swayidle" {print $1}')
|
||||
if [ "$pid" != "" ]; then
|
||||
echo "Restarting... Sending SIGKILL." >> "$log_file"
|
||||
kill -9 "$pid"
|
||||
sleep 1
|
||||
pid=$(ps -o pid,comm -p "$pid" | awk '$2=="swayidle" {print $1}')
|
||||
if [ "$pid" != "" ]; then
|
||||
echo "$(date +"%Y-%m-%d %T") - idle-launcher: Sending SIGKILL" >> "$log_file"
|
||||
kill -9 "$pid"
|
||||
sleep 1
|
||||
fi
|
||||
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 \
|
||||
brightness=/sys/class/backlight/amdgpu_bl1/brightness
|
||||
prev_brightness=$log_dir/prev_brightness
|
||||
swayidle -dw \
|
||||
timeout 120 "cat $brightness > $prev_brightness && echo 0 > $brightness" \
|
||||
resume "cat $prev_brightness > $brightness" \
|
||||
timeout 300 'waylock-launcher' \
|
||||
|
@ -41,7 +42,7 @@ swayidle -w \
|
|||
2>&1 | tee -a "$log_file" &
|
||||
{{- else if eq .chezmoi.hostname "hydrus" }}
|
||||
# lock: 5m, display: 15m
|
||||
swayidle -w \
|
||||
swayidle -dw \
|
||||
timeout 300 'waylock-launcher' \
|
||||
timeout 900 'kanshictl switch dual-off' \
|
||||
resume 'kanshictl switch dual' \
|
||||
|
@ -50,7 +51,7 @@ swayidle -w \
|
|||
2>&1 | tee -a "$log_file" &
|
||||
{{- else }}
|
||||
# lock after 5m
|
||||
swayidle -w \
|
||||
swayidle -dw \
|
||||
timeout 300 'waylock-launcher' \
|
||||
2>&1 | tee -a "$log_file" &
|
||||
{{ end }}
|
||||
{{- end }}
|
||||
|
|
Loading…
Reference in a new issue