aboutsummaryrefslogtreecommitdiff
path: root/.config/i3blocks/scripts/brightness.py
blob: 983a54f1d2ae5c3bc2ccb2407d16229e5796f99f (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
#!/usr/bin/python3
# This script is for my i3blocks bar, its handles scrolling to change
# brightness of monitor

import subprocess
import re
import os

display = "eDP-1"

proc = subprocess.Popen("xrandr --verbose | grep Brightness", shell=True,
                        stdout=subprocess.PIPE)


res = proc.stdout.readline().strip()
res = str(res)

num = re.compile("\d\.\d+")
bri = num.findall(res)[0]

bri = round(float(bri)*100)

env = os.environ
if 'BLOCK_BUTTON' in env:
    button = env['BLOCK_BUTTON']
    if button is not '':
        button = int(button)
        if button is 4:
            new_bri = bri + 5
        elif button is 5:
            new_bri = bri - 5
        else:
            new_bri = bri

        if new_bri <= 100 and new_bri >= 10:
            bri = new_bri
            new_bri = new_bri/100
            subprocess.call(f"xrandr --output {display} --brightness {new_bri}",
                            shell=True)
            subprocess.call(f"echo {new_bri} > ~/.last_brightness", shell=True)

print(f"{bri}%")