diff options
| -rw-r--r-- | dot_config/sway/executable_resume-lock-grace.sh | 35 | ||||
| -rw-r--r-- | dot_config/systemd/user/inhibridge.service | 15 | ||||
| -rw-r--r-- | dot_config/systemd/user/swayidle.service | 10 | ||||
| -rw-r--r-- | meta/base.txt | 4 | ||||
| -rw-r--r-- | systemd-units/user.txt | 1 |
5 files changed, 63 insertions, 2 deletions
diff --git a/dot_config/sway/executable_resume-lock-grace.sh b/dot_config/sway/executable_resume-lock-grace.sh new file mode 100644 index 0000000..212eaa1 --- /dev/null +++ b/dot_config/sway/executable_resume-lock-grace.sh @@ -0,0 +1,35 @@ +#!/bin/sh +# resume-lock-grace: lock the screen if the user stays idle for $1 +# (default 30) seconds after waking from suspend. Designed to be invoked +# from swayidle's `after-resume` so a quick wake-and-keep-using doesn't +# require typing the password, while a wake-and-walk-away still locks. +# +# Implementation: spawn a one-shot swayidle that locks once and exits. +# A watchdog kills it as soon as swaylock is detected, and a hard cap +# guarantees we never linger competing with the main swayidle. +set -eu + +GRACE="${1:-30}" +LOCK_CMD='swaylock -f -e -c 282828' +HARD_CAP=$((GRACE * 4)) + +# If a lock is already up (e.g. main swayidle already fired), do nothing. +pgrep -x swaylock >/dev/null && exit 0 + +swayidle -w timeout "$GRACE" "$LOCK_CMD" >/dev/null 2>&1 & +PID=$! + +elapsed=0 +while [ "$elapsed" -lt "$HARD_CAP" ]; do + if pgrep -x swaylock >/dev/null; then + break + fi + if ! kill -0 "$PID" 2>/dev/null; then + exit 0 + fi + sleep 1 + elapsed=$((elapsed + 1)) +done + +kill "$PID" 2>/dev/null || true +wait 2>/dev/null || true diff --git a/dot_config/systemd/user/inhibridge.service b/dot_config/systemd/user/inhibridge.service new file mode 100644 index 0000000..a4435bf --- /dev/null +++ b/dot_config/systemd/user/inhibridge.service @@ -0,0 +1,15 @@ +[Unit] +Description=Bridge org.freedesktop.ScreenSaver inhibits to systemd-inhibit +Documentation=https://codeberg.org/Scrumplex/inhibridge +PartOf=graphical-session.target +After=graphical-session.target +ConditionEnvironment=DBUS_SESSION_BUS_ADDRESS + +[Service] +Type=simple +ExecStart=/usr/bin/inhibridge +Restart=on-failure +RestartSec=2s + +[Install] +WantedBy=sway-session.target diff --git a/dot_config/systemd/user/swayidle.service b/dot_config/systemd/user/swayidle.service index 8a99bfb..7f60847 100644 --- a/dot_config/systemd/user/swayidle.service +++ b/dot_config/systemd/user/swayidle.service @@ -1,16 +1,22 @@ [Unit] -Description=Idle manager for Wayland (lock + DPMS + before-sleep) +Description=Idle manager for Wayland (lock + DPMS + post-resume grace) PartOf=graphical-session.target After=graphical-session.target ConditionEnvironment=WAYLAND_DISPLAY [Service] Type=simple +# We deliberately do NOT lock on `before-sleep`; instead we lock only +# after a grace period post-resume, so a quick wake-and-keep-using +# doesn't require the password. `before-sleep` only pauses media so the +# call/track doesn't run on into suspend. The `lock` action still +# handles explicit `loginctl lock-session` immediately. ExecStart=/usr/bin/swayidle -w \ timeout 300 'swaylock -f -e -c 282828' \ timeout 360 'swaymsg "output * power off"' \ resume 'swaymsg "output * power on"' \ - before-sleep 'playerctl -a pause; swaylock -f -e -c 282828' \ + before-sleep 'playerctl -a pause' \ + after-resume '%h/.config/sway/resume-lock-grace.sh 30' \ lock 'swaylock -f -e -c 282828' Restart=on-failure RestartSec=2s diff --git a/meta/base.txt b/meta/base.txt index 2ee74bd..dae2d3f 100644 --- a/meta/base.txt +++ b/meta/base.txt @@ -168,6 +168,10 @@ poweralertd # Lock screen swaylock swayidle +# Bridge browsers' org.freedesktop.ScreenSaver inhibits to systemd-inhibit +# so swayidle honors them (e.g. video calls, fullscreen video). Without +# this swayidle would still time out and lock during a Meet call. +inhibridge # Clipboard wl-clipboard diff --git a/systemd-units/user.txt b/systemd-units/user.txt index 37e7e7a..35fc2c3 100644 --- a/systemd-units/user.txt +++ b/systemd-units/user.txt @@ -6,6 +6,7 @@ cliphist-image.service cliphist-text.service display-watcher.service +inhibridge.service signal.service swayidle.service waybar.service |
