From 9959578cbec4e959d85fb9ec50e7988a43b6c28b Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Sat, 31 Jul 2021 16:40:14 +1000 Subject: [PATCH] [client] app: prevent buttons/keys from being held when focus is lost --- client/src/app.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/client/src/app.c b/client/src/app.c index 59fcf718..fe9b869b 100644 --- a/client/src/app.c +++ b/client/src/app.c @@ -76,6 +76,17 @@ void app_updateCursorPos(double x, double y) void app_handleFocusEvent(bool focused) { g_state.focused = focused; + + if (!focused && g_state.overlayInput) + { + // release any imgui buttons/keys if we lost focus + g_state.io->MouseDown[ImGuiMouseButton_Left ] = false; + g_state.io->MouseDown[ImGuiMouseButton_Right ] = false; + g_state.io->MouseDown[ImGuiMouseButton_Middle] = false; + for(int key = 0; key < sizeof(g_state.io->KeysDown) / sizeof(bool); key++) + g_state.io->KeysDown[key] = false; + } + if (!core_inputEnabled()) { if (!focused && g_params.minimizeOnFocusLoss && app_getFullscreen()) @@ -121,6 +132,15 @@ void app_handleEnterEvent(bool entered) g_cursor.inWindow = false; core_setCursorInView(false); + // stop the user being able to drag windows off the screen and work around + // the mouse button release being missed due to not being in capture mode. + if (g_state.overlayInput) + { + g_state.io->MouseDown[ImGuiMouseButton_Left ] = false; + g_state.io->MouseDown[ImGuiMouseButton_Right ] = false; + g_state.io->MouseDown[ImGuiMouseButton_Middle] = false; + } + if (!core_inputEnabled()) return;