From 747d429fb38e168d3fc0bdedd8428bb8c194da22 Mon Sep 17 00:00:00 2001 From: Sergii Pylypenko Date: Sun, 2 May 2021 23:55:45 +0300 Subject: [PATCH] Emscripten: request fullscreen on first mouse click --- src/video/sdl2_v.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/video/sdl2_v.cpp b/src/video/sdl2_v.cpp index 08b25c9956..6e9f7b40f8 100644 --- a/src/video/sdl2_v.cpp +++ b/src/video/sdl2_v.cpp @@ -33,6 +33,7 @@ #ifdef __EMSCRIPTEN__ /** Whether we just had a window-enter event. */ static bool _cursor_new_in_window = false; +static bool _request_fullscreen = true; #endif void VideoDriver_SDL_Base::MakeDirty(int left, int top, int width, int height) @@ -432,6 +433,12 @@ bool VideoDriver_SDL_Base::PollEvent() default: break; } HandleMouseEvents(); +#ifdef __EMSCRIPTEN__ + if (_request_fullscreen) { + _request_fullscreen = false; + EM_ASM( document.documentElement.requestFullscreen(); ); + } +#endif break; case SDL_MOUSEBUTTONUP: @@ -499,6 +506,9 @@ bool VideoDriver_SDL_Base::PollEvent() if (ev.window.event == SDL_WINDOWEVENT_EXPOSED) { // Force a redraw of the entire screen. this->MakeDirty(0, 0, _screen.width, _screen.height); +#ifdef __EMSCRIPTEN__ + _request_fullscreen = true; +#endif } else if (ev.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) { int w = std::max(ev.window.data1, 64); int h = std::max(ev.window.data2, 64); @@ -511,6 +521,7 @@ bool VideoDriver_SDL_Base::PollEvent() * so we can pick up the absolutely position again. */ _cursor_new_in_window = true; SDL_SetRelativeMouseMode(SDL_FALSE); + _request_fullscreen = true; #endif } else if (ev.window.event == SDL_WINDOWEVENT_LEAVE) { // mouse left the window, undraw cursor