[client] imgui: improved overlay input handling

1. Overlay always releases confines.
2. Overlay turns off mouse sync with guest.
This commit is contained in:
Quantum 2021-07-29 05:29:33 -04:00 committed by Geoffrey McRae
parent d9a3b6523c
commit c991de7ccd
2 changed files with 13 additions and 10 deletions

View File

@ -241,8 +241,7 @@ void app_handleButtonPress(int button)
int igButton = mapSpiceToImGuiButton(button); int igButton = mapSpiceToImGuiButton(button);
if (igButton != -1) if (igButton != -1)
g_state.io->MouseDown[igButton] = true; g_state.io->MouseDown[igButton] = true;
if (g_state.io->WantCaptureMouse) return;
return;
} }
if (!core_inputEnabled() || !g_cursor.inView) if (!core_inputEnabled() || !g_cursor.inView)
@ -261,8 +260,7 @@ void app_handleButtonRelease(int button)
int igButton = mapSpiceToImGuiButton(button); int igButton = mapSpiceToImGuiButton(button);
if (igButton != -1) if (igButton != -1)
g_state.io->MouseDown[igButton] = false; g_state.io->MouseDown[igButton] = false;
if (g_state.io->WantCaptureMouse) return;
return;
} }
if (!core_inputEnabled()) if (!core_inputEnabled())
@ -291,8 +289,7 @@ void app_handleKeyPress(int sc)
if (g_state.overlayInput) if (g_state.overlayInput)
{ {
g_state.io->KeysDown[sc] = true; g_state.io->KeysDown[sc] = true;
if (g_state.io->WantCaptureKeyboard) return;
return;
} }
if (!core_inputEnabled()) if (!core_inputEnabled())
@ -323,7 +320,7 @@ void app_handleKeyRelease(int sc)
{ {
if (g_state.escapeAction == -1) if (g_state.escapeAction == -1)
{ {
if (!g_state.escapeHelp && g_params.useSpiceInput) if (!g_state.escapeHelp && g_params.useSpiceInput && !g_state.overlayInput)
core_setGrab(!g_cursor.grab); core_setGrab(!g_cursor.grab);
} }
else else
@ -346,8 +343,7 @@ void app_handleKeyRelease(int sc)
if (g_state.overlayInput) if (g_state.overlayInput)
{ {
g_state.io->KeysDown[sc] = false; g_state.io->KeysDown[sc] = false;
if (g_state.io->WantCaptureKeyboard) return;
return;
} }
// avoid sending key up events when we didn't send a down // avoid sending key up events when we didn't send a down
@ -373,6 +369,9 @@ void app_handleKeyRelease(int sc)
void app_handleMouseRelative(double normx, double normy, void app_handleMouseRelative(double normx, double normy,
double rawx, double rawy) double rawx, double rawy)
{ {
if (g_state.overlayInput)
return;
if (g_cursor.grab) if (g_cursor.grab)
{ {
if (g_params.rawMouse) if (g_params.rawMouse)
@ -392,7 +391,7 @@ void app_handleMouseRelative(double normx, double normy,
void app_handleMouseBasic() void app_handleMouseBasic()
{ {
/* do not pass mouse events to the guest if we do not have focus */ /* do not pass mouse events to the guest if we do not have focus */
if (!g_cursor.guest.valid || !g_state.haveSrcSize || !g_state.focused) if (!g_cursor.guest.valid || !g_state.haveSrcSize || !g_state.focused || g_state.overlayInput)
return; return;
if (!core_inputEnabled()) if (!core_inputEnabled())

View File

@ -137,7 +137,11 @@ static void bind_toggleOverlay(int sc, void * opaque)
{ {
g_state.overlayInput ^= true; g_state.overlayInput ^= true;
if (g_state.overlayInput) if (g_state.overlayInput)
{
g_state.io->ConfigFlags &= ~ImGuiConfigFlags_NoMouse; g_state.io->ConfigFlags &= ~ImGuiConfigFlags_NoMouse;
core_setGrabQuiet(false);
core_setCursorInView(false);
}
else else
g_state.io->ConfigFlags |= ImGuiConfigFlags_NoMouse; g_state.io->ConfigFlags |= ImGuiConfigFlags_NoMouse;
} }