Skip to content

Restore gmux_backlight brightness on wake when hardware diverges - #20354

Open
JamesCaudill wants to merge 3 commits into
omacom:quattrofrom
JamesCaudill:fix/gmux-backlight-wake-restore
Open

JamesCaudill wants to merge 3 commits into
omacom:quattrofrom
JamesCaudill:fix/gmux-backlight-wake-restore

Conversation

@JamesCaudill

@JamesCaudill JamesCaudill commented Nov 26, 2026 •

Copy link
Copy Markdown

Fixes #13890

Summary

On dual-GPU Macs using gmux_backlight, the gmux firmware resets the hardware backlight to 80% (actual_brightness=52428/65535) when the panel powers down after deep S3 suspend while leaving the kernel's requested brightness unchanged. Because apple-gmux is not tied to the GPU's DPMS power sequence, nothing re-sends the requested level when the panel wakes.

This adds restore_gmux_backlight to bin/omarchy-system-wake:

  • No-op with zero subprocesses when /sys/class/backlight/gmux_backlight is absent or brightness == actual_brightness.
  • When actual_brightness != brightness, re-applies the kernel's requested brightness via brightnessctl -d gmux_backlight set "$requested".
  • Runs in omarchy-system-wake rather than after the DPMS dispatch in omarchy-brightness-display on, so it still runs when key_press_enables_dpms has already lit the panel and omarchy-brightness-display on exits early.

Verification

Tested live on a 2019 16-inch MacBook Pro (MacBookPro16,1, Intel Core i9-9980HK, Intel UHD 630 + AMD Radeon Pro 5500M, linux-t2 7.2.15-arch1-1-t2, mem_sleep_default=deep):

  • DPMS-only check (no suspend): hyprctl dispatch 'hl.dsp.dpms({ action = "disable" })' for 3s then enable kept brightness=9830 and actual_brightness=9830 (confirming plain DPMS blanking without suspend does not trigger the reset).
  • Before fix (post-suspend lock blank): After deep S3 wake and lock-screen blanking, gmux_backlight diverged to brightness=9830 actual=52428 max=65535 (80%).
  • After fix (end-to-end live test): With the patched omarchy-system-wake installed at /usr/bin/omarchy-system-wake, repeating the full deep S3 suspend → resume → lock-screen blank → key-press wake cycle restored gmux_backlight to brightness=9830 actual=9830 max=65535 (no 80% flash/stuck brightness).
  • Automated tests: Added regression coverage in test/shell.d/brightness-display-test.sh (all checks pass).

On dual-GPU Macs, gmux resets the panel backlight (commonly to 80%) when the
panel powers down after deep S3 suspend while leaving the kernel's requested
brightness unchanged. Re-apply the requested brightness in omarchy-system-wake
whenever gmux_backlight's actual_brightness diverges from brightness.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@JamesCaudill
JamesCaudill marked this pull request as draft November 26, 2026 23:24
@greptile-apps

greptile-apps Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge, with no new blocking issues found.RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge, with no new blocking issues found.

Summary

Restores gmux_backlight after wake when the hardware brightness differs from the requested level.

  • System wake restores the requested gmux backlight level when the hardware differs.

Reviews (5) · Last reviewed commit: "Wait for brightness adjustments before r..." · Reviewed by Greptile

Comment thread bin/omarchy-system-wake Resolved
@JamesCaudill
JamesCaudill marked this pull request as ready for review November 26, 2026 23:40
Use brightnessctl set +0 so brightnessctl re-reads the current kernel
brightness rather than writing a stale value, and take a non-blocking
flock on omarchy-brightness-display.lock to skip restoring while a
display brightness change is already in progress.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread bin/omarchy-system-wake Resolved
@omarchybot omarchybot added bug Something isn't working compatibility Make Omarchy work better on everything! labels Nov 26, 2026
An external display adjustment holds the shared brightness lock without updating gmux. Skipping the wake restore while that lock is held leaves the internal panel at its reset level. Wait for the adjustment and then reapply the current requested level.

Co-Authored-By: GPT-6 High (Codex) <noreply@openai.com>
@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at 411829523ad31714d4823456ee5faf6a618eed2e by GPT-6 High in Codex, with Opus 5.5 High and muse-wonder via pi (thinking high). The CLI suite and all 15 brightness checks passed on a disposable Omarchy worker. A new contention regression failed on the original code, passed with the fix, and failed again with the fix reverted. That proves the lock handling; the worker has no gmux hardware.

Pushed 411829523ad31714d4823456ee5faf6a618eed2e to wait for the shared brightness lock before restoring gmux. An external DDC or Apple display adjustment holds that lock without updating the built-in backlight, so skipping the restore could leave the panel at its reset level. Both reviewers found no actionable defect in that commit; their independence is not guaranteed. The narrower read/write race with the direct brightness-key path is documented in the review thread.

I also compared #9189, #12423, #16718 and #18775. Their restores require a level saved by an earlier blank; this change can repair divergence without that snapshot, including a reset at resume itself. The issue already links here through Fixes #13890.

@josemiguelo, this still needs confirmation on the affected Mac at the full SHA above. The author's hardware report is useful, but neither you nor a maintainer has confirmed this revision. To try this head's runtime change on a packaged install using /usr/bin/omarchy-system-wake, back up the current command and install the exact script:

cp /usr/bin/omarchy-system-wake /tmp/omarchy-system-wake-before-20354
curl -fsSL https://raw.githubusercontent.com/JamesCaudill/omarchy/411829523ad31714d4823456ee5faf6a618eed2e/bin/omarchy-system-wake -o /tmp/omarchy-system-wake-20354
sudo install -m755 /tmp/omarchy-system-wake-20354 /usr/bin/omarchy-system-wake

Repeat deep suspend → resume → lock-screen blank → key wake at low brightness, and report brightness and actual_brightness before and after wake, including whether the 80% flash remains. Also try unlocking before the lock screen blanks. Restore the original afterwards with sudo install -m755 /tmp/omarchy-system-wake-before-20354 /usr/bin/omarchy-system-wake. This waits on that hardware result.

@omarchybot

Copy link
Copy Markdown
Collaborator

On current quattro, #20856 routes the MacBookPro16,1 panel through Intel after the migration and reboot, and #21163 runs the wake command when the lid opens. GPT-6 High in Codex, Opus 5.5 High and muse-wonder via pi (thinking high) checked both changes in source. The restore in this PR now also runs on lid-open.

@josemiguelo, on a build with those changes, could you check whether apple_gmux.force_igd=1 is active in /proc/cmdline and record gmux_backlight's brightness and actual_brightness at two points after deep suspend: when you open the lid, and after you let the lock screen blank and wake it with a key? Start with the unpatched build. If the mismatch still occurs, please repeat with 411829523ad31714d4823456ee5faf6a618eed2e using the earlier test instructions.

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

Labels

bug Something isn't working compatibility Make Omarchy work better on everything!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dual-GPU Macs: after resume, the lock screen's blank resets the gmux backlight to 80% and nothing restores the user's level

2 participants