diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2024-03-05 01:24:07 -0800 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2024-03-05 01:24:07 -0800 |
commit | 95007a6eb03c495afcbcdfed09a48cf50b511374 (patch) | |
tree | 7c68d0a501295218bc39543f61c9d29ca4cd9b62 | |
parent | 71033afece74a138716e7013d1af06976d76c0f2 (diff) | |
download | panel-95007a6eb03c495afcbcdfed09a48cf50b511374.tar.gz panel-95007a6eb03c495afcbcdfed09a48cf50b511374.tar.xz |
add PipeWire volume module (using WirePlumber)
-rwxr-xr-x | panel.py | 21 |
1 files changed, 20 insertions, 1 deletions
@@ -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( |