on b9739cb help sign in
224 lines 6.7 kB history raw
1/*
2 * Copyright (C) 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 "Screen.h"
18#include "WorkspaceManager.h"
19#include "Workspace.h"
21#include <QQmlEngine>
23Screen::Screen(qtmir::Screen* screen)
24 : m_wrapped(screen)
25 , m_workspaces(new WorkspaceModel)
27 QQmlEngine::setObjectOwnership(m_workspaces.data(), QQmlEngine::CppOwnership);
29 connect(m_wrapped, &qtmir::Screen::usedChanged, this, &Screen::usedChanged);
30 connect(m_wrapped, &qtmir::Screen::nameChanged, this, &Screen::nameChanged);
31 connect(m_wrapped, &qtmir::Screen::outputTypeChanged, this, &Screen::outputTypeChanged);
32 connect(m_wrapped, &qtmir::Screen::scaleChanged, this, &Screen::scaleChanged);
33 connect(m_wrapped, &qtmir::Screen::formFactorChanged, this, &Screen::formFactorChanged);
34 connect(m_wrapped, &qtmir::Screen::physicalSizeChanged, this, &Screen::physicalSizeChanged);
35 connect(m_wrapped, &qtmir::Screen::positionChanged, this, &Screen::positionChanged);
36 connect(m_wrapped, &qtmir::Screen::activeChanged, this, &Screen::activeChanged);
37 connect(m_wrapped, &qtmir::Screen::currentModeIndexChanged, this, &Screen::currentModeIndexChanged);
38 connect(m_wrapped, &qtmir::Screen::availableModesChanged, this, &Screen::availableModesChanged);
40 // Connect the active workspace to activate the screen.
41 connect(m_workspaces.data(), &WorkspaceModel::workspaceAdded, this, [this](Workspace* workspace) {
42 connect(workspace, &Workspace::activeChanged, this, [this, workspace](bool active) {
43 if (active) {
44 setCurrentWorkspace(workspace);
45 activate();
46 }
47 });
48 if (workspace->isActive()) {
49 activate();
50 setCurrentWorkspace(workspace);
51 }
52 if (!m_currentWorspace) {
53 setCurrentWorkspace(workspace);
54 }
55 });
56 connect(m_workspaces.data(), &WorkspaceModel::workspaceRemoved, this, [this](Workspace* workspace) {
57 disconnect(workspace, &Workspace::activeChanged, this, 0);
58 if (workspace == m_currentWorspace) {
59 resetCurrentWorkspace();
60 }
61 });
62 connect(this, &Screen::activeChanged, this, [this](bool active) {
63 if (active && m_currentWorspace) {
64 m_currentWorspace->activate();
65 }
66 });
68 WorkspaceManager::instance()->createWorkspace()->assign(m_workspaces.data());
69 WorkspaceManager::instance()->createWorkspace()->assign(m_workspaces.data());
72Screen::Screen(const Screen &other)
73 : qtmir::Screen(nullptr)
74 , m_wrapped(other.m_wrapped)
75 , m_workspaces(new WorkspaceModelProxy(other.m_workspaces.data()))
77 QQmlEngine::setObjectOwnership(m_workspaces.data(), QQmlEngine::CppOwnership);
79 connect(m_wrapped, &qtmir::Screen::usedChanged, this, &Screen::usedChanged);
80 connect(m_wrapped, &qtmir::Screen::nameChanged, this, &Screen::nameChanged);
81 connect(m_wrapped, &qtmir::Screen::outputTypeChanged, this, &Screen::outputTypeChanged);
82 connect(m_wrapped, &qtmir::Screen::scaleChanged, this, &Screen::scaleChanged);
83 connect(m_wrapped, &qtmir::Screen::formFactorChanged, this, &Screen::formFactorChanged);
84 connect(m_wrapped, &qtmir::Screen::physicalSizeChanged, this, &Screen::physicalSizeChanged);
85 connect(m_wrapped, &qtmir::Screen::positionChanged, this, &Screen::positionChanged);
86 connect(m_wrapped, &qtmir::Screen::activeChanged, this, &Screen::activeChanged);
87 connect(m_wrapped, &qtmir::Screen::currentModeIndexChanged, this, &Screen::currentModeIndexChanged);
88 connect(m_wrapped, &qtmir::Screen::availableModesChanged, this, &Screen::availableModesChanged);
91void Screen::resetCurrentWorkspace()
93 auto newCurrent = m_workspaces->rowCount() > 0 ? m_workspaces->get(0) : nullptr;
94 if (m_currentWorspace != newCurrent) {
95 m_currentWorspace = newCurrent;
96 Q_EMIT currentWorkspaceChanged(newCurrent);
97 }
100qtmir::OutputId Screen::outputId() const
102 return m_wrapped->outputId();
105bool Screen::used() const
107 return m_wrapped->used();
110QString Screen::name() const
112 return m_wrapped->name();
115float Screen::scale() const
117 return m_wrapped->scale();
120QSizeF Screen::physicalSize() const
122 return m_wrapped->physicalSize();
125qtmir::FormFactor Screen::formFactor() const
127 return m_wrapped->formFactor();
130qtmir::OutputTypes Screen::outputType() const
132 return m_wrapped->outputType();
135MirPowerMode Screen::powerMode() const
137 return m_wrapped->powerMode();
140Qt::ScreenOrientation Screen::orientation() const
142 return m_wrapped->orientation();
145QPoint Screen::position() const
147 return m_wrapped->position();
150QQmlListProperty<qtmir::ScreenMode> Screen::availableModes()
152 return m_wrapped->availableModes();
155uint Screen::currentModeIndex() const
157 return m_wrapped->currentModeIndex();
160bool Screen::isActive() const
162 return m_wrapped->isActive();
165qtmir::ScreenConfiguration *Screen::beginConfiguration() const
167 return m_wrapped->beginConfiguration();
170bool Screen::applyConfiguration(qtmir::ScreenConfiguration *configuration)
172 return m_wrapped->applyConfiguration(configuration);
175WorkspaceModel *Screen::workspaces() const
177 return m_workspaces.data();
180Workspace *Screen::currentWorkspace() const
182 return m_currentWorspace.data();
185void Screen::setCurrentWorkspace(Workspace *workspace)
187 if (m_currentWorspace != workspace) {
188 m_currentWorspace = workspace;
189 Q_EMIT currentWorkspaceChanged(workspace);
190 }
193void Screen::sync(Screen *proxy)
195 if (!proxy) return;
197 workspaces()->sync(proxy->workspaces());
200void Screen::activate()
202 setActive(true);
205void Screen::setActive(bool active)
207 m_wrapped->setActive(active);
210QScreen *Screen::qscreen() const
212 return m_wrapped->qscreen();
215ScreenProxy::ScreenProxy(ScreenProxy::Screen *const screen)
216 : Screen(*screen)
217 , m_original(screen)
221void ScreenProxy::addWorkspace()
223 (new WorkspaceProxy(WorkspaceManager::instance()->createWorkspace()))->assign(workspaces());