From e8edf24edc1c7414456e25b3516660872bf8b820 Mon Sep 17 00:00:00 2001 From: Ignacio Sanchez Gines <863613+drhelius@users.noreply.github.com> Date: Thu, 2 Jan 2025 11:22:58 +0100 Subject: [PATCH] Workaround to avoid mouse offset in Macbooks with notch --- platforms/desktop-shared/imgui/imgui_impl_sdl2.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/platforms/desktop-shared/imgui/imgui_impl_sdl2.cpp b/platforms/desktop-shared/imgui/imgui_impl_sdl2.cpp index 2e5af0ea..37dce3f8 100644 --- a/platforms/desktop-shared/imgui/imgui_impl_sdl2.cpp +++ b/platforms/desktop-shared/imgui/imgui_impl_sdl2.cpp @@ -688,8 +688,13 @@ static void ImGui_ImplSDL2_UpdateMouseData() SDL_WarpMouseInWindow(bd->Window, (int)io.MousePos.x, (int)io.MousePos.y); } + bool workaround_for_notch = false; +#if defined(__APPLE__) + workaround_for_notch = (SDL_GetWindowFlags(bd->Window) & SDL_WINDOW_FULLSCREEN) != 0; +#endif + // (Optional) Fallback to provide mouse position when focused (SDL_MOUSEMOTION already provides this when hovered or captured) - if (bd->MouseCanUseGlobalState && bd->MouseButtonsDown == 0) + if (!workaround_for_notch && bd->MouseCanUseGlobalState && bd->MouseButtonsDown == 0) { // Single-viewport mode: mouse position in client window coordinates (io.MousePos is (0,0) when the mouse is on the upper-left corner of the app window) // Multi-viewport mode: mouse position in OS absolute coordinates (io.MousePos is (0,0) when the mouse is on the upper-left of the primary monitor)