From edf4fdfb1f33ae194715992d21c538c8d3a19e89 Mon Sep 17 00:00:00 2001 From: llyyr Date: Sun, 9 Mar 2025 07:12:25 +0530 Subject: [PATCH] positioning.lua: clamp values within {-1, 1} for video-align-{x,y} Otherwise you can move your cursor outside the mpv window while having align-to-cursor "held" and make the script send illegal values --- player/lua/positioning.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/player/lua/positioning.lua b/player/lua/positioning.lua index 679bfe52b9..611eec67c5 100644 --- a/player/lua/positioning.lua +++ b/player/lua/positioning.lua @@ -83,8 +83,10 @@ local align_to_cursor_bound = false local function align_to_cursor(_, mouse_pos) local dims = mp.get_property_native("osd-dimensions") - 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) + local align = (mouse_pos.x * 2 - dims.w) / dims.w + mp.set_property("video-align-x", clamp(align, -1, 1)) + align = (mouse_pos.y * 2 - dims.h) / dims.h + mp.set_property("video-align-y", clamp(align, -1, 1)) end mp.add_key_binding(nil, "align-to-cursor", function (t)