Skip to content

Dim internal panels below the backlight floor with hyprsunset gamma - #18326

Open
minholi wants to merge 1 commit into
omacom:quattrofrom
minholi:brightness-gamma-dim
Open

minholi wants to merge 1 commit into
omacom:quattrofrom
minholi:brightness-gamma-dim

Conversation

@minholi

@minholi minholi commented Nov 10, 2026 •

Copy link
Copy Markdown

What this does

Extends the brightness keys below the internal panel's 1% backlight floor with hyprsunset's gamma filter, so a laptop that stays bright at its hardware minimum can dim further (down to 30% gamma). Brightness up retraces the gamma range before the backlight rises.

This follows the suggestion in #11819 and the prototype in https://gist.github.com/minholi/31a52abaae19dc288dfb81bf4f6fb149.

Design notes

  • Only while the laptop panel is the sole active display. hyprsunset gamma is global: with an external monitor connected, dimming the panel would dim the external too. In that case the keys keep today's behavior (1% floor), and any gamma this script set is handed back.
  • Keeps the 1% backlight floor. The dimming range steps from 1% into gamma; it never goes to raw 0, which blanks some panels (Implement non-uniform brightness step adjustments #5525).
  • Preserves a user's gamma. The state records the gamma the user had before dimming; resetting restores that baseline instead of assuming 100. A gamma set outside the script is never overwritten by a normal brightness change.
  • The shell fast path defers at the floor. BrightnessKeys.qml handles internal panels in process; it now returns to the script at 1% so the gamma range is reachable.
  • Precise (Alt) steps use one gamma point, the normal keys five.
  • The OSD shows "Dim N%", translated through omarchy-i18n.

Screenshots

The OSD while an internal panel is below its backlight floor:

OSD showing Dim 75%

Tests

  • test/shell.d/brightness-display-test.sh — gamma steps, the 30% floor, the external-display gate, baseline restoration, a user's gamma left alone, start on demand, and the OSD.
  • test/shell.d/brightness-keys-test.sh — the floor handoff.
  • test/shell.d/brightness-display-apple-cache-test.sh and test/shell.d/i18n-test.sh still pass.

Tested on a VAIO/Positivo AMD Barceló laptop (amdgpu_bl1) with Hyprland 0.56.2 and hyprsunset 0.4.0: backlight fixed at 1%, gamma 80 -> 75 -> 80, state cleared, and the user's 80 kept.

Related

#13261 also used gamma below 1%, but it removes the 1% floor and dims external monitors; it now conflicts with quattro. This takes the internal-panel case while keeping the floor and avoiding that side effect. #13332 is the DDC-less external-monitor case and is complementary.

hyprsunset's gamma filter extends the brightness range below the 1% backlight floor, but it applies to every output. Only use it while the laptop panel is the sole active display, record the user's gamma as the baseline, and hand it back when the range is left.
@greptile-apps

greptile-apps Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The change affects the laptop display-brightness workflow and its shell key handler.

The PR still needs the external-display reset fixed before merging.

Findings

  1. P1 Connected monitors stay dim ▶

Summary

Extends laptop brightness keys below the 1% backlight floor using hyprsunset gamma.

  • Laptop brightness keys dim below the 1% backlight floor.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Brightness key] --> B{Backlight above 1%?}
  B -->|Yes| C[Shell adjusts backlight]
  B -->|No| D[Brightness script]
  D --> E{Lower brightness?}
  E -->|Yes| F{External display active?}
  F -->|Yes| G[Restore saved gamma]
  F -->|No| H[Lower gamma toward 30%]
  E -->|No| I{Saved gamma still owned?}
  I -->|Yes| J[Raise gamma toward saved baseline]
  I -->|No| K[Raise backlight]
Loading

Reviews (2) · Last reviewed commit: "Dim internal panels below the backlight ..." · Reviewed by Greptile

Comment on lines +221 to +222
if (( delta < 0 )) && (( current <= 1 )); then
if gamma_dim_allowed; then

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.

P1 Connected monitors stay dim

The external-display check only runs when lowering brightness at the backlight floor. If a user dims the laptop and then connects an external monitor, nothing restores the saved gamma, so the external screen is dimmed too. Pressing brightness up on the laptop skips this check and keeps the external screen dimmed while gamma climbs back toward the baseline.

Restore owned gamma when an external output becomes active, and check that condition before either gamma-step direction.

Knowledge Base Used: Hyprland configuration and display control

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.

Tested on a Dell XPS 9320 (dev channel, laptop screen only), with the commit on top of current quattro. hyprsunset wasn't running beforehand.

Once I fixed the bug below, it works well: below 1% the keys keep dimming, the OSD shows the dim level, and brightness up lifts the dim first, then the backlight goes up from 1%.

The bug: the first time the script starts hyprsunset, hyprsunset inherits the lock fd and keeps omarchy-brightness-display.lock held for as long as it runs. After that, every press exits at flock -n and the keys stop working in both directions. I got stuck at 1% with gamma at 95. fuser showed hyprsunset holding the lock. The tests pass either way, so they don't catch it.

Closing the fd in the child fixed it for me:

-  setsid uwsm-app -- hyprsunset >/dev/null 2>&1 &
+  setsid uwsm-app -- hyprsunset {lock_fd}>&- >/dev/null 2>&1 &

With that, going down from 1% gave gamma 95 → 90 → 85, and going up went back to 100 and then the backlight rose to 2%. The lock stayed free between presses.

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.

You’re right—this is a real lock-lifetime bug. The background uwsm-app/hyprsunset process inherits lock_fd, so it keeps the flock held after the brightness script exits and causes later key presses to be dropped. Closing the descriptor on the launch command is the right fix:

setsid uwsm-app -- hyprsunset {lock_fd}>&- >/dev/null 2>&1 &

Thanks for catching and reproducing it; the existing tests don’t cover descriptor inheritance by the long-lived child.

Tip: You can customize Greptile's behavior for this repo with .greptile/rules.md and .greptile/config.json.

@omarchybot omarchybot added the enhancement New feature or request label Nov 22, 2026
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.

3 participants