irongit
hygoland/scripts/Brightness.sh
74 lines1.6 KBBourne Again Shell (bash)
1#!/bin/bash
2# /* ---- 💫 https://github.com/JaKooLit 💫 ---- */ ##
3# Script for Monitor backlights (if supported) using brightnessctl
4
5iDIR="$HOME/.config/swaync/icons"
6notification_timeout=1000
7step=10 # INCREASE/DECREASE BY THIS VALUE
8
9# Get brightness
10get_backlight() {
11 brightnessctl -m | cut -d, -f4 | sed 's/%//'
12}
13
14# Get icons
15get_icon() {
16 current=$(get_backlight)
17 if [ "$current" -le "20" ]; then
18 icon="$iDIR/brightness-20.png"
19 elif [ "$current" -le "40" ]; then
20 icon="$iDIR/brightness-40.png"
21 elif [ "$current" -le "60" ]; then
22 icon="$iDIR/brightness-60.png"
23 elif [ "$current" -le "80" ]; then
24 icon="$iDIR/brightness-80.png"
25 else
26 icon="$iDIR/brightness-100.png"
27 fi
28}
29
30# Notify
31notify_user() {
32 notify-send -e -h string:x-canonical-private-synchronous:brightness_notif -h int:value:$current -u low -i $icon "Screen" "Brightness:$current%"
33}
34
35# Change brightness
36change_backlight() {
37 local current_brightness
38 current_brightness=$(get_backlight)
39
40 # Calculate new brightness
41 if [[ "$1" == "+${step}%" ]]; then
42 new_brightness=$((current_brightness + step))
43 elif [[ "$1" == "${step}%-" ]]; then
44 new_brightness=$((current_brightness - step))
45 fi
46
47 # Ensure new brightness is within valid range
48 if (( new_brightness < 5 )); then
49 new_brightness=5
50 elif (( new_brightness > 100 )); then
51 new_brightness=100
52 fi
53
54 brightnessctl set "${new_brightness}%"
55 get_icon
56 current=$new_brightness
57 notify_user
58}
59
60# Execute accordingly
61case "$1" in
62 "--get")
63 get_backlight
64 ;;
65 "--inc")
66 change_backlight "+${step}%"
67 ;;
68 "--dec")
69 change_backlight "${step}%-"
70 ;;
71 *)
72 get_backlight
73 ;;
74esac