From bc23a610d350dfe81594959f5b238eed4bde0f95 Mon Sep 17 00:00:00 2001 From: grorp Date: Fri, 14 Jun 2024 16:50:41 +0200 Subject: [PATCH] Fix two problems with toggling fullscreen at runtime (#14750) --- src/client/inputhandler.cpp | 10 ++++++++-- src/client/renderingengine.cpp | 5 ++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/client/inputhandler.cpp b/src/client/inputhandler.cpp index ae994b8b5..a30c818a7 100644 --- a/src/client/inputhandler.cpp +++ b/src/client/inputhandler.cpp @@ -118,8 +118,14 @@ bool MyEventReceiver::OnEvent(const SEvent &event) const KeyPress keyCode(event.KeyInput); if (keyCode == getKeySetting("keymap_fullscreen")) { if (event.KeyInput.PressedDown && !fullscreen_is_down) { - bool fullscreen = RenderingEngine::get_raw_device()->isFullscreen(); - g_settings->setBool("fullscreen", !fullscreen); + IrrlichtDevice *device = RenderingEngine::get_raw_device(); + + bool new_fullscreen = !device->isFullscreen(); + // Only update the setting if toggling succeeds - it always fails + // if Minetest was built without SDL. + if (device->setFullscreen(new_fullscreen)) { + g_settings->setBool("fullscreen", new_fullscreen); + } } fullscreen_is_down = event.KeyInput.PressedDown; return true; diff --git a/src/client/renderingengine.cpp b/src/client/renderingengine.cpp index b0033c0e2..e7ba333d2 100644 --- a/src/client/renderingengine.cpp +++ b/src/client/renderingengine.cpp @@ -489,11 +489,14 @@ void RenderingEngine::autosaveScreensizeAndCo( // we do not want to save the thing. This allows users to also manually change // the settings. + // Don't save the fullscreen size, we want the windowed size. + bool fullscreen = RenderingEngine::get_raw_device()->isFullscreen(); // Screen size const irr::core::dimension2d current_screen_size = RenderingEngine::get_video_driver()->getScreenSize(); // Don't replace good value with (0, 0) - if (current_screen_size != irr::core::dimension2d(0, 0) && + if (!fullscreen && + current_screen_size != irr::core::dimension2d(0, 0) && current_screen_size != initial_screen_size) { g_settings->setU16("screen_w", current_screen_size.Width); g_settings->setU16("screen_h", current_screen_size.Height);