From edaf5a386f5f9adc42b86222e4086108159949ce Mon Sep 17 00:00:00 2001 From: bicarus-dev <202771338+bicarus-dev@users.noreply.github.com> Date: Wed, 2 Apr 2025 18:32:30 -0700 Subject: [PATCH] overlay: fix mouse cursor getting stuck in wrong shape when leaving and coming back to window (#283) ## Link to GitHub Issue, if one exists Fixes #27 ## Description of change In standalone configurator mode, when a mouse cursor moves outside the window and comes back, it may get stuck in the wrong cursor type (e.g., get stuck in horizontal resize mode). This is a side effect of software rendering we do that doesn't deal nicely with mouse events (i.e., not at all). ## Compiling Should be fine. ## Testing Testing spicecfg, spice -cfg, spice64 -cfg, and in-game overlay. --- src/spice2x/overlay/imgui/impl_spice.cpp | 28 +++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/spice2x/overlay/imgui/impl_spice.cpp b/src/spice2x/overlay/imgui/impl_spice.cpp index d8d73cb..2d2dd18 100644 --- a/src/spice2x/overlay/imgui/impl_spice.cpp +++ b/src/spice2x/overlay/imgui/impl_spice.cpp @@ -2,6 +2,7 @@ #include +#include "cfg/configurator.h" #include "games/io.h" #include "launcher/launcher.h" #include "launcher/superexit.h" @@ -378,10 +379,27 @@ void ImGui_ImplSpice_NewFrame() { // update OS mouse position ImGui_ImplSpice_UpdateMousePos(); - // update OS mouse cursor with the cursor requested by imgui - ImGuiMouseCursor mouse_cursor = io.MouseDrawCursor ? ImGuiMouseCursor_None : ImGui::GetMouseCursor(); - if (g_LastMouseCursor != mouse_cursor) { - g_LastMouseCursor = mouse_cursor; - ImGui_ImplSpice_UpdateMouseCursor(); + if (cfg::CONFIGURATOR_STANDALONE) { + // if cursor is inside the client area, always set the OS cursor to what ImGui wants + // this is to deal with cases where mouse cursor changes outside the client rect and comes + // back into the window + // i'm sure there might be better ways to deal with this but this works so whatever, right? + RECT client_rect; + if (GetClientRect(g_hWnd, &client_rect)) { + POINT cursor; + if (GetCursorPos(&cursor) && ScreenToClient(g_hWnd, &cursor)) { + if (client_rect.left < cursor.x && cursor.x < client_rect.right && + client_rect.top < cursor.y && cursor.y < client_rect.bottom) { + ImGui_ImplSpice_UpdateMouseCursor(); + } + } + } + } else { + // update OS mouse cursor with the cursor requested by imgui + ImGuiMouseCursor mouse_cursor = io.MouseDrawCursor ? ImGuiMouseCursor_None : ImGui::GetMouseCursor(); + if (g_LastMouseCursor != mouse_cursor) { + g_LastMouseCursor = mouse_cursor; + ImGui_ImplSpice_UpdateMouseCursor(); + } } }