Skip to content

Commit

Permalink
feat(widgets): add mute foreground for Volume and PulseVolume
Browse files Browse the repository at this point in the history
  • Loading branch information
shyguyCreate committed May 1, 2024
1 parent 8d254f6 commit a2a84d6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libqtile/widget/volume.py
Expand Up @@ -76,6 +76,7 @@ class Volume(base._TextBox):
" List contains 4 symbols, from lowest volume to highest.",
),
("mute_command", None, "Mute command"),
("mute_foreground", None, "Foreground color for mute volume."),
("mute_format", "M", "Format to display when volume is muted."),
("unmute_format", "{volume}%", "Format of text to display when volume is not muted."),
("volume_app", None, "App to control volume"),
Expand Down Expand Up @@ -109,6 +110,7 @@ def __init__(self, **config):
self.surfaces = {}
self.volume = None
self.mute = False
self.unmute_foreground = self.foreground

self.add_callbacks(
{
Expand Down Expand Up @@ -158,6 +160,9 @@ def update(self):
self.timeout_add(self.update_interval, self.update)

def _update_drawer(self):
if self.mute_foreground is not None:
self.foreground = self.mute_foreground if self.mute else self.unmute_foreground

if self.theme_path:
self.drawer.clear(self.background or self.bar.background)
if self.volume <= 0:
Expand Down
18 changes: 18 additions & 0 deletions test/widgets/test_volume.py
Expand Up @@ -75,3 +75,21 @@ def test_formats():
vol.mute = True
vol._update_drawer()
assert vol.text == "Volume: 50% M"


def test_foregrounds():
foreground = "#dddddd"
mute_foreground = None
vol = Volume(foreground=foreground, mute_foreground=mute_foreground)
vol.volume = 50
vol._update_drawer()
assert vol.foreground == foreground

vol.mute_foreground = mute_foreground = "#888888"
vol.mute = False
vol._update_drawer()
assert vol.foreground == foreground

vol.mute = True
vol._update_drawer()
assert vol.foreground == mute_foreground

0 comments on commit a2a84d6

Please sign in to comment.