Skip to content

Run display brightness from omarchy-media: one process per key press, not sixteen - #13286

Draft
cefege wants to merge 1 commit into
omacom:quattrofrom
cefege:native-brightness-display
Draft

cefege wants to merge 1 commit into
omacom:quattrofrom
cefege:native-brightness-display

Conversation

@cefege

@cefege cefege commented Sep 26, 2026 •

Copy link
Copy Markdown

A brightness key press currently spends about sixteen processes:

monitor name omarchy-hyprland-monitor-focused (bash + hyprctl + jq)
is it an Apple display omarchy-hyprland-monitor-focused-apple (bash + hyprctl + jq)
which device omarchy-hw-display (bash)
read brightnessctl + awk
write brightnessctl
read again, for the OSD brightnessctl + awk
OSD omarchy-osd (bash + jq) + omarchy-shell (bash + timeout + qs)

default/hypr/bindings/media.lua marks those bindings repeating = true, so
it happens several times a second while the key is held down.

This moves the implementation to
cefege/omarchy-media, which does the
same work in one binary: the monitor list comes from Hyprland's socket instead
of hyprctl | jq, the internal panel is read from /sys/class/backlight
directly, and the OSD is one qs ipc call. exec replaces the wrapper's shell
rather than running beside it, so a press is one process, plus the qs call
the OSD needs and a brightnessctl call on writes, where the kernel node is
root-owned and brightnessctl is what talks to systemd-logind.

Same argv, same percentages, same exit codes. The # omarchy: header stays,
because omarchy routes subcommands through it.

Measured

omarchy-media bench runs the query form 50 times with every helper on PATH
replaced by a logging stub, and reports what a press cost and what it called:

  mean    0.76 ms
  hyprland socket: in use
  helper processes invoked: 0

The comparable figure is a shell loop over each side, 50 runs, timed the same
way on the same machine (aarch64, Hyprland, one internal panel):

Per invocation Processes
this script 25.3 ms ~16
omarchy-media 9.7 ms 1
/bin/true, for scale 7.4 ms 1

That machine spawns processes slowly, which is what the last row is for: most
of what is left after the rewrite is the cost of starting any process at all.
The work itself is under a millisecond, and the process count goes from sixteen
to one. Run it on your own hardware with the loop the bench prints.

Deliberate behaviour differences

  • A failed write is an error. The script ignores brightnessctl's exit
    status and carries on to show an OSD for a brightness that did not change.
    The native command exits 1 with the reason on stderr. Only reachable when
    brightnessctl also fails.
  • The internal panel is read from the kernel, not through brightnessctl.
    The percentage is brightnessctl's rule, roundf(current / max * 100) in
    f32, so the number on the OSD does not move.

Tests

test/shell.d/brightness-display-test.sh passes unchanged apart from two cases
that are re-pointed at where the work happens now: the panel case reads a fake
kernel node instead of asserting a brightnessctl call, and the focused-monitor
case answers Hyprland instead of stubbing a script this no longer calls. Both
still assert the same behaviour. The full suite and
brightness-display-apple-cache-test.sh pass against the wrapper.

The package carries 39 tests of its own, 14 of which drive the built binary
with the same stubs and are the port of that suite; they found four bugs in the
native implementation, which is why they exist here rather than upstream.

Before this can merge

omarchy-media needs to be in a repository this can install from. It is
packaged and ready, but AUR is not GitHub, so submitting it is a manual step
and it is not done yet. Without it the base package list would fail to
pacstrap.

🤖 Generated with Claude Code

A brightness key press spends about sixteen processes: hyprctl and jq
twice over for the monitor name, three more bash helpers, brightnessctl
and awk to read the percentage, brightnessctl to write it, the same
again for the OSD, then omarchy-osd and omarchy-shell around jq and
timeout. Those bindings are repeating, so it happens several times a
second while the key is down.

omarchy-media does the same work in one binary, and exec replaces this
shell rather than running beside it, so a press is one process plus the
qs call the OSD needs. Same argv, same percentages, same exit codes.

Two cases in the test suite are re-pointed at where the work happens
now: the internal panel is read from the kernel node rather than
through brightnessctl, and the focused monitor comes from Hyprland
rather than from a stub for the script this no longer calls. Both
assert the same behaviour as before.

Co-Authored-By: cefege <cefege@users.noreply.github.com>
@cefege

cefege commented Sep 26, 2026

Copy link
Copy Markdown
Author

Notes for whoever reviews this, so they are not all in the description.

Trying it without the package

omarchy-media builds with cargo and no dependencies beyond libc:

git clone https://github.com/cefege/omarchy-media
cd omarchy-media && cargo build --release
PATH="$PWD/target/release:$PATH" ./test/shell.d/brightness-display-test.sh

The suite runs green against the wrapper that way — it is how the four bugs in
the port were found. omarchy-media bench prints what one press costs and how
many helper processes it invoked, with every helper replaced by a logging stub:

  mean    0.76 ms
  hyprland socket: in use
  helper processes invoked: 0

Fifty runs of each, same machine, timed the same way:

per press processes
the script in quattro 25.3 ms ~16
this branch 9.7 ms 1
/bin/true, for scale 7.4 ms 1

That machine spawns processes slowly, which is why the last row matters: most of
what remains after the rewrite is the cost of starting any process at all. On
hardware that spawns in a millisecond the gap widens. If you would rather see it
on yours, the loop is printed at the end of the bench output.

The two behaviour differences, in full

A failed write now exits 1. The script runs brightnessctl set without
checking its status, then shows an OSD for a brightness that did not change, and
exits 0. This exits 1 and prints the reason to stderr. Reachable only when
brightnessctl also fails, which is to say when the panel is gone.

The internal panel is read from the kernel. Not through brightnessctl.
The percentage is still brightnessctl's rule — roundf(current / max * 100) in
f32, read out of brightnessctl.c rather than guessed — so the OSD number
does not move. A unit test sweeps the whole range against that formula.

Reverting

One commit, one file of behaviour. git revert it and drop the
omarchy-media line from install/omarchy-base.packages; nothing else in the
tree refers to the binary, because the wrapper keeps the command name and the
bindings never change.

What is not in here

The audio and keyboard commands are the same shape and are not part of this PR.
The audio one has a decision in it that deserves its own thread: pactl stays
a child process unless the binary links libpipewire.

@jandrusk

jandrusk commented Oct 8, 2026

Copy link
Copy Markdown

One blocking issue besides the packaging step you already listed: adding omarchy-media to install/omarchy-base.packages only covers fresh installs. On existing machines, the wrapper becomes exec omarchy-media ... on the next update, and the brightness keys stop working (command not found). The exception is if the omarchy package itself depends on it. It needs a migration, for example:

echo "Install omarchy-media for the brightness keys"
omarchy-pkg-add omarchy-media

The larger question is a product call: moving a core key path into a separate binary from a personal repo means the maintainers take on its packaging and review. #13332 also edits omarchy-brightness-display (the hyprsunset fallback), so whichever lands second has to be redone.

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