-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Backends: SDL2, SDL3: ignore events of other windows #7853
Conversation
Hello, The function says: // If you have multiple SDL events and some of them are not meant to be used by dear imgui, you may need to filter events based on their windowID field. But I agree it'll be simpler if the backend does it because I'll look into reworking this to support multi-viewports too. |
I asked on SDL's discord about a function to easily extract the |
SDL3 now has a function extern SDL_Window *imgui_sdl_window;
SDL_Event event; /* After SDL_PollEvent(&event); */
SDL_Window *event_window = SDL_GetWindowFromEvent(&event);
if (event_window == imgui_sdl_window || event_window == NULL) {
ImGui_ImplSDL3_ProcessEvent(&event);
} |
I think we could add the equivalent |
Thank you for your work adding this to SDL3. I realized that this function may unfortunately not be what we want, as some events are not associated to a window and yet useful for the backend, e.g. Unfortunately this means maybe even the newly added So either we provide a function with a different signature implying something else, e.g. |
The behavior of the SDL function is to return a You're probably right the SDL3 function should be wrapped by a imgui helper function. e.g. bool ImGui_ImplSDL3_IsEventWantedByWindow(const SDL_Event *event, SDL_Window *window) {
SDL_Window *event_window = SDL_GetWindowFromEvent(event);
return event_window == window || event_window == nullptr;
} |
…apping into a function as it'll be convenient for multi-viewport check. (#7853) + Misc typo fix.
…formHandle instead of SDL_Window*. (#7853) This will be used to support filtering of events with multi-viewports.
Right, that would also work for single viewport mode. Anyhow it's harder to figure out for multi-viewports so I believe it should be done in the backend as you initially suggested. I have pushed for following:
Thanks for your help! |
When creating multiple SDL2/SDL3 windows, of which not all windows use imgui,
it is expected that imgui ignores all events of other windows.
This pull requests checks the windowID of the event and only acknowledges the event if it targets the current window.
Patch of SDL3 example that creates a second SDL windows
Mouse movements and/or clicks in the 2nd window should be ignored by imgui.