Skip to content

Reload once more after a modeless monitor recovers, so clients learn its size - #16778

Open
Hamza0101 wants to merge 3 commits into
omacom:quattrofrom
Hamza0101:modeless-reload-after-recovery
Open

Hamza0101 wants to merge 3 commits into
omacom:quattrofrom
Hamza0101:modeless-reload-after-recovery

Conversation

@Hamza0101

@Hamza0101 Hamza0101 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #14422

When a monitor comes back through a KVM switch, Hyprland sometimes announces it at 0x0 and applies the real mode about half a second later. It sends the new wl_output.mode then, but not a new zxdg_output_v1.logical_size: Hyprland re-sends that only on monitor.layoutChanged and config.reloaded (src/protocols/XDGOutput.cpp). GTK clients that were already running keep the monitor at 0x0, take its scale as infinite, and Nautilus segfaults on its next icon redraw there. A manual hyprctl reload clears it. That is #14422.

recover_modeless() in bin/omarchy-hyprland-monitor-watch already reloads while a monitor has no mode, but it stops as soon as every monitor reports one. Every reload it made was made at 0x0, so nothing re-sends the size once the mode is there. The loop now reloads once more when it sees the monitor recover, the step omarchybot proposed on the issue. A loop that never saw a modeless monitor doesn't, so the configreloaded that final reload fires starts a loop that finds everything healthy and stops without reloading. The reload guard still holds it off during a package transaction. A healthy machine is never reloaded, as before.

#15542 edits the same loop to skip internal panels; the two changes touch different lines and combine without conflict in meaning.

Reproduce on a VM

The 0x0-then-mode sequence comes from a KVM switch or a monitor that announces itself before its EDID; a VM's virtual output can't produce it on demand, so the recovery loop is exercised against a model of Hyprland instead:

$ bash test/shell.d/monitor-modeless-test.sh

With bin/omarchy-hyprland-monitor-watch from quattro it fails at a recovered monitor gets one more reload so clients see its size; on this branch all 16 checks pass.

Validation

  • test/shell.d/monitor-modeless-test.sh: the startup scenario now expects one more reload once the monitor reports its mode and none after, and a new scenario has the mode arrive on its own after a reload made at 0x0, the KVM case, and expects exactly one reload made at the recovered size, and nothing after it. The stubbed hyprctl records the width at each reload, so a slow runner adding one more reload at 0x0 can't break the count. The scenario that follows startup waits for the new loop's first reload rather than the second overall. In an Arch container the file passes five runs out of five (16 checks) with four CPU hogs running beside it. With the watcher reverted it fails at a recovered monitor gets one more reload so clients see its size.
  • monitor-recovery-test.sh passes. bash -n and git diff --check pass. The 0x0-then-mode sequence needs real hardware or a KVM; it was not reproduced, and this was not run on an Omarchy install.

Human check

Switch a KVM away and back with Nautilus open on that monitor. After the switch, journalctl --user -b | grep 'scale > 0' should stay quiet, and Nautilus should keep running.

@greptile-apps

greptile-apps Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the previously reported test race is fixed.

Summary

The watcher reloads once more after a monitor recovers so running clients learn its size.

  • Recovered monitors get one more reload so clients learn their size.

Reviews (3) · Last reviewed commit: "Label each stubbed reload with the width..." · Reviewed by Greptile

Comment thread test/shell.d/monitor-modeless-test.sh Outdated
Comment on lines +245 to +249
before=$(reloads)
printf '%s' '[{"name":"DP-1","width":2560,"height":1440,"disabled":false}]' >"$monitors_file"
await_reloads $((before + 1)) || fail "a mode that arrives on its own gets a reload after it" "$(<"$reload_log")"
sleep 0.6
(( $(reloads) == before + 1 )) || fail "recovery stops after the reload for the size" "$(<"$reload_log")"

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 Recovery test can fail randomly

After before=$(reloads), the watcher can read the old 0x0 state before the test writes the recovered size. It then logs another recovery reload, followed by the required reload after recovery. The exact before + 1 check rejects this valid sequence, so a busy runner can fail even when recovery works.

Have the stub record the monitor size at each reload, then check for exactly one reload with the recovered size instead of counting all reloads after the snapshot.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fair: the loop can still reload once at 0x0 between the snapshot and the write. The stubbed hyprctl reload now logs the width the monitor had when it was asked for, and the case checks that exactly one reload was made at 2560 and that it was the last, however many came before at 0x0. Five runs out of five pass with four CPU hogs running beside the test; with the watcher reverted it still fails.

The KVM scenario writes the mode at an arbitrary moment. Landing between the watcher's 0x0 query and the reload it decided on, the write relabeled that recovery reload as made at 2560, so a slow runner saw two and failed a correct watcher. The stub now records what each `monitors all` query returned and logs the reload against that.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Codex Medium <[email protected]>
Co-Authored-By: muse-wonder via pi, thinking high <[email protected]>
@omarchybot

Copy link
Copy Markdown
Collaborator

I checked this against quattro and pushed one fix to the new test. The watcher change itself is unchanged. Next it needs the KVM that #14422 came from, so @a1lazydog, could you try it as described below?

What was checked, on an Omarchy worker VM (Hyprland 0.57.0):

  • My own reproduction ran the watcher against a stubbed hyprctl. The output starts at 0x0, the watcher reloads it, then the mode arrives on its own. On quattro the only reload is made at 0x0. At this head one more reload follows at 2560, and then it stops.
  • On the real compositor, hyprctl reload sent a running Nautilus a fresh zxdg_output_v1.logical_size, so the extra reload delivers the size, as the PR says.
  • I polled hyprctl monitors all 3,879 times across five reloads and a working output never showed 0x0. This head's watcher, run against the live session, added no reloads to one manual reload.
  • test/shell.d/monitor-modeless-test.sh passes at this head five runs out of five, and monitor-recovery-test.sh passes. With the watcher reverted, the test fails. ./test/cli is green. ./test/shell has 7 failures in 9 files, none of them about monitors. Seven files fail the same way on this PR's base commit, and the other two pass when run on their own.

Fixed on your branch (228e400): the new KVM test could fail on a slow runner even when the watcher was right. The test writes the mode at an arbitrary moment. If that write landed between the watcher's 0x0 query and the reload it chose, the stub logged that recovery reload as made at 2560, and the test saw two. The stub now logs each reload at the width the watcher's last query returned. I proved this by slowing the reload guard and delaying the test's write: the old test failed three runs out of three and the fixed one passed three out of three.

Second opinion: Codex Medium and muse-wonder (via pi, thinking high) reviewed the change. Both found the test race above, and both found nothing wrong with the fix in a second round. They agreed the watcher change is sound and proportionate, which I had concluded too; their independence from my reasoning is not guaranteed. They also raised three points that are not defects in this PR:

To test on the machine with the KVM (it replaces the watcher for this session only; logging out and back in restores the installed one):

curl -fsSLo ~/omarchy-hyprland-monitor-watch https://raw.githubusercontent.com/Hamza0101/omarchy/228e400a4e0c99b01ea82c7342a08f1a21f410a7/bin/omarchy-hyprland-monitor-watch
chmod +x ~/omarchy-hyprland-monitor-watch
pkill -f bin/omarchy-hyprland-monitor-watch; setsid -f ~/omarchy-hyprland-monitor-watch

Then switch the KVM away and back a few times with Nautilus open on that monitor. journalctl --user -b | grep 'scale > 0' should stay quiet, and Nautilus should keep running. Please also say whether the screen ever kept reloading after a switch.

This waits on that confirmation from the reporter of #14422. After that it goes to the maintainer.

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

Development

Successfully merging this pull request may close these issues.

recover_modeless() stops at "has a mode" while GTK clients still see the output at 0x0, so Nautilus segfaults after a KVM switch

2 participants