From 7be786b88f03e97acdfa4c80ef3619c1dd013d4e Mon Sep 17 00:00:00 2001 From: Sebastian Krzyszkowiak Date: Thu, 2 Nov 2023 07:43:43 +0100 Subject: [PATCH] emscripten: Handle fullscreen toggling manually Works better than SDL's own handling thanks to our shell. --- src/utils.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/utils.c b/src/utils.c index 469584e..64b98ef 100644 --- a/src/utils.c +++ b/src/utils.c @@ -696,12 +696,16 @@ SYMBOL_EXPORT void QuitGame(struct Game* game, bool allow_pausing) { } SYMBOL_EXPORT bool ToggleFullscreen(struct Game* game) { - if (IS_EMSCRIPTEN && game->_priv.params.fixed_size) { - al_set_display_flag(game->display, ALLEGRO_FULLSCREEN_WINDOW, true); +#ifdef __EMSCRIPTEN + if (game->_priv.params.fixed_size) { + EM_ASM({ + document.documentElement.requestFullscreen(); + }); SetupViewport(game); PrintConsole(game, "Fullscreen toggled"); return true; } +#endif game->config.fullscreen = !game->config.fullscreen; if (game->config.fullscreen) { SetConfigOption(game, "SuperDerpy", "fullscreen", "1"); @@ -711,7 +715,17 @@ SYMBOL_EXPORT bool ToggleFullscreen(struct Game* game) { #ifdef ALLEGRO_ANDROID al_set_display_flag(game->display, ALLEGRO_FRAMELESS, game->config.fullscreen); #endif +#ifdef __EMSCRIPTEN__ + EM_ASM({ + if ($0) { + document.documentElement.requestFullscreen(); + } else if (document.fullscreenElement) { + document.exitFullscreen(); + } + }, game->config.fullscreen); +#else al_set_display_flag(game->display, ALLEGRO_FULLSCREEN_WINDOW, game->config.fullscreen); +#endif SetupViewport(game); PrintConsole(game, "Fullscreen toggled: %s", game->config.fullscreen ? "on" : "off"); if (!game->_priv.params.show_cursor) {