diff --git a/src/imgui/renderer/imgui_core.cpp b/src/imgui/renderer/imgui_core.cpp index 311e86a3c..5bf8d56e9 100644 --- a/src/imgui/renderer/imgui_core.cpp +++ b/src/imgui/renderer/imgui_core.cpp @@ -83,7 +83,7 @@ void Initialize(const ::Vulkan::Instance& instance, const Frontend::WindowSDL& w StyleColorsDark(); ::Core::Devtools::Layer::SetupSettings(); - Sdl::Init(window.GetSdlWindow()); + Sdl::Init(&window); const Vulkan::InitInfo vk_info{ .instance = instance.GetInstance(), diff --git a/src/imgui/renderer/imgui_impl_sdl3.cpp b/src/imgui/renderer/imgui_impl_sdl3.cpp index 230d396f0..a97c2dbb9 100644 --- a/src/imgui/renderer/imgui_impl_sdl3.cpp +++ b/src/imgui/renderer/imgui_impl_sdl3.cpp @@ -9,6 +9,9 @@ // SDL #include + +#include "sdl_window.h" +#include "video_core/renderer_vulkan/vk_instance.h" #if defined(__APPLE__) #include #endif @@ -23,6 +26,9 @@ namespace ImGui::Sdl { // SDL Data struct SdlData { + // SDL Wrapper + const Frontend::WindowSDL* wrapper{}; + SDL_Window* window{}; SDL_WindowID window_id{}; Uint64 time{}; @@ -501,7 +507,7 @@ static void SetupPlatformHandles(ImGuiViewport* viewport, SDL_Window* window) { #endif } -bool Init(SDL_Window* window) { +bool Init(const Frontend::WindowSDL* wrapper) { ImGuiIO& io = ImGui::GetIO(); IMGUI_CHECKVERSION(); IM_ASSERT(io.BackendPlatformUserData == nullptr && "Already initialized a platform backend!"); @@ -514,8 +520,9 @@ bool Init(SDL_Window* window) { io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos; // We can honor io.WantSetMousePos requests // (optional, rarely used) - bd->window = window; - bd->window_id = SDL_GetWindowID(window); + bd->wrapper = wrapper; + bd->window = wrapper->GetSdlWindow(); + bd->window_id = SDL_GetWindowID(bd->window); ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); platform_io.Platform_SetClipboardTextFn = SetClipboardText; @@ -543,7 +550,7 @@ bool Init(SDL_Window* window) { // Set platform dependent data in viewport // Our mouse update function expect PlatformHandle to be filled for the main viewport ImGuiViewport* main_viewport = ImGui::GetMainViewport(); - SetupPlatformHandles(main_viewport, window); + SetupPlatformHandles(main_viewport, bd->window); // From 2.0.5: Set SDL hint to receive mouse click events on window focus, otherwise SDL doesn't // emit the event. Without this, when clicking to gain focus, our widgets wouldn't activate even @@ -593,7 +600,6 @@ static void UpdateMouseData() { // (below) // SDL_CaptureMouse() let the OS know e.g. that our imgui drag outside the SDL window boundaries // shouldn't e.g. trigger other operations outside - SDL_CaptureMouse((bd->mouse_buttons_down != 0) ? true : false); SDL_Window* focused_window = SDL_GetKeyboardFocus(); const bool is_app_focused = (bd->window == focused_window); @@ -662,7 +668,9 @@ static void UpdateMouseCursor() { SDL_SetCursor(expected_cursor); // SDL function doesn't have an early out (see #6113) bd->mouse_last_cursor = expected_cursor; } - SDL_ShowCursor(); + if (!bd->wrapper->isCapturingMouse()) { + SDL_ShowCursor(); + } } } diff --git a/src/imgui/renderer/imgui_impl_sdl3.h b/src/imgui/renderer/imgui_impl_sdl3.h index 59b1a6856..a67cea65d 100644 --- a/src/imgui/renderer/imgui_impl_sdl3.h +++ b/src/imgui/renderer/imgui_impl_sdl3.h @@ -10,9 +10,13 @@ struct SDL_Renderer; struct SDL_Gamepad; typedef union SDL_Event SDL_Event; +namespace Frontend { +class WindowSDL; +} + namespace ImGui::Sdl { -bool Init(SDL_Window* window); +bool Init(const Frontend::WindowSDL* window); void Shutdown(); void NewFrame(); bool ProcessEvent(const SDL_Event* event); diff --git a/src/sdl_window.h b/src/sdl_window.h index 4bcaf46d1..ee7e23e02 100644 --- a/src/sdl_window.h +++ b/src/sdl_window.h @@ -58,6 +58,10 @@ public: return is_open; } + bool isCapturingMouse() const { + return is_capturing_mouse; + } + [[nodiscard]] SDL_Window* GetSdlWindow() const { return window; } @@ -83,6 +87,8 @@ private: SDL_Window* window{}; bool is_shown{}; bool is_open{true}; + + bool is_capturing_mouse{false}; }; } // namespace Frontend