From f49948506b7108d3738bff949a85ccbf62fbcd34 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Sat, 31 Jul 2021 20:51:08 +1000 Subject: [PATCH] [client] move imgui input state reset to it's own core function --- client/src/app.c | 10 ++-------- client/src/core.c | 10 ++++++++++ client/src/core.h | 1 + 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/client/src/app.c b/client/src/app.c index 34ba90c0..623dd916 100644 --- a/client/src/app.c +++ b/client/src/app.c @@ -77,15 +77,9 @@ void app_handleFocusEvent(bool focused) { g_state.focused = focused; + // release any imgui buttons/keys if we lost focus 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; - } + core_resetOverlayInputState(); if (!core_inputEnabled()) { diff --git a/client/src/core.c b/client/src/core.c index fa851cd9..c629dcae 100644 --- a/client/src/core.c +++ b/client/src/core.c @@ -25,6 +25,7 @@ #include "common/time.h" #include "common/debug.h" +#include "common/array.h" #include #include @@ -522,3 +523,12 @@ void core_handleMouseNormal(double ex, double ey) if (!spice_mouse_motion(x, y)) DEBUG_ERROR("failed to send mouse motion message"); } + +void core_resetOverlayInputState(void) +{ + 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 < ARRAY_LENGTH(g_state.io->KeysDown); key++) + g_state.io->KeysDown[key] = false; +} diff --git a/client/src/core.h b/client/src/core.h index 19d82395..8ccaa942 100644 --- a/client/src/core.h +++ b/client/src/core.h @@ -36,5 +36,6 @@ void core_stopFrameThread(void); void core_handleGuestMouseUpdate(void); void core_handleMouseGrabbed(double ex, double ey); void core_handleMouseNormal(double ex, double ey); +void core_resetOverlayInputState(void); #endif