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, &QWindow::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, &QWindow::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();
75 connect(w, &QWindow::activeChanged, this, [w, this]() {
76 if (w->isActive()) setActive(true);
78 if (w->isActive()) setActive(true);
80 Q_EMIT availableModesChanged();
85 miral::DisplayId displayId() const override { return m_id; }
86 bool used() const override { return m_used; }
87 QString name() const override { return m_name; }
88 float scale() const override { return m_scale; }
89 QSizeF physicalSize() const override { return m_physicalSize; }
90 qtmir::FormFactor formFactor() const override { return m_formFactor; }
91 qtmir::OutputTypes outputType() const override { return m_outputType; }
92 QString outputTypeName() const { return QStringLiteral("Internal"); }
93 MirPowerMode powerMode() const override { return m_powerMode; }
94 Qt::ScreenOrientation orientation() const override { return m_orientation; }
95 QPoint position() const override { return m_position; }
96 uint currentModeIndex() const override { return m_currentModeIndex; }
97 bool isActive() const override { return m_active; }
99 QQmlListProperty<qtmir::ScreenMode> availableModes() override {
100 return QQmlListProperty<qtmir::ScreenMode>(this, m_sizes);
103 void setActive(bool active) override {
104 if (m_active != active) {
106 Q_EMIT activeChanged(m_active);
110 QScreen* qscreen() const override {
111 if (qGuiApp->topLevelWindows().count() > 0) {
112 return qGuiApp->topLevelWindows()[0]->screen();
114 return qGuiApp->primaryScreen();
117 qtmir::ScreenConfiguration *beginConfiguration() const override {
118 auto config = new qtmir::ScreenConfiguration;
119 config->valid = true;
120 config->id = m_id.output_id;
121 config->used = m_used;
122 config->topLeft = m_position;
123 config->currentModeIndex = m_currentModeIndex;
124 config->powerMode = m_powerMode;
125 config->scale = m_scale;
126 config->formFactor = m_formFactor;
130 bool applyConfiguration(qtmir::ScreenConfiguration *configuration) override {
131 m_used = configuration->used;
132 m_position = configuration->topLeft;
133 m_currentModeIndex = configuration->currentModeIndex;
134 m_powerMode = configuration->powerMode;
135 m_scale = configuration->scale;
136 m_formFactor = configuration->formFactor;
141 void outputTypeNameChanged();
144 miral::DisplayId m_id;
145 bool m_active{false};
148 qtmir::OutputTypes m_outputType{qtmir::Unknown};
149 MirPowerMode m_powerMode{mir_power_mode_on};
150 Qt::ScreenOrientation m_orientation{Qt::PrimaryOrientation};
152 qtmir::FormFactor m_formFactor{qtmir::FormFactorMonitor};
154 uint m_currentModeIndex{0};
155 QList<qtmir::ScreenMode*> m_sizes;
156 QSizeF m_physicalSize;
158 QPointer<QWindow> m_connectedWindow;
162MockScreens::MockScreens()
165 int screenCount = qEnvironmentVariableIntValue("UNITY_MOCK_SCREEN_COUNT", &ok);
166 if (!ok) screenCount = 1;
167 QPoint lastPoint(0,0);
168 for (int i = 0; i < screenCount; ++i) {
169 auto screen = new MockScreen();
170 screen->m_id.output_id = miral::OutputId{i};
171 screen->m_active = i == 0;
172 screen->m_name = QString("Monitor %1").arg(i);
173 screen->m_position = QPoint(lastPoint.x(), lastPoint.y());
174 screen->m_currentModeIndex = 0;
175 m_mocks.append(screen);
177 lastPoint.rx() += screen->m_sizes[screen->m_currentModeIndex]->size.width();
179 connect(screen, &qtmir::Screen::activeChanged, this, [=](bool active) {
180 Q_FOREACH(auto otherScreen, m_mocks) {
181 if (active && otherScreen != screen) {
182 otherScreen->setActive(false);
189MockScreens::~MockScreens()
195QVector<qtmir::Screen *> MockScreens::screens() const
200qtmir::Screen *MockScreens::activeScreen() const
202 Q_FOREACH(auto screen, m_mocks) {
203 if (screen->isActive()) return screen;
208QSharedPointer<MockScreens> MockScreens::instance()
211 QSharedPointer<MockScreens> screens(new MockScreens());
212 m_screens = screens.toWeakRef();
215 return m_screens.lock();
219void MockScreens::connectWindow(ScreenWindow *w)
221 ConcreteScreen* screen = w->screenWrapper();
224 auto mockScreen = qobject_cast<MockScreen*>(screen->wrapped());
226 mockScreen->connectToWindow(w);
230#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