Support mute state in volume slider #100
-
I "created" (mostly copied from dotfiles) this volume popup. from ignis.widgets import Widget
from ignis.utils import Utils
from ignis.services.audio import AudioService
audio_service = AudioService.get_default()
class VolumePopup(Widget.Window):
def __init__(self):
super().__init__(
layer="overlay",
anchor=["bottom"],
namespace="volume_popup",
visible=False,
css_classes=["rec-unset"],
child=Widget.Box(
css_classes=["popup"],
spacing=10,
child=[
Widget.Icon(
pixel_size=26,
image="volume-high-symbolic",
),
Widget.Scale(
min=0,
max=150,
value=audio_service.speaker.bind("volume"),
css_classes=["material-slider"],
sensitive=False,
hexpand=True,
),
],
),
)
def set_property(self, property_name, value):
if property_name == "visible":
self.__update_visible()
super().set_property(property_name, value)
@Utils.debounce(3_000)
def __update_visible(self) -> None:
super().set_property("visible", False) When i click the mute key on the keyboard, the sink is muted, the volume is left untouched, and this popup is shown. Currently, the scale widget shows the correct volume value just when increasing or decreasing the volume. When it's muted, i want it to show the value 0 on the slider, but it still shows the current volume (the behavior is correct). However I want it to:
How can i do so? How can i bind to the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
add this to your setup=lambda self: audio.speaker.connect(
"notify::is-muted",
lambda x, y: self.set_value(
0 if audio.speaker.is_muted else audio.speaker.volume
),
), |
Beta Was this translation helpful? Give feedback.
-
UPD: #103 adds Widget.Scale(
value=audio.speaker.bind_many(
["volume", "is_muted"],
lambda volume, is_muted: 0 if is_muted else volume,
),
) |
Beta Was this translation helpful? Give feedback.
UPD: #103 adds
bind_many()
, so you can write it just like this: