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"]