Skip to content

Only treat lost focus as a dismissal once the screensaver has held focus - #7102

Open
omarchybot wants to merge 2 commits into
quattrofrom
fix/issue-6917
Open

omarchybot wants to merge 2 commits into
quattrofrom
fix/issue-6917

Conversation

@omarchybot

@omarchybot omarchybot commented Aug 16, 2026 •

Copy link
Copy Markdown
Collaborator

The screensaver's watchdog exits when hyprctl activewindow stops reporting the screensaver's class, which is meant to catch the user clicking away onto another window. hyprctl activewindow only ever reports toplevels, so it cannot see a layer surface. When a bar panel is open it holds layer-shell keyboard focus (shell/Ui/KeyboardPanel.qml:98) and the newly mapped screensaver never becomes the active toplevel at all -- the panel leaves the previously focused terminal sitting there as activewindow. bin/omarchy-screensaver:44 then reads "never acquired focus" as "the user dismissed me" and the screensaver kills itself on the first tick of the loop, about one second after it appeared. That matches the lifetimes the reporter measured across five failures (1.046, 1.044, 1.228, 1.235, 1.235s): the 1.000s read -n1 -t 1 timeout plus the wait_for_terminal_resize prefix.

The damage is not just the flash of a window. The idle service watches for the screensaver's window closing and treats it as activity: handleScreensaverWindowClosed cancels the idle cycle with screensaver-dismissed (shell/plugins/services/idle/Service.qml:138), and cancelIdleCycle stops the pending lock timer. Leaving the battery dropdown open and walking away therefore leaves the machine idle and unlocked.

This latches a flag the first time the screensaver is genuinely focused, and only counts the absence of focus as a dismissal after that. Sampling focus before the blocking read rather than after it means a normal launch latches immediately, so clicking away is still detected within the same second as before.

This deliberately fixes only half of #6917. With a panel open the fullscreen window rule also fails to apply and the screensaver draws as a floating 700x500 window. default/hypr/apps/system.lua:35 registers that rule through Hyprland's own hl.window_rule (via the thin wrapper at default/hypr/helpers.lua:142) and Omarchy has no other fullscreen path, so the failure is inside the compositor and not fixable here. What is left after this change is a screensaver that stays up, keeps the lock timer armed, and locks on schedule -- but is still a small floating box on that cycle. Making it go fullscreen regardless, or closing open panels before launching, is a call for you rather than a defect to correct.

Not a duplicate of #6995, which needs a lock already in flight, launches a second screensaver into it, and ends in a ttfx SIGABRT with a core dump. This one needs no lock at all and leaves no core dump.

Touches the same loop as the open #6813, which keeps the read -n1 -t 1 || ! screensaver_in_focus condition verbatim and so does not fix this; whichever lands second will need a small rebase.

Fixes #6917

Fixes #13265

Fixes #8114

The screensaver's watchdog exits when `hyprctl activewindow` stops reporting the screensaver class, which is meant to catch the user clicking away onto another window. `hyprctl activewindow` only ever reports toplevels, though, so it cannot see a layer surface. When a bar panel is open it holds layer-shell keyboard focus and the newly mapped screensaver never becomes the active toplevel at all -- the panel leaves the previously focused terminal sitting there as `activewindow`. The check then reads "never acquired focus" as "the user dismissed me" and the screensaver kills itself on the first tick of the loop, roughly one second after it appeared.

The damage is not just the flash of a window. The idle service watches for the screensaver's window closing and treats it as activity: `handleScreensaverWindowClosed` cancels the idle cycle with `screensaver-dismissed`, which stops the pending lock timer. Walking away with the battery dropdown open therefore leaves the machine idle and unlocked.

Latch a flag the first time the screensaver is genuinely focused and only count the absence of focus as a dismissal after that. Sampling focus before the blocking read rather than after it means a normal launch latches immediately, so clicking away is still detected within the same second as before.

This leaves the other half of #6917 alone: with a panel open the fullscreen window rule does not apply either and the screensaver draws as a floating 700x500 window. That happens inside the compositor -- `default/hypr/apps/system.lua` registers the rule through Hyprland's own `hl.window_rule` and Omarchy has no other fullscreen path -- so it is not fixable here.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings August 16, 2026 11:09

Copilot AI left a comment

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.

Copilot wasn't able to review any files in this pull request.


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@EduardsSk

Copy link
Copy Markdown

The latch fixes the panel case, but the same watchdog has a second trigger it does not cover: a multi-monitor launch, where the screensaver does hold focus first and then loses it while omarchy-launch-screensaver is still working.

omarchy-launch-screensaver iterates monitors, focusing each one (hypr_focus_monitor) and waiting for that monitor's window (wait_for_screensaver_window) before moving on. While it spawns monitor N+1, the instance already running on monitor N sees monitor N+1's previously focused toplevel as activewindow. With this PR applied that instance has already set was_focused=1 on its first tick, so the second tick takes the elif branch and calls exit_screensaver — which pkills ttfx and every org.omarchy.screensaver window, taking the whole set down.

Captured from Hyprland's event stream on a three-output session, launched from the menu entry (omarchy-launch-screensaver force), with no user input at any point:

focusedmon>>eDP-1,3
activewindow>>org.omarchy.btop,btop
openwindow>>…,3,org.omarchy.screensaver,Ghostty
activewindow>>org.omarchy.screensaver,Ghostty    <- instance 1 holds focus; was_focused=1
focusedmon>>DP-5,1
activewindow>>md.obsidian.Obsidian,…             <- instance 1 now sees a foreign toplevel
openwindow>>…,1,org.omarchy.screensaver,Ghostty
activewindow>>org.omarchy.screensaver,Ghostty
focusedmon>>DP-6,2
activewindow>>com.mitchellh.ghostty,…            <- and again
closewindow>>…                                   <- whole set gone, ~3.7s after launch
closewindow>>…

Whether it fires depends on how long the launch takes relative to the 1s read -n1 -t 1 tick, which is presumably why single-output reporters only see the panel variant. Spawn-to-mapped for the same class on this machine:

terminal spawn-to-mapped × 3 outputs
foot 0.18s ~0.6s
alacritty 0.28s ~0.9s
ghostty 0.50s (warm) ~2.7s in a real launcher run (~0.85s per monitor including the per-monitor wait)

The consequence is the one described in the second half of #6917: handleScreensaverWindowClosed reads the closes as a dismissal, cancelIdleCycle stops the pending lock, and the session does not lock. One day of this machine's journal: 5 cycles cancelled as screensaver-dismissed, 3 of them 2.3–3.3s after idle-cycle-start — too fast to be a human — with no lock on those cycles. (The other two came 73s and 110s in and may well be genuine dismissals.) The cycles that did lock are the ones where the launcher returned in under a second without spawning anything.

A complement that would close this: don't enforce the focus check until every output has a screensaver window — compare hyprctl clients -j filtered on the class against hyprctl monitors -j | jq length, with a deadline so a failed spawn falls through to current behaviour, and a short read inside the wait so a keypress still dismisses.

Fully aware #7193 makes this moot if it lands, since one exclusive overlay per output removes both the terminal spawn sequence and the activewindow watchdog. Posting mainly so the multi-monitor trigger is on record in case the latch ships first.

Environment
Omarchy 4.0.0-1
Hyprland 0.56.2
Quickshell 0.3.0.r20.g28771c7-1
ttfx 0.3.1-1
ghostty 1.3.1-2 (xdg-terminal-exec --print-id → com.mitchellh.ghostty.desktop)
Kernel 7.1.8-arch1-3
Outputs eDP-1 1920x1200, DP-5 2560x1440, DP-6 3840x2160

The latch watches for any screensaver-class window being active, so the comment says it has been seen with focus rather than that it held it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Codex Medium <noreply@openai.com>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Sep 28, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator Author

Re-checked against current quattro (3faafba2), which now opens screensavers on special:screensaver-<monitor> workspaces. The bug is still there and this still fixes it. Tested on a disposable worker (Hyprland, foot, one 1280x800 output) with the PR merged onto that commit, and no input given:

omarchy.menu open clock calendar (omarchy-keyboard-panel) open no panel
quattro gone at ~1.1s gone at ~1.1s stays
this PR stays past 4.7s stays past 4.7s stays
this PR, fix reverted gone at ~1.1s gone at ~1.1s —

With the panel case on this PR, closing the menu hands focus to the screensaver, which latches it, and clicking away then dismisses it as before. Clicking away with no panel open still dismisses within a second. test/shell.d/screensaver-workspace-test.sh and system-lock-test.sh pass. ./test/cli has one failure, vscode generated theme references current theme file, which fails the same way on quattro without this change. Linked #13265 as well, since that is this bug with the clock calendar as the trigger.

I pushed one commit, c9eef00, that shortens the comment above was_focused to two lines and says the screensaver has been seen with focus, since the check watches for any screensaver-class window being active.

@EduardsSk, your multi-monitor trigger is real in quattro's launcher: it still focuses each monitor before spawning that monitor's screensaver, so a running instance can see a foreign toplevel as active for as long as the next terminal takes to map. This PR leaves it no more likely than quattro does. It can only exit at the checks where quattro would, and it spares an instance that has not yet been seen with focus. With foot on two outputs, the worker kept both screensavers up on quattro and on this PR alike, which fits your timing table. It needs ghostty-slow spawns, and fixing it means coordinating the launcher, so it is separate work. #7193 would remove that path along with this one.

Residual: if focus moves somewhere else before the first sample (right after ttfx starts), the screensaver stays up until a keypress reaches it or the lock fires, and omarchy-system-lock kills it then. Any deadline for "never focused" would bring back the failure on a panel that stays open.

#13475 fixes the same bug by closing open panels at launch and ignoring focus for five seconds. It covers only panels the shell knows how to close. If the focus-holding surface outlives the five seconds, the original failure comes back. It closes whatever panel the user had open, and it carries unrelated Windows VM permission changes. #6813 keeps the read -n1 -t 1 || ! screensaver_in_focus exit and does not fix this.

Second opinion: Codex Medium reviewed the change in two rounds and found nothing open on this head. Independence is not guaranteed. It raised the startup window above, which it judged a residual to name rather than a blocker, and suggested the comment wording. Asked separately to choose between this and #13475, it picked this one for the reasons above.

This is waiting on the maintainer.

@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Oct 31, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator Author

This no longer applies to quattro. fdbe182 (Launch the native Wayland screensaver) deleted bin/omarchy-screensaver, the only file this PR changes, along with the hyprctl activewindow focus watchdog it fixed. omarchy-launch-screensaver now execs /usr/lib/omarchy-screensaver/omarchy-screensaver, which draws a layer-shell overlay and is dismissed by input rather than by losing focus. That is why it now shows as conflicting, and there is nothing left to port.

I checked the reported failure on a disposable worker running quattro at e4fffc6 with omarchy-screensaver 1.3.1-1 (Hyprland, foot focused behind it). With omarchy.menu open, the case that killed the old screensaver at ~1.1s, the native screensaver was still running after 6s. It also stayed up with no panel open. I did not get the clock calendar panel open in that run, so that trigger is untested, and I did not run a full idle cycle through to the lock.

Codex Medium reviewed the PR diff, fdbe182 and the current idle service. It agreed that nothing in this PR still applies. It also pointed out that the idle service still cancels the lock cycle when the screensaver exits while the idle monitor reports activity (handleScreensaverExited, shell/plugins/services/idle/Service.qml), so the probe supports "the menu case no longer reproduces", not "#6917, #8114 and #13265 are fixed". Independence is not guaranteed.

This is waiting on the maintainer, with a recommendation to close it as superseded by the native screensaver. The three linked issues would then stay open until someone confirms them against the native screensaver.

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

Labels

bug Something isn't working

Projects

None yet

3 participants