Skip to content
Open
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
709b67a
omarchy-mac: Add omarchy brightness auto, ambient light brightness th…
joshuaswarren Nov 15, 2026
fec1c54
omarchy-mac: Leave idle dimming to Omarchy in the wluma config
joshuaswarren Nov 15, 2026
0ddbc0e
omarchy-mac: Fix brightness auto status, arguments and seeding checks
joshuaswarren Nov 15, 2026
113ecbf
omarchy-mac: Refuse brightness auto without a panel, skip the Touch B…
joshuaswarren Nov 15, 2026
667764e
omarchy-mac: Say why brightness auto stops when the panel disconnects…
joshuaswarren Nov 15, 2026
1dabf33
omarchy-mac: Run the machine's own mv in the brightness-auto test stub
joshuaswarren Nov 15, 2026
9255b71
omarchy-mac: Turn automatic brightness on by default
joshuaswarren Nov 15, 2026
79dfff0
omarchy-mac: Say starting while brightness auto waits for the sensor,…
joshuaswarren Nov 15, 2026
ed2db4b
omarchy-mac: Drop the mid-start disconnect test, prepare already pins it
joshuaswarren Nov 15, 2026
55fb1a9
omarchy-mac: Fail prepare without a panel or config, so a start does …
joshuaswarren Nov 15, 2026
439ee80
omarchy-mac: Leave the keyboard backlight out of the generated wluma …
joshuaswarren Nov 15, 2026
6af0ed4
Manual: say automatic brightness moves the screen only
joshuaswarren Nov 15, 2026
988e120
Manual: the hardware table no longer says the keyboard backlight foll…
joshuaswarren Nov 15, 2026
0c410cf
Manual: name the ambient light sensor on the keyboard page
joshuaswarren Nov 16, 2026
ee0f5f5
Manual: say when the keyboard backlight comes on and what happens aft…
joshuaswarren Nov 16, 2026
b977140
omarchy-brightness-auto: report every failed write and never leave a …
joshuaswarren Nov 16, 2026
d98dc9d
brightness-auto test: match real is-active while starting, cover the …
joshuaswarren Nov 16, 2026
19d3ea4
omarchy-mac: Run the machine's own awk in the brightness-auto test stub
joshuaswarren Nov 16, 2026
9dc638f
omarchy-mac: Leave external displays out of automatic brightness
joshuaswarren Nov 16, 2026
2f755bf
omarchy-mac: Refuse wluma older than 5.0
joshuaswarren Nov 16, 2026
155c16d
vercmp fail-closed + stub; bounded restart; review wording
joshuaswarren Nov 18, 2026
1f33a29
on clears the start limit; burst 5; honest limit wording
joshuaswarren Nov 18, 2026
d94d24a
omarchy-mac: name the panel backlight path in wluma config
joshuaswarren Nov 18, 2026
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
4 changes: 3 additions & 1 deletion mac-manual/content/06-keyboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ Apple keyboards have no Print Screen key, so Omarchy's `Print` bindings have no

## Keyboard backlight

On Macs with an ambient light sensor, the keyboard backlight follows the room: lit in the dark, off in bright light. Apple Silicon keyboards have no backlight keys, so Omarchy's keyboard backlight bindings have no key on the built-in keyboard yet; [omacom/omarchy-mac#683](https://github.com/omacom/omarchy-mac/issues/683) tracks giving it some.
The keyboard backlight comes on at half brightness at the passphrase prompt, then returns to its last level after unlock; the automatic brightness below moves the screen only. Apple Silicon keyboards have no backlight keys, so Omarchy's keyboard backlight bindings have no key on the built-in keyboard yet; [omacom/omarchy-mac#683](https://github.com/omacom/omarchy-mac/issues/683) tracks giving it some.

The screen follows the room, from the ambient light sensor through wluma. It is on by default, as on macOS. `omarchy brightness auto off` stops it and keeps it off; `omarchy brightness auto on` turns it back on. If wluma is missing, `omarchy-pkg-add wluma` installs it. It starts from a built-in curve and keeps learning from the brightness you set by hand.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please say here that an external display keeps the brightness you set, to go with 9dc638f (AGENTS.md:19).

— Marcelo's agent


## Trackpad

Expand Down
2 changes: 1 addition & 1 deletion mac-manual/content/12-hardware.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ This is what the first release is qualified against on both reference Macs. <spa
| --- | --- | --- |
| Apple GPU | <span class="status ok">works</span> | Mesa `vulkan-asahi`, hardware acceleration. A desktop on `llvmpipe` means something is wrong. |
| Internal display, brightness | <span class="status ok">works</span> | The panel includes the strip beside the notch |
| Keyboard, backlight, trackpad | <span class="status ok">works</span> | Drivers loaded early, so they work at the passphrase prompt. The backlight follows the ambient light sensor. See [Keyboard and trackpad]({{page:keyboard}}). |
| Keyboard, backlight, trackpad | <span class="status ok">works</span> | Drivers loaded early, so they work at the passphrase prompt. The backlight comes on at half brightness at the passphrase prompt; automatic brightness leaves it alone. See [Keyboard and trackpad]({{page:keyboard}}). |
| Wi-Fi, Bluetooth | <span class="status ok">works</span> | NetworkManager with the iwd backend. Wi-Fi on BCM4378 and BCM4387 chips recovers after resume. Wi-Fi 6E Macs join on 2.4 and 5 GHz: a 6 GHz join passes no traffic with the current firmware. On the MacBook Neo's MT7932, NetworkManager rather than iwd reconnects, so a connect the firmware rejects is retried. |
| Speakers, microphone, headphones | <span class="status ok">works</span> | Asahi's DSP chain with `speakersafetyd` protecting the speakers. The microphone array is mapped, and a headset microphone takes priority when plugged in. If the microphone is still missing 30 s after the session starts, or when an update changes its DSP chain, one restart of the audio session is attempted to bring it back without a reboot. |
| Suspend and resume | <span class="status ok">works</span> | Open the lid or press the power button to wake the Mac. A key press or trackpad click does not wake it: the kernel drivers for the built-in keyboard and trackpad do not register as a wakeup source on M1 or M2 MacBooks. Closed in a bag, it stays asleep. |
Expand Down
14 changes: 13 additions & 1 deletion omarchy-mac/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# omarchy-mac

Apple Silicon defaults and support services for Omarchy. Version: `0.2.6` (candidate). This add-on complements `omarchy` and `omarchy-settings`; it selects no kernel and contains no installer or repository trust configuration. It covers what stays on an installed Mac; installing one is the job of the [Omarchy Installer](https://github.com/omacom/omarchy-mac-installer), and boot support is the separate `omarchy-mac-boot` package beside this one.
Apple Silicon defaults and support services for Omarchy. Version: `0.2.8` (candidate). This add-on complements `omarchy` and `omarchy-settings`; it selects no kernel and contains no installer or repository trust configuration. It covers what stays on an installed Mac; installing one is the job of the [Omarchy Installer](https://github.com/omacom/omarchy-mac-installer), and boot support is the separate `omarchy-mac-boot` package beside this one.

## Build and stage

Expand Down Expand Up @@ -57,6 +57,18 @@ A set limit is saved as `CHARGE_CONTROL_END_THRESHOLD=` in `/etc/udev/macsmc-bat

asahi-scripts' path unit starts `macsmc-battery-charge-control-end-threshold.service`, which saves the limit, on every SMC battery event, so plugging in the charger or resuming can start it more than five times in ten seconds and leave it `failed` with `start-limit-hit`. Since it only rewrites the same line, the package's drop-in removes its start limit; the drop-in goes once AsahiLinux/asahi-scripts#78 fixes the unit upstream.

## Automatic brightness

`omarchy brightness auto [status [--json]|on|off|toggle|seed [--force]]` controls automatic brightness for the panel from the ambient light sensor. It is on by default, as on macOS. It runs [wluma](https://github.com/max-baz/wluma) as the user unit `wluma.service` with the sensor alone: no screen capture, and no gamma control, so hyprsunset keeps the colour temperature. The package links the unit into `graphical-session.target.wants`, so every user gets it at the next login, an upgrade included, and a drop-in (`wluma.service.d/omarchy-mac.conf`) starts it only when wluma is installed and a light sensor under `/sys/bus/iio/devices` (`in_illuminance_input` or `in_illuminance_raw`) gives a number; it waits up to 60 s after login for the first reading, and only while the always-on processor's platform node (`*.aop`) exists, since that node is what loads the sensor driver. A Mac with no sensor and no such node skips the unit at once and without an error. A sensor that reports later than that wait is not picked up until the next login or `omarchy brightness auto on`, and a Mac whose node exists but whose sensor never appears holds the unit in its start condition for the full wait at each login, without delaying the session. `on` prints a line when it has to wait for the first reading.

`off` masks the unit and stops it, which no package upgrade undoes; `on` unmasks it and starts it. `on` refuses without wluma 5.0 or newer (the message names `omarchy-pkg-add wluma`, or the version it found; the version comes from `pacman -Q wluma`, and a wluma pacman does not know is let through), without a light sensor, and with neither a connected internal panel nor a config of the user's own, because wluma on its defaults captures the screen and dims on idle; a refused `on` starts nothing. The drop-in's start condition holds for the same reason: with no light sensor, no wluma, or neither a connected internal panel nor a config, the unit stays stopped.

wluma learns from manual brightness changes and does nothing until it has data, so before each start the drop-in runs `omarchy-brightness-auto prepare`, which seeds one starting curve per device in `~/.local/state/wluma/`, named as wluma names them: the panel's DRM connector and the keyboard LED (the keyboard curve is only used if you enable the keyboard in your own config). The panel's backlight is picked by the platform's `displays.conf`: the listed Touch Bar backlights are skipped and the preferred one wins. The panel curve climbs from 5% of `max_brightness` in the dark to 100% at 10000 lux; the keyboard is at half of its maximum in the dark and off from 50 lux. A seed never overwrites a file wluma has written; `seed --force` does. `prepare` also writes `~/.config/wluma/config.toml` when none exists, and never replaces one: the panel with ambient light only, wluma's idle dimming off because Omarchy's own idle chain handles an idle screen, and the keyboard backlight disabled in wluma. With its idle off, wluma would learn the lock screen switching the keyboard off as your choice and leave the keyboard dark in a dark room, so the keyboard is left to whatever else drives it. Every external display is disabled in wluma too: the light sensor is in the laptop and does not see the light at a Studio Display, so a display on a cable keeps the brightness you set.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This holds only for connectors present when the config is written, and an existing config is kept (omarchy-brightness-auto:167-169). Suggest: "Every external connector present when the config is written is disabled in wluma; a config that already exists is kept as it is."

— Marcelo's agent


`prepare` fails, and so the unit does not start, when no internal panel is connected and no config exists, since wluma on its defaults would capture the screen and dim on idle. `ready` already skips the unit in that case; the failure covers a panel that goes away between `ready` and `prepare`.

`status` reports whether the unit is running (a stopped or skipped unit reads off; while the unit waits for the sensor it reads starting) and the current lux reading, which stays empty until the sensor reports.

## Keyboard function-key mode

The built-in keyboard binds to `hid_apple`, whose `fnmode` decides what the top row sends. Apple Silicon uses the kernel's default, `fnmode=3` (auto): Apple keyboards send mute, volume, brightness and media first with F1-F12 behind Fn, as in macOS, and the non-Apple boards `hid_apple` recognises (Keychron and similar) keep F-keys first. The package ships no `hid_apple` option and the desktop install leaf writes none on Apple Silicon, so any option the owner sets wins, whatever its file name. For F-keys first on the Mac, write `options hid_apple fnmode=2` to `/etc/modprobe.d/hid_apple.conf` and rebuild the boot image (`sudo mkinitcpio -P`, or `sudo omarchy-mac-boot-update` on a Limine Mac): `hid_apple` loads from the initramfs with the options it was built with.
Expand Down
306 changes: 306 additions & 0 deletions omarchy-mac/bin/omarchy-brightness-auto
Original file line number Diff line number Diff line change
@@ -0,0 +1,306 @@
#!/bin/bash

# omarchy:summary=Turn automatic brightness from the ambient light sensor on or off
# omarchy:args=[status [--json]|on|off|toggle|seed [--force]]
# omarchy:examples=omarchy brightness auto | omarchy brightness auto off | omarchy brightness auto seed --force

set -euo pipefail

sys_root=/sys
displays_conf=/usr/share/omarchy-platform/displays.conf
unit=wluma.service
wluma_floor=5.0
state_dir=${XDG_STATE_HOME:-$HOME/.local/state}/wluma
config_file=${XDG_CONFIG_HOME:-$HOME/.config}/wluma/config.toml

# Starting curves, as lux:per-mille of the device's maximum. wluma keeps learning from manual changes on top of them.
panel_curve="0:50 5:120 20:220 50:320 150:450 400:600 1000:780 3000:920 10000:1000"
keyboard_curve="0:500 3:400 10:250 25:100 50:0"

usage() {
echo "Usage: omarchy brightness auto [status [--json]|on|off|toggle|seed [--force]]" >&2
exit 2
}

sensor_dir() {
local dir
for dir in "$sys_root"/bus/iio/devices/*; do
if [[ -e $dir/in_illuminance_input || -e $dir/in_illuminance_raw ]]; then
echo "$dir"
return 0
fi
done
return 1
}

# The lux reading, or nothing while the sensor has none (reads fail with ENODATA until it reports).
read_lux() {
local dir file value
dir=$(sensor_dir) || return 0
for file in in_illuminance_input in_illuminance_raw; do
if value=$(cat "$dir/$file" 2>/dev/null) && [[ $value =~ ^[0-9]+([.][0-9]+)?$ ]]; then
echo "${value%.*}"
return 0
fi
done
}

first_dir() {
local dir
for dir in "$@"; do
if [[ -d $dir ]]; then
echo "$dir"
return 0
fi
done
return 1
}

# The built-in panel's backlight, by the platform's displays.conf: skip the listed Touch Bar backlights, take the preferred
# one when present, else the first left.
panel_backlight() {
local dir name skip=" " prefer="" kind value first=""
if [[ -r $displays_conf ]]; then
while read -r kind value _; do
case "$kind" in
"backlight-skip") skip+="$value " ;;
"backlight-prefer") prefer=$value ;;
esac
done <"$displays_conf"
fi
for dir in "$sys_root"/class/backlight/*; do
name=${dir##*/}
if [[ ! -d $dir || $skip == *" $name "* ]]; then
continue
fi
if [[ $name == "$prefer" ]]; then
echo "$dir"
return 0
fi
if [[ -z $first ]]; then
first=$dir
fi
done
if [[ -z $first ]]; then
return 1
fi
echo "$first"
}

# wluma names the panel after its DRM connector.
panel_connector() {
local dir name
for dir in "$sys_root"/class/drm/card*-eDP-*; do
if [[ -f $dir/status && $(<"$dir/status") == "connected" ]]; then
name=${dir##*/}
echo "${name#*-}"
return 0
fi
done
return 1
}

# Writes $2 to $1 through a temp file, so a failed write leaves the old file or none. Each step returns its own
# status: the callers run this on the left of ||, where set -e is off.
write_file() {
local file=$1
mkdir -p "${file%/*}"
printf '%s' "$2" >"$file.tmp" && mv "$file.tmp" "$file" && return 0
rm -f "$file.tmp"
return 1
}

# Writes one wluma data file unless it exists: name, device maximum, curve.
write_curve() {
local name=$1 maximum=$2 curve=$3 force=$4 body content
local file=$state_dir/$name.yaml
if [[ ! $maximum =~ ^[1-9][0-9]*$ ]]; then
echo "Cannot read max_brightness for $name, so no curve is seeded for it." >&2
return 1
fi
if [[ -e $file ]] && (( force != 1 )); then
return 0
fi
body=$(awk -v maximum="$maximum" -v curve="$curve" 'BEGIN {
count = split(curve, points, " ")
for (index_ = 1; index_ <= count; index_++) {
split(points[index_], pair, ":")
value = int(maximum * pair[2] / 1000 + 0.5)
printf " - als: %d\n luma: 0\n value: %d\n", pair[1], value
}
}') || return 1
printf -v content 'output_name: %s\nentries:\n brightness:\n%s\n dim: []\n temperature: []\n' "$name" "$body"
write_file "$file" "$content"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b977140: awk is checked on its own (:130), and the write goes through write_file.

— Marcelo's agent

}

seed() {
local force=0 panel keyboard connector seeded=0
if [[ ${1:-} == "--force" ]]; then
force=1
elif [[ -n ${1:-} ]]; then
usage
fi
if panel=$(panel_backlight) && connector=$(panel_connector); then
write_curve "$connector" "$(<"$panel/max_brightness")" "$panel_curve" "$force" || return 1
seeded=1
fi
if keyboard=$(first_dir "$sys_root"/class/leds/*kbd_backlight*); then
write_curve "${keyboard##*/}" "$(<"$keyboard/max_brightness")" "$keyboard_curve" "$force" || return 1
seeded=1
fi
if (( seeded == 0 )); then
echo "No internal display backlight or keyboard backlight found to seed." >&2
return 1
fi
}

# wluma on no config runs on its defaults (screen capture, idle dimming), so a machine with neither a connected
# internal panel nor a config of the user's own stays stopped.
panel_or_config() {
[[ -e $config_file ]] || panel_connector >/dev/null
}

# Ambient light only for the panel: no screen capture, gamma left to hyprsunset, idle dimming left to Omarchy's idle
# chain, the keyboard backlight left to whatever else drives it, every external display left alone.
write_config() {
local connector keyboard content block dir name seen=" "
if [[ -e $config_file ]]; then
return 0
fi
if ! connector=$(panel_connector); then
echo "No internal panel is connected and there is no wluma config, so wluma does not start." >&2
return 1
fi
printf -v content '[idle]\nenabled = false\n\n[[output.backlight]]\nname = "%s"\ncapturer = "none"\ngamma = false\n' "$connector"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The panel entry names only the connector, so wluma has to pick the backlight itself, past the Touch Bar's. Could it carry path = "<panel_backlight dir>", as the keyboard entry does at :178?

— Marcelo's agent

# wluma finds every kbd_backlight on its own and, with its idle off, learns the lock screen's keyboard-off as the
# user's choice, so the keyboard stays dark in a dark room. Naming the LED with enabled = false drops it.
if keyboard=$(first_dir "$sys_root"/class/leds/*kbd_backlight*); then
printf -v block '\n[[keyboard]]\nname = "%s"\npath = "%s"\nenabled = false\n' "${keyboard##*/}" "$keyboard"
content+=$block
fi
# wluma drives every connected display it finds a backlight for, and a Studio Display has one. The sensor sits in the
# laptop and does not see the light at an external display, so every other connector is named once with
# enabled = false. sysfs lists a connector whether or not a display is plugged in, so a later hotplug is covered too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this holds for connectors present when the config is first written, and the config is never rewritten. Suggest "every connector present now".

— Marcelo's agent

for dir in "$sys_root"/class/drm/card*-*; do
[[ -d $dir ]] || continue
name=${dir##*/}
name=${name#*-}
if [[ $name == eDP-* || $seen == *" $name "* ]]; then
continue
fi
seen+="$name "
printf -v block '\n[[output.backlight]]\nname = "%s"\nenabled = false\n' "$name"
content+=$block
done
write_file "$config_file" "$content"
}

# The real state: is the unit running. is-enabled answers "disabled" for a unit that starts from the target's vendor link.
enabled() {
systemctl --user is-active --quiet "$unit"
}

# wluma 5 added the keyboard and output tables the config uses. wluma 4 has no --version and would start on any flag,
# so the version comes from the package database. A wluma pacman does not know (a user build) is let through.
wluma_usable() {
local found
if ! command -v wluma >/dev/null; then
echo "wluma is not installed. Install it with: omarchy-pkg-add wluma" >&2
return 1
fi
found=$(pacman -Q wluma 2>/dev/null) || return 0
found=${found#* }
if (( $(vercmp "$found" "$wluma_floor") < 0 )); then

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without vercmp this becomes (( < 0 )), the if is skipped and the check fails open. Could it check vercmp's output first, as omarchy-mac-boot/setup/m1n1-display.sh:46 does?

— Marcelo's agent

echo "wluma $wluma_floor or newer is required, found ${found%-*}" >&2
return 1
fi
}

# The unit's start condition: wluma, and a sensor that reports a number. The sensor's driver may load after login
# (a guarded loader) and the sensor needs a few seconds to report, so this waits up to 60 s. A Mac with no sensor
# and no always-on processor node to load a driver for it, or a kernel whose sensor never reports, skips the unit.
ready() {
local tries=60
wluma_usable || return 1
panel_or_config || return 1
while [[ -z $(read_lux) ]]; do
if ! sensor_dir >/dev/null && ! compgen -G "$sys_root/bus/platform/devices/*.aop" >/dev/null; then
return 1
fi
(( --tries > 0 )) || return 1
sleep 1
done
}

# Run by the unit before every start: the starting curves and the config, each only where none exists yet.
prepare() {
write_config || return 1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set -e is off inside write_config here, because it's called on the left of ||. On a Mac with no keyboard LED, a failed mkdir -p or write at :170-171 returns 0, and wluma starts with no config. Could each step return 1, with prepare also checking [[ -e $config_file ]]?

— Marcelo's agent

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Joshua's agent] Fixed in b977140. Both points hold: write_config ended on a false if when there is no keyboard LED, so a failed mkdir or write left status 0 and prepare carried on with no config. Now write_config builds the whole config in memory and writes it once through a new write_file helper (temp file, mv, return 1 on any failed step, temp file removed), so a failed write leaves no config and prepare fails. This also answers the earlier :171 thread (write to .tmp, then mv).

On the [[ -e $config_file ]] check in prepare: I left it out. write_config can now return 0 only when the config already exists or write_file succeeded, so the check cannot fail and no test can reach it.

Tests written first, in brightness-auto-test.sh: prepare fails with no keyboard LED when the config directory cannot be made (the config home is a file) and when the config cannot be written (config.toml.tmp is a directory); the first one failed on the old code. MEASURED: the suite passes at b977140; three mutants (awk status dropped, direct write, temp file left behind) each fail it. UNKNOWN: a real disk-full or read-only home on a Mac.

Model: anthropic/claude-sonnet-5-5 (live from lane_models.py this turn).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in b977140: write_config returns write_file's status (:180), so a failed write now fails prepare. Agreed the extra -e check isn't needed.

— Marcelo's agent

seed || return 0
}

turn_on() {
wluma_usable || exit 1
if ! sensor_dir >/dev/null; then
echo "No ambient light sensor found." >&2
exit 1
fi
# Without a config wluma runs on its defaults: it captures the screen and dims on idle.
if ! panel_or_config; then
echo "No internal panel is connected and there is no wluma config, so wluma would run on its defaults. Wake the panel, or write $config_file first." >&2
exit 1
fi
systemctl --user unmask "$unit"
if [[ -z $(read_lux) ]]; then
echo "Waiting up to 60 s for the light sensor to report before wluma starts." >&2
fi
systemctl --user start "$unit"
}

# A mask is the one off switch that outlives the vendor link which turns the unit on for everyone.
turn_off() {
systemctl --user mask --now "$unit"
}

status() {
local lux state=off
lux=$(read_lux)
case $(systemctl --user is-active "$unit" 2>/dev/null || true) in
active) state=on ;;
activating) state=starting ;;
esac
if [[ ${1:-} == "--json" ]]; then
printf '{"enabled":%s,"lux":%s}\n' "$([[ $state == "on" ]] && echo true || echo false)" "${lux:-null}"
elif [[ -z ${1:-} ]]; then
echo "Automatic brightness: $state"
if [[ -n $lux ]]; then
echo "Ambient light: $lux lux"
else
echo "Ambient light: no reading"
fi
else
usage
fi
}

if ! omarchy-hw-apple-silicon; then
echo "Automatic brightness is only set up for Apple Silicon Macs." >&2
exit 1
fi

# A verb takes at most this many words after it.
arguments_at_most() {
if (( $# - 2 > $1 )); then
usage
fi
}

case "${1:-status}" in
status) arguments_at_most 1 "$@"; status "${2:-}" ;;
on) arguments_at_most 0 "$@"; turn_on ;;
off) arguments_at_most 0 "$@"; turn_off ;;
toggle) arguments_at_most 0 "$@"; if enabled; then turn_off; else turn_on; fi ;;
seed) arguments_at_most 1 "$@"; seed "${2:-}" ;;
ready) arguments_at_most 0 "$@"; ready ;;
prepare) arguments_at_most 0 "$@"; prepare ;;
*) usage ;;
esac
Loading
Loading