Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
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 when the keyboard appears and stays there; it follows the room only once you turn on automatic brightness, below. 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.

Automatic brightness is off by default. Install wluma once with `omarchy-pkg-add wluma`, then `omarchy brightness auto on` makes the screen and the keyboard backlight follow the room from the ambient light sensor; `omarchy brightness auto off` stops it. It needs a Mac whose kernel shows the sensor. It starts from a built-in curve and keeps learning from the brightness you set by hand.

## 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; it follows the ambient light sensor only with automatic brightness, which is off by default. 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
10 changes: 9 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.7` (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,14 @@ 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]]` turns on automatic brightness for the panel and the keyboard backlight from the ambient light sensor, as macOS does. 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. It is off until `on` runs. `on` refuses without wluma (the message names `omarchy-pkg-add wluma`), without a light sensor under `/sys/bus/iio/devices` (`in_illuminance_input` or `in_illuminance_raw`), 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 and writes nothing.

wluma learns from manual brightness changes and does nothing until it has data, so `on` first 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 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. `on` also writes `~/.config/wluma/config.toml` when none exists, and never replaces one: the panel with ambient light only, and wluma's idle dimming off, since Omarchy's own idle chain handles an idle screen and would otherwise fight wluma over the keyboard backlight.

`status` reports whether the unit is enabled 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
234 changes: 234 additions & 0 deletions omarchy-mac/bin/omarchy-brightness-auto
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
#!/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 toggle | omarchy brightness auto seed --force

set -euo pipefail

sys_root=/sys
displays_conf=/usr/share/omarchy-platform/displays.conf
unit=wluma.service
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 one wluma data file unless it exists: name, device maximum, curve.
write_curve() {
local name=$1 maximum=$2 curve=$3 force=$4
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
exit 1
fi
if [[ -e $file ]] && (( force != 1 )); then
return 0
fi
mkdir -p "$state_dir"
{
echo "output_name: $name"
echo "entries:"
echo " brightness:"
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
}
}'
echo " dim: []"
echo " temperature: []"
} >"$file.tmp"
mv "$file.tmp" "$file"
}

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"
seeded=1
fi
if keyboard=$(first_dir "$sys_root"/class/leds/*kbd_backlight*); then
write_curve "${keyboard##*/}" "$(<"$keyboard/max_brightness")" "$keyboard_curve" "$force"
seeded=1
fi
if (( seeded == 0 )); then
echo "No internal display backlight or keyboard backlight found to seed." >&2
exit 1
fi
}

# Ambient light only: no screen capture, gamma left to hyprsunset, idle dimming left to Omarchy's idle chain.
write_config() {
local connector
if [[ -e $config_file ]]; then
return 0
fi
# The panel can disconnect after turn_on checked it; without a name there is no config to write.
if ! connector=$(panel_connector); then
echo "The internal panel disconnected while brightness auto was starting, so no wluma config was written and wluma was not started. Wake the panel and run it again." >&2
exit 1
fi
mkdir -p "${config_file%/*}"
printf '[idle]\nenabled = false\n\n[[output.backlight]]\nname = "%s"\ncapturer = "none"\ngamma = false\n' "$connector" >"$config_file"
}

enabled() {
systemctl --user is-enabled "$unit" >/dev/null 2>&1
}

turn_on() {
if ! command -v wluma >/dev/null; then
echo "wluma is not installed. Install it with: omarchy-pkg-add wluma" >&2
exit 1
fi
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 [[ ! -e $config_file ]] && ! panel_connector >/dev/null; 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.

With a connected eDP but no panel backlight this passes, so seed writes the keyboard curve before write_config refuses at :166. Could this check panel_backlight too?

— Marcelo's agent

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
seed
write_config
systemctl --user enable --now "$unit"
}

turn_off() {
systemctl --user disable --now "$unit"
}

status() {
local lux state=off
lux=$(read_lux)
if enabled; then
state=on
fi
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:-}" ;;
*) usage ;;
esac
Loading
Loading