Add device filter support to pulsectl popup menu

This commit is contained in:
Pavle Portic 2023-06-14 21:30:16 +02:00
parent b9e45ca994
commit 9e6e656fa8
No known key found for this signature in database
GPG key ID: 66AD4BA646FBC0D2

View file

@ -13,6 +13,8 @@ Parameters:
* pulsectl.autostart: If set to 'true' (default is 'false'), automatically starts the pulsectl daemon if it is not running * 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.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.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; * pulsectl.showbars: 'true' for showing volume bars, requires --markup=pango;
'false' for not showing volume bars (default) 'false' for not showing volume bars (default)
* pulsectl.showdevicename: If set to 'true' (default is 'false'), the currently selected default device is shown. * pulsectl.showdevicename: If set to 'true' (default is 'false'), the currently selected default device is shown.
@ -70,6 +72,11 @@ class Module(core.module.Module):
self.parameter("percent_change", "2%").strip("%"), 0, 100 self.parameter("percent_change", "2%").strip("%"), 0, 100
) )
self.__limit = util.format.asint(self.parameter("limit", "0%").strip("%"), 0) 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 = [ events = [
{ {
@ -103,8 +110,8 @@ class Module(core.module.Module):
res = f"{res} {util.graph.hbar(self.__volume*100)}" res = f"{res} {util.graph.hbar(self.__volume*100)}"
if self.__show_device_name: if self.__show_device_name:
friendly_name = self.parameter(self.__devicename, self.__devicename) friendly_name = self.parameter(self.__devicename.lower(), self.__devicename)
icon = self.parameter("icon." + self.__devicename, "") icon = self.parameter("icon." + self.__devicename.lower(), "")
res = ( res = (
icon + " " + friendly_name + " | " + res icon + " " + friendly_name + " | " + res
if icon != "" if icon != ""
@ -170,7 +177,12 @@ class Module(core.module.Module):
def select_default_device_popup(self, widget): def select_default_device_popup(self, widget):
with pulsectl.Pulse(self.id) as pulse: 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) menu = util.popup.menu(self.__config)
for dev in devs: for dev in devs:
menu.add_menuitem( menu.add_menuitem(