Merge branch '917-event-based-pulseaudio'

fixes #917
This commit is contained in:
tobi-wan-kenobi 2022-09-09 08:25:23 +02:00
commit 72a888748e
3 changed files with 59 additions and 9 deletions

View file

@ -33,12 +33,18 @@ Requires the following executable:
"""
import re
import os
import time
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 +109,36 @@ 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)
try:
proc = subprocess.Popen("pactl subscribe",
stdout = subprocess.PIPE,
stderr = subprocess.STDOUT,
shell = True
)
except:
return
while threading.main_thread().is_alive():
r, w, e = select.select([proc.stdout], [], [], 1)
if not (r or w or e):
self.update2()
core.event.trigger("update", [self.id], redraw_only=True)
core.event.trigger("draw")
continue # timeout
# whateve we got, use it
self.update2()
core.event.trigger("update", [self.id], redraw_only=True)
core.event.trigger("draw")
os.set_blocking(proc.stdout.fileno(), False)
proc.stdout.read()
os.set_blocking(proc.stdout.fileno(), True)
def set_volume(self, amount):
util.cli.execute(
"pactl set-{}-{} @DEFAULT_{}@ {}".format(
@ -200,6 +236,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"