Skip to content

Commit 2d99052

Browse files
committed
Backends: SDL2, SDL3: storing SDL_WindowID inside ImGuiViewport::PlatformHandle instead of SDL_Window*. (#7853)
This will be used to support filtering of events with multi-viewports.
1 parent 1b61d55 commit 2d99052

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

backends/imgui_impl_sdl2.cpp

+2-1
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+
// 2024-08-19: Storing SDL's Uint32 WindowID inside ImGuiViewport::PlatformHandle instead of SDL_Window*.
2425
// 2024-08-19: ImGui_ImplSDL2_ProcessEvent() now ignores events intended for other SDL windows. (#7853)
2526
// 2024-07-02: Emscripten: Added io.PlatformOpenInShellFn() handler for Emscripten versions.
2627
// 2024-07-02: Update for io.SetPlatformImeDataFn() -> io.PlatformSetImeDataFn() renaming in main library.
@@ -483,7 +484,7 @@ static bool ImGui_ImplSDL2_Init(SDL_Window* window, SDL_Renderer* renderer, void
483484
// Set platform dependent data in viewport
484485
// Our mouse update function expect PlatformHandle to be filled for the main viewport
485486
ImGuiViewport* main_viewport = ImGui::GetMainViewport();
486-
main_viewport->PlatformHandle = (void*)window;
487+
main_viewport->PlatformHandle = (void*)(intptr_t)bd->WindowID;
487488
main_viewport->PlatformHandleRaw = nullptr;
488489
SDL_SysWMinfo info;
489490
SDL_VERSION(&info.version);

backends/imgui_impl_sdl3.cpp

+4-2
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+
// 2024-08-19: Storing SDL_WindowID inside ImGuiViewport::PlatformHandle instead of SDL_Window*.
2425
// 2024-08-19: ImGui_ImplSDL3_ProcessEvent() now ignores events intended for other SDL windows. (#7853)
2526
// 2024-07-22: Update for SDL3 api changes: SDL_GetGamepads() memory ownership change. (#7807)
2627
// 2024-07-18: Update for SDL3 api changes: SDL_GetClipboardText() memory ownership change. (#7801)
@@ -133,7 +134,8 @@ static void ImGui_ImplSDL3_SetClipboardText(void*, const char* text)
133134
static void ImGui_ImplSDL3_PlatformSetImeData(ImGuiContext*, ImGuiViewport* viewport, ImGuiPlatformImeData* data)
134135
{
135136
ImGui_ImplSDL3_Data* bd = ImGui_ImplSDL3_GetBackendData();
136-
SDL_Window* window = (SDL_Window*)viewport->PlatformHandle;
137+
SDL_WindowID window_id = (SDL_WindowID)(intptr_t)viewport->PlatformHandle;
138+
SDL_Window* window = SDL_GetWindowFromID(window_id);
137139
if ((data->WantVisible == false || bd->ImeWindow != window) && bd->ImeWindow != NULL)
138140
{
139141
SDL_StopTextInput(bd->ImeWindow);
@@ -413,7 +415,7 @@ bool ImGui_ImplSDL3_ProcessEvent(const SDL_Event* event)
413415

414416
static void ImGui_ImplSDL3_SetupPlatformHandles(ImGuiViewport* viewport, SDL_Window* window)
415417
{
416-
viewport->PlatformHandle = window;
418+
viewport->PlatformHandle = (void*)(intptr_t)SDL_GetWindowID(window);
417419
viewport->PlatformHandleRaw = nullptr;
418420
#if defined(_WIN32) && !defined(__WINRT__)
419421
viewport->PlatformHandleRaw = (HWND)SDL_GetPointerProperty(SDL_GetWindowProperties(window), SDL_PROP_WINDOW_WIN32_HWND_POINTER, nullptr);

docs/CHANGELOG.txt

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ Other changes:
5151
- Backends: GLFW: added ImGui_ImplGlfw_Sleep() helper function because GLFW does not
5252
provide a way to do a portable sleep. (#7844)
5353
- Backends: SDL2, SDL3: ignore events of other SDL windows. (#7853) [@madebr, @ocornut]
54+
- Backends: SDL2, SDL3: storing SDL_WindowID inside ImGuiViewport::PlatformHandle instead of SDL_Window*.
5455
- Examples: GLFW (all), SDL2 (all), SDL3 (all), Win32+OpenGL3: rework examples main loop
5556
to handle minimization without burning CPU or GPU by running unthrottled code. (#7844)
5657

0 commit comments

Comments
 (0)