From 003a6efc8e6b929834ffb2a7ca419dbe5bfc8073 Mon Sep 17 00:00:00 2001 From: tobi-wan-kenobi Date: Fri, 9 Sep 2022 21:40:03 +0200 Subject: [PATCH] [modules/pulsectl] figure out default devices make sure the modules always refer to the default devices --- bumblebee_status/modules/core/pulsectl.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/bumblebee_status/modules/core/pulsectl.py b/bumblebee_status/modules/core/pulsectl.py index 46f3775..364156b 100644 --- a/bumblebee_status/modules/core/pulsectl.py +++ b/bumblebee_status/modules/core/pulsectl.py @@ -50,12 +50,12 @@ class Module(core.module.Module): def toggle_mute(self, _): with pulsectl.Pulse(self.id + "vol") as pulse: - dev = pulse.sink_list()[0] if self.__type == "sink" else pulse.source_list()[1] + dev = self.get_device(pulse) pulse.mute(dev, not self.__muted) def change_volume(self, amount): with pulsectl.Pulse(self.id + "vol") as pulse: - dev = pulse.sink_list()[0] if self.__type == "sink" else pulse.source_list()[1] + dev = self.get_device(pulse) vol = dev.volume vol.value_flat += amount pulse.volume_set(dev, vol) @@ -66,9 +66,20 @@ class Module(core.module.Module): def decrease_volume(self, _): self.change_volume(-self.__change/100.0) + def get_device(self, pulse): + devs = pulse.sink_list() if self.__type == "sink" else pulse.source_list() + default = pulse.server_info().default_sink_name if self.__type == "sink" else pulse.server_info().default_source_name + + for dev in devs: + if dev.name == default: + return dev + return devs[0] # fallback + + + def process(self, _): with pulsectl.Pulse(self.id + "proc") as pulse: - dev = pulse.sink_list()[0] if self.__type == "sink" else pulse.source_list()[1] + dev = self.get_device(pulse) self.__volume = dev.volume.value_flat self.__muted = dev.mute core.event.trigger("update", [self.id], redraw_only=True)