aboutsummaryrefslogtreecommitdiffstats
path: root/config/hypr/scripts/ChangeBlur.sh
blob: 66269a2c8dc7b8fef91bdb12a44a555d1e8f8a9d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/env bash
# ==================================================
#  KoolDots (2026)
#  Project URL: https://github.com/LinuxBeginnings
#  License: GNU GPLv3
#  SPDX-License-Identifier: GPL-3.0-or-later
# ==================================================
# Script for changing blur levels on the fly with desktop notifications.
# Supports cycling preset levels (Off -> Low -> Medium -> High -> Ultra),
# stepping up/down (--inc / --dec), or selecting explicit levels.
# Uses flock to prevent double-execution from dual-config (.conf + .lua) loading.

set -uo pipefail

notif="${XDG_CONFIG_HOME:-$HOME/.config}/swaync/images"
icons_dir="${XDG_CONFIG_HOME:-$HOME/.config}/swaync/icons"

config_home="${XDG_CONFIG_HOME:-$HOME/.config}"
hypr_dir="$config_home/hypr"
lua_entry="$hypr_dir/hyprland.lua"
legacy_lua_entry="$config_home/hyprland.lua"

if [[ -f "$lua_entry" || -f "$legacy_lua_entry" ]]; then
    hypr_config_mode="lua"
else
    hypr_config_mode="conf"
fi

LOCK="/tmp/.hypr_change_blur_${HYPRLAND_INSTANCE_SIGNATURE:-default}.lock"

# Pick appropriate icons
if [[ -f "$icons_dir/palette.png" ]]; then
    ICON_ON="$icons_dir/palette.png"
elif [[ -f "$notif/ja.png" ]]; then
    ICON_ON="$notif/ja.png"
else
    ICON_ON="$notif/note.png"
fi

if [[ -f "$notif/note.png" ]]; then
    ICON_OFF="$notif/note.png"
else
    ICON_OFF="$ICON_ON"
fi

(
  flock -n 200 || exit 0

  # Check if blur is currently enabled
  BLUR_ENABLED=$(hyprctl -j getoption decoration:blur:enabled 2>/dev/null | jq -r ".bool // empty")
  if [[ -z "$BLUR_ENABLED" || "$BLUR_ENABLED" == "null" ]]; then
      BLUR_ENABLED=$(hyprctl getoption decoration:blur:enabled 2>/dev/null | awk 'NR==1{print $2}')
  fi

  PASSES=$(hyprctl -j getoption decoration:blur:passes 2>/dev/null | jq -r ".int // empty")
  if [[ -z "$PASSES" || "$PASSES" == "null" ]]; then
      PASSES=$(hyprctl getoption decoration:blur:passes 2>/dev/null | awk 'NR==1{print $2}')
  fi

  # Determine current level (0: Off, 1: Low, 2: Medium, 3: High, 4: Ultra)
  if [[ "$BLUR_ENABLED" == "false" || "$BLUR_ENABLED" == "0" || "${PASSES:-0}" -le 0 ]]; then
      CURRENT_LEVEL=0
  elif [ "${PASSES}" -eq 1 ]; then
      CURRENT_LEVEL=1
  elif [ "${PASSES}" -eq 2 ]; then
      CURRENT_LEVEL=2
  elif [ "${PASSES}" -eq 3 ]; then
      CURRENT_LEVEL=3
  else
      CURRENT_LEVEL=4
  fi

  ACTION="${1:---toggle}"

  case "$ACTION" in
    --inc|+|-inc|inc|up|--up)
      TARGET_LEVEL=$((CURRENT_LEVEL + 1))
      (( TARGET_LEVEL > 4 )) && TARGET_LEVEL=4
      ;;
    --dec|-|-dec|dec|down|--down)
      TARGET_LEVEL=$((CURRENT_LEVEL - 1))
      (( TARGET_LEVEL < 0 )) && TARGET_LEVEL=0
      ;;
    --off|off|0)
      TARGET_LEVEL=0
      ;;
    --low|low|1)
      TARGET_LEVEL=1
      ;;
    --med|--medium|--normal|medium|normal|2)
      TARGET_LEVEL=2
      ;;
    --high|high|3)
      TARGET_LEVEL=3
      ;;
    --ultra|--max|ultra|max|4)
      TARGET_LEVEL=4
      ;;
    --toggle|toggle|"")
      # Cycle: Off (0) -> Low (1) -> Medium (2) -> High (3) -> Ultra (4) -> Off (0)
      case "$CURRENT_LEVEL" in
        0) TARGET_LEVEL=1 ;;
        1) TARGET_LEVEL=2 ;;
        2) TARGET_LEVEL=3 ;;
        3) TARGET_LEVEL=4 ;;
        *) TARGET_LEVEL=0 ;;
      esac
      ;;
    *)
      # Parse numeric arg directly
      if [[ "$ACTION" =~ ^[0-4]$ ]]; then
        TARGET_LEVEL="$ACTION"
      else
        TARGET_LEVEL=$(( (CURRENT_LEVEL + 1) % 5 ))
      fi
      ;;
  esac

  # Map target level to Hyprland blur properties
  case "$TARGET_LEVEL" in
    0)
      SET_ENABLED="false"
      SET_SIZE=0
      SET_PASSES=0
      LEVEL_NAME="Disabled"
      PERCENT=0
      ICON="$ICON_OFF"
      DETAIL="Blur Off"
      ;;
    1)
      SET_ENABLED="true"
      SET_SIZE=3
      SET_PASSES=1
      LEVEL_NAME="Low"
      PERCENT=25
      ICON="$ICON_ON"
      DETAIL="Size: 3 | Passes: 1"
      ;;
    2)
      SET_ENABLED="true"
      SET_SIZE=6
      SET_PASSES=2
      LEVEL_NAME="Medium"
      PERCENT=50
      ICON="$ICON_ON"
      DETAIL="Size: 6 | Passes: 2"
      ;;
    3)
      SET_ENABLED="true"
      SET_SIZE=8
      SET_PASSES=3
      LEVEL_NAME="High"
      PERCENT=75
      ICON="$ICON_ON"
      DETAIL="Size: 8 | Passes: 3"
      ;;
    4|*)
      SET_ENABLED="true"
      SET_SIZE=10
      SET_PASSES=4
      LEVEL_NAME="Ultra"
      PERCENT=100
      ICON="$ICON_ON"
      DETAIL="Size: 10 | Passes: 4"
      ;;
  esac

  if [[ "$hypr_config_mode" == "lua" ]]; then
    hyprctl -r eval "hl.config({ decoration = { blur = { enabled = ${SET_ENABLED}, size = ${SET_SIZE}, passes = ${SET_PASSES}, ignore_opacity = true, xray = false, new_optimizations = true } } })" >/dev/null 2>&1 || true
  else
    if [[ "$SET_ENABLED" == "true" ]]; then
      hyprctl keyword decoration:blur:enabled 1
    else
      hyprctl keyword decoration:blur:enabled 0
    fi
    hyprctl keyword decoration:blur:size "$SET_SIZE"
    hyprctl keyword decoration:blur:passes "$SET_PASSES"
    hyprctl keyword decoration:blur:ignore_opacity 1
    hyprctl keyword decoration:blur:xray 0
    hyprctl keyword decoration:blur:new_optimizations 1
  fi

  # Send notification
  if command -v notify-send >/dev/null 2>&1 && [[ -n "${WAYLAND_DISPLAY:-}${DISPLAY:-}" ]]; then
    notify-send -e \
      -h string:x-canonical-private-synchronous:blur_notif \
      -h int:value:"$PERCENT" \
      -u low \
      -i "$ICON" \
      " Blur: ${LEVEL_NAME}" " ${DETAIL}" 2>/dev/null || true
  fi
) 200>"$LOCK"
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage