From d5d0d6a56cec31610e30b5b7ef73008cae78a85a Mon Sep 17 00:00:00 2001 From: tobi-wan-kenobi Date: Tue, 30 Aug 2022 21:38:48 +0200 Subject: [PATCH] [module/pulseaudio] somewhat experimental immediate update try to immediately update pulseaudio, if pactl subscribe exists & allows us to monitor update. see #913 --- bumblebee_status/modules/core/pulseaudio.py | 46 +++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/bumblebee_status/modules/core/pulseaudio.py b/bumblebee_status/modules/core/pulseaudio.py index 70acb01..22d5b07 100644 --- a/bumblebee_status/modules/core/pulseaudio.py +++ b/bumblebee_status/modules/core/pulseaudio.py @@ -33,12 +33,17 @@ Requires the following executable: """ import re +import os import logging import functools +import threading +import subprocess +import select import core.module import core.widget import core.input +import core.event import util.cli import util.graph @@ -103,6 +108,42 @@ class Module(core.module.Module): for event in events: core.input.register(self, button=event["button"], cmd=event["action"]) + self.__monitor = threading.Thread(target=self.__subscribe, args=()) + self.__monitor.start() + + def __subscribe(self): + self.update2() + core.event.trigger("update", [self.id], redraw_only=True) + core.event.trigger("draw") + try: + proc = subprocess.Popen("pactl subscribe", + stdout = subprocess.PIPE, + stderr = subprocess.PIPE, + shell = True + ) + except: + return + os.set_blocking(proc.stdout.fileno(), False) + while threading.main_thread().is_alive(): + r, w, e = select.select([proc.stdout], [], [], 1) + + if not (r or w or e): + continue # timeout + + line = 'test' + update = False + while line: + line = proc.stdout.readline().decode("ascii", errors="ignore") + if "client" in line: + update = True + + if update: + self.update2() + core.event.trigger("update", [self.id], redraw_only=True) + core.event.trigger("draw") + while proc.stdout.readline().decode("ascii", errors="ignore"): + pass + def set_volume(self, amount): util.cli.execute( "pactl set-{}-{} @DEFAULT_{}@ {}".format( @@ -200,6 +241,11 @@ class Module(core.module.Module): return output def update(self): + if self.__monitor.is_alive(): + return + self.update2() + + def update2(self): try: self._failed = False channel = "sinks" if self._channel == "sink" else "sources"