diff --git a/bumblebee/modules/battery.py b/bumblebee/modules/battery.py index e5be816..7f5207e 100644 --- a/bumblebee/modules/battery.py +++ b/bumblebee/modules/battery.py @@ -11,9 +11,14 @@ class Module(bumblebee.module.Module): def data(self): with open("/sys/class/power_supply/%s/capacity" % self._battery) as f: self._capacity = int(f.read()) - with open("/sys/class/power_supply/%s/status" % self._battery) as f: - self._status = f.read().strip() return "%02d%%" % self._capacity + def state(self): + with open("/sys/class/power_supply/%s/status" % self._battery) as f: + self._status = f.read().strip() + if self._status == "Discharging": + return "discharging" + else: + return "charging" # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/bumblebee/theme.py b/bumblebee/theme.py index 8e095be..91100ba 100644 --- a/bumblebee/theme.py +++ b/bumblebee/theme.py @@ -17,6 +17,12 @@ class Theme: value = self._defaults.get(key, value) value = module_theme.get(key, value) + if hasattr(obj, "state"): + state = getattr(obj, "state")() + state_theme = module_theme.get("states", {}).get(state, {}) + + value = state_theme.get(key, value) + return value def prefix(self, obj): diff --git a/bumblebee/themes/default.json b/bumblebee/themes/default.json index d0e5e53..68040de 100644 --- a/bumblebee/themes/default.json +++ b/bumblebee/themes/default.json @@ -4,7 +4,15 @@ "suffix" : " " }, "battery": { - "prefix": "bat " + "prefix": "bat ", + "states": { + "charging": { + "suffix": "+" + }, + "discharging": { + "suffix": "-" + } + } }, "time": { }