From c275ec857d5c1da766dace495b0a0100b0a418d2 Mon Sep 17 00:00:00 2001 From: meliurwen Date: Thu, 2 Jun 2022 19:21:17 +0200 Subject: [PATCH] Polybar: switched to pulseaudio module; bluetooth and temperature modules are loaded only when the respective devices are available --- polybar/.config/polybar/config | 11 +++++------ polybar/.config/polybar/launch.sh | 17 +++++++++++++++-- polybar/.config/polybar/scripts/mpv.sh | 2 +- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/polybar/.config/polybar/config b/polybar/.config/polybar/config index 6d46a8b..0e84f85 100644 --- a/polybar/.config/polybar/config +++ b/polybar/.config/polybar/config @@ -52,7 +52,7 @@ font-3 = "Material Wifi Signal Enhanced:style=Regular:weight=bold:size=10" #modules-left = i3 clementine mpv modules-left = i3 mpv modules-center = date -modules-right = temperature bluetooth wireless-network wired-network alsa battery +modules-right = ${env:POLY_MODR} separator = " " spacing = 0 @@ -114,18 +114,17 @@ ramp-capacity-2 =  ramp-capacity-3 =  ramp-capacity-4 =  -[module/alsa] -type = internal/alsa +[module/pulseaudio] +type = internal/pulseaudio +use-ui-max = false interval = 5 format-volume = format-muted = label-muted =  label-muted-foreground = ${color.grey} -; You cannot customize click actions on official modules? Really?!? >:( -;click-right = exec pavucontrol +click-right = exec pavucontrol -; Only applies if is used ramp-volume-0 =  ramp-volume-1 =  ramp-volume-2 =  diff --git a/polybar/.config/polybar/launch.sh b/polybar/.config/polybar/launch.sh index af647ec..713f7da 100755 --- a/polybar/.config/polybar/launch.sh +++ b/polybar/.config/polybar/launch.sh @@ -20,6 +20,8 @@ do done unset cycle +POLY_MODR="wireless-network wired-network pulseaudio battery" + NET_IFACES="$(ip link show | awk '/^[0-9]+:/ {sub(/:/,"",$2); print $2}')" for NET_IFACE in $NET_IFACES ; do case $NET_IFACE in @@ -34,13 +36,24 @@ if [ -d "$HWMON_MODULE" ]; then HWMON_BASEDIR="$(find "$HWMON_MODULE" -maxdepth 1 -type d -name 'hwmon*' | tail -n +2 | head -1)" POLY_HWMON="$HWMON_BASEDIR"/temp1_input unset HWMON_BASEDIR + POLY_MODR="temperature $POLY_MODR" fi unset HWMON_MODULE +# Skip if the folder doesn't exist (kernel module not loaded) or it's empty +if [ ! -d /sys/class/bluetooth ]; then + : +elif [ -z "$(ls -A /sys/class/bluetooth)" ]; then + : +else + POLY_MODR="bluetooth $POLY_MODR" +fi + if type "xrandr"; then for m in $(xrandr --query | grep " connected" | cut -d" " -f1); do - POLY_WLP=$POLY_WLP POLY_ENP=$POLY_ENP POLY_HWMON=$POLY_HWMON MONITOR=$m polybar main -c "$HOME/.config/polybar/config" & + POLY_WLP=$POLY_WLP POLY_ENP=$POLY_ENP POLY_HWMON=$POLY_HWMON POLY_MODR="$POLY_MODR" MONITOR=$m \ + polybar main -c "$HOME/.config/polybar/config" & done fi -unset POLY_WLP POLY_ENP POLY_HWMON +unset POLY_WLP POLY_ENP POLY_HWMON POLY_MODR diff --git a/polybar/.config/polybar/scripts/mpv.sh b/polybar/.config/polybar/scripts/mpv.sh index 29bedcd..93e0f42 100755 --- a/polybar/.config/polybar/scripts/mpv.sh +++ b/polybar/.config/polybar/scripts/mpv.sh @@ -43,7 +43,7 @@ while [ $# -gt 0 ]; do case $COMMAND in "time-pos" | "time-remaining" | "duration" | "media-title" | "playlist-pos" | "playlist-pos-1" | "playlist-count" | "core-idle" | "play-pause-btn") if [ "$COMMAND" = "play-pause-btn" ]; then - COMMAND="core-idle" + COMMAND="core-idle" fi API_OUTPUT=$(printf '{ "command": ["get_property", "%s"] }\n' "$COMMAND" | socat - "$MPV_SOCKET_PATH") ;;