diff options
author | Alex Trotsenko <alex1973tr@gmail.com> | 2021-02-23 15:00:48 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-02-26 06:40:52 +0000 |
commit | 26e34fcb52b44de6f8d6c8ca8910f9586e8eea81 (patch) | |
tree | 8d90866016694abda3591c4f0bdc532a2fd50235 /src/corelib | |
parent | 1c025842823cbfb02c3618da00ed4166e7eea8f4 (diff) |
QEventDispatcherWin32: get rid of the hook procedure
Instead of intercepting the WM_QT_SENDPOSTEDEVENTS message in the hook
procedure, we can handle it at receive points, making
qt_GetMessageHook() unnecessary.
Including general performance improvements, this patch fixes the issue
where some applications (e.g. Ableton Live) do not call a chain of
nested hooks for plugins.
Fixes: QTBUG-90949
Change-Id: If8e96848392c6f10d45af2aac0567707d16af673
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Nuno Santos <nunosantos@imaginando.net>
(cherry picked from commit b7e08599cc784777d06d34e49e90c2d408ab629d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/kernel/qeventdispatcher_win.cpp | 36 | ||||
-rw-r--r-- | src/corelib/kernel/qeventdispatcher_win_p.h | 3 |
2 files changed, 9 insertions, 30 deletions
diff --git a/src/corelib/kernel/qeventdispatcher_win.cpp b/src/corelib/kernel/qeventdispatcher_win.cpp index 3609bfe389..19604de32f 100644 --- a/src/corelib/kernel/qeventdispatcher_win.cpp +++ b/src/corelib/kernel/qeventdispatcher_win.cpp @@ -96,7 +96,7 @@ LRESULT QT_WIN_CALLBACK qt_internal_proc(HWND hwnd, UINT message, WPARAM wp, LPA QEventDispatcherWin32Private::QEventDispatcherWin32Private() : interrupt(false), internalHwnd(0), - getMessageHook(0), sendPostedEventsTimerId(0), wakeUps(0), + sendPostedEventsTimerId(0), wakeUps(0), activateNotifiersPosted(false) { } @@ -251,30 +251,21 @@ LRESULT QT_WIN_CALLBACK qt_internal_proc(HWND hwnd, UINT message, WPARAM wp, LPA static const UINT mask = inputQueueMask(); if (HIWORD(GetQueueStatus(mask)) == 0) q->sendPostedEvents(); + else + d->startPostedEventsTimer(); return 0; } // switch (message) return DefWindowProc(hwnd, message, wp, lp); } -LRESULT QT_WIN_CALLBACK qt_GetMessageHook(int code, WPARAM wp, LPARAM lp) +void QEventDispatcherWin32Private::startPostedEventsTimer() { - QEventDispatcherWin32 *q = qobject_cast<QEventDispatcherWin32 *>(QAbstractEventDispatcher::instance()); - Q_ASSERT(q != nullptr); - QEventDispatcherWin32Private *d = q->d_func(); - MSG *msg = reinterpret_cast<MSG *>(lp); - // Windows unexpectedly passes PM_NOYIELD flag to the hook procedure, - // if ::PeekMessage(..., PM_REMOVE | PM_NOYIELD) is called from the event loop. - // So, retrieve 'removed' tag as a bit field. - const bool messageRemoved = (wp & PM_REMOVE) != 0; - - if (msg->hwnd == d->internalHwnd && msg->message == WM_QT_SENDPOSTEDEVENTS - && messageRemoved && d->sendPostedEventsTimerId == 0) { + if (sendPostedEventsTimerId == 0) { // Start a timer to deliver posted events when the message queue is emptied. - d->sendPostedEventsTimerId = SetTimer(d->internalHwnd, SendPostedEventsTimerId, - USER_TIMER_MINIMUM, NULL); + sendPostedEventsTimerId = SetTimer(internalHwnd, SendPostedEventsTimerId, + USER_TIMER_MINIMUM, NULL); } - return d->getMessageHook ? CallNextHookEx(0, code, wp, lp) : 0; } // Provide class name and atom for the message window used by @@ -458,14 +449,6 @@ QEventDispatcherWin32::QEventDispatcherWin32(QEventDispatcherWin32Private &dd, Q Q_D(QEventDispatcherWin32); d->internalHwnd = qt_create_internal_window(this); - - // setup GetMessage hook needed to drive our posted events - d->getMessageHook = SetWindowsHookEx(WH_GETMESSAGE, (HOOKPROC) qt_GetMessageHook, NULL, GetCurrentThreadId()); - if (Q_UNLIKELY(!d->getMessageHook)) { - int errorCode = GetLastError(); - qFatal("Qt: INTERNAL ERROR: failed to install GetMessage hook: %d, %ls", - errorCode, qUtf16Printable(qt_error_string(errorCode))); - } } QEventDispatcherWin32::~QEventDispatcherWin32() @@ -536,6 +519,7 @@ bool QEventDispatcherWin32::processEvents(QEventLoop::ProcessEventsFlags flags) } if (d->internalHwnd == msg.hwnd && msg.message == WM_QT_SENDPOSTEDEVENTS) { + d->startPostedEventsTimer(); // Set result to 'true' because the message was sent by wakeUp(). retVal = true; continue; @@ -865,10 +849,6 @@ void QEventDispatcherWin32::closingDown() d->closingDown = true; - if (d->getMessageHook) - UnhookWindowsHookEx(d->getMessageHook); - d->getMessageHook = 0; - if (d->sendPostedEventsTimerId != 0) KillTimer(d->internalHwnd, d->sendPostedEventsTimerId); d->sendPostedEventsTimerId = 0; diff --git a/src/corelib/kernel/qeventdispatcher_win_p.h b/src/corelib/kernel/qeventdispatcher_win_p.h index 90a818b0f5..49a6d3ebbc 100644 --- a/src/corelib/kernel/qeventdispatcher_win_p.h +++ b/src/corelib/kernel/qeventdispatcher_win_p.h @@ -104,7 +104,6 @@ protected: private: friend LRESULT QT_WIN_CALLBACK qt_internal_proc(HWND hwnd, UINT message, WPARAM wp, LPARAM lp); - friend LRESULT QT_WIN_CALLBACK qt_GetMessageHook(int, WPARAM, LPARAM); }; struct QSockNot { @@ -154,11 +153,11 @@ public: // internal window handle used for socketnotifiers/timers/etc HWND internalHwnd; - HHOOK getMessageHook; // for controlling when to send posted events UINT_PTR sendPostedEventsTimerId; QAtomicInt wakeUps; + void startPostedEventsTimer(); // timers WinTimerDict timerDict; |