on 80fc88d help sign in
unity8/plugins/WindowManager/WorkspaceManager.cpp
108 lines 3.2 kB history raw
1/*
2 * Copyright (C) 2017 Canonical, Ltd.
3 *
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.
7 *
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.
12 *
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/>.
15 */
17#include "WorkspaceManager.h"
18#include "Workspace.h"
19#include "TopLevelWindowModel.h"
20#include "WindowManagerObjects.h"
21#include <unity/shell/application/SurfaceManagerInterface.h>
23// Qt
24#include <QGuiApplication>
25#include <QScreen>
26#include <QQmlEngine>
28WorkspaceManager *WorkspaceManager::instance()
30 static WorkspaceManager* workspaceManager(new WorkspaceManager());
31 return workspaceManager;
34WorkspaceManager::WorkspaceManager()
35 : m_activeWorkspace(nullptr)
39Workspace *WorkspaceManager::createWorkspace()
41 auto workspace = new ConcreteWorkspace(this);
42 QQmlEngine::setObjectOwnership(workspace, QQmlEngine::CppOwnership);
43 m_allWorkspaces.insert(workspace);
45 if (m_allWorkspaces.count() == 0 && m_activeWorkspace) {
46 setActiveWorkspace(nullptr);
47 } else if (m_allWorkspaces.count() == 1) {
48 setActiveWorkspace(workspace);
49 }
51 return workspace;
54void WorkspaceManager::destroyWorkspace(Workspace *workspace)
56 if (!workspace) return;
58 if (workspace->isAssigned()) {
59 workspace->unassign();
60 }
61 m_allWorkspaces.remove(workspace);
63 if (m_activeWorkspace == workspace) {
64 Q_ASSERT(false); // Shouldn't happen, should have chosen something by now.
65 // just choose anything.
66 setActiveWorkspace(m_allWorkspaces.count() ? *m_allWorkspaces.begin() : nullptr);
67 }
68 if (m_activeWorkspace) {
69 moveWorkspaceContentToWorkspace(m_activeWorkspace, workspace);
70 }
72 disconnect(workspace, 0, this, 0);
75void WorkspaceManager::moveSurfaceToWorkspace(unity::shell::application::MirSurfaceInterface *surface, Workspace *workspace)
77 auto surfaceManager = WindowManagerObjects::instance()->surfaceManager();
78 if (surfaceManager) {
79 surfaceManager->moveSurfaceToWorkspace(surface, workspace->workspace());
80 }
83void WorkspaceManager::moveWorkspaceContentToWorkspace(Workspace *to, Workspace *from)
85 auto surfaceManager = WindowManagerObjects::instance()->surfaceManager();
86 if (surfaceManager) {
87 surfaceManager->moveWorkspaceContentToWorkspace(to->workspace(), from->workspace());
88 }
91Workspace *WorkspaceManager::activeWorkspace() const
93 return m_activeWorkspace;
96void WorkspaceManager::setActiveWorkspace(Workspace *workspace)
98 if (workspace != m_activeWorkspace) {
99 m_activeWorkspace = workspace;
100 Q_EMIT activeWorkspaceChanged(workspace);
101 }
104void WorkspaceManager::setActiveWorkspace2(Workspace *workspace)
106 if (!workspace) return;
107 workspace->activate();