From 441d54f7f72c4ef1dab277339893b0688cc55f92 Mon Sep 17 00:00:00 2001 From: Matt Guerrette Date: Sun, 25 Aug 2024 21:44:39 -0400 Subject: [PATCH] Backends: SDL3: Fix macOS mouse position incorrect for fullscreen apps This commit fixes an issue with macOS on devices with a notch. SDL3 no longer provides a client area that encompasses the notch, so any reporting of the mouse location must factor this in for fullscreen SDL3 apps on macOS. SDL3 developers suggested using SDL_GetMouseState() to retrieve the correct location until they can find a solution for rendering into the notch area. --- backends/imgui_impl_sdl3.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/backends/imgui_impl_sdl3.cpp b/backends/imgui_impl_sdl3.cpp index deb8c7925dc5..a218db0ee7c6 100644 --- a/backends/imgui_impl_sdl3.cpp +++ b/backends/imgui_impl_sdl3.cpp @@ -582,6 +582,21 @@ static void ImGui_ImplSDL3_UpdateMouseData() float mouse_x_global, mouse_y_global; int window_x, window_y; SDL_GetGlobalMouseState(&mouse_x_global, &mouse_y_global); +#if defined(SDL_PLATFORM_MACOS) + // On macOS SDL3 no longer renders fullscreen windows into the notch area + // on devices with such hardware, but will still report the global mouse state relative + // to the entire display. + // This results in incorrect mouse location data, as the mouse should be reported + // relative to the drawable client area. + // To resolve this issue, SDL_GetMouseState() can be used. + uint32_t window_flags = SDL_GetWindowFlags(bd->Window); + if (window_flags & SDL_WINDOW_FULLSCREEN) + { + SDL_GetMouseState(&mouse_x_global, &mouse_y_global); + } +#endif + + SDL_GetWindowPosition(focused_window, &window_x, &window_y); io.AddMousePosEvent(mouse_x_global - window_x, mouse_y_global - window_y); }