From 02b587fe8273dfbe508fa04650860ee4729f9be7 Mon Sep 17 00:00:00 2001 From: Guilherme Rugai Freire <41879254+GRFreire@users.noreply.github.com> Date: Fri, 6 Aug 2021 12:42:18 -0300 Subject: [PATCH] add volume bar --- .config/qtile/autostart.sh | 3 +++ .config/xob/base.sh | 5 ++++ .config/xob/pulse-volume-watcher.py | 41 +++++++++++++++++++++++++++++ .config/xob/styles.cfg | 39 +++++++++++++++++++++++++++ .config/xob/volume.sh | 3 +++ 5 files changed, 91 insertions(+) create mode 100755 .config/xob/base.sh create mode 100755 .config/xob/pulse-volume-watcher.py create mode 100644 .config/xob/styles.cfg create mode 100755 .config/xob/volume.sh diff --git a/.config/qtile/autostart.sh b/.config/qtile/autostart.sh index 91d05b5..3ea4f66 100755 --- a/.config/qtile/autostart.sh +++ b/.config/qtile/autostart.sh @@ -17,3 +17,6 @@ nitrogen --restore # Start network manager applet (systray) nm-applet & + +# Start volume bar +~/.config/xob/volume.sh \ No newline at end of file diff --git a/.config/xob/base.sh b/.config/xob/base.sh new file mode 100755 index 0000000..eda9f85 --- /dev/null +++ b/.config/xob/base.sh @@ -0,0 +1,5 @@ +#!/bin/sh + +CONFIG="styles.cfg" + +([ "$1" = "-r" ] || [ "$1" = "--reload" ] && echo "$CONFIG" | entr -r "$0" "$2") || (python "$WATCHER" | xob -s "$1") \ No newline at end of file diff --git a/.config/xob/pulse-volume-watcher.py b/.config/xob/pulse-volume-watcher.py new file mode 100755 index 0000000..8297a45 --- /dev/null +++ b/.config/xob/pulse-volume-watcher.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 + +import sys +from pulsectl import Pulse, PulseLoopStop + +with Pulse() as pulse: + def callback(ev): + if ev.index == sink_index: raise PulseLoopStop + def current_status(sink): + return round(sink.volume.value_flat * 100), sink.mute == 1 + try: + sinks = {s.index:s for s in pulse.sink_list()} + if len(sys.argv) > 1: + # Sink index from command line argument if provided + sink_index = int(sys.argv[1]) + if not sink_index in sinks: + raise KeyError(f"Sink index {sink_index} not found in list of sinks.") + else: + # Automatic determination of default sink otherwise + default_sink_name = pulse.server_info().default_sink_name + try: + sink_index = next(index for index, sink in sinks.items() + if sink.name == default_sink_name) + except StopIteration: raise StopIteration("No default sink was found.") + + pulse.event_mask_set('sink') + pulse.event_callback_set(callback) + last_value, last_mute = current_status(sinks[sink_index]) + + while True: + pulse.event_listen() + sinks = {s.index:s for s in pulse.sink_list()} + value, mute = current_status(sinks[sink_index]) + if value != last_value or mute != last_mute: + print(str(value) + ('!' if mute else '')) + last_value, last_mute = value, mute + sys.stdout.flush() + + except Exception as e: + print(f"ERROR: {e}", file=sys.stderr) + diff --git a/.config/xob/styles.cfg b/.config/xob/styles.cfg new file mode 100644 index 0000000..ca03ea3 --- /dev/null +++ b/.config/xob/styles.cfg @@ -0,0 +1,39 @@ +volume = { + thickness = 20; + outline = 2; + border = 3; + padding = 1; + orientation = "vertical"; + + x = { + relative = 0; + offset = 24; + } + y = { + relative = 0.5; + offset = 0; + } + + color = { + normal = { + fg = "#49659C"; + bg = "#272A34"; + border = "#49659C"; + }; + alt = { + fg = "#363D54"; + bg = "#272A34"; + border = "#49659C"; + }; + overflow = { + fg = "#900000"; + bg = "#272A34"; + border = "#933333"; + }; + altoverflow = { + fg = "#900000"; + bg = "#272A34"; + border = "#49659C"; + }; + }; +}; diff --git a/.config/xob/volume.sh b/.config/xob/volume.sh new file mode 100755 index 0000000..fdb3b3f --- /dev/null +++ b/.config/xob/volume.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +WATCHER=pulse-volume-watcher.py ./base.sh $@ \ No newline at end of file