From 097af16558e75a961f322b60824506c11491ef63 Mon Sep 17 00:00:00 2001 From: James Turner Date: Thu, 11 Oct 2012 16:35:28 +0100 Subject: QNX: Add and remove screens dynamically. Backport from Qt5: Watch for display events from libscreen, and dynamically add and remove QPlatformScreens (and hence QScreens) in response. Qt5 commit: 1f0d430c3a660c9e72581b582fe16c440bcf9eac Change-Id: I65f69fc9eca5b32b0aa0e929d09837a6f01385d0 Reviewed-by: Thomas McGuire Reviewed-by: Kevin Krammer Reviewed-by: Rafael Roquetto Reviewed-by: Marc Mutz --- .../platforms/blackberry/qbbintegration.cpp | 59 +++++++++++++++++----- src/plugins/platforms/blackberry/qbbintegration.h | 4 ++ .../platforms/blackberry/qbbscreeneventhandler.cpp | 38 +++++++++++++- .../platforms/blackberry/qbbscreeneventhandler.h | 6 ++- 4 files changed, 90 insertions(+), 17 deletions(-) diff --git a/src/plugins/platforms/blackberry/qbbintegration.cpp b/src/plugins/platforms/blackberry/qbbintegration.cpp index 85dd6cf..e329bbe 100644 --- a/src/plugins/platforms/blackberry/qbbintegration.cpp +++ b/src/plugins/platforms/blackberry/qbbintegration.cpp @@ -87,7 +87,7 @@ QBBIntegration::QBBIntegration() : mNavigatorEventHandler(new QBBNavigatorEventHandler()), mButtonsNotifier(new QBBButtonEventNotifier()), mFontDb(new QGenericUnixFontDatabase()), - mScreenEventHandler(new QBBScreenEventHandler()), + mScreenEventHandler(new QBBScreenEventHandler(this)), mPaintUsingOpenGL(getenv("QBB_USE_OPENGL") != NULL), mVirtualKeyboard(0), mNativeInterface(new QBBNativeInterface(this)), @@ -351,21 +351,41 @@ void QBBIntegration::createDisplays() qFatal("QBBIntegration: failed to query displays, errno=%d", errno); for (int i=0; ideleteLater(); } void QBBIntegration::destroyDisplays() @@ -374,4 +394,15 @@ void QBBIntegration::destroyDisplays() mScreens.clear(); } +QBBScreen *QBBIntegration::screenForNative(screen_display_t nativeScreen) const +{ + Q_FOREACH (QPlatformScreen *screen, mScreens) { + QBBScreen *bbScreen = static_cast(screen); + if (bbScreen->nativeDisplay() == nativeScreen) + return bbScreen; + } + + return 0; +} + QT_END_NAMESPACE diff --git a/src/plugins/platforms/blackberry/qbbintegration.h b/src/plugins/platforms/blackberry/qbbintegration.h index c2ff8f7..b524950 100644 --- a/src/plugins/platforms/blackberry/qbbintegration.h +++ b/src/plugins/platforms/blackberry/qbbintegration.h @@ -86,6 +86,10 @@ public: QBBScreen *screenForWindow(screen_window_t window) const; + QBBScreen *screenForNative(screen_display_t screen) const; + + void createDisplay(screen_display_t display, bool isPrimary); + void removeDisplay(QBBScreen *screen); private: QBBScreen *primaryDisplay() const; void createDisplays(); diff --git a/src/plugins/platforms/blackberry/qbbscreeneventhandler.cpp b/src/plugins/platforms/blackberry/qbbscreeneventhandler.cpp index 14040f4..f408a49 100644 --- a/src/plugins/platforms/blackberry/qbbscreeneventhandler.cpp +++ b/src/plugins/platforms/blackberry/qbbscreeneventhandler.cpp @@ -43,6 +43,8 @@ #include "qbbscreeneventhandler.h" +#include "qbbscreen.h" +#include "qbbintegration.h" #include "qbbinputcontext.h" #include "qbbkeytranslator.h" @@ -54,8 +56,9 @@ QT_BEGIN_NAMESPACE -QBBScreenEventHandler::QBBScreenEventHandler() - : mLastButtonState(Qt::NoButton) +QBBScreenEventHandler::QBBScreenEventHandler(QBBIntegration *integration) + : mBBIntegration(integration) + , mLastButtonState(Qt::NoButton) , mLastMouseWindow(0) { // initialize array of touch points @@ -113,6 +116,10 @@ bool QBBScreenEventHandler::handleEvent(screen_event_t event, int qnxType) handleCreateEvent(event); break; + case SCREEN_EVENT_DISPLAY: + handleDisplayEvent(event); + break; + default: // event ignored #if defined(QBBSCREENEVENTHANDLER_DEBUG) @@ -540,6 +547,33 @@ void QBBScreenEventHandler::handleCreateEvent(screen_event_t event) emit newWindowCreated(window); } +void QBBScreenEventHandler::handleDisplayEvent(screen_event_t event) +{ + screen_display_t nativeDisplay = 0; + if (screen_get_event_property_pv(event, SCREEN_PROPERTY_DISPLAY, (void **)&nativeDisplay) != 0) { + qWarning("QBB: failed to query display property, errno=%d", errno); + return; + } + + int isAttached = 0; + if (screen_get_event_property_iv(event, SCREEN_PROPERTY_ATTACHED, &isAttached) != 0) { + qWarning("QBB: failed to query display attached property, errno=%d", errno); + return; + } + +#if defined(QBBSCREENEVENTHANDLER_DEBUG) + qDebug() << Q_FUNC_INFO << "display attachment is now:" << isAttached; +#endif + QBBScreen *screen = mBBIntegration->screenForNative(nativeDisplay); + if (!screen) { + if (isAttached) + mBBIntegration->createDisplay(nativeDisplay, false /* not primary, we assume */); + } else if (!isAttached) { + // libscreen display is deactivated, let's remove the QBBScreen / QScreen + mBBIntegration->removeDisplay(screen); + } +} + #include "moc_qbbscreeneventhandler.cpp" QT_END_NAMESPACE diff --git a/src/plugins/platforms/blackberry/qbbscreeneventhandler.h b/src/plugins/platforms/blackberry/qbbscreeneventhandler.h index c44240a..70f2447 100644 --- a/src/plugins/platforms/blackberry/qbbscreeneventhandler.h +++ b/src/plugins/platforms/blackberry/qbbscreeneventhandler.h @@ -48,11 +48,13 @@ QT_BEGIN_NAMESPACE +class QBBIntegration; + class QBBScreenEventHandler : public QObject { Q_OBJECT public: - QBBScreenEventHandler(); + explicit QBBScreenEventHandler(QBBIntegration *integration); static void injectKeyboardEvent(int flags, int sym, int mod, int scan, int cap); void injectPointerMoveEvent(int x, int y); @@ -70,12 +72,14 @@ private: void handleTouchEvent(screen_event_t event, int type); void handleCloseEvent(screen_event_t event); void handleCreateEvent(screen_event_t event); + void handleDisplayEvent(screen_event_t event); private: enum { MAX_TOUCH_POINTS = 10 }; + QBBIntegration *mBBIntegration; QPoint mLastGlobalMousePoint; QPoint mLastLocalMousePoint; Qt::MouseButtons mLastButtonState; -- cgit v0.12