diff options
Diffstat (limited to 'polybar')
| -rw-r--r-- | polybar/.config/polybar/config.ini | 18 | ||||
| -rwxr-xr-x | polybar/.config/polybar/scripts/mic-status.sh | 29 | ||||
| -rwxr-xr-x | polybar/.config/polybar/scripts/mic.sh | 23 |
3 files changed, 40 insertions, 30 deletions
diff --git a/polybar/.config/polybar/config.ini b/polybar/.config/polybar/config.ini index b6d3693..5c35631 100644 --- a/polybar/.config/polybar/config.ini +++ b/polybar/.config/polybar/config.ini @@ -34,6 +34,8 @@ screenchange-reload = true pseudo-transparency = true [bar/main] +#dpi = ${xrdb:Xft.dpi:96} +dpi = 144 width = 100% height = 30pt @@ -65,7 +67,7 @@ module-margin = 0 modules-left = void space space date space space xwindow modules-center = xworkspaces -modules-right = cpu space space memory space separator space mic space space pulseaudio space separator space wlan space separator space battery space +modules-right = cpu space space memory space separator space mic space pulseaudio space separator space wlan space separator space battery space ;modules-right = pulseaudio cpu memory wlan battery date @@ -137,12 +139,14 @@ label-foreground = ${colors.foreground} [module/mic] type = custom/script -exec = ~/.config/polybar/scripts/mic.sh -interval = 1 # Update interval in seconds -format-foreground = ${colors.foreground} -format = <label> -label = %output% -click-left = ~/Scripts/mic.sh 1 +exec = ~/.config/polybar/scripts/mic-status.sh +tail = true +; Click to toggle mute +click-left = pactl set-source-mute @DEFAULT_SOURCE@ toggle +; Scroll up to increase volume +scroll-up = pactl set-source-volume @DEFAULT_SOURCE@ +5% +; Scroll down to decrease volume +scroll-down = pactl set-source-volume @DEFAULT_SOURCE@ -5% [module/pulseaudio] type = internal/pulseaudio diff --git a/polybar/.config/polybar/scripts/mic-status.sh b/polybar/.config/polybar/scripts/mic-status.sh new file mode 100755 index 0000000..aae580c --- /dev/null +++ b/polybar/.config/polybar/scripts/mic-status.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Function to check the default source's mute status +get_mic_status() { + # We look for the default source and check its 'Mute' field + STATUS=$(pactl get-source-mute @DEFAULT_SOURCE@ | awk '{print $2}') + + # Convert the volume to percentage + mic_percentage=$(pactl get-source-volume @DEFAULT_SOURCE@ | awk -F'/' '/Volume:/ {print $2}' | xargs) + + if [ "$STATUS" = "yes" ]; then + #echo " Muted" # Use your preferred icon/text + echo " $mic_percentage" + else + echo " $mic_percentage" + fi +} + +# 1. Output the status immediately on startup +get_mic_status + +# 2. Subscribe to 'change' events from PulseAudio +# The '-r' ensures backslashes aren't mangled +pactl subscribe | while read -r event; do + # Only refresh if the event involves a 'source' (microphone) + if echo "$event" | grep -q "source"; then + get_mic_status + fi +done diff --git a/polybar/.config/polybar/scripts/mic.sh b/polybar/.config/polybar/scripts/mic.sh deleted file mode 100755 index 2ed3165..0000000 --- a/polybar/.config/polybar/scripts/mic.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash - -mic_source=$(pactl info | grep "Default Source:" | awk '{print $3}') - -if [ "$1" == "1" ]; then - # Left mouse button clicked - toggle microphone mute status - pactl set-source-mute "$mic_source" toggle -fi - -# Get the microphone status (mute/unmute) -mic_status=$(pactl list sources | awk -v mic_source="$mic_source" '/^Source/ {in_source=0} $0 ~ ("Name: " mic_source) {in_source=1} in_source && /Mute:/ {print $2}') - -mic_volume=$(pactl list sources | awk -v mic_source="$mic_source" '/^Source/ {in_source=0} $0 ~ ("Name: " mic_source) {in_source=1} in_source && /Volume:/ {print $5}') - -# Convert the volume to percentage -mic_percentage=$(awk -v volume="$mic_volume" 'BEGIN {split(volume, a, "%"); print a[1]}') - -# Check the microphone status and set the output accordingly -if [ "$mic_status" == "yes" ]; then - echo " Muted" -else - echo " $mic_percentage%" -fi |
