diff --git a/.config/waybar/config.jsonc b/.config/waybar/config.jsonc index 6cdd967..82284da 100644 --- a/.config/waybar/config.jsonc +++ b/.config/waybar/config.jsonc @@ -123,9 +123,12 @@ "return-type": "json", "exec": "~/.local/bin/fanstat", "interval": 1, + "smooth-scrolling-threshold": 5, + "on-scroll-up": "~/.local/bin/fanctl incr", + "on-scroll-down": "~/.local/bin/fanctl decr", "on-click": "~/.local/bin/fanctl min", "on-click-right": "~/.local/bin/fanctl max", - "on-click-middle": "~/.local/bin/fanctl auto" + "on-click-double": "~/.local/bin/fanctl auto" }, "custom/quit": { "format": " 󰗼 ", diff --git a/.local/bin/fanctl b/.local/bin/fanctl index 6ae8775..2561335 100755 --- a/.local/bin/fanctl +++ b/.local/bin/fanctl @@ -1,5 +1,9 @@ #!/bin/bash - +if [ -f ~/.local/bin/fanctl ]; then + # Read the values of text, class, and tooltip + source ~/.local/bin/stats/fanstat +fi + # Function to check if a string is an integer is_integer() { [[ $1 =~ ^[0-9]+$ ]] @@ -42,10 +46,42 @@ case $1 in tooltip="Auto" class="auto" ;; + incr) + if [[ $tooltipstat != "Auto" ]]; then + new_tooltipstat="${tooltipstat%?}" + new_speed=$(( $new_tooltipstat + 10)) + if [[ $new_speed -lt 100 ]]; then + nbfc set -f 0 1 -s $new_speed + text="custom" + tooltip="$new_speed%" + class="custom" + else + text=$textstat + tooltip="$tooltipstat" + class=$classstat + fi + fi + ;; + decr) + if [[ $tooltipstat != "Auto" ]]; then + new_tooltipstat="${tooltipstat%?}" + new_speed=$(( $new_tooltipstat - 10)) + if [[ $new_speed -gt 0 ]]; then + nbfc set -f 0 1 -s $new_speed + text="custom" + tooltip="$new_speed%" + class="custom" + else + text=$textstat + tooltip="$tooltipstat" + class=$classstat + fi + fi + ;; *) if is_integer "$1"; then # Check if argument is an integer nbfc set -f 0 1 -s "$1" # Execute nbfc with the provided integer value - text="$1" + text="custom" tooltip="$1%" class="custom" else @@ -56,7 +92,7 @@ case $1 in esac # Output text, tooltip, and class to statfile -echo "text=$text" > ~/.local/bin/stats/fanstat -echo "tooltip=$(waybar_tooltip "$tooltip")" >> ~/.local/bin/stats/fanstat -echo "class=$class" >> ~/.local/bin/stats/fanstat +echo "textstat=$text" > ~/.local/bin/stats/fanstat +echo "tooltipstat=$(waybar_tooltip "$tooltip")" >> ~/.local/bin/stats/fanstat +echo "classstat=$class" >> ~/.local/bin/stats/fanstat diff --git a/.local/bin/fanstat b/.local/bin/fanstat index fd2ff6b..c04102b 100755 --- a/.local/bin/fanstat +++ b/.local/bin/fanstat @@ -6,7 +6,7 @@ if [ -f ~/.local/bin/fanctl ]; then source ~/.local/bin/stats/fanstat # Output the values in JSON format using printf - printf '{"text": "%s", "tooltip": "%s", "class": "%s"}\n' "$text" "$tooltip" "$class" + printf '{"text": "%s", "tooltip": "%s", "class": "%s"}\n' "$textstat" "$tooltipstat" "$classstat" else echo "{\"error\": \"File not found\"}" fi diff --git a/.local/bin/stats/fanstat b/.local/bin/stats/fanstat index 3b2e177..0b1caf3 100644 --- a/.local/bin/stats/fanstat +++ b/.local/bin/stats/fanstat @@ -1,3 +1,3 @@ -text=min -tooltip=30% -class=min +textstat=min +tooltipstat=30% +classstat=min