Skip to content

screensaver: survive the launcher's focus walk - #15614

Open
AnPod wants to merge 1 commit into
omacom:quattrofrom
AnPod:screensaver-startup-focus-grace
Open

AnPod wants to merge 1 commit into
omacom:quattrofrom
AnPod:screensaver-startup-focus-grace

Conversation

@AnPod

@AnPod AnPod commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Problem

After the seat goes idle, the screensaver could close itself about a second after launching, and the idle service read that close as the user dismissing the screensaver — cancelling the pending lock. The session then never locked (#15489).

omarchy-launch-screensaver walks the focus across every monitor to find the windows it just opened, then hands focus back to the monitor the user was on. During that walk — the first seconds after launch — the screensaver window is not focused, and omarchy-screensaver exits as soon as its focus check fails:

12:19:33.939 process-start: screensaver
12:19:34.042 idle-monitor: active
12:19:34.048 process-exit: screensaver exitCode=0
12:19:35.130 idle-cycle-cancel: screensaver-dismissed

Fix

Give the watch loop a short startup grace window (5s) where only a key exits. Once the grace is over, losing focus still closes the screensaver, so nothing leaks when a launch fails outright.

Test

New test/shell.d/screensaver-startup-grace-test.sh (stubbed hyprctl/pgrep/pkill/ttfx, fifo stdin):

  • an unfocused screensaver stays up through the grace window — fails on quattro (exits after ~1s), passes with this change;
  • a key still closes the screensaver inside the grace window;
  • an unfocused screensaver closes on its own, but no earlier than the grace (elapsed >= 4s asserted) — also fails on quattro.

Related existing tests pass: screensaver-workspace-test.sh, idle-test.sh, system-lock-test.sh.

Fixes #15489

omarchy-launch-screensaver walks the focus across every monitor to find
the windows it opened, then hands focus back to the monitor the user was
on. omarchy-screensaver used to exit as soon as its focus check failed,
which happens a second after launch while that walk is still running,
and the idle service read the close as the user dismissing the
screensaver, cancelling the pending lock.

Give the watch loop a short startup grace window where only a key exits.
Once the grace is over, losing focus still closes the screensaver.

Fixes omacom#15489
@greptile-apps

greptile-apps Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The change reaches the idle screensaver and its lock handoff.

The PR appears safe to merge, with two non-blocking improvements needed in the new test.

Findings

  1. P2 Test leaves children running ▶
  2. P2 Key check can pass incorrectly ▶

Summary

Adds a five-second startup grace to omarchy-screensaver. Keys still close it during startup; focus loss closes it after the grace ends.

  • Screensavers wait five seconds before closing after losing focus.

Reviews (1) · Last reviewed commit: "screensaver: survive the launcher's focu..." · Reviewed by Greptile

Comment on lines +19 to +20
[[ -f $tmpdir/ttfx-stop ]] || touch "$tmpdir/ttfx-stop" 2>/dev/null || true
rm -rf "$tmpdir"

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 Test leaves children running

The pkill stub does nothing, and cleanup removes ttfx-stop immediately after creating it. If the ttfx child misses that brief interval, it keeps waking every 50 milliseconds forever. Repeated test runs can accumulate these children.

Stop and wait for the children before removing the directory, or let the ttfx stub exit immediately since the fake pgrep already keeps the screensaver loop running.

Comment on lines +70 to +76
printf 'x' >&"$keys"
for (( attempt = 0; attempt < 50; attempt++ )); do
kill -0 "$saver_pid" 2>/dev/null || break
sleep 0.1
done
if kill -0 "$saver_pid" 2>/dev/null; then
fail "a key closes the screensaver even inside the grace window" "$(head -c 400 "$tmpdir/out")"

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 Key check can pass incorrectly

The test sends a key about 2.5 seconds after startup, then allows another five seconds for exit. Because the fake active window remains foot, the screensaver exits on its own when the startup grace ends. This passes the assertion even if keyboard dismissal is broken.

Set activewindow.json to the screensaver class before sending the key so focus loss cannot make this check pass.

@omarchybot

Copy link
Copy Markdown
Collaborator

Read the diff at 485530c against quattro, along with #15489 and the launcher (bin/omarchy-launch-screensaver). Nothing has run yet, and no label is applied: the second opinion (Codex Medium) that confirms every classification could not run today because its daily review budget is spent. With only one model's call (a bug fix), the classification is unsettled. This pull request goes round again once the reviewer is available, and it is verified on a worker then.

Two things that verification has to settle, noted here so they are visible now:

  • Screensaver closes itself about a second after launch and cancels the idle lock #15489 is a single-display machine (DP-4 only), so the walk visits one monitor and hands focus straight back to it. In the log quoted above, the launcher exits at 34.048 and the window closes at 35.130, so the focus check failed after the walk was already over. The grace only fixes this if focus comes back to the screensaver on its own within five seconds. If it doesn't, the close (and the cancelled lock) just moves from about one second to about five. The reproduction will check this on a real compositor rather than with stubs.
  • Keep screensavers open while the launcher moves focus between monitors #15243 (older, labelled verified) changes the same focus check in bin/omarchy-screensaver for the multi-monitor walk, using a pid marker that holds only while the launcher runs. The two overlap on multi-monitor setups. Which one lands, or whether both do, is the maintainer's call.

Waiting on the second opinion, then on a worker run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Screensaver closes itself about a second after launch and cancels the idle lock

2 participants