Multimonitor audio control.

This commit is contained in:
Bartek Stalewski 2021-08-20 19:38:24 +02:00
parent 52cf8a7385
commit c6ce6ef251
3 changed files with 43 additions and 20 deletions

View File

@ -37,6 +37,7 @@ onescreen() {
postrun() {
feh --no-fehbg --bg-scale ~/.local/share/wallpaper
{ killall dunst ; setsid -f dunst ;} >/dev/null 2>&1 # Restart dunst to ensure proper location on screen
kill -46 $(pidof dwmblocks)
}
# Get all possible displays
@ -47,7 +48,7 @@ screens=$(echo "$allposs" | awk '/ connected/ {print $1}')
# If there's only one screen
[ "$(echo "$screens" | wc -l)" -lt 2 ] &&
{ onescreen "$screens"; postrun; exit ;}
{ onescreen "$screens"; postrun; notify-send "💻 Only one screen detected."; exit ;}
# Get user choice including both and manual selection:
chosen=$(printf -- "home-1\\nhome-2\\n----\\n%s\\n----\\nmulti" "$screens" | rofi -dmenu -i -p "Select display arangement") &&

View File

@ -1,20 +1,42 @@
#!/bin/bash
if [ ${1} = "micmute" ]; then
case $(cat '/sys/devices/platform/thinkpad_acpi/leds/platform::micmute/brightness') in
1) echo 0 | sudo tee /sys/devices/platform/thinkpad_acpi/leds/platform::micmute/brightness;;
0) echo 1 | sudo tee /sys/devices/platform/thinkpad_acpi/leds/platform::micmute/brightness;;
esac
device=$(pamixer --list-sources | awk '/Raven/ {print $1}')
for i in $(pamixer --list-sources | grep -v Sources | awk '{print $1}'); do
pamixer --source $i -t
done
kill -46 $(pidof dwmblocks)
if [ $(xrandr | grep DisplayPort | grep ' connected' | wc -l) -gt 0 ]; then
sink=$(pamixer --list-sinks | awk '/HDMI/ {print $1}')
else
vol="$(pamixer --get-volume)"
[ $(echo $vol | wc -c) -lt 4 ] && svol=" ${vol}%%" || svol="${vol}%%"
[ $(pamixer --get-mute) = true ] && volinfo="^c#161616^^b#fd4285^\ue04f mute^d^" || volinfo="\ue050 ${svol}"
device=$(pamixer --list-sources | awk '/Raven/ {print $1}')
[ $(pamixer --source $device --get-mute) = true ] && micinfo="^c#161616^^b#fd4285^\ue02b^d^" || micinfo="\ue02a^d^"
printf "${micinfo} ${volinfo}"
sink=$(pamixer --list-sinks | awk '/HD Audio Controller/ {print $1}')
fi
case "${1}" in
"micmute")
case $(cat '/sys/devices/platform/thinkpad_acpi/leds/platform::micmute/brightness') in
1) echo 0 | sudo tee /sys/devices/platform/thinkpad_acpi/leds/platform::micmute/brightness;;
0) echo 1 | sudo tee /sys/devices/platform/thinkpad_acpi/leds/platform::micmute/brightness;;
esac
device=$(pamixer --list-sources | awk '/Raven/ {print $1}')
for i in $(pamixer --list-sources | grep -v Sources | awk '{print $1}'); do
pamixer --source $i -t
done
kill -46 $(pidof dwmblocks)
exit ;;
"volmute")
for i in $(pamixer --list-sinks | grep -v Sinks | awk '{print $1}'); do
pamixer --sink $i -t
done
kill -46 $(pidof dwmblocks)
exit ;;
"increase")
pamixer --sink $sink --allow-boost -i 5
kill -46 $(pidof dwmblocks)
exit ;;
"decrease")
pamixer --sink $sink --allow-boost -d 5
kill -46 $(pidof dwmblocks)
exit ;;
esac
vol="$(pamixer --sink $sink --get-volume)"
[ $(echo $vol | wc -c) -lt 4 ] && svol=" ${vol}%%" || svol="${vol}%%"
[ $(pamixer --sink $sink --get-mute) = true ] && volinfo="^c#161616^^b#fd4285^\ue04f mute^d^" || volinfo="\ue050 ${svol}"
device=$(pamixer --list-sources | awk '/Raven/ {print $1}')
[ $(pamixer --source $device --get-mute) = true ] && micinfo="^c#161616^^b#fd4285^\ue02b^d^" || micinfo="\ue02a^d^"
printf "${micinfo} ${volinfo}"

View File

@ -138,10 +138,10 @@ static Key keys[] = {
{ MODKEY, XK_period, focusmon, {.i = +1 } },
{ SHTKEY, XK_comma, tagmon, {.i = -1 } },
{ SHTKEY, XK_period, tagmon, {.i = +1 } },
{ 0, XF86XK_AudioMute, spawn, SHCMD("pamixer -t; kill -46 $(pidof dwmblocks)") },
{ 0, XF86XK_AudioMute, spawn, SHCMD("sb-volume volmute") },
{ 0, XF86XK_AudioMicMute, spawn, SHCMD("sb-volume micmute") },
{ 0, XF86XK_AudioRaiseVolume, spawn, SHCMD("pamixer --allow-boost -i 5; kill -46 $(pidof dwmblocks)") },
{ 0, XF86XK_AudioLowerVolume, spawn, SHCMD("pamixer --allow-boost -d 5; kill -46 $(pidof dwmblocks)") },
{ 0, XF86XK_AudioRaiseVolume, spawn, SHCMD("sb-volume increase") },
{ 0, XF86XK_AudioLowerVolume, spawn, SHCMD("sb-volume decrease") },
{ 0, XF86XK_MonBrightnessUp, spawn, SHCMD("sudo xbacklight -inc 10") },
{ 0, XF86XK_MonBrightnessDown, spawn, SHCMD("sudo xbacklight -dec 10") },
};