diff options
Diffstat (limited to 'src/app.c')
-rw-r--r-- | src/app.c | 27 |
1 files changed, 17 insertions, 10 deletions
@@ -318,12 +318,17 @@ const iString *dataDir_App(void) { | |||
318 | return collect_String(cleanedCStr_Path(dataDir_App_)); | 318 | return collect_String(cleanedCStr_Path(dataDir_App_)); |
319 | } | 319 | } |
320 | 320 | ||
321 | iLocalDef iBool isWaitingAllowed_App_(const iApp *d) { | ||
322 | return !d->pendingRefresh && isEmpty_SortedArray(&d->tickers); | ||
323 | } | ||
324 | |||
321 | void processEvents_App(enum iAppEventMode eventMode) { | 325 | void processEvents_App(enum iAppEventMode eventMode) { |
322 | iApp *d = &app_; | 326 | iApp *d = &app_; |
323 | SDL_Event ev; | 327 | SDL_Event ev; |
324 | while ( | 328 | while ((isWaitingAllowed_App_(d) && eventMode == waitForNewEvents_AppEventMode && |
325 | (!d->pendingRefresh && eventMode == waitForNewEvents_AppEventMode && SDL_WaitEvent(&ev)) || | 329 | SDL_WaitEvent(&ev)) || |
326 | ((d->pendingRefresh || eventMode == postedEventsOnly_AppEventMode) && SDL_PollEvent(&ev))) { | 330 | ((!isWaitingAllowed_App_(d) || eventMode == postedEventsOnly_AppEventMode) && |
331 | SDL_PollEvent(&ev))) { | ||
327 | switch (ev.type) { | 332 | switch (ev.type) { |
328 | case SDL_QUIT: | 333 | case SDL_QUIT: |
329 | d->running = iFalse; | 334 | d->running = iFalse; |
@@ -358,12 +363,14 @@ static void runTickers_App_(iApp *d) { | |||
358 | const uint32_t now = SDL_GetTicks(); | 363 | const uint32_t now = SDL_GetTicks(); |
359 | d->elapsedSinceLastTicker = (d->lastTickerTime ? now - d->lastTickerTime : 0); | 364 | d->elapsedSinceLastTicker = (d->lastTickerTime ? now - d->lastTickerTime : 0); |
360 | d->lastTickerTime = now; | 365 | d->lastTickerTime = now; |
366 | if (isEmpty_SortedArray(&d->tickers)) { | ||
367 | d->lastTickerTime = 0; | ||
368 | return; | ||
369 | } | ||
361 | /* Tickers may add themselves again, so we'll run off a copy. */ | 370 | /* Tickers may add themselves again, so we'll run off a copy. */ |
362 | iSortedArray *pending = copy_SortedArray(&d->tickers); | 371 | iSortedArray *pending = copy_SortedArray(&d->tickers); |
363 | clear_SortedArray(&d->tickers); | 372 | clear_SortedArray(&d->tickers); |
364 | if (!isEmpty_SortedArray(pending)) { | 373 | postRefresh_App(); |
365 | postRefresh_App(); | ||
366 | } | ||
367 | iConstForEach(Array, i, &pending->values) { | 374 | iConstForEach(Array, i, &pending->values) { |
368 | const iTicker *ticker = i.value; | 375 | const iTicker *ticker = i.value; |
369 | if (ticker->callback) { | 376 | if (ticker->callback) { |
@@ -371,6 +378,9 @@ static void runTickers_App_(iApp *d) { | |||
371 | } | 378 | } |
372 | } | 379 | } |
373 | delete_SortedArray(pending); | 380 | delete_SortedArray(pending); |
381 | if (isEmpty_SortedArray(&d->tickers)) { | ||
382 | d->lastTickerTime = 0; | ||
383 | } | ||
374 | } | 384 | } |
375 | 385 | ||
376 | static int run_App_(iApp *d) { | 386 | static int run_App_(iApp *d) { |
@@ -378,8 +388,8 @@ static int run_App_(iApp *d) { | |||
378 | d->running = iTrue; | 388 | d->running = iTrue; |
379 | SDL_EventState(SDL_DROPFILE, SDL_ENABLE); /* open files via drag'n'drop */ | 389 | SDL_EventState(SDL_DROPFILE, SDL_ENABLE); /* open files via drag'n'drop */ |
380 | while (d->running) { | 390 | while (d->running) { |
381 | runTickers_App_(d); | ||
382 | processEvents_App(waitForNewEvents_AppEventMode); | 391 | processEvents_App(waitForNewEvents_AppEventMode); |
392 | runTickers_App_(d); | ||
383 | refresh_App(); | 393 | refresh_App(); |
384 | recycle_Garbage(); | 394 | recycle_Garbage(); |
385 | } | 395 | } |
@@ -419,9 +429,6 @@ int run_App(int argc, char **argv) { | |||
419 | void postRefresh_App(void) { | 429 | void postRefresh_App(void) { |
420 | iApp *d = &app_; | 430 | iApp *d = &app_; |
421 | if (!d->pendingRefresh) { | 431 | if (!d->pendingRefresh) { |
422 | if (!isEmpty_SortedArray(&d->tickers)) { | ||
423 | d->lastTickerTime = SDL_GetTicks(); /* tickers had been paused */ | ||
424 | } | ||
425 | d->pendingRefresh = iTrue; | 432 | d->pendingRefresh = iTrue; |
426 | SDL_Event ev; | 433 | SDL_Event ev; |
427 | ev.user.type = SDL_USEREVENT; | 434 | ev.user.type = SDL_USEREVENT; |