From 9e6e656fa87eb9e5ae45a790bbd427b88de5b186 Mon Sep 17 00:00:00 2001 From: Pavle Portic Date: Wed, 14 Jun 2023 21:30:16 +0200 Subject: [PATCH] Add device filter support to pulsectl popup menu --- bumblebee_status/modules/core/pulsectl.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/bumblebee_status/modules/core/pulsectl.py b/bumblebee_status/modules/core/pulsectl.py index 43429135..701f6ef4 100644 --- a/bumblebee_status/modules/core/pulsectl.py +++ b/bumblebee_status/modules/core/pulsectl.py @@ -13,6 +13,8 @@ * pulsectl.autostart: If set to 'true' (default is 'false'), automatically starts the pulsectl daemon if it is not running * pulsectl.percent_change: How much to change volume by when scrolling on the module (default is 2%) * pulsectl.limit: Upper limit for setting the volume (default is 0%, which means 'no limit') + * pulsectl.popup-filter: Comma-separated list of device strings (if the device name contains it) to exclude + from the default device popup menu (e.g. Monitor for sources) * pulsectl.showbars: 'true' for showing volume bars, requires --markup=pango; 'false' for not showing volume bars (default) * pulsectl.showdevicename: If set to 'true' (default is 'false'), the currently selected default device is shown. @@ -70,6 +72,11 @@ def __init__(self, config, theme, type): self.parameter("percent_change", "2%").strip("%"), 0, 100 ) self.__limit = util.format.asint(self.parameter("limit", "0%").strip("%"), 0) + popup_filter_param = self.parameter("popup-filter", []) + if popup_filter_param == '': + self.__popup_filter = [] + else: + self.__popup_filter = util.format.aslist(popup_filter_param) events = [ { @@ -103,8 +110,8 @@ def display(self, _): res = f"{res} {util.graph.hbar(self.__volume*100)}" if self.__show_device_name: - friendly_name = self.parameter(self.__devicename, self.__devicename) - icon = self.parameter("icon." + self.__devicename, "") + friendly_name = self.parameter(self.__devicename.lower(), self.__devicename) + icon = self.parameter("icon." + self.__devicename.lower(), "") res = ( icon + " " + friendly_name + " | " + res if icon != "" @@ -170,7 +177,12 @@ def update(self): def select_default_device_popup(self, widget): with pulsectl.Pulse(self.id) as pulse: - devs = pulse.sink_list() if self.__type == "sink" else pulse.source_list() + if self.__type == "sink": + devs = pulse.sink_list() + else: + devs = pulse.source_list() + + devs = filter(lambda dev: not any(filter in dev.description for filter in self.__popup_filter), devs) menu = util.popup.menu(self.__config) for dev in devs: menu.add_menuitem(