emscripten: Handle fullscreen toggling manually

Works better than SDL's own handling thanks to our shell.
This commit is contained in:
Sebastian Krzyszkowiak 2023-11-02 07:43:43 +01:00
parent 01423ead90
commit 7be786b88f
No known key found for this signature in database
GPG key ID: E8F235CF3BDBC3FF

View file

@ -696,12 +696,16 @@ SYMBOL_EXPORT void QuitGame(struct Game* game, bool allow_pausing) {
} }
SYMBOL_EXPORT bool ToggleFullscreen(struct Game* game) { SYMBOL_EXPORT bool ToggleFullscreen(struct Game* game) {
if (IS_EMSCRIPTEN && game->_priv.params.fixed_size) { #ifdef __EMSCRIPTEN
al_set_display_flag(game->display, ALLEGRO_FULLSCREEN_WINDOW, true); if (game->_priv.params.fixed_size) {
EM_ASM({
document.documentElement.requestFullscreen();
});
SetupViewport(game); SetupViewport(game);
PrintConsole(game, "Fullscreen toggled"); PrintConsole(game, "Fullscreen toggled");
return true; return true;
} }
#endif
game->config.fullscreen = !game->config.fullscreen; game->config.fullscreen = !game->config.fullscreen;
if (game->config.fullscreen) { if (game->config.fullscreen) {
SetConfigOption(game, "SuperDerpy", "fullscreen", "1"); SetConfigOption(game, "SuperDerpy", "fullscreen", "1");
@ -711,7 +715,17 @@ SYMBOL_EXPORT bool ToggleFullscreen(struct Game* game) {
#ifdef ALLEGRO_ANDROID #ifdef ALLEGRO_ANDROID
al_set_display_flag(game->display, ALLEGRO_FRAMELESS, game->config.fullscreen); al_set_display_flag(game->display, ALLEGRO_FRAMELESS, game->config.fullscreen);
#endif #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); al_set_display_flag(game->display, ALLEGRO_FULLSCREEN_WINDOW, game->config.fullscreen);
#endif
SetupViewport(game); SetupViewport(game);
PrintConsole(game, "Fullscreen toggled: %s", game->config.fullscreen ? "on" : "off"); PrintConsole(game, "Fullscreen toggled: %s", game->config.fullscreen ? "on" : "off");
if (!game->_priv.params.show_cursor) { if (!game->_priv.params.show_cursor) {