2 * Copyright (C) 2017 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17#include "WorkspaceManager.h"
19#include "TopLevelWindowModel.h"
20#include <unity/shell/application/SurfaceManagerInterface.h>
23#include <QGuiApplication>
27WorkspaceManager *WorkspaceManager::instance()
29 static WorkspaceManager* workspaceManager(new WorkspaceManager());
30 return workspaceManager;
33WorkspaceManager::WorkspaceManager()
34 : m_activeWorkspace(nullptr)
35 , m_surfaceManager(nullptr)
39Workspace *WorkspaceManager::createWorkspace()
41 auto workspace = new Workspace(this);
42 QQmlEngine::setObjectOwnership(workspace, QQmlEngine::CppOwnership);
43 m_allWorkspaces.insert(workspace);
44 m_floatingWorkspaces.append(workspace);
46 connect(workspace, &Workspace::assigned, this, [this, workspace]() {
47 m_floatingWorkspaces.removeOne(workspace);
48 Q_EMIT floatingWorkspacesChanged();
50 connect(workspace, &Workspace::unassigned, this, [this, workspace]() {
51 m_floatingWorkspaces.append(workspace);
52 Q_EMIT floatingWorkspacesChanged();
55 if (m_allWorkspaces.count() == 0 && m_activeWorkspace) {
56 setActiveWorkspace(nullptr);
57 Q_EMIT activeWorkspaceChanged();
58 } else if (m_allWorkspaces.count() == 1) {
59 setActiveWorkspace(workspace);
65void WorkspaceManager::destroyWorkspace(Workspace *workspace)
67 if (!workspace) return;
69 if (workspace->isAssigned()) {
70 workspace->unassign();
72 m_floatingWorkspaces.removeOne(workspace);
73 m_allWorkspaces.remove(workspace);
74 Q_EMIT floatingWorkspacesChanged();
76 if (m_activeWorkspace == workspace) {
77 Q_ASSERT(false); // Shouldn't happen, should have chosen something by now.
78 // just choose anything.
79 setActiveWorkspace(m_allWorkspaces.count() ? *m_allWorkspaces.begin() : nullptr);
81 if (m_activeWorkspace) {
82 moveWorkspaceContentToWorkspace(workspace, m_activeWorkspace);
85 disconnect(workspace, 0, this, 0);
89QQmlListProperty<Workspace> WorkspaceManager::floatingWorkspaces()
91 return QQmlListProperty<Workspace>(this, m_floatingWorkspaces);
94void WorkspaceManager::destroyFloatingWorkspaces()
96 QList<Workspace*> dpCpy(m_floatingWorkspaces);
97 Q_FOREACH(auto workspace, dpCpy) {
98 destroyWorkspace(workspace);
102void WorkspaceManager::setSurfaceManager(unity::shell::application::SurfaceManagerInterface *surfaceManager)
104 if (m_surfaceManager == surfaceManager) return;
106 m_surfaceManager = surfaceManager;
107 Q_EMIT surfaceManagerChanged();
110void WorkspaceManager::moveSurfaceToWorkspace(unity::shell::application::MirSurfaceInterface *surface, Workspace *workspace)
112 if (m_surfaceManager) {
113 m_surfaceManager->moveSurfaceToWorkspace(surface, workspace->workspace());
117void WorkspaceManager::moveWorkspaceContentToWorkspace(Workspace *from, Workspace *to)
119 if (m_surfaceManager) {
120 m_surfaceManager->moveWorkspaceContentToWorkspace(from->workspace(), to->workspace());
124Workspace *WorkspaceManager::activeWorkspace() const
126 return m_activeWorkspace;
129void WorkspaceManager::setActiveWorkspace(Workspace *workspace)
131 if (workspace != m_activeWorkspace) {
132 m_activeWorkspace = workspace;
133 Q_EMIT activeWorkspaceChanged();
137void WorkspaceManager::setActiveWorkspace2(Workspace *workspace)
139 if (!workspace) return;
140 workspace->activate();
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