about summary refs log tree commit diff
path: root/swaywm/local/bin/brightness
diff options
context:
space:
mode:
Diffstat (limited to 'swaywm/local/bin/brightness')
-rwxr-xr-xswaywm/local/bin/brightness52
1 files changed, 52 insertions, 0 deletions
diff --git a/swaywm/local/bin/brightness b/swaywm/local/bin/brightness
new file mode 100755
index 0000000..2c8ebb4
--- /dev/null
+++ b/swaywm/local/bin/brightness
@@ -0,0 +1,52 @@
+#!/bin/bash
+
+function get_brightness {
+    cntb=$(brightnessctl g)
+    maxb=$(brightnessctl m)
+
+    echo $(( ($cntb * 100) / $maxb ))
+}
+
+# Function to get the icon based on the brightness level
+function get_brightness_icon {
+    brightness_level=$1
+    if [ $brightness_level -le 33 ]; then
+        echo "󰃞"
+    elif [ $brightness_level -le 66 ]; then
+        echo "󰃟"
+    else
+        echo "󰃠"
+    fi
+}
+
+# Function to set the contents of "/tmp/brightness_status" to the current brightness level
+function set_tmp_brightness_status {
+    brightness_level=$(get_brightness)
+    icon=$(get_brightness_icon $brightness_level)
+    echo "$icon  $brightness_level%" > /tmp/brightness_status
+}
+
+function send_notification {
+    brightness_level=$(get_brightness)
+    icon=$(get_brightness_icon $brightness_level)
+    # Make the bar with the special character ─ (it's not dash -)
+    # https://en.wikipedia.org/wiki/Box-drawing_character
+    bar=$(seq -s "─" $(($brightness_level / 5)) | sed 's/[0-9]//g')
+    # Send the notification
+    dunstify -i display-brightness-symbolic -t 2500 -r 2593 -u normal "    $bar"
+}
+
+case $1 in
+    up)
+	# Set the brightness level up (+ 5%)
+        brightnessctl s 5%+
+        send_notification
+        set_tmp_brightness_status
+	;;
+    down)
+	# Set the brightness level down (- 5%)
+        brightnessctl s 5%-
+	send_notification
+        set_tmp_brightness_status
+	;;
+esac