summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Turner <james.turner.qnx@kdab.com>2012-10-11 15:35:28 (GMT)
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-10-18 00:32:09 (GMT)
commit097af16558e75a961f322b60824506c11491ef63 (patch)
tree5b99699104aa8d7d9134ee1efebeb04d8b56db37
parent53a450d45e344bfe66f401886f31d6749bc5dcd7 (diff)
downloadQt-097af16558e75a961f322b60824506c11491ef63.zip
Qt-097af16558e75a961f322b60824506c11491ef63.tar.gz
Qt-097af16558e75a961f322b60824506c11491ef63.tar.bz2
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 <thomas.mcguire@kdab.com> Reviewed-by: Kevin Krammer <kevin.krammer@kdab.com> Reviewed-by: Rafael Roquetto <rafael.roquetto@kdab.com> Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
-rw-r--r--src/plugins/platforms/blackberry/qbbintegration.cpp59
-rw-r--r--src/plugins/platforms/blackberry/qbbintegration.h4
-rw-r--r--src/plugins/platforms/blackberry/qbbscreeneventhandler.cpp38
-rw-r--r--src/plugins/platforms/blackberry/qbbscreeneventhandler.h6
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; i<displayCount; i++) {
-#if defined(QBBINTEGRATION_DEBUG)
- qDebug() << "QBBIntegration: Creating screen for display " << i;
-#endif
- QBBScreen *screen = new QBBScreen(mContext, displays[i], i);
- mScreens.push_back(screen);
+ int isAttached = 0;
+ result = screen_get_display_property_iv(displays[i], SCREEN_PROPERTY_ATTACHED, &isAttached);
+ if (result != 0) {
+ qWarning("QBBIntegration: failed to query display attachment, errno=%d", errno);
+ isAttached = 1; // assume attached
+ }
- QObject::connect(mScreenEventHandler, SIGNAL(newWindowCreated(screen_window_t)),
- screen, SLOT(newWindowCreated(screen_window_t)));
- QObject::connect(mScreenEventHandler, SIGNAL(windowClosed(screen_window_t)),
- screen, SLOT(windowClosed(screen_window_t)));
+ if (!isAttached)
+ continue;
- QObject::connect(mNavigatorEventHandler, SIGNAL(rotationChanged(int)), screen, SLOT(setRotation(int)));
- QObject::connect(mNavigatorEventHandler, SIGNAL(windowGroupActivated(QByteArray)), screen, SLOT(activateWindowGroup(QByteArray)));
- QObject::connect(mNavigatorEventHandler, SIGNAL(windowGroupDeactivated(QByteArray)), screen, SLOT(deactivateWindowGroup(QByteArray)));
- }
+ createDisplay(displays[i], i == 0);
+ } // of displays iteration
+}
+
+void QBBIntegration::createDisplay(screen_display_t display, bool isPrimary)
+{
+ QBBScreen *screen = new QBBScreen(mContext, display, isPrimary);
+ mScreens.append(screen);
+
+ QObject::connect(mScreenEventHandler, SIGNAL(newWindowCreated(screen_window_t)),
+ screen, SLOT(newWindowCreated(screen_window_t)));
+ QObject::connect(mScreenEventHandler, SIGNAL(windowClosed(screen_window_t)),
+ screen, SLOT(windowClosed(screen_window_t)));
+
+ QObject::connect(mNavigatorEventHandler, SIGNAL(rotationChanged(int)), screen, SLOT(setRotation(int)));
+ QObject::connect(mNavigatorEventHandler, SIGNAL(windowGroupActivated(QByteArray)), screen, SLOT(activateWindowGroup(QByteArray)));
+ QObject::connect(mNavigatorEventHandler, SIGNAL(windowGroupDeactivated(QByteArray)), screen, SLOT(deactivateWindowGroup(QByteArray)));
+}
+
+void QBBIntegration::removeDisplay(QBBScreen *screen)
+{
+ Q_CHECK_PTR(screen);
+ Q_ASSERT(mScreens.contains(screen));
+ mScreens.removeAll(screen);
+ screen->deleteLater();
}
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<QBBScreen*>(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;