diff options
author | Kevin Krammer <kevin.krammer.qnx@kdab.com> | 2012-04-24 16:05:02 (GMT) |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-05-03 07:20:03 (GMT) |
commit | da06e593d744c7edde3df934ecbc0875f98a156a (patch) | |
tree | 194520eef62e2e60eb36ed2b72bdfe73f0d45e08 | |
parent | a28f29270611247775a43e99525c18c7030e1488 (diff) | |
download | Qt-da06e593d744c7edde3df934ecbc0875f98a156a.zip Qt-da06e593d744c7edde3df934ecbc0875f98a156a.tar.gz Qt-da06e593d744c7edde3df934ecbc0875f98a156a.tar.bz2 |
Register for and handle screen events delivered through BPS
Delegates actual event inspection and reaction to the screen event
handler class already used by the PPS screen event handler
Backport of e212d25972dbc19e3cc687b8c7bd4503eec8a602
Change-Id: I0e7f2fb91bedd0b5200d90b9e67be55ec9386dde
Reviewed-by: Thomas McGuire <thomas.mcguire@kdab.com>
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
-rw-r--r-- | src/plugins/platforms/blackberry/blackberry.pro | 4 | ||||
-rw-r--r-- | src/plugins/platforms/blackberry/qbbbpseventfilter.cpp | 29 | ||||
-rw-r--r-- | src/plugins/platforms/blackberry/qbbbpseventfilter.h | 10 | ||||
-rw-r--r-- | src/plugins/platforms/blackberry/qbbintegration.cpp | 29 | ||||
-rw-r--r-- | src/plugins/platforms/blackberry/qbbintegration.h | 4 | ||||
-rw-r--r-- | src/plugins/platforms/blackberry/qbbscreeneventhandler.cpp | 20 | ||||
-rw-r--r-- | src/plugins/platforms/blackberry/qbbscreeneventthread.cpp (renamed from src/plugins/platforms/blackberry/qbbeventthread.cpp) | 50 | ||||
-rw-r--r-- | src/plugins/platforms/blackberry/qbbscreeneventthread.h (renamed from src/plugins/platforms/blackberry/qbbeventthread.h) | 6 |
8 files changed, 100 insertions, 52 deletions
diff --git a/src/plugins/platforms/blackberry/blackberry.pro b/src/plugins/platforms/blackberry/blackberry.pro index 2b0f0ab..4070237 100644 --- a/src/plugins/platforms/blackberry/blackberry.pro +++ b/src/plugins/platforms/blackberry/blackberry.pro @@ -6,7 +6,7 @@ QT += opengl SOURCES = main.cpp \ qbbbuffer.cpp \ - qbbeventthread.cpp \ + qbbscreeneventthread.cpp \ qbbglcontext.cpp \ qbbglwindowsurface.cpp \ qbbinputcontext.cpp \ @@ -25,7 +25,7 @@ SOURCES = main.cpp \ qbbnativeinterface.cpp HEADERS = qbbbuffer.h \ - qbbeventthread.h \ + qbbscreeneventthread.h \ qbbinputcontext.h \ qbbintegration.h \ qbbnavigatoreventhandler.h \ diff --git a/src/plugins/platforms/blackberry/qbbbpseventfilter.cpp b/src/plugins/platforms/blackberry/qbbbpseventfilter.cpp index 97ed89c..5240a90 100644 --- a/src/plugins/platforms/blackberry/qbbbpseventfilter.cpp +++ b/src/plugins/platforms/blackberry/qbbbpseventfilter.cpp @@ -40,18 +40,22 @@ //#define QBBBPSEVENTFILTER_DEBUG #include "qbbbpseventfilter.h" +#include "qbbscreen.h" +#include "qbbscreeneventhandler.h" #include <QAbstractEventDispatcher> #include <QDebug> #include <bps/event.h> +#include <bps/screen.h> QT_BEGIN_NAMESPACE static QBBBpsEventFilter *sInstance; -QBBBpsEventFilter::QBBBpsEventFilter(QObject *parent) +QBBBpsEventFilter::QBBBpsEventFilter(QBBScreenEventHandler *screenEventHandler, QObject *parent) : QObject(parent) + , mScreenEventHandler(screenEventHandler) { Q_ASSERT(sInstance == 0); @@ -81,6 +85,18 @@ void QBBBpsEventFilter::installOnEventDispatcher(QAbstractEventDispatcher *dispa Q_UNUSED(previousEventFilter); } +void QBBBpsEventFilter::registerForScreenEvents(QBBScreen *screen) +{ + if (screen_request_events(screen->nativeContext()) != BPS_SUCCESS) + qWarning("QBB: failed to register for screen events on screen %p", screen->nativeContext()); +} + +void QBBBpsEventFilter::unregisterForScreenEvents(QBBScreen *screen) +{ + if (screen_stop_events(screen->nativeContext()) != BPS_SUCCESS) + qWarning("QBB: failed to unregister for screen events on screen %p", screen->nativeContext()); +} + bool QBBBpsEventFilter::dispatcherEventFilter(void *message) { #if defined(QBBBPSEVENTFILTER_DEBUG) @@ -95,12 +111,17 @@ bool QBBBpsEventFilter::dispatcherEventFilter(void *message) bool QBBBpsEventFilter::bpsEventFilter(bps_event_t *event) { + const int eventDomain = bps_event_get_domain(event); + #if defined(QBBBPSEVENTFILTER_DEBUG) - qDebug() << Q_FUNC_INFO << "event=" << event << "domain=" << bps_event_get_domain(event); -#else - Q_UNUSED(event); + qDebug() << Q_FUNC_INFO << "event=" << event << "domain=" << eventDomain; #endif + if (eventDomain == screen_get_domain()) { + screen_event_t screenEvent = screen_event_get_event(event); + return mScreenEventHandler->handleEvent(screenEvent); + } + return false; } diff --git a/src/plugins/platforms/blackberry/qbbbpseventfilter.h b/src/plugins/platforms/blackberry/qbbbpseventfilter.h index 3466577..e11478c 100644 --- a/src/plugins/platforms/blackberry/qbbbpseventfilter.h +++ b/src/plugins/platforms/blackberry/qbbbpseventfilter.h @@ -47,19 +47,27 @@ struct bps_event_t; QT_BEGIN_NAMESPACE class QAbstractEventDispatcher; +class QBBScreen; +class QBBScreenEventHandler; class QBBBpsEventFilter : public QObject { Q_OBJECT public: - explicit QBBBpsEventFilter(QObject *parent = 0); + explicit QBBBpsEventFilter(QBBScreenEventHandler *screenEventHandler, QObject *parent = 0); ~QBBBpsEventFilter(); void installOnEventDispatcher(QAbstractEventDispatcher *dispatcher); + void registerForScreenEvents(QBBScreen *screen); + void unregisterForScreenEvents(QBBScreen *screen); + private: static bool dispatcherEventFilter(void *message); bool bpsEventFilter(bps_event_t *event); + +private: + QBBScreenEventHandler *mScreenEventHandler; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/blackberry/qbbintegration.cpp b/src/plugins/platforms/blackberry/qbbintegration.cpp index ee06c31..aba8514 100644 --- a/src/plugins/platforms/blackberry/qbbintegration.cpp +++ b/src/plugins/platforms/blackberry/qbbintegration.cpp @@ -41,7 +41,7 @@ #include "qbbintegration.h" #include "qbbinputcontext.h" -#include "qbbeventthread.h" +#include "qbbscreeneventthread.h" #include "qbbglcontext.h" #include "qbbglwindowsurface.h" #include "qbbnavigatoreventhandler.h" @@ -117,8 +117,11 @@ QBBIntegration::QBBIntegration() : createDisplays(); // create/start event thread - mEventThread = new QBBEventThread(mContext, mScreenEventHandler); - mEventThread->start(); + // Not on BlackBerry, it has specialised event dispatcher which also handles screen events +#if !defined(Q_OS_BLACKBERRY) + mScreenEventThread = new QBBScreenEventThread(mContext, mScreenEventHandler); + mScreenEventThread->start(); +#endif #ifdef QBBLOCALETHREAD_ENABLED // Start the locale change monitoring thread. @@ -128,7 +131,12 @@ QBBIntegration::QBBIntegration() : #if defined(Q_OS_BLACKBERRY) bps_initialize(); - mBpsEventFilter = new QBBBpsEventFilter; + mBpsEventFilter = new QBBBpsEventFilter(mScreenEventHandler); + Q_FOREACH (QPlatformScreen *platformScreen, mScreens) { + QBBScreen *screen = static_cast<QBBScreen*>(platformScreen); + mBpsEventFilter->registerForScreenEvents(screen); + } + mBpsEventFilter->installOnEventDispatcher(QAbstractEventDispatcher::instance()); #endif @@ -165,12 +173,21 @@ QBBIntegration::~QBBIntegration() #endif // stop/destroy event thread - delete mEventThread; + delete mScreenEventThread; // stop/destroy navigator event handling classes delete mNavigatorEventNotifier; delete mNavigatorEventHandler; +#if defined(Q_OS_BLACKBERRY) + Q_FOREACH (QPlatformScreen *platformScreen, mScreens) { + QBBScreen *screen = static_cast<QBBScreen*>(platformScreen); + mBpsEventFilter->unregisterForScreenEvents(screen); + } + + delete mBpsEventFilter; +#endif + delete mScreenEventHandler; // destroy all displays @@ -291,7 +308,7 @@ QBBScreen *QBBIntegration::primaryDisplay() const void QBBIntegration::setCursorPos(int x, int y) { - mEventThread->injectPointerMoveEvent(x, y); + mScreenEventThread->injectPointerMoveEvent(x, y); } void QBBIntegration::createDisplays() diff --git a/src/plugins/platforms/blackberry/qbbintegration.h b/src/plugins/platforms/blackberry/qbbintegration.h index eaf3876..8fabe3f 100644 --- a/src/plugins/platforms/blackberry/qbbintegration.h +++ b/src/plugins/platforms/blackberry/qbbintegration.h @@ -46,7 +46,7 @@ QT_BEGIN_NAMESPACE -class QBBEventThread; +class QBBScreenEventThread; class QBBNavigatorEventHandler; class QBBNavigatorEventNotifier; class QBBLocaleThread; @@ -89,7 +89,7 @@ private: void destroyDisplays(); screen_context_t mContext; - QBBEventThread *mEventThread; + QBBScreenEventThread *mScreenEventThread; QBBNavigatorEventHandler *mNavigatorEventHandler; QBBNavigatorEventNotifier *mNavigatorEventNotifier; QBBLocaleThread *mLocaleThread; diff --git a/src/plugins/platforms/blackberry/qbbscreeneventhandler.cpp b/src/plugins/platforms/blackberry/qbbscreeneventhandler.cpp index 1a87c7e..a12f71b 100644 --- a/src/plugins/platforms/blackberry/qbbscreeneventhandler.cpp +++ b/src/plugins/platforms/blackberry/qbbscreeneventhandler.cpp @@ -37,6 +37,8 @@ ** ****************************************************************************/ +//#define QBBSCREENEVENTHANDLER_DEBUG + #include "qbbscreeneventhandler.h" #include "qbbinputcontext.h" @@ -111,7 +113,7 @@ bool QBBScreenEventHandler::handleEvent(screen_event_t event, int qnxType) default: // event ignored -#if defined(QBBEVENTTHREAD_DEBUG) +#if defined(QBBSCREENEVENTHANDLER_DEBUG) qDebug() << "QBB: QNX unknown event"; #endif return false; @@ -323,14 +325,14 @@ void QBBScreenEventHandler::handlePointerEvent(screen_event_t event) if (wOld) { QWindowSystemInterface::handleLeaveEvent(wOld); -#if defined(QBBScreenEventHandler_DEBUG) +#if defined(QBBSCREENEVENTHANDLER_DEBUG) qDebug() << "QBB: Qt leave, w=" << wOld; #endif } if (w) { QWindowSystemInterface::handleEnterEvent(w); -#if defined(QBBScreenEventHandler_DEBUG) +#if defined(QBBSCREENEVENTHANDLER_DEBUG) qDebug() << "QBB: Qt enter, w=" << w; #endif } @@ -368,7 +370,7 @@ void QBBScreenEventHandler::handlePointerEvent(screen_event_t event) mLastLocalMousePoint != localPoint || mLastButtonState != buttons) { QWindowSystemInterface::handleMouseEvent(w, localPoint, globalPoint, buttons); -#if defined(QBBScreenEventHandler_DEBUG) +#if defined(QBBSCREENEVENTHANDLER_DEBUG) qDebug() << "QBB: Qt mouse, w=" << w << ", (" << localPoint.x() << "," << localPoint.y() << "), b=" << (int)buttons; #endif } @@ -377,7 +379,7 @@ void QBBScreenEventHandler::handlePointerEvent(screen_event_t event) // Screen only supports a single wheel, so we will assume Vertical orientation for // now since that is pretty much standard. QWindowSystemInterface::handleWheelEvent(w, localPoint, globalPoint, wheelDelta, Qt::Vertical); -#if defined(QBBScreenEventHandler_DEBUG) +#if defined(QBBSCREENEVENTHANDLER_DEBUG) qDebug() << "QBB: Qt wheel, w=" << w << ", (" << localPoint.x() << "," << localPoint.y() << "), d=" << (int)wheelDelta; #endif } @@ -434,14 +436,14 @@ void QBBScreenEventHandler::handleTouchEvent(screen_event_t event, int qnxType) if (wOld) { QWindowSystemInterface::handleLeaveEvent(wOld); - #if defined(QBBScreenEventHandler_DEBUG) + #if defined(QBBSCREENEVENTHANDLER_DEBUG) qDebug() << "QBB: Qt leave, w=" << wOld; #endif } if (w) { QWindowSystemInterface::handleEnterEvent(w); - #if defined(QBBScreenEventHandler_DEBUG) + #if defined(QBBSCREENEVENTHANDLER_DEBUG) qDebug() << "QBB: Qt enter, w=" << w; #endif } @@ -461,7 +463,7 @@ void QBBScreenEventHandler::handleTouchEvent(screen_event_t event, int qnxType) // inject event into Qt QWindowSystemInterface::handleMouseEvent(w, localPoint, globalPoint, buttons); -#if defined(QBBScreenEventHandler_DEBUG) +#if defined(QBBSCREENEVENTHANDLER_DEBUG) qDebug() << "QBB: Qt mouse, w=" << w << ", (" << localPoint.x() << "," << localPoint.y() << "), b=" << buttons; #endif } @@ -506,7 +508,7 @@ void QBBScreenEventHandler::handleTouchEvent(screen_event_t event, int qnxType) // inject event into Qt QWindowSystemInterface::handleTouchEvent(w, type, QTouchEvent::TouchScreen, pointList); -#if defined(QBBScreenEventHandler_DEBUG) +#if defined(QBBSCREENEVENTHANDLER_DEBUG) qDebug() << "QBB: Qt touch, w=" << w << ", p=(" << pos[0] << "," << pos[1] << "), t=" << type; #endif } diff --git a/src/plugins/platforms/blackberry/qbbeventthread.cpp b/src/plugins/platforms/blackberry/qbbscreeneventthread.cpp index 2593223..f6dfcb2 100644 --- a/src/plugins/platforms/blackberry/qbbeventthread.cpp +++ b/src/plugins/platforms/blackberry/qbbscreeneventthread.cpp @@ -37,9 +37,9 @@ ** ****************************************************************************/ -// #define QBBEVENTTHREAD_DEBUG +// #define QBBSCREENEVENTTHREAD_DEBUG -#include "qbbeventthread.h" +#include "qbbscreeneventthread.h" #include "qbbscreeneventhandler.h" #include <QDebug> @@ -48,30 +48,30 @@ QT_BEGIN_NAMESPACE -QBBEventThread::QBBEventThread(screen_context_t context, QBBScreenEventHandler *eventHandler) +QBBScreenEventThread::QBBScreenEventThread(screen_context_t context, QBBScreenEventHandler *eventHandler) : mContext(context), mQuit(false), mEventHandler(eventHandler) { } -QBBEventThread::~QBBEventThread() +QBBScreenEventThread::~QBBScreenEventThread() { // block until thread terminates shutdown(); } -void QBBEventThread::injectKeyboardEvent(int flags, int sym, int mod, int scan, int cap) +void QBBScreenEventThread::injectKeyboardEvent(int flags, int sym, int mod, int scan, int cap) { QBBScreenEventHandler::injectKeyboardEvent(flags, sym, mod, scan, cap); } -void QBBEventThread::injectPointerMoveEvent(int x, int y) +void QBBScreenEventThread::injectPointerMoveEvent(int x, int y) { mEventHandler->injectPointerMoveEvent(x, y); } -void QBBEventThread::run() +void QBBScreenEventThread::run() { screen_event_t event; @@ -79,10 +79,10 @@ void QBBEventThread::run() errno = 0; int result = screen_create_event(&event); if (result) - qFatal("QBB: failed to create event, errno=%d", errno); + qFatal("QBB: failed to create screen event, errno=%d", errno); -#if defined(QBBEVENTTHREAD_DEBUG) - qDebug() << "QBB: event loop started"; +#if defined(QBBSCREENEVENTTHREAD_DEBUG) + qDebug() << "QBB: screen event thread started"; #endif // loop indefinitely @@ -92,19 +92,19 @@ void QBBEventThread::run() errno = 0; result = screen_get_event(mContext, event, -1); if (result) - qFatal("QBB: failed to get event, errno=%d", errno); + qFatal("QBB: failed to get screen event, errno=%d", errno); // process received event errno = 0; int qnxType; int result = screen_get_event_property_iv(event, SCREEN_PROPERTY_TYPE, &qnxType); if (result) - qFatal("QBB: failed to query event type, errno=%d", errno); + qFatal("QBB: failed to query screen event type, errno=%d", errno); if (qnxType == SCREEN_EVENT_USER) { - // treat all user events as shutdown requests - #if defined(QBBEVENTTHREAD_DEBUG) - qDebug() << "QBB: QNX user event"; + // treat all screen user events as shutdown requests + #if defined(QBBSCREENEVENTTHREAD_DEBUG) + qDebug() << "QBB: QNX screen user event"; #endif mQuit = true; } else { @@ -112,15 +112,15 @@ void QBBEventThread::run() } } -#if defined(QBBEVENTTHREAD_DEBUG) - qDebug() << "QBB: event loop stopped"; +#if defined(QBBSCREENEVENTTHREAD_DEBUG) + qDebug() << "QBB: screen event thread stopped"; #endif // cleanup screen_destroy_event(event); } -void QBBEventThread::shutdown() +void QBBScreenEventThread::shutdown() { screen_event_t event; @@ -128,14 +128,14 @@ void QBBEventThread::shutdown() errno = 0; int result = screen_create_event(&event); if (result) - qFatal("QBB: failed to create event, errno=%d", errno); + qFatal("QBB: failed to create screen event, errno=%d", errno); // set the event type as user errno = 0; int type = SCREEN_EVENT_USER; result = screen_set_event_property_iv(event, SCREEN_PROPERTY_TYPE, &type); if (result) - qFatal("QBB: failed to set event type, errno=%d", errno); + qFatal("QBB: failed to set screen event type, errno=%d", errno); // NOTE: ignore SCREEN_PROPERTY_USER_DATA; treat all user events as shutdown events @@ -143,20 +143,20 @@ void QBBEventThread::shutdown() errno = 0; result = screen_send_event(mContext, event, getpid()); if (result) - qFatal("QBB: failed to set event type, errno=%d", errno); + qFatal("QBB: failed to set screen event type, errno=%d", errno); // cleanup screen_destroy_event(event); -#if defined(QBBEVENTTHREAD_DEBUG) - qDebug() << "QBB: event loop shutdown begin"; +#if defined(QBBSCREENEVENTTHREAD_DEBUG) + qDebug() << "QBB: screen event thread shutdown begin"; #endif // block until thread terminates wait(); -#if defined(QBBEVENTTHREAD_DEBUG) - qDebug() << "QBB: event loop shutdown end"; +#if defined(QBBSCREENEVENTTHREAD_DEBUG) + qDebug() << "QBB: screen event thread shutdown end"; #endif } diff --git a/src/plugins/platforms/blackberry/qbbeventthread.h b/src/plugins/platforms/blackberry/qbbscreeneventthread.h index df8c0ea..0cc2355 100644 --- a/src/plugins/platforms/blackberry/qbbeventthread.h +++ b/src/plugins/platforms/blackberry/qbbscreeneventthread.h @@ -48,11 +48,11 @@ QT_BEGIN_NAMESPACE class QBBScreenEventHandler; -class QBBEventThread : public QThread +class QBBScreenEventThread : public QThread { public: - QBBEventThread(screen_context_t context, QBBScreenEventHandler *eventHandler); - virtual ~QBBEventThread(); + QBBScreenEventThread(screen_context_t context, QBBScreenEventHandler *eventHandler); + virtual ~QBBScreenEventThread(); static void injectKeyboardEvent(int flags, int sym, int mod, int scan, int cap); void injectPointerMoveEvent(int x, int y); |