diff options
author | Guilherme Felipe <guilhermefelipecgs@gmail.com> | 2019-04-15 14:41:44 -0300 |
---|---|---|
committer | Guilherme Felipe <guilhermefelipecgs@gmail.com> | 2019-04-27 12:05:12 -0300 |
commit | c709dfdf06f6b09b61c1f34ff5a32cbfa8acc523 (patch) | |
tree | eb330830f3f29f623134806d29ac0e1cc09a1fe1 | |
parent | 260530f01caa8ea3e2fb7bfda04f4bd718ae14f5 (diff) |
[Input] Release keys/actions pressed if window loses focus
Co-authored-by: bruvzg <7645683+bruvzg@users.noreply.github.com>
Co-authored-by: Marcelo Fernandez <marcelofg55@gmail.com>
-rw-r--r-- | main/input_default.cpp | 13 | ||||
-rw-r--r-- | main/input_default.h | 1 | ||||
-rw-r--r-- | platform/osx/os_osx.mm | 5 | ||||
-rw-r--r-- | platform/windows/os_windows.cpp | 2 | ||||
-rw-r--r-- | platform/x11/os_x11.cpp | 2 |
5 files changed, 23 insertions, 0 deletions
diff --git a/main/input_default.cpp b/main/input_default.cpp index 6c3252ad1a..a939d77a1e 100644 --- a/main/input_default.cpp +++ b/main/input_default.cpp @@ -677,6 +677,19 @@ void InputDefault::set_use_accumulated_input(bool p_enable) { use_accumulated_input = p_enable; } +void InputDefault::release_pressed_events() { + + flush_accumulated_events(); // this is needed to release actions strengths + + keys_pressed.clear(); + joy_buttons_pressed.clear(); + _joy_axis.clear(); + + for (Map<StringName, InputDefault::Action>::Element *E = action_state.front(); E; E = E->next()) { + action_release(E->key()); + } +} + InputDefault::InputDefault() { use_accumulated_input = true; diff --git a/main/input_default.h b/main/input_default.h index f9b4cbbd57..80ee17656c 100644 --- a/main/input_default.h +++ b/main/input_default.h @@ -272,6 +272,7 @@ public: virtual void flush_accumulated_events(); virtual void set_use_accumulated_input(bool p_enable); + virtual void release_pressed_events(); InputDefault(); }; diff --git a/platform/osx/os_osx.mm b/platform/osx/os_osx.mm index 5a4c0593bc..945290ac73 100644 --- a/platform/osx/os_osx.mm +++ b/platform/osx/os_osx.mm @@ -337,6 +337,11 @@ static CVReturn DisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeSt } - (void)windowDidMove:(NSNotification *)notification { + + if (OS_OSX::singleton->get_main_loop()) { + OS_OSX::singleton->input->release_pressed_events(); + } + /* [window->nsgl.context update]; diff --git a/platform/windows/os_windows.cpp b/platform/windows/os_windows.cpp index 193a3fa2c6..c3cadea855 100644 --- a/platform/windows/os_windows.cpp +++ b/platform/windows/os_windows.cpp @@ -346,6 +346,7 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) control_mem = false; shift_mem = false; } else { // WM_INACTIVE + input->release_pressed_events(); main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT); alt_mem = false; }; @@ -786,6 +787,7 @@ LRESULT OS_Windows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) } break; case WM_ENTERSIZEMOVE: { + input->release_pressed_events(); move_timer_id = SetTimer(hWnd, 1, USER_TIMER_MINIMUM, (TIMERPROC)NULL); } break; case WM_EXITSIZEMOVE: { diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index f6161a9485..8d857de239 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -2076,7 +2076,9 @@ void OS_X11::process_xevents() { case FocusOut: window_has_focus = false; + input->release_pressed_events(); main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT); + if (mouse_mode_grab) { //dear X11, I try, I really try, but you never work, you do whathever you want. if (mouse_mode == MOUSE_MODE_CAPTURED) { |