diff --git a/data/core/init.lua b/data/core/init.lua index cc4b46d8..95eb7973 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -948,26 +948,18 @@ end function core.step() -- handle events local did_keymap = false - local mouse_moved = false - local mouse = { x = 0, y = 0, dx = 0, dy = 0 } - for type, a,b,c,d in system.poll_event do - if type == "mousemoved" then - mouse_moved = true - mouse.x, mouse.y = a, b - mouse.dx, mouse.dy = mouse.dx + c, mouse.dy + d - elseif type == "textinput" and did_keymap then + if type == "textinput" and did_keymap then did_keymap = false + elseif type == "mousemoved" then + core.try(core.on_event, type, a, b, c, d) else local _, res = core.try(core.on_event, type, a, b, c, d) did_keymap = res or did_keymap end core.redraw = true end - if mouse_moved then - core.try(core.on_event, "mousemoved", mouse.x, mouse.y, mouse.dx, mouse.dy) - end local width, height = renderer.get_size() diff --git a/src/api/system.c b/src/api/system.c index bbe0801b..d00a9e47 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -201,6 +201,14 @@ top: return 4; case SDL_MOUSEMOTION: + SDL_PumpEvents(); + SDL_Event event_plus; + while (SDL_PeepEvents(&event_plus, 1, SDL_GETEVENT, SDL_MOUSEMOTION, SDL_MOUSEMOTION) > 0) { + e.motion.x = event_plus.motion.x; + e.motion.y = event_plus.motion.y; + e.motion.xrel += event_plus.motion.xrel; + e.motion.yrel += event_plus.motion.yrel; + } lua_pushstring(L, "mousemoved"); lua_pushnumber(L, e.motion.x); lua_pushnumber(L, e.motion.y);