From 14f19c897a5147f4a99f4928950d719f333e12b2 Mon Sep 17 00:00:00 2001 From: tobi-wan-kenobi Date: Thu, 11 May 2023 08:45:03 +0200 Subject: [PATCH] [modules/pulsectl] add default device selection re-enable functionality to add a popup that allows the user to select the default source/sink. fixes #965 --- bumblebee-status | 11 +++++++---- bumblebee_status/modules/core/pulsectl.py | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/bumblebee-status b/bumblebee-status index e714daa..a16c747 100755 --- a/bumblebee-status +++ b/bumblebee-status @@ -68,10 +68,13 @@ def handle_commands(config, update_lock): def handle_events(config, update_lock): while True: - line = sys.stdin.readline().strip(",").strip() - if line == "[": continue - logging.info("input event: {}".format(line)) - process_event(line, config, update_lock) + try: + line = sys.stdin.readline().strip(",").strip() + if line == "[": continue + logging.info("input event: {}".format(line)) + process_event(line, config, update_lock) + except Exception as e: + logging.error(e) def main(): diff --git a/bumblebee_status/modules/core/pulsectl.py b/bumblebee_status/modules/core/pulsectl.py index 9ea0642..901202a 100644 --- a/bumblebee_status/modules/core/pulsectl.py +++ b/bumblebee_status/modules/core/pulsectl.py @@ -35,6 +35,8 @@ Requires the following Python module: """ import pulsectl +import logging +import functools import core.module import core.widget @@ -45,6 +47,11 @@ import util.cli import util.graph import util.format +try: + import util.popup +except ImportError as e: + logging.warning("Couldn't import util.popup: %s. Popups won't work!", e) + class Module(core.module.Module): def __init__(self, config, theme, type): super().__init__(config, theme, core.widget.Widget(self.display)) @@ -161,6 +168,21 @@ class Module(core.module.Module): pulse.event_callback_set(self.process) pulse.event_listen() + 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() + menu = util.popup.menu() + for dev in devs: + menu.add_menuitem( + dev.description, + callback=functools.partial(self.__on_default_changed, dev), + ) + menu.show(widget) + + def __on_default_changed(self, dev): + with pulsectl.Pulse(self.id) as pulse: + pulse.default_set(dev) + def state(self, _): if self.__muted: return ["warning", "muted"]