From e1ebcd40448442a1285995d700e2480dc093b824 Mon Sep 17 00:00:00 2001 From: Don Williams Date: Tue, 25 Aug 2026 22:41:17 -0400 Subject: Improved robustness and LUA compatiblity Signed-off-by: Don Williams On branch development Your branch is up to date with 'origin/development'. Changes to be committed: modified: CHANGELOG.md modified: config/hypr/UserScripts/RainbowBorders-low-cpu.sh modified: config/hypr/UserScripts/RainbowBorders.bak.sh modified: config/hypr/UserScripts/RofiBeats.sh modified: config/hypr/UserScripts/RofiCalc.sh --- config/hypr/UserScripts/RainbowBorders-low-cpu.sh | 55 +++++++++++++++++++++-- config/hypr/UserScripts/RainbowBorders.bak.sh | 10 ++++- config/hypr/UserScripts/RofiBeats.sh | 12 +++-- config/hypr/UserScripts/RofiCalc.sh | 37 ++++++++++++--- 4 files changed, 100 insertions(+), 14 deletions(-) (limited to 'config/hypr/UserScripts') diff --git a/config/hypr/UserScripts/RainbowBorders-low-cpu.sh b/config/hypr/UserScripts/RainbowBorders-low-cpu.sh index 388a771b..861b8ed2 100755 --- a/config/hypr/UserScripts/RainbowBorders-low-cpu.sh +++ b/config/hypr/UserScripts/RainbowBorders-low-cpu.sh @@ -187,18 +187,64 @@ if [[ "$RB_RESTORE" == "1" && "$RB_ONCE" != "1" ]]; then fi # Apply a border color value under conf or Lua Hyprland modes. -# Prefer hyprctl keyword (legacy). On Lua parsers, fall back to hl.config via eval. +# Cache parser mode (keyword vs eval) to avoid double-process overhead per tick on Lua configs. +HYPR_DISPATCH_MODE="" + apply_border_value() { local option="$1" local value="$2" - local out angle colors_str c lua_colors expr + local out angle colors_str c lua_colors expr rc local -a colors=() - # Note: under Lua config mode hyprctl may exit 0 while still printing - # "keyword can't work with non-legacy parsers", so check output too. + # Fast path: if parser mode is already known to be keyword (legacy) + if [[ "$HYPR_DISPATCH_MODE" == "keyword" ]]; then + if out="$(hyprctl keyword "$option" $value 2>&1)"; then + return 0 + fi + HYPR_DISPATCH_MODE="" + fi + + # Fast path: if parser mode is already known to be Lua eval + if [[ "$HYPR_DISPATCH_MODE" == "eval" ]]; then + angle="0" + for c in $value; do + if [[ "$c" =~ ^([0-9]+)deg$ ]]; then + angle="${BASH_REMATCH[1]}" + else + colors+=("$c") + fi + done + ((${#colors[@]} > 0)) || return 1 + + lua_colors="" + for c in "${colors[@]}"; do + [[ -n "$lua_colors" ]] && lua_colors+=", " + lua_colors+="\"${c}\"" + done + + case "$option" in + general:col.active_border) + expr="hl.config({ general = { col = { active_border = { colors = { ${lua_colors} }, angle = ${angle} } } } })" + ;; + general:col.inactive_border) + expr="hl.config({ general = { col = { inactive_border = { colors = { ${lua_colors} }, angle = ${angle} } } } })" + ;; + *) + return 1 + ;; + esac + + if hyprctl eval "$expr" >/dev/null 2>&1; then + return 0 + fi + HYPR_DISPATCH_MODE="" + fi + + # Auto-detection pass (runs on first tick or after fallback) out="$(hyprctl keyword "$option" $value 2>&1)" rc=$? if [[ $rc -eq 0 && "$out" != *"non-legacy parsers"* && "$out" != *"Use eval"* && "$out" != *"error"* && "$out" != *"invalid"* ]]; then + HYPR_DISPATCH_MODE="keyword" return 0 fi @@ -236,6 +282,7 @@ apply_border_value() { esac if out="$(hyprctl eval "$expr" 2>&1)"; then + HYPR_DISPATCH_MODE="eval" return 0 fi log "WARN: failed to apply border via eval: $out" diff --git a/config/hypr/UserScripts/RainbowBorders.bak.sh b/config/hypr/UserScripts/RainbowBorders.bak.sh index 82807919..528bb455 100755 --- a/config/hypr/UserScripts/RainbowBorders.bak.sh +++ b/config/hypr/UserScripts/RainbowBorders.bak.sh @@ -46,6 +46,10 @@ fi # ---------- RANDOM WALLUST COLORS ---------- function wallust_random() { + if ((${#WALLUST_COLORS[@]} == 0)); then + random_hex + return + fi echo "${WALLUST_COLORS[RANDOM % ${#WALLUST_COLORS[@]}]}" } @@ -61,7 +65,11 @@ function random_hex() { echo "${RAINBOW_PALETTE[RANDOM % ${#RAINBOW_PALETTE[@]}]}" return fi - echo "0xff$(openssl rand -hex 3)" + if command -v openssl >/dev/null 2>&1; then + echo "0xff$(openssl rand -hex 3)" + else + printf '0xff%02x%02x%02x\n' $((RANDOM % 256)) $((RANDOM % 256)) $((RANDOM % 256)) + fi } function rainbow_color() { local idx="${1:-0}" diff --git a/config/hypr/UserScripts/RofiBeats.sh b/config/hypr/UserScripts/RofiBeats.sh index b2371859..5fc1389d 100755 --- a/config/hypr/UserScripts/RofiBeats.sh +++ b/config/hypr/UserScripts/RofiBeats.sh @@ -16,6 +16,8 @@ music_list="${XDG_CONFIG_HOME:-$HOME/.config}/rofi/online_music.list" mkdir -p "$(dirname "$music_list")" [[ -f "$music_list" ]] || touch "$music_list" +[[ -d "$mDIR" ]] || mkdir -p "$mDIR" + # Send notification notification() { notify-send -u normal -i "$iDIR/music.png" "$@" @@ -26,12 +28,16 @@ music_playing() { pgrep -x "mpv" >/dev/null; } # Stop all mpv processes except mpvpaper stop_music() { + local mpv_pids mpv_pids=$(pgrep -x mpv) if [ -n "$mpv_pids" ]; then - mpvpaper_pid=$(ps aux | grep -- 'unique-wallpaper-process' | grep -v 'grep' | awk '{print $2}') + local mpvpaper_pid + mpvpaper_pid=$(ps aux 2>/dev/null | grep -- 'unique-wallpaper-process' | grep -v 'grep' | awk '{print $2}') for pid in $mpv_pids; do if ! echo "$mpvpaper_pid" | grep -q "$pid"; then - kill -9 $pid || true + kill -TERM "$pid" 2>/dev/null || true + sleep 0.05 + kill -0 "$pid" 2>/dev/null && kill -9 "$pid" 2>/dev/null || true fi done notification "Music stopped" @@ -111,7 +117,7 @@ manage_music() { entry=$(awk -F'|' '{print $1}' "$music_list" | rofi -dmenu -config "$rofi_theme_menu" \ -theme-str 'entry { placeholder: "🗑️ Select Music to Remove"; }') [[ -z "$entry" ]] && return - grep -vF "$entry" "$music_list" >"$music_list.tmp" && mv "$music_list.tmp" "$music_list" + grep -v "^${entry}|" "$music_list" >"$music_list.tmp" && mv "$music_list.tmp" "$music_list" notification "Removed" "$entry" ;; "View List") diff --git a/config/hypr/UserScripts/RofiCalc.sh b/config/hypr/UserScripts/RofiCalc.sh index ccb18903..48f150d8 100755 --- a/config/hypr/UserScripts/RofiCalc.sh +++ b/config/hypr/UserScripts/RofiCalc.sh @@ -10,22 +10,47 @@ rofi_theme="${XDG_CONFIG_HOME:-$HOME/.config}/rofi/config-calc.rasi" -# Kill Rofi if already running before execution -if pgrep -x "rofi" >/dev/null; then - pkill rofi +# Dependency checks +for cmd in rofi qalc wl-copy; do + if ! command -v "$cmd" >/dev/null 2>&1; then + if command -v notify-send >/dev/null 2>&1; then + notify-send -u critical "RofiCalc" "Missing required dependency: $cmd" + else + echo "Error: Missing required dependency: $cmd" >&2 + fi + exit 1 + fi +done + +CALC_LOCKFILE="/tmp/roficalc-${UID:-0}.pid" +if [[ -f "$CALC_LOCKFILE" ]]; then + oldpid="$(cat "$CALC_LOCKFILE" 2>/dev/null || true)" + if [[ -n "$oldpid" ]] && kill -0 "$oldpid" 2>/dev/null; then + kill "$oldpid" 2>/dev/null || true + fi + rm -f "$CALC_LOCKFILE" 2>/dev/null || true fi +printf '%d' "$$" > "$CALC_LOCKFILE" 2>/dev/null || true +trap 'rm -f "$CALC_LOCKFILE" 2>/dev/null' EXIT INT TERM # main function +calc_result="" +result="" while true; do + mesg_args=() + if [[ -n "$result" || -n "$calc_result" ]]; then + mesg_args=(-mesg "$result = $calc_result") + fi + result=$( rofi -i -dmenu \ - -config $rofi_theme \ - -mesg "$result = $calc_result" + -config "$rofi_theme" \ + "${mesg_args[@]}" ) if [ $? -ne 0 ]; then - exit + exit 0 fi if [ -n "$result" ]; then -- cgit v1.2.3