Files
omarchy/test/shell.d/brightness-keys-test.sh
T
David Heinemeier HanssonandClaude Opus 5.5 d3fb0284a8 Step the internal backlight in the shell instead of a script per keypress (#13427)
Each brightness key ran omarchy-brightness-display: resolving the focused
monitor and backlight device, checking for an Apple display, reading,
writing and reading back through brightnessctl, then omarchy-osd over a
qs IPC client. That is 64-133ms from keypress to OSD depending on load,
on keys that repeat while held.

The brightness up and down keys now dispatch global shortcuts. On an
internal panel the shell reads the level from sysfs, steps it by the
script's rules, writes it with one brightnessctl, and shows the OSD from
the level read back. A press overlapping one still being applied is
dropped, as the script's flock drops it. External and Apple displays
fall back to the script, which drives them over DDC or their own helper.
The absolute and precise brightness keys still run the script.

Across 24 steps from eight starting levels the shell and the script land
on identical levels, and keypress to OSD drops to ~31ms.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 19:34:36 +02:00

46 lines
1.8 KiB
Bash

#!/bin/bash
set -euo pipefail
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
run_node_test <<'JS'
const fs = require('fs')
const model = requireFromRoot('shell/services/BrightnessModel.js')
// The in-shell brightness keys follow omarchy-brightness-display's steps.
const steps = [
['raise', 60, 65], ['lower', 60, 55],
['raise', 4, 5], ['raise', 5, 10], ['lower', 5, 4], ['lower', 6, 1],
['raise', 98, 100], ['raise', 100, 100], ['lower', 1, 1], ['lower', 2, 1],
]
for (const [action, current, target] of steps) {
assertEqual(model.brightnessKeyTarget(action, current), target, `brightness ${action} from ${current}% lands on ${target}%`)
}
const qml = fs.readFileSync(path.join(root, 'shell/services/BrightnessKeys.qml'), 'utf8')
assert(
qml.includes('if (!/^(eDP|LVDS|DSI)-/.test(name) || !device) return false'),
'brightness keys act in the shell only on the internal panel and defer external and Apple displays to the script'
)
assert(
/if \(setProc\.running\) return true/.test(qml),
'brightness keys drop a press that overlaps one still being applied, as the script does'
)
assert(
/file\.reload\(\)\s*file\.waitForJob\(\)/.test(qml),
'brightness keys read the current level fresh, so a level changed elsewhere steps from the right place'
)
assert(
qml.includes('var current = Math.round(100 * readNumber(brightnessFile) / max)') &&
qml.includes('var percent = Math.round(100 * readNumber(brightnessFile) / max)'),
'brightness keys compute percentages as brightnessctl reports them'
)
const shellQml = fs.readFileSync(path.join(root, 'shell/shell.qml'), 'utf8')
assert(
/if \(!shell\.brightnessKeys\.handle\(entry\.target\)\)\s*Util\.execArgv\(\["omarchy-brightness-display", entry\.target === "raise" \? "\+5%" : "5%-"\]\)/.test(shellQml),
'a brightness key the shell declines runs omarchy-brightness-display'
)
JS