From 007d6fcd7dd9bb992c3bd92ebd36db089f3b470f Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Fri, 7 Aug 2026 23:59:50 +0200 Subject: [PATCH] Use the gmux backlight instead of the Touch Bar on T2 Macs (#6597) * Match display backlight candidates against real globs [[ ]] does not do pathname expansion, so amdgpu_bl* and acpi_video* only ever tested for files with a literal asterisk in the name. Every machine without intel_backlight silently fell through to the alphabetical first entry, which picks acpi_video0 over amdgpu_bl0. Co-Authored-By: Claude Opus 5 (1M context) * Use the gmux backlight instead of the Touch Bar on T2 Macs /sys/class/backlight on a T2 Mac holds appletb_backlight and gmux_backlight. Neither was a candidate, so the alphabetical fallback picked the Touch Bar and brightness keys dimmed it instead of the display. Add gmux_backlight and never fall back to the Touch Bar, which is not a display panel on any Mac. gmux ranks above the GPU backlights because apple-gmux only registers its device when the kernel has already selected it for the machine, and on dual-GPU Macs the GPU's own PWM stops driving the panel as soon as that GPU suspends. Fixes #6558 Co-Authored-By: Claude Opus 5 (1M context) --------- Co-authored-by: Claude Opus 5 (1M context) --- bin/omarchy-hw-display | 14 +++++--- test/shell.d/hw-display-test.sh | 64 +++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 4 deletions(-) create mode 100755 test/shell.d/hw-display-test.sh diff --git a/bin/omarchy-hw-display b/bin/omarchy-hw-display index dcab14ac..d3c6d3e6 100755 --- a/bin/omarchy-hw-display +++ b/bin/omarchy-hw-display @@ -3,11 +3,17 @@ # omarchy:summary=Print the most likely display backlight device. # omarchy:examples=omarchy-hw-display +backlight_path="${OMARCHY_BACKLIGHT_PATH:-/sys/class/backlight}" + # Start with the first possible output, then refine to the most likely given an order heuristic. -device="$(ls -1 /sys/class/backlight 2>/dev/null | head -n1)" -for candidate in amdgpu_bl* intel_backlight acpi_video*; do - if [[ -e /sys/class/backlight/$candidate ]]; then - device="$candidate" +# Glob the candidates in the loop list: [[ ]] does not do pathname expansion. +# The Touch Bar on T2 Macs registers a backlight that never drives the display panel. +device="$(ls -1 "$backlight_path" 2>/dev/null | grep -vx appletb_backlight | head -n1)" +# gmux comes first: apple-gmux only registers when the kernel has already picked it, and on +# dual-GPU Macs the GPU's own PWM stops driving the panel once that GPU suspends. +for candidate in "$backlight_path"/gmux_backlight "$backlight_path"/amdgpu_bl* "$backlight_path"/intel_backlight "$backlight_path"/acpi_video*; do + if [[ -e $candidate ]]; then + device="${candidate##*/}" break fi done diff --git a/test/shell.d/hw-display-test.sh b/test/shell.d/hw-display-test.sh new file mode 100755 index 00000000..e4028831 --- /dev/null +++ b/test/shell.d/hw-display-test.sh @@ -0,0 +1,64 @@ +#!/bin/bash + +set -euo pipefail + +source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" + +tmp_dir=$(mktemp -d) +trap 'rm -rf "$tmp_dir"' EXIT + +write_backlights() { + rm -rf "$tmp_dir/backlight" + mkdir -p "$tmp_dir/backlight" + + local device + for device in "$@"; do + mkdir -p "$tmp_dir/backlight/$device" + done +} + +hw_display() { + OMARCHY_BACKLIGHT_PATH="$tmp_dir/backlight" "$ROOT/bin/omarchy-hw-display" +} + +write_backlights intel_backlight +device=$(hw_display) +[[ $device == "intel_backlight" ]] || fail "the only backlight is used" "actual: $device" +pass "the only backlight is used" + +write_backlights acpi_video0 amdgpu_bl1 +device=$(hw_display) +[[ $device == "amdgpu_bl1" ]] || fail "globbed candidates beat the alphabetical fallback" "actual: $device" +pass "globbed candidates beat the alphabetical fallback" + +write_backlights acpi_video0 intel_backlight +device=$(hw_display) +[[ $device == "intel_backlight" ]] || fail "the candidate order is honored" "actual: $device" +pass "the candidate order is honored" + +write_backlights nvidia_wmi_ec_backlight +device=$(hw_display) +[[ $device == "nvidia_wmi_ec_backlight" ]] || fail "an unknown backlight falls back to the first device" "actual: $device" +pass "an unknown backlight falls back to the first device" + +write_backlights appletb_backlight gmux_backlight +device=$(hw_display) +[[ $device == "gmux_backlight" ]] || fail "a T2 Mac uses gmux instead of the Touch Bar" "actual: $device" +pass "a T2 Mac uses gmux instead of the Touch Bar" + +write_backlights appletb_backlight +if hw_display >/dev/null 2>&1; then + fail "the Touch Bar is never used as the display backlight" +fi +pass "the Touch Bar is never used as the display backlight" + +write_backlights acpi_video0 amdgpu_bl0 appletb_backlight gmux_backlight intel_backlight +device=$(hw_display) +[[ $device == "gmux_backlight" ]] || fail "gmux outranks the GPU backlights on dual-GPU Macs" "actual: $device" +pass "gmux outranks the GPU backlights on dual-GPU Macs" + +write_backlights +if hw_display >/dev/null 2>&1; then + fail "no backlight device reports failure" +fi +pass "no backlight device reports failure"