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>
This commit is contained in:
1 parent
25ead28f90
commit
d3fb0284a8
8 files changed
+184
-12
No files matched your search
@@ -0,0 +1,45 @@
|
||||
#!/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
|
||||
@@ -57,6 +57,7 @@ o.bind("C", "listed panel", { panel = "omarchy.emojis" })
|
||||
o.bind("D", "unlisted panel", { panel = "omarchy.wifiqr" })
|
||||
o.bind("E", "listed audio", { audio = "raise" })
|
||||
o.bind("F", "unlisted audio", { audio = "+1" })
|
||||
o.bind("I", "listed brightness", { brightness = "raise" })
|
||||
o.bind("G", "listed ipc", { ipc = "media.next" })
|
||||
o.bind("H", "unlisted ipc", { ipc = "media.sourceNext" })
|
||||
|
||||
@@ -80,6 +81,7 @@ expect_binding $'global\tomarchy:panel.omarchy.emojis\tlisted panel' "a listed p
|
||||
expect_binding $'exec\tomarchy-shell shell toggle \'omarchy.wifiqr\'\tunlisted panel' "an unlisted panel falls back to the command"
|
||||
expect_binding $'global\tomarchy:audio.raise\tlisted audio' "a listed volume key binds its global shortcut"
|
||||
expect_binding $'exec\tomarchy-audio-output-volume \'+1\'\tunlisted audio' "an unlisted volume step falls back to the script"
|
||||
expect_binding $'global\tomarchy:brightness.raise\tlisted brightness' "a listed brightness key binds its global shortcut"
|
||||
expect_binding $'global\tomarchy:ipc.media.next\tlisted ipc' "a listed IPC call binds its global shortcut"
|
||||
expect_binding $'exec\tomarchy-shell \'media\' \'sourceNext\'\tunlisted ipc' "an unlisted IPC call falls back to omarchy-shell"
|
||||
pass "shell bindings use global shortcuts only for what the shell registers"
|
||||
@@ -94,6 +96,8 @@ expect_binding $'global\tomarchy:panel.omarchy.clipboard\tClipboard manager' "th
|
||||
expect_binding $'global\tomarchy:audio.raise\tVolume up' "the volume up key steps the volume in the shell"
|
||||
expect_binding $'global\tomarchy:audio.lower\tVolume down' "the volume down key steps the volume in the shell"
|
||||
expect_binding $'global\tomarchy:audio.mute-toggle\tMute' "the mute key toggles mute in the shell"
|
||||
expect_binding $'global\tomarchy:brightness.raise\tBrightness up' "the brightness up key steps the backlight in the shell"
|
||||
expect_binding $'global\tomarchy:brightness.lower\tBrightness down' "the brightness down key steps the backlight in the shell"
|
||||
expect_binding $'global\tomarchy:ipc.media.playPause\tPlay' "the play key reaches the media service directly"
|
||||
expect_binding $'global\tomarchy:ipc.notifications.dismissOne\tDismiss last notification' "dismissing a notification reaches the service directly"
|
||||
! grep -E $'^exec\tomarchy-shell (media|notifications) ' <<<"$bindings" ||
|
||||
@@ -103,7 +107,7 @@ pass "default bindings toggle menus and panels through global shortcuts"
|
||||
# The shell and the helpers read the same list, in the same format.
|
||||
while IFS= read -r line; do
|
||||
[[ -z $line || $line == \#* ]] && continue
|
||||
[[ $line =~ ^(menu|panel|audio|ipc)\ [^[:space:]]+$ ]] || fail "shortcuts lines are a kind and a target: $line"
|
||||
[[ $line =~ ^(menu|panel|audio|brightness|ipc)\ [^[:space:]]+$ ]] || fail "shortcuts lines are a kind and a target: $line"
|
||||
if [[ $line == ipc\ * ]]; then
|
||||
[[ $line =~ ^ipc\ (media|notifications)\.[A-Za-z]+$ ]] || fail "ipc shortcuts name a mapped target and method: $line"
|
||||
fi
|
||||
|
||||
Reference in new issue
Block a user