summaryrefslogtreecommitdiff
path: root/dot-config/bspwm/scripts/bspbrightness
blob: cdf67047623129f6bc7d9c9b14f41e8f855c8acc (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env bash

## Script to manage brightness on Archcraft.

# Icons
iDIR='/usr/share/archcraft/icons/dunst'

# Graphics card
CARD=`ls /sys/class/backlight | head -n 1`

# Get brightness
get_backlight() {
	if [[ "$CARD" == *"intel_"* ]]; then
		BNESS=`xbacklight -get`
		LIGHT=${BNESS%.*}
	else
		LIGHT=$(printf "%.0f\n" `light -G`)
	fi
	echo "${LIGHT}%"
}

# Get icons
get_icon() {
	backlight="$(get_backlight)"
	current="${backlight%%%}"
	if [[ ("$current" -ge "0") && ("$current" -le "20") ]]; then
		icon="$iDIR"/brightness-20.png
	elif [[ ("$current" -ge "20") && ("$current" -le "40") ]]; then
		icon="$iDIR"/brightness-40.png
	elif [[ ("$current" -ge "40") && ("$current" -le "60") ]]; then
		icon="$iDIR"/brightness-60.png
	elif [[ ("$current" -ge "60") && ("$current" -le "80") ]]; then
		icon="$iDIR"/brightness-80.png
	elif [[ ("$current" -ge "80") && ("$current" -le "100") ]]; then
		icon="$iDIR"/brightness-100.png
	fi
}

# Notify 
notify_bl() {
	get_icon && dunstify -u low -h string:x-dunst-stack-tag:obbacklight -i "$icon" "Brightness : $(get_backlight)"
}

# Increase brightness
inc_backlight() {
	if [[ "$CARD" == *"intel_"* ]]; then
		xbacklight -inc 10 && notify_bl
	else
		light -A 5 && notify_bl
	fi
}

# Decrease brightness
dec_backlight() {
	if [[ "$CARD" == *"intel_"* ]]; then
		xbacklight -dec 10 && notify_bl
	else
		light -U 5 && notify_bl
	fi
}

# Execute accordingly
if [[ "$1" == "--get" ]]; then
	get_backlight
elif [[ "$1" == "--inc" ]]; then
	inc_backlight
elif [[ "$1" == "--dec" ]]; then
	dec_backlight
else
	get_backlight
fi