@@ -830,14 +830,32 @@ namespace
830
830
#else
831
831
flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
832
832
#endif
833
+
834
+ // If the window size was manually changed to a non-standard one (which does not correspond to any of the resolutions supported by the display),
835
+ // then after switching to full-screen mode, the in-game display area may not take up the entire screen and black bars will remain on the sides
836
+ // of the screen. In this case, even if it is specified to use the SDL_WINDOW_FULLSCREEN, the SDL_WINDOW_FULLSCREEN_DESKTOP will still be used
837
+ // under the hood. To avoid this, we need to remember the window size (to restore it later when turning off full-screen mode) and then set the
838
+ // window size to the size of the in-game display area before switching to the full-screen mode.
839
+ SDL_GetWindowSize ( _window, &_windowedSize.width , &_windowedSize.height );
840
+
841
+ if ( const fheroes2::Display & display = fheroes2::Display::instance (); display.width () != 0 && display.height () != 0 ) {
842
+ assert ( display.screenSize ().width >= display.width () && display.screenSize ().height >= display.height () );
843
+
844
+ SDL_SetWindowSize ( _window, display.screenSize ().width , display.screenSize ().height );
845
+ }
833
846
}
834
847
835
- const int returnCode = SDL_SetWindowFullscreen ( _window, flags );
836
- if ( returnCode < 0 ) {
848
+ if ( const int returnCode = SDL_SetWindowFullscreen ( _window, flags ); returnCode < 0 ) {
837
849
ERROR_LOG ( " Failed to set fullscreen mode flags. The error value: " << returnCode << " , description: " << SDL_GetError () )
838
850
}
839
851
840
852
_syncFullScreen ();
853
+
854
+ // If the full-screen mode has been turned off, then restore the remembered window size.
855
+ if ( !isFullScreen () && _windowedSize.width != 0 && _windowedSize.height != 0 ) {
856
+ SDL_SetWindowSize ( _window, _windowedSize.width , _windowedSize.height );
857
+ }
858
+
841
859
_retrieveWindowInfo ();
842
860
_toggleMouseCaptureMode ();
843
861
}
@@ -954,6 +972,8 @@ namespace
954
972
fheroes2::Size _currentScreenResolution;
955
973
fheroes2::Rect _activeWindowROI;
956
974
975
+ fheroes2::Size _windowedSize;
976
+
957
977
bool _isVSyncEnabled{ false };
958
978
959
979
RenderEngine () = default ;
@@ -987,6 +1007,7 @@ namespace
987
1007
}
988
1008
989
1009
_driverIndex = -1 ;
1010
+ _windowedSize = {};
990
1011
}
991
1012
992
1013
void render ( const fheroes2::Display & display, const fheroes2::Rect & roi ) override
0 commit comments