From 145abdc4429f636b365ce6ebd51f81e216bc7fa3 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Mon, 5 Nov 2012 10:53:59 +0100 Subject: iOS: QIOSEventDispatcher: add runloop source for processing events MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I6cd649a493dab9a982d71921f19d2a9252fc14b0 Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/ios/qioseventdispatcher.h | 9 +++- src/plugins/platforms/ios/qioseventdispatcher.mm | 61 +++++++++++++++++++++--- 2 files changed, 63 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/plugins/platforms/ios/qioseventdispatcher.h b/src/plugins/platforms/ios/qioseventdispatcher.h index 479ec1d0a0..db3eb85ffc 100644 --- a/src/plugins/platforms/ios/qioseventdispatcher.h +++ b/src/plugins/platforms/ios/qioseventdispatcher.h @@ -77,6 +77,7 @@ #define QEVENTDISPATCHER_IOS_P_H #include +#include QT_BEGIN_NAMESPACE @@ -85,7 +86,8 @@ class QIOSEventDispatcher : public QAbstractEventDispatcher Q_OBJECT public: - explicit QIOSEventDispatcher(QObject *parent = 0); ~QIOSEventDispatcher(); + explicit QIOSEventDispatcher(QObject *parent = 0); + ~QIOSEventDispatcher(); bool processEvents(QEventLoop::ProcessEventsFlags flags); bool hasPendingEvents(); @@ -103,6 +105,11 @@ public: void wakeUp(); void interrupt(); void flush(); + +private: + CFRunLoopSourceRef m_postedEventsSource; + static void postedEventsSourceCallback(void *info); + void processPostedEvents(); }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/ios/qioseventdispatcher.mm b/src/plugins/platforms/ios/qioseventdispatcher.mm index 12f448488e..85854f711e 100644 --- a/src/plugins/platforms/ios/qioseventdispatcher.mm +++ b/src/plugins/platforms/ios/qioseventdispatcher.mm @@ -75,42 +75,80 @@ #include "qioseventdispatcher.h" #include +#include QT_BEGIN_NAMESPACE QT_USE_NAMESPACE +static Boolean runLoopSourceEqualCallback(const void *info1, const void *info2) +{ + return info1 == info2; +} + +void QIOSEventDispatcher::postedEventsSourceCallback(void *info) +{ + QIOSEventDispatcher *self = static_cast(info); + self->processPostedEvents(); +} + +void QIOSEventDispatcher::processPostedEvents() +{ + qDebug() << __FUNCTION__ << "called"; + QWindowSystemInterface::sendWindowSystemEvents(QEventLoop::AllEvents); +} + QIOSEventDispatcher::QIOSEventDispatcher(QObject *parent) + : QAbstractEventDispatcher(parent) { - Q_UNUSED(parent); - qDebug() << __FUNCTION__ << "eventdispatcher not implemented"; + CFRunLoopRef mainRunLoop = CFRunLoopGetMain(); + + CFRunLoopSourceContext context; + bzero(&context, sizeof(CFRunLoopSourceContext)); + context.equal = runLoopSourceEqualCallback; + context.info = this; + + // source used to send posted events: + context.perform = QIOSEventDispatcher::postedEventsSourceCallback; + m_postedEventsSource = CFRunLoopSourceCreate(kCFAllocatorDefault, 0, &context); + Q_ASSERT(m_postedEventsSource); + CFRunLoopAddSource(mainRunLoop, m_postedEventsSource, kCFRunLoopCommonModes); } QIOSEventDispatcher::~QIOSEventDispatcher() -{} +{ + CFRunLoopRef mainRunLoop = CFRunLoopGetMain(); + CFRunLoopRemoveSource(mainRunLoop, m_postedEventsSource, kCFRunLoopCommonModes); + CFRelease(m_postedEventsSource); +} bool QIOSEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags) { Q_UNUSED(flags); + qDebug() << __FUNCTION__ << "not implemented"; return false; } bool QIOSEventDispatcher::hasPendingEvents() { + qDebug() << __FUNCTION__ << "not implemented"; return false; } void QIOSEventDispatcher::registerSocketNotifier(QSocketNotifier *notifier) { + qDebug() << __FUNCTION__ << "not implemented"; Q_UNUSED(notifier); } void QIOSEventDispatcher::unregisterSocketNotifier(QSocketNotifier *notifier) { + qDebug() << __FUNCTION__ << "not implemented"; Q_UNUSED(notifier); } void QIOSEventDispatcher::registerTimer(int timerId, int interval, Qt::TimerType timerType, QObject *object) { + qDebug() << __FUNCTION__ << "not implemented"; Q_UNUSED(timerId); Q_UNUSED(interval); Q_UNUSED(timerType); @@ -119,36 +157,47 @@ void QIOSEventDispatcher::registerTimer(int timerId, int interval, Qt::TimerType bool QIOSEventDispatcher::unregisterTimer(int timerId) { + qDebug() << __FUNCTION__ << "not implemented"; Q_UNUSED(timerId); return false; } bool QIOSEventDispatcher::unregisterTimers(QObject *object) { + qDebug() << __FUNCTION__ << "not implemented"; Q_UNUSED(object); return false; } QList QIOSEventDispatcher::registeredTimers(QObject *object) const { + qDebug() << __FUNCTION__ << "not implemented"; Q_UNUSED(object); return QList(); } int QIOSEventDispatcher::remainingTime(int timerId) { + qDebug() << __FUNCTION__ << "not implemented"; Q_UNUSED(timerId); return 0; } void QIOSEventDispatcher::wakeUp() -{} +{ + CFRunLoopSourceSignal(m_postedEventsSource); + CFRunLoopWakeUp(CFRunLoopGetMain()); +} void QIOSEventDispatcher::interrupt() -{} +{ + qDebug() << __FUNCTION__ << "not implemented"; +} void QIOSEventDispatcher::flush() -{} +{ + qDebug() << __FUNCTION__ << "not implemented"; +} QT_END_NAMESPACE -- cgit v1.2.3