summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-12-18 16:50:16 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-12-18 16:50:16 +0200
commit075cef7b43d2b26d32a5ccb8b916f06987af8cea (patch)
tree3a1adefd09538a4f3e4a39a098c4b5f00e2ef3ad /src
parenta26637839a14e70f8f722cb5b37031f2cffe44e2 (diff)
App: If in the background, don't do periodic events
Does SDL stop all timers?
Diffstat (limited to 'src')
-rw-r--r--src/app.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/app.c b/src/app.c
index e81490aa..2590da0d 100644
--- a/src/app.c
+++ b/src/app.c
@@ -125,6 +125,7 @@ struct Impl_App {
125 iBool isRunning; 125 iBool isRunning;
126 iBool isRunningUnderWindowSystem; 126 iBool isRunningUnderWindowSystem;
127 iBool isDarkSystemTheme; 127 iBool isDarkSystemTheme;
128 iBool isSuspended;
128#if defined (LAGRANGE_ENABLE_IDLE_SLEEP) 129#if defined (LAGRANGE_ENABLE_IDLE_SLEEP)
129 iBool isIdling; 130 iBool isIdling;
130 uint32_t lastEventTime; 131 uint32_t lastEventTime;
@@ -721,6 +722,7 @@ static void init_App_(iApp *d, int argc, char **argv) {
721 d->isRunningUnderWindowSystem = iTrue; 722 d->isRunningUnderWindowSystem = iTrue;
722#endif 723#endif
723 d->isDarkSystemTheme = iTrue; /* will be updated by system later on, if supported */ 724 d->isDarkSystemTheme = iTrue; /* will be updated by system later on, if supported */
725 d->isSuspended = iFalse;
724 init_CommandLine(&d->args, argc, argv); 726 init_CommandLine(&d->args, argc, argv);
725 /* Where was the app started from? We ask SDL first because the command line alone 727 /* Where was the app started from? We ask SDL first because the command line alone
726 cannot be relied on (behavior differs depending on OS). */ { 728 cannot be relied on (behavior differs depending on OS). */ {
@@ -1195,6 +1197,10 @@ iLocalDef iBool isWaitingAllowed_App_(iApp *d) {
1195} 1197}
1196 1198
1197static iBool nextEvent_App_(iApp *d, enum iAppEventMode eventMode, SDL_Event *event) { 1199static iBool nextEvent_App_(iApp *d, enum iAppEventMode eventMode, SDL_Event *event) {
1200 if (d->isSuspended) {
1201 /* Do nothing except wait for the app to return to the foreground. */
1202 return SDL_WaitEvent(event);
1203 }
1198 if (eventMode == waitForNewEvents_AppEventMode && isWaitingAllowed_App_(d)) { 1204 if (eventMode == waitForNewEvents_AppEventMode && isWaitingAllowed_App_(d)) {
1199 /* If there are periodic commands pending, wait only for a short while. */ 1205 /* If there are periodic commands pending, wait only for a short while. */
1200 if (!isEmpty_Periodic(&d->periodic)) { 1206 if (!isEmpty_Periodic(&d->periodic)) {
@@ -1244,6 +1250,7 @@ void processEvents_App(enum iAppEventMode eventMode) {
1244 break; 1250 break;
1245 case SDL_APP_WILLENTERFOREGROUND: 1251 case SDL_APP_WILLENTERFOREGROUND:
1246 invalidate_Window(as_Window(d->window)); 1252 invalidate_Window(as_Window(d->window));
1253 d->isSuspended = iFalse;
1247 break; 1254 break;
1248 case SDL_APP_DIDENTERFOREGROUND: 1255 case SDL_APP_DIDENTERFOREGROUND:
1249 gotEvents = iTrue; 1256 gotEvents = iTrue;
@@ -1251,7 +1258,7 @@ void processEvents_App(enum iAppEventMode eventMode) {
1251#if defined (LAGRANGE_ENABLE_IDLE_SLEEP) 1258#if defined (LAGRANGE_ENABLE_IDLE_SLEEP)
1252 d->isIdling = iFalse; 1259 d->isIdling = iFalse;
1253 d->lastEventTime = SDL_GetTicks(); 1260 d->lastEventTime = SDL_GetTicks();
1254#endif 1261#endif
1255 postRefresh_App(); 1262 postRefresh_App();
1256 break; 1263 break;
1257 case SDL_APP_WILLENTERBACKGROUND: 1264 case SDL_APP_WILLENTERBACKGROUND:
@@ -1261,6 +1268,7 @@ void processEvents_App(enum iAppEventMode eventMode) {
1261 setFreezeDraw_MainWindow(d->window, iTrue); 1268 setFreezeDraw_MainWindow(d->window, iTrue);
1262 savePrefs_App_(d); 1269 savePrefs_App_(d);
1263 saveState_App_(d); 1270 saveState_App_(d);
1271 d->isSuspended = iTrue;
1264 break; 1272 break;
1265 case SDL_APP_TERMINATING: 1273 case SDL_APP_TERMINATING:
1266 setFreezeDraw_MainWindow(d->window, iTrue); 1274 setFreezeDraw_MainWindow(d->window, iTrue);