on xenial help sign in
multi screen desktop mock
commit8ec082fa92e5f3733eba7ad2909cf30e18cc74bd authorNick Dedekind <nick.dedekind@canonical.com> dateThu 12 Jan 2017, 10:58 (10 years ago) parenta6d26bc
11 files changed+112−4
tests/mocks/GSettings.1.0/plugin.cpp+12 tests/mocks/GSettings.1.0/plugin.h+1 tests/mocks/Unity/InputInfo/mockcontroller.cpp+6 tests/mocks/Unity/InputInfo/mockcontroller.h+2 tests/mocks/Unity/InputInfo/plugin.cpp+11−1 tests/mocks/Unity/InputInfo/plugin.h+1 tests/mocks/Unity/Screens/CMakeLists.txt+2−1 tests/mocks/Unity/Screens/plugin.cpp+3 tests/mocks/Unity/Screens/screens.cpp+6−2 tests/mocks/Unity/Screens/screenwindow.cpp+32 tests/mocks/Unity/Screens/screenwindow.h+36
tests/mocks/GSettings.1.0/plugin.cpp+12
@@ -18,6 +18,8 @@
1818#include "fake_gsettings.h"
1919
2020#include <QtQml/qqml.h>
21+#include <QQmlEngine>
22+#include <QQmlContext>
2123
2224static QObject* controllerProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */)
2325{
@@ -31,3 +33,13 @@ void FakeGSettingsQmlPlugin::registerTypes(const char *uri)
3133 qmlRegisterUncreatableType<GSettingsSchemaQml>(uri, 1, 0, "GSettingsSchema",
3234 "GSettingsSchema can only be used inside of a GSettings component");
3335}
36+
37+void FakeGSettingsQmlPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
38+{
39+ QQmlExtensionPlugin::initializeEngine(engine, uri);
40+
41+ QString usageType = qgetenv("UNITY_MOCK_DESKTOP");
42+ if (!usageType.isEmpty()) {
43+ GSettingsControllerQml::instance()->setUsageMode("Windowed");
44+ }
45+}
tests/mocks/GSettings.1.0/plugin.h+1
@@ -26,6 +26,7 @@ class FakeGSettingsQmlPlugin : public QQmlExtensionPlugin
2626
2727public:
2828 void registerTypes(const char *uri) override;
29+ void initializeEngine(QQmlEngine *engine, const char *uri) override;
2930};
3031
3132#endif // PLUGIN_H
tests/mocks/Unity/InputInfo/mockcontroller.cpp+6
@@ -24,6 +24,12 @@ MockController::MockController(QObject *parent):
2424
2525}
2626
27+MockController *MockController::instance()
28+{
29+ static MockController* controller = new MockController;
30+ return controller;
31+}
32+
2733QInputDevice *MockController::addMockDevice(const QString &devicePath, QInputDevice::InputType type)
2834{
2935 return QInputDeviceManagerPrivate::instance()->addMockDevice(devicePath, type);
tests/mocks/Unity/InputInfo/mockcontroller.h+2
@@ -27,6 +27,8 @@ public:
2727 MockController(QObject *parent = 0);
2828 ~MockController() = default;
2929
30+ static MockController *instance();
31+
3032 Q_INVOKABLE QInputDevice* addMockDevice(const QString &devicePath, QInputDevice::InputType type);
3133 Q_INVOKABLE void removeDevice(const QString &devicePath);
3234};
tests/mocks/Unity/InputInfo/plugin.cpp+11−1
@@ -28,7 +28,7 @@ static QObject *backendProvider(QQmlEngine *engine, QJSEngine *scriptEngine)
2828{
2929 Q_UNUSED(engine)
3030 Q_UNUSED(scriptEngine)
31− return new MockController(engine);
31+ return MockController::instance();
3232}
3333
3434void InputInfoPlugin::registerTypes(const char *uri)
@@ -44,3 +44,13 @@ void InputInfoPlugin::registerTypes(const char *uri)
4444 // MockController
4545 qmlRegisterSingletonType<MockController>(uri, major, minor, "MockInputDeviceBackend", backendProvider);
4646}
47+
48+void InputInfoPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
49+{
50+ QQmlExtensionPlugin::initializeEngine(engine, uri);
51+
52+ if (qEnvironmentVariableIsSet("UNITY_MOCK_DESKTOP")) {
53+ MockController::instance()->addMockDevice("/mouse0", QInputDevice::Mouse);
54+ MockController::instance()->addMockDevice("/kbd0", QInputDevice::Keyboard);
55+ }
56+}
tests/mocks/Unity/InputInfo/plugin.h+1
@@ -25,6 +25,7 @@ class InputInfoPlugin : public QQmlExtensionPlugin
2525 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
2626public:
2727 void registerTypes(const char *uri) override;
28+ void initializeEngine(QQmlEngine *engine, const char *uri);
2829};
2930
3031#endif // INPUTINFO_PLUGIN_H
tests/mocks/Unity/Screens/CMakeLists.txt+2−1
@@ -5,10 +5,11 @@ include_directories(
55set(MockScreens_SOURCES
66 plugin.cpp
77 screens.cpp
8+ screenwindow.cpp
89)
910
1011add_library(MockScreensPlugin MODULE ${MockScreens_SOURCES})
1112
12−qt5_use_modules(MockScreensPlugin Gui Qml)
13+qt5_use_modules(MockScreensPlugin Gui Qml Quick)
1314
1415add_unity8_mock(Unity.Screens 0.1 Unity/Screens PREFIX mocks TARGETS MockScreensPlugin)
tests/mocks/Unity/Screens/plugin.cpp+3
@@ -16,6 +16,7 @@
1616
1717#include "plugin.h"
1818#include "screens.h"
19+#include "screenwindow.h"
1920
2021#include <QScreen>
2122
@@ -26,4 +27,6 @@ void UnityScreensPlugin::registerTypes(const char* uri)
2627 qRegisterMetaType<QScreen*>("QScreen*");
2728
2829 qmlRegisterType<Screens>(uri, 0, 1, "Screens");
30+ qmlRegisterType<ScreenWindow>(uri, 0, 1, "ScreenWindow");
31+ qmlRegisterRevision<QWindow,1>(uri, 0, 1);
2932}
tests/mocks/Unity/Screens/screens.cpp+6−2
@@ -26,8 +26,12 @@ Q_DECLARE_METATYPE(QScreen*)
2626Screens::Screens(QObject *parent) :
2727 QAbstractListModel(parent)
2828{
29− // start with one screen attached
30− m_screenList.append(new Screen());
29+ bool ok = false;
30+ int screenCount = qEnvironmentVariableIntValue("UNITY_MOCK_SCREEN_COUNT", &ok);
31+ if (!ok) screenCount = 1;
32+ for (int i = 0; i < screenCount; ++i) {
33+ m_screenList.append(new Screen());
34+ }
3135}
3236
3337Screens::~Screens()
tests/mocks/Unity/Screens/screenwindow.cppnew file+32
@@ -0,0 +1,32 @@
1+/*
2+ * Copyright (C) 2016 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#include "screenwindow.h"
18+
19+ScreenWindow::ScreenWindow(QWindow *parent)
20+ : QQuickWindow(parent)
21+{
22+}
23+
24+QScreen *ScreenWindow::screen() const
25+{
26+ return QQuickWindow::screen();
27+}
28+
29+void ScreenWindow::setScreen(QScreen *screen)
30+{
31+ QQuickWindow::setScreen(screen);
32+}
tests/mocks/Unity/Screens/screenwindow.hnew file+36
@@ -0,0 +1,36 @@
1+/*
2+ * Copyright (C) 2016 Canonical, Ltd.
3+ *
4+ * This program is free software: you can redistribute it and/or modify it under
5+ * the terms of the GNU Lesser General Public License version 3, as published by
6+ * the Free Software Foundation.
7+ *
8+ * This program is distributed in the hope that it will be useful, but WITHOUT
9+ * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10+ * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+ * Lesser General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU Lesser General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+#ifndef SCREENWINDOW_H
18+#define SCREENWINDOW_H
19+
20+#include <QQuickWindow>
21+
22+class ScreenWindow : public QQuickWindow
23+{
24+ Q_OBJECT
25+ Q_PROPERTY(QScreen *screen READ screen WRITE setScreen NOTIFY screenChanged)
26+public:
27+ ScreenWindow(QWindow *parent = 0);
28+
29+ QScreen *screen() const;
30+ void setScreen(QScreen *screen);
31+
32+Q_SIGNALS:
33+ void screenChanged(QScreen *screen);
34+};
35+
36+#endif // SCREENWINDOW_H