Resize and move bind and mpv

Question

Hi, I have this bind that takes your window and forces it to be little floating window near corner of the screen (or smaller one in the middle etc).

This can be easily done with this bind (for 1920x1080 resolution)

### Right floating miniature
bindsym $mod+period floating enable, resize set 560 280, move absolute position 1348 788

But mpv doesnt seem to understand these resize events, and moves but doesnt resize, going out of the screen.

After second run (second screen) it draws border correctly but mpv overflows. screen

What is the root cause of issue like this? Or am i just missing some package?

Posted Jul 31, 2022, 10:39 AM UTC

27

I have the same problem, I made it into a script a while ago and it also frequently does not resize mpv correctly. I have also noticed that it is not consistent. The script is made to toggle between the toggled in the window corner state and the normal tiled state, and, if I keep the bind pressed it will run the script over and over multiple time a second, and at some point the mpv window gets the right size.
I thinks what is happening is that mpv does not correctly react to the resize event correctly, it also tries to force a certain aspect ratio for the window to conform to what the video has
(It might even be a race condition since spamming it works in the end - usually)

2
hellfiniterOP•

i experimented with swaymsg as well, I guessed its caused by those event so fast after each other, but no it is just that resize event. It simply draws outside of its sway border bounds.

I thought this should be impossible so I think my biggest question is, should I report it to sway or is it more like mpv not implementing some protocol, OR is it xwayland that could bridge this properly? Maybe this should be reported there?

2

Nothing to do with Xwayland I think, for me it's running natively in wayland at least. I think it is an mpv bug. From what I now about wayland, the compositor can communicate a new size for a clients surface, but the surface can also notify the compositor of size changes. In this case it seems to be that sway tells mpv that it has a new size and mpv resize to the closest size that respect the videos aspect ratio, but sometimes doesn't informe sway of it so you can get a partially filled window or window borders that overlap the content. This last scenario happens because even when the client does not follow the size it has been given, sway will just draw it's border were it wants and not crop the content (which I think it should do but that would be very annoying for window that are buggy and do not respect the size assigned to them)

1
blank_spiral•

Firstly if you can set it to mpv when executing it, you can use --autofit. Otherwise I kinda have a hacky solution:

Run mpv with:

mpv --input-ipc-server=/tmp/mpv-socket

and change the binding to

bindsym $mod+period exec echo '{ "command": ["set_property", "autofit", "560x280"] }' | socat - /tmp/mpv-socket; floating enable, resize set 560 280, move absolute position 1348 788

It doesn't seem to quite align up for me, maybe you can tweak it a bit to get it right, and maybe try using other options for mpv like geometry.

2
hellfiniterOP•

so basically what you are saying is that mpv needs to be explicitly said "this is size you are going to occupy" otherwise it doesnt respect it. I guess that works but i m more interested in reason why this happens. Because I m pretty sure i will find another app that does the same and doesnt have this flag :X

1
blank_spiral•

It's unlikely to happen with other programs unless they hardcoded the size. mpv by default makes the window size the same as the video size (there's some discussion regarding this behaviour) and you can make sure it doesn't get larger than your screen size by using --autofit-larger. mpv probably won't change this behaviour soon since they'll have to redo the backends.

Sway, in tiling mode at least, forces windows to be of certain size, regardless of what they want to draw. I'm not sure how it does this, but maybe it's possible to do the same thing with floating windows?

mpv also seems to not recognize sway resizing as user resizing. And goes back to default size when sway is not forcing any sizes.

1
hellfiniterOP•

this is exactly the point i dont understand ...what is the difference between me resizing it (where it works) or even tiling size (where it also respects forced size). That to me sounds like sway is the one at fault where in this specific scenario it doesnt do all the events it does during other ones. I will open sway issue, maybe someone can add some details.

1