Skip to content

Commit

Permalink
polybar mic control
Browse files Browse the repository at this point in the history
  • Loading branch information
Anexen committed Nov 6, 2021
1 parent 8271db5 commit bf8c99a
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 18 deletions.
45 changes: 27 additions & 18 deletions home/.config/polybar/config
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ font-0 = "Sauce Code Pro Nerd Font:size=11;3"

enable-ipc = true
cursor-click = pointer
modules-left = menu i3 cpu memory
modules-right = wireless-network xkeyboard battery backlight volume date dunst powermenu
modules-left = menu i3 cpu memory wireless-network wired-network
modules-right = xkeyboard battery backlight volume microphone date dunst powermenu

# [module/power]
# type = custom/text
Expand All @@ -60,8 +60,8 @@ type = custom/ipc
initial = 1
format-background = ${color.bg}
format-foreground = ${color.fg}
hook-0 = echo "%{A1:dunstctl set-paused true && polybar-msg hook dunst 2:} %{A}"
hook-1 = echo "%{A1:dunstctl set-paused false && polybar-msg hook dunst 1:}%{F#e53935} %{F-}%{A}"
hook-0 = echo "%{A1:dunstctl set-paused true && polybar-msg hook dunst 2:} %{A}"
hook-1 = echo "%{A1:dunstctl set-paused false && polybar-msg hook dunst 1:}%{F#e53935} %{F-}%{A}"

[module/powermenu]
type = custom/menu
Expand Down Expand Up @@ -207,17 +207,24 @@ format-volume = <ramp-volume> <label-volume>
format-volume-padding = 1
format-volume-background = ${color.bg}
label-volume = %percentage%%
label-volume-font = 3
label-muted = ""
label-muted-background = ${color.bg}
label-muted = ""
label-muted-foreground = ${color.red}
label-muted-padding = 1
ramp-volume-0 = ""
ramp-volume-1 = ""
ramp-volume-2 = "奔 "
ramp-volume-3 = "奔 "
ramp-volume-4 = ""
ramp-volume-5 = ""
ramp-volume-6 = ""
ramp-volume-0 = 奄
ramp-volume-1 = 奄
ramp-volume-2 = 奔
ramp-volume-3 = 奔
ramp-volume-4 = 墳
ramp-volume-5 = 墳
ramp-volume-6 = 墳

[module/microphone]
type = custom/script
exec = ~/.config/polybar/mic.sh
tail = true
click-left = ~/.config/polybar/mic.sh --toggle &
scroll-up = ~/.config/polybar/mic.sh --increase &
scroll-down = ~/.config/polybar/mic.sh --decrease &

# [module/backlight]
# type = internal/xbacklight
Expand All @@ -242,10 +249,8 @@ battery = BAT0
adapter = AC

label-charging = %percentage%%
label-charging-font = 3
# label-discharging = %percentage%% (%time%, %consumption%)
label-discharging = %percentage%% (%time%)
label-discharging-font = 3

format-charging = <animation-charging> <label-charging>
format-charging-background = ${color.bg}
Expand Down Expand Up @@ -278,7 +283,6 @@ animation-charging-0 = 
type = internal/date
interval = 1
label = %time%
label-font = 3
label-padding = 1
label-background = ${color.bg}
time =  %H:%M
Expand All @@ -287,8 +291,13 @@ time-alt =  %a, %d %B
[module/wireless-network]
type = internal/network
interface = wlo1
label-connected =  %downspeed:3%
label-connected-padding = 1

label-connected = %upspeed:5%|%downspeed:5%
[module/wired-network]
type = internal/network
interface = eno2
label-connected =  %downspeed:3%
label-connected-padding = 1

# vim: ft=dosini commentstring=#\ %s
58 changes: 58 additions & 0 deletions home/.config/polybar/mic.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash

status() {
MUTED=$(pacmd list-sources | awk '/\*/,EOF {print}' | awk '/muted/ {print $2; exit}')

if [ "$MUTED" = "yes" ]; then
echo ' %{F#f00}%{F-} '
else
PERCENTAGE=$(pacmd list-sources | grep "\* index:" -A 7 | grep volume | awk -F/ '{print $2}' | tr -d ' ')
echo "${PERCENTAGE}"
fi
}

listen() {
status

LANG=EN; pactl subscribe | while read -r event; do
if echo "$event" | grep -q "source" || echo "$event" | grep -q "server"; then
status
fi
done
}

toggle() {
MUTED=$(pacmd list-sources | awk '/\*/,EOF {print}' | awk '/muted/ {print $2; exit}')
DEFAULT_SOURCE=$(pacmd list-sources | awk '/\*/,EOF {print $3; exit}')

if [ "$MUTED" = "yes" ]; then
pactl set-source-mute "$DEFAULT_SOURCE" 0
else
pactl set-source-mute "$DEFAULT_SOURCE" 1
fi
}

increase() {
DEFAULT_SOURCE=$(pacmd list-sources | awk '/\*/,EOF {print $3; exit}')
pactl set-source-volume "$DEFAULT_SOURCE" +5%
}

decrease() {
DEFAULT_SOURCE=$(pacmd list-sources | awk '/\*/,EOF {print $3; exit}')
pactl set-source-volume "$DEFAULT_SOURCE" -5%
}

case "$1" in
--toggle)
toggle
;;
--increase)
increase
;;
--decrease)
decrease
;;
*)
listen
;;
esac

0 comments on commit bf8c99a

Please sign in to comment.