Batterie icon mit acpi_listen implementiert

This commit is contained in:
madmaurice 2015-06-12 00:01:05 +02:00
parent 71f05bdaee
commit 042dbb3dd8

View file

@ -2,7 +2,7 @@
FIFO="/tmp/bar.fifo"
FORMAT=" %(music)s %(services)s %(diskspace)s %%{c} %(debug)s %%{r} %(updates)s %(wifi)s %(battery)s %(clock)s "
FORMAT=" %(music)s %(services)s %(diskspace)s %%{c} %(debug)s %%{r} %(updates)s %(wifi)s %(adapter)s %(battery)s %(clock)s "
icon_color="#A0A57E"
icon() { echo -n "%{F$icon_color}"; printf '%b' "\ue$1"; echo -n "%{F-}"; }
@ -82,23 +82,43 @@ wifi() {
battery() {
while true; do
level=$(acpi -b | awk -F, 'BEGIN { s=0 } { s+=$2 } END { print int(s/NR) }')
charging=$(acpi -a | grep on-line)
icon=$icon_battery
if [ -n "$charging" ]; then
icon=$icon_battery_charging
fi
info="%{F$color_battery_good}$level%%{F-}"
if [ "$level" -lt 20 ]; then
info="%{F$color_battery_low}$level%%{F-}"
fi
echo battery "%{A:I battery 1061:}$icon $info%{A}" > $FIFO
echo battery "%{A:I battery 1061:}$info%{A}" > $FIFO
sleep 5;
done;
}
adapter() {
_update() {
icon=$icon_battery
if [ "$1" == "1" ]; then
icon=$icon_battery_charging
fi
echo adapter "%{A:I battery 1061:}$icon%{A}" > $FIFO
}
if [ -n "$(acpi -a | grep on-line)" ]; then
_update 1
else
_update 0
fi
acpi_listen | while read DEVTYPE DEVID FLAGS STATUS; do
if [ "$DEVTYPE" == "ac_adapter" ]; then
if [ "$STATUS" == "00000001" ]; then
_update 1
else
_update 0
fi
fi
done
}
clock() {
while true; do
info=$(date +"%H:%M")
@ -146,6 +166,7 @@ services &
diskspace &
wifi &
updates &
adapter &
( while true; do cat $FIFO; done ) | python ./barformatter.py "$FORMAT" | lemonbar -g 1366x15 -f "Stlarch:size=6:style=regular" -f "Terminus:size=8" -B "#88000000" | run_handler