2021-07-21 07:31:27 +02:00
|
|
|
#!/bin/sh
|
2021-07-20 22:27:49 +02:00
|
|
|
|
|
|
|
# Media player menu with rofi
|
|
|
|
|
2021-07-21 02:17:04 +02:00
|
|
|
if [ -z "${ROFI_OUTSIDE}" ]; then
|
|
|
|
export mediaplayer=$1
|
2021-07-21 07:31:27 +02:00
|
|
|
export Mediaplayer=$(echo $1 | sed -E 's/(.)/\U\1/')
|
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
|
|
|
exec rofi -no-lazy-grab -show-icons -no-custom -modi m:$0 -show m \
|
2022-01-07 23:27:41 +01:00
|
|
|
-kb-custom-1 Super+z \
|
|
|
|
-kb-custom-2 Super+x \
|
|
|
|
-kb-custom-3 Super+c \
|
|
|
|
-kb-custom-4 Super+v \
|
|
|
|
-kb-custom-5 Super+b \
|
|
|
|
-kb-custom-6 Super+m \
|
2022-05-21 10:12:44 +02:00
|
|
|
-kb-custom-7 Super+s \
|
2022-01-07 23:29:56 +01:00
|
|
|
-kb-cancel Escape,Control+g,Super+Escape
|
2022-01-07 23:27:41 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $ROFI_RETV -ge 10 ] && [ $ROFI_RETV -le 28 ]; then
|
|
|
|
ROFI_INFO=$((ROFI_RETV-9))
|
|
|
|
ROFI_RETV=1
|
2021-07-21 02:17:04 +02:00
|
|
|
fi
|
|
|
|
|
2023-05-18 12:22:43 +02:00
|
|
|
playerctl="playerctl -p $mediaplayer"
|
|
|
|
|
2021-07-21 02:17:04 +02:00
|
|
|
case $ROFI_RETV in
|
|
|
|
0)
|
|
|
|
# Prompt
|
2021-07-21 07:31:27 +02:00
|
|
|
printf "\00prompt\037media player\n"
|
|
|
|
printf "\00message\037$...\n"
|
2022-01-07 23:27:41 +01:00
|
|
|
printf "\00use-hot-keys\037true\n"
|
2021-07-21 02:17:04 +02:00
|
|
|
|
2021-07-21 01:44:23 +02:00
|
|
|
# Available actions
|
2021-07-21 02:17:04 +02:00
|
|
|
i=0
|
2021-07-21 01:44:23 +02:00
|
|
|
while read icon description
|
|
|
|
do
|
2021-07-21 02:17:04 +02:00
|
|
|
i=$((i+1))
|
2021-07-21 07:31:27 +02:00
|
|
|
printf "$description\00icon\037$icon\037info\037$i\n"
|
2021-07-21 01:44:23 +02:00
|
|
|
done <<EOF
|
2021-12-27 11:43:01 +01:00
|
|
|
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
|
2023-05-18 12:22:43 +02:00
|
|
|
com.spotify.Client Open Spotify
|
2021-07-20 23:00:48 +02:00
|
|
|
EOF
|
2021-07-21 01:44:23 +02:00
|
|
|
|
|
|
|
# Player status
|
2023-05-18 12:22:43 +02:00
|
|
|
status=$($playerctl status)
|
2021-07-21 01:44:23 +02:00
|
|
|
case $status in
|
|
|
|
Playing|Paused)
|
2023-05-18 12:22:43 +02:00
|
|
|
title="$($playerctl metadata xesam:title | sed -e 's/&/\&/g' -e 's/</\</g')"
|
|
|
|
artist="$($playerctl metadata xesam:artist | sed -e 's/&/\&/g' -e 's/</\</g')"
|
2021-07-21 01:44:23 +02:00
|
|
|
status="$status <span weight='light'><i>${title} (${artist})</i></span>"
|
|
|
|
;;
|
|
|
|
esac
|
2021-07-21 07:31:27 +02:00
|
|
|
printf "\00message\037${status}\n"
|
2021-07-21 02:17:04 +02:00
|
|
|
;;
|
|
|
|
1)
|
|
|
|
case $ROFI_INFO in
|
2023-05-18 12:22:43 +02:00
|
|
|
1) $playerctl previous ;;
|
|
|
|
2) $playerctl play ;;
|
|
|
|
3) $playerctl pause ;;
|
|
|
|
4) $playerctl stop ;;
|
|
|
|
5) $playerctl next ;;
|
2021-07-21 02:17:04 +02:00
|
|
|
6) i3-msg '[class="Pavucontrol"] focus' || i3-msg exec exec pavucontrol ;;
|
2023-05-18 12:22:43 +02:00
|
|
|
7) i3-msg '[class="Spotify"] focus' || i3-msg exec exec spotify ;;
|
2021-07-21 02:17:04 +02:00
|
|
|
esac >&2
|
|
|
|
;;
|
2021-07-20 22:27:49 +02:00
|
|
|
esac
|