diff options
author | Gerry Boland <gerry.boland@canonical.com> | 2016-11-02 16:46:53 +0000 |
---|---|---|
committer | Matti Paaso <matti.paaso@qt.io> | 2017-01-24 05:52:52 +0000 |
commit | c28fde3fdac19fd5a5f614bb7983080031c924b3 (patch) | |
tree | 441d2d4ea4e1e17db49ed3b12c7c724cbc6db894 /src/plugins/platforms/mirclient/qmirclientnativeinterface.cpp | |
parent | 4b507e8257243e36f40089d57099c2d668c5884d (diff) |
Mirclient: update based on upstream development in lp:qtubuntu
This is based on revision 360 of lp:qtubuntu.
Main features/bugs fixed:
- fix QQuickWidget-based app rendering
- wire up Qt window types to Mir to enable desktop-based applications
to function with a window manager
- use QEGLPlatformContext and QEGLPBuffer instead of custom code
- correctly populate and update list of QScreens
- support for switching keyboard layouts
- improve window resizing to fix visual glitching
Change-Id: If816a858eb10b6356275d4b80c89a72562b3c29f
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Reviewed-by: Matti Paaso <matti.paaso@qt.io>
Diffstat (limited to 'src/plugins/platforms/mirclient/qmirclientnativeinterface.cpp')
-rw-r--r-- | src/plugins/platforms/mirclient/qmirclientnativeinterface.cpp | 103 |
1 files changed, 82 insertions, 21 deletions
diff --git a/src/plugins/platforms/mirclient/qmirclientnativeinterface.cpp b/src/plugins/platforms/mirclient/qmirclientnativeinterface.cpp index 033df6ba11..b85e6fedfa 100644 --- a/src/plugins/platforms/mirclient/qmirclientnativeinterface.cpp +++ b/src/plugins/platforms/mirclient/qmirclientnativeinterface.cpp @@ -42,32 +42,36 @@ #include "qmirclientnativeinterface.h" #include "qmirclientscreen.h" #include "qmirclientglcontext.h" +#include "qmirclientwindow.h" // Qt -#include <private/qguiapplication_p.h> +#include <QtGui/private/qguiapplication_p.h> #include <QtGui/qopenglcontext.h> #include <QtGui/qscreen.h> #include <QtCore/QMap> -class QMirClientResourceMap : public QMap<QByteArray, QMirClientNativeInterface::ResourceType> +class UbuntuResourceMap : public QMap<QByteArray, QMirClientNativeInterface::ResourceType> { public: - QMirClientResourceMap() + UbuntuResourceMap() : QMap<QByteArray, QMirClientNativeInterface::ResourceType>() { insert("egldisplay", QMirClientNativeInterface::EglDisplay); insert("eglcontext", QMirClientNativeInterface::EglContext); insert("nativeorientation", QMirClientNativeInterface::NativeOrientation); insert("display", QMirClientNativeInterface::Display); insert("mirconnection", QMirClientNativeInterface::MirConnection); + insert("mirsurface", QMirClientNativeInterface::MirSurface); + insert("scale", QMirClientNativeInterface::Scale); + insert("formfactor", QMirClientNativeInterface::FormFactor); } }; -Q_GLOBAL_STATIC(QMirClientResourceMap, ubuntuResourceMap) +Q_GLOBAL_STATIC(UbuntuResourceMap, ubuntuResourceMap) -QMirClientNativeInterface::QMirClientNativeInterface() - : mGenericEventFilterType(QByteArrayLiteral("Event")) +QMirClientNativeInterface::QMirClientNativeInterface(const QMirClientClientIntegration *integration) + : mIntegration(integration) + , mGenericEventFilterType(QByteArrayLiteral("Event")) , mNativeOrientation(nullptr) - , mMirConnection(nullptr) { } @@ -88,7 +92,7 @@ void* QMirClientNativeInterface::nativeResourceForIntegration(const QByteArray & const ResourceType resourceType = ubuntuResourceMap()->value(lowerCaseResource); if (resourceType == QMirClientNativeInterface::MirConnection) { - return mMirConnection; + return mIntegration->mirConnection(); } else { return nullptr; } @@ -119,14 +123,11 @@ void* QMirClientNativeInterface::nativeResourceForWindow(const QByteArray& resou if (!ubuntuResourceMap()->contains(kLowerCaseResource)) return NULL; const ResourceType kResourceType = ubuntuResourceMap()->value(kLowerCaseResource); - if (kResourceType == QMirClientNativeInterface::EglDisplay) { - if (window) { - return static_cast<QMirClientScreen*>(window->screen()->handle())->eglDisplay(); - } else { - return static_cast<QMirClientScreen*>( - QGuiApplication::primaryScreen()->handle())->eglDisplay(); - } - } else if (kResourceType == QMirClientNativeInterface::NativeOrientation) { + + switch (kResourceType) { + case EglDisplay: + return mIntegration->eglDisplay(); + case NativeOrientation: // Return the device's native screen orientation. if (window) { QMirClientScreen *ubuntuScreen = static_cast<QMirClientScreen*>(window->screen()->handle()); @@ -136,8 +137,19 @@ void* QMirClientNativeInterface::nativeResourceForWindow(const QByteArray& resou mNativeOrientation = new Qt::ScreenOrientation(platformScreen->nativeOrientation()); } return mNativeOrientation; - } else { - return NULL; + case MirSurface: + if (window) { + auto ubuntuWindow = static_cast<QMirClientWindow*>(window->handle()); + if (ubuntuWindow) { + return ubuntuWindow->mirSurface(); + } else { + return nullptr; + } + } else { + return nullptr; + } + default: + return nullptr; } } @@ -147,10 +159,59 @@ void* QMirClientNativeInterface::nativeResourceForScreen(const QByteArray& resou if (!ubuntuResourceMap()->contains(kLowerCaseResource)) return NULL; const ResourceType kResourceType = ubuntuResourceMap()->value(kLowerCaseResource); + if (!screen) + screen = QGuiApplication::primaryScreen(); + auto ubuntuScreen = static_cast<QMirClientScreen*>(screen->handle()); if (kResourceType == QMirClientNativeInterface::Display) { - if (!screen) - screen = QGuiApplication::primaryScreen(); - return static_cast<QMirClientScreen*>(screen->handle())->eglNativeDisplay(); + return mIntegration->eglNativeDisplay(); + // Changes to the following properties are emitted via the QMirClientNativeInterface::screenPropertyChanged + // signal fired by QMirClientScreen. Connect to this signal for these properties updates. + // WARNING: code highly thread unsafe! + } else if (kResourceType == QMirClientNativeInterface::Scale) { + // In application code, read with: + // float scale = *reinterpret_cast<float*>(nativeResourceForScreen("scale", screen())); + return &ubuntuScreen->mScale; + } else if (kResourceType == QMirClientNativeInterface::FormFactor) { + return &ubuntuScreen->mFormFactor; } else return NULL; } + +// Changes to these properties are emitted via the QMirClientNativeInterface::windowPropertyChanged +// signal fired by QMirClientWindow. Connect to this signal for these properties updates. +QVariantMap QMirClientNativeInterface::windowProperties(QPlatformWindow *window) const +{ + QVariantMap propertyMap; + auto w = static_cast<QMirClientWindow*>(window); + if (w) { + propertyMap.insert("scale", w->scale()); + propertyMap.insert("formFactor", w->formFactor()); + } + return propertyMap; +} + +QVariant QMirClientNativeInterface::windowProperty(QPlatformWindow *window, const QString &name) const +{ + auto w = static_cast<QMirClientWindow*>(window); + if (!w) { + return QVariant(); + } + + if (name == QStringLiteral("scale")) { + return w->scale(); + } else if (name == QStringLiteral("formFactor")) { + return w->formFactor(); + } else { + return QVariant(); + } +} + +QVariant QMirClientNativeInterface::windowProperty(QPlatformWindow *window, const QString &name, const QVariant &defaultValue) const +{ + QVariant returnVal = windowProperty(window, name); + if (!returnVal.isValid()) { + return defaultValue; + } else { + return returnVal; + } +} |