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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DOCS/interface-changes/cursor-centric-zoom.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add `cursor-centric-zoom` command
8 changes: 8 additions & 0 deletions DOCS/man/input.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,14 @@ Remember to quote string arguments in input.conf (see `Flat command syntax`_).
of window dragging. For example, on Windows only the left mouse button can
begin window dragging, while X11 and Wayland allow other mouse buttons.

``cursor-centric-zoom <zoom>``
Increase ``--video-zoom`` by ``zoom`` and adjust ``--video-align-x`` and
``--video-align-y`` to shift the OSD towards the position hovered by the
cursor, or the average position of touch points if known.

If the video is smaller than the OSD in one direction, alignment in that
direction is centered.

Undocumented commands: ``ao-reload`` (experimental/internal).

List of events
Expand Down
3 changes: 2 additions & 1 deletion DOCS/man/mpv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ Wheel left/right
Seek forward/backward 10 seconds.

Ctrl+Wheel up/down
Change video zoom.
Change video zoom and shift the OSD towards the position hovered by the
cursor.

Context Menu
-------------
Expand Down
6 changes: 3 additions & 3 deletions etc/input.conf
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@
#ZOOMIN add video-zoom 0.1 # zoom in
#Alt+- add video-zoom -0.1 # zoom out
#ZOOMOUT add video-zoom -0.1 # zoom out
#Ctrl+WHEEL_UP add video-zoom 0.1 # zoom in
#Ctrl+WHEEL_DOWN add video-zoom -0.1 # zoom out
#Alt+BS set video-zoom 0; set panscan 0; set video-pan-x 0; set video-pan-y 0 # reset zoom and pan settings
#Ctrl+WHEEL_UP cursor-centric-zoom 0.1 # zoom in
#Ctrl+WHEEL_DOWN cursor-centric-zoom -0.1 # zoom out
#Alt+BS set video-zoom 0; no-osd set panscan 0; no-osd set video-pan-x 0; no-osd set video-pan-y 0; no-osd set video-align-x 0; no-osd set video-align-y 0 # reset zoom and pan settings
#PGUP add chapter 1 # seek to the next chapter
#PGDWN add chapter -1 # seek to the previous chapter
#Shift+PGUP seek 600 # seek 10 minutes forward
Expand Down
58 changes: 58 additions & 0 deletions player/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -6813,6 +6813,59 @@ static void cmd_flush_status_line(void *p)
mp_msg_flush_status_line(mpctx->log, cmd->args[0].v.b);
}

static void cmd_cursor_centric_zoom(void *p)
{
struct mp_cmd_ctx *cmd = p;
struct MPContext *mpctx = cmd->mpctx;

double zoom = cmd->args[0].v.d * cmd->cmd->scale;

int x = 0, y = 0;
int xs[MAX_TOUCH_POINTS], ys[MAX_TOUCH_POINTS], ids[MAX_TOUCH_POINTS];
int count = mp_input_get_touch_pos(mpctx->input, MAX_TOUCH_POINTS, xs, ys, ids);
if (count) {
for (int i = 0; i < count; i++) {
x += xs[i];
y += ys[i];
}
x /= count;
y /= count;
} else {
int hover;
mp_input_get_mouse_pos(mpctx->input, &x, &y, &hover);
}

struct mp_osd_res osd = osd_get_vo_res(mpctx->osd);
int width = (osd.w - osd.ml - osd.mr) * pow(2, zoom);
int height = (osd.h - osd.mt - osd.mb) * pow(2, zoom);
float align;

if (width > osd.w) {
int old_cursor_ml = osd.ml - x;
int cursor_ml = old_cursor_ml * pow(2, zoom);
int ml = cursor_ml + x;
// video/out/aspect.c:src_dst_split_scaling() defines ml as:
// ml = (osd-width - width) * (video-align-x + 1) / 2 + pan-x * width
// So video-align-x is:
align = 2.0 * (ml - mpctx->video_out->opts->pan_x * width) / (osd.w - width) - 1;
align = MPMIN(1, MPMAX(-1, align));
} else {
align = 0;
}
mp_property_do("video-align-x", M_PROPERTY_SET, &align, mpctx);

if (height > osd.h) {
int mt = (osd.mt - y) * pow(2, zoom) + y;
align = 2.0 * (mt - mpctx->video_out->opts->pan_y * height) / (osd.h - height) - 1;
align = MPMIN(1, MPMAX(-1, align));
} else {
align = 0;
}
mp_property_do("video-align-y", M_PROPERTY_SET, &align, mpctx);

change_property_cmd(cmd, "video-zoom", M_PROPERTY_SWITCH, &zoom);
}

/* This array defines all known commands.
* The first field the command name used in libmpv and input.conf.
* The second field is the handler function (see mp_cmd_def.handler and
Expand Down Expand Up @@ -7291,6 +7344,11 @@ const struct mp_cmd_def mp_cmds[] = {

{ "flush-status-line", cmd_flush_status_line, { {"clear", OPT_BOOL(v.b)} } },

{ "cursor-centric-zoom", cmd_cursor_centric_zoom, {
{"zoom", OPT_DOUBLE(v.d)}, },
.allow_auto_repeat = true,
.scalable = true,
},
{0}
};

Expand Down
Loading