2 * Copyright (C) 2016-2017 Canonical, Ltd.
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.
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.
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/>.
17#include "MockScreens.h"
18#include "ScreenWindow.h"
21#include <qtmir/screen.h>
23#include <QGuiApplication>
25#include <QWeakPointer>
29QWeakPointer<MockScreens> m_screens;
31class MockScreen : public qtmir::Screen
34 Q_PROPERTY(QString outputTypeName READ outputTypeName NOTIFY outputTypeNameChanged)
38 m_sizes.append(new qtmir::ScreenMode(50, QSize(800,568)));
39 m_sizes.append(new qtmir::ScreenMode(60, QSize(1280,1024)));
40 m_sizes.append(new qtmir::ScreenMode(60, QSize(1440,900)));
41 m_sizes.append(new qtmir::ScreenMode(60, QSize(1920,1080)));
42 m_physicalSize = QSize(800,568);
49 void connectToWindow(QWindow* w)
51 if (m_connectedWindow == w) return;
53 if (m_connectedWindow) {
54 disconnect(m_connectedWindow.data());
57 m_connectedWindow = w;
60 connect(w, &ScreenWindow::heightChanged, this, [this](int height) {
61 if (height == 0 || height == m_sizes.first()->size.rheight()) {
64 m_sizes.first()->size.rheight() = height;
65 Q_EMIT availableModesChanged();
68 connect(w, &ScreenWindow::widthChanged, this, [this](int width) {
69 if (width == 0 || width == m_sizes.first()->size.rwidth()) {
72 m_sizes.first()->size.rwidth() = width;
73 Q_EMIT availableModesChanged();
76 Q_EMIT availableModesChanged();
80 qtmir::OutputId outputId() const override { return m_id; }
81 bool used() const override { return m_used; }
82 QString name() const override { return m_name; }
83 float scale() const override { return m_scale; }
84 QSizeF physicalSize() const override { return m_physicalSize; }
85 qtmir::FormFactor formFactor() const override { return m_formFactor; }
86 qtmir::OutputTypes outputType() const override { return m_outputType; }
87 QString outputTypeName() const { return QStringLiteral("Internal"); }
88 MirPowerMode powerMode() const override { return m_powerMode; }
89 Qt::ScreenOrientation orientation() const override { return m_orientation; }
90 QPoint position() const override { return m_position; }
91 uint currentModeIndex() const override { return m_currentModeIndex; }
92 bool isActive() const override { return m_active; }
94 QQmlListProperty<qtmir::ScreenMode> availableModes() override {
95 return QQmlListProperty<qtmir::ScreenMode>(this, m_sizes);
98 void setActive(bool active) override {
99 if (m_active != active) {
101 Q_EMIT activeChanged(m_active);
105 QScreen* qscreen() const override {
106 if (qGuiApp->topLevelWindows().count() > 0) {
107 return qGuiApp->topLevelWindows()[0]->screen();
109 return qGuiApp->primaryScreen();
112 qtmir::ScreenConfiguration *beginConfiguration() const override {
113 auto config = new qtmir::ScreenConfiguration;
114 config->valid = true;
116 config->used = m_used;
117 config->topLeft = m_position;
118 config->currentModeIndex = m_currentModeIndex;
119 config->powerMode = m_powerMode;
120 config->scale = m_scale;
121 config->formFactor = m_formFactor;
125 bool applyConfiguration(qtmir::ScreenConfiguration *configuration) override {
126 m_used = configuration->used;
127 m_position = configuration->topLeft;
128 m_currentModeIndex = configuration->currentModeIndex;
129 m_powerMode = configuration->powerMode;
130 m_scale = configuration->scale;
131 m_formFactor = configuration->formFactor;
136 void outputTypeNameChanged();
139 qtmir::OutputId m_id{0};
140 bool m_active{false};
143 qtmir::OutputTypes m_outputType{qtmir::Unknown};
144 MirPowerMode m_powerMode{mir_power_mode_on};
145 Qt::ScreenOrientation m_orientation{Qt::PrimaryOrientation};
147 qtmir::FormFactor m_formFactor{qtmir::FormFactorMonitor};
149 uint m_currentModeIndex{0};
150 QList<qtmir::ScreenMode*> m_sizes;
151 QSizeF m_physicalSize;
153 QPointer<QWindow> m_connectedWindow;
157MockScreens::MockScreens()
160 int screenCount = qEnvironmentVariableIntValue("UNITY_MOCK_SCREEN_COUNT", &ok);
161 if (!ok) screenCount = 1;
162 QPoint lastPoint(0,0);
163 for (int i = 0; i < screenCount; ++i) {
164 auto screen = new MockScreen();
165 screen->m_id = qtmir::OutputId{i};
166 screen->m_active = i == 0;
167 screen->m_name = QString("Monitor %1").arg(i);
168 screen->m_position = QPoint(lastPoint.x(), lastPoint.y());
169 screen->m_currentModeIndex = 0;
170 m_mocks.append(screen);
172 lastPoint.rx() += screen->m_sizes[screen->m_currentModeIndex]->size.width();
176MockScreens::~MockScreens()
182QVector<qtmir::Screen *> MockScreens::screens() const
187qtmir::Screen *MockScreens::activeScreen() const
189 Q_FOREACH(auto screen, m_mocks) {
190 if (screen->isActive()) return screen;
195QSharedPointer<MockScreens> MockScreens::instance()
198 QSharedPointer<MockScreens> screens(new MockScreens());
199 m_screens = screens.toWeakRef();
202 return m_screens.lock();
206void MockScreens::connectWindow(ScreenWindow *w)
208 Screen* screen = w->screenWrapper();
211 auto mockScreen = qobject_cast<MockScreen*>(screen->wrapped());
213 mockScreen->connectToWindow(w);
217#include "MockScreens.moc"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list