From 2eda13c965497e41bb2d031f7890979a819d6438 Mon Sep 17 00:00:00 2001 From: Andrew Knight Date: Mon, 10 Feb 2014 10:11:18 +0200 Subject: WinRT: move most of GUI event dispatcher logic into core The native event dispatcher is responsible for delivering callbacks to non-GUI handlers, such as network socket listeners. So, the non-GUI logic is moved into the core dispatcher so that the event loop works better for apps (and test cases) which use QCoreApplication. Change-Id: Ic5f7d939cf164198fd39aa5880e265ae560b39b4 Reviewed-by: Oliver Wolff --- .../platforms/winrt/qwinrteventdispatcher.cpp | 44 ++-------------------- .../platforms/winrt/qwinrteventdispatcher.h | 23 +---------- src/plugins/platforms/winrt/qwinrtintegration.cpp | 5 +-- 3 files changed, 7 insertions(+), 65 deletions(-) (limited to 'src/plugins/platforms/winrt') diff --git a/src/plugins/platforms/winrt/qwinrteventdispatcher.cpp b/src/plugins/platforms/winrt/qwinrteventdispatcher.cpp index baa8b5c636..98eb83f5eb 100644 --- a/src/plugins/platforms/winrt/qwinrteventdispatcher.cpp +++ b/src/plugins/platforms/winrt/qwinrteventdispatcher.cpp @@ -46,20 +46,10 @@ #include #include -#include -#include - -using namespace ABI::Windows::ApplicationModel::Core; -using namespace ABI::Windows::UI::Core; -using namespace ABI::Windows::Foundation; -using namespace Microsoft::WRL; - QT_BEGIN_NAMESPACE -QWinRTEventDispatcher::QWinRTEventDispatcher(ICoreDispatcher *dispatcher, QObject *parent) +QWinRTEventDispatcher::QWinRTEventDispatcher(QObject *parent) : QEventDispatcherWinRT(parent) - , m_dispatcher(dispatcher) - , m_interrupt(false) { } @@ -68,37 +58,11 @@ bool QWinRTEventDispatcher::hasPendingEvents() return QEventDispatcherWinRT::hasPendingEvents() || QWindowSystemInterface::windowSystemEventsQueued(); } -void QWinRTEventDispatcher::interrupt() -{ - m_interrupt = true; -} - -bool QWinRTEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags) +bool QWinRTEventDispatcher::sendPostedEvents(QEventLoop::ProcessEventsFlags flags) { - bool canWait = flags & QEventLoop::WaitForMoreEvents; - bool didProcess; - m_interrupt = false; - do { - // Send Qt events - didProcess = QEventDispatcherWinRT::processEvents(flags); - - // Process system events - emit aboutToBlock(); - if (m_dispatcher) - m_dispatcher->ProcessEvents(CoreProcessEventsOption_ProcessAllIfPresent); - emit awake(); - - // Dispatch accumulated user events + bool didProcess = QEventDispatcherWinRT::sendPostedEvents(flags); + if (!(flags & QEventLoop::ExcludeUserInputEvents)) didProcess |= QWindowSystemInterface::sendWindowSystemEvents(flags); - canWait = canWait && !didProcess && !m_interrupt; - - // Short sleep if there is nothing to do - if (canWait) { - emit aboutToBlock(); - WaitForSingleObjectEx(GetCurrentThread(), 1, true); - emit awake(); - } - } while (canWait); return didProcess; } diff --git a/src/plugins/platforms/winrt/qwinrteventdispatcher.h b/src/plugins/platforms/winrt/qwinrteventdispatcher.h index 741007c7fa..612d5ff6e2 100644 --- a/src/plugins/platforms/winrt/qwinrteventdispatcher.h +++ b/src/plugins/platforms/winrt/qwinrteventdispatcher.h @@ -44,36 +44,17 @@ #include -#include - -namespace ABI { - namespace Windows { - namespace UI { - namespace Core { - struct ICoreDispatcher; - } - } - } -} - QT_BEGIN_NAMESPACE class QWinRTEventDispatcher : public QEventDispatcherWinRT { Q_OBJECT public: - explicit QWinRTEventDispatcher(ABI::Windows::UI::Core::ICoreDispatcher *dispatcher, QObject *parent = 0); + explicit QWinRTEventDispatcher(QObject *parent = 0); protected: - void interrupt(); bool hasPendingEvents(); - bool processEvents(QEventLoop::ProcessEventsFlags flags); - -private: - Microsoft::WRL::ComPtr m_dispatcher; - bool m_interrupt; - - friend class QWinRTIntegration; + bool sendPostedEvents(QEventLoop::ProcessEventsFlags flags); }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/winrt/qwinrtintegration.cpp b/src/plugins/platforms/winrt/qwinrtintegration.cpp index 80ed9d1aab..be82390723 100644 --- a/src/plugins/platforms/winrt/qwinrtintegration.cpp +++ b/src/plugins/platforms/winrt/qwinrtintegration.cpp @@ -114,10 +114,7 @@ QWinRTIntegration::~QWinRTIntegration() QAbstractEventDispatcher *QWinRTIntegration::createEventDispatcher() const { - ICoreDispatcher *dispatcher; - if (FAILED(m_screen->coreWindow()->get_Dispatcher(&dispatcher))) - qCritical("Could not capture UI Dispatcher"); - return new QWinRTEventDispatcher(dispatcher); + return new QWinRTEventDispatcher; } bool QWinRTIntegration::hasCapability(QPlatformIntegration::Capability cap) const -- cgit v1.2.3