Skip to content

Commit 6711caa

Browse files
Temdog007slouken
authored andcommitted
Emscripten: Fix Emscripten_GetFocusedWindow
Ensure a window is focused if the DOM is focused
1 parent 712ce16 commit 6711caa

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/video/emscripten/SDL_emscriptenevents.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,16 @@ static SDL_Window *Emscripten_GetFocusedWindow(SDL_VideoDevice *device)
286286
break;
287287
}
288288
}
289+
// If the DOM is focused, then at least one canvas in the DOM should be considered focused.
290+
// So in this case, just assume that the first canvas is focused.
291+
if (!window) {
292+
const int focused = MAIN_THREAD_EM_ASM_INT({
293+
return document.hasFocus();
294+
});
295+
if (focused) {
296+
window = device->windows;
297+
}
298+
}
289299
return window;
290300
}
291301

0 commit comments

Comments
 (0)