config: barpyrus: config.py: add battery percentage/status to conky

Depending on the state of the battery (discharging/charging) the color
and the battery icon will change.
This commit is contained in:
Thomas Preisner 2018-03-02 13:15:24 +01:00
parent 38a8c0710b
commit 4c615d6167

View file

@ -69,6 +69,37 @@ conky_text += '${acpitemp}°C '
conky_text += conky_icon('\ue026', 'green') + '${cpu}% ' conky_text += conky_icon('\ue026', 'green') + '${cpu}% '
conky_text += conky_icon('\ue021', 'green') + '${memperc}% ' conky_text += conky_icon('\ue021', 'green') + '${memperc}% '
# battery display
bat_icons = [
'\ue242', '\ue243', '\ue244', '\ue245', '\ue246',
'\ue247', '\ue248', '\ue249', '\ue24a', '\ue24b',
]
bat_delta = 100 / len(bat_icons)
conky_text += '${if_existing /sys/class/power_supply/BAT0}'
conky_text += '${if_match \"$battery\" == \"discharging $battery_percent%\"}'
for i, icon in enumerate(bat_icons[:-1]):
percentage = (i + 1) * bat_delta
conky_text += '${if_match $battery_percent < %d}' % (percentage)
if percentage <= 20:
conky_text += conky_icon(icon, 'red')
elif percentage <= 65:
conky_text += conky_icon(icon, 'yellow')
else:
conky_text += conky_icon(icon, 'green')
conky_text += '${else}'
# 100 percent icon
conky_text += conky_icon(bat_icons[-1], 'green')
# close all previously opened if_match tags
for _ in bat_icons[:-1]:
conky_text += '${endif}'
conky_text += '${else}'
conky_text += conky_icon('\ue239', 'cyan')
conky_text += '${endif}'
conky_text += ' $battery_percent% '
conky_text += '${endif}'
conky_text += '%{F-}'
# options for hlwm.HLWMLayoutSwitcher widget # options for hlwm.HLWMLayoutSwitcher widget
xkblayouts = [ xkblayouts = [
'us us -variant altgr-intl us'.split(' '), 'us us -variant altgr-intl us'.split(' '),