From c97e7025e6cf7595ee04ff6177505f3c43e0a846 Mon Sep 17 00:00:00 2001 From: David Luevano Alvarado <55825613+luevano@users.noreply.github.com> Date: Thu, 24 Dec 2020 17:53:08 -0700 Subject: Create new player module --- .config/polybar/config | 2 +- .config/polybar/main.ini | 2 +- .config/polybar/pulseaudio.ini | 4 ++-- .local/bin/statusbar/player_mpris_module | 35 ++++++++++++++++++++++++++++++++ 4 files changed, 39 insertions(+), 4 deletions(-) create mode 100755 .local/bin/statusbar/player_mpris_module diff --git a/.config/polybar/config b/.config/polybar/config index 2c33cad..334bd3c 100644 --- a/.config/polybar/config +++ b/.config/polybar/config @@ -32,7 +32,7 @@ include-file = $XDG_CONFIG_HOME/polybar/filesystem.ini 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 # 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 0fbabb8..d66ffb8 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=xkeyboard cpu memory pulseaudio date dunst powermenu +modules-right=player_mpris xkeyboard cpu memory pulseaudio date dunst powermenu # tray-position = right # tray-padding = 2 diff --git a/.config/polybar/pulseaudio.ini b/.config/polybar/pulseaudio.ini index 3dfc7b4..016ac57 100644 --- a/.config/polybar/pulseaudio.ini +++ b/.config/polybar/pulseaudio.ini @@ -25,7 +25,7 @@ format-volume-underline = ${colors.green} # # format-muted = -format-muted-underline = ${colors.white} +format-muted-underline = ${colors.black-alt} # Available tokens: # %percentage% (default) @@ -36,7 +36,7 @@ label-volume = %percentage%% # %percentage% (default) # %decibels% label-muted =  (muted) -label-muted-foreground = ${colors.white} +label-muted-foreground = ${colors.black-alt} # Only applies if is used ramp-volume-0 =  diff --git a/.local/bin/statusbar/player_mpris_module b/.local/bin/statusbar/player_mpris_module new file mode 100755 index 0000000..42d6df6 --- /dev/null +++ b/.local/bin/statusbar/player_mpris_module @@ -0,0 +1,35 @@ +#!/bin/sh + +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)" + elif [ "$player_status" = "Paused" ]; then + echo "%{F$(xresource color8)} $(playerctl metadata artist) - $(playerctl metadata title)%{F-}" + else + echo "%{F$(xresource color8)} (nothing playing)" + fi +} + +send_notification (){ + artist="$(playerctl metadata artist)" + album="$(playerctl metadata album)" + title="$(playerctl metadata title)" + + if [ $album = "\n"]; then + notify-send "$artist - $album" "$title" + else + notify-send "$artist" "$title" + fi +} + +case $1 in + show) + show_panel + ;; + notify) + send_notification + ;; +esac -- cgit v1.2.3-54-g00ecf