From 93079858f1c6f2839870d98d9914b5288945b5b7 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 14 Jan 2026 17:21:10 -0500 Subject: [PATCH] Extract shared swayosd helper --- bin/omarchy-cmd-apple-display-brightness | 12 ++++-------- bin/omarchy-cmd-brightness | 9 ++------- bin/omarchy-swayosd-brightness | 12 ++++++++++++ 3 files changed, 18 insertions(+), 15 deletions(-) create mode 100755 bin/omarchy-swayosd-brightness diff --git a/bin/omarchy-cmd-apple-display-brightness b/bin/omarchy-cmd-apple-display-brightness index d4d7968e..00fde072 100755 --- a/bin/omarchy-cmd-apple-display-brightness +++ b/bin/omarchy-cmd-apple-display-brightness @@ -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 diff --git a/bin/omarchy-cmd-brightness b/bin/omarchy-cmd-brightness index 5db63dd2..5213f421 100755 --- a/bin/omarchy-cmd-brightness +++ b/bin/omarchy-cmd-brightness @@ -1,6 +1,7 @@ #!/bin/bash # Adjust brightness on the most likely display device. +# Usage: omarchy-cmd-brightness 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 '%')" diff --git a/bin/omarchy-swayosd-brightness b/bin/omarchy-swayosd-brightness new file mode 100755 index 00000000..6afc251a --- /dev/null +++ b/bin/omarchy-swayosd-brightness @@ -0,0 +1,12 @@ +#!/bin/bash + +# Display brightness level using SwayOSD on the current monitor. +# Usage: omarchy-swayosd-brightness + +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}%"