Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions bin/omarchy-brightness-display
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

no_osd=0
monitor=""
panel_without_ddc=""

while (( $# > 0 )); do
case "$1" in
Expand Down Expand Up @@ -40,7 +41,7 @@ use_apple_display() {
}

use_ddc_display() {
[[ -n $monitor ]] && ! monitor_is_internal && monitor_may_have_ddc
[[ -n $monitor ]] && ! monitor_is_internal && monitor_may_have_ddc && ! monitor_is_panel_without_ddc
}

# A platform whose display driver registers no DDC channel says so in its
Expand All @@ -60,10 +61,25 @@ monitor_may_have_ddc() {
return 0
}

# An all-in-one wires its built-in panel to a DP connector, which DDC/CI does not answer.
# When that is the only display and the kernel has a backlight, take the backlight to be its own.
monitor_is_panel_without_ddc() {
if [[ -z $panel_without_ddc ]]; then
panel_without_ddc=0
[[ $monitor == DP-* ]] && monitor_may_have_ddc &&
hyprctl monitors all -j 2>/dev/null | jq -e --arg monitor "$monitor" 'length == 1 and .[0].name == $monitor' >/dev/null 2>&1 &&
omarchy-hw-display >/dev/null 2>&1 &&
! omarchy-brightness-display-ddc "$monitor" >/dev/null 2>&1 &&
panel_without_ddc=1
fi

(( panel_without_ddc ))
}

# The kernel backlight is the built-in panel's, so an external monitor without
# DDC fails rather than dimming the panel.
use_backlight_display() {
[[ -z $monitor ]] || monitor_is_internal
[[ -z $monitor ]] || monitor_is_internal || monitor_is_panel_without_ddc
}

if (( $# == 0 )); then
Expand Down
14 changes: 14 additions & 0 deletions test/shell.d/brightness-display-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ cat >"$mock_bin/omarchy-hw-display" <<'SH'
printf 'mock_backlight\n'
SH

cat >"$mock_bin/hyprctl" <<'SH'
#!/bin/bash
default='[{"name":"eDP-1"},{"name":"DP-1"},{"name":"DP-2"}]'
printf '%s\n' "${HYPR_MONITORS:-$default}"
SH

cat >"$mock_bin/brightnessctl" <<'SH'
#!/bin/bash
printf 'brightnessctl %s\n' "$*" >>"$CALL_LOG"
Expand Down Expand Up @@ -139,6 +145,14 @@ grep -F 'ddcutil --bus 7 --skip-ddc-checks --noverify setvcp 10 5' "$call_log" >
fail "external low brightness writes the one-percent target"
pass "external low brightness uses a one-percent step"

# An all-in-one's built-in panel is its lone display, on DP-1, and does not answer DDC.
rm -f "$runtime_dir/omarchy-brightness-display-ddc/DP-1.bus"
: >"$call_log"
HYPR_MONITORS='[{"name":"DP-1"}]' DDC_READ_FAIL=1 run_brightness --no-osd --monitor DP-1 60%
grep -Fx 'brightnessctl -d mock_backlight set 60%' "$call_log" >/dev/null || \
fail "all-in-one panel on a DP connector sets the kernel backlight" "$(<"$call_log")"
pass "all-in-one panel on a DP connector falls back to the kernel backlight"
Comment on lines +148 to +154

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 Fallback safeguards lose test coverage

The shortened block removes the lone-DP checks for working DDC, failed DDC writes, and missing backlights. The remaining external-display tests use multiple monitors, so they skip the new fallback check. Restore these cases and their mock failure switches so a change that sends a readable DP monitor to the kernel backlight cannot pass unnoticed.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!


cat >"$mock_bin/hyprctl" <<'SH'
#!/bin/bash
printf '%s\n' '[
Expand Down
Loading