From 71d4005a8ab9d0d70ceb1068136cc7e84134b385 Mon Sep 17 00:00:00 2001 From: Ohad Livne Date: Wed, 4 Jun 2025 22:45:07 +0300 Subject: [PATCH] Use ALSA for audio control and status --- .config/setup/01-install-packages.sh | 1 + .config/sway/config | 6 +++--- .local/bin/print-status | 9 +++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.config/setup/01-install-packages.sh b/.config/setup/01-install-packages.sh index 4fcc0af..8bae299 100755 --- a/.config/setup/01-install-packages.sh +++ b/.config/setup/01-install-packages.sh @@ -1,6 +1,7 @@ #! /usr/bin/sh DEB_PKGS="\ +alsa-utils \ audacity \ borgbackup \ curl \ diff --git a/.config/sway/config b/.config/sway/config index 67edc61..5c10302 100644 --- a/.config/sway/config +++ b/.config/sway/config @@ -232,9 +232,9 @@ bindsym Mod4+4 exec fcitx5-remote -s keyboard-fr # bindsym XF86TouchpadToggle exec swaymsg input type:touchpad events toggle enabled disabled -bindsym XF86AudioMute exec pactl set-sink-mute @DEFAULT_SINK@ toggle -bindsym XF86AudioLowerVolume exec pactl set-sink-volume @DEFAULT_SINK@ -5% -bindsym XF86AudioRaiseVolume exec pactl set-sink-volume @DEFAULT_SINK@ +5% +bindsym XF86AudioMute exec amixer set Master toggle +bindsym XF86AudioLowerVolume exec amixer set Master 5%- +bindsym XF86AudioRaiseVolume exec amixer set Master 5%+ # # Start a password manager in the scratchpad diff --git a/.local/bin/print-status b/.local/bin/print-status index bc818d5..c8ad8e6 100755 --- a/.local/bin/print-status +++ b/.local/bin/print-status @@ -3,12 +3,13 @@ today=$(date +'%Y-%m-%d') now=$(date +'%H:%M:%S') -audio_mute=$(pactl get-sink-mute @DEFAULT_SINK@ | awk '{print $2}') -audio_volume=$(pactl get-sink-volume @DEFAULT_SINK@ | grep -o '[0-9]\+%' | head -n 1 | tr -d %) +audio_state=$(amixer get Master | tail -n 1) +audio_volume=$(echo "$audio_state" | grep -o '[0-9]*%' | tr -d %) +audio_mute=$(echo "$audio_state" | grep -o '\[o.*\]' | tr -d \[\]) audio_symbol="❔" -if [ "${audio_mute}" = "yes" ]; then +if [ "${audio_mute}" = "off" ]; then audio_symbol="🔇" -elif [ "${audio_mute}" = "no" ]; then +elif [ "${audio_mute}" = "on" ]; then if [ "${audio_volume}" = "0" ]; then audio_symbol="🔈" elif [ "${audio_volume}" -lt 50 ]; then