2 * Copyright (C) 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/>.
19#include "WorkspaceManager.h"
22ScreenInterface::ScreenInterface(QObject *parent)
27void ScreenInterface::connectToScreen(qtmir::Screen *screen)
30 connect(screen, &qtmir::Screen::usedChanged, this, &ScreenInterface::usedChanged);
31 connect(screen, &qtmir::Screen::nameChanged, this, &ScreenInterface::nameChanged);
32 connect(screen, &qtmir::Screen::outputTypeChanged, this, &ScreenInterface::outputTypeChanged);
33 connect(screen, &qtmir::Screen::scaleChanged, this, &ScreenInterface::scaleChanged);
34 connect(screen, &qtmir::Screen::formFactorChanged, this, &ScreenInterface::formFactorChanged);
35 connect(screen, &qtmir::Screen::physicalSizeChanged, this, &ScreenInterface::physicalSizeChanged);
36 connect(screen, &qtmir::Screen::positionChanged, this, &ScreenInterface::positionChanged);
37 connect(screen, &qtmir::Screen::activeChanged, this, &ScreenInterface::activeChanged);
38 connect(screen, &qtmir::Screen::currentModeIndexChanged, this, &ScreenInterface::currentModeIndexChanged);
39 connect(screen, &qtmir::Screen::availableModesChanged, this, &ScreenInterface::availableModesChanged);
42qtmir::OutputId ScreenInterface::outputId() const
44 if (!m_wrapped) return qtmir::OutputId(-1);
45 return m_wrapped->outputId();
48bool ScreenInterface::used() const
50 if (!m_wrapped) return false;
51 return m_wrapped->used();
54QString ScreenInterface::name() const
56 if (!m_wrapped) return QString();
57 return m_wrapped->name();
60float ScreenInterface::scale() const
62 if (!m_wrapped) return 1.0;
63 return m_wrapped->scale();
66QSizeF ScreenInterface::physicalSize() const
68 if (!m_wrapped) return QSizeF();
69 return m_wrapped->physicalSize();
72qtmir::FormFactor ScreenInterface::formFactor() const
74 if (!m_wrapped) return qtmir::FormFactorUnknown;
75 return m_wrapped->formFactor();
78qtmir::OutputTypes ScreenInterface::outputType() const
80 if (!m_wrapped) return qtmir::Unknown;
81 return m_wrapped->outputType();
84MirPowerMode ScreenInterface::powerMode() const
86 if (!m_wrapped) return mir_power_mode_on;
87 return m_wrapped->powerMode();
90Qt::ScreenOrientation ScreenInterface::orientation() const
92 if (!m_wrapped) return Qt::PrimaryOrientation;
93 return m_wrapped->orientation();
96QPoint ScreenInterface::position() const
98 if (!m_wrapped) return QPoint();
99 return m_wrapped->position();
102QQmlListProperty<qtmir::ScreenMode> ScreenInterface::availableModes()
104 if (!m_wrapped) return QQmlListProperty<qtmir::ScreenMode>();
105 return m_wrapped->availableModes();
108uint ScreenInterface::currentModeIndex() const
110 if (!m_wrapped) return -1;
111 return m_wrapped->currentModeIndex();
114bool ScreenInterface::isActive() const
116 if (!m_wrapped) return false;
117 return m_wrapped->isActive();
120void ScreenInterface::activate()
125void ScreenInterface::setActive(bool active)
127 if (!m_wrapped) return;
128 m_wrapped->setActive(active);
131QScreen *ScreenInterface::qscreen() const
133 if (!m_wrapped) return nullptr;
134 return m_wrapped->qscreen();
137qtmir::ScreenConfiguration *ScreenInterface::beginConfiguration() const
139 if (!m_wrapped) return nullptr;
140 return m_wrapped->beginConfiguration();
143bool ScreenInterface::applyConfiguration(qtmir::ScreenConfiguration *configuration)
145 if (!m_wrapped) return false;
146 return m_wrapped->applyConfiguration(configuration);
149void ScreenInterface::sync(ScreenInterface *proxy)
152 workspaces()->sync(proxy->workspaces());
155Screen::Screen(qtmir::Screen* wrapped)
156 : m_workspaces(new WorkspaceModel)
158 connectToScreen(wrapped);
160 // Connect the active workspace to activate the screen.
161 connect(m_workspaces.data(), &WorkspaceModel::workspaceInserted, this, [this](int, Workspace* workspace) {
162 connect(workspace, &Workspace::activeChanged, this, [this, workspace](bool active) {
164 setCurrentWorkspace(workspace);
168 if (workspace->isActive()) {
170 setCurrentWorkspace(workspace);
172 if (!m_currentWorspace) {
173 setCurrentWorkspace(workspace);
176 connect(m_workspaces.data(), &WorkspaceModel::workspaceRemoved, this, [this](Workspace* workspace) {
177 disconnect(workspace, &Workspace::activeChanged, this, 0);
178 if (workspace == m_currentWorspace) {
179 resetCurrentWorkspace();
182 connect(this, &Screen::activeChanged, this, [this](bool active) {
183 if (active && m_currentWorspace) {
184 m_currentWorspace->activate();
188 WorkspaceManager::instance()->createWorkspace()->assign(m_workspaces.data());
189 WorkspaceManager::instance()->createWorkspace()->assign(m_workspaces.data());
192void Screen::resetCurrentWorkspace()
194 auto newCurrent = m_workspaces->rowCount() > 0 ? m_workspaces->get(0) : nullptr;
195 if (m_currentWorspace != newCurrent) {
196 m_currentWorspace = newCurrent;
197 Q_EMIT currentWorkspaceChanged(newCurrent);
202WorkspaceModel *Screen::workspaces() const
204 return m_workspaces.data();
207Workspace *Screen::currentWorkspace() const
209 return m_currentWorspace.data();
212void Screen::setCurrentWorkspace(Workspace *workspace)
214 if (m_currentWorspace != workspace) {
215 m_currentWorspace = workspace;
216 Q_EMIT currentWorkspaceChanged(workspace);
220ScreenProxy::ScreenProxy(ScreenInterface *const screen)
221 : m_workspaces(new WorkspaceModelProxy(screen->workspaces()))
224 connectToScreen(screen->wrapped());
226 auto updateCurrentWorkspaceFn = [this](Workspace* realWorkspace) {
227 Q_FOREACH(Workspace* workspace, m_workspaces->list()) {
228 auto p = qobject_cast<WorkspaceProxy*>(workspace);
229 if (p && p->proxyObject() == realWorkspace) {
230 if (m_currentWorspace != p) {
231 m_currentWorspace = p;
232 Q_EMIT currentWorkspaceChanged(p);
237 connect(screen, &ScreenInterface::currentWorkspaceChanged, this, updateCurrentWorkspaceFn);
238 updateCurrentWorkspaceFn(screen->currentWorkspace());
241WorkspaceModel *ScreenProxy::workspaces() const
243 return m_workspaces.data();
246Workspace *ScreenProxy::currentWorkspace() const
248 return m_currentWorspace.data();
251void ScreenProxy::setCurrentWorkspace(Workspace *workspace)
253 auto p = qobject_cast<WorkspaceProxy*>(workspace);
255 m_original->setCurrentWorkspace(p->proxyObject());
259void ScreenProxy::addWorkspace()
261 (new WorkspaceProxy(WorkspaceManager::instance()->createWorkspace()))->assign(workspaces());
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