about summary refs log tree commit diff
path: root/swaywm/local/bin/brightness
blob: 2c8ebb46c922a79f21bd26397fbde667a8dac85b (plain)
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
#!/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