[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
This commit is contained in:
tobi-wan-kenobi 2023-05-11 08:45:03 +02:00
parent e9696b2150
commit 14f19c897a
2 changed files with 29 additions and 4 deletions

View file

@ -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():

View file

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