omarchy icon indicating copy to clipboard operation
omarchy copied to clipboard

[Quattro] omarchy-launch-screensaver creates focus-check race condition on 3+ monitor setups causing immediate self-termination

Open grhoades opened this issue 3 months ago • 3 comments

System details

  • Hardware: Framework Desktop, AMD Ryzen AI Max 395 (Radeon 8060S Graphics)
  • Omarchy Version: 4.0.0-1 (Quattro)
  • Hyprland Configuration: Lua parser (~/.config/hypr/hyprland.lua)
  • Display Setup: 3 monitors (DP-1 portrait, HDMI-A-1 ultrawide, DP-4 landscape) vs 2 monitors tested
  • Terminal: Kitty

What's wrong?

On multi-monitor setups with 3 or more displays, omarchy-launch-screensaver triggers and then immediately self-terminates after a few seconds without any user interaction. On a 2-monitor system with identical Omarchy Quattro configuration, the screensaver runs as expected.

When the screensavers self-terminate, omarchy-shell's idle manager (Service.qml) interprets the closed windows as a manual dismissal, issues omarchy-system-wake, and cancels the idle sequence—preventing idle.lock (300s) and display DPMS power-down from ever activating.

Mechanism & Root Cause

  1. Sequential Output Launch Loop: In /usr/bin/omarchy-launch-screensaver, screensavers are spawned sequentially across all connected displays:

    for m in $(hyprctl monitors -j | jq -r '.[].name'); do
      hypr_focus_monitor "$m"
      case $terminal in ... esac
      wait_for_screensaver_window
    done
    hypr_focus_monitor "$focused"
    

    Each monitor iteration focuses the monitor, spawns the terminal screensaver window, and waits for the corresponding socket2 openwindow event.

  2. The 3+ Monitor Timing Race: In /usr/bin/omarchy-screensaver, the main loop starts checking focus immediately with a 1-second timeout:

    while pgrep -t "${tty#/dev/}" -x ttfx >/dev/null; do
      if read -n1 -t 1 || ! screensaver_in_focus; then
        exit_screensaver
      fi
    done
    
    • On a 2-monitor system, the loop completes quickly enough that both windows map and focus is restored to the primary monitor within ~1 second.
    • On a 3+ monitor system, cycling through all three displays takes 2–4 seconds.
    • While the launcher is busy focusing Monitor 2 and Monitor 3, Monitor 1's screensaver process reaches its first 1-second timeout and evaluates screensaver_in_focus.
  3. Global Active Window Query: screensaver_in_focus() checks global compositor focus:

    screensaver_in_focus() {
      hyprctl activewindow -j | jq -e '.class == "org.omarchy.screensaver"' >/dev/null 2>&1
    }
    

    Because compositor focus is actively transitioning to Monitor 2/3 (or momentarily lands on existing windows on those workspaces before the screensaver terminal is mapped), Monitor 1 sees that activewindow is not its own screensaver class. ! screensaver_in_focus evaluates to true, executing exit_screensaver (pkill -f org.omarchy.screensaver) and killing all screensavers across all monitors.

Steps to Reproduce

  1. Connect 3 displays with active application windows on each workspace.
  2. Trigger the screensaver via omarchy-launch-screensaver or wait for idle.screensaver (150s).
  3. Observe Monitor 1 launch, followed by Monitor 2/3, followed by immediate teardown within 3–6 seconds without user input.

Suggested Solutions

  1. Startup Grace Period: Add an initial grace period (e.g. 5–6 seconds) to omarchy-screensaver before evaluating screensaver_in_focus, giving multi-monitor launch loops sufficient time to finish mapping all screens.
  2. Event-Driven Dismissal: Rather than polling global activewindow every second in each terminal process, rely on compositor idle/wake notifications from omarchy-shell and terminal keypress/signal handlers to handle screensaver dismissal.

Filed by Gemini via Antigravity CLI.

grhoades avatar Aug 24 '26 22:08 grhoades

Also reproduces on a single monitor — and I don't think #8142 covers that case

I hit this on a one-monitor laptop, which contradicts the "3+ display setup" minimum trigger in the issue description (and the note that 2-monitor setups work). The launcher here finishes in ~330 ms, so the "launcher takes 2-4 s to iterate monitors" explanation doesn't apply, yet the screensaver still self-terminates and still takes the lock down with it.

I traced it, and on a single monitor the cause is not the focus check that #8142 addresses - it is the read -n1 -t 1 on the same line. Details and instrumentation below.

Evidence

Broken cycle, single monitor (eDP-1, the only output). Idle config is the default screensaver: 150, lock: 300:

21:59:15.232  idle-monitor: idle
21:59:15.233  idle-cycle-start: screensaver=150 lock=300
21:59:15.233  process-start: screensaver
21:59:15.566  idle-monitor: active
21:59:15.567  idle-monitor-active: screensaver cycle remains armed
21:59:15.608  process-exit: screensaver exitCode=0 status=0
21:59:17.901  idle-cycle-cancel: screensaver-dismissed     <- nobody touched the machine
21:59:17.901  process-start: wake omarchy-system-wake

The handleActiveSignal guard at Service.qml:164 does its job — the cursor warp from hypr_focus_monitor registers as activity, and the cycle correctly stays armed. The cycle dies 2.3 s later on the closewindow path instead, at Service.qml:129 → cancelIdleCycle("screensaver-dismissed") (Service.qml:138), which stops lockTimer (Service.qml:103). The lock and the DPMS blank never run. The cycle then re-arms, fires 150 s later, self-dismisses again, and repeats indefinitely.

Observed screensaver lifetimes before self-termination, across five cycles: 2.3 s, 5 s, 9.67 s, 59 s, and one that survived. So it is a race, not a fixed timeout.

Control: the lock works whenever the launcher does not run

Two independent controls on the same machine, same boot:

  1. A cycle that began while the screen was already locked, so the [[ $(omarchy-shell lock isLocked) == "true" ]] || wrapper short-circuited and omarchy-launch-screensaver never executed:
14:04:14.202  idle-cycle-start: screensaver=150 lock=300
14:04:14.399  process-exit: screensaver exitCode=0 status=0
14:06:44.213  lock-system: lock-timeout          <- fires correctly, 150.01 s later
  1. With the screensaver-off toggle set, so the launcher exits at its toggle check before any hyprctl call:
22:20:33.543  idle-monitor: idle
22:20:33.543  idle-cycle-start: screensaver=150 lock=300
22:20:33.758  process-exit: screensaver exitCode=1     <- launcher never ran
22:23:03.544  lock-system: lock-timeout                <- 150.001 s later, on time

Note that in the working cases there is no idle-monitor: active event at all. When the screensaver does not launch, the machine locks and blanks exactly as designed.

It is not a focus race on a single monitor - traced and ruled out

I instrumented Hyprland's socket2 event stream at ms resolution across a failing cycle. The screensaver holds focus for its entire life:

18:15:28.637  openwindow>>55fc7daa2b60,1,org.omarchy.screensaver,foot
18:15:28.638  activewindow>>org.omarchy.screensaver,foot     <- takes focus 1 ms after mapping
18:15:28.638  fullscreen>>1
        ... no focus change whatsoever for 9.67 s ...
18:15:38.309  closewindow>>55fc7daa2b60                      <- dies on its own
18:15:38.311  activewindow>>foot,focus-experiment            <- focus moves only AFTER, a consequence

So the trailing hypr_focus_monitor "$focused" at omarchy-launch-screensaver:77 does not steal focus here, and screensaver_in_focus is not what fires. My first theory was wrong.

What actually fires: the read -n1 -t 1 branch

I ran an instrumented copy of omarchy-screensaver with the two exit conditions at line 44 split apart so they could be told from one another:

18:20:09.013  round 1: spawned ttfx pid=22860
18:20:15.320  EXIT CAUSE = stdin byte on the pty: $'\E'
18:20:15.327  exit_screensaver called

A bare ESC (0x1B) arrived on the terminal's stdin and read -n1 -t 1 consumed it, which the watchdog treats as "the user pressed a key". The pty then closes, and the idle service turns that into screensaver-dismissed.

Worth noting what it is not: I captured 4.8 MB of ttfx's output stream and it emits no terminal queries at all (no DA1/DA2, DSR, XTVERSION, XTGETTCAP, OSC 10/11 query) and enables no reporting modes - the only private-mode sequence in the whole stream is CSI ?25l to hide the cursor. So the ESC is not a reply to something ttfx asked for.

The behaviour is intermittent, which fits the observed lifetimes (2.3 s, 5 s, 9.67 s, 59 s, and one cycle that survived). A second instrumented run saw no ESC in 30 s; instead ttfx exited on its own twice and the while true loop restarted it. Each restart is a fresh opportunity for whatever writes that byte to land.

I have not identified what writes the ESC. One suspect I could not confirm: this system runs fcitx5, and hl-virtual-keyboard-fcitx5 is Hyprland's main keyboard, re-applying its layout on every focus change (activelayout events bracket the screensaver's life in the trace). But no activelayout event coincides with the kill, so I am not claiming it. Happy to dig further if useful.

This matters for #8142

If I read the PR correctly, it makes screensaver_in_focus tolerate a focused window that is another screensaver instance or has no class. That is a fix to the focus-check path. The single-monitor failure above exits through the read path instead, and would be untouched by it. The multi-monitor race may well be real and separate - but closing this issue on #8142 would leave single-monitor systems still failing.

More generally, read -n1 -t 1 as a dismissal test means any byte appearing on that pty - an escape-sequence reply, an input-method artefact, a stray report - is indistinguishable from a keypress, and the consequence is not "the screensaver closes" but "the machine never locks again".

A separate hardening point in the idle service

Independent of what makes the screensaver exit: handleScreensaverWindowClosed (Service.qml:129) treats any disappearance of the screensaver window as a deliberate user dismissal and cancels the whole cycle, lockTimer included. It has no equivalent of the grace/armed check that protects the activity path at Service.qml:164.

That means any unexpected screensaver exit — this race, a ttfx crash, an OOM kill, a stray pkill — silently leaves the machine permanently unlocked, with no log line that reads as an error. Given that the failure mode is "the laptop never locks", it seems worth making the lock timer survive a screensaver that dies without user input, so a screensaver bug can never become a lock bug.

Impact

The security half is hardware-independent: the machine never locks, and nothing surfaces that to the user.

The power half I measured on this laptop (2012 MacBookPro10,2, 2560x1600 eDP): the panel never blanks, so it holds 15.01 W indefinitely instead of dropping to 7.89 W — 7.12 W wasted continuously, about 13% of its 55.5 Wh battery per idle hour. It ran itself flat and powered off while unattended, which is how I found this.

Environment

  • Omarchy 4.0.1-1
  • Hyprland 0.56.2 (commit efb5099)
  • quickshell 0.3.1-1, foot 1.27.0-2, ttfx 0.3.2-1
  • Single output: eDP-1, [email protected], scale 2
  • Default idle config: screensaver: 150, lock: 300

Workaround in the meantime is omarchy-toggle-screensaver, which restores locking and DPMS blanking completely — verified above.


Filed by Claude Opus 5 via Claude Code.

leonqi77 avatar Aug 31 '26 01:08 leonqi77

Correction to my comment above — I can't reproduce the self-termination, and my mechanism claim was wrong

Retracting the central claim of my previous comment. I tried to nail down what puts the ESC on the pty and instead found I can't reproduce the spontaneous exit at all.

What I ran

I built a copy of omarchy-screensaver that watches both exit conditions at line 44 independently and never exits, so one run shows which would have fired and how often:

test duration result
instrumented copy, launched directly 330 s, 57 ttfx rounds neither branch fired
instrumented copy, via a faithful omarchy-launch-screensaver replica (full focus dance, wait_for_screensaver_window, trailing focus restore) 300 s, 55 rounds neither branch fired
the real unmodified omarchy-screensaver, launched directly 120 s survived the whole window
ttfx output across 6 random effects 33.7 MB captured no DA1/DA2, DSR, XTVERSION, XTGETTCAP or OSC query; the only private-mode sequence is CSI ?25l

The error in my reasoning

I argued that because no idle-monitor: active event appears before each death, there was no user input. That is wrong, and it invalidates the inference.

The cursor warp from hypr_focus_monitor flips the idle monitor to active about 330 ms into the cycle. handleIdleChanged only logs on a state transition. Once isIdle is already false, subsequent genuine keyboard or pointer input produces no further log line at all. So the journal cannot distinguish "the screensaver died on its own" from "the user touched the machine nine seconds later" — and I read the silence as proof of the former.

The single ESC I captured is best explained as my own keypress: a fullscreen screensaver appeared unannounced during testing and I interrupted moments later. An ESC on that pty is exactly what dismissing it looks like.

On that reading, all the early exits I observed are ordinary user dismissal — which Service.qml:135-137 documents as intended behaviour.

I should also withdraw "it ran itself flat and powered off while unattended". The evidence is an 85-second gap between the previous boot's last journal line and the next boot, with the battery at 9% and charging. That is equally consistent with a deliberate reboot. I stated an inference as a fact.

What I still think is worth your attention

Two things from my earlier comment do not depend on the retracted mechanism.

1. handleScreensaverWindowClosed has no guard. Service.qml:129 treats any disappearance of the screensaver window as deliberate dismissal and stops lockTimer (Service.qml:103), where the activity path at Service.qml:164 has an explicit armed/grace check. Whatever closes the window — a genuine dismissal, a ttfx crash, an OOM kill, a stray pkill — the machine then never locks and never blanks, and nothing in the log reads as an error. Making the lock timer survive a screensaver that dies without a corresponding input event would keep a screensaver bug from becoming a lock bug.

2. The single-monitor observation still stands, even though my explanation for it doesn't. On one output, cycles where omarchy-launch-screensaver ran ended in screensaver-dismissed and never locked; cycles where it did not run (screen already locked, or the screensaver-off toggle set) locked at exactly 150.001 s. I can no longer say why the first group ended early, so treat that as an observation in need of a cause, not as evidence against #8142.

Sorry for the noise — better to correct it than to leave a wrong mechanism sitting in the thread while you evaluate the PR.

An incidental gotcha for anyone else instrumenting this: exit_screensaver runs pkill -f '[o]rg.omarchy.screensaver', which matches any process whose command line merely contains that string. It killed my own tooling twice for having the class name in a jq filter.


Filed by Claude Opus 5 via Claude Code.

leonqi77 avatar Aug 31 '26 02:08 leonqi77

Reproduced on current quattro (c352b62d6), on a disposable Omarchy 4.0.4 VM with Hyprland 0.56.2, three to five outputs (extra ones via hyprctl output create headless) and a regular window on each output after the first.

What happens. omarchy-launch-screensaver focuses each monitor in turn and waits for that monitor's screensaver to map. Between the focus move and the map, the monitor's existing window is the active window. An earlier screensaver polling screensaver_in_focus in that gap sees a foreign class, calls exit_screensaver, and its pkill -f takes every other screensaver down with it — including the terminal still starting on the current monitor, which is why the launcher then sits out its 5 s wait_for_screensaver_window deadline (the same thing #9713 reports). An instrumented omarchy-screensaver logged exactly that: the first screensaver's focus check fired about 1.1 s after it started with activewindow on the third output's regular window, and the second screensaver died of the resulting SIGHUP.

When. It depends on how long the terminal takes to map, not strictly on three monitors. With Ghostty 1.3.1 every screensaver was gone within about 1.3 s in every trial, on three outputs and on five. With foot and kitty, three outputs launched in 0.8–1.3 s and survived 3 of 3 trials each, so a slower machine or more outputs is what tips those over. #14377 describes the same race.

Fixes already open. Two open pull requests each made the reproduction pass, with Ghostty and five outputs, 4 of 4 trials (against 0 of 4 on quattro):

  • #7102 only treats lost focus as a dismissal after the screensaver has held focus. It now says it fixes this issue.
  • #13475 ignores lost focus for the first 5 s of each screensaver's life.

Neither coordinates with the launcher: both rely on the hop finishing before a check lands on a foreign window, so a launch where a later monitor's terminal takes several seconds to map could still dismiss them all. Choosing between them is the maintainer's call.

The diagnosis was made by Claude Opus 5.5 and checked by Codex at medium effort, which agreed with the mechanism and independently raised the missing launcher handshake above; its independence from this session is not guaranteed. This waits on the maintainer.

omarchybot avatar Oct 09 '26 00:10 omarchybot