Skip to content

Commit

Permalink
Add fill_charge parameter for UPower widget
Browse files Browse the repository at this point in the history
Default behaviour is to use standard colours but the PR
allows users to override the default behvaiour and set a fill
colour for when the battery is charging.
  • Loading branch information
elParaguayo committed Jul 27, 2022
1 parent bb6e7ea commit 159eb19
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
2022-07-21: [BUGFIX] Fux CurrentLayoutIcon to work with latest git version
2022-07-27: [FEATURE] Add `fill_charge` to UPower widget
2022-07-21: [BUGFIX] Fix CurrentLayoutIcon to work with latest git version
2022-07-21: [BUGFIX] Fix blocking API calls in Snapcast and GithubNotification widgets
2022-07-07: [BUGFIX] Fix UPowerWidget not showing text on click when fontsize is None
2022-07-03: [PACKAGING] Use git versioning details
Expand Down
10 changes: 7 additions & 3 deletions qtile_extras/widget/upower.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class UPowerWidget(base._Widget):
("fill_normal", "dbdbe0", "Fill when normal"),
("fill_low", "aa00aa", "Fill colour when battery low"),
("fill_critical", "cc0000", "Fill when critically low"),
("fill_charge", None, "Override fill colour when charging"),
("margin", 2, "Margin on sides of widget"),
("spacing", 5, "Space between batteries"),
("percentage_low", 0.20, "Low level threshold."),
Expand Down Expand Up @@ -289,9 +290,12 @@ def draw(self):
percentage = battery["fraction"]

# Get the appropriate fill colour
# This finds the first value in self_colours which is greater than
# the current battery level and returns the colour string
fill = next(x[1] for x in self.colours if percentage <= x[0])
if self.charging and self.fill_charge:
fill = self.fill_charge
else:
# This finds the first value in self_colours which is greater than
# the current battery level and returns the colour string
fill = next(x[1] for x in self.colours if percentage <= x[0])

# Choose border colour
if (percentage <= self.percentage_critical) and not self.charging:
Expand Down

0 comments on commit 159eb19

Please sign in to comment.