Skip to content

Commit b811c42

Browse files
committed
Backends: SDL2/SDL3: revert updating monitors and work area info every frame. Workaround for Windows. (#8415, #8558)
Partly revert logic from 1a7b594.
1 parent 47d1ab1 commit b811c42

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

backends/imgui_impl_sdl2.cpp

+18-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
// CHANGELOG
2727
// (minor and older changes stripped away, please see git history for details)
2828
// 2025-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
29+
// 2025-04-09: [Docking] Revert update monitors and work areas information every frame. Only do it on Windows. (#8415, #8558)
2930
// 2025-03-21: Fill gamepad inputs and set ImGuiBackendFlags_HasGamepad regardless of ImGuiConfigFlags_NavEnableGamepad being set.
3031
// 2025-03-10: When dealing with OEM keys, use scancodes instead of translated keycodes to choose ImGuiKey values. (#7136, #7201, #7206, #7306, #7670, #7672, #8468)
3132
// 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)
@@ -151,6 +152,7 @@ struct ImGui_ImplSDL2_Data
151152
Uint64 Time;
152153
char* ClipboardTextData;
153154
bool UseVulkan;
155+
bool WantUpdateMonitors;
154156

155157
// Mouse handling
156158
Uint32 MouseWindowID;
@@ -459,6 +461,15 @@ bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event)
459461
io.SetKeyEventNativeData(key, event->key.keysym.sym, event->key.keysym.scancode, event->key.keysym.scancode); // To support legacy indexing (<1.87 user code). Legacy backend uses SDLK_*** as indices to IsKeyXXX() functions.
460462
return true;
461463
}
464+
#if SDL_HAS_DISPLAY_EVENT
465+
case SDL_DISPLAYEVENT:
466+
{
467+
// 2.0.26 has SDL_DISPLAYEVENT_CONNECTED/SDL_DISPLAYEVENT_DISCONNECTED/SDL_DISPLAYEVENT_ORIENTATION,
468+
// so change of DPI/Scaling are not reflected in this event. (SDL3 has it)
469+
bd->WantUpdateMonitors = true;
470+
return true;
471+
}
472+
#endif
462473
case SDL_WINDOWEVENT:
463474
{
464475
ImGuiViewport* viewport = ImGui_ImplSDL2_GetViewportForWindowID(event->window.windowID);
@@ -882,8 +893,10 @@ static void ImGui_ImplSDL2_UpdateGamepads()
882893
// FIXME: Note that doesn't update with DPI/Scaling change only as SDL2 doesn't have an event for it (SDL3 has).
883894
static void ImGui_ImplSDL2_UpdateMonitors()
884895
{
896+
ImGui_ImplSDL2_Data* bd = ImGui_ImplSDL2_GetBackendData();
885897
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
886898
platform_io.Monitors.resize(0);
899+
bd->WantUpdateMonitors = false;
887900
int display_count = SDL_GetNumVideoDisplays();
888901
for (int n = 0; n < display_count; n++)
889902
{
@@ -941,7 +954,11 @@ void ImGui_ImplSDL2_NewFrame()
941954
io.DisplayFramebufferScale = ImVec2((float)display_w / w, (float)display_h / h);
942955

943956
// Update monitors
944-
ImGui_ImplSDL2_UpdateMonitors();
957+
#ifdef WIN32
958+
bd->WantUpdateMonitors = true; // Keep polling under Windows to handle changes of work area when resizing task-bar (#8415)
959+
#endif
960+
if (bd->WantUpdateMonitors)
961+
ImGui_ImplSDL2_UpdateMonitors();
945962

946963
// Setup time step (we don't use SDL_GetTicks() because it is using millisecond resolution)
947964
// (Accept SDL_GetPerformanceCounter() not returning a monotonically increasing value. Happens in VMs and Emscripten, see #6189, #6114, #3644)

backends/imgui_impl_sdl3.cpp

+18-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
// CHANGELOG
2525
// (minor and older changes stripped away, please see git history for details)
2626
// 2025-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
27+
// 2025-04-09: [Docking] Revert update monitors and work areas information every frame. Only do it on Windows. (#8415, #8558)
2728
// 2025-03-30: Update for SDL3 api changes: Revert SDL_GetClipboardText() memory ownership change. (#8530, #7801)
2829
// 2025-03-21: Fill gamepad inputs and set ImGuiBackendFlags_HasGamepad regardless of ImGuiConfigFlags_NavEnableGamepad being set.
2930
// 2025-03-10: When dealing with OEM keys, use scancodes instead of translated keycodes to choose ImGuiKey values. (#7136, #7201, #7206, #7306, #7670, #7672, #8468)
@@ -107,6 +108,7 @@ struct ImGui_ImplSDL3_Data
107108
Uint64 Time;
108109
char* ClipboardTextData;
109110
bool UseVulkan;
111+
bool WantUpdateMonitors;
110112

111113
// IME handling
112114
SDL_Window* ImeWindow;
@@ -424,6 +426,15 @@ bool ImGui_ImplSDL3_ProcessEvent(const SDL_Event* event)
424426
io.SetKeyEventNativeData(key, event->key.key, event->key.scancode, event->key.scancode); // To support legacy indexing (<1.87 user code). Legacy backend uses SDLK_*** as indices to IsKeyXXX() functions.
425427
return true;
426428
}
429+
case SDL_EVENT_DISPLAY_ORIENTATION:
430+
case SDL_EVENT_DISPLAY_ADDED:
431+
case SDL_EVENT_DISPLAY_REMOVED:
432+
case SDL_EVENT_DISPLAY_MOVED:
433+
case SDL_EVENT_DISPLAY_CONTENT_SCALE_CHANGED:
434+
{
435+
bd->WantUpdateMonitors = true;
436+
return true;
437+
}
427438
case SDL_EVENT_WINDOW_MOUSE_ENTER:
428439
{
429440
if (ImGui_ImplSDL3_GetViewportForWindowID(event->window.windowID) == nullptr)
@@ -845,8 +856,10 @@ static void ImGui_ImplSDL3_UpdateGamepads()
845856

846857
static void ImGui_ImplSDL3_UpdateMonitors()
847858
{
859+
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
848860
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
849861
platform_io.Monitors.resize(0);
862+
bd->WantUpdateMonitors = false;
850863

851864
int display_count;
852865
SDL_DisplayID* displays = SDL_GetDisplays(&display_count);
@@ -893,7 +906,11 @@ void ImGui_ImplSDL3_NewFrame()
893906
io.DisplayFramebufferScale = ImVec2((float)display_w / w, (float)display_h / h);
894907

895908
// Update monitors
896-
ImGui_ImplSDL3_UpdateMonitors();
909+
#ifdef WIN32
910+
bd->WantUpdateMonitors = true; // Keep polling under Windows to handle changes of work area when resizing task-bar (#8415)
911+
#endif
912+
if (bd->WantUpdateMonitors)
913+
ImGui_ImplSDL3_UpdateMonitors();
897914

898915
// Setup time step (we don't use SDL_GetTicks() because it is using millisecond resolution)
899916
// (Accept SDL_GetPerformanceCounter() not returning a monotonically increasing value. Happens in VMs and Emscripten, see #6189, #6114, #3644)

docs/CHANGELOG.txt

+3
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ Docking+Viewports Branch:
9393
Because we allowed the Win32 window to close early, Windows destroyed
9494
it and our imgui window became not visible even though user code was
9595
still submitting it.
96+
- Backends: SDL2, SDL3: revert updating monitors and work areas info every
97+
frame. Only do it on Windows to detect task-bar resize until we get an
98+
adequate event for it. (#8415, #8558)
9699

97100

98101
-----------------------------------------------------------------------

0 commit comments

Comments
 (0)