mpv-player / mpv

🎥 Command line video player
https://mpv.io
Other
28.66k stars 2.93k forks source link

positioning.lua: add this script #15314

Open guidocella opened 1 week ago

guidocella commented 1 week ago

This script provides script messages and bindings to pan videos and images, making mpv a better image viewer out of the box.

I've had this script for 3 years in my image config so why not upstream it to view images better out of the box. Credits to occivink for the original ideas of the bindings.

I also have a mouse gesture and a oneshot double page mode in my script but those may not be worth upstreaming.

For the reasoning behind the suppress_osd naming, see https://github.com/mpv-player/mpv/pull/9051#issuecomment-887290791

Touch input in cursor-centric-zoom is untested.

For negative zoom, I think we need a global option like --auto-recenter-video (implemented in vo_get_src_dst_rects()?) to reset video-align to 0 when the image is smaller than the OSD, so that it also applies when changing video-zoom/panscan/video-unscaled/video-aspect-override/video-scale/changing file. Then positioning.lua should do nothing when that option is true and the image is smaller than the OSD. In my config, I use

mp.observe_property('osd-dimensions', 'native', function (_, dims)
    if dims.ml + dims.mr > 0 then
        mp.set_property('video-align-x', 0)
    end
    if dims.mt + dims.mb > 0 then
        mp.set_property('video-align-y', 0)
    end
end)
github-actions[bot] commented 1 week ago

Download the artifacts for this pull request:

Windows * [mpv-i686-w64-mingw32](https://nightly.link/mpv-player/mpv/actions/artifacts/2198911539.zip) * [mpv-x86_64-w64-mingw32](https://nightly.link/mpv-player/mpv/actions/artifacts/2198913785.zip) * [mpv-x86_64-windows-msvc](https://nightly.link/mpv-player/mpv/actions/artifacts/2198930927.zip)
macOS * [mpv-macos-13-intel](https://nightly.link/mpv-player/mpv/actions/artifacts/2198912936.zip) * [mpv-macos-14-arm](https://nightly.link/mpv-player/mpv/actions/artifacts/2198910272.zip) * [mpv-macos-15-arm](https://nightly.link/mpv-player/mpv/actions/artifacts/2198910450.zip)
kasper93 commented 1 week ago

Can we add default keybindings for those commands? Else it will become dead code.

guidocella commented 1 week ago

Sure I was trying not to burden the original proposal with breaking changes. What about:

Move cycle pause to MBTN_LEFT drag-to-pan on MBTN_RIGHT align-to-cursor on MBTN_MID cursor-centric-zoom on Ctrl+wheel Rebind Alt+Arrows to osd-relative-pan ?

Unfortunately we can't easily set different default key bindings for images if we're set on deprecating input sections.

mrfragger commented 6 days ago

Touch input in cursor-centric-zoom is untested.

I'm using a touchpad but not sure how exactly I'm supposed to keybind it

Ctrl+MBTN_LEFT script-binding drag-to-pan. (this one works) tried this and invalid command Ctrl+Alt+WHEEL_UP cursor-centric-zoom same as this one Ctrl+Alt+WHEEL_UP cursor-centric-zoom add video-zoom 0.05 Ctrl+UP align-to-cursor (not sure but says invalid command)

guidocella commented 6 days ago

https://github.com/guidocella/mpv-image-config/blob/f8ba0d22bb738bb0c55545121d525613a92b498d/input.conf#L98

mrfragger commented 5 days ago

thanks for the help..yes the centric-cursor-zoom works great on touchpad. Thanks for adding these...gonna use mpv as main image viewer on mac. These are great additions.

Ctrl+Wheel_Down add video-zoom -0.05 #! [Video/Image] > [Scale] > Zoom Out (scroll down) Ctrl+Wheel_Up add video-zoom 0.05 #! [Video/Image] > [Scale] > Zoom In (scroll up) Alt+Wheel_Down script-message cursor-centric-zoom -0.05 #! [Video/Image] > [Scale] > Zoom Out near cursor Alt+Wheel_Up script-message cursor-centric-zoom 0.05 #! [Video/Image] > [Scale] > Zoom In near cursor Alt+MBTN_LEFT script-binding align-to-cursor #! [Video/Image] > [Scale] > Pan aligned to cursor (while zoomed in) Ctrl+MBTN_LEFT script-binding drag-to-pan #! [Video/Image] > [Scale] > Drag to Pan (while zoomed in)

guidocella commented 5 days ago

Yeah I know it works on a touchpad, by untested touch input I meant devices like tables which populate the touch-pos property (or at least I assume touch-pos is not supposed to work with touchpads).

EDIT: I was trying a touchpad on Xorg whose backend doesn't implement touch-pos, it should work on Wayland.

guidocella commented 4 days ago

Updated as nanahi requested in https://github.com/mpv-player/mpv/pull/15316. Also, my point in https://github.com/mpv-player/mpv/pull/15316#issuecomment-2481457532 of cursor-centric-zoom not needing multiple amounts was moot since you need a negative amount to zoom out (unless you add different script-bindings to zoom in and out).

But unfortunately, beyond the bindings being so long that they get cropped in the stats page, they just don't work, because the script-binding runs before change-list updates the script-opt. So something like repeatable no-osd change-list script-opts append positioning-pan_amount=-0.2; script-binding positioning/pan-x will use the last pan_amount on the first trigger, and only use -0.2 from the second trigger onwards.

na-na-hi commented 4 days ago

input.conf: cycle pause with MBTN_LEFT

This should be put off until dragging deadzone is supported on macOS. It wasn't implemented in that PR.

Akemi commented 4 days ago

@na-na-hi did you mean this https://github.com/mpv-player/mpv/pull/13582 one?

na-na-hi commented 4 days ago

@na-na-hi did you mean this #13582 one?

Yes. It makes dragging send a VOCTRL to the VO to signal beginning of dragging, so it has no effect if the VO doesn't handle the VOCTRL.

Akemi commented 4 days ago

okay, i will look into it. sry that PR kinda went by me.

guidocella commented 4 days ago

How do you intend to support key bindings with different pan and zoom amounts without making them commands? repeatable script-message-to positioning set-pan-amount -0.2; script-binding positioning/pan-x works, but it is a hack which may break if ever support holding down multiple keys to pan diagonally. I think script-binding should just support variable arguments like script-message, else it will always be inferior to commands. It can pass a JSON array of user arguments, mp.input already works this way. (Supporting no-osd would also be nice if feasible).

na-na-hi commented 3 days ago

How do you intend to support key bindings with different pan and zoom amounts without making them commands?

The easiest way would be making fast and slow pan parameters as script options.

I think script-binding should just support variable arguments like script-message, else it will always be inferior to commands. It can pass a JSON array of user arguments, mp.input already works this way.

The problem is that script-binding internally sends the key information as script-message, so any arguments added to script-binding need to be also included in the message which already has some parameters. At best it can only support one argument, because if multiple parameters are supported, we can never add more arguments for the key information again without breaking compatibility.

guidocella commented 3 days ago

The easiest way would be making fast and slow pan parameters as script options.

As I just wrote changing script-opts within the binding doesn't work, so we would need 8 script bindings + 2 script-opts just to pan: pan-up, pan-right, pan-down, pan-left, pan-up-slow, pan-right-slow, pan-down-slow, pan-left-slow. And what about when someone wants a 3rd speed? How is this better than 1 command?

The problem is that script-binding internally sends the key information as script-message, so any arguments added to script-binding need to be also included in the message which already has some parameters. At best it can only support one argument, because if multiple parameters are supported, we can never add more arguments for the key information again without breaking compatibility.

Hence the JSON array, you send all user arguments as 1 argument to script message. I already do this in console.lua to send 0 1 or 2 arguments to input.lua, and I can add more arguments whenever is necessary.

na-na-hi commented 3 days ago

I have added support for custom argument for script-binding in https://github.com/mpv-player/mpv/pull/15316. This should make it possible to customize amount in input.conf.

guidocella commented 3 days ago

This works great now by depending on #15316. You can easily fork the script and there is no need to add commands to the core, and other scripts can also benefit from the new scale and arg arguments to script-binding.

Once macOS supports the dragging deadzone we can bind drag-to-pan to MBTN_RIGHT by default, but there is no hurry.