1
0
mirror of https://github.com/mpv-player/mpv synced 2025-03-25 04:38:01 +00:00

lua/js: mp.get_mouse_pos: use the mouse-pos property

mp.get_mouse_pos() is undocumented and is no longer required - the
property can be used officially by any client now, however, osc.lua
uses it, and also some user scripts learnt to rely on it, so we keep
it - as a trivial wrapper around the new mouse-pos property.
This commit is contained in:
Avi Halachmi (:avih) 2020-11-16 18:15:18 +02:00 committed by avih
parent a768667956
commit 0d5055fe93
4 changed files with 6 additions and 22 deletions

View File

@ -781,16 +781,6 @@ static void push_nums_obj(js_State *J, const char * const names[],
}
}
// args: none, return: object with properties x, y
static void script_get_mouse_pos(js_State *J)
{
int x, y;
mp_input_get_mouse_pos(jctx(J)->mpctx->input, &x, &y);
const char * const names[] = {"x", "y", NULL};
const double vals[] = {x, y};
push_nums_obj(J, names, vals);
}
// args: input-section-name, x0, y0, x1, y1
static void script_input_set_section_mouse_area(js_State *J)
{
@ -1181,7 +1171,6 @@ static const struct fn_entry main_fns[] = {
FN_ENTRY(get_wakeup_pipe, 0),
FN_ENTRY(_hook_add, 3),
FN_ENTRY(_hook_continue, 1),
FN_ENTRY(get_mouse_pos, 0),
FN_ENTRY(input_set_section_mouse_area, 5),
FN_ENTRY(last_error, 0),
FN_ENTRY(_set_last_error, 1),

View File

@ -663,6 +663,7 @@ mp.get_script_file = function() { return mp.script_file };
mp.get_script_directory = function() { return mp.script_path };
mp.get_time = function() { return mp.get_time_ms() / 1000 };
mp.utils.getcwd = function() { return mp.get_property("working-directory") };
mp.get_mouse_pos = function() { return mp.get_property_native("mouse-pos") };
mp.dispatch_event = dispatch_event;
mp.process_timers = process_timers;
mp.notify_idle_observers = notify_idle_observers;

View File

@ -991,16 +991,6 @@ static int script_raw_abort_async_command(lua_State *L)
return 0;
}
static int script_get_mouse_pos(lua_State *L)
{
struct MPContext *mpctx = get_mpctx(L);
int px, py;
mp_input_get_mouse_pos(mpctx->input, &px, &py);
lua_pushnumber(L, px);
lua_pushnumber(L, py);
return 2;
}
static int script_get_time(lua_State *L)
{
struct script_ctx *ctx = get_ctx(L);
@ -1242,7 +1232,6 @@ static const struct fn_entry main_fns[] = {
AF_ENTRY(set_property_native),
FN_ENTRY(raw_observe_property),
FN_ENTRY(raw_unobserve_property),
FN_ENTRY(get_mouse_pos),
FN_ENTRY(get_time),
FN_ENTRY(input_set_section_mouse_area),
FN_ENTRY(format_time),

View File

@ -42,6 +42,11 @@ function mp.input_disable_section(section)
mp.commandv("disable-section", section)
end
function mp.get_mouse_pos()
local m = mp.get_property_native("mouse-pos")
return m.x, m.y
end
-- For dispatching script-binding. This is sent as:
-- script-message-to $script_name $binding_name $keystate
-- The array is indexed by $binding_name, and has functions like this as value: