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/>.
19#include "WorkspaceManager.h"
22#include <qtmir/screens.h>
23#include <QGuiApplication>
30ConcreteScreens* ConcreteScreens::m_self{nullptr};
32Screens::Screens(const QSharedPointer<qtmir::Screens>& model)
39 qDeleteAll(m_screens);
43QHash<int, QByteArray> Screens::roleNames() const
45 QHash<int, QByteArray> roles;
46 roles[ScreenRole] = "screen";
50QVariant Screens::data(const QModelIndex &index, int role) const
52 if (!index.isValid() || index.row() >= m_screens.size()) {
58 return QVariant::fromValue(m_screens.at(index.row()));
64int Screens::rowCount(const QModelIndex &) const
69int Screens::count() const
71 return m_screens.size();
74QVariant Screens::activeScreen() const
76 for (int i = 0; i < m_screens.count(); i++) {
77 if (m_screens[i]->isActive()) return i;
82void Screens::activateScreen(const QVariant& vindex)
85 int index = vindex.toInt(&ok);
86 if (!ok || index < 0 || m_screens.count() <= index) return;
88 auto screen = m_screens.at(index);
89 screen->setActive(true);
93ConcreteScreens::ConcreteScreens(const QSharedPointer<qtmir::Screens> &model)
97 connect(m_wrapped.data(), &qtmir::Screens::screenAdded, this, &ConcreteScreens::onScreenAdded);
98 connect(m_wrapped.data(), &qtmir::Screens::screenRemoved, this, &ConcreteScreens::onScreenRemoved);
99 connect(m_wrapped.data(), &qtmir::Screens::activeScreenChanged, this, &ConcreteScreens::activeScreenChanged);
101 Q_FOREACH(qtmir::Screen* screen, m_wrapped->screens()) {
102 auto screenWrapper(new ConcreteScreen(screen));
103 QQmlEngine::setObjectOwnership(screenWrapper, QQmlEngine::CppOwnership);
104 m_screens.push_back(screenWrapper);
108ConcreteScreens *ConcreteScreens::self()
110 return ConcreteScreens::m_self;
113ProxyScreens *ConcreteScreens::createProxy()
115 return new ProxyScreens(this);
118void ConcreteScreens::sync(Screens *proxy)
122 for (auto screen : m_screens) {
123 screen->setSyncing(true);
126 const auto& proxyList = proxy->list();
127 for (int i = 0; i < m_screens.count() && i < proxyList.count(); ++i) {
128 m_screens[i]->sync(proxyList[i]);
131 for (auto screen : m_screens) {
132 screen->setSyncing(false);
136void ConcreteScreens::onScreenAdded(qtmir::Screen *added)
138 Q_FOREACH(auto screenWrapper, m_screens) {
139 if (screenWrapper->wrapped() == added) return;
142 beginInsertRows(QModelIndex(), count(), count());
143 auto screenWrapper(new ConcreteScreen(added));
144 QQmlEngine::setObjectOwnership(screenWrapper, QQmlEngine::CppOwnership);
145 m_screens.push_back(screenWrapper);
147 Q_EMIT screenAdded(screenWrapper);
148 Q_EMIT countChanged();
151void ConcreteScreens::onScreenRemoved(qtmir::Screen *removed)
154 QMutableVectorIterator<Screen*> iter(m_screens);
155 while(iter.hasNext()) {
156 auto screenWrapper = iter.next();
157 if (screenWrapper->wrapped() == removed) {
159 beginRemoveRows(QModelIndex(), index, index);
163 Q_EMIT screenRemoved(screenWrapper);
164 Q_EMIT countChanged();
166 screenWrapper->deleteLater();
174ProxyScreens::ProxyScreens(Screens * const screens)
175 : Screens(screens->m_wrapped)
176 , m_original(screens)
178 connect(screens, &Screens::screenAdded, this, [this](Screen *added) {
179 Q_FOREACH(auto screen, m_screens) {
180 auto proxy = static_cast<ProxyScreen*>(screen);
181 if (proxy->proxyObject() == added) return;
184 beginInsertRows(QModelIndex(), count(), count());
185 auto screenWrapper(new ProxyScreen(added));
186 QQmlEngine::setObjectOwnership(screenWrapper, QQmlEngine::CppOwnership);
187 m_screens.push_back(screenWrapper);
189 Q_EMIT screenAdded(screenWrapper);
190 Q_EMIT countChanged();
193 connect(screens, &Screens::screenRemoved, this, [this](Screen *removed) {
195 QMutableVectorIterator<Screen*> iter(m_screens);
196 while(iter.hasNext()) {
197 auto proxy = static_cast<ProxyScreen*>(iter.next());
198 if (proxy->proxyObject() == removed) {
200 beginRemoveRows(QModelIndex(), index, index);
204 Q_EMIT screenRemoved(proxy);
205 Q_EMIT countChanged();
214 Q_FOREACH(Screen* screen, screens->list()) {
215 auto screenWrapper(new ProxyScreen(screen));
216 QQmlEngine::setObjectOwnership(screenWrapper, QQmlEngine::CppOwnership);
217 m_screens.push_back(new ProxyScreen(screen));
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