From 35098e927cd9c8b92d4eaea7d3f73958cc211f82 Mon Sep 17 00:00:00 2001 From: Vittorio Romeo Date: Wed, 6 May 2026 01:25:30 +0200 Subject: [PATCH] emscripten: don't dispatch user input to hidden windows --- src/video/emscripten/SDL_emscriptenevents.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/video/emscripten/SDL_emscriptenevents.c b/src/video/emscripten/SDL_emscriptenevents.c index 6326d6967e..d4bd854a9e 100644 --- a/src/video/emscripten/SDL_emscriptenevents.c +++ b/src/video/emscripten/SDL_emscriptenevents.c @@ -713,6 +713,15 @@ static void Emscripten_UpdateMouseFromEvent(SDL_WindowData *window_data, const E { SDL_assert(event->pointer_type == PTRTYPE_MOUSE); + // Hidden windows (e.g. a shared GL-context window) may share the DOM canvas with the + // visible window. Their pointer-event listeners would otherwise fire alongside the + // visible window's, fighting over `mouse->focus` and producing events tagged with the + // hidden window's ID -- causing downstream consumers that key by window ID to silently + // drop them. Hidden windows shouldn't take part in user-input dispatch. + if (window_data->window->flags & SDL_WINDOW_HIDDEN) { + return; + } + // rescale (in case canvas is being scaled) double client_w, client_h; emscripten_get_element_css_size(window_data->canvas_id, &client_w, &client_h); @@ -838,6 +847,11 @@ static void Emscripten_HandleMouseFocus(SDL_WindowData *window_data, const Emscr { SDL_assert(event->pointer_type == PTRTYPE_MOUSE); + // Hidden windows shouldn't ever become the mouse-focus target. + if (window_data->window->flags & SDL_WINDOW_HIDDEN) { + return; + } + const bool isPointerLocked = window_data->has_pointer_lock; if (!isPointerLocked) {