diff options
| author | Josh Rahm <rahm@google.com> | 2023-02-03 11:51:20 -0700 |
|---|---|---|
| committer | Josh Rahm <rahm@google.com> | 2023-02-03 11:51:20 -0700 |
| commit | f4784b81d36a2b60e66fd4050f2c93aa077ca7f5 (patch) | |
| tree | 4cd410771a86683b63266322e1deb2ee5faa0e0e | |
| parent | 0ddcc4362ccab3a443d244c6c8beb7a1eef4d9a4 (diff) | |
| download | rde-f4784b81d36a2b60e66fd4050f2c93aa077ca7f5.tar.gz rde-f4784b81d36a2b60e66fd4050f2c93aa077ca7f5.tar.bz2 rde-f4784b81d36a2b60e66fd4050f2c93aa077ca7f5.zip | |
Decouple RDE from spotify by allowing the user to select the media to control
Perhaps a Python script is in order to make it less ugly, but
as things stand it works.
This also uses the XDG_RUNTIME_DIR to store the variable associated with
the target to control.
| -rwxr-xr-x | extras/HOME/.local/bin/media-control | 67 | ||||
| -rwxr-xr-x | extras/HOME/.local/bin/media-select.sh | 26 | ||||
| -rw-r--r-- | src/Rahm/Desktop/Keys.hs | 5 |
3 files changed, 70 insertions, 28 deletions
diff --git a/extras/HOME/.local/bin/media-control b/extras/HOME/.local/bin/media-control index 34a2633..c3febcd 100755 --- a/extras/HOME/.local/bin/media-control +++ b/extras/HOME/.local/bin/media-control @@ -6,37 +6,48 @@ then exit fi -target_hint="spotify" -while [[ "$1" == --* ]] ; do - arg="$1" - case "$arg" in - --target-hint=*) - target_hint="${arg/--target-hint=/}" - ;; - *) - echo "Bad Argument $1" - exit 1 - ;; - esac - shift -done - -# Some targets (spotifyd) don't have a stable dbus path. -targets="$( \ - dbus-send \ - --print-reply \ - --dest=org.freedesktop.DBus \ - /org/freedesktop/DBus org.freedesktop.DBus.ListNames \ - | sed 's#.*string \"\(.*\)"#\1#' \ - | grep MediaPlayer2)" +function get-default-target() { + local target_hint="spotify" + while [[ "$1" == --* ]] ; do + local arg="$1" + case "$arg" in + --target-hint=*) + target_hint="${arg/--target-hint=/}" + ;; + *) + echo "Bad Argument $1" + exit 1 + ;; + esac + shift + done + + # Some targets (spotifyd) don't have a stable dbus path. + local targets="$( \ + dbus-send \ + --print-reply \ + --dest=org.freedesktop.DBus \ + /org/freedesktop/DBus org.freedesktop.DBus.ListNames \ + | sed 's#.*string \"\(.*\)"#\1#' \ + | grep MediaPlayer2)" + + # Prefer the target hint. + target="$(echo "$targets" | grep -i "$target_hint" | head -n1)" + if [ -z "$target" ] ; then + # If no spotify, pick an arbitrary one + target="$(echo "$targets" | head -n1)" + fi +} -# Prefer the target hint. -target="$(echo "$targets" | grep -i "$target_hint" | head -n1)" -if [ -z "$target" ] ; then - # If no spotify, pick an arbitrary one - target="$(echo "$targets" | head -n1)" +media_selection_file=$XDG_RUNTIME_DIR/rde/vars/MEDIA +if [ -f "$media_selection_file" ] ; then + target=$(cat "$media_selection_file") +else + get-default-target fi +echo "Sending to taget: $target" + function mpris2_dbus_player_do { dbus-send \ --print-reply \ diff --git a/extras/HOME/.local/bin/media-select.sh b/extras/HOME/.local/bin/media-select.sh new file mode 100755 index 0000000..0d2f9de --- /dev/null +++ b/extras/HOME/.local/bin/media-select.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +runtime_dir=$XDG_RUNTIME_DIR/rde/vars/ +mkdir -p $runtime_dir + +media_selection_file=$runtime_dir/MEDIA + +raw_dbus_opts=$( \ + dbus-send \ + --print-reply \ + --dest=org.freedesktop.DBus \ + /org/freedesktop/DBus org.freedesktop.DBus.ListNames | \ + grep MediaPlayer2 | \ + sed 's#.*["]\(.*\)["]#\1#') + +selection="$(echo -e "$raw_dbus_opts\ndefault" | \ + $ROFI -i -p "Control Media" \ + -theme-str '* {theme-color: #88ff88;}')" + +if [ ! -z "$selection" ] ; then + if [ "$selection" == "default" ] ; then + rm $media_selection_file + else + echo "$selection" > $media_selection_file + fi +fi diff --git a/src/Rahm/Desktop/Keys.hs b/src/Rahm/Desktop/Keys.hs index c0d9c3a..5c6866e 100644 --- a/src/Rahm/Desktop/Keys.hs +++ b/src/Rahm/Desktop/Keys.hs @@ -703,6 +703,11 @@ keymap = runKeys $ do doc "Set the volume of an application via rofi." $ spawnX "set-volume.sh -a" + bind xK_m $ do + (justMod -|- noMod) $ + doc "Set the media source to control" $ + spawnX "media-select.sh" + -- Double-tap Z to toggle zoom. bind xK_z $ do noMod -|- justMod $ |