Skip to content

Commit

Permalink
Workaround to avoid mouse offset in Macbooks with notch
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Jan 2, 2025
1 parent ac16000 commit e8edf24
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion platforms/desktop-shared/imgui/imgui_impl_sdl2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e8edf24

Please sign in to comment.