Lock before suspend with sleep inhibitor service
This commit is contained in:
@@ -29,9 +29,12 @@ quickshell --no-color log -p "$OMARCHY_PATH/shell" --any-display --tail "$lines"
|
||||
|
||||
section "Relevant processes"
|
||||
ps -eo pid=,args= \
|
||||
| grep -E 'quickshell -n -p|dbus-monitor.*PrepareForSleep|org\.omarchy\.screensaver|omarchy-screensaver|(^|/| )tte( |$)' \
|
||||
| grep -E 'quickshell -n -p|omarchy-system-sleep-monitor|systemd-inhibit.*Lock screen before suspend|org\.omarchy\.screensaver|omarchy-screensaver|(^|/| )tte( |$)' \
|
||||
| grep -v grep || true
|
||||
|
||||
section "Sleep lock service"
|
||||
systemctl --user status omarchy-sleep-lock.service --no-pager 2>/dev/null || true
|
||||
|
||||
section "Hyprland screensaver clients"
|
||||
hyprctl clients -j 2>/dev/null \
|
||||
| jq -r '.[] | select(.class == "org.omarchy.screensaver" or .initialClass == "org.omarchy.screensaver") | [.pid,.class,.initialClass,.title,.focusHistoryID] | @tsv' || true
|
||||
|
||||
@@ -5,6 +5,11 @@
|
||||
|
||||
CONFIG_DIR="$OMARCHY_PATH/shell"
|
||||
|
||||
if [[ $(omarchy-shell lock isLocked 2>/dev/null || true) == "true" ]]; then
|
||||
echo "Refusing to restart Omarchy shell while the session is locked." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
pkill -x quickshell 2>/dev/null || true
|
||||
sleep 0.2
|
||||
setsid quickshell -n -p "$CONFIG_DIR" >/dev/null 2>&1 &
|
||||
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
#!/bin/bash
|
||||
|
||||
# omarchy:summary=Lock before suspend and wait for the session lock to become secure
|
||||
# omarchy:group=system
|
||||
# omarchy:hidden=true
|
||||
|
||||
wait_attempts=${1:-100}
|
||||
|
||||
if [[ ! $wait_attempts =~ ^[0-9]+$ ]] || (( wait_attempts < 1 )); then
|
||||
wait_attempts=100
|
||||
fi
|
||||
|
||||
omarchy-shell lock lock >/dev/null 2>&1 || exit 1
|
||||
|
||||
for (( attempt = 0; attempt < wait_attempts; attempt++ )); do
|
||||
status=$(omarchy-shell lock status 2>/dev/null || true)
|
||||
|
||||
if jq -e '.secure == true' <<<"$status" >/dev/null 2>&1; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
sleep 0.05
|
||||
done
|
||||
|
||||
exit 1
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
#!/bin/bash
|
||||
|
||||
# omarchy:summary=Monitor sleep preparation and lock before suspend
|
||||
# omarchy:group=system
|
||||
# omarchy:hidden=true
|
||||
|
||||
monitor_command='exec dbus-monitor --system "type='\''signal'\'',sender='\''org.freedesktop.login1'\'',interface='\''org.freedesktop.login1.Manager'\'',member='\''PrepareForSleep'\''"'
|
||||
|
||||
consume_sleep_events() {
|
||||
local line
|
||||
|
||||
while IFS= read -r line; do
|
||||
if [[ $line == *"boolean true"* ]]; then
|
||||
"$OMARCHY_PATH/bin/omarchy-system-sleep-lock"
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
if [[ ${1:-} == "--consume" ]]; then
|
||||
consume_sleep_events
|
||||
exit 0
|
||||
fi
|
||||
|
||||
exec systemd-inhibit \
|
||||
--what=sleep \
|
||||
--mode=delay \
|
||||
--who=Omarchy \
|
||||
--why="Lock screen before suspend" \
|
||||
bash -lc "$monitor_command | \"$OMARCHY_PATH/bin/omarchy-system-sleep-monitor\" --consume"
|
||||
Reference in New Issue
Block a user