Pause the game when the window is minimized

This commit is contained in:
Sébastien Noel 2023-05-04 15:24:34 +02:00
parent 4c0b882e85
commit 65ff2cad03
2 changed files with 20 additions and 1 deletions

View File

@ -85,6 +85,11 @@ BOOL PeekMessage(MSG *msg, void *hwnd, UINT wMsgFilterMin,
msg->message = WM_PAINT; msg->message = WM_PAINT;
return TRUE; return TRUE;
} }
if (sdlevent.window.event == SDL_WINDOWEVENT_MINIMIZED)
{
msg->wParam = sdlevent.window.event;
return TRUE;
}
break; break;
// These all map to WM_* things without any drama. // These all map to WM_* things without any drama.

View File

@ -1028,7 +1028,21 @@ int SubMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int
} }
} }
#else #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 #endif
// toggle full-screen on alt-enter // toggle full-screen on alt-enter