From 9d44898fb3c2dbac189f5fa7b9b1d789937f348c Mon Sep 17 00:00:00 2001 From: David Luevano Alvarado <55825613+luevano@users.noreply.github.com> Date: Fri, 25 Dec 2020 21:52:30 -0700 Subject: Better "now playing" module --- .config/bspwm/bspwmrc | 1 + .config/polybar/config | 1 + .config/polybar/main.ini | 2 +- .config/sxhkd/sxhkdrc | 2 +- .local/bin/pctl_status | 30 ++++++++++++ .local/bin/statusbar/player_mpris_module | 21 +++++---- .local/bin/statusbar/player_mpris_zscroll_module | 60 ++++++++++++++++++++++++ 7 files changed, 107 insertions(+), 10 deletions(-) create mode 100755 .local/bin/pctl_status create mode 100755 .local/bin/statusbar/player_mpris_zscroll_module diff --git a/.config/bspwm/bspwmrc b/.config/bspwm/bspwmrc index 87dd58c..05da177 100755 --- a/.config/bspwm/bspwmrc +++ b/.config/bspwm/bspwmrc @@ -95,6 +95,7 @@ bspc config presel_feedback_color $COLOR_BLUE # Rules. bspc rule -a *:*:"Picture-in-Picture" state=floating rectangle=640x360+640+360 +bspc rule -a Peek:*:* state=floating # bspc rule -a Gimp desktop='^8' state=floating follow=on # bspc rule -a Chromium desktop='^2' # bspc rule -a mplayer2 state=floating diff --git a/.config/polybar/config b/.config/polybar/config index 334bd3c..65d0cdc 100644 --- a/.config/polybar/config +++ b/.config/polybar/config @@ -33,6 +33,7 @@ include-file = $XDG_CONFIG_HOME/polybar/eth.ini include-file = $XDG_CONFIG_HOME/polybar/wlan.ini include-file = $XDG_CONFIG_HOME/polybar/dunst.ini include-file = $XDG_CONFIG_HOME/polybar/player_mpris.ini +include-file = $XDG_CONFIG_HOME/polybar/player_mpris_zscroll.ini # Other modules that came by default on the example config. # The ones that I configured are on separate ini files. diff --git a/.config/polybar/main.ini b/.config/polybar/main.ini index d66ffb8..752d2ff 100644 --- a/.config/polybar/main.ini +++ b/.config/polybar/main.ini @@ -4,7 +4,7 @@ monitor = ${env:MAINMON:HDMI-0} modules-left=bspwm xwindow modules-center= -modules-right=player_mpris xkeyboard cpu memory pulseaudio date dunst powermenu +modules-right=player_mpris_zscroll xkeyboard cpu memory pulseaudio date dunst powermenu # tray-position = right # tray-padding = 2 diff --git a/.config/sxhkd/sxhkdrc b/.config/sxhkd/sxhkdrc index 044ce1d..987bb60 100644 --- a/.config/sxhkd/sxhkdrc +++ b/.config/sxhkd/sxhkdrc @@ -7,7 +7,7 @@ super + Return $TERMINAL # Read after releasing 'd' because as soon # as dmenu runs it listens for kb presses. -super + @d +super + d dmenu_run -fn "Noto Sans Mono:size=12" -nb "$(xresource background)" -nf "$(xresource foreground)" -sb "$(xresource color4)" -sf "$(xresource color0)" super + Escape pkill -USR1 -x sxhkd diff --git a/.local/bin/pctl_status b/.local/bin/pctl_status new file mode 100755 index 0000000..0eccfb8 --- /dev/null +++ b/.local/bin/pctl_status @@ -0,0 +1,30 @@ +#!/bin/bash + +playerctl_status=$(playerctl status 2>/dev/null) +exit_code=$? + +if [ $exit_code -eq 0 ]; then + status=$playerctl_status +else + status="NPF" +fi + +case $1 in + status) + echo "$status" + ;; + text) + artist="$(playerctl metadata artist 2>/dev/null)" + title="$(playerctl metadata title 2>/dev/null)" + + if [ "$status" = "Stopped" ]; then + echo "%{F$(xresource color8)}No music playing%{F}" + elif [ "$status" = "Paused" ]; then + echo "%{F$(xresource color8)}$artist - $title%{F}" + elif [ "$status" = "NPF" ]; then + echo "%{F$(xresource color8)}No player found%{F}" + else + echo "$artist - $title" + fi + ;; +esac diff --git a/.local/bin/statusbar/player_mpris_module b/.local/bin/statusbar/player_mpris_module index 3701cbf..fef6bb8 100755 --- a/.local/bin/statusbar/player_mpris_module +++ b/.local/bin/statusbar/player_mpris_module @@ -1,15 +1,20 @@ #!/bin/sh +# This is a static status module, for a dynamic one, there is the option +# with zscroll. + +icon=" " + show_panel (){ # Needs to send to /dev/null for the actual else case. player_status=$(playerctl status 2> /dev/null) if [ "$player_status" = "Playing" ]; then - echo " $(playerctl metadata artist) - $(playerctl metadata title)" + echo "$icon $(playerctl metadata artist) - $(playerctl metadata title)" elif [ "$player_status" = "Paused" ]; then - echo "%{F$(xresource color8)} $(playerctl metadata artist) - $(playerctl metadata title)%{F-}" + echo "%{F$(xresource color8)}$icon $(playerctl metadata artist) - $(playerctl metadata title)%{F-}" else - echo "%{F$(xresource color8)} (nothing playing)" + echo "%{F$(xresource color8)}$icon (nothing playing)" fi } @@ -21,9 +26,9 @@ send_notification (){ title="$(playerctl metadata title)" if [ $album = "\n"]; then - notify-send " $artist - $album" "$title" + notify-send "$icon $artist - $album" "$title" else - notify-send " $artist" "$title" + notify-send "$icon $artist" "$title" fi elif [ "$player_status" = "Paused" ]; then artist="$(playerctl metadata artist)" @@ -31,12 +36,12 @@ send_notification (){ title="$(playerctl metadata title)" if [ $album = "\n"]; then - notify-send " (Paused) $artist - $album" "$title" + notify-send "$icon (Paused) $artist - $album" "$title" else - notify-send " (Paused) $artist" "$title" + notify-send "$icon (Paused) $artist" "$title" fi else - notify-send " Nothing playing" + notify-send "$icon Nothing playing" fi } diff --git a/.local/bin/statusbar/player_mpris_zscroll_module b/.local/bin/statusbar/player_mpris_zscroll_module new file mode 100755 index 0000000..5930182 --- /dev/null +++ b/.local/bin/statusbar/player_mpris_zscroll_module @@ -0,0 +1,60 @@ +#!/bin/sh + +# This is a static status module, for a dynamic one, there is the option +# with zscroll. + +icon=" " +length=50 +delay=0.1 +b_padding=$icon +a_padding="" +p_padding="  |  " + +show_panel (){ + zscroll -d $delay -l $length \ + -M "pctl_status status" \ + -m "Playing" "--scroll-padding '$p_padding' --scroll 1" \ + -m "Paused" "--scroll 0" \ + -m "Stopped" "--scroll 0" \ + -m "NRP" "--scroll 0" \ + -u true "pctl_status text" & + + wait +} + +send_notification (){ + player_status=$(playerctl status 2> /dev/null) + if [ "$player_status" = "Playing" ]; then + artist="$(playerctl metadata artist)" + album="$(playerctl metadata album)" + title="$(playerctl metadata title)" + + if [ $album = "\n"]; then + notify-send "$icon $artist - $album" "$title" + else + notify-send "$icon $artist" "$title" + fi + elif [ "$player_status" = "Paused" ]; then + artist="$(playerctl metadata artist)" + album="$(playerctl metadata album)" + title="$(playerctl metadata title)" + + if [ $album = "\n"]; then + notify-send "$icon (Paused) $artist - $album" "$title" + else + notify-send "$icon (Paused) $artist" "$title" + fi + else + notify-send "$icon Nothing playing" + fi + +} + +case $1 in + show) + show_panel + ;; + notify) + send_notification + ;; +esac -- cgit v1.2.3-54-g00ecf