Skip to content

Fall back to hyprsunset gamma on displays without DDC/CI - #13332

Open
C50NK4 wants to merge 1 commit into
omacom:quattrofrom
C50NK4:software-brightness-fallback
Open

C50NK4 wants to merge 1 commit into
omacom:quattrofrom
C50NK4:software-brightness-fallback

Conversation

@C50NK4

@C50NK4 C50NK4 commented Sep 26, 2026

Copy link
Copy Markdown

TVs and many OLED monitors don't support DDC/CI, so on those displays the brightness keys and the Display panel slider do nothing. Follows up on #8302.

When the DDC probe fails on an external display, omarchy-brightness-display now dims with hyprsunset gamma instead:

  • 20% minimum. 20% is already quite low, even in a dark room. At 1% you can easily lose track of the cursor and not find your way back to the slider, and then a restart is the only way out.
  • Remembers a failed probe for 60s. On my LG TV, every failed DDC probe takes about 4 seconds (detect finds an I2C bus, then getvcp times out). Without this, each key press and each panel refresh would stall.
  • Starts hyprsunset if it isn't running, the same way the nightlight toggle does.
  • No change for internal panels, Apple displays, or monitors where DDC works.

Known limits:

  • hyprsunset gamma applies to every output, so dimming a DDC-less external display also dims any other screen.
  • The panel slider still goes below 20%. The screen stays at 20% and the slider shows the right value the next time the panel opens.

Tested on an LG OLED TV over DP (via a dock) with no DDC/CI. test/shell.d/brightness-display-test.sh covers the fallback, the 20% floor, and retrying DDC after the fallback expires.

🤖 Generated with Claude Code

TVs and many OLED monitors have no DDC/CI, so the brightness keys and
the Display panel slider did nothing on them. When the DDC probe fails
on an external display, dim with hyprsunset gamma instead, never below
20% so the screen stays readable. The failed probe is remembered for a
minute because each one takes several seconds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@llstrk

llstrk commented Sep 27, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Verified: on the happy path the fallback does what the description says. When the DDC probe fails on an external display, steps go to hyprctl hyprsunset gamma, are clamped to 20..100, the failed probe is remembered for 60 s, and reads return the gamma value so the Display panel gets a slider. The internal and Apple branches, and DDC steps that succeed, behave as before. The updated test passes on this head and fails against the base script.

Two behavioural problems showed up in sandboxed runs with stubbed hyprctl, ddcutil, uwsm-app and hyprsunset.

Starting hyprsunset from this script keeps the brightness lock held

set_gamma_brightness starts hyprsunset (bin/omarchy-brightness-display:76) while the script holds flock on omarchy-brightness-display.lock (:136-137). Only stdout and stderr are redirected, so the daemon inherits the lock descriptor. Nothing in the real launch chain closes it: util-linux setsid closes no descriptors before execvp, uwsm-app with its default unit type (Omarchy does not set UWSM_APP_UNIT_TYPE) execs systemd-run --user --scope, and that execvpes hyprsunset in place (per upstream source; this chain was not executed). A flock lock belongs to the open file, so it stays held for as long as hyprsunset runs.

hyprsunset not running (default: Omarchy does not autostart it)
  step 1  --monitor DP-2 5%-   -> starts hyprsunset, gamma 95, OSD 95
          hyprsunset now holds fd -> omarchy-brightness-display.lock
  step 2  --monitor DP-2 5%-   -> flock -n fails, exit 0, no calls, gamma still 95
  step 3  --monitor eDP-1 +5%  -> flock -n fails, laptop backlight unchanged
  kill hyprsunset              -> lock free, steps work again

Controls: with hyprsunset already running (as after the nightlight toggle), repeated steps work. Adding {lock_fd}>&- to the launch line also makes repeated steps work.

Impact: on a session where hyprsunset is not already running, the first gamma step works, then the brightness keys and the Display panel slider silently stop for every display (laptop panel, Apple and DDC monitors included) until hyprsunset exits. The panel shows the value it tried to set until its next refresh (within 5 s while open).

Suggested change: close the descriptor for the launch, for example setsid uwsm-app -- hyprsunset {lock_fd}>&- >/dev/null 2>&1 &, or start hyprsunset before taking the lock. A test with pgrep reporting "not running" would cover the launch path, which the current pgrep mock (always succeeds) skips.

Any DDC helper failure switches a working DDC monitor to global gamma, and the dimming stays

:148 (step) and :108-109 (read) call mark_ddc_missing whenever omarchy-brightness-display-ddc exits nonzero. The helper also exits 1 for a transient getvcp failure, a failed setvcp and an unrecognised step, so each of these marks a working DDC monitor as DDC-less for 60 s. A failed step then goes to gamma instead (a typo step still exits 1), and later steps and reads use gamma until the marker expires. The base treated transient read failures as retryable on the next call without caching them, and its test asserted that; the updated test deletes the marker by hand before checking the retry (test/shell.d/brightness-display-test.sh:140).

DDC monitor DP-1, sandbox run Base This PR
5%- whose getvcp fails once exit 1, nothing changes gamma 95 (all outputs), marker written
next 5%- DDC setvcp (45%) gamma 90, no DDC call
after 60 s, +5% DDC DDC setvcp (55%), gamma stays 90
typo 50, then 50% 50% goes to DDC typo writes the marker, 50% sets gamma 50
one failed setvcp, 30% exit 1 gamma 30

Impact: on a monitor where DDC works, one failed DDC call turns the keys and slider into global gamma for 60 s, which also dims every other output. Dimming set in that window survives the return to DDC control: reads then report the DDC value, and nothing in the brightness UI brings gamma back to 100. How often real monitors produce such failures was not measured.

Suggested change: mark a display as DDC-less only when the read probe fails, not on invalid arguments or failed writes (consider requiring more than one failed probe for a monitor that has answered before). When DDC control succeeds while gamma is below 100, restore gamma.

Related open PRs

Smaller notes

  • Gamma outlives the display it was set for: after dimming the TV to 20%, --monitor eDP-1 100% sets the laptop backlight and leaves gamma at 20. After unplugging the TV, the laptop stays dimmed and its brightness keys cannot fix it. This goes a step beyond the acknowledged "dims any other screen" limit; a restart of hyprsunset or the default profile's daily 07:00 re-apply resets it.
  • A failed gamma set still reports success: when hyprsunset cannot start or hyprctl cannot connect to it, every read falls back to 100, the sets fail silently, and set_gamma_brightness still prints the target and exits 0. The OSD shows, for example, 95 on every 5%- press while nothing changes, and each press below 100% takes about 2 s when the launch fails (sleep 1 plus the retry loop), about 1 s when hyprsunset runs but cannot be reached. Checking whether any set command succeeded, rather than only the read-back (a target of 100 matches the fallback reading), would surface this.
  • Leading-zero absolute steps skip the floor: for 08%, bash arithmetic treats 08 as invalid octal, so both clamp checks fail with an error and neither applies. hyprctl hyprsunset gamma 08 is sent, and hyprsunset parses it as 8. Only manual CLI use or custom bindings can produce such a step (keys and the Display panel send plain integers). $((10#${BASH_REMATCH[1]})) in all three step branches avoids it (the relative forms +08% and 08%- also misbehave and land on 20%).
  • Comma-decimal locales: hyprsunset replies with a dot (95.000000). Under de_DE.UTF-8, bash printf '%.0f' in gamma_brightness prints an "invalid number" error and returns 1, so a read exits 1. Some replies are not integral (target 53 comes back as 52.999996), so 53 reads as 52 and setting it takes 5 calls. LC_ALL=C printf '%.0f' avoids this.

Optional test improvement: of nine single-line mutations of the new logic, the updated test caught only the removal of the 20% floor. Not caught: the 60 s marker never honoured or never written (the DDC-less mock has no I2C bus, so the DDC helper's own cache hides it; the author's bus-found, getvcp-fails case is only tested after deleting the marker by hand), an integer-only reply regex (the mock replies 50, real hyprsunset 50.000000), no hyprsunset launch, no retry loop, N%- adding instead of subtracting, and no upper clamp. The base test's check of the DDC helper's own "unavailable" cache was also lost. A bus-found mock, %f replies and pgrep returning "not running" would cover most of these.


Review information

Test scope: source review of the pinned head and merge-base, and of hyprsunset 0.4.0, hyprctl (Hyprland 0.56.2), uwsm 0.27.0, systemd-run 262 and util-linux setsid 2.42.4 source. The PR's test and scenario scripts ran in an isolated sandbox with every display, DDC and hyprsunset command stubbed; the setsid stub ran the real util-linux setsid. No display, DDC hardware, real hyprsunset or live Hyprland session was used, and the real uwsm-app / systemd-run --scope launch chain was not executed. Related open PRs were compared from their current heads, not merged.

AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

@Murderlon

Copy link
Copy Markdown

Are you 100% sure my PR doesn't fix this already? It went through a lot of iterations + upstream research. If so, please close this to reduce noise for maintainers

#9876

@C50NK4

C50NK4 commented Sep 30, 2026

Copy link
Copy Markdown
Author

Checked it on my LG TV before answering. They fix different things: #9876 is for monitors where DDC works but the first write gets ignored. My TV has no working DDC/CI at all. ddcutil finds the bus, but getvcp 10 fails, so your helper (tested at f1617fa) exits after the read and never gets to the write it retries.

So they complement each other rather than overlap. I'd keep this one open for now.

@jandrusk

jandrusk commented Oct 8, 2026

Copy link
Copy Markdown

Heads-up on overlap: #14525 (remember a DDC display whose brightness can't be read) and #14397 (skip DDC buses ddcutil reports as invalid) both change the same "DDC probe failed" path in omarchy-brightness-display-ddc, which already has its own 60s unavailable cache. It would be good to settle on one "this display has no DDC" cache, either the helper's own or this new omarchy-brightness-display-gamma/ file, so the two don't expire at different times and give different answers.

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants