Fix two problems with toggling fullscreen at runtime (#14750)

This commit is contained in:
grorp 2024-06-14 16:50:41 +02:00 committed by GitHub
parent 9def45aa80
commit bc23a610d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 3 deletions

@ -118,8 +118,14 @@ bool MyEventReceiver::OnEvent(const SEvent &event)
const KeyPress keyCode(event.KeyInput); const KeyPress keyCode(event.KeyInput);
if (keyCode == getKeySetting("keymap_fullscreen")) { if (keyCode == getKeySetting("keymap_fullscreen")) {
if (event.KeyInput.PressedDown && !fullscreen_is_down) { if (event.KeyInput.PressedDown && !fullscreen_is_down) {
bool fullscreen = RenderingEngine::get_raw_device()->isFullscreen(); IrrlichtDevice *device = RenderingEngine::get_raw_device();
g_settings->setBool("fullscreen", !fullscreen);
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; fullscreen_is_down = event.KeyInput.PressedDown;
return true; return true;

@ -489,11 +489,14 @@ void RenderingEngine::autosaveScreensizeAndCo(
// we do not want to save the thing. This allows users to also manually change // we do not want to save the thing. This allows users to also manually change
// the settings. // the settings.
// Don't save the fullscreen size, we want the windowed size.
bool fullscreen = RenderingEngine::get_raw_device()->isFullscreen();
// Screen size // Screen size
const irr::core::dimension2d<u32> current_screen_size = const irr::core::dimension2d<u32> current_screen_size =
RenderingEngine::get_video_driver()->getScreenSize(); RenderingEngine::get_video_driver()->getScreenSize();
// Don't replace good value with (0, 0) // Don't replace good value with (0, 0)
if (current_screen_size != irr::core::dimension2d<u32>(0, 0) && if (!fullscreen &&
current_screen_size != irr::core::dimension2d<u32>(0, 0) &&
current_screen_size != initial_screen_size) { current_screen_size != initial_screen_size) {
g_settings->setU16("screen_w", current_screen_size.Width); g_settings->setU16("screen_w", current_screen_size.Width);
g_settings->setU16("screen_h", current_screen_size.Height); g_settings->setU16("screen_h", current_screen_size.Height);