Skip to content

Commit 35098e9

Browse files
vittorioromeoslouken
authored andcommitted
emscripten: don't dispatch user input to hidden windows
1 parent c9e2e73 commit 35098e9

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

src/video/emscripten/SDL_emscriptenevents.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,15 @@ static void Emscripten_UpdateMouseFromEvent(SDL_WindowData *window_data, const E
713713
{
714714
SDL_assert(event->pointer_type == PTRTYPE_MOUSE);
715715

716+
// Hidden windows (e.g. a shared GL-context window) may share the DOM canvas with the
717+
// visible window. Their pointer-event listeners would otherwise fire alongside the
718+
// visible window's, fighting over `mouse->focus` and producing events tagged with the
719+
// hidden window's ID -- causing downstream consumers that key by window ID to silently
720+
// drop them. Hidden windows shouldn't take part in user-input dispatch.
721+
if (window_data->window->flags & SDL_WINDOW_HIDDEN) {
722+
return;
723+
}
724+
716725
// rescale (in case canvas is being scaled)
717726
double client_w, client_h;
718727
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
838847
{
839848
SDL_assert(event->pointer_type == PTRTYPE_MOUSE);
840849

850+
// Hidden windows shouldn't ever become the mouse-focus target.
851+
if (window_data->window->flags & SDL_WINDOW_HIDDEN) {
852+
return;
853+
}
854+
841855
const bool isPointerLocked = window_data->has_pointer_lock;
842856

843857
if (!isPointerLocked) {

0 commit comments

Comments
 (0)