Skip to content

Commit

Permalink
Merge pull request #988 from TheEdgeOfRage/pulsectl-filter
Browse files Browse the repository at this point in the history
Add device filter support to pulsectl popup menu
  • Loading branch information
tobi-wan-kenobi authored Sep 7, 2023
2 parents b9e45ca + 9e6e656 commit 9c5e30a
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions bumblebee_status/modules/core/pulsectl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 = [
{
Expand Down Expand Up @@ -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 != ""
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 9c5e30a

Please sign in to comment.