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
37 m_sizes.append(new qtmir::ScreenMode(50, QSize(640,480)));
38 m_sizes.append(new qtmir::ScreenMode(60, QSize(1280,1024)));
39 m_sizes.append(new qtmir::ScreenMode(60, QSize(1440,900)));
40 m_sizes.append(new qtmir::ScreenMode(60, QSize(1920,1080)));
41 m_physicalSize = QSize(800,568);
48 void connectToWindow(QWindow* w)
50 if (m_connectedWindow == w) return;
52 if (m_connectedWindow) {
53 disconnect(m_connectedWindow.data());
54 m_sizes.takeFirst()->deleteLater();
57 m_connectedWindow = w;
60 connect(w, &ScreenWindow::heightChanged, this, [this](int height) {
61 m_sizes.first()->size.rheight() = height;
62 Q_EMIT availableModesChanged();
65 connect(w, &ScreenWindow::widthChanged, this, [this](int width) {
66 m_sizes.first()->size.rwidth() = width;
67 Q_EMIT availableModesChanged();
70 m_sizes.push_front(new qtmir::ScreenMode(50, w->size()));
71 Q_EMIT availableModesChanged();
75 qtmir::OutputId outputId() const override { return m_id; }
76 bool used() const override { return m_used; }
77 QString name() const override { return m_name; }
78 float scale() const override { return m_scale; }
79 QSizeF physicalSize() const override { return m_physicalSize; }
80 qtmir::FormFactor formFactor() const override { return m_formFactor; }
81 qtmir::OutputTypes outputType() const override { return m_outputType; }
82 MirPowerMode powerMode() const override { return m_powerMode; }
83 Qt::ScreenOrientation orientation() const override { return m_orientation; }
84 QPoint position() const override { return m_position; }
85 uint currentModeIndex() const override { return m_currentModeIndex; }
86 bool isActive() const override { return m_active; }
88 QQmlListProperty<qtmir::ScreenMode> availableModes() override {
89 return QQmlListProperty<qtmir::ScreenMode>(this, m_sizes);
92 void setActive(bool active) override {
93 if (m_active != active) {
95 Q_EMIT activeChanged(m_active);
99 QScreen* qscreen() const override {
100 qDebug() << "GET SCREEN" << qGuiApp->topLevelWindows();
101 if (qGuiApp->topLevelWindows().count() > 0) {
102 return qGuiApp->topLevelWindows()[0]->screen();
104 return qGuiApp->primaryScreen();
107 qtmir::ScreenConfiguration *beginConfiguration() const override {
108 auto config = new qtmir::ScreenConfiguration;
109 config->valid = true;
111 config->used = m_used;
112 config->topLeft = m_position;
113 config->currentModeIndex = m_currentModeIndex;
114 config->powerMode = m_powerMode;
115 config->scale = m_scale;
116 config->formFactor = m_formFactor;
120 bool applyConfiguration(qtmir::ScreenConfiguration *configuration) override {
121 m_used = configuration->used;
122 m_position = configuration->topLeft;
123 m_currentModeIndex = configuration->currentModeIndex;
124 m_powerMode = configuration->powerMode;
125 m_scale = configuration->scale;
126 m_formFactor = configuration->formFactor;
131 qtmir::OutputId m_id{0};
132 bool m_active{false};
135 qtmir::OutputTypes m_outputType{qtmir::Unknown};
136 MirPowerMode m_powerMode{mir_power_mode_on};
137 Qt::ScreenOrientation m_orientation{Qt::PrimaryOrientation};
139 qtmir::FormFactor m_formFactor{qtmir::FormFactorMonitor};
141 uint m_currentModeIndex{0};
142 QList<qtmir::ScreenMode*> m_sizes;
143 QSizeF m_physicalSize;
145 QPointer<QWindow> m_connectedWindow;
149MockScreens::MockScreens()
152 int screenCount = qEnvironmentVariableIntValue("UNITY_MOCK_SCREEN_COUNT", &ok);
153 if (!ok) screenCount = 1;
154 QPoint lastPoint(0,0);
155 for (int i = 0; i < screenCount; ++i) {
156 auto screen = new MockScreen();
157 screen->m_id = qtmir::OutputId{i};
158 screen->m_active = i == 0;
159 screen->m_name = QString("Monitor %1").arg(i);
160 screen->m_position = QPoint(lastPoint.x(), lastPoint.y());
161 screen->m_currentModeIndex = 3;
162 m_mocks.append(screen);
164 lastPoint.rx() += screen->m_sizes[screen->m_currentModeIndex]->size.width();
168MockScreens::~MockScreens()
174QVector<qtmir::Screen *> MockScreens::screens() const
179qtmir::Screen *MockScreens::activeScreen() const
181 Q_FOREACH(auto screen, m_mocks) {
182 if (screen->isActive()) return screen;
187QSharedPointer<MockScreens> MockScreens::instance()
190 QSharedPointer<MockScreens> screens(new MockScreens());
191 m_screens = screens.toWeakRef();
194 return m_screens.lock();
198void MockScreens::connectWindow(ScreenWindow *w)
200 ConcreteScreen* screen = w->screenWrapper();
203 auto mockScreen = qobject_cast<MockScreen*>(screen->wrapped());
205 mockScreen->connectToWindow(w);
209#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