From b4696a1f867faec280fd078e633a5010f74b1d87 Mon Sep 17 00:00:00 2001 From: Wryn Wagner Date: Mon, 5 Oct 2020 10:48:05 -0600 Subject: [PATCH] updated media controller to optionally not try and refocus previous window --- bin/desktop/youtube-music/controller.sh | 11 ++------ .../youtube-music/return-controller.sh | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 9 deletions(-) create mode 100755 bin/desktop/youtube-music/return-controller.sh diff --git a/bin/desktop/youtube-music/controller.sh b/bin/desktop/youtube-music/controller.sh index 57ae275..f41a757 100755 --- a/bin/desktop/youtube-music/controller.sh +++ b/bin/desktop/youtube-music/controller.sh @@ -1,16 +1,12 @@ # # Chrome / YouTube only accepts keypresses when window is active # -# This activates the YouTube window, sends the keypress, then reactivates the original window +# This activates the YouTube window and sends the keypress # xdotool search --name 'YouTube Music' >/dev/null 2>&1 || return 1; -ACTIVE_DESKTOP="$(xdotool get_desktop)" -ACTIVE_WINDOW_ID="$(xdotool getactivewindow)" -ACTIVE_WINDOW_NAME="$(xdotool getwindowname $ACTIVE_WINDOW_ID)" - -TIMEOUT='0.1'; +TIMEOUT='0.3'; case $1 in next) KEY_COMMAND='j';; @@ -21,6 +17,3 @@ esac xdotool search --name 'YouTube Music' windowactivate; sleep $TIMEOUT; xdotool key --clearmodifiers "$KEY_COMMAND"; - -xdotool set_desktop "$ACTIVE_DESKTOP"; -[[ "$ACTIVE_WINDOW_NAME" != "Desktop" ]] && xdotool windowactivate "$ACTIVE_WINDOW_ID"; diff --git a/bin/desktop/youtube-music/return-controller.sh b/bin/desktop/youtube-music/return-controller.sh new file mode 100755 index 0000000..57ae275 --- /dev/null +++ b/bin/desktop/youtube-music/return-controller.sh @@ -0,0 +1,26 @@ +# +# Chrome / YouTube only accepts keypresses when window is active +# +# This activates the YouTube window, sends the keypress, then reactivates the original window +# + +xdotool search --name 'YouTube Music' >/dev/null 2>&1 || return 1; + +ACTIVE_DESKTOP="$(xdotool get_desktop)" +ACTIVE_WINDOW_ID="$(xdotool getactivewindow)" +ACTIVE_WINDOW_NAME="$(xdotool getwindowname $ACTIVE_WINDOW_ID)" + +TIMEOUT='0.1'; + +case $1 in + next) KEY_COMMAND='j';; + prev) KEY_COMMAND='k';; + *) KEY_COMMAND='space';; +esac + +xdotool search --name 'YouTube Music' windowactivate; +sleep $TIMEOUT; +xdotool key --clearmodifiers "$KEY_COMMAND"; + +xdotool set_desktop "$ACTIVE_DESKTOP"; +[[ "$ACTIVE_WINDOW_NAME" != "Desktop" ]] && xdotool windowactivate "$ACTIVE_WINDOW_ID";