Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/omarchy-shell
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ elif (( ipc_status != 0 )); then
# /etc/omarchy.conf (keeping scratch tests and unlinked worktrees isolated).
case "$1"$'\x1f'"$2" in
"notifications"$'\x1f'"ping" | "notifications"$'\x1f'"dismiss" | \
"lock"$'\x1f'"lock" | "lock"$'\x1f'"status" | \
"lock"$'\x1f'"lock" | "lock"$'\x1f'"status" | "lock"$'\x1f'"wake" | \
"omarchy.system-update"$'\x1f'"clear" | \
"background"$'\x1f'"set" | "shell"$'\x1f'"ping")
if (( ipc_status == 255 )) && [[ $output == "No running instances for"* ]]; then
Expand Down
23 changes: 23 additions & 0 deletions bin/omarchy-system-lid-open
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# omarchy:summary=Reconcile displays and wake the screen when the laptop lid opens
# omarchy:group=system
# omarchy:hidden=true

# On non-ACPI laptops, omarchy-hw-laptop-closed queries logind, which reads the
# switch independently of Hyprland and can briefly lag behind switch:off.
# Re-check once before treating the lid as closed.
lid_closed() {
omarchy-hw-laptop-closed && sleep 0.1 && omarchy-hw-laptop-closed
}

# Hyprland can replay a switch binding while the lid is still closed, and a
# closed lid must never light the panel. When open and locked, wake through the
# lock service (which runs omarchy-system-wake, resumes fingerprint auth, and
# re-arms the blank timer); fall back to omarchy-system-wake when unlocked or
# if the shell cannot answer. Both wake paths reconcile clamshell state.
if lid_closed; then
omarchy-hyprland-monitor-clamshell
elif ! wake_reply=$(omarchy-shell lock wake 2>/dev/null) || [[ $wake_reply != "ok" ]]; then
omarchy-system-wake >/dev/null 2>&1 || true
fi
6 changes: 3 additions & 3 deletions default/hypr/bindings/utilities.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ o.bind_toggle("SUPER + CTRL + I", "Toggle locking on idle", "idle")
o.bind("SUPER + CTRL + Delete", "Toggle laptop display", "omarchy-hyprland-monitor-internal toggle")
o.bind("SUPER + CTRL + ALT + Delete", "Toggle laptop display mirroring", "omarchy-hyprland-monitor-internal-mirror toggle")
o.bind("switch:on:Lid Switch", nil, "omarchy-system-lid-close", { locked = true })
o.bind("switch:off:Lid Switch", nil, "omarchy-hyprland-monitor-clamshell", { locked = true })
o.bind("switch:off:Lid Switch", nil, "omarchy-system-lid-open", { locked = true })
-- Apple Silicon reports its lid through the SMC, under its own switch name.
o.bind("switch:on:Apple SMC power/lid events", nil, "omarchy-system-lid-close", { locked = true })
o.bind("switch:off:Apple SMC power/lid events", nil, "omarchy-hyprland-monitor-clamshell", { locked = true })
o.bind("switch:off:Apple SMC power/lid events", nil, "omarchy-system-lid-open", { locked = true })
-- ChromeOS EC laptops (Googlebooks, Chromebooks) report their lid through cros_ec_buttons.
o.bind("switch:on:cros_ec_buttons", nil, "omarchy-system-lid-close", { locked = true })
o.bind("switch:off:cros_ec_buttons", nil, "omarchy-hyprland-monitor-clamshell", { locked = true })
o.bind("switch:off:cros_ec_buttons", nil, "omarchy-system-lid-open", { locked = true })

o.bind("PRINT", "Screenshot", "omarchy-capture-screenshot")
o.bind("SUPER + CTRL + ALT + C", "Screenshot", "omarchy-capture-screenshot")
Expand Down
31 changes: 24 additions & 7 deletions shell/plugins/lock/Service.qml
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,27 @@ Item {
}

function armBlankTimer(delayMs) {
idleBlankTimer.interval = delayMs || idleBlankTimer.idleMs
idleBlankTimer.armedAt = Date.now()
var now = Date.now()
var targetMs = delayMs || idleBlankTimer.idleMs
if (idleBlankTimer.running && idleBlankTimer.armedAt > 0) {
var elapsedMs = now - idleBlankTimer.armedAt
if (elapsedMs > idleBlankTimer.interval + 2000) targetMs = Math.max(targetMs, idleBlankTimer.resumeMs)
else if (elapsedMs >= 0 && idleBlankTimer.interval - elapsedMs > targetMs) return
}
idleBlankTimer.interval = targetMs
idleBlankTimer.armedAt = now
idleBlankTimer.restart()
}

function runWake() {
function runWake(delayMs) {
if (lockRequested && fingerprintPaused && fingerprintResumeTimer.running
&& FingerprintModel.spannedSleep(Date.now() - fingerprintResumeTimer.lastTickMs, fingerprintResumeTimer.interval)) {
fingerprintResumeTimer.stop()
fingerprintSleptWhilePaused = true
delayMs = Math.max(delayMs || 0, idleBlankTimer.resumeMs)
}
if (!wakeProcess.running) wakeProcess.running = true
if (lockRequested) armBlankTimer()
if (lockRequested) armBlankTimer(delayMs)
resumeFingerprint()
nudgeFingerprint()
}
Expand Down Expand Up @@ -744,9 +757,7 @@ Item {
root.fingerprintSleptWhilePaused = true
// A panel blanked before the sleep stays dark through the resume, and
// opening the lid is no input that would light it.
if (!wakeProcess.running) wakeProcess.running = true
root.resumeFingerprint()
root.armBlankTimer(idleBlankTimer.resumeMs)
root.runWake(idleBlankTimer.resumeMs)
} else if (slept || !root.fingerprintPaused || --ticksLeft <= 0) {
stop()
}
Expand Down Expand Up @@ -977,6 +988,12 @@ Item {
return root.currentlyLocked() ? "true" : "false"
}

function wake(): string {
if (!root.currentlyLocked()) return "unlocked"
root.runWake()
return "ok"
}

function status(): string {
return JSON.stringify({
locked: root.currentlyLocked(),
Expand Down
49 changes: 49 additions & 0 deletions test/shell.d/fixtures/lock-fingerprint-service/shell.qml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,55 @@ ShellRoot {
check(!service.fingerprintPaused, "a resume with no input still brings the reader back")
check(retry.running && retry.interval === 250, "a wake after a sleep while blank recovers at once")
check(service.fingerprintUnreachedStreak === 0, "a sleep while blank opens the resume grace")

// Lid open while locked and blanked with no suspend (e.g. external power):
// lights the panel, resumes fingerprint auth, and re-arms the blank timer.
retry.stop()
wake.running = false
service.pauseFingerprint()
service.fingerprintRetryDueMs = Date.now() - 1000
service.runWake()
var lidBlankRunning = blankTimer.running
var lidBlankInterval = blankTimer.interval
blankTimer.stop()
check(wake.running, "lid wake lights a panel blanked without sleeping")
check(!service.fingerprintPaused && retry.running && retry.interval === 250, "lid wake resumes fingerprint authentication")
check(lidBlankRunning && lidBlankInterval === 5000, "lid wake re-arms the lock blank timer")

// Lid open arriving right after resume before fingerprintResumeTimer ticks
// still applies the resume grace and longer resume blank window.
retry.stop()
wake.running = false
service.fingerprintUnreachedStreak = 4
service.fingerprintResumedAtMs = 0
service.pauseFingerprint()
service.noteSleepRequested()
resumeTimer.lastTickMs = Date.now() - 60000
service.runWake()
var resumeBlankRunning = blankTimer.running
var resumeBlankInterval = blankTimer.interval
// A follow-up normal wake during the resume run-up must not shorten it to 5s.
service.armBlankTimer()
var preservedBlankInterval = blankTimer.interval
blankTimer.stop()
check(wake.running && !resumeTimer.running, "lid wake after sleep lights the panel and ends the sleep watch")
check(!service.fingerprintPaused && service.fingerprintUnreachedStreak === 0, "lid wake after sleep opens the resume grace")
check(resumeBlankRunning && resumeBlankInterval === 15000, "lid wake after sleep uses the longer resume blank window")
check(preservedBlankInterval === 15000, "armBlankTimer preserves a longer remaining resume window")

// If fingerprint already resumed before the resume timer's next tick, a
// wake spanning sleep must not leave fingerprintSleptWhilePaused stranded.
retry.stop()
wake.running = false
service.pauseFingerprint()
service.noteSleepRequested()
service.resumeFingerprint()
resumeTimer.lastTickMs = Date.now() - 60000
service.runWake()
blankTimer.stop()
check(!service.fingerprintSleptWhilePaused, "wake while not paused does not leave fingerprintSleptWhilePaused set")
resumeTimer.stop()

retry.stop()
service.pauseFingerprint()
service.noteSleepRequested()
Expand Down
66 changes: 66 additions & 0 deletions test/shell.d/lid-close-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,69 @@ pass "undocked lid close does not lock when passwordless login is active"
[[ ${calls[0]} == "omarchy-hyprland-monitor-clamshell" ]] ||
fail "undocked lid close with passwordless login still reconciles displays" "calls: ${calls[*]}"
pass "undocked lid close with passwordless login still reconciles displays"

# Lid open: wakes via the lock service when locked, falls back to
# omarchy-system-wake when unlocked or unreachable, retries a briefly stale
# closed reading (logind lag on non-ACPI laptops), and never wakes while closed.
lid_open="$ROOT/bin/omarchy-system-lid-open"

setup_lid_open() {
setup_scenario "open_$1" "$2" 1
local shell_reply="${3-ok}" shell_exit="${4:-0}"

cat >"$mock_bin/omarchy-shell" <<SH
#!/bin/bash
echo "omarchy-shell \$*" >>"\$CALL_LOG"
[[ -n "$shell_reply" ]] && printf '%s\n' "$shell_reply"
exit $shell_exit
SH
cat >"$mock_bin/omarchy-system-wake" <<'SH'
#!/bin/bash
echo omarchy-system-wake >>"$CALL_LOG"
SH
chmod +x "$mock_bin/omarchy-shell" "$mock_bin/omarchy-system-wake"
}

run_lid_open() {
CALL_LOG="$call_log" PATH="$mock_bin:$PATH" "$lid_open"
mapfile -t calls <"$call_log"
}

setup_lid_open locked 1 ok 0
run_lid_open
[[ ${calls[0]:-} == "omarchy-shell lock wake" && ${calls[*]} != *omarchy-system-wake* ]] ||
fail "locked lid open wakes through the lock service" "calls: ${calls[*]}"
pass "locked lid open wakes through the lock service"

setup_lid_open unlocked 1 unlocked 0
run_lid_open
[[ ${calls[1]:-} == "omarchy-system-wake" ]] ||
fail "unlocked lid open falls back to omarchy-system-wake" "calls: ${calls[*]}"
pass "unlocked lid open falls back to omarchy-system-wake"

setup_lid_open unreachable 1 "" 1
run_lid_open
[[ ${calls[1]:-} == "omarchy-system-wake" ]] ||
fail "lid open falls back to omarchy-system-wake when omarchy-shell fails" "calls: ${calls[*]}"
pass "lid open falls back to omarchy-system-wake when omarchy-shell fails"

setup_lid_open stale_closed 0 ok 0
cat >"$mock_bin/omarchy-hw-laptop-closed" <<SH
#!/bin/bash
if [[ ! -f "$scenario_dir/checked" ]]; then
touch "$scenario_dir/checked"
exit 0
fi
exit 1
SH
chmod +x "$mock_bin/omarchy-hw-laptop-closed"
run_lid_open
[[ ${calls[0]:-} == "omarchy-shell lock wake" ]] ||
fail "lid open retries a briefly stale closed reading before skipping wake" "calls: ${calls[*]}"
pass "lid open retries a briefly stale closed reading before skipping wake"

setup_lid_open closed 0 ok 0
run_lid_open
[[ ${calls[0]:-} == "omarchy-hyprland-monitor-clamshell" && ${calls[*]} != *omarchy-shell* && ${calls[*]} != *omarchy-system-wake* ]] ||
fail "replayed lid-open while closed reconciles displays without waking" "calls: ${calls[*]}"
pass "replayed lid-open while closed reconciles displays without waking"