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>
30Screens* Screens::m_self{nullptr};
32Screens::Screens(const QSharedPointer<qtmir::Screens>& model)
36 connect(m_wrapped.data(), &qtmir::Screens::screenAdded, this, &Screens::onScreenAdded);
37 connect(m_wrapped.data(), &qtmir::Screens::screenRemoved, this, &Screens::onScreenRemoved);
38 connect(m_wrapped.data(), &qtmir::Screens::activeScreenChanged, this, &Screens::activeScreenChanged);
40 Q_FOREACH(qtmir::Screen* screen, m_wrapped->screens()) {
41 auto screenWrapper(new Screen(screen));
42 QQmlEngine::setObjectOwnership(screenWrapper, QQmlEngine::CppOwnership);
43 m_screens.push_back(screenWrapper);
49 qDeleteAll(m_screens);
53Screens::Screens(const Screens &other)
54 : QAbstractListModel(nullptr)
55 , m_wrapped(other.m_wrapped)
59QHash<int, QByteArray> Screens::roleNames() const
61 QHash<int, QByteArray> roles;
62 roles[ScreenRole] = "screen";
66QVariant Screens::data(const QModelIndex &index, int role) const
68 if (!index.isValid() || index.row() >= m_screens.size()) {
74 return QVariant::fromValue(m_screens.at(index.row()));
80int Screens::rowCount(const QModelIndex &) const
85int Screens::count() const
87 return m_screens.size();
90QVariant Screens::activeScreen() const
92 for (int i = 0; i < m_screens.count(); i++) {
93 if (m_screens[i]->isActive()) return i;
98Screens *Screens::self()
100 return Screens::m_self;
103ScreensProxy *Screens::createProxy()
105 return new ScreensProxy(this);
108void Screens::sync(Screens *proxy)
112 const auto& proxyList = proxy->list();
113 for (int i = 0; i < m_screens.count() && i < proxyList.count(); ++i) {
114 m_screens[i]->sync(proxyList[i]);
117 // need to clean up all the workspaces we unassigned.
118 WorkspaceManager::instance()->destroyFloatingWorkspaces();
121void Screens::activateScreen(const QVariant& vindex)
124 int index = vindex.toInt(&ok);
125 if (!ok || index < 0 || m_screens.count() <= index) return;
127 auto screen = m_screens.at(index);
128 screen->setActive(true);
131void Screens::onScreenAdded(qtmir::Screen *added)
133 Q_FOREACH(auto screenWrapper, m_screens) {
134 if (screenWrapper->wrapped() == added) return;
137 beginInsertRows(QModelIndex(), count(), count());
138 auto screenWrapper(new Screen(added));
139 QQmlEngine::setObjectOwnership(screenWrapper, QQmlEngine::CppOwnership);
140 m_screens.push_back(screenWrapper);
142 Q_EMIT screenAdded(screenWrapper);
143 Q_EMIT countChanged();
146void Screens::onScreenRemoved(qtmir::Screen *removed)
149 QMutableVectorIterator<ScreenInterface*> iter(m_screens);
150 while(iter.hasNext()) {
151 auto screenWrapper = iter.next();
152 if (screenWrapper->wrapped() == removed) {
154 beginRemoveRows(QModelIndex(), index, index);
158 Q_EMIT screenRemoved(screenWrapper);
159 Q_EMIT countChanged();
161 screenWrapper->deleteLater();
168ScreensProxy::ScreensProxy(Screens * const screens)
170 , m_original(screens)
172 connect(screens, &Screens::screenAdded, this, [this](ScreenInterface *added) {
173 Q_FOREACH(auto screen, m_screens) {
174 auto proxy = static_cast<ScreenProxy*>(screen);
175 if (proxy->proxyObject() == added) return;
178 beginInsertRows(QModelIndex(), count(), count());
179 auto screenWrapper(new ScreenProxy(added));
180 QQmlEngine::setObjectOwnership(screenWrapper, QQmlEngine::CppOwnership);
181 m_screens.push_back(screenWrapper);
183 Q_EMIT screenAdded(screenWrapper);
184 Q_EMIT countChanged();
187 connect(screens, &Screens::screenRemoved, this, [this](ScreenInterface *removed) {
189 QMutableVectorIterator<ScreenInterface*> iter(m_screens);
190 while(iter.hasNext()) {
191 auto proxy = static_cast<ScreenProxy*>(iter.next());
192 if (proxy->proxyObject() == removed) {
194 beginRemoveRows(QModelIndex(), index, index);
198 Q_EMIT screenRemoved(proxy);
199 Q_EMIT countChanged();
208 Q_FOREACH(ScreenInterface* screen, screens->list()) {
209 auto screenWrapper(new ScreenProxy(screen));
210 QQmlEngine::setObjectOwnership(screenWrapper, QQmlEngine::CppOwnership);
211 m_screens.push_back(new ScreenProxy(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