From 14bce293eb0a90494f1c8dafab4ed3b767765542 Mon Sep 17 00:00:00 2001 From: Tobias Witek Date: Mon, 31 Oct 2016 11:35:12 +0100 Subject: [PATCH] [themes] Add support for generic warning/critical colors Font and background colors for warning and critical elements can now be specified using fg-warning, fg-critical, bg-warning and bg-critical. Also, optionally, the "urgent" flag will be set towards the i3bar, if possible. --- bumblebee/module.py | 6 ++++++ bumblebee/modules/battery.py | 10 +++++++++- bumblebee/outputs/i3.py | 4 ++++ bumblebee/theme.py | 22 ++++++++++++++++++++-- bumblebee/themes/default.json | 1 + 5 files changed, 40 insertions(+), 3 deletions(-) diff --git a/bumblebee/module.py b/bumblebee/module.py index 4b3811b..11549a5 100644 --- a/bumblebee/module.py +++ b/bumblebee/module.py @@ -6,6 +6,12 @@ class Module(object): def data(self): pass + def critical(self): + return False + + def warning(self): + return False + def state(self): return "default" diff --git a/bumblebee/modules/battery.py b/bumblebee/modules/battery.py index abe0a68..2c779e8 100644 --- a/bumblebee/modules/battery.py +++ b/bumblebee/modules/battery.py @@ -18,7 +18,15 @@ class Module(bumblebee.module.Module): with open("/sys/class/power_supply/{}/status".format(self._battery)) as f: self._status = f.read().strip() if self._status == "Discharging": - return "discharging" + if self._capacity < 10: + return "discharging_critical" + if self._capacity < 25: + return "discharging_low" + if self._capacity < 50: + return "discharging_medium" + if self._capacity < 75: + return "discharging_high" + return "discharging_full" else: return "charging" # vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/bumblebee/outputs/i3.py b/bumblebee/outputs/i3.py index eec156e..63bbeed 100644 --- a/bumblebee/outputs/i3.py +++ b/bumblebee/outputs/i3.py @@ -20,6 +20,10 @@ class i3bar(bumblebee.output.Output): "color": theme.color(obj), "background": theme.background(obj), } + + if theme.urgent(obj) and obj.critical(): + data["urgent"] = True + if theme.default_separators(obj) == False: data["separator"] = False data["separator_block_width"] = 0 diff --git a/bumblebee/theme.py b/bumblebee/theme.py index e7f7776..6cf115d 100644 --- a/bumblebee/theme.py +++ b/bumblebee/theme.py @@ -37,6 +37,9 @@ class Theme: self._previous_background = None self._background = None + def urgent(self, obj): + self._gettheme(obj, "urgent") + def next(self): self._cycle_index += 1 self._previous_background = self._background @@ -44,10 +47,25 @@ class Theme: self._cycle_index = 0 def color(self, obj): - return self._gettheme(obj, "fg") + fg = None + if obj.warning(): + fg = self._gettheme(obj, "fg-warning") + if obj.critical(): + fg = self._gettheme(obj, "fg-critical") + if fg == None: + fg = self._gettheme(obj, "fg") + return fg def background(self, obj): - self._background = self._gettheme(obj, "bg") + self._background = None + if obj.warning(): + self._background = self._gettheme(obj, "bg-warning") + if obj.critical(): + self._background = self._gettheme(obj, "bg-critical") + + if self._background == None: + self._background = self._gettheme(obj, "bg") + return self._background def previous_background(self): diff --git a/bumblebee/themes/default.json b/bumblebee/themes/default.json index 09fdcdd..cb05338 100644 --- a/bumblebee/themes/default.json +++ b/bumblebee/themes/default.json @@ -1,5 +1,6 @@ { "defaults": { + "urgent": true, "prefix": " ", "suffix" : " ", "cycle": [