vincentbernat.i3wm-configur.../bin/rofi-mediaplayer
Vincent Bernat d9aafa54a4 rofi-mediaplayer: grab keyboard as soon as possible
Otherwise, we may miss the shortcut input. With -no-lazy-grab, rofi
grabs the keyboard early and wait for half a second before giving up.
Without, it will try for 0 second. So, if i3 still has the grab, it
will try again every millisecond for 5 seconds. However, this needs to
get scheduled after everything else, so in practice, this can take
some time. I get better results with -no-lazy-grab.

Also, we could use --release from i3. In this case, we are guaranteed
that rofi can grab the keyboard during the first try. But, after
trying a bit, I think this is still better with -no-lazy-grab: the
shell script needs to be executed, rofi needs to be executed. It's
better to do that while the user did not depress the key yet.
2021-07-23 20:27:22 +02:00

62 lines
2.1 KiB
Bash
Executable file

#!/bin/sh
# Media player menu with rofi
if [ -z "${ROFI_OUTSIDE}" ]; then
export mediaplayer=$1
export Mediaplayer=$(echo $1 | sed -E 's/(.)/\U\1/')
exec rofi -no-lazy-grab -show-icons -no-custom -modi m:$0 -show m \
-kb-select-1 Super+z \
-kb-select-2 Super+x \
-kb-select-3 Super+c \
-kb-select-4 Super+v \
-kb-select-5 Super+b \
-kb-select-6 Super+m \
-kb-select-7 Super+s
fi
case $ROFI_RETV in
0)
# Prompt
printf "\00prompt\037media player\n"
printf "\00message\037$...\n"
# Available actions
i=0
while read icon description
do
i=$((i+1))
printf "$description\00icon\037$icon\037info\037$i\n"
done <<EOF
go-previous Previous track
media-playback-start Play
media-playback-pause Pause
media-playback-stop Stop
go-next Next track
multimedia-volume-control Open mixer panel
com.spotify.Client Open ${Mediaplayer}
EOF
# Player status
status=$(playerctl -p $mediaplayer status)
case $status in
Playing|Paused)
title="$(playerctl -p $mediaplayer metadata xesam:title | sed -e 's/&/\&amp;/g' -e 's/</\&lt;/g')"
artist="$(playerctl -p $mediaplayer metadata xesam:artist | sed -e 's/&/\&amp;/g' -e 's/</\&lt;/g')"
status="$status <span weight='light'><i>${title} (${artist})</i></span>"
;;
esac
printf "\00message\037${status}\n"
;;
1)
case $ROFI_INFO in
1) playerctl -p $mediaplayer previous ;;
2) playerctl -p $mediaplayer play-pause ;;
3) playerctl -p $mediaplayer pause ;;
4) playerctl -p $mediaplayer stop ;;
5) playerctl -p $mediaplayer next ;;
6) i3-msg '[class="Pavucontrol"] focus' || i3-msg exec exec pavucontrol ;;
7) i3-msg '[class="'${Mediaplayer}'"] focus' || i3-msg exec exec spotify ;;
esac >&2
;;
esac