diff options
author | Bradley T. Hughes <bradley.hughes@nokia.com> | 2010-11-18 11:42:14 (GMT) |
---|---|---|
committer | Bradley T. Hughes <bradley.hughes@nokia.com> | 2010-11-18 11:42:14 (GMT) |
commit | 7196045b78b33cf135683d5c0b4e164f95231791 (patch) | |
tree | cd33d982cbaba4ff7cc5dd4af0bb45eceea61b4e | |
parent | 346953b985deb5003e801b23063daf3f6dee3824 (diff) | |
download | Qt-7196045b78b33cf135683d5c0b4e164f95231791.zip Qt-7196045b78b33cf135683d5c0b4e164f95231791.tar.gz Qt-7196045b78b33cf135683d5c0b4e164f95231791.tar.bz2 |
Don't let posted events starve native dialogs (regression)
After commit eb1015c7bbf135af3656110a4d112377c1209db8, it is possible
for posted events to starve some of the (most likely internal) messages
used by native dialogs.
This commit reverts eb1015c7bbf135af3656110a4d112377c1209db8, and
instead introduces a Windows timer to keep sendPostedEvents() happening
while the event queue is very active. The GetMessage() hook we install
will eventually see when the queue is empty and we can use PostMessage()
again, which will then stop this timer.
This fixes the regression reported in QTBUG-14655, as well as all of the
other reported regressions and problems since the initial commit
31f1ff91028dd7f90925d5b3737e4d88b5fb07aa (which ensures that posted
events are sent even when Windows is spinning the message loop).
Task-number: QTBUG-14655
Reviewed-by: joao
-rw-r--r-- | src/corelib/kernel/qeventdispatcher_win.cpp | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/src/corelib/kernel/qeventdispatcher_win.cpp b/src/corelib/kernel/qeventdispatcher_win.cpp index a719e72..3dccda6 100644 --- a/src/corelib/kernel/qeventdispatcher_win.cpp +++ b/src/corelib/kernel/qeventdispatcher_win.cpp @@ -84,7 +84,8 @@ extern uint qGlobalPostedEventsCount(); enum { WM_QT_SOCKETNOTIFIER = WM_USER, - WM_QT_SENDPOSTEDEVENTS = WM_USER + 1 + WM_QT_SENDPOSTEDEVENTS = WM_USER + 1, + SendPostedEventsWindowsTimerId = ~1u }; #if defined(Q_OS_WINCE) @@ -353,7 +354,7 @@ public: // for controlling when to send posted events QAtomicInt serialNumber; - int lastSerialNumber; + int lastSerialNumber, sendPostedEventsWindowsTimerId; QAtomicInt wakeUps; // timers @@ -378,7 +379,7 @@ public: QEventDispatcherWin32Private::QEventDispatcherWin32Private() : threadId(GetCurrentThreadId()), interrupt(false), internalHwnd(0), getMessageHook(0), - serialNumber(0), lastSerialNumber(0), wakeUps(0) + serialNumber(0), lastSerialNumber(0), sendPostedEventsWindowsTimerId(0), wakeUps(0) { resolveTimerAPI(); } @@ -485,17 +486,21 @@ LRESULT QT_WIN_CALLBACK qt_internal_proc(HWND hwnd, UINT message, WPARAM wp, LPA } } return 0; - } else if (message == WM_TIMER) { - Q_ASSERT(d != 0); - d->sendTimerEvent(wp); - return 0; - } else if (message == WM_QT_SENDPOSTEDEVENTS) { + } else if (message == WM_QT_SENDPOSTEDEVENTS + // we also use a Windows timer to send posted events when the message queue is full + || (message == WM_TIMER + && d->sendPostedEventsWindowsTimerId != 0 + && wp == d->sendPostedEventsWindowsTimerId)) { int localSerialNumber = d->serialNumber; if (localSerialNumber != d->lastSerialNumber) { d->lastSerialNumber = localSerialNumber; QCoreApplicationPrivate::sendPostedEvents(0, 0, d->threadData); } return 0; + } else if (message == WM_TIMER) { + Q_ASSERT(d != 0); + d->sendTimerEvent(wp); + return 0; } return DefWindowProc(hwnd, message, wp, lp); @@ -507,21 +512,36 @@ LRESULT QT_WIN_CALLBACK qt_GetMessageHook(int code, WPARAM wp, LPARAM lp) QEventDispatcherWin32 *q = qobject_cast<QEventDispatcherWin32 *>(QAbstractEventDispatcher::instance()); Q_ASSERT(q != 0); if (q) { + MSG *msg = (MSG *) lp; QEventDispatcherWin32Private *d = q->d_func(); int localSerialNumber = d->serialNumber; - MSG unused; - if ((HIWORD(GetQueueStatus(QS_INPUT | QS_RAWINPUT)) == 0 - && PeekMessage(&unused, 0, WM_TIMER, WM_TIMER, PM_NOREMOVE) == 0)) { - // no more input or timer events in the message queue or more than 10ms has elapsed since - // we send posted events, we can allow posted events to be sent now + if (HIWORD(GetQueueStatus(QS_TIMER | QS_INPUT | QS_RAWINPUT)) == 0) { + // no more input or timer events in the message queue, we can allow posted events to be sent normally now + if (d->sendPostedEventsWindowsTimerId != 0) { + // stop the timer to send posted events, since we now allow the WM_QT_SENDPOSTEDEVENTS message + KillTimer(d->internalHwnd, d->sendPostedEventsWindowsTimerId); + d->sendPostedEventsWindowsTimerId = 0; + } (void) d->wakeUps.fetchAndStoreRelease(0); - MSG *msg = (MSG *) lp; if (localSerialNumber != d->lastSerialNumber // if this message IS the one that triggers sendPostedEvents(), no need to post it again && (msg->hwnd != d->internalHwnd || msg->message != WM_QT_SENDPOSTEDEVENTS)) { PostMessage(d->internalHwnd, WM_QT_SENDPOSTEDEVENTS, 0, 0); } + } else if (d->sendPostedEventsWindowsTimerId == 0 + && localSerialNumber != d->lastSerialNumber + // if this message IS the one that triggers sendPostedEvents(), no need to post it again + && (msg->hwnd != d->internalHwnd + || msg->message != WM_QT_SENDPOSTEDEVENTS)) { + // start a special timer to continue delivering posted events while + // there are still input and timer messages in the message queue + d->sendPostedEventsWindowsTimerId = SetTimer(d->internalHwnd, + SendPostedEventsWindowsTimerId, + USER_TIMER_MINIMUM, + NULL); + // we don't check the return value of SetTimer()... if creating the timer failed, there's little + // we can do. we just have to accept that posted events will be starved } } } |