From 65ff2cad030cbd15427ef8ba9e8b577e39adcec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Noel?= Date: Thu, 4 May 2023 15:24:34 +0200 Subject: [PATCH] Pause the game when the window is minimized --- Sources/Engine/Base/SDL/SDLEvents.cpp | 5 +++++ Sources/SeriousSam/SeriousSam.cpp | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Sources/Engine/Base/SDL/SDLEvents.cpp b/Sources/Engine/Base/SDL/SDLEvents.cpp index 9d69ef1..ef507a6 100755 --- a/Sources/Engine/Base/SDL/SDLEvents.cpp +++ b/Sources/Engine/Base/SDL/SDLEvents.cpp @@ -85,6 +85,11 @@ BOOL PeekMessage(MSG *msg, void *hwnd, UINT wMsgFilterMin, msg->message = WM_PAINT; return TRUE; } + if (sdlevent.window.event == SDL_WINDOWEVENT_MINIMIZED) + { + msg->wParam = sdlevent.window.event; + return TRUE; + } break; // These all map to WM_* things without any drama. diff --git a/Sources/SeriousSam/SeriousSam.cpp b/Sources/SeriousSam/SeriousSam.cpp index c458598..ed57f1d 100755 --- a/Sources/SeriousSam/SeriousSam.cpp +++ b/Sources/SeriousSam/SeriousSam.cpp @@ -1028,7 +1028,21 @@ int SubMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int } } #else - STUBBED("SDL2 can handle these events"); + if( msg.message==SDL_WINDOWEVENT) + { + switch( msg.wParam) { + case SDL_WINDOWEVENT_MINIMIZED: + if( _bWindowChanging) break; + _bWindowChanging = TRUE; + _bReconsiderInput = TRUE; + // if allowed, not already paused and only in single player game mode + if( sam_bPauseOnMinimize && !_pNetwork->IsPaused() && _gmRunningGameMode==GM_SINGLE_PLAYER) { + // pause game + _pNetwork->TogglePause(); + } + break; + } + } #endif // toggle full-screen on alt-enter