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(640,480)));
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());
55 m_sizes.takeFirst()->deleteLater();
58 m_connectedWindow = w;
61 connect(w, &ScreenWindow::heightChanged, this, [this](int height) {
62 m_sizes.first()->size.rheight() = height;
63 Q_EMIT availableModesChanged();
66 connect(w, &ScreenWindow::widthChanged, this, [this](int width) {
67 m_sizes.first()->size.rwidth() = width;
68 Q_EMIT availableModesChanged();
71 m_sizes.push_front(new qtmir::ScreenMode(50, w->size()));
72 Q_EMIT availableModesChanged();
76 qtmir::OutputId outputId() const override { return m_id; }
77 bool used() const override { return m_used; }
78 QString name() const override { return m_name; }
79 float scale() const override { return m_scale; }
80 QSizeF physicalSize() const override { return m_physicalSize; }
81 qtmir::FormFactor formFactor() const override { return m_formFactor; }
82 qtmir::OutputTypes outputType() const override { return m_outputType; }
83 QString outputTypeName() const { return QStringLiteral("Internal"); }
84 MirPowerMode powerMode() const override { return m_powerMode; }
85 Qt::ScreenOrientation orientation() const override { return m_orientation; }
86 QPoint position() const override { return m_position; }
87 uint currentModeIndex() const override { return m_currentModeIndex; }
88 bool isActive() const override { return m_active; }
90 QQmlListProperty<qtmir::ScreenMode> availableModes() override {
91 return QQmlListProperty<qtmir::ScreenMode>(this, m_sizes);
94 void setActive(bool active) override {
95 if (m_active != active) {
97 Q_EMIT activeChanged(m_active);
101 QScreen* qscreen() const override {
102 if (qGuiApp->topLevelWindows().count() > 0) {
103 return qGuiApp->topLevelWindows()[0]->screen();
105 return qGuiApp->primaryScreen();
108 qtmir::ScreenConfiguration *beginConfiguration() const override {
109 auto config = new qtmir::ScreenConfiguration;
110 config->valid = true;
112 config->used = m_used;
113 config->topLeft = m_position;
114 config->currentModeIndex = m_currentModeIndex;
115 config->powerMode = m_powerMode;
116 config->scale = m_scale;
117 config->formFactor = m_formFactor;
121 bool applyConfiguration(qtmir::ScreenConfiguration *configuration) override {
122 m_used = configuration->used;
123 m_position = configuration->topLeft;
124 m_currentModeIndex = configuration->currentModeIndex;
125 m_powerMode = configuration->powerMode;
126 m_scale = configuration->scale;
127 m_formFactor = configuration->formFactor;
132 void outputTypeNameChanged();
135 qtmir::OutputId m_id{0};
136 bool m_active{false};
139 qtmir::OutputTypes m_outputType{qtmir::Unknown};
140 MirPowerMode m_powerMode{mir_power_mode_on};
141 Qt::ScreenOrientation m_orientation{Qt::PrimaryOrientation};
143 qtmir::FormFactor m_formFactor{qtmir::FormFactorMonitor};
145 uint m_currentModeIndex{0};
146 QList<qtmir::ScreenMode*> m_sizes;
147 QSizeF m_physicalSize;
149 QPointer<QWindow> m_connectedWindow;
153MockScreens::MockScreens()
156 int screenCount = qEnvironmentVariableIntValue("UNITY_MOCK_SCREEN_COUNT", &ok);
157 if (!ok) screenCount = 1;
158 QPoint lastPoint(0,0);
159 for (int i = 0; i < screenCount; ++i) {
160 auto screen = new MockScreen();
161 screen->m_id = qtmir::OutputId{i};
162 screen->m_active = i == 0;
163 screen->m_name = QString("Monitor %1").arg(i);
164 screen->m_position = QPoint(lastPoint.x(), lastPoint.y());
165 screen->m_currentModeIndex = 3;
166 m_mocks.append(screen);
168 lastPoint.rx() += screen->m_sizes[screen->m_currentModeIndex]->size.width();
172MockScreens::~MockScreens()
178QVector<qtmir::Screen *> MockScreens::screens() const
183qtmir::Screen *MockScreens::activeScreen() const
185 Q_FOREACH(auto screen, m_mocks) {
186 if (screen->isActive()) return screen;
191QSharedPointer<MockScreens> MockScreens::instance()
194 QSharedPointer<MockScreens> screens(new MockScreens());
195 m_screens = screens.toWeakRef();
198 return m_screens.lock();
202void MockScreens::connectWindow(ScreenWindow *w)
204 Screen* screen = w->screenWrapper();
207 auto mockScreen = qobject_cast<MockScreen*>(screen->wrapped());
209 mockScreen->connectToWindow(w);
213#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