diff --git a/bin/omarchy-brightness-display b/bin/omarchy-brightness-display index 3f4862b7..d9c43904 100755 --- a/bin/omarchy-brightness-display +++ b/bin/omarchy-brightness-display @@ -1,10 +1,27 @@ #!/bin/bash -# omarchy:summary=Adjust brightness on the most likely display device. -# omarchy:args=<+N%|N%-|N%|off|on> -# omarchy:examples=omarchy brightness display +5% | omarchy brightness display 5%- | omarchy brightness display 50% | omarchy brightness display off | omarchy brightness display on +# omarchy:summary=Show or adjust brightness on the most likely display device. +# omarchy:args=[+N%|N%-|N%|off|on] +# omarchy:examples=omarchy brightness display | omarchy brightness display +5% | omarchy brightness display 5%- | omarchy brightness display 50% | omarchy brightness display off | omarchy brightness display on -step="${1:-+5%}" +display_brightness() { + local device="$1" + + brightnessctl -d "$device" -m 2>/dev/null | awk -F, '{ gsub("%", "", $4); print $4; found=1 } END{ exit !found }' +} + +if (( $# == 0 )) || [[ ${1:-} == "get" ]]; then + if omarchy-hyprland-monitor-focused-apple; then + omarchy-brightness-display-apple + exit + fi + + device="$(omarchy-hw-display)" || exit 1 + display_brightness "$device" + exit +fi + +step="$1" if [[ $step == "off" ]]; then hyprctl dispatch 'hl.dsp.dpms({ action = "disable" })' >/dev/null 2>&1 @@ -14,12 +31,10 @@ elif [[ $step == "on" ]]; then exit 0 fi -runtime_dir="${XDG_RUNTIME_DIR:-/tmp}" - # Drop overlapping brightness key events so concurrent invocations do not race. # Hardware key repeat present on some devices can otherwise glitch OSD rendering. -exec 9>"$runtime_dir/omarchy-brightness-display.lock" -flock -n 9 || exit 0 +exec {lock_fd}>"${XDG_RUNTIME_DIR:-/tmp}/omarchy-brightness-display.lock" +flock -n "$lock_fd" || exit 0 if omarchy-hyprland-monitor-focused-apple; then omarchy-brightness-display-apple "$step" @@ -29,7 +44,7 @@ fi device="$(omarchy-hw-display)" || exit 1 # Current brightness percentage -current=$(brightnessctl -d "$device" -m | cut -d',' -f4 | tr -d '%') +current=$(display_brightness "$device") || exit 1 # Apply non-uniform step size: 1% steps if at or below 5%, otherwise set an # absolute target percentage to avoid raw backlight rounding causing uneven OSD steps. @@ -55,4 +70,4 @@ fi # Set brightness of the display device. brightnessctl -d "$device" set "$step" >/dev/null -omarchy-osd -i brightness -p "$(brightnessctl -d "$device" -m | cut -d',' -f4 | tr -d '%')" +omarchy-osd -i brightness -p "$(display_brightness "$device")" diff --git a/bin/omarchy-brightness-display-get b/bin/omarchy-brightness-display-get deleted file mode 100755 index 15475026..00000000 --- a/bin/omarchy-brightness-display-get +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -# omarchy:summary=Get brightness for the most likely display device. -# omarchy:examples=omarchy-brightness-display-get - -if omarchy-hyprland-monitor-focused-apple; then - omarchy-brightness-display-apple-get -else - brightnessctl -d "$(omarchy-hw-display)" -m 2>/dev/null | awk -F, '{ gsub("%", "", $4); print $4; found=1 } END{ exit !found }' -fi diff --git a/default/quickshell/omarchy-shell/plugins/bar/widgets/monitorPanel.qml b/default/quickshell/omarchy-shell/plugins/bar/widgets/monitorPanel.qml index c7b5ec41..11998158 100644 --- a/default/quickshell/omarchy-shell/plugins/bar/widgets/monitorPanel.qml +++ b/default/quickshell/omarchy-shell/plugins/bar/widgets/monitorPanel.qml @@ -129,7 +129,7 @@ Item { Process { id: stateProc - command: ["bash", "-lc", "omarchy-brightness-display-get 2>/dev/null || true; monitors_json=$(hyprctl monitors all -j); printf '%s\\n' \"$monitors_json\" | jq -r 'def internal: test(\"^(eDP|LVDS|DSI)-\"); ([.[] | select(.name | internal)][0].name // \"\"), ([.[] | select((.name | internal) | not)][0].name // \"\"), ([.[] | select((.name | internal) and .disabled != true)][0].name // \"\"), ([.[] | select((.name | internal) and .mirrorOf != \"none\")][0].mirrorOf // \"\")'; omarchy-hyprland-monitor-focused 2>/dev/null || echo; omarchy-hyprland-monitor-scaling-get 2>/dev/null || echo; printf '%s\\n' \"$monitors_json\" | jq -c '[.[] | {name, enabled:(.disabled != true), focused:(.focused == true)}]'"] + command: ["bash", "-lc", "omarchy-brightness-display 2>/dev/null || true; monitors_json=$(hyprctl monitors all -j); printf '%s\\n' \"$monitors_json\" | jq -r 'def internal: test(\"^(eDP|LVDS|DSI)-\"); ([.[] | select(.name | internal)][0].name // \"\"), ([.[] | select((.name | internal) | not)][0].name // \"\"), ([.[] | select((.name | internal) and .disabled != true)][0].name // \"\"), ([.[] | select((.name | internal) and .mirrorOf != \"none\")][0].mirrorOf // \"\")'; omarchy-hyprland-monitor-focused 2>/dev/null || echo; omarchy-hyprland-monitor-scaling-get 2>/dev/null || echo; printf '%s\\n' \"$monitors_json\" | jq -c '[.[] | {name, enabled:(.disabled != true), focused:(.focused == true)}]'"] stdout: StdioCollector { waitForEnd: true onStreamFinished: {