switched to different battery indicator.

This commit is contained in:
Rick van Lieshout 2019-09-16 09:16:54 +02:00
parent 4d68d00007
commit efc1f43ebf
3 changed files with 116 additions and 6 deletions

View File

@ -11,6 +11,6 @@ ln -sf "$MYPATH/Xresources.undocked" ~/.Xresources.undocked
ln -sf "$MYPATH/docked.sh" ~/.docked.sh
ln -sf "$MYPATH/undocked.sh" ~/.undocked.sh
ln -sf "$MYPATH/xprofile.sh" ~/.xprofile
# custom (laptop specific) bashrc thingies :)
ln -sf "$MYPATH/custom-bashrc.sh" ~/.custom

View File

@ -120,17 +120,25 @@ color=#999999
label=
instance=Master
interval=1
command=/usr/lib/i3blocks/volume 5 pulse
command=/usr/lib/i3blocks/volume/volume 5 pulse
signal=10
separator=true
color=#999999
# Battery indicator
# The battery instance defaults to 0.
[battery]
#label=BAT
label=
#instance=1
# [battery]
# label=
# #instance=1
# interval=30
# separator=true
# color=#999999
# Battery indicator
# The battery instance defaults to 0.
[battery2]
command=python ~/.config/i3/scripts/blocks/battery
markup=pango
interval=30
separator=true
color=#999999

102
i3/scripts/blocks/battery Executable file
View File

@ -0,0 +1,102 @@
#!/usr/bin/env python3
#
# Copyright (C) 2016 James Murphy
# Licensed under the GPL version 2 only
#
# A battery indicator blocklet script for i3blocks
import re
from subprocess import check_output
status = check_output(['acpi'], universal_newlines=True)
if not status:
# stands for no battery found
fulltext = "<span color='red'><span font='FontAwesome'>\uf00d \uf240</span></span>"
percentleft = 100
else:
# if there is more than one battery in one laptop, the percentage left is
# available for each battery separately, although state and remaining
# time for overall block is shown in the status of the first battery
batteries = status.split("\n")
state_batteries=[]
commasplitstatus_batteries=[]
percentleft_batteries=[]
time = ""
for battery in batteries:
if battery!='':
state_batteries.append(battery.split(": ")[1].split(", ")[0])
commasplitstatus = battery.split(", ")
if not time:
time = commasplitstatus[-1].strip()
# check if it matches a time
time = re.match(r"(\d+):(\d+)", time)
if time:
time = ":".join(time.groups())
timeleft = " ({})".format(time)
else:
timeleft = ""
p = int(commasplitstatus[1].rstrip("%\n"))
if p>0:
percentleft_batteries.append(p)
commasplitstatus_batteries.append(commasplitstatus)
state = state_batteries[0]
commasplitstatus = commasplitstatus_batteries[0]
if percentleft_batteries:
percentleft = int(sum(percentleft_batteries)/len(percentleft_batteries))
else:
percentleft = 0
# stands for charging
FA_LIGHTNING = "<span color='yellow'><span font='FontAwesome'>\uf0e7</span></span>"
# stands for plugged in
FA_PLUG = "<span font='FontAwesome'>\uf1e6</span>"
# stands for using battery
FA_BATTERY = "<span font='FontAwesome'>\uf240</span>"
# stands for unknown status of battery
FA_QUESTION = "<span font='FontAwesome'>\uf128</span>"
if state == "Discharging":
fulltext = FA_BATTERY + " "
elif state == "Full":
fulltext = FA_PLUG + " "
timeleft = ""
elif state == "Unknown":
fulltext = FA_QUESTION + " " + FA_BATTERY + " "
timeleft = ""
else:
fulltext = FA_LIGHTNING + " " + FA_PLUG + " "
def color(percent):
if percent < 10:
# exit code 33 will turn background red
return "#FFFFFF"
if percent < 20:
return "#FF3300"
if percent < 30:
return "#FF6600"
if percent < 40:
return "#FF9900"
if percent < 50:
return "#FFCC00"
if percent < 60:
return "#FFFF00"
if percent < 70:
return "#FFFF33"
if percent < 80:
return "#FFFF66"
return "#FFFFFF"
form = '<span>{}%</span>'
fulltext += form.format(percentleft)
fulltext += timeleft
print(fulltext)
print(fulltext)
if percentleft < 10:
exit(33)