Extract shared swayosd helper

This commit is contained in:
David Heinemeier Hansson
2026-01-14 17:21:10 -05:00
parent 4287472e02
commit 93079858f1
3 changed files with 18 additions and 15 deletions

View File

@@ -5,12 +5,8 @@
if [[ $# -eq 0 ]]; then
echo "Adjust Apple Display Brightness by passing +5000 or -5000 (or any range from 0-60000)"
else
DEVICE="$(sudo asdcontrol --detect /dev/usb/hiddev* | grep ^/dev/usb/hiddev | cut -d: -f1)"
sudo asdcontrol "$DEVICE" -- "$1" >/dev/null
VALUE="$(sudo asdcontrol "$DEVICE" | awk -F= '/BRIGHTNESS=/{print $2+0}')"
swayosd-client \
--monitor "$(hyprctl monitors -j | jq -r '.[]|select(.focused==true).name')" \
--custom-icon display-brightness \
--custom-progress "$(awk -v v="$VALUE" 'BEGIN{printf "%.2f", v/60000}')" \
--custom-progress-text "$(( VALUE * 100 / 60000 ))%"
device="$(sudo asdcontrol --detect /dev/usb/hiddev* | grep ^/dev/usb/hiddev | cut -d: -f1)"
sudo asdcontrol "$device" -- "$1" >/dev/null
value="$(sudo asdcontrol "$device" | awk -F= '/BRIGHTNESS=/{print $2+0}')"
omarchy-swayosd-brightness "$(( value * 100 / 60000 ))"
fi

View File

@@ -1,6 +1,7 @@
#!/bin/bash
# Adjust brightness on the most likely display device.
# Usage: omarchy-cmd-brightness <step>
step="${1:-+5%}"
@@ -17,10 +18,4 @@ done
brightnessctl -d "$device" set "$step" >/dev/null
# Use SwayOSD to display the new brightness setting.
percent=$(brightnessctl -d "$device" -m | cut -d',' -f4 | tr -d '%')
swayosd-client \
--monitor "$(hyprctl monitors -j | jq -r '.[]|select(.focused==true).name')" \
--custom-icon display-brightness \
--custom-progress "$(awk -v p="$percent" 'BEGIN{printf "%.2f", p/100}')" \
--custom-progress-text "${percent}%"
omarchy-swayosd-brightness "$(brightnessctl -d "$device" -m | cut -d',' -f4 | tr -d '%')"

12
bin/omarchy-swayosd-brightness Executable file
View File

@@ -0,0 +1,12 @@
#!/bin/bash
# Display brightness level using SwayOSD on the current monitor.
# Usage: omarchy-swayosd-brightness <percent>
percent="$1"
swayosd-client \
--monitor "$(hyprctl monitors -j | jq -r '.[]|select(.focused==true).name')" \
--custom-icon display-brightness \
--custom-progress "$(awk -v p="$percent" 'BEGIN{printf "%.2f", p/100}')" \
--custom-progress-text "${percent}%"