Register for and handle screen events delivered through BPS
authorKevin Krammer <kevin.krammer.qnx@kdab.com>
Mon, 26 Mar 2012 14:44:07 +0000 (16:44 +0200)
committerQt by Nokia <qt-info@nokia.com>
Tue, 1 May 2012 05:10:43 +0000 (07:10 +0200)
Delegates actual event inspection and reaction to the screen event
handler class already used by the PPS screen event handler

Change-Id: Ic07efa1de3f6b452f3091e901bd8a577175e3cf0
Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com>
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
src/plugins/platforms/qnx/qnx.pro
src/plugins/platforms/qnx/qqnxbpseventfilter.cpp
src/plugins/platforms/qnx/qqnxbpseventfilter.h
src/plugins/platforms/qnx/qqnxintegration.cpp
src/plugins/platforms/qnx/qqnxintegration.h
src/plugins/platforms/qnx/qqnxscreeneventthread.cpp [moved from src/plugins/platforms/qnx/qqnxeventthread.cpp with 73% similarity]
src/plugins/platforms/qnx/qqnxscreeneventthread.h [moved from src/plugins/platforms/qnx/qqnxeventthread.h with 88% similarity]

index 48738a5..c218b5e 100644 (file)
@@ -22,7 +22,7 @@ CONFIG(blackberry) {
 #DEFINES += QQNXBUFFER_DEBUG
 #DEFINES += QQNXBPSEVENTFILTER_DEBUG
 #DEFINES += QQNXCLIPBOARD_DEBUG
-#DEFINES += QQNXEVENTTHREAD_DEBUG
+#DEFINES += QQNXSCREENEVENTTHREAD_DEBUG
 #DEFINES += QQNXGLBACKINGSTORE_DEBUG
 #DEFINES += QQNXGLCONTEXT_DEBUG
 #DEFINES += QQNXINPUTCONTEXT_DEBUG
@@ -40,7 +40,7 @@ CONFIG(blackberry) {
 
 SOURCES =   main.cpp \
             qqnxbuffer.cpp \
-            qqnxeventthread.cpp \
+            qqnxscreeneventthread.cpp \
             qqnxintegration.cpp \
             qqnxscreen.cpp \
             qqnxwindow.cpp \
@@ -55,7 +55,7 @@ SOURCES =   main.cpp \
 
 HEADERS =   main.h \
             qqnxbuffer.h \
-            qqnxeventthread.h \
+            qqnxscreeneventthread.h \
             qqnxkeytranslator.h \
             qqnxintegration.h \
             qqnxscreen.h \
index d1db066..c4e6f2b 100644 (file)
 ****************************************************************************/
 
 #include "qqnxbpseventfilter.h"
+#include "qqnxscreen.h"
+#include "qqnxscreeneventhandler.h"
 
 #include <QAbstractEventDispatcher>
 #include <QDebug>
 
 #include <bps/event.h>
+#include <bps/screen.h>
 
 QT_BEGIN_NAMESPACE
 
 static QQnxBpsEventFilter *s_instance = 0;
 
-QQnxBpsEventFilter::QQnxBpsEventFilter(QObject *parent)
+QQnxBpsEventFilter::QQnxBpsEventFilter(QQnxScreenEventHandler *screenEventHandler, QObject *parent)
     : QObject(parent)
+    , m_screenEventHandler(screenEventHandler)
 {
     Q_ASSERT(s_instance == 0);
 
@@ -80,6 +84,18 @@ void QQnxBpsEventFilter::installOnEventDispatcher(QAbstractEventDispatcher *disp
     Q_UNUSED(previousEventFilter);
 }
 
+void QQnxBpsEventFilter::registerForScreenEvents(QQnxScreen *screen)
+{
+    if (screen_request_events(screen->nativeContext()) != BPS_SUCCESS)
+        qWarning("QQNX: failed to register for screen events on screen %p", screen->nativeContext());
+}
+
+void QQnxBpsEventFilter::unregisterForScreenEvents(QQnxScreen *screen)
+{
+    if (screen_stop_events(screen->nativeContext()) != BPS_SUCCESS)
+        qWarning("QQNX: failed to unregister for screen events on screen %p", screen->nativeContext());
+}
+
 bool QQnxBpsEventFilter::dispatcherEventFilter(void *message)
 {
 #if defined(QQNXBPSEVENTFILTER_DEBUG)
@@ -95,12 +111,17 @@ bool QQnxBpsEventFilter::dispatcherEventFilter(void *message)
 
 bool QQnxBpsEventFilter::bpsEventFilter(bps_event_t *event)
 {
+    const int eventDomain = bps_event_get_domain(event);
+
 #if defined(QQNXBPSEVENTFILTER_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 m_screenEventHandler->handleEvent(screenEvent);
+    }
+
     return false;
 }
 
index f03ea8e..1c08f13 100644 (file)
@@ -49,19 +49,27 @@ struct bps_event_t;
 QT_BEGIN_NAMESPACE
 
 class QAbstractEventDispatcher;
+class QQnxScreen;
+class QQnxScreenEventHandler;
 
 class QQnxBpsEventFilter : public QObject
 {
     Q_OBJECT
 public:
-    explicit QQnxBpsEventFilter(QObject *parent = 0);
+    explicit QQnxBpsEventFilter(QQnxScreenEventHandler *screenEventHandler, QObject *parent = 0);
     ~QQnxBpsEventFilter();
 
     void installOnEventDispatcher(QAbstractEventDispatcher *dispatcher);
 
+    void registerForScreenEvents(QQnxScreen *screen);
+    void unregisterForScreenEvents(QQnxScreen *screen);
+
 private:
     static bool dispatcherEventFilter(void *message);
     bool bpsEventFilter(bps_event_t *event);
+
+private:
+    QQnxScreenEventHandler *m_screenEventHandler;
 };
 
 QT_END_NAMESPACE
index b3c3949..54aa311 100644 (file)
@@ -40,7 +40,7 @@
 ****************************************************************************/
 
 #include "qqnxintegration.h"
-#include "qqnxeventthread.h"
+#include "qqnxscreeneventthread.h"
 #include "qqnxnativeinterface.h"
 #include "qqnxrasterbackingstore.h"
 #include "qqnxscreen.h"
@@ -100,7 +100,7 @@ QMutex QQnxIntegration::ms_windowMapperMutex;
 
 QQnxIntegration::QQnxIntegration()
     : QPlatformIntegration()
-    , m_eventThread(0)
+    , m_screenEventThread(0)
     , m_navigatorEventHandler(new QQnxNavigatorEventHandler())
     , m_virtualKeyboard(0)
 #if defined(QQNX_PPS)
@@ -152,8 +152,11 @@ QQnxIntegration::QQnxIntegration()
 #endif
 
     // Create/start event thread
-    m_eventThread = new QQnxEventThread(m_screenContext, m_screenEventHandler);
-    m_eventThread->start();
+    // Not on BlackBerry, it has specialised event dispatcher which also handles screen events
+#if !defined(Q_OS_BLACKBERRY)
+    m_screenEventThread = new QQnxScreenEventThread(m_screenContext, m_screenEventHandler);
+    m_screenEventThread->start();
+#endif
 
 #if defined(QQNX_PPS)
     // Create/start the keyboard class.
@@ -182,7 +185,10 @@ QQnxIntegration::QQnxIntegration()
         m_services = new QQnxServices(m_navigator);
 
 #if defined(Q_OS_BLACKBERRY)
-    m_bpsEventFilter = new QQnxBpsEventFilter;
+    m_bpsEventFilter = new QQnxBpsEventFilter(m_screenEventHandler);
+    Q_FOREACH (QQnxScreen *screen, m_screens)
+        m_bpsEventFilter->registerForScreenEvents(screen);
+
     m_bpsEventFilter->installOnEventDispatcher(m_eventDispatcher);
 #endif
 
@@ -216,8 +222,16 @@ QQnxIntegration::~QQnxIntegration()
 #endif
     delete m_navigatorEventHandler;
 
-    // Stop/destroy event thread
-    delete m_eventThread;
+#if !defined(Q_OS_BLACKBERRY)
+    // Stop/destroy screen event thread
+    delete m_screenEventThread;
+#else
+    Q_FOREACH (QQnxScreen *screen, m_screens)
+        m_bpsEventFilter->unregisterForScreenEvents(screen);
+
+    delete m_bpsEventFilter;
+#endif
+
     delete m_screenEventHandler;
 
     // Destroy all displays
@@ -237,10 +251,6 @@ QQnxIntegration::~QQnxIntegration()
     // Destroy navigator interface
     delete m_navigator;
 
-#if defined(Q_OS_BLACKBERRY)
-    delete m_bpsEventFilter;
-#endif
-
 #if defined(QQNXINTEGRATION_DEBUG)
     qDebug() << "QQnx: platform plugin shutdown end";
 #endif
index 538892e..a3c476f 100644 (file)
@@ -51,7 +51,7 @@
 QT_BEGIN_NAMESPACE
 
 class QQnxBpsEventFilter;
-class QQnxEventThread;
+class QQnxScreenEventThread;
 class QQnxNativeInterface;
 class QQnxWindow;
 class QQnxScreen;
@@ -123,7 +123,7 @@ private:
     static void removeWindow(screen_window_t qnxWindow);
 
     screen_context_t m_screenContext;
-    QQnxEventThread *m_eventThread;
+    QQnxScreenEventThread *m_screenEventThread;
     QQnxNavigatorEventHandler *m_navigatorEventHandler;
     QQnxAbstractVirtualKeyboard *m_virtualKeyboard;
 #if defined(QQNX_PPS)
@@ -39,7 +39,7 @@
 **
 ****************************************************************************/
 
-#include "qqnxeventthread.h"
+#include "qqnxscreeneventthread.h"
 #include "qqnxscreeneventhandler.h"
 
 #include <QtCore/QDebug>
@@ -49,8 +49,7 @@
 
 #include <cctype>
 
-QQnxEventThread::QQnxEventThread(screen_context_t context,
-                                 QQnxScreenEventHandler *screenEventHandler)
+QQnxScreenEventThread::QQnxScreenEventThread(screen_context_t context, QQnxScreenEventHandler *screenEventHandler)
     : QThread(),
       m_screenContext(context),
       m_screenEventHandler(screenEventHandler),
@@ -58,18 +57,18 @@ QQnxEventThread::QQnxEventThread(screen_context_t context,
 {
 }
 
-QQnxEventThread::~QQnxEventThread()
+QQnxScreenEventThread::~QQnxScreenEventThread()
 {
     // block until thread terminates
     shutdown();
 }
 
-void QQnxEventThread::injectKeyboardEvent(int flags, int sym, int mod, int scan, int cap)
+void QQnxScreenEventThread::injectKeyboardEvent(int flags, int sym, int mod, int scan, int cap)
 {
     QQnxScreenEventHandler::injectKeyboardEvent(flags, sym, mod, scan, cap);
 }
 
-void QQnxEventThread::run()
+void QQnxScreenEventThread::run()
 {
     screen_event_t event;
 
@@ -77,10 +76,10 @@ void QQnxEventThread::run()
     errno = 0;
     int result = screen_create_event(&event);
     if (result)
-        qFatal("QQNX: failed to create event, errno=%d", errno);
+        qFatal("QQNX: failed to create screen event, errno=%d", errno);
 
-#if defined(QQNXEVENTTHREAD_DEBUG)
-    qDebug() << "QQNX: event loop started";
+#if defined(QQNXSCREENEVENTTHREAD_DEBUG)
+    qDebug() << "QQNX: screen event thread started";
 #endif
 
     // loop indefinitely
@@ -90,7 +89,7 @@ void QQnxEventThread::run()
         errno = 0;
         result = screen_get_event(m_screenContext, event, -1);
         if (result)
-            qFatal("QQNX: failed to get event, errno=%d", errno);
+            qFatal("QQNX: failed to get screen event, errno=%d", errno);
 
         // process received event
         // get the event type
@@ -98,12 +97,12 @@ void QQnxEventThread::run()
         int qnxType;
         result = screen_get_event_property_iv(event, SCREEN_PROPERTY_TYPE, &qnxType);
         if (result)
-            qFatal("QQNX: failed to query event type, errno=%d", errno);
+            qFatal("QQNX: failed to query screen event type, errno=%d", errno);
 
         if (qnxType == SCREEN_EVENT_USER) {
             // treat all user events as shutdown requests
-    #if defined(QQNXEVENTTHREAD_DEBUG)
-            qDebug() << "QQNX: QNX user event";
+    #if defined(QQNXSCREENEVENTTHREAD_DEBUG)
+            qDebug() << "QQNX: QNX user screen event";
     #endif
             m_quit = true;
         } else {
@@ -111,15 +110,15 @@ void QQnxEventThread::run()
         }
     }
 
-#if defined(QQNXEVENTTHREAD_DEBUG)
-    qDebug() << "QQNX: event loop stopped";
+#if defined(QQNXSCREENEVENTTHREAD_DEBUG)
+    qDebug() << "QQNX: screen event thread stopped";
 #endif
 
     // cleanup
     screen_destroy_event(event);
 }
 
-void QQnxEventThread::shutdown()
+void QQnxScreenEventThread::shutdown()
 {
     screen_event_t event;
 
@@ -127,14 +126,14 @@ void QQnxEventThread::shutdown()
     errno = 0;
     int result = screen_create_event(&event);
     if (result)
-        qFatal("QQNX: failed to create event, errno=%d", errno);
+        qFatal("QQNX: 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("QQNX: failed to set event type, errno=%d", errno);
+        qFatal("QQNX: failed to set screen event type, errno=%d", errno);
 
     // NOTE: ignore SCREEN_PROPERTY_USER_DATA; treat all user events as shutdown events
 
@@ -142,19 +141,19 @@ void QQnxEventThread::shutdown()
     errno = 0;
     result = screen_send_event(m_screenContext, event, getpid());
     if (result)
-        qFatal("QQNX: failed to set event type, errno=%d", errno);
+        qFatal("QQNX: failed to set screen event type, errno=%d", errno);
 
     // cleanup
     screen_destroy_event(event);
 
-#if defined(QQNXEVENTTHREAD_DEBUG)
-    qDebug() << "QQNX: event loop shutdown begin";
+#if defined(QQNXSCREENEVENTTHREAD_DEBUG)
+    qDebug() << "QQNX: screen event thread shutdown begin";
 #endif
 
     // block until thread terminates
     wait();
 
-#if defined(QQNXEVENTTHREAD_DEBUG)
-    qDebug() << "QQNX: event loop shutdown end";
+#if defined(QQNXSCREENEVENTTHREAD_DEBUG)
+    qDebug() << "QQNX: screen event thread shutdown end";
 #endif
 }
@@ -39,8 +39,8 @@
 **
 ****************************************************************************/
 
-#ifndef QQNXEVENTTHREAD_H
-#define QQNXEVENTTHREAD_H
+#ifndef QQNXSCREENEVENTTHREAD_H
+#define QQNXSCREENEVENTTHREAD_H
 
 #include <QtCore/QThread>
 
@@ -50,11 +50,11 @@ QT_BEGIN_NAMESPACE
 
 class QQnxScreenEventHandler;
 
-class QQnxEventThread : public QThread
+class QQnxScreenEventThread : public QThread
 {
 public:
-    QQnxEventThread(screen_context_t context, QQnxScreenEventHandler *screenEventHandler);
-    virtual ~QQnxEventThread();
+    QQnxScreenEventThread(screen_context_t context, QQnxScreenEventHandler *screenEventHandler);
+    ~QQnxScreenEventThread();
 
     static void injectKeyboardEvent(int flags, int sym, int mod, int scan, int cap);
 
@@ -71,4 +71,4 @@ private:
 
 QT_END_NAMESPACE
 
-#endif // QQNXEVENTTHREAD_H
+#endif // QQNXSCREENEVENTTHREAD_H