-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathi3_brightness_ctrl.py
More file actions
executable file
·51 lines (45 loc) · 1.43 KB
/
i3_brightness_ctrl.py
File metadata and controls
executable file
·51 lines (45 loc) · 1.43 KB
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
#!/usr/bin/env python3
#
# GNU GENERAL PUBLIC LICENSE v3
#
# Copyright (C) <2017> JOSE MARCOS <jm4rcos@gmail.com>
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.
#
# See <http://www.gnu.org/licenses/> for more details of the GNU General Public
# License.
#
# comments/requirements:
#
# usage: ./i3_brightness_ctrl.py <value>
#
# [*] allowed values for sys.argv[1] (first argument for script) are:
# +/- 0.1
# +/- 0.3
# +/- 0.5
import os
import sys
# defining primary output
p_output = os.popen("xrandr |grep primary |awk -F' ' '{ print $1 }'").read().strip()
# current brightness value as float type
#
b = os.popen("xrandr --verbose | grep -i brightness | cut -f2 -d ' ' | head -n1")
b = float(b.read().strip('\n'))
# read brightness new value
#
try:
new_b = float(sys.argv[1])
except IndexError:
exit()
# check if sys.argv[1] is one of the allowed values and add it to current
# brightness values
#
if any(x == new_b for x in [0.1, -0.1, 0.3, -0.3, 0.5, -0.5]):
os.popen("xrandr --output " + p_output + " --brightness " + str(b + new_b))