From 2ee4b470866239d2b52c72b664e318ebaefbfbf8 Mon Sep 17 00:00:00 2001 From: Alexander Rosenberg Date: Mon, 18 Aug 2025 19:53:14 -0700 Subject: [PATCH] Fix sleep and wake on lock screen --- swayidle-lock-screen | 32 ++++++++++---------------------- way-displays-enable | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 22 deletions(-) create mode 100755 way-displays-enable diff --git a/swayidle-lock-screen b/swayidle-lock-screen index bbd2408..8da0297 100755 --- a/swayidle-lock-screen +++ b/swayidle-lock-screen @@ -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 diff --git a/way-displays-enable b/way-displays-enable new file mode 100755 index 0000000..b400a62 --- /dev/null +++ b/way-displays-enable @@ -0,0 +1,37 @@ +#!/usr/bin/env zsh + +let just_list=0 +local operation="-d" +local jq_filter_neg="| not" +local ignored=() + +while getopts 'ldi:' name; do + case "${name}" in + l) + just_list=1 + ;; + d) + jq_filter_neg="" + operation="-s" + ;; + i) + ignored+="${OPTARG}" + ;; + esac +done + +SCRIPT=".[] | select(.enabled${jq_filter_neg}) | .name" + +set -e +displays=("${(0)$(wlr-randr --json | jq --raw-output0 "${SCRIPT}")}") +set +e + +displays=(${displays:|ignored}) + +if ((just_list)); then + printf '%s\0' ${displays} +else + for display in ${displays}; do + way-displays "${operation}" DISABLED "${display}" + done +fi