From ad1b9f93c8b33df7824b8ca395b6471b8db70d8c Mon Sep 17 00:00:00 2001 From: Ronald Kinard Date: Thu, 20 Mar 2014 17:26:07 -0500 Subject: [PATCH] sdl2: Fix changing between fullscreen/windowed --- src/sdl2/i_video.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/sdl2/i_video.c b/src/sdl2/i_video.c index 97b9b6c20..a46f4fde7 100644 --- a/src/sdl2/i_video.c +++ b/src/sdl2/i_video.c @@ -196,21 +196,35 @@ static void SDLSetMode(INT32 width, INT32 height, SDL_bool fullscreen) realheight = (Uint16)height; #endif + static SDL_bool wasfullscreen = SDL_FALSE; int rmask; int gmask; int bmask; int amask; - if (fullscreen) + if (fullscreen && !wasfullscreen) { + // Recreate window in fullscreen SDL_DestroyRenderer(renderer); renderer = NULL; SDL_DestroyWindow(window); window = NULL; - Impl_CreateWindow(fullscreen); + Impl_CreateWindow(SDL_TRUE); + wasfullscreen = SDL_TRUE; } - else + else if (!fullscreen && wasfullscreen) { + // Recreate window in windowed mode + SDL_DestroyRenderer(renderer); + renderer = NULL; + SDL_DestroyWindow(window); + window = NULL; + Impl_CreateWindow(SDL_FALSE); + wasfullscreen = SDL_FALSE; + } + else if (!wasfullscreen) + { + // Reposition window only in windowed mode SDL_SetWindowSize(window, width, height); SDL_SetWindowPosition(window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); }