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 if (qGuiApp->platformName() != QLatin1String("mirserver")) {
33 qCritical("Not using 'mirserver' QPA plugin. Using qGuiApp may produce unknown results.");
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 m_screens.push_back(new Screen(screen));
47 qDeleteAll(m_screens);
51Screens::Screens(const Screens &other)
52 : QAbstractListModel(nullptr)
53 , m_wrapped(other.m_wrapped)
57QHash<int, QByteArray> Screens::roleNames() const
59 QHash<int, QByteArray> roles;
60 roles[ScreenRole] = "screen";
64QVariant Screens::data(const QModelIndex &index, int role) const
66 if (!index.isValid() || index.row() >= m_screens.size()) {
72 return QVariant::fromValue(m_screens.at(index.row()));
78int Screens::rowCount(const QModelIndex &) const
83int Screens::count() const
85 return m_screens.size();
88QVariant Screens::activeScreen() const
90 for (int i = 0; i < m_screens.count(); i++) {
91 if (m_screens[i]->isActive()) return i;
96ScreensProxy *Screens::createProxy()
98 return new ScreensProxy(this);
101void Screens::sync(Screens *proxy)
105 const auto& proxyList = proxy->list();
106 for (int i = 0; i < m_screens.count() && i < proxyList.count(); ++i) {
107 m_screens[i]->sync(proxyList[i]);
110 // need to clean up all the workspaces we unassigned.
111 WorkspaceManager::instance()->destroyFloatingWorkspaces();
114void Screens::activateScreen(const QVariant& vindex)
117 int index = vindex.toInt(&ok);
118 if (!ok || index < 0 || m_screens.count() <= index) return;
120 auto screen = m_screens.at(index);
121 screen->setActive(true);
124void Screens::onScreenAdded(qtmir::Screen *added)
126 Q_FOREACH(auto screenWrapper, m_screens) {
127 if (screenWrapper->wrapped() == added) return;
130 beginInsertRows(QModelIndex(), count(), count());
131 auto screenWrapper(new Screen(added));
132 m_screens.push_back(screenWrapper);
134 Q_EMIT screenAdded(screenWrapper);
135 Q_EMIT countChanged();
138void Screens::onScreenRemoved(qtmir::Screen *removed)
141 QMutableVectorIterator<Screen*> iter(m_screens);
142 while(iter.hasNext()) {
143 auto screenWrapper = iter.next();
144 if (screenWrapper->wrapped() == removed) {
146 beginRemoveRows(QModelIndex(), index, index);
150 Q_EMIT screenRemoved(screenWrapper);
151 Q_EMIT countChanged();
153 screenWrapper->deleteLater();
160ScreensProxy::ScreensProxy(Screens * const screens)
162 , m_original(screens)
164 connect(screens, &Screens::screenAdded, this, [this](Screen *added) {
165 Q_FOREACH(auto screen, m_screens) {
166 auto proxy = static_cast<ScreenProxy*>(screen);
167 if (proxy->proxyObject() == added) return;
170 beginInsertRows(QModelIndex(), count(), count());
171 auto screenWrapper(new ScreenProxy(added));
172 m_screens.push_back(screenWrapper);
174 Q_EMIT screenAdded(screenWrapper);
175 Q_EMIT countChanged();
178 connect(screens, &Screens::screenAdded, this, [this](Screen *removed) {
180 QMutableVectorIterator<Screen*> iter(m_screens);
181 while(iter.hasNext()) {
182 auto proxy = static_cast<ScreenProxy*>(iter.next());
183 if (proxy->proxyObject() == removed) {
185 beginRemoveRows(QModelIndex(), index, index);
189 Q_EMIT screenRemoved(proxy);
190 Q_EMIT countChanged();
199 Q_FOREACH(Screen* screen, screens->list()) {
200 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