Skip to content

Recover laptop display after external disconnect - #7207

Open
omnomburp wants to merge 2 commits into
omacom:quattrofrom
omnomburp:fix/internal-monitor-disconnect-recovery
Open

omnomburp wants to merge 2 commits into
omacom:quattrofrom
omnomburp:fix/internal-monitor-disconnect-recovery

Conversation

@omnomburp

@omnomburp omnomburp commented Aug 17, 2026 •

Copy link
Copy Markdown

Disabling the laptop screen with SUPER + CTRL + DEL can leave the laptop screen still dark after removing the HDMI cable.

Apparently Hyprland can temporarily retain a disconnected output as active even after DRM reports that it is physically disconnected. Every event-driven recovery attempt can therefore exit early, leaving the internal-display toggle enabled.

Fix is to check that a external monitor is connected with the DRM and that Hyprland reports a connected external monitor

Fixes #7209

The fixture built a single external connector, so the case its comment
described -- one display removed while another remains -- was never
exercised. omarchy-hw-external-monitors scans every connector and answers
from the first connected one it finds, so a disconnected connector read
before a connected one must not settle the answer. Take the external
states as arguments and add the two-connector case.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed by Claude Opus 5 with an independent second opinion from Codex at xhigh reasoning. The change holds up. Reading it as a truth table over (external physically connected, Hyprland reports an external active, toggle present), the guard changes exactly one cell — DRM says gone, Hyprland still says active, toggle present — from "do nothing" to "recover". Every other cell behaves as it did on quattro. Codex derived the same table independently and reached the same single-cell delta.

Checked the shapes this must not disturb, since a monitor script runs on every hardware shape:

  • Desktop with no internal panel. No-op. Neither off() nor the mirror's on() can create a toggle without an internal display, so omarchy-hyprland-toggle-enabled returns false and recover bails.
  • Two externals, one unplugged. No-op. omarchy-hw-external-monitors scans every connector and answers from the first connected one it finds, so the remaining display keeps the panel disabled.
  • Lid closed. recover clears internal-monitor-disable.lua; clamshell disabling uses a separate internal-monitor-clamshell.lua that recover never touches, so an ordinary docked clamshell session is unaffected.
  • The mirror script. The rewrite is !A && T to (!H || !A) && T — the same guard, plus the hardware check. The non-mirror path is untouched.

One thing for the maintainer rather than for you: with the lid shut and the panel disabled by the manual toggle, this now re-enables it on physical disconnect. That is the same thing enable_internal in omarchy-hyprland-monitor-clamshell already does today in the ordinary clamshell case, so the change makes the manual-toggle case consistent with the case around it rather than inventing new behaviour — but it is a judgement call about undocking a shut laptop and it is not ours to make, so it is flagged, not changed.

Pushed one commit (9c26006): the new test's fixture built a single external connector, so the case its own comment described — one display removed while another remains — was never actually exercised. write_connectors now takes the external states as arguments and there is a two-connector case. Mutation-proved: making omarchy-hw-external-monitors answer from the first connector it reads instead of scanning them all turns that assertion red and nothing else.

Tests, all on a disposable VM with a real compositor, never on the review machine: monitor-internal-recovery-test.sh 7/7 after the addition, plus monitor-recovery, monitor-state, monitor-clamshell-scale, lid-close, monitor-modeless, hw-external-monitors and monitor-test — 90 assertions, none failing.

Codex raised the case of a DRM connector reporting unknown rather than connected for a genuinely active external, which would undo a deliberate disable on every two-second poll. Real mechanism, but omarchy-hw-external-monitors is already load-bearing for that same population in omarchy-hw-clamshell and omarchy-system-lid-close, so such hardware is already broken in louder ways than this; not a reason to hold the PR. Its suggested remedy of deferring recovery while the lid is closed we did not take — it would contradict enable_internal a few lines further down the same script. Codex's independence is not guaranteed here, since it can read the machine this review ran on; where it agreed, treat that as agreement rather than as confirmation. The truth table and the unknown case it contributed on its own.

Waiting on the maintainer to merge.

@omarchybot

Copy link
Copy Markdown
Collaborator

Looked at this again against current quattro (3faafba), alongside the other open pull requests fixing the same dark-panel-after-unplug bug (#7209, #7228, #8027, #10584, #12618). This updates the earlier review here: there is a more direct fix, and this one is no longer the one we would recommend.

What Hyprland actually leaves behind. The live capture in #10584 shows that after monitorremoved>>HDMI-A-1 the unplugged HDMI output is gone from hyprctl monitors; what remains is eDP-1 disabled plus an enabled output named FALLBACK. Hyprland creates that output itself whenever the last enabled monitor disappears (FallbackStateKeeper, src/state/FallbackState.cpp in 0.56.2, which creates it and identifies it by that exact name). omarchy-hyprland-monitor-external-active counts it as an external display, so recover() returns early. That is the cause of the stale state this PR describes.

Why #10586 over this one. #10586 excludes FALLBACK inside omarchy-hyprland-monitor-external-active, a one-line change that corrects every caller of the helper (off(), both recover()s, the clamshell script and the monitor-watch poll) rather than two of them. Requiring DRM agreement in recover(), as this PR does, also changes behaviour for setups the bug does not involve:

  • A deliberate headless output (hyprctl output create headless, used for streaming) has no DRM connector, so with the laptop panel disabled or mirrored the clamshell watcher's recovery would re-enable it every time it runs.
  • A usable VGA/DVI display whose connector reports unknown rather than connected fails omarchy-hw-external-monitors, with the same result.
  • With a second external physically connected but disabled in the config, unplugging the active one leaves omarchy-hw-external-monitors true (the disabled one) and omarchy-hyprland-monitor-external-active true (FALLBACK), so the panel still stays dark.

#12616 fixes the same cause by requiring a DRM connector behind every counted output, which also stops counting deliberate headless outputs. #12253 requires a non-zero mode, which does not help here because FALLBACK carries a 1920x1080 mode; it addresses a different, modeless-output problem.

The recovery assertions in test/shell.d/monitor-internal-recovery-test.sh here (toggle removed, reload and wake, no wake without a toggle, a remaining external keeps the panel off) would still be useful coverage on top of #10586, with a FALLBACK fixture in place of the DRM disagreement.

Checked: read the diffs of this PR, #10586, #12616 and #12253 against quattro, every caller of both helpers, and Hyprland's fallback-output source. Nothing was run for this pass: a PR that is not the recommended fix does not get a worker, and the earlier worker results on this head still stand. The second opinion, Codex at medium effort, was asked to pick between the four without being told our answer. It picked #10586 and raised the headless and unknown cases and the disabled-second-external case above. Its independence is not guaranteed.

Waiting on the maintainer to choose between the competing fixes.

@shimsangjoon

Copy link
Copy Markdown

I run 4.0.4-1 on my T14 and have to daily connect/disconnect to various screen setups.

After I applied these changes alongside https://github.com/omacom/omarchy/pull/10586/changes manually to my setup I am no longer having these recovery issues.

Perhaps this info is helpful.

@omarchybot

Copy link
Copy Markdown
Collaborator

@shimsangjoon thanks, that helps. With both applied, though, it can't tell the two fixes apart, and that is the open question here. #10586 alone would be enough if what kept the panel dark was Hyprland's FALLBACK output. This PR's DRM check only adds something if a real, unplugged output also stays enabled in Hyprland. Your result is what either explanation predicts.

If you can, please run with only #10586 applied (revert this PR's changes to bin/omarchy-hyprland-monitor-internal and bin/omarchy-hyprland-monitor-internal-mirror) and repeat your usual undocking. If the panel stays dark, the output of hyprctl monitors all -j and grep . /sys/class/drm/card*-*/status, taken while it is dark, would settle which fix is needed. If it recovers every time, #10586 is sufficient on its own.

Checked: re-read this PR, #10586, #12616 and #12253 against current quattro (8b4eae6). None of the monitor helpers they touch has changed since the last review, and this PR's head has not moved. Nothing was run on a worker for this pass. The second opinion, Codex at medium effort, was asked again which of the four is the best fix and whether your report changes that. It picked #10586 and made the point above about the combined result. Its independence is not guaranteed.

Still waiting on the maintainer to choose between the competing fixes. The recommendation is still #10586.

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.

Laptop display stays dark after disconnecting from External Display

3 participants