A simple yet powerful UI overlay made for Wayland WMs built with Quickshell
wayland qs linux ui ux
at main 134 lines 2.9 kB view raw
1#!/usr/bin/env bash 2# visualctl.sh — brightnessctl + sunsetr (replaces hyprsunset) 3 4set -u 5 6cmd="${1:-}" 7 8have() { command -v "$1" >/dev/null 2>&1; } 9 10clamp_int() { 11 local v="${1:-0}" lo="${2:-0}" hi="${3:-100}" 12 if ! [[ "$v" =~ ^-?[0-9]+$ ]]; then v="$lo"; fi 13 if [ "$v" -lt "$lo" ]; then v="$lo"; fi 14 if [ "$v" -gt "$hi" ]; then v="$hi"; fi 15 printf '%s' "$v" 16} 17 18status_brightness() { 19 if ! have brightnessctl; then 20 echo "BRIGHT_AVAIL|0" 21 exit 0 22 fi 23 24 local line 25 line="$(brightnessctl -m 2>/dev/null | head -n1 | tr -d $'\r')" 26 27 if [ -z "${line:-}" ]; then 28 echo "BRIGHT_AVAIL|0" 29 exit 0 30 fi 31 32 local pct_field pct 33 pct_field="$(printf '%s' "$line" | awk -F, '{print $5}')" 34 pct="$(printf '%s' "$pct_field" | tr -d ' %' 2>/dev/null || true)" 35 36 if ! [[ "${pct:-}" =~ ^[0-9]+$ ]]; then 37 echo "BRIGHT_AVAIL|1" 38 exit 0 39 fi 40 41 pct="$(clamp_int "$pct" 0 100)" 42 echo "BRIGHT_AVAIL|1" 43 echo "BRIGHT_PCT|$pct" 44 exit 0 45} 46 47set_brightness() { 48 local pct="${1:-100}" 49 have brightnessctl || exit 0 50 pct="$(clamp_int "$pct" 1 100)" # avoid full black; QML also clamps 51 brightnessctl set "${pct}%" >/dev/null 2>&1 || true 52 exit 0 53} 54 55# ---------- sunsetr (blue light) ---------- 56 57sunsetr_is_running() { 58 pgrep -x sunsetr >/dev/null 2>&1 59} 60 61status_bluelight() { 62 if ! have sunsetr; then 63 echo "BLUELIGHT|0" 64 exit 0 65 fi 66 67 if sunsetr_is_running; then 68 echo "BLUELIGHT|1" 69 else 70 echo "BLUELIGHT|0" 71 fi 72 exit 0 73} 74 75blue_on() { 76 local temp="${1:-3800}" 77 have sunsetr || exit 0 78 79 temp="$(clamp_int "$temp" 1000 20000)" 80 81 # Ensure a running instance (background) 82 if ! sunsetr_is_running; then 83 sunsetr --background >/dev/null 2>&1 & disown || true 84 # give it a moment to spawn; don't hard-fail if it doesn't 85 sleep 0.05 2>/dev/null || true 86 fi 87 88 # Force "static" mode at requested temperature (gamma 100) 89 # Use individual set calls for maximal compatibility across versions. 90 sunsetr set transition_mode=static >/dev/null 2>&1 || true 91 sunsetr set static_temp="$temp" >/dev/null 2>&1 || true 92 sunsetr set static_gamma=100 >/dev/null 2>&1 || true 93 94 # Apply immediately if supported; fall back to plain restart. 95 sunsetr restart --instant >/dev/null 2>&1 || sunsetr restart >/dev/null 2>&1 || true 96 97 exit 0 98} 99 100blue_off() { 101 # Prefer clean shutdown; fall back to pkill. 102 if have sunsetr; then 103 sunsetr stop >/dev/null 2>&1 || true 104 fi 105 pkill -x sunsetr >/dev/null 2>&1 || true 106 exit 0 107} 108 109case "$cmd" in 110 status_brightness) 111 status_brightness 112 ;; 113 set) 114 key="${2:-}" 115 case "$key" in 116 brightness) set_brightness "${3:-100}" ;; 117 *) exit 0 ;; 118 esac 119 ;; 120 status_bluelight) 121 status_bluelight 122 ;; 123 blue) 124 action="${2:-}" 125 case "$action" in 126 on) blue_on "${3:-3600}" ;; 127 off) blue_off ;; 128 *) exit 0 ;; 129 esac 130 ;; 131 *) 132 exit 0 133 ;; 134esac