소스 검색

Emscripten: Fix Emscripten_GetFocusedWindow

Ensure a window is focused if the DOM is focused
Temdog007 2 일 전
부모
커밋
6711caa431
1개의 변경된 파일10개의 추가작업 그리고 0개의 파일을 삭제
  1. 10 0
      src/video/emscripten/SDL_emscriptenevents.c

+ 10 - 0
src/video/emscripten/SDL_emscriptenevents.c

@@ -286,6 +286,16 @@ static SDL_Window *Emscripten_GetFocusedWindow(SDL_VideoDevice *device)
             break;
         }
     }
+    // If the DOM is focused, then at least one canvas in the DOM should be considered focused.
+    // So in this case, just assume that the first canvas is focused.
+    if (!window) {
+        const int focused = MAIN_THREAD_EM_ASM_INT({
+            return document.hasFocus();
+        });
+        if (focused) {
+            window = device->windows;
+        }
+    }
     return window;
 }