7

I have these lines in my i3 config right now:

# Play/pause, prev, next
bindcode 172 exec "/opt/playerctl/bin/playerctl play-pause"
bindcode 173 exec "/opt/playerctl/bin/playerctl previous"
bindcode 171 exec "/opt/playerctl/bin/playerctl next"

This makes the media buttons on my keyboard play/pause audio players supported by playerctl, like Spotify.

The issue is that the play/pause media button now no longer works in my video player (SMPlayer).

Is it possible to make the key bindings only take effect when the focused window is not SMPlayer?


To summarize what I'm trying to do: I want the key bindings above to always be in effect, except for when the SMPlayer window (class: "Smplayer") is focused.

Is this possible?

2

You could try this. Remember to replace username with your real Linux username in the following. For some reason, using ~ instead of home/username did not work for me.

Use these lines in i3 config:

# Play/pause, prev, next
bindcode 172 exec /home/username/.i3/play.sh play-pause
bindcode 173 exec /home/username/.i3/play.sh previous
bindcode 171 exec /home/username/.i3/play.sh next

Paste the following into a file called /home/username/.i3/play.sh

cmd="$1"
id=$(xprop -root | awk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}')
curr_title=$(xprop -id $id | awk '/_NET_WM_NAME/{$1=$2="";print}' | cut -d'"' -f2)
if [[ "$curr_title" != "SMPlayer"* ]]; then
    /opt/playerctl/bin/playerctl "$cmd"
fi

You may have to adjust the "SMPlayer"* part depending on the exact title that the window has - I have no experience with that program. You can add an else clause to run another program when SMPlayer is running, if you wish to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.