Fixed mouse-position resolution when dropping a file

This commit is contained in:
rxi 2020-05-20 10:33:08 +01:00
parent 08ce7e2563
commit 7aabfebfa0
2 changed files with 8 additions and 3 deletions

View File

@ -317,8 +317,8 @@ function core.on_event(type, ...)
elseif type == "mousewheel" then
core.root_view:on_mouse_wheel(...)
elseif type == "filedropped" then
local mx, my = core.root_view.mouse.x, core.root_view.mouse.y
local ok, doc = core.try(core.open_doc, select(1, ...))
local filename, mx, my = ...
local ok, doc = core.try(core.open_doc, filename)
if ok then
local node = core.root_view.root_node:get_child_overlapping_point(mx, my)
node:set_active_view(node.active_view)

View File

@ -36,6 +36,7 @@ static char* key_name(char *dst, int sym) {
static int f_poll_event(lua_State *L) {
char buf[16];
int mx, my, wx, wy;
SDL_Event e;
top:
@ -66,10 +67,14 @@ top:
goto top;
case SDL_DROPFILE:
SDL_GetGlobalMouseState(&mx, &my);
SDL_GetWindowPosition(window, &wx, &wy);
lua_pushstring(L, "filedropped");
lua_pushstring(L, e.drop.file);
lua_pushnumber(L, mx - wx);
lua_pushnumber(L, my - wy);
SDL_free(e.drop.file);
return 2;
return 4;
case SDL_KEYDOWN:
lua_pushstring(L, "keypressed");