diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2024-03-09 01:12:38 -0800 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2024-03-09 01:12:38 -0800 |
commit | 67efb32979524fb5b5f3764ef058e40274bb5947 (patch) | |
tree | 380bc3d1ffa2d55e89f3b8c40c52eada7da0bbcf | |
parent | 5dd09b56750552463af37e71aed18bb2e32c8900 (diff) | |
download | panel-67efb32979524fb5b5f3764ef058e40274bb5947.tar.gz panel-67efb32979524fb5b5f3764ef058e40274bb5947.tar.xz |
add colour and optional limit to volume
-rwxr-xr-x | panel.py | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -465,10 +465,12 @@ class ModMem(ModInterval): self.out = Fmt.labelled('MEM', f'{percent:.0f}%%') class ModPWVol(ModInterval): - def __init__(self, sink='@DEFAULT_AUDIO_SINK@', step='0.05', **kwargs): + def __init__(self, sink='@DEFAULT_AUDIO_SINK@', step='0.05', limit=None, + **kwargs): super().__init__(**kwargs) self.sink = sink self.step = step + self.limit = limit def refresh(self): res = subprocess.run( @@ -477,8 +479,9 @@ class ModPWVol(ModInterval): 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]' + buf = (Fmt.fg('#777777', buf + ' [muted]') if m.group(2) + else Fmt.fg('#ff4000', buf) if vol > 100 + else buf) else: buf = Fmt.bg('#a03000', ' error ') @@ -494,7 +497,10 @@ class ModPWVol(ModInterval): if cmd == 'toggle-mute': subprocess.run(('wpctl', 'set-mute', self.sink, 'toggle')) elif cmd.startswith('set'): - subprocess.run(('wpctl', 'set-volume', self.sink, cmd[4:])) + args = ('wpctl', 'set-volume', self.sink, cmd[4:]) + if self.limit: + args = (*args, '-l', str(self.limit)) + subprocess.run(args) self.refresh() self.repaint() @@ -563,7 +569,7 @@ Panel( '/dev/input/by-id/usb-HID_Keyboard_HID_Keyboard-event-kbd', unavail_text='NO KEYBOARD'), ModNetIf('wg(?!0$).*', regex=True, label='wg*'), - ModPWVol(), + ModPWVol(limit=1.5), ModCPU(interval=0.5), ModMem(interval=0.5), ModDate( |