From 564f9ef0be6140afabc239cea6a7c30ab65be75b Mon Sep 17 00:00:00 2001 From: Cian Bagshaw Date: Thu, 16 Feb 2023 00:26:01 +0000 Subject: [PATCH] Improved and expanded volume manipulation - Replaced .local/bin/sb-volume with .local/bin/gvol, my own simpler script - Allowed for manipulation of microphone volume also - Allowed for both volumes to be muted/unmuted --- .config/i3/config | 12 ++++-- .config/i3blocks/config | 11 +++-- .local/bin/gvol | 19 +++++++++ .local/bin/sb-volume | 91 ----------------------------------------- 4 files changed, 35 insertions(+), 98 deletions(-) create mode 100755 .local/bin/gvol delete mode 100755 .local/bin/sb-volume diff --git a/.config/i3/config b/.config/i3/config index 4b01e9e..212b951 100755 --- a/.config/i3/config +++ b/.config/i3/config @@ -11,9 +11,13 @@ exec_always picom # drag floating windows with mouse+mod floating_modifier $mod -# increase/decrease volume -bindsym $mod+plus exec amixer sset 'Master' 5%+ && notify-send "volume +5%" -bindsym $mod+minus exec amixer sset 'Master' 5%- && notify-send "volume -5%" +# volumes +bindsym $mod+plus exec amixer set Master 5%+ && notify-send " $(gvol) (+5%)" +bindsym $mod+minus exec amixer set Master 5%- && notify-send " $(gvol) (-5%)" +bindsym $mod+Shift+plus exec amixer set Capture 5%+ && notify-send " $(gvol Capture) (+5%)" +bindsym $mod+Shift+minus exec amixer set Capture 5%- && notify-send " $(gvol Capture) (-5%)" +bindsym $mod+backslash exec amixer set Master toggle && notify-send " $(gvol)" +bindsym $mod+Shift+backslash exec amixer set Capture toggle && notify-send " $(gvol Capture)" # start a terminal bindsym $mod+Return exec alacritty @@ -30,7 +34,7 @@ gaps outer 2 gaps inner 4 bindsym $mod+bracketright gaps inner current plus 5 bindsym $mod+bracketleft gaps inner current minus 5 -bindsym $mod+BackSpace gaps inner current set 4 +bindsym $mod+BackSpace gaps inner current set 4 # change focus bindsym $mod+h focus left diff --git a/.config/i3blocks/config b/.config/i3blocks/config index c1ae755..34e4d05 100644 --- a/.config/i3blocks/config +++ b/.config/i3blocks/config @@ -7,10 +7,15 @@ interval=once command=uptime -p interval=60 -[volume] -command=sb-volume +[speaker volume] +command=gvol label= -interval=60 +interval=10 + +[mic volume] +command=gvol Capture +label= +interval=10 [memory] command=sb-memory diff --git a/.local/bin/gvol b/.local/bin/gvol new file mode 100755 index 0000000..e26c1bc --- /dev/null +++ b/.local/bin/gvol @@ -0,0 +1,19 @@ +#!/bin/sh +# gvol - get volume of alsa control using amixer, with $1 as the control name, +# defaults to Master if blank + +if [ $# == 1 ] +then + CONTROL=$1 +else + CONTROL=Master +fi + +VOL=$(amixer get $CONTROL | grep Left:) + +if [ $(echo $VOL | awk '{print $6}') == "[off]" ] +then + echo MUTE +else + echo $(echo $VOL | awk '{print $5}' | tr -d []) +fi diff --git a/.local/bin/sb-volume b/.local/bin/sb-volume deleted file mode 100755 index e8e1372..0000000 --- a/.local/bin/sb-volume +++ /dev/null @@ -1,91 +0,0 @@ -#!/usr/bin/env bash -# Copyright (C) 2014 Julien Bonjean -# Copyright (C) 2014 Alexander Keller - -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -#------------------------------------------------------------------------ - -# The second parameter overrides the mixer selection -# For PulseAudio users, eventually use "pulse" -# For Jack/Jack2 users, use "jackplug" -# For ALSA users, you may use "default" for your primary card -# or you may use hw:# where # is the number of the card desired -if [[ -z "$MIXER" ]] ; then - MIXER="default" - if command -v pulseaudio >/dev/null 2>&1 && pulseaudio --check ; then - # pulseaudio is running, but not all installations use "pulse" - if amixer -D pulse info >/dev/null 2>&1 ; then - MIXER="pulse" - fi - fi - [ -n "$(lsmod | grep jack)" ] && MIXER="jackplug" - MIXER="${2:-$MIXER}" -fi - -# The instance option sets the control to report and configure -# This defaults to the first control of your selected mixer -# For a list of the available, use `amixer -D $Your_Mixer scontrols` -if [[ -z "$SCONTROL" ]] ; then - SCONTROL="${BLOCK_INSTANCE:-$(amixer -D $MIXER scontrols | - sed -n "s/Simple mixer control '\([^']*\)',0/\1/p" | - head -n1 - )}" -fi - -# The first parameter sets the step to change the volume by (and units to display) -# This may be in in % or dB (eg. 5% or 3dB) -if [[ -z "$STEP" ]] ; then - STEP="${1:-5%}" -fi - -# AMIXER(1): -# "Use the mapped volume for evaluating the percentage representation like alsamixer, to be -# more natural for human ear." -NATURAL_MAPPING=${NATURAL_MAPPING:-0} -if [[ "$NATURAL_MAPPING" != "0" ]] ; then - AMIXER_PARAMS="-M" -fi - -#------------------------------------------------------------------------ - -capability() { # Return "Capture" if the device is a capture device - amixer $AMIXER_PARAMS -D $MIXER get $SCONTROL | - sed -n "s/ Capabilities:.*cvolume.*/Capture/p" -} - -volume() { - amixer $AMIXER_PARAMS -D $MIXER get $SCONTROL $(capability) -} - -format() { - - perl_filter='if (/.*\[(\d+%)\] (\[(-?\d+.\d+dB)\] )?\[(on|off)\]/)' - perl_filter+='{CORE::say $4 eq "off" ? "MUTE" : "' - # If dB was selected, print that instead - perl_filter+=$([[ $STEP = *dB ]] && echo '$3' || echo '$1') - perl_filter+='"; exit}' - output=$(perl -ne "$perl_filter") - echo "$LABEL$output" -} - -#------------------------------------------------------------------------ - -case $BLOCK_BUTTON in - 3) amixer $AMIXER_PARAMS -q -D $MIXER sset $SCONTROL $(capability) toggle ;; # right click, mute/unmute - 4) amixer $AMIXER_PARAMS -q -D $MIXER sset $SCONTROL $(capability) ${STEP}+ unmute ;; # scroll up, increase - 5) amixer $AMIXER_PARAMS -q -D $MIXER sset $SCONTROL $(capability) ${STEP}- unmute ;; # scroll down, decrease -esac - -volume | format -- 2.20.1