How to keep Picture In Picture windows automatically on top in Plasma

Currently PiP isn’t supported on Wayland, but recently I finally discovered how to create a Window rule to force the PiP video window to automatically be forced to stay above other windows. The effect is undistinguished from the expected correct behavior, except for when I try to upload something somewhere.

When I’m on Mastodon for example and click the button to upload an image, when the file picker opens it makes the PiP video window go away.
What is curious about it is that when the file picker is open for the opposite purpose, download instead of upload, like when I want to save an image or file in these cases the file picker does not make the PiP video window go away.
Why? It’s the exact same “xdg-desktop-portal-kde org.freedesktop.impl.portal.desktop.kde” program being invoked in both cases.

Anyone has any idea for how to prevent the file picker portal from making the PiP video window go away when uploading files?
I tried everything with the Window Rules, is it not possible?

EDIT: forgot something importante. This only happens when using PiP on Vivaldi (chorume based web browser), it doesn’t happen on Firefox.
So if you use Firefox as default and wants PiP on Wayland, create this rule:

4 Likes

Nice! I occasionally watch YouTube videos in a PiP window and manually setting the “always-on-top” property is annoying. So this was a great find. Thanks for sharing!

1 Like

I just edited the title to help people searching

1 Like

I added a screenshot for the same thing, but for chrome, using Chrome’s Picture-in-Picture extension :slight_smile:

For a general solution (across any PiP window manager):

  1. Use KDE Window Manager to select the active PiP window with “Detect Window Properties" to determine how to “match” your PiP window to your new Window Policy.

  2. Once selected, add the window attributes that will help to select your specific PiP window (I’ve highlighted what I think are the most important, but these might be different for your setup).

  3. Once you’ve added these attributes, set a property to force the window to the top of the “stack” all the time.

Once you’ve applied, you should see that this will keep the window to the top of the screen all the time. You might also notice that the PiP window is treated separately as its own Wayland icon. This might look like a different icon depending on your setup, but if you’d prefer to not have this behavior so that it’s never in the taskbar, you can set that rule as well.

Note here that I didn’t specify the window class, and the menu is not loving that. You can further specify the window to dismiss that by specifying that the window is a “normal window.” Be careful though, because some PiP’s might not specify the window type (although this might be managed by Chrome/the browser itself, I’m not 100 percent sure). You can always use the “Detect Window Properties” to determine all the relevant matching information on the PiP window you’re trying to control the rules for.

Hope this helps!