Skip to content

Commit aa83d5d

Browse files
committed
Backends: SDL2, SDL3: Only start SDL_CaptureMouse() when mouse is being dragged. (#6410, #3650)
To mitigate issues with e.g. Linux debuggers not claiming capture back.
1 parent aaacb01 commit aa83d5d

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

backends/imgui_impl_sdl2.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
// CHANGELOG
2323
// (minor and older changes stripped away, please see git history for details)
24+
// 2025-02-26: Only start SDL_CaptureMouse() when mouse is being dragged, to mitigate issues with e.g.Linux debuggers not claiming capture back. (#6410, #3650)
2425
// 2025-02-24: Avoid calling SDL_GetGlobalMouseState() when mouse is in relative mode.
2526
// 2025-02-18: Added ImGuiMouseCursor_Wait and ImGuiMouseCursor_Progress mouse cursor support.
2627
// 2025-02-10: Using SDL_OpenURL() in platform_io.Platform_OpenInShellFn handler.
@@ -609,8 +610,14 @@ static void ImGui_ImplSDL2_UpdateMouseData()
609610

610611
// We forward mouse input when hovered or captured (via SDL_MOUSEMOTION) or when focused (below)
611612
#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE
612-
// 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
613-
SDL_CaptureMouse((bd->MouseButtonsDown != 0) ? SDL_TRUE : SDL_FALSE);
613+
// - SDL_CaptureMouse() let the OS know e.g. that our drags can extend outside of parent boundaries (we want updated position) and shouldn't trigger other operations outside.
614+
// - Debuggers under Linux tends to leave captured mouse on break, which may be very inconvenient, so to migitate the issue we wait until mouse has moved to begin capture.
615+
bool want_capture = false;
616+
for (int button_n = 0; button_n < ImGuiMouseButton_COUNT && !want_capture; button_n++)
617+
if (ImGui::IsMouseDragging(button_n, 1.0f))
618+
want_capture = true;
619+
SDL_CaptureMouse(want_capture ? SDL_TRUE : SDL_FALSE);
620+
614621
SDL_Window* focused_window = SDL_GetKeyboardFocus();
615622
const bool is_app_focused = (bd->Window == focused_window);
616623
#else

backends/imgui_impl_sdl3.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
// CHANGELOG
2222
// (minor and older changes stripped away, please see git history for details)
23+
// 2025-02-26: Only start SDL_CaptureMouse() when mouse is being dragged, to mitigate issues with e.g.Linux debuggers not claiming capture back. (#6410, #3650)
2324
// 2025-02-24: Avoid calling SDL_GetGlobalMouseState() when mouse is in relative mode.
2425
// 2025-02-18: Added ImGuiMouseCursor_Wait and ImGuiMouseCursor_Progress mouse cursor support.
2526
// 2025-02-10: Using SDL_OpenURL() in platform_io.Platform_OpenInShellFn handler.
@@ -574,8 +575,14 @@ static void ImGui_ImplSDL3_UpdateMouseData()
574575

575576
// We forward mouse input when hovered or captured (via SDL_EVENT_MOUSE_MOTION) or when focused (below)
576577
#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE
577-
// 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
578-
SDL_CaptureMouse(bd->MouseButtonsDown != 0);
578+
// - SDL_CaptureMouse() let the OS know e.g. that our drags can extend outside of parent boundaries (we want updated position) and shouldn't trigger other operations outside.
579+
// - Debuggers under Linux tends to leave captured mouse on break, which may be very inconvenient, so to migitate the issue we wait until mouse has moved to begin capture.
580+
bool want_capture = false;
581+
for (int button_n = 0; button_n < ImGuiMouseButton_COUNT && !want_capture; button_n++)
582+
if (ImGui::IsMouseDragging(button_n, 1.0f))
583+
want_capture = true;
584+
SDL_CaptureMouse(want_capture);
585+
579586
SDL_Window* focused_window = SDL_GetKeyboardFocus();
580587
const bool is_app_focused = (bd->Window == focused_window);
581588
#else

docs/CHANGELOG.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ Other changes:
9595
and ImGuiMouseCursor_Progress cursors.
9696
- Backends: SDL2, SDL3: Avoid calling SDL_GetGlobalMouseState() when mouse is in
9797
relative mode. (#8425, #8407) [@TheMode]
98+
- Backends: SDL2, SDL3: Only start SDL_CaptureMouse() when mouse is being dragged,
99+
to mitigate issues with e.g. Linux debuggers not claiming capture back. (#6410, #3650)
98100
- Backends: OpenGL3: Lazily reinitialize embedded GL loader for when calling backend
99101
from e.g. other DLL boundaries. (#8406)
100102
- Backends: DirectX12: Fixed an issue where pre-1.91.5 legacy ImGui_ImplDX12_Init()

0 commit comments

Comments
 (0)