From 95007a6eb03c495afcbcdfed09a48cf50b511374 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Tue, 5 Mar 2024 01:24:07 -0800 Subject: add PipeWire volume module (using WirePlumber) --- panel.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/panel.py b/panel.py index 93db494..4c9decd 100755 --- a/panel.py +++ b/panel.py @@ -462,6 +462,24 @@ class ModMem(ModInterval): percent = psutil.virtual_memory().percent self.out = Fmt.labelled('MEM', f'{percent:.0f}%%') +class ModPWVol(ModInterval): + def __init__(self, sink='@DEFAULT_AUDIO_SINK@', **kwargs): + super().__init__(**kwargs) + self.sink = sink + + def refresh(self): + res = subprocess.run( + ('wpctl', 'get-volume', self.sink), + stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True) + if (m := re.match('Volume: ([0-9.]*)( \[MUTED\])?', res.stdout)): + vol = float(m.group(1)) * 100 + buf = f'{vol:.0f}%%' + if m.group(2): + buf += ' [muted]' + else: + buf = Fmt.bg('#a03000', ' error ') + self.out = Fmt.labelled('VOL', buf) + class Panel: def __init__(self, *mods, max_paint_delay=0, width=1920, height=22): self.e_repaint = threading.Event() @@ -526,7 +544,8 @@ Panel( ModInputAvail( '/dev/input/by-id/usb-HID_Keyboard_HID_Keyboard-event-kbd', unavail_text='NO KEYBOARD'), - ModNetIf('wg.*', regex=True, label='wg*', interval=1), + ModNetIf('wg(?!0$).*', regex=True, label='wg*'), + ModPWVol(), ModCPU(interval=0.5), ModMem(interval=0.5), ModDate( -- cgit v1.2.3-70-g09d2