Add backlight percentage indicator to i3 status wrapper
This commit is contained in:
parent
a904acc05e
commit
c203baa25d
21
i3wrapper.py
21
i3wrapper.py
@ -5,14 +5,14 @@ import json
|
||||
_BITS = []
|
||||
|
||||
|
||||
def _bit(idx, name):
|
||||
def _bit(idx):
|
||||
def wrapper(func):
|
||||
_BITS.append([idx, name, func])
|
||||
_BITS.append([idx, func.__name__.replace('_', ''), func])
|
||||
return func
|
||||
return wrapper
|
||||
|
||||
|
||||
@_bit(6, 'mem')
|
||||
@_bit(6)
|
||||
def _mem():
|
||||
with open('/proc/meminfo') as meminfo_fp:
|
||||
attrs = {}
|
||||
@ -30,6 +30,21 @@ def _mem():
|
||||
return 'M:{}%'.format(used), color
|
||||
|
||||
|
||||
@_bit(0)
|
||||
def _backlight(dev_dir='/sys/class/backlight/intel_backlight'):
|
||||
with open('{}/brightness'.format(dev_dir)) as br_fp:
|
||||
with open('{}/max_brightness'.format(dev_dir)) as mb_fp:
|
||||
value = int(br_fp.read().strip())
|
||||
max_value = int(mb_fp.read().strip())
|
||||
pct = int(float(float(value) / float(max_value)) * 100)
|
||||
color = None
|
||||
if pct >= 75:
|
||||
color = '#ffaa00'
|
||||
if pct <= 25:
|
||||
color = '#5599ff'
|
||||
return '☼:{}%'.format(pct), color
|
||||
|
||||
|
||||
def _print_line(message):
|
||||
sys.stdout.write(message + '\n')
|
||||
sys.stdout.flush()
|
||||
|
Loading…
Reference in New Issue
Block a user