Compare commits

...

3 commits

Author SHA1 Message Date
Bruno BELANYI 6f643052e1 home: wm: i3: show notification on toggling mute
All checks were successful
continuous-integration/drone/push Build is passing
2021-11-12 10:21:25 +01:00
Bruno BELANYI 119504d0b5 pkgs: change-audio: 0.1.2 -> 0.2.0
Allow muting microphone and speakers, with refactor to make it DRY.
2021-11-12 10:17:42 +01:00
Bruno BELANYI 2d7f01f035 pkgs: change-audio: 0.1.1 -> 0.1.2
Show if volume is currently muted.
2021-11-12 09:52:22 +01:00
3 changed files with 59 additions and 14 deletions

View file

@ -249,8 +249,8 @@ in
"XF86AudioLowerVolume" = "exec --no-startup-id ${changeAudio} down 5"; "XF86AudioLowerVolume" = "exec --no-startup-id ${changeAudio} down 5";
"Control+XF86AudioRaiseVolume" = "exec --no-startup-id ${changeAudio} up 1"; "Control+XF86AudioRaiseVolume" = "exec --no-startup-id ${changeAudio} up 1";
"Control+XF86AudioLowerVolume" = "exec --no-startup-id ${changeAudio} down 1"; "Control+XF86AudioLowerVolume" = "exec --no-startup-id ${changeAudio} down 1";
"XF86AudioMute" = "exec pamixer --toggle-mute"; "XF86AudioMute" = "exec --no-startup-id ${changeAudio} toggle";
"XF86AudioMicMute" = "exec pamixer --default-source --toggle-mute"; "XF86AudioMicMute" = "exec --no-startup-id ${changeAudio} toggle mic";
"XF86AudioPlay" = "exec playerctl play-pause"; "XF86AudioPlay" = "exec playerctl play-pause";
"XF86AudioNext" = "exec playerctl next"; "XF86AudioNext" = "exec playerctl next";

View file

@ -2,16 +2,61 @@
set -euo pipefail set -euo pipefail
if [ "$1" = "up" ]; then NOTIFY=(
notify-send
-u low
-h string:x-canonical-private-synchronous:change-audio
)
do_change_volume() {
if [ "$1" = "up" ]; then
upDown="-i" upDown="-i"
else else
upDown="-d" upDown="-d"
fi fi
pamixer --allow-boost "$upDown" "$2" pamixer --allow-boost "$upDown" "$2"
newVolume="$(pamixer --get-volume || true)" newVolume="$(pamixer --get-volume || true)"
[ "$(pamixer --get-volume-human)" = "muted" ] && isMuted=true
notify-send -u low \ MSG="Set volume to $newVolume%"
-h string:x-canonical-private-synchronous:change-audio \ if [ "${isMuted:-false}" = true ]; then
MSG="$MSG (muted)"
fi
"${NOTIFY[@]}" \
-h "int:value:$newVolume" \ -h "int:value:$newVolume" \
-- "Set volume to $newVolume%" -- "$MSG"
}
do_toggle() {
args=()
if [ "${2:-audio}" = mic ]; then
args+=(--default-source)
MSG="Toggled microphone"
else
MSG="Toggled audio output"
fi
pamixer "${args[@]}" --toggle-mute
if [ "$(pamixer "${args[@]}" --get-mute)" = true ]; then
MSG="$MSG (muted)"
else
MSG="$MSG (unmuted)"
fi
"${NOTIFY[@]}" -- "$MSG"
}
case "$1" in
up|down)
do_change_volume "$@"
;;
toggle)
do_toggle "$@"
;;
*)
echo "No suche option '$1'" >&2
exit 1
;;
esac

View file

@ -1,7 +1,7 @@
{ lib, libnotify, makeWrapper, pamixer, shellcheck, stdenvNoCC }: { lib, libnotify, makeWrapper, pamixer, shellcheck, stdenvNoCC }:
stdenvNoCC.mkDerivation rec { stdenvNoCC.mkDerivation rec {
pname = "change-audio"; pname = "change-audio";
version = "0.1.1"; version = "0.2.0";
src = ./change-audio; src = ./change-audio;