summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/mirclient/qmirclientnativeinterface.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/platforms/mirclient/qmirclientnativeinterface.cpp')
-rw-r--r--src/plugins/platforms/mirclient/qmirclientnativeinterface.cpp103
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;
+ }
+}