From c373245cbc0285f62030530fed9ccbcdc4ab145f Mon Sep 17 00:00:00 2001 From: kento2 Date: Mon, 9 Feb 2026 06:56:48 +0100 Subject: [PATCH] volume in bar --- files/.config/dk/sxhkdrc | 4 ++-- files/.local/bin/bar.sh | 2 +- files/.local/bin/vol | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100755 files/.local/bin/vol diff --git a/files/.config/dk/sxhkdrc b/files/.config/dk/sxhkdrc index 8bafc9d..5757ab1 100644 --- a/files/.config/dk/sxhkdrc +++ b/files/.config/dk/sxhkdrc @@ -71,9 +71,9 @@ super + {_,shift + }{c,v} # volume keys {XF86AudioRaiseVolume,XF86AudioLowerVolume} - pactl set-sink-volume @DEFAULT_SINK@ {+,-}5% + vol {+,-} {XF86AudioMute,XF86AudioMicMute} - pactl set-{sink,source}-mute @DEFAULT_{SINK,SOURCE}@ toggle + vol {.,!} # media keys super + {y,less,greater} diff --git a/files/.local/bin/bar.sh b/files/.local/bin/bar.sh index e5e1799..c4bddf0 100755 --- a/files/.local/bin/bar.sh +++ b/files/.local/bin/bar.sh @@ -40,7 +40,7 @@ battery() volume() { - vol="$(amixer sget Master | awk -F"[][]" '/(Mono|Left):/ { print $2 }')" + vol="$(pactl get-sink-volume @DEFAULT_SINK@ | grep -oE '[1-9]+%' | head -n1)" echo "V vol: ${vol}" } diff --git a/files/.local/bin/vol b/files/.local/bin/vol new file mode 100755 index 0000000..5a5f89e --- /dev/null +++ b/files/.local/bin/vol @@ -0,0 +1,36 @@ +#!/bin/sh + +get_vol() { + pactl get-sink-volume @DEFAULT_SINK@ | grep -oE -m 1 '[1-9]+%' | head -n1 +} + +update_bar() { + test -e /tmp/bar.fifo || return 0 + perc="$(get_vol)" + echo "V vol: ${perc}" >> /tmp/bar.fifo +} + +case "$1" in + +) + pactl set-sink-volume @DEFAULT_SINK@ +5% + update_bar + ;; + -) + pactl set-sink-volume @DEFAULT_SINK@ -5% + update_bar + ;; + .) + pactl set-sink-mute @DEFAULT_SINK@ toggle + ;; + !) + pactl set-source-mute @DEFAULT_SOURCE@ toggle + ;; + *) + { + echo "usage: $0 +/-/./!" + echo ". to toggle output" + echo "! to toggle mic" + } >&2 + exit 1 + ;; +esac