Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

command: add cursor-centric-zoom #15310

Closed
wants to merge 4 commits into from

Conversation

guidocella
Copy link
Contributor

Touch input is untested.

Copy link

github-actions bot commented Nov 14, 2024

Download the artifacts for this pull request:

Windows
macOS

@na-na-hi
Copy link
Contributor

na-na-hi commented Nov 14, 2024

This should be done as a built-in/TOOLS script. There is no reason for this to be a command when everything else uses writable properties for zooming.

@llyyr
Copy link
Contributor

llyyr commented Nov 14, 2024

I think it's a good idea to have a way to provide cursor centric zoom without external scripts. We can either do it with this PR, or a built-in script. But I don't really know why we would add more built-in scripts when a C implementation is already done

@na-na-hi
Copy link
Contributor

na-na-hi commented Nov 14, 2024

But I don't really know why we would add more built-in scripts when a C implementation is already done

Providing it as a script has several advantages:

  • Writing it in a memory-safe language simplifies programming.
  • Avoids bloating player core and command interface.
  • Easily modifiable by users without having to recompile the whole program.

The goal of mpv is to be an extensible player, by making more functionalities possible to be implemented as scripts, instead of making everything going into C code, especially for "nice to have", non-essential features like this.

@kasper93
Copy link
Contributor

Writing it in a memory-safe language simplifies programming.

Not applicable here. I also don’t think memory-safe languages simplify programming; they merely prevent you from accessing memory incorrectly. C is very simple language to work with.

Avoids bloating player core and command interface.

If it is a built-in script, the interface will be bloated anyway.

Easily modifiable by users without having to recompile the whole program.

Depending on the use case, users generally don't need to modify these basic commands.

The goal of mpv is to be an extensible player, by making more functionalities possible to be implemented as scripts, instead of making everything going into C code, especially for "nice to have", non-essential features like this.

I kind of agree. All this command does is set already existing properties; it doesn't need to be in C. There are many similar cases where we could move some functionality to scripts for better flexibility. In this case, I would see it as a built-in script that computes correct values for the video-zoom and video-align properties. Such a script could also be extended to include video-dragging functionality, not just zooming. While it's valid to implement this in C, it's a decision whether we want some things directly implemented or if we should rely on the scripting backend and keep the core untouched.

But since, it's implemented in C, I don't mind having it, if it's easier this way.

@llyyr
Copy link
Contributor

llyyr commented Nov 14, 2024

Easily modifiable by users without having to recompile the whole program.

The goal of mpv is to be an extensible player, by making more functionalities possible to be implemented as scripts, instead of making everything going into C code, especially for "nice to have", non-essential features like this.

What reasonable modifications do you envision being made to "cursor centric zoom" without it being a totally different feature entirely?

I'm ignoring the first two points on your bullet list because I don't believe even you seriously believe they're good points to bring up, please keep the trolling to a minimum next time.

@avih
Copy link
Member

avih commented Nov 14, 2024

Extending internally with scripts does keep the core from bloating, and memory-safe languages do have less footguns than C. Just think how much care would be needed to write the OSC or ytdl-hook in C, while in lua, it's maybe not always perfect, but at least you know it's safe (as far as memory access goes), and trivial for users to start hacking.

So generally, keep using scripts to extend the code does have advantages.

However, in this case I think the functionality is simple enough to keep at the C code.

@na-na-hi
Copy link
Contributor

they merely prevent you from accessing memory incorrectly. C is very simple language to work with.

What's lua's drawback compared to C here? There is no reason to use C when lua works for this case.

If it is a built-in script, the interface will be bloated anyway.

Not really. The command and options of playback core are unchanged. This is what had been done with SMTC, which is a built-in plugin instead of in player core.

I would see it as a built-in script that computes correct values for the video-zoom and video-align properties. Such a script could also be extended to include video-dragging functionality, not just zooming.

This is my plan. I will open a PR to implement them as a built-in script. It will be better than the C implementation for various reasons noted.

What reasonable modifications do you envision being made to "cursor centric zoom" without it being a totally different feature entirely?

For example, smooth/"kinetic" zooming with mouse wheel, or setting to control whether it centers to cursor or screen when zooming to <100% etc.
Smooth zooming would be much more complicated to implement in player core compared to lua, where it can use timers.

I'm ignoring the first two points on your bullet list because I don't believe even you seriously believe they're good points to bring up, please keep the trolling to a minimum next time.

Please keep bad faith arguments to a minimum next time. This is not constructive to the discussion.

@guidocella
Copy link
Contributor Author

Some points to consider:

  • An advantage of being a command is that it respects the no-osd prefix for whether to show the new video-zoom, while script-message doesn't; it can be added as an extra argument that takes an arbitrary value like osc-visibility, but it is more awkward.
  • I assume the high resolution scaling with touchpads (cmd->scale) would no longer work.
  • We already have playlist-next-playlist and playlist-prev-playlist as a precedent for commands that could be scripts.
  • We recently went in the opposite direction by converting autoload.lua to a C option.
  • I converted this to C specifically to upstream it, but if we're going to add a script for (mostly) image bindings, positioning.lua maybe, at least I can just put my existing drag-to-pan and align-to-cursor implementations there, I assume those would be much harder to convert to C since they temporarily rebind MOUSE_MOVE (and I can also osd-relative-pan).

@na-na-hi
Copy link
Contributor

na-na-hi commented Nov 14, 2024

  • An advantage of being a command is that it respects the no-osd prefix for whether to show the new video-zoom, while script-message doesn't

If it's implemented as a script, this can simply be a script option.

  • We already have playlist-next-playlist and playlist-prev-playlist as a precedent for commands that could be scripts.
  • We recently went in the opposite direction by converting autoload.lua to a C option.

These are playlist management features that are expected to be a built-in player functionality for any video players, and in the loadfile case it reuses existing directory loading code, so they get a pass. A nonessential feature like this PR shouldn't be treated the same.

  • at least I can just put my existing drag-to-pan and align-to-cursor implementations there, I assume those would be much harder to convert to C since they temporarily rebind MOUSE_MOVE (and I can also osd-relative-pan).

This would be a better solution than the C one IMO. I don't see any problem with upstreaming built-in lua scripts when they enhance the player with useful features.

@guidocella
Copy link
Contributor Author

Do you know if there's a way to respect cmd->scale in Lua? That would be the only disadvantage of a script. We probably have to add support to script-message itself.

@na-na-hi
Copy link
Contributor

na-na-hi commented Nov 14, 2024

Do you know if there's a way to respect cmd->scale in Lua?

Not currently, but I have been looking into this. Several script features don't support scaled commands right now but I'm planning to add them. As you said this can be added to script-message.

Edit: Scripts can now add scalable key bindings with #15316, so your scripts can handle scaled input devices now.

@llyyr
Copy link
Contributor

llyyr commented Nov 14, 2024

What's lua's drawback compared to C here? There is no reason to use C when lua works for this case.

The functionality will be unavailable if mpv is compiled without lua. Of course this is rare, but I don't see why we would opt for a Lua implementation when a C implementation is already done. mpv historically has always preferred C implementations except for things that are intended to be modular, like osc or stats.lua or console.lua. This is a command, it is not intended to be modular. If there are improvements to be made to it, it should be done inside mpv. Another reason would be that this increases the maintenance burden in the future when/if luajit stops being actively developed, it's yet another script that will need to be tested to work with Lua 5.3/5.4. This is something we've already discussed before. You don't have to deal with any of these problems if it's implemented in C.

Of course, none of this matters if using a built-in Lua script means we can merge more features into mpv beyond just cursor centric zoom. I was in favor of this MR purely because the work is already done, so it makes no sense to add a Lua script just for this. I like #15314 better in any case.

This is my plan. I will open a PR to implement them as a built-in script. It will be better than the C implementation for various reasons noted.

You're engaging in circular reasoning here. You can't say "better for reasons noted" when those reasons are a point of contention. We're discussing the reasons you've cited, you can't say "my reasons are valid for the reasons noted".

These are playlist management features that are expected to be a built-in player functionality for any video players, and in the loadfile case it reuses existing directory loading code, so they get a pass. A nonessential feature like this PR shouldn't be treated the same.

This is subjective and has changed over time in this project, I don't believe you get to unilaterally decide where the line is drawn for "non-essential".

@guidocella
Copy link
Contributor Author

For the record, upgrading to Lua 5.4 is easy, I already showed all that's necessary in #14905 and it is just +16 -15 lines. positioning.lua shouldn't need any modification since it doesn't use string.format.

@Samillion
Copy link
Contributor

My input will be about the centric-zoom itself, not whether it should be a script or not.

Honestly, a welcomed addition. mpv is capable of being a great image viewer, it is why I suggest guido's centric zoom in my osc's image mode https://github.com/Samillion/ModernZ/blob/main/docs/IMAGE_VIEWER.md

To be even more blunt, I genuinely think osc.lua should offer an image mode as well, with the relative features such as centric zoom enabled in it.

To be fair, I realize this has never been a high demand, but I honestly think it's because most users aren't aware of such capabilities to be possible within mpv.

Also, while my use case suggests "image mode", I'm sure many would appreciate it in all modes as well.

It's one of those things that you realize you need, only once you know about it.

@guidocella guidocella force-pushed the cursor-centric-zoom branch 2 times, most recently from a416177 to 76d8390 Compare November 16, 2024 12:52
@guidocella
Copy link
Contributor Author

  • Writing it in a memory-safe language simplifies programming.

Ironically, I just noticed that change_property_cmd causes a stack-buffer-overflow when building with ASan. I'm not sure what the problem is.

Alt+BS prints "video-pan-y: 0" which seems arbitrary. Make it print
video-zoom: 0 which is the most important property that gets reset.
This is useful after binding cursor-centric-zoom by default.
@guidocella
Copy link
Contributor Author

Fixed the stack-buffer-overflow.

@guidocella
Copy link
Contributor Author

Superseded by #15314.

@guidocella guidocella closed this Nov 17, 2024
@guidocella
Copy link
Contributor Author

To be even more blunt, I genuinely think osc.lua should offer an image mode as well, with the relative features such as centric zoom enabled in it.

osc.lua is terrible for images because it breaks drag-to-pan from the bottom half of the window. Unless it can be made to work like uosc I think we should just disable it for images, I don't think an OSC for images is that useful anyway, e.g. sxiv/feh/imv don't have any.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants