Skip to content

Commit

Permalink
Merge 59763c6 into 36c3f76
Browse files Browse the repository at this point in the history
  • Loading branch information
shyguyCreate committed Apr 28, 2024
2 parents 36c3f76 + 59763c6 commit 34720c5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Qtile x.xx.x, released XXXX-XX-XX:
the `qtile cmd-obj` command line
- Add `Plasma` layout. The original layout (https://github.com/numirias/qtile-plasma) appears to be unmaintained
so we have added this to the main codebase.
- Add ability to specify muted and unmuted formats for `Volume` and `PulseVolume` widgets.
* bugfixes

Qtile 0.25.0, released 2024-04-06:
Expand Down
2 changes: 0 additions & 2 deletions libqtile/widget/pulse_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,6 @@ def get_volume(self):

if self.default_sink:
mute = self.default_sink.mute
if mute:
return -1, mute
base = self.default_sink.base_volume
if not base:
return -1, mute
Expand Down
24 changes: 13 additions & 11 deletions libqtile/widget/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class Volume(base._TextBox):
" List contains 4 symbols, from lowest volume to highest.",
),
("mute_command", None, "Mute command"),
("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"),
("volume_up_command", None, "Volume up command"),
("volume_down_command", None, "Volume down command"),
Expand Down Expand Up @@ -106,6 +108,7 @@ def __init__(self, **config):
self.add_defaults(Volume.defaults)
self.surfaces = {}
self.volume = None
self.mute = False

self.add_callbacks(
{
Expand Down Expand Up @@ -144,9 +147,10 @@ def button_press(self, x, y, button):
self.draw()

def update(self):
vol = self.get_volume()
if vol != self.volume:
vol, muted = self.get_volume()
if vol != self.volume or muted != self.mute:
self.volume = vol
self.mute = muted
# Update the underlying canvas size before actually attempting
# to figure out how big it is and draw it.
self._update_drawer()
Expand Down Expand Up @@ -183,10 +187,9 @@ def _update_drawer(self):
elif self.volume >= 80:
self.text = self.emoji_list[3]
else:
if self.volume == -1:
self.text = "M"
else:
self.text = "{}%".format(self.volume)
self.text = (
self.mute_format if self.mute or self.volume < 0 else self.unmute_format
).format(volume=self.volume)

def setup_images(self):
from libqtile import images
Expand Down Expand Up @@ -214,21 +217,20 @@ def get_volume(self):

mixer_out = subprocess.getoutput(get_volume_cmd)
except subprocess.CalledProcessError:
return -1
return -1, False

check_mute = mixer_out
if self.check_mute_command:
check_mute = subprocess.getoutput(self.check_mute_command)

if self.check_mute_string in check_mute:
return -1
mute = self.check_mute_string in check_mute

volgroups = re_vol.search(mixer_out)
if volgroups:
return int(volgroups.groups()[0])
return int(volgroups.groups()[0]), mute
else:
# this shouldn't happen
return -1
return -1, mute

def draw(self):
if self.theme_path:
Expand Down
13 changes: 13 additions & 0 deletions test/widgets/test_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,16 @@ def test_text():
vol.volume = 50
vol._update_drawer()
assert vol.text == "50%"


def test_formats():
unmute_format = "Volume: {volume}%"
mute_format = "Volume: {volume}% M"
vol = Volume(unmute_format=unmute_format, mute_format=mute_format)
vol.volume = 50
vol._update_drawer()
assert vol.text == "Volume: 50%"

vol.mute = True
vol._update_drawer()
assert vol.text == "Volume: 50% M"

0 comments on commit 34720c5

Please sign in to comment.