random-scripts/swayidle-lock-screen

34 lines
697 B
Plaintext
Raw Normal View History

2023-09-10 03:11:44 -07:00
#!/usr/bin/env zsh
2023-09-10 03:26:19 -07:00
function run {
swayidle -w -C /dev/null \
timeout 15 'hyprctl dispatch dpms off' resume 'hyprctl dispatch dpms on' &
2023-09-10 18:51:02 -07:00
local swayidle_pid="${!}"
swaylock -e "${@}"
2023-09-10 03:26:19 -07:00
kill "${swayidle_pid}"
hyprctl dispatch dpms on
}
2023-09-10 18:51:02 -07:00
local background=false
let img_index=1
for arg; do
case "${arg}" in
-f)
background=true
((++img_index))
;;
-*)
printf "error: unknown flag '%s'\n" "${arg}" >&2
((++img_index))
;;
esac
done
(( ${#} >= ${img_index} )) && img_flags=(-s fill -i "${@[${img_index}]}")
if ${background}; then
run ${img_flags} &
2023-09-10 03:26:19 -07:00
else
2023-09-10 18:51:02 -07:00
run ${img_flags}
2023-09-10 03:26:19 -07:00
fi