summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2024-03-05 01:24:07 -0800
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2024-03-05 01:24:07 -0800
commit95007a6eb03c495afcbcdfed09a48cf50b511374 (patch)
tree7c68d0a501295218bc39543f61c9d29ca4cd9b62
parent71033afece74a138716e7013d1af06976d76c0f2 (diff)
downloadpanel-95007a6eb03c495afcbcdfed09a48cf50b511374.tar.gz
panel-95007a6eb03c495afcbcdfed09a48cf50b511374.tar.xz
add PipeWire volume module (using WirePlumber)
-rwxr-xr-xpanel.py21
1 files changed, 20 insertions, 1 deletions
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(