random-scripts/swayidle-lock-screen

50 lines
956 B
Bash
Executable File

#!/usr/bin/env zsh
function run {
dunstctl set-paused true
swayidle -w -C /dev/null \
timeout 15 'hyprctl dispatch dpms off' resume 'hyprctl dispatch dpms on' &
local swayidle_pid="${!}"
swaylock -e ${img_flags}
kill "${swayidle_pid}"
hyprctl dispatch dpms on
dunstctl set-paused false
fix_eww
}
function fix_eww {
if (( ${#fix_eww} > 0 )); then
eww open-many ${fix_eww}
fi
}
local background=false
local fix_eww=()
while [[ "${1}" =~ '^-' ]]; do
case "${1}" in
--)
shift
break
;;
-f)
background=true
;;
-b)
fix_eww+="${2}"
shift
;;
-*)
printf "error: unknown flag '%s'\n" "${1}" >&2
;;
esac
shift
done
(( ${#} != 0 )) && img_flags=(-s fill -i "${1}")
if ${background}; then
run '${img_flags}' &
else
run '${img_flags}'
fi