Fix sleep and wake on lock screen

This commit is contained in:
2025-08-18 19:53:14 -07:00
parent f763fc1188
commit 2ee4b47086
2 changed files with 47 additions and 22 deletions

View File

@ -21,12 +21,20 @@ function run {
if [[ "${XDG_CURRENT_DESKTOP}" == 'river' ]] && has-rootful-xwayland-p; then
swaylock ${empty_flag} --color '#000000'
else
# get the list of currently disabled monitors so we don't touch them
local ignored=("${(0)$(way-displays-enable -l)}")
local ignored_args=()
for name in ${ignored}; do
# quote so it can be safely passed to swayidle
ignored_args+=(-i "${(q)name}")
done
swayidle -w -C /dev/null \
timeout 15 "${suspend_command}" resume "${wake_command}" &
timeout 15 "way-displays-enable -d ${ignored}" \
resume "way-displays-enable {$ignored}" &
local swayidle_pid="${!}"
swaylock ${empty_flag} ${img_flags}
kill "${swayidle_pid}"
eval "${wake_command}"
fi
dunstctl set-paused false
fix_eww
@ -57,14 +65,6 @@ while [[ "${1}" =~ '^-' ]]; do
fix_eww+="${2}"
shift
;;
-s)
local suspend_command="${2}"
shift
;;
-w)
local wake_command="${2}"
shift
;;
-e)
empty_flag='-e'
;;
@ -75,18 +75,6 @@ while [[ "${1}" =~ '^-' ]]; do
shift
done
if [[ -z "${suspend_command}" ]]; then
# default to turning off all displays
suspend_command="wlr-randr $(wlr-randr --json |
jq -r '[.[] | .modes = [.modes.[] |
select(.current)]] |
map("--output ''\(.name)'' --off") | join(" ")')"
fi
if [[ -z "${wake_command}" ]]; then
wake_command="wlr-randr $(wlr-randr --json | jq -r '[.[]| select(.enabled) | .modes = [.modes.[] | select(.current)].[]] | map("--output ''\(.name)'' --on --mode ''\(.modes.width)x\(.modes.height)@\(.modes.refresh)Hz'' --pos ''\(.position.x),\(.position.y)'' --transform \(.transform) --scale \(.scale)") | join(" ")')"
fi
(( ${#} != 0 )) && img_flags=(-s fill -i "${1}")
if ${background}; then