Skip to content

add click-to-focus player window with menu close - #936

Open
romanstingler wants to merge 1 commit into
MalpenZibo:mainfrom
romanstingler:feature/media-player-click-to-focus
Open

add click-to-focus player window with menu close#936
romanstingler wants to merge 1 commit into
MalpenZibo:mainfrom
romanstingler:feature/media-player-click-to-focus

Conversation

@romanstingler

Copy link
Copy Markdown
Collaborator

Add a Raise command to the media player module that focuses the player's window through the compositor.
Clicking a player card now triggers this behavior, selecting the most recently focused window when multiple windows exist for the same player.

org.mpris.MediaPlayer2.Raise() is the MPRIS method intended to bring the player's UI to the front, and the players tested here advertise CanRaise = true.
On Wayland, successfully handling Raise() still requires the player to get its own surface activated: normal activation is mediated by xdg-activation-v1 and an activation token, and the compositor decides whether to honor it.
The MPRIS spec itself notes that Raise() may be prevented by the window manager even when CanRaise is true.

In the tested cases the D-Bus call therefore succeeds while the player's window stays unfocused:

$ hyprctl activewindow -j | jq -r .class
firefox
$ busctl --user call org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 \
        org.mpris.MediaPlayer2 Raise
$ hyprctl activewindow -j | jq -r .class
firefox     # Spotify never came up

Since the tested players do not reliably get their windows activated this way, asking
the compositor directly is the dependable alternative. FocusWindowByPid is therefore
implemented for the Hyprland and Niri backends, and MPRIS Raise() is kept as the
fallback, for backends that cannot focus by pid (MangoWC, generic Wayland) and for
clients where self-activation does work, such as X11/XWayland windows.

Clicking a card also closes the menu, so it does not sit on top of the window that
was just focused.

Caveat

This focuses the player's window, not a browser tab. MPRIS reports that a player is playing but carries no tab information, so with

Firefox window A -> YouTube tab
Firefox window B -> Gmail tab
Firefox PiP window

resolving pid to window gets you to the application/window level, not to the tab that owns the media.
A video playing in a background tab stays in the background.

Testing

  • Verified on Hyprland (configProvider: lua) with Firefox and Spotify: clicking a
    card focuses the player, and with two Firefox windows open it lands on the one that
    was last used rather than on the picture-in-picture pop-up.

@MalpenZibo are you still using Niri ?

  • The Niri path is written against niri-ipc 26.4 but is untested on a live Niri
    session.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant