Skip to content

Commit fef094d

Browse files
AndywinXpsev-
authored andcommitted
SDL: Preserve events outside ImGui input capture
1 parent f8d604d commit fef094d

2 files changed

Lines changed: 28 additions & 3 deletions

File tree

‎backends/events/sdl/sdl2-events.cpp‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,10 @@ bool SdlEventSource::pollEvent(Common::Event &event) {
695695
if (ImGui_ImplSDL2_Ready()) {
696696
ImGui_ImplSDL2_ProcessEvent(&ev);
697697
ImGuiIO &io = ImGui::GetIO();
698-
if (io.WantTextInput || io.WantCaptureMouse)
698+
bool mouseEvent = ev.type == SDL_MOUSEMOTION || ev.type == SDL_MOUSEBUTTONDOWN ||
699+
ev.type == SDL_MOUSEBUTTONUP || ev.type == SDL_MOUSEWHEEL;
700+
bool textEvent = ev.type == SDL_TEXTINPUT;
701+
if ((mouseEvent && io.WantCaptureMouse) || (textEvent && io.WantTextInput))
699702
continue;
700703
}
701704
#endif
@@ -779,7 +782,16 @@ bool SdlEventSource::dispatchSDLEvent(SDL_Event &ev, Common::Event &event) {
779782
}
780783
}
781784

782-
switch (ev.window.event) {
785+
switch (ev.window.event) {
786+
case SDL_WINDOWEVENT_CLOSE:
787+
if (_graphicsManager) {
788+
uint32 windowID = SDL_GetWindowID(_graphicsManager->getWindow()->getSDLWindow());
789+
if (windowID != ev.window.windowID)
790+
return false;
791+
}
792+
793+
event.type = Common::EVENT_QUIT;
794+
return true;
783795

784796
case SDL_WINDOWEVENT_EXPOSED:
785797
if (_graphicsManager) {

‎backends/events/sdl/sdl3-events.cpp‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,10 @@ bool SdlEventSource::pollEvent(Common::Event &event) {
678678
#if defined(USE_IMGUI)
679679
ImGui_ImplSDL3_ProcessEvent(&ev);
680680
ImGuiIO &io = ImGui::GetIO();
681-
if (io.WantTextInput || io.WantCaptureMouse)
681+
bool mouseEvent = ev.type == SDL_EVENT_MOUSE_MOTION || ev.type == SDL_EVENT_MOUSE_BUTTON_DOWN ||
682+
ev.type == SDL_EVENT_MOUSE_BUTTON_UP || ev.type == SDL_EVENT_MOUSE_WHEEL;
683+
bool textEvent = ev.type == SDL_EVENT_TEXT_INPUT;
684+
if ((mouseEvent && io.WantCaptureMouse) || (textEvent && io.WantTextInput))
682685
continue;
683686
#endif
684687
if (dispatchSDLEvent(ev, event))
@@ -748,6 +751,16 @@ bool SdlEventSource::dispatchSDLEvent(SDL_Event &ev, Common::Event &event) {
748751
return _queuedFakeKeyUp;
749752
}
750753

754+
case SDL_EVENT_WINDOW_CLOSE_REQUESTED:
755+
if (_graphicsManager) {
756+
uint32 windowID = SDL_GetWindowID(_graphicsManager->getWindow()->getSDLWindow());
757+
if (windowID != ev.window.windowID)
758+
return false;
759+
}
760+
761+
event.type = Common::EVENT_QUIT;
762+
return true;
763+
751764
case SDL_EVENT_WINDOW_EXPOSED:
752765
if (_graphicsManager) {
753766
_graphicsManager->notifyVideoExpose();

0 commit comments

Comments
 (0)