on xenial help sign in
multi screen desktop mock
8ec082fNick Dedekind
tests/mocks/GSettings.1.0/plugin.cpp+12
@@ -18,6 +18,8 @@
18#include "fake_gsettings.h"
18#include "fake_gsettings.h"
19
19
20#include <QtQml/qqml.h>
20#include <QtQml/qqml.h>
21+#include <QQmlEngine>
22+#include <QQmlContext>
21
23
22static QObject* controllerProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */)
24static QObject* controllerProvider(QQmlEngine* /* engine */, QJSEngine* /* scriptEngine */)
23{
25{
@@ -31,3 +33,13 @@ void FakeGSettingsQmlPlugin::registerTypes(const char *uri)
31 qmlRegisterUncreatableType<GSettingsSchemaQml>(uri, 1, 0, "GSettingsSchema",
33 qmlRegisterUncreatableType<GSettingsSchemaQml>(uri, 1, 0, "GSettingsSchema",
32 "GSettingsSchema can only be used inside of a GSettings component");
34 "GSettingsSchema can only be used inside of a GSettings component");
33}
35}
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
26
26
27public:
27public:
28 void registerTypes(const char *uri) override;
28 void registerTypes(const char *uri) override;
29+ void initializeEngine(QQmlEngine *engine, const char *uri) override;
29};
30};
30
31
31#endif // PLUGIN_H
32#endif // PLUGIN_H
tests/mocks/Unity/InputInfo/mockcontroller.cpp+6
@@ -24,6 +24,12 @@ MockController::MockController(QObject *parent):
24
24
25}
25}
26
26
27+MockController *MockController::instance()
28+{
29+ static MockController* controller = new MockController;
30+ return controller;
31+}
32+
27QInputDevice *MockController::addMockDevice(const QString &devicePath, QInputDevice::InputType type)
33QInputDevice *MockController::addMockDevice(const QString &devicePath, QInputDevice::InputType type)
28{
34{
29 return QInputDeviceManagerPrivate::instance()->addMockDevice(devicePath, type);
35 return QInputDeviceManagerPrivate::instance()->addMockDevice(devicePath, type);
tests/mocks/Unity/InputInfo/mockcontroller.h+2
@@ -27,6 +27,8 @@ public:
27 MockController(QObject *parent = 0);
27 MockController(QObject *parent = 0);
28 ~MockController() = default;
28 ~MockController() = default;
29
29
30+ static MockController *instance();
31+
30 Q_INVOKABLE QInputDevice* addMockDevice(const QString &devicePath, QInputDevice::InputType type);
32 Q_INVOKABLE QInputDevice* addMockDevice(const QString &devicePath, QInputDevice::InputType type);
31 Q_INVOKABLE void removeDevice(const QString &devicePath);
33 Q_INVOKABLE void removeDevice(const QString &devicePath);
32};
34};
tests/mocks/Unity/InputInfo/plugin.cpp+11−1
@@ -28,7 +28,7 @@ static QObject *backendProvider(QQmlEngine *engine, QJSEngine *scriptEngine)
28{
28{
29 Q_UNUSED(engine)
29 Q_UNUSED(engine)
30 Q_UNUSED(scriptEngine)
30 Q_UNUSED(scriptEngine)
31− return new MockController(engine);
31+ return MockController::instance();
32}
32}
33
33
34void InputInfoPlugin::registerTypes(const char *uri)
34void InputInfoPlugin::registerTypes(const char *uri)
@@ -44,3 +44,13 @@ void InputInfoPlugin::registerTypes(const char *uri)
44 // MockController
44 // MockController
45 qmlRegisterSingletonType<MockController>(uri, major, minor, "MockInputDeviceBackend", backendProvider);
45 qmlRegisterSingletonType<MockController>(uri, major, minor, "MockInputDeviceBackend", backendProvider);
46}
46}
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
25 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
25 Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
26public:
26public:
27 void registerTypes(const char *uri) override;
27 void registerTypes(const char *uri) override;
28+ void initializeEngine(QQmlEngine *engine, const char *uri);
28};
29};
29
30
30#endif // INPUTINFO_PLUGIN_H
31#endif // INPUTINFO_PLUGIN_H
tests/mocks/Unity/Screens/CMakeLists.txt+2−1
@@ -5,10 +5,11 @@ include_directories(
5set(MockScreens_SOURCES
5set(MockScreens_SOURCES
6 plugin.cpp
6 plugin.cpp
7 screens.cpp
7 screens.cpp
8+ screenwindow.cpp
8)
9)
9
10
10add_library(MockScreensPlugin MODULE ${MockScreens_SOURCES})
11add_library(MockScreensPlugin MODULE ${MockScreens_SOURCES})
11
12
12−qt5_use_modules(MockScreensPlugin Gui Qml)
13+qt5_use_modules(MockScreensPlugin Gui Qml Quick)
13
14
14add_unity8_mock(Unity.Screens 0.1 Unity/Screens PREFIX mocks TARGETS MockScreensPlugin)
15add_unity8_mock(Unity.Screens 0.1 Unity/Screens PREFIX mocks TARGETS MockScreensPlugin)
tests/mocks/Unity/Screens/plugin.cpp+3
@@ -16,6 +16,7 @@
16
16
17#include "plugin.h"
17#include "plugin.h"
18#include "screens.h"
18#include "screens.h"
19+#include "screenwindow.h"
19
20
20#include <QScreen>
21#include <QScreen>
21
22
@@ -26,4 +27,6 @@ void UnityScreensPlugin::registerTypes(const char* uri)
26 qRegisterMetaType<QScreen*>("QScreen*");
27 qRegisterMetaType<QScreen*>("QScreen*");
27
28
28 qmlRegisterType<Screens>(uri, 0, 1, "Screens");
29 qmlRegisterType<Screens>(uri, 0, 1, "Screens");
30+ qmlRegisterType<ScreenWindow>(uri, 0, 1, "ScreenWindow");
31+ qmlRegisterRevision<QWindow,1>(uri, 0, 1);
29}
32}
tests/mocks/Unity/Screens/screens.cpp+6−2
@@ -26,8 +26,12 @@ Q_DECLARE_METATYPE(QScreen*)
26Screens::Screens(QObject *parent) :
26Screens::Screens(QObject *parent) :
27 QAbstractListModel(parent)
27 QAbstractListModel(parent)
28{
28{
29− // start with one screen attached
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) {
30− m_screenList.append(new Screen());
33+ m_screenList.append(new Screen());
34+ }
31}
35}
32
36
33Screens::~Screens()
37Screens::~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