Skip to content

Commit

Permalink
Release pressed events when the window is blurred on HTML5 platform
Browse files Browse the repository at this point in the history
  • Loading branch information
Selgesel committed Sep 23, 2021
1 parent 88b347d commit 5d1d9f2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions platform/javascript/display_server_javascript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,12 @@ void DisplayServerJavaScript::virtual_keyboard_hide() {
godot_js_display_vk_hide();
}

// Window blur callback
EM_BOOL DisplayServerJavaScript::blur_callback(int p_event_type, const EmscriptenFocusEvent *p_event, void *p_user_data) {
Input::get_singleton()->release_pressed_events();
return false;
}

// Gamepad
void DisplayServerJavaScript::gamepad_callback(int p_index, int p_connected, const char *p_id, const char *p_guid) {
Input *input = Input::get_singleton();
Expand Down Expand Up @@ -797,6 +803,7 @@ DisplayServerJavaScript::DisplayServerJavaScript(const String &p_rendering_drive
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)
Expand Down
2 changes: 2 additions & 0 deletions platform/javascript/display_server_javascript.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class DisplayServerJavaScript : public DisplayServer {
static EM_BOOL touch_press_callback(int p_event_type, const EmscriptenTouchEvent *p_event, void *p_user_data);
static EM_BOOL touchmove_callback(int p_event_type, const EmscriptenTouchEvent *p_event, void *p_user_data);

static EM_BOOL blur_callback(int p_event_type, const EmscriptenFocusEvent *p_event, void *p_user_data);

static void gamepad_callback(int p_index, int p_connected, const char *p_id, const char *p_guid);
void process_joypads();

Expand Down

0 comments on commit 5d1d9f2

Please sign in to comment.