Skip to content
Closed
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
1 change: 1 addition & 0 deletions bin/omarchy-launch-screensaver
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ while read -r m special; do
done < <(hyprctl monitors -j | jq -r '.[] | "\(.name) \(.specialWorkspace.name)"')

hypr_focus_monitor "$focused"
omarchy-shell -q idle screensaverReady

# Emptying a special workspace focuses its monitor, so the last screensaver to close would take focus
# with it. Hand focus back to the monitor that had it once they are all gone.
Expand Down
57 changes: 48 additions & 9 deletions shell/plugins/services/idle/Service.qml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ Item {
property bool screensaverStartedThisCycle: false
property string lastEvent: "starting"
property string lastEventAt: ""
// Keep mapped windows across idle cycles, including manually started screensavers.
property var screensaverWindows: ({})
property int screensaverWindowCount: 0
property bool screensaverInputReady: false

function secondsFromConfig(value, fallback) {
return IdleModel.secondsFromConfig(value, fallback)
Expand Down Expand Up @@ -80,7 +82,6 @@ Item {
screensaverLaunchGraceTimer.stop()
root.idledThisCycle = false
root.screensaverStartedThisCycle = false
resetScreensaverWindows()
runProcess(lockProcess, "lock", "omarchy-system-lock")
}

Expand All @@ -93,7 +94,6 @@ Item {
logEvent("idle-cycle-start", "screensaver=" + root.screensaverTimeoutSeconds + " lock=" + root.lockTimeoutSeconds)
root.idledThisCycle = true
root.screensaverStartedThisCycle = false
resetScreensaverWindows()

// Set this cycle's deadlines once: a bound interval would restart a pending
// timer from the moment shell.json changes, locking early or late.
Expand Down Expand Up @@ -124,18 +124,16 @@ Item {

root.idledThisCycle = false
root.screensaverStartedThisCycle = false
resetScreensaverWindows()
}

function resetScreensaverWindows() {
root.screensaverWindows = ({})
root.screensaverWindowCount = 0
}

function setScreensaverWindow(address, visible) {
var next = IdleModel.screensaverWindowsAfter(root.screensaverWindows, address, visible)
root.screensaverWindows = next.windows
root.screensaverWindowCount = next.count
if (next.count === 0) {
screensaverInputArmTimer.stop()
root.screensaverInputReady = false
}
}

function handleScreensaverWindowOpened(address) {
Expand Down Expand Up @@ -171,6 +169,12 @@ Item {
}
}

function dismissScreensaver() {
logEvent("screensaver-dismiss", "input")
root.screensaverInputReady = false
screensaverDismissProcess.running = true
}

function handleActiveSignal() {
if (!root.idledThisCycle) return

Expand Down Expand Up @@ -208,13 +212,16 @@ Item {
screensaverDelay: root.screensaverDelaySeconds,
lockDelay: root.lockDelaySeconds,
screensaverWindows: root.screensaverWindowCount,
screensaverInputReady: root.screensaverInputReady,
timers: {
screensaver: screensaverTimer.running,
lock: lockTimer.running,
screensaverLaunchGrace: screensaverLaunchGraceTimer.running
screensaverLaunchGrace: screensaverLaunchGraceTimer.running,
screensaverInputArm: screensaverInputArmTimer.running
},
processes: {
screensaver: screensaverProcess.running,
screensaverDismiss: screensaverDismissProcess.running,
lock: lockProcess.running,
wake: wakeProcess.running
},
Expand Down Expand Up @@ -275,6 +282,34 @@ Item {
onIsIdleChanged: root.handleIdleChanged()
}

// Ignore trailing input from the gesture that launched the screensaver.
Timer {
id: screensaverInputArmTimer
interval: 500
repeat: false
onTriggered: {
root.screensaverInputReady = root.screensaverWindowCount > 0
if (root.screensaverInputReady) root.logEvent("screensaver-input-armed")
if (root.screensaverInputReady && !screensaverInput.isIdle) root.dismissScreensaver()
}
}

// Hyprland never resumes a zero-timeout notification; use one millisecond.
IdleMonitor {
id: screensaverInput
enabled: root.screensaverWindowCount > 0
timeout: 0.001
respectInhibitors: false
onIsIdleChanged: {
if (enabled && !isIdle && root.screensaverInputReady) root.dismissScreensaver()
}
}

Process {
id: screensaverDismissProcess
command: ["pkill", "-f", "[o]rg.omarchy.screensaver"]
}

Timer {
id: screensaverTimer
repeat: false
Expand Down Expand Up @@ -363,6 +398,10 @@ Item {
return root.statusJson()
}

function screensaverReady(): void {
screensaverInputArmTimer.restart()
}

function enable(): string {
return root.setIdleEnabled(true)
}
Expand Down
11 changes: 11 additions & 0 deletions test/shell.d/screensaver-workspace-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ cat >"$tmpdir/bin/socat" <<'SH'
printf '%s\n' "$$" >"$TEST_DIR/socat.pid"
exec cat "$TEST_DIR/events"
SH
cat >"$tmpdir/bin/omarchy-shell" <<'SH'
#!/bin/bash
if [[ $* == "-q idle screensaverReady" ]] &&
[[ $(wc -l <"$TEST_DIR/spawned") == 2 ]] &&
[[ $(tail -n 1 "$TEST_DIR/calls") == 'dispatch hl.dsp.focus({ monitor = "DP-1" })' ]]; then
touch "$TEST_DIR/input-ready"
fi
SH
printf '#!/bin/bash\nexit 1\n' >"$tmpdir/bin/pgrep"
printf '#!/bin/bash\nexit 1\n' >"$tmpdir/bin/omarchy-toggle-enabled"
printf '#!/bin/bash\necho DP-1\n' >"$tmpdir/bin/omarchy-hyprland-monitor-focused"
Expand All @@ -53,6 +61,9 @@ printf '[{"class":"org.omarchy.screensaver","mapped":true}]\n' >"$tmpdir/clients
PATH="$tmpdir/bin:$PATH" TEST_DIR="$tmpdir" XDG_RUNTIME_DIR="$tmpdir" HYPRLAND_INSTANCE_SIGNATURE=test \
timeout 10 "$ROOT/bin/omarchy-launch-screensaver" force

[[ -f $tmpdir/input-ready ]] || fail "input dismissal arms after both screensavers map and focus returns" "$(<"$tmpdir/calls")"
pass "input dismissal arms after both screensavers map and focus returns"
Comment on lines +64 to +65

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Input dismissal remains untested

The new assertion checks that the launcher sends screensaverReady, but never runs the dismissal code in Service.qml. It would still pass if the arm timer or input handler stopped working. Add a focused test for input before and after arming, dismissal during continuous input, and disarming when the last window closes.


mapfile -t spawns < <(grep exec_cmd "$tmpdir/calls")
(( ${#spawns[@]} == 2 )) || fail "a screensaver opens on each monitor" "$(<"$tmpdir/calls")"
[[ ${spawns[0]} == *"[workspace special:screensaver-DP-1]"* ]] ||
Expand Down
Loading