From 98ec844388af6fbf6432f8c552dbef1fd92ace13 Mon Sep 17 00:00:00 2001 From: Charlie Birks Date: Tue, 13 Sep 2016 00:03:39 -0700 Subject: [PATCH] send mouse move on enter/leave --- src/video/emscripten/SDL_emscriptenevents.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/video/emscripten/SDL_emscriptenevents.c b/src/video/emscripten/SDL_emscriptenevents.c index 67937b53b..fc72e0f49 100644 --- a/src/video/emscripten/SDL_emscriptenevents.c +++ b/src/video/emscripten/SDL_emscriptenevents.c @@ -350,6 +350,22 @@ Emscripten_HandleMouseFocus(int eventType, const EmscriptenMouseEvent *mouseEven { SDL_WindowData *window_data = userData; + int mx = mouseEvent->canvasX, my = mouseEvent->canvasY; + EmscriptenPointerlockChangeEvent pointerlock_status; + + /* check for pointer lock */ + emscripten_get_pointerlock_status(&pointerlock_status); + + if (!pointerlock_status.isActive) { + /* rescale (in case canvas is being scaled)*/ + double client_w, client_h; + emscripten_get_element_css_size(NULL, &client_w, &client_h); + + mx = mx * (window_data->window->w / (client_w * window_data->pixel_ratio)); + my = my * (window_data->window->h / (client_h * window_data->pixel_ratio)); + SDL_SendMouseMotion(window_data->window, 0, pointerlock_status.isActive, mx, my); + } + SDL_SetMouseFocus(eventType == EMSCRIPTEN_EVENT_MOUSEENTER ? window_data->window : NULL); return 1; }