From c918b4d246df3b1ca0c7e6353c09de8316feeff1 Mon Sep 17 00:00:00 2001 From: Selgesel Date: Sat, 18 Sep 2021 09:45:02 +0300 Subject: [PATCH] [3.x] Release pressed events when the window is blurred on HTML5 platform --- platform/javascript/os_javascript.cpp | 6 ++++++ platform/javascript/os_javascript.h | 1 + 2 files changed, 7 insertions(+) diff --git a/platform/javascript/os_javascript.cpp b/platform/javascript/os_javascript.cpp index 4785d1d2bf5..033260cd1fd 100644 --- a/platform/javascript/os_javascript.cpp +++ b/platform/javascript/os_javascript.cpp @@ -121,6 +121,11 @@ EM_BOOL OS_JavaScript::fullscreen_change_callback(int p_event_type, const Emscri return false; } +EM_BOOL OS_JavaScript::blur_callback(int p_event_type, const EmscriptenFocusEvent *p_event, void *p_user_data) { + get_singleton()->input->release_pressed_events(); + return false; +} + void OS_JavaScript::set_video_mode(const VideoMode &p_video_mode, int p_screen) { video_mode = p_video_mode; } @@ -884,6 +889,7 @@ Error OS_JavaScript::initialize(const VideoMode &p_desired, int p_video_driver, SET_EM_CALLBACK(canvas_id, mousedown, mouse_button_callback) SET_EM_WINDOW_CALLBACK(mousemove, mousemove_callback) SET_EM_WINDOW_CALLBACK(mouseup, mouse_button_callback) + SET_EM_WINDOW_CALLBACK(blur, blur_callback) SET_EM_CALLBACK(canvas_id, wheel, wheel_callback) SET_EM_CALLBACK(canvas_id, touchstart, touch_press_callback) SET_EM_CALLBACK(canvas_id, touchmove, touchmove_callback) diff --git a/platform/javascript/os_javascript.h b/platform/javascript/os_javascript.h index 43e3a99dda2..5295e76a616 100644 --- a/platform/javascript/os_javascript.h +++ b/platform/javascript/os_javascript.h @@ -72,6 +72,7 @@ private: static Point2 compute_position_in_canvas(int x, int y); static EM_BOOL fullscreen_change_callback(int p_event_type, const EmscriptenFullscreenChangeEvent *p_event, void *p_user_data); + static EM_BOOL blur_callback(int p_event_type, const EmscriptenFocusEvent *p_event, void *p_user_data); static EM_BOOL keydown_callback(int p_event_type, const EmscriptenKeyboardEvent *p_event, void *p_user_data); static EM_BOOL keypress_callback(int p_event_type, const EmscriptenKeyboardEvent *p_event, void *p_user_data);