From 8e35ff5cb3326d724bac5d7a3107421ae80be54f Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 28 Jul 2021 14:20:29 -0700 Subject: [PATCH] By default minimize real fullscreen windows when they lose focus so the desktop video mode is restored. This fixes https://github.com/libsdl-org/SDL/issues/4039 --- src/video/SDL_video.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index bf7d4bb7c..c13d47898 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -2887,6 +2887,8 @@ SDL_OnWindowFocusGained(SDL_Window * window) static SDL_bool ShouldMinimizeOnFocusLoss(SDL_Window * window) { + const char *hint; + if (!(window->flags & SDL_WINDOW_FULLSCREEN) || window->is_destroying) { return SDL_FALSE; } @@ -2902,12 +2904,21 @@ ShouldMinimizeOnFocusLoss(SDL_Window * window) #ifdef __ANDROID__ { extern SDL_bool Android_JNI_ShouldMinimizeOnFocusLoss(void); - if (! Android_JNI_ShouldMinimizeOnFocusLoss()) { + if (!Android_JNI_ShouldMinimizeOnFocusLoss()) { return SDL_FALSE; } } #endif + /* Real fullscreen windows should minimize on focus loss so the desktop video mode is restored */ + hint = SDL_GetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS); + if (!hint || !*hint || SDL_strcasecmp(hint, "auto") == 0) { + if ((window->flags & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP) { + return SDL_FALSE; + } else { + return SDL_TRUE; + } + } return SDL_GetHintBoolean(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, SDL_FALSE); }