From 9caa3d5d8e279a6420f040c756239bcd31a0dde7 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 8 May 2018 01:11:55 +0200 Subject: [PATCH] Fix dispatching pending events in console applications under Mac Apply parts of the changes of 34c5aaa7693b073617264bd2a5393cad18cfc300 done in the common code to Mac-specific wxCFEventLoop too. This is not ideal as we really should reuse the same common code here, but for now it's better than nothing as previously pending events were just not dispatched at all in console Mac applications, meaning that CallAfter() from worker threads never executed. --- docs/changes.txt | 4 ++++ src/osx/core/evtloop_cf.cpp | 27 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/docs/changes.txt b/docs/changes.txt index e6551fa719..cb5d94e75b 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -94,6 +94,10 @@ wxMSW: - Fix positioning windows at positions >= SHORT_MAX (Cătălin Răceanu). - Honour alignment flags for multiline buttons using custom colours too. +wxOSX: + +- Fix dispatching pending events (and CallAfter()) in console applications. + 3.1.1: (released 2018-02-19) ---------------------------- diff --git a/src/osx/core/evtloop_cf.cpp b/src/osx/core/evtloop_cf.cpp index 4bdce90f1e..30fe4e39be 100644 --- a/src/osx/core/evtloop_cf.cpp +++ b/src/osx/core/evtloop_cf.cpp @@ -283,6 +283,33 @@ void wxCFEventLoop::OSXDoRun() break; } + + // Process the remaining queued messages, both at the level of the + // underlying toolkit level (Pending/Dispatch()) and wx level + // (Has/ProcessPendingEvents()). + // + // We do run the risk of never exiting this loop if pending event + // handlers endlessly generate new events but they shouldn't do + // this in a well-behaved program and we shouldn't just discard the + // events we already have, they might be important. + for ( ;; ) + { + bool hasMoreEvents = false; + if ( wxTheApp && wxTheApp->HasPendingEvents() ) + { + wxTheApp->ProcessPendingEvents(); + hasMoreEvents = true; + } + + if ( Pending() ) + { + Dispatch(); + hasMoreEvents = true; + } + + if ( !hasMoreEvents ) + break; + } } }