Replace mpc with strawberry

This commit is contained in:
Guillaume Dott 2026-09-03 11:10:59 +02:00
parent e234f9fc65
commit e3f59f7cad
5 changed files with 69 additions and 18 deletions

View File

@ -139,8 +139,8 @@ bindsym Shift+XF86AudioLowerVolume exec --no-startup-id "wpctl set-volume @DEFAU
bindsym XF86AudioMute exec --no-startup-id "pactl set-sink-mute @DEFAULT_SINK@ toggle && pkill -RTMIN+10 i3blocks"
# Media player controls
bindsym XF86AudioPlay exec --no-startup-id mpc toggle
bindsym XF86AudioNext exec --no-startup-id mpc next
bindsym XF86AudioPrev exec --no-startup-id mpc prev
bindsym XF86AudioPlay exec --no-startup-id "strawberry --play-pause && pkill -SIGRTMIN+12 i3blocks"
bindsym XF86AudioNext exec --no-startup-id "strawberry --next && pkill -SIGRTMIN+12 i3blocks"
bindsym XF86AudioPrev exec --no-startup-id "strawberry --previous && pkill -SIGRTMIN+12 i3blocks"
bindsym Print exec "flameshot gui"

4
i3blocks/multi/blocks/mpc.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
mpc | head -2 | tr '\n' ' ' | sed 's/#[^ ]*//' | tr -s ' '
echo

View File

@ -0,0 +1,41 @@
#!/bin/sh
metadata=$(busctl --user get-property org.mpris.MediaPlayer2.strawberry /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player Metadata 2>/dev/null)
if [ $? -ne 0 ]
then
echo "Strawberry not running"
exit 1
fi
if [ "$metadata" = "a{sv} 0" ]
then
echo "No song in playlist"
exit 2
fi
artist=$(echo $metadata | sed 's/^.*"xesam:albumArtist" as 1 "\([^"]\+\)".*$/\1/')
album=$(echo $metadata | sed 's/^.*"xesam:album" s "\([^"]\+\)".*$/\1/')
trackNumber=$(echo $metadata | sed 's/^.*"xesam:trackNumber" i \([0-9]\+\).*$/\1/')
title=$(echo $metadata | sed 's/^.*"xesam:title" s "\([^"]\+\)".*$/\1/')
length=$(echo $metadata | sed 's/^.*"mpris:length" x \([0-9]\+\)[0-9]\{6\}.*$/\1/')
position=$(busctl --user get-property org.mpris.MediaPlayer2.strawberry /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player Position | sed 's/^x \([0-9]\+\)[0-9]\{6\}$/\1/')
playback_status=$(busctl --user get-property org.mpris.MediaPlayer2.strawberry /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player PlaybackStatus | sed 's/^s "\(.\+\)"$/\1/')
if [ "$length" -ge 3600 ]
then
format="+%H:%M:%S"
else
format="+%M:%S"
fi
formatted_length=$(date --date=@$length --utc $format)
formatted_position=$(date --date=@$position --utc $format)
if [ "$playback_status" != "Playing" ]
then
printf "($playback_status) "
fi
echo "$artist - $album - $title ($trackNumber) [$formatted_position / $formatted_length]"

View File

@ -3,15 +3,15 @@ separator_block_width=10
markup=none
[mpc]
command=mpc | head -2 | tr '\n' ' ' | sed 's/#[^ ]*//' | tr -s ' '
command=./blocks/strawberry.sh
interval=5
signal=12
[volume]
[volume-pipewire]
label=VOL
instance=Master
interval=once
signal=10
[time]
command=date '+%Y-%m-%d %H:%M:%S'
[calendar]
interval=5
LABEL=

View File

@ -2,25 +2,31 @@ command=/usr/lib/i3blocks/$BLOCK_NAME
separator_block_width=10
markup=none
[bandwidth]
interval=5
[memory]
label=MEM
separator=false
interval=30
[bandwidth2]
interval=persist
markup=pango
LABEL=
[disk]
label=/
label=/
instance=/
separator=false
interval=30
[disk]
label=/home
label=/home
interval=30
[memory]
label=MEM
separator=false
interval=30
[cpu_usage]
label=CPU
label=CPU
interval=10
min_width=CPU: 100.00%
[calendar]
interval=5
LABEL=