aboutsummaryrefslogtreecommitdiff
path: root/.config/eww/scripts/brightnesscontrol
blob: 3f9cca9de5a6a1b1163b53601bfda3156aa3f3e3 (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
#!/bin/bash

# You can call this script like this:
# brightnessControl up
# brightnessControl down

# Script inspired by these wonderful people:
# https://github.com/dastorm/volume-notification-dunst/blob/master/volume.sh
# https://gist.github.com/sebastiencs/5d7227f388d93374cebdf72e783fbd6a

function send_notification {
  icon="/usr/share/icons/Adwaita/symbolic/status/daytime-sunrise-symbolic.svg"
  brightness=$(brightnessctl g)
  brightness=$((brightness *100 / 255 ))
  brightness=$(echo "$brightness" | awk '{print ($0-int($0)<0.499)?int($0):int($0)+1}')
  # Make the bar with the special character ─ (it's not dash -)
  # https://en.wikipedia.org/wiki/Box-drawing_character
  bar=$(seq -s "─" 0 $((brightness / 10 )) | sed 's/[0-9]//g')
  # Send the notification
  fyi -i "$icon" --hint=string:x-canonical-private-synchronous:brightness -u normal "$bar  $brightness"
}

case $1 in
  up)
    # increase the backlight by 5%
    brightnessctl s +5%
    send_notification
    # canberra-gtk-play -i audio-volume-change
    ;;
  down)
    # decrease the backlight by 5%
    brightnessctl s 5%-
    send_notification
    # canberra-gtk-play -i audio-volume-change
    ;;
  *)
    brightness=$(brightnessctl g)
    brightness=$((brightness *100 / 255 ))
    brightness=$(echo "$brightness" | awk '{print ($0-int($0)<0.499)?int($0):int($0)+1}')
    icon=""
    printf "%s" "$icon $brightness" "%"
    ;;
esac