-
Notifications
You must be signed in to change notification settings - Fork 0
/
brightnesscontrol.py
executable file
·72 lines (54 loc) · 1.9 KB
/
brightnesscontrol.py
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/python3
# Add following rule to udev and add user to group video
# /etc/udev/rules.d/backlight.rules:
# ACTION=="add", SUBSYSTEM=="backlight", KERNEL=="%k", RUN+="/bin/chgrp video /sys/class/backlight/%k/brightness"
# ACTION=="add", SUBSYSTEM=="backlight", KERNEL=="%k", RUN+="/bin/chmod g+w /sys/class/backlight/%k/brightness"
import sys
import argparse
import notify2
parser = argparse.ArgumentParser()
parser.add_argument('-u', '--up', action='store_true', help='Turns brightness up by 10%')
parser.add_argument('-d', '--down', action='store_true', help='Turns brightness down by 10%')
parser.add_argument('-v', '--value', dest='value',
help='Set a brightness value between 0 - 100%', type=int, choices=range(0, 100))
args = parser.parse_args()
value = args.value
# Change the one image here: (for now)
image = 'display-brightness'
def getval():
with open('/sys/class/backlight/amdgpu_bl0/brightness', 'r') as f:
raw = int(f.read())
return raw
def putval(value):
if value > 255:
value = 255
if value > 0 and value <= 255:
with open('/sys/class/backlight/amdgpu_bl0/brightness', 'w') as f:
f.write(str(value))
def calc(raw):
perc = round(raw/2.55)
return perc
def send_notify(message):
try:
with open('/tmp/notify_brightness.tmp', 'r') as num:
nid = num.read()
except FileNotFoundError:
nid = 0
notify2.init("Brightness")
n = notify2.Notification('Brightness', message=str(message))
n.set_hint_string('image-path', image)
n.id = nid
n.show()
with open('/tmp/notify_brightness.tmp', 'w') as num:
num.write(str(n.id))
if args.up:
a = round(getval()+25)
putval(a)
send_notify(calc(getval()))
if args.down:
a = round(getval()-25)
putval(a)
send_notify(calc(getval()))
if args.value:
putval(round(value*2.55))
send_notify(calc(getval()))