on 53904db help sign in
unity8/tests/mocks/WindowManager/MockScreens.cpp
140 lines 4.6 kB history raw
1/*
2 * Copyright (C) 2016-2017 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 */
17#include "MockScreens.h"
19// qtmirserver
20#include <qtmir/screen.h>
22namespace {
24class MockScreen : public qtmir::Screen
26 Q_OBJECT
27public:
28 MockScreen()
29 {
30 m_sizes.append(new qtmir::ScreenMode(50, QSize(640,480)));
31 m_sizes.append(new qtmir::ScreenMode(60, QSize(1280,1024)));
32 m_sizes.append(new qtmir::ScreenMode(60, QSize(1440,900)));
33 m_sizes.append(new qtmir::ScreenMode(60, QSize(1920,1080)));
34 m_physicalSize = QSize(800,568);
35 }
37 qtmir::OutputId outputId() const override { return m_id; }
38 bool used() const override { return m_used; }
39 QString name() const override { return m_name; }
40 float scale() const override { return m_scale; }
41 QSizeF physicalSize() const override { return m_physicalSize; }
42 qtmir::FormFactor formFactor() const override { return m_formFactor; }
43 qtmir::OutputTypes outputType() const override { return m_outputType; }
44 MirPowerMode powerMode() const override { return m_powerMode; }
45 Qt::ScreenOrientation orientation() const override { return m_orientation; }
46 QPoint position() const override { return m_position; }
47 uint currentModeIndex() const override { return m_currentModeIndex; }
48 bool isActive() const override { return m_active; }
50 QQmlListProperty<qtmir::ScreenMode> availableModes() override {
51 return QQmlListProperty<qtmir::ScreenMode>(this, m_sizes);
52 }
54 void setActive(bool active) override {
55 if (m_active != active) {
56 m_active = active;
57 Q_EMIT activeChanged(m_active);
58 }
59 }
61 QScreen* qscreen() const override { return nullptr; }
63 qtmir::ScreenConfiguration *beginConfiguration() const override {
64 auto config = new qtmir::ScreenConfiguration;
65 config->valid = true;
66 config->id = m_id;
67 config->used = m_used;
68 config->topLeft = m_position;
69 config->currentModeIndex = m_currentModeIndex;
70 config->powerMode = m_powerMode;
71 config->scale = m_scale;
72 config->formFactor = m_formFactor;
73 return config;
74 }
76 bool applyConfiguration(qtmir::ScreenConfiguration *configuration) override {
77 m_used = configuration->used;
78 m_position = configuration->topLeft;
79 m_currentModeIndex = configuration->currentModeIndex;
80 m_powerMode = configuration->powerMode;
81 m_scale = configuration->scale;
82 m_formFactor = configuration->formFactor;
83 return true;
84 }
86public:
87 qtmir::OutputId m_id{0};
88 bool m_active{false};
89 bool m_used{true};
90 QString m_name;
91 qtmir::OutputTypes m_outputType{qtmir::Unknown};
92 MirPowerMode m_powerMode{mir_power_mode_on};
93 Qt::ScreenOrientation m_orientation{Qt::PrimaryOrientation};
94 float m_scale{1.0};
95 qtmir::FormFactor m_formFactor{qtmir::FormFactorMonitor};
96 QPoint m_position;
97 uint m_currentModeIndex{0};
98 QList<qtmir::ScreenMode*> m_sizes;
99 QSizeF m_physicalSize;
100};
103MockScreens::MockScreens()
105 bool ok = false;
106 int screenCount = qEnvironmentVariableIntValue("UNITY_MOCK_SCREEN_COUNT", &ok);
107 if (!ok) screenCount = 1;
108 QPoint lastPoint(0,0);
109 for (int i = 0; i < screenCount; ++i) {
110 auto screen = new MockScreen();
111 screen->m_id = qtmir::OutputId{i};
112 screen->m_active = i == 0;
113 screen->m_name = QString("Monitor %1").arg(i);
114 screen->m_position = QPoint(lastPoint.x(), lastPoint.y());
115 screen->m_currentModeIndex = 3;
116 m_mocks.append(screen);
118 lastPoint.rx() += screen->m_sizes[screen->m_currentModeIndex]->size.width();
119 }
122MockScreens::~MockScreens()
124 qDeleteAll(m_mocks);
127QVector<qtmir::Screen *> MockScreens::screens() const
129 return m_mocks;
132qtmir::Screen *MockScreens::activeScreen() const
134 Q_FOREACH(auto screen, m_mocks) {
135 if (screen->isActive()) return screen;
136 }
137 return nullptr;
140#include "MockScreens.moc"