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>
29Screens::Screens(const QSharedPointer<qtmir::Screens>& model)
32 connect(m_wrapped.data(), &qtmir::Screens::screenAdded, this, &Screens::onScreenAdded);
33 connect(m_wrapped.data(), &qtmir::Screens::screenRemoved, this, &Screens::onScreenRemoved);
34 connect(m_wrapped.data(), &qtmir::Screens::activeScreenChanged, this, &Screens::activeScreenChanged);
36 Q_FOREACH(qtmir::Screen* screen, m_wrapped->screens()) {
37 m_screens.push_back(new Screen(screen));
43 qDeleteAll(m_screens);
47Screens::Screens(const Screens &other)
48 : QAbstractListModel(nullptr)
49 , m_wrapped(other.m_wrapped)
53QHash<int, QByteArray> Screens::roleNames() const
55 QHash<int, QByteArray> roles;
56 roles[ScreenRole] = "screen";
60QVariant Screens::data(const QModelIndex &index, int role) const
62 if (!index.isValid() || index.row() >= m_screens.size()) {
68 return QVariant::fromValue(m_screens.at(index.row()));
74int Screens::rowCount(const QModelIndex &) const
79int Screens::count() const
81 return m_screens.size();
84QVariant Screens::activeScreen() const
86 for (int i = 0; i < m_screens.count(); i++) {
87 if (m_screens[i]->isActive()) return i;
92ScreensProxy *Screens::createProxy()
94 return new ScreensProxy(this);
97void Screens::sync(Screens *proxy)
101 const auto& proxyList = proxy->list();
102 for (int i = 0; i < m_screens.count() && i < proxyList.count(); ++i) {
103 m_screens[i]->sync(proxyList[i]);
106 // need to clean up all the workspaces we unassigned.
107 WorkspaceManager::instance()->destroyFloatingWorkspaces();
110void Screens::activateScreen(const QVariant& vindex)
113 int index = vindex.toInt(&ok);
114 if (!ok || index < 0 || m_screens.count() <= index) return;
116 auto screen = m_screens.at(index);
117 screen->setActive(true);
120void Screens::onScreenAdded(qtmir::Screen *added)
122 Q_FOREACH(auto screenWrapper, m_screens) {
123 if (screenWrapper->wrapped() == added) return;
126 beginInsertRows(QModelIndex(), count(), count());
127 auto screenWrapper(new Screen(added));
128 m_screens.push_back(screenWrapper);
130 Q_EMIT screenAdded(screenWrapper);
131 Q_EMIT countChanged();
134void Screens::onScreenRemoved(qtmir::Screen *removed)
137 QMutableVectorIterator<Screen*> iter(m_screens);
138 while(iter.hasNext()) {
139 auto screenWrapper = iter.next();
140 if (screenWrapper->wrapped() == removed) {
142 beginRemoveRows(QModelIndex(), index, index);
146 Q_EMIT screenRemoved(screenWrapper);
147 Q_EMIT countChanged();
149 screenWrapper->deleteLater();
156ScreensProxy::ScreensProxy(Screens * const screens)
158 , m_original(screens)
160 connect(screens, &Screens::screenAdded, this, [this](Screen *added) {
161 Q_FOREACH(auto screen, m_screens) {
162 auto proxy = static_cast<ScreenProxy*>(screen);
163 if (proxy->proxyObject() == added) return;
166 beginInsertRows(QModelIndex(), count(), count());
167 auto screenWrapper(new ScreenProxy(added));
168 m_screens.push_back(screenWrapper);
170 Q_EMIT screenAdded(screenWrapper);
171 Q_EMIT countChanged();
174 connect(screens, &Screens::screenAdded, this, [this](Screen *removed) {
176 QMutableVectorIterator<Screen*> iter(m_screens);
177 while(iter.hasNext()) {
178 auto proxy = static_cast<ScreenProxy*>(iter.next());
179 if (proxy->proxyObject() == removed) {
181 beginRemoveRows(QModelIndex(), index, index);
185 Q_EMIT screenRemoved(proxy);
186 Q_EMIT countChanged();
195 Q_FOREACH(Screen* screen, screens->list()) {
196 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