From 3662027578f85366547e8e172cf3a42c54e59793 Mon Sep 17 00:00:00 2001 From: Kevin Krammer Date: Mon, 16 Apr 2012 09:53:17 +0200 Subject: Use BPS based event handling Create a QPA specific subclass of the blackberry event dispatcher (basically the BPS equivalent to QPAEventDispatcherGlib or QEventDispatcherQPA. Create an event dispatcher event filter that will receive all BPS events and then either handle them itself or delegate to event subtype specific handlers. Backport of fa94f01489611f2c72d1678b4d9439a584e7c4f9 Change-Id: Ie51c064c5ef1faca04e09a4f7ff35069ff6afda5 Reviewed-by: Thomas McGuire Reviewed-by: Sean Harmer Reviewed-by: Giuseppe D'Angelo --- src/gui/kernel/kernel.pri | 7 ++ src/gui/kernel/qapplication_qpa.cpp | 8 ++ src/gui/kernel/qeventdispatcher_blackberry_qpa.cpp | 116 +++++++++++++++++++++ src/gui/kernel/qeventdispatcher_blackberry_qpa_p.h | 76 ++++++++++++++ src/plugins/platforms/blackberry/blackberry.pro | 6 ++ .../platforms/blackberry/qbbbpseventfilter.cpp | 107 +++++++++++++++++++ .../platforms/blackberry/qbbbpseventfilter.h | 67 ++++++++++++ .../platforms/blackberry/qbbintegration.cpp | 12 ++- src/plugins/platforms/blackberry/qbbintegration.h | 2 + 9 files changed, 399 insertions(+), 2 deletions(-) create mode 100644 src/gui/kernel/qeventdispatcher_blackberry_qpa.cpp create mode 100644 src/gui/kernel/qeventdispatcher_blackberry_qpa_p.h create mode 100644 src/plugins/platforms/blackberry/qbbbpseventfilter.cpp create mode 100644 src/plugins/platforms/blackberry/qbbbpseventfilter.h diff --git a/src/gui/kernel/kernel.pri b/src/gui/kernel/kernel.pri index 3c57368..d9d67e7 100644 --- a/src/gui/kernel/kernel.pri +++ b/src/gui/kernel/kernel.pri @@ -261,6 +261,13 @@ qpa { QMAKE_CXXFLAGS += $$QT_CFLAGS_GLIB LIBS_PRIVATE +=$$QT_LIBS_GLIB } + + blackberry { + SOURCES += \ + kernel/qeventdispatcher_blackberry_qpa.cpp + HEADERS += \ + kernel/qeventdispatcher_blackberry_qpa_p.h + } } !embedded:!qpa:!x11:mac { diff --git a/src/gui/kernel/qapplication_qpa.cpp b/src/gui/kernel/qapplication_qpa.cpp index 242b5ef..b777e38 100644 --- a/src/gui/kernel/qapplication_qpa.cpp +++ b/src/gui/kernel/qapplication_qpa.cpp @@ -42,10 +42,14 @@ #include "qapplication_p.h" #include "qcolormap.h" #include "qpixmapcache.h" +#if defined(Q_OS_BLACKBERRY) +#include "qeventdispatcher_blackberry_qpa_p.h" +#else #if !defined(QT_NO_GLIB) #include "qeventdispatcher_glib_qpa_p.h" #endif #include "qeventdispatcher_qpa_p.h" +#endif #ifndef QT_NO_CURSOR #include "private/qcursor_p.h" #endif @@ -147,12 +151,16 @@ QString QApplicationPrivate::appName() const void QApplicationPrivate::createEventDispatcher() { Q_Q(QApplication); +#if defined(Q_OS_BLACKBERRY) + eventDispatcher = new QEventDispatcherBlackberryQPA(q); +#else #if !defined(QT_NO_GLIB) if (qgetenv("QT_NO_GLIB").isEmpty() && QEventDispatcherGlib::versionSupported()) eventDispatcher = new QPAEventDispatcherGlib(q); else #endif eventDispatcher = new QEventDispatcherQPA(q); +#endif } static bool qt_try_modal(QWidget *widget, QEvent::Type type) diff --git a/src/gui/kernel/qeventdispatcher_blackberry_qpa.cpp b/src/gui/kernel/qeventdispatcher_blackberry_qpa.cpp new file mode 100644 index 0000000..a7aa9a8 --- /dev/null +++ b/src/gui/kernel/qeventdispatcher_blackberry_qpa.cpp @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** Contact: Research In Motion +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qeventdispatcher_blackberry_qpa_p.h" + +#include "qapplication_p.h" + +#include + +QT_BEGIN_NAMESPACE + +static bool sendWindowSystemEvents(QAbstractEventDispatcher *eventDispatcher, QEventLoop::ProcessEventsFlags flags) +{ + int nevents = 0; + + // handle gui and posted events + QCoreApplication::sendPostedEvents(); + + while (true) { + QWindowSystemInterfacePrivate::WindowSystemEvent *event; + if (!(flags & QEventLoop::ExcludeUserInputEvents) + && QWindowSystemInterfacePrivate::windowSystemEventsQueued() > 0) { + // process a pending user input event + event = QWindowSystemInterfacePrivate::getWindowSystemEvent(); + if (!event) + break; + } else { + break; + } + + if (eventDispatcher->filterEvent(event)) { + delete event; + continue; + } + + nevents++; + + QApplicationPrivate::processWindowSystemEvent(event); + delete event; + } + + return (nevents > 0); +} + +QEventDispatcherBlackberryQPA::QEventDispatcherBlackberryQPA(QObject *parent) + : QEventDispatcherBlackberry(parent) +{ +} + +QEventDispatcherBlackberryQPA::~QEventDispatcherBlackberryQPA() +{ +} + +bool QEventDispatcherBlackberryQPA::processEvents(QEventLoop::ProcessEventsFlags flags) +{ + bool didSendEvents = sendWindowSystemEvents(this, flags); + + if (QEventDispatcherBlackberry::processEvents(flags)) + return true; + + return didSendEvents; +} + +bool QEventDispatcherBlackberryQPA::hasPendingEvents() +{ + return QEventDispatcherBlackberry::hasPendingEvents() || QWindowSystemInterfacePrivate::windowSystemEventsQueued(); +} + +void QEventDispatcherBlackberryQPA::flush() +{ + if (qApp) + qApp->sendPostedEvents(); +} + +QT_END_NAMESPACE diff --git a/src/gui/kernel/qeventdispatcher_blackberry_qpa_p.h b/src/gui/kernel/qeventdispatcher_blackberry_qpa_p.h new file mode 100644 index 0000000..7c5b5a1 --- /dev/null +++ b/src/gui/kernel/qeventdispatcher_blackberry_qpa_p.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** +** Contact: Research In Motion +** +** This file is part of the QtGui module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QEVENTDISPATCHER_BLACKBERRY_QPA_P_H +#define QEVENTDISPATCHER_BLACkBERRY_QPA_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include + +QT_BEGIN_NAMESPACE + +class QEventDispatcherBlackberryQPA : public QEventDispatcherBlackberry +{ + Q_OBJECT + +public: + explicit QEventDispatcherBlackberryQPA(QObject *parent = 0); + ~QEventDispatcherBlackberryQPA(); + + bool processEvents(QEventLoop::ProcessEventsFlags flags); + bool hasPendingEvents(); + + void flush(); +}; + +QT_END_NAMESPACE + +#endif // QEVENTDISPATCHER_BLACKBERRY_QPA_P_H diff --git a/src/plugins/platforms/blackberry/blackberry.pro b/src/plugins/platforms/blackberry/blackberry.pro index cded59c..2b0f0ab 100644 --- a/src/plugins/platforms/blackberry/blackberry.pro +++ b/src/plugins/platforms/blackberry/blackberry.pro @@ -43,6 +43,12 @@ HEADERS = qbbbuffer.h \ qbbabstractvirtualkeyboard.h \ qbbnativeinterface.h +blackberry { + SOURCES += qbbbpseventfilter.cpp + + HEADERS += qbbbpseventfilter.h +} + QMAKE_CXXFLAGS += -I./private LIBS += -lpps -lscreen -lEGL -lclipboard diff --git a/src/plugins/platforms/blackberry/qbbbpseventfilter.cpp b/src/plugins/platforms/blackberry/qbbbpseventfilter.cpp new file mode 100644 index 0000000..97ed89c --- /dev/null +++ b/src/plugins/platforms/blackberry/qbbbpseventfilter.cpp @@ -0,0 +1,107 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** +** Contact: Research In Motion +** Contact: Klarälvdalens Datakonsult AB +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +//#define QBBBPSEVENTFILTER_DEBUG + +#include "qbbbpseventfilter.h" + +#include +#include + +#include + +QT_BEGIN_NAMESPACE + +static QBBBpsEventFilter *sInstance; + +QBBBpsEventFilter::QBBBpsEventFilter(QObject *parent) + : QObject(parent) +{ + Q_ASSERT(sInstance == 0); + + sInstance = this; +} + +QBBBpsEventFilter::~QBBBpsEventFilter() +{ + Q_ASSERT(sInstance == this); + + sInstance = 0; +} + +void QBBBpsEventFilter::installOnEventDispatcher(QAbstractEventDispatcher *dispatcher) +{ +#if defined(QBBBPSEVENTFILTER_DEBUG) + qDebug() << Q_FUNC_INFO << "dispatcher=" << dispatcher; +#endif + + QAbstractEventDispatcher::EventFilter previousEventFilter = dispatcher->setEventFilter(dispatcherEventFilter); + + // the QPA plugin in created in the QApplication constructor which indirectly also creates + // the event dispatcher so we are the first event filter. + // assert on that just in case somebody adds another event filter + // in the QBBIntegration constructor instead of adding a new section in here + Q_ASSERT(previousEventFilter == 0); + Q_UNUSED(previousEventFilter); +} + +bool QBBBpsEventFilter::dispatcherEventFilter(void *message) +{ +#if defined(QBBBPSEVENTFILTER_DEBUG) + qDebug() << Q_FUNC_INFO; +#endif + if (sInstance == 0) + return false; + + bps_event_t *event = static_cast(message); + return sInstance->bpsEventFilter(event); +} + +bool QBBBpsEventFilter::bpsEventFilter(bps_event_t *event) +{ +#if defined(QBBBPSEVENTFILTER_DEBUG) + qDebug() << Q_FUNC_INFO << "event=" << event << "domain=" << bps_event_get_domain(event); +#else + Q_UNUSED(event); +#endif + + return false; +} + +QT_END_NAMESPACE diff --git a/src/plugins/platforms/blackberry/qbbbpseventfilter.h b/src/plugins/platforms/blackberry/qbbbpseventfilter.h new file mode 100644 index 0000000..3466577 --- /dev/null +++ b/src/plugins/platforms/blackberry/qbbbpseventfilter.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Research In Motion +** +** Contact: Research In Motion +** Contact: Klarälvdalens Datakonsult AB +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QBBBPSEVENTFILTER_H +#define QBBBPSEVENTFILTER_H + +#include + +struct bps_event_t; + +QT_BEGIN_NAMESPACE + +class QAbstractEventDispatcher; + +class QBBBpsEventFilter : public QObject +{ + Q_OBJECT +public: + explicit QBBBpsEventFilter(QObject *parent = 0); + ~QBBBpsEventFilter(); + + void installOnEventDispatcher(QAbstractEventDispatcher *dispatcher); + +private: + static bool dispatcherEventFilter(void *message); + bool bpsEventFilter(bps_event_t *event); +}; + +QT_END_NAMESPACE + +#endif // QBBBPSEVENTFILTER_H diff --git a/src/plugins/platforms/blackberry/qbbintegration.cpp b/src/plugins/platforms/blackberry/qbbintegration.cpp index 32c795b..ee06c31 100644 --- a/src/plugins/platforms/blackberry/qbbintegration.cpp +++ b/src/plugins/platforms/blackberry/qbbintegration.cpp @@ -56,8 +56,12 @@ #include "qbbglcontext.h" #include "qbblocalethread.h" #include "qbbnativeinterface.h" +#if defined(Q_OS_BLACKBERRY) +#include "qbbbpseventfilter.h" +#endif -#include "qapplication.h" +#include +#include #include #include #include @@ -80,7 +84,8 @@ QBBIntegration::QBBIntegration() : mScreenEventHandler(new QBBScreenEventHandler()), mPaintUsingOpenGL(getenv("QBB_USE_OPENGL") != NULL), mVirtualKeyboard(0), - mNativeInterface(new QBBNativeInterface(this)) + mNativeInterface(new QBBNativeInterface(this)), + mBpsEventFilter(0) { qRegisterMetaType(); @@ -123,6 +128,8 @@ QBBIntegration::QBBIntegration() : #if defined(Q_OS_BLACKBERRY) bps_initialize(); + mBpsEventFilter = new QBBBpsEventFilter; + mBpsEventFilter->installOnEventDispatcher(QAbstractEventDispatcher::instance()); #endif // create/start the keyboard class. @@ -176,6 +183,7 @@ QBBIntegration::~QBBIntegration() QBBGLContext::shutdown(); #if defined(Q_OS_BLACKBERRY) + delete mBpsEventFilter; bps_shutdown(); #endif diff --git a/src/plugins/platforms/blackberry/qbbintegration.h b/src/plugins/platforms/blackberry/qbbintegration.h index ac51f0f..eaf3876 100644 --- a/src/plugins/platforms/blackberry/qbbintegration.h +++ b/src/plugins/platforms/blackberry/qbbintegration.h @@ -54,6 +54,7 @@ class QBBAbstractVirtualKeyboard; class QBBScreen; class QBBScreenEventHandler; class QBBNativeInterface; +class QBBBpsEventFilter; class QBBIntegration : public QPlatformIntegration { @@ -98,6 +99,7 @@ private: bool mPaintUsingOpenGL; QBBAbstractVirtualKeyboard *mVirtualKeyboard; QBBNativeInterface *mNativeInterface; + QBBBpsEventFilter *mBpsEventFilter; }; QT_END_NAMESPACE -- cgit v0.12