From 7a6d7ca17266eb246504153a1e0d71161edf07ea Mon Sep 17 00:00:00 2001 From: dcarrillo Date: Tue, 6 Aug 2019 16:25:59 +0200 Subject: [PATCH] Add script to switch window states between active/minimize and use it when clicking Spotify module --- .config/polybar/launch.sh | 2 +- .config/polybar/scripts/spotify.py | 1 + .config/polybar/scripts/switch_window_state | 22 +++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100755 .config/polybar/scripts/switch_window_state diff --git a/.config/polybar/launch.sh b/.config/polybar/launch.sh index ac6af67..07ea758 100755 --- a/.config/polybar/launch.sh +++ b/.config/polybar/launch.sh @@ -4,7 +4,7 @@ killall -q polybar while pgrep -u $UID -x polybar >/dev/null; do sleep 1; done export TERMINAL_CMD="tilix --profile orange --new-process -e" -export WM_CONTROL="wmctrl -a" +export WM_CONTROL="$(dirname $0)/scripts/switch_window_state" for monitor in $(polybar --list-monitors | cut -d":" -f1); do export MONITOR=$monitor diff --git a/.config/polybar/scripts/spotify.py b/.config/polybar/scripts/spotify.py index 43c1d04..5a18f38 100755 --- a/.config/polybar/scripts/spotify.py +++ b/.config/polybar/scripts/spotify.py @@ -18,6 +18,7 @@ def get_spotify_song(): title = metadata['xesam:title'] window_title = artist + ' - ' + title + output = "%{A1:$WM_CONTROL '" + window_title + "' &:}" + window_title + "%{A-}" except dbus.DBusException as e: if (e.get_dbus_message() == f'The name {bus_name} was not provided by any .service files'): diff --git a/.config/polybar/scripts/switch_window_state b/.config/polybar/scripts/switch_window_state new file mode 100755 index 0000000..b7efa92 --- /dev/null +++ b/.config/polybar/scripts/switch_window_state @@ -0,0 +1,22 @@ +#!/bin/bash + +set -e + +[[ -z $1 ]] && exit 1 + +active_window=$(xdotool getactivewindow) +window=$(xdotool search --name "$1") +[[ $? -ne 0 ]] && exit 1 + +if [[ $active_window == $window ]]; then + xdotool windowminimize $window +else + xdotool windowactivate $window +fi + +exit 0 + + + + +