-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
positioning.lua: add this script #15314
base: master
Are you sure you want to change the base?
Changes from all commits
f3e0122
5a1f307
ef62214
e66e570
1581d81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
POSITIONING | ||
=========== | ||
|
||
This script provides script bindings to pan videos and images. | ||
|
||
Script bindings | ||
---------------------------- | ||
|
||
``pan-x <amount>`` | ||
Adjust ``--video-align-x`` relatively to the OSD width, rather than | ||
relatively to the video width like the option. This is useful to pan large | ||
images consistently. | ||
|
||
``amount`` is a number such that an amount of 1 scrolls as much as the OSD | ||
width. | ||
|
||
``pan-y <amount>`` | ||
Adjust ``--video-align-y`` relatively to the OSD height, rather than | ||
relatively to the video height like the option. | ||
|
||
``amount`` is a number such that an amount of 1 scrolls as much as the OSD | ||
height. | ||
|
||
``drag-to-pan`` | ||
Pan the video while holding a mouse button, keeping the clicked part of the | ||
video under the cursor. | ||
|
||
``align-to-cursor`` | ||
Pan through the whole video while holding a mouse button. | ||
|
||
``cursor-centric-zoom <amount>`` | ||
Increase ``--video-zoom`` by ``amount`` while keeping the part of the video | ||
hovered by the cursor under it, or the average position of touch points if | ||
known. | ||
|
||
Configurable Options | ||
~~~~~~~~~~~~~~~~~~~~ | ||
|
||
``suppress_osd`` | ||
Default: no | ||
|
||
Whether to not print the new value of ``--video-zoom`` when using | ||
``cursor-centric-zoom``. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,8 @@ | |
#MBTN_LEFT ignore # don't do anything | ||
#MBTN_LEFT_DBL cycle fullscreen # toggle fullscreen | ||
#MBTN_RIGHT cycle pause # toggle pause/playback mode | ||
#MBTN_MID script-binding positioning/align-to-cursor # pan the whole video | ||
MBTN_MID_DBL no-osd set video-align-x 0; no-osd set video-align-y 0; no-osd set video-pan-x 0; no-osd set video-pan-y 0 # reset pan | ||
#MBTN_BACK playlist-prev # skip to the previous file | ||
#MBTN_FORWARD playlist-next # skip to the next file | ||
|
||
|
@@ -65,9 +67,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 script-binding positioning/cursor-centric-zoom 0.1 # zoom in towards the cursor | ||
#Ctrl+WHEEL_DOWN script-binding positioning/cursor-centric-zoom -0.1 # zoom out towards the cursor | ||
#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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could update numpad bindings the same way. |
||
#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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -588,6 +588,7 @@ static const m_option_t mp_opts[] = { | |
OPT_CHOICE(lua_load_auto_profiles, {"no", 0}, {"yes", 1}, {"auto", -1}), | ||
.flags = UPDATE_BUILTIN_SCRIPTS}, | ||
{"load-select", OPT_BOOL(lua_load_select), .flags = UPDATE_BUILTIN_SCRIPTS}, | ||
{"load-positioning", OPT_BOOL(lua_load_positioning), .flags = UPDATE_BUILTIN_SCRIPTS}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is used int defualt input.conf, I don't know if it is good to allow unloading this script. But maybe needed in some cases. EDIT: We should probably merge all those There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. --load options let you use a fork of that script in your scripts directory which was one of the arguments for making this a script. They are also convenient for development without recompiling. |
||
#endif | ||
|
||
// ------------------------- stream options -------------------- | ||
|
@@ -1009,6 +1010,7 @@ static const struct MPOpts mp_default_opts = { | |
.lua_load_console = true, | ||
.lua_load_auto_profiles = -1, | ||
.lua_load_select = true, | ||
.lua_load_positioning = true, | ||
#endif | ||
.auto_load_scripts = true, | ||
.loop_times = 1, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
--[[ | ||
This file is part of mpv. | ||
|
||
mpv is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2.1 of the License, or (at your option) any later version. | ||
|
||
mpv is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Lesser General Public License for more details. | ||
|
||
You should have received a copy of the GNU Lesser General Public | ||
License along with mpv. If not, see <http://www.gnu.org/licenses/>. | ||
]] | ||
|
||
local options = { | ||
suppress_osd = false, | ||
} | ||
|
||
require "mp.options".read_options(options, nil, function () end) | ||
|
||
mp.add_key_binding(nil, "pan-x", function (t) | ||
if t.event == "up" then | ||
return | ||
end | ||
|
||
local dims = mp.get_property_native("osd-dimensions") | ||
local width = dims.w - dims.ml - dims.mr | ||
-- 1 video-align shifts the OSD by (width - osd-width) / 2 pixels, so the | ||
-- equation to find how much video-align to add to offset the OSD by | ||
-- osd-width is: | ||
-- x/1 = osd-width / ((width - osd-width) / 2) | ||
if width ~= dims.w then | ||
mp.commandv("add", "video-align-x", | ||
t.arg * t.scale * 2 * dims.w / (width - dims.w)) | ||
end | ||
end, { complex = true, scalable = true }) | ||
|
||
mp.add_key_binding(nil, "pan-y", function (t) | ||
if t.event == "up" then | ||
return | ||
end | ||
|
||
local dims = mp.get_property_native("osd-dimensions") | ||
local height = dims.h - dims.mt - dims.mb | ||
if height ~= dims.h then | ||
mp.commandv("add", "video-align-y", | ||
t.arg * t.scale * 2 * dims.h / (height - dims.h)) | ||
end | ||
end, { complex = true, scalable = true }) | ||
|
||
mp.add_key_binding(nil, "drag-to-pan", function (t) | ||
if t.event == "up" then | ||
mp.remove_key_binding("drag-to-pan-mouse-move") | ||
return | ||
end | ||
|
||
local dims = mp.get_property_native("osd-dimensions") | ||
local old_mouse_pos = mp.get_property_native("mouse-pos") | ||
local old_align_x = mp.get_property_native("video-align-x") | ||
local old_align_y = mp.get_property_native("video-align-y") | ||
|
||
mp.add_forced_key_binding("MOUSE_MOVE", "drag-to-pan-mouse-move", function() | ||
local mouse_pos = mp.get_property_native("mouse-pos") | ||
-- 1 video-align shifts the OSD by (dimension - osd_dimension) / 2 pixels, | ||
-- so the equation to find how much video-align to add to offset the OSD | ||
-- by the difference in mouse position is: | ||
-- x/1 = (mouse_pos - old_mouse_pos) / ((dimension - osd_dimension) / 2) | ||
local align = old_align_x + 2 * (mouse_pos.x - old_mouse_pos.x) | ||
/ (dims.ml + dims.mr) | ||
mp.set_property("video-align-x", math.min(1, math.max(align, -1))) | ||
align = old_align_y + 2 * (mouse_pos.y - old_mouse_pos.y) | ||
/ (dims.mt + dims.mb) | ||
mp.set_property("video-align-y", math.min(1, math.max(align, -1))) | ||
end) | ||
end, { complex = true }) | ||
|
||
mp.add_key_binding(nil, "align-to-cursor", function (t) | ||
if t.event == "up" then | ||
mp.remove_key_binding("align-to-cursor-mouse-move") | ||
return | ||
end | ||
|
||
local dims = mp.get_property_native("osd-dimensions") | ||
mp.add_forced_key_binding("MOUSE_MOVE", "align-to-cursor-mouse-move", function() | ||
local mouse_pos = mp.get_property_native("mouse-pos") | ||
mp.set_property("video-align-x", (mouse_pos.x * 2 - dims.w) / dims.w) | ||
mp.set_property("video-align-y", (mouse_pos.y * 2 - dims.h) / dims.h) | ||
end) | ||
end, { complex = true }) | ||
|
||
mp.add_key_binding(nil, "cursor-centric-zoom", function (t) | ||
local amount = t.arg * t.scale | ||
|
||
local command = (options.suppress_osd and "no-osd " or "") .. | ||
"add video-zoom " .. amount .. ";" | ||
|
||
local x, y | ||
local touch_positions = mp.get_property_native("touch-pos") | ||
if next(touch_positions) then | ||
for _, position in pairs(touch_positions) do | ||
x = x + position.x | ||
y = y + position.y | ||
end | ||
x = x / #touch_positions | ||
y = y / #touch_positions | ||
else | ||
local mouse_pos = mp.get_property_native("mouse-pos") | ||
x = mouse_pos.x | ||
y = mouse_pos.y | ||
end | ||
|
||
local dims = mp.get_property_native("osd-dimensions") | ||
local width = (dims.w - dims.ml - dims.mr) * 2^amount | ||
local height = (dims.h - dims.mt - dims.mb) * 2^amount | ||
|
||
local old_cursor_ml = dims.ml - x | ||
local cursor_ml = old_cursor_ml * 2^amount | ||
local 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: | ||
local align = 2 * (ml - mp.get_property_native("video-pan-x") * width) | ||
/ (dims.w - width) - 1 | ||
command = command .. "no-osd set video-align-x " .. | ||
math.min(1, math.max(align, -1)) .. ";" | ||
|
||
local mt = (dims.mt - y) * 2^amount + y | ||
align = 2 * (mt - mp.get_property_native("video-pan-y") * height) | ||
/ (dims.h - height) - 1 | ||
command = command .. "no-osd set video-align-y " .. | ||
math.min(1, math.max(align, -1)) | ||
|
||
mp.command(command) | ||
end, { complex = true, scalable = true }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it need to be changed? Could we use Ctrl+Alt modifier for new behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason not to have cursor-centric-zoom on the wheel? It is more convenient, also according to nanahi ctrl+wheel "makes "pinch to zoom" with touchpads and touchscreens work out of box on Windows, since by default applications receive these key inputs for pinch gesture.", so it needs to be bind to ctrl+wheel to work with pinch gestures by default.
I have no idea what numpad bindings have to do with cursor-centric-zoom, the numpad is not a cursor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, if you think it is more convenient this way. I think it is still valuable to control zoom without messing up video positioning completely on each step. But I guess by default it can be cursor centric.
Note that same issues applies, if lua is disabled in mpv build, it probably should fallback to normal video-zoom.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can still use the Alt key bindings for that, we didn't even have Ctrl+wheel until recently.
I removed the Alt+Arrow bindings so you do want to implement a fallback system just for this? I guess we can define alternative bindings with some keyword that input.c can recognize?