on 747a319 help sign in
90 lines 2.5 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 "Workspace.h"
18#include "WorkspaceModel.h"
19#include "WorkspaceManager.h"
20#include "TopLevelWindowModel.h"
22#include "windowmanagementpolicy.h"
24Workspace::Workspace(QObject *parent)
25 : QObject(parent)
26 , m_workspace(WindowManagementPolicy::instance()->createWorkspace())
27 , m_model(nullptr)
28 , m_active(false)
30 connect(WorkspaceManager::instance(), &WorkspaceManager::activeWorkspaceChanged, this, [this]() {
31 bool newActive = WorkspaceManager::instance()->activeWorkspace() == this;
32 if (newActive != m_active) {
33 m_active = newActive;
34 Q_EMIT activeChanged(m_active);
36 if (m_active) {
37 WindowManagementPolicy::instance()->setActiveWorkspace(m_workspace);
38 }
39 }
40 });
43Workspace::~Workspace()
45 WindowManagementPolicy::instance()->destroyWorkspace(m_workspace);
46 if (m_model) {
47 m_model->remove(this);
48 }
51void Workspace::assign(WorkspaceModel *model, const QVariant& vIndex)
53 if (m_model == model) return;
55 if (m_model) {
56 disconnect(model);
57 m_model->remove(this);
58 }
60 m_model = model;
62 if (model) {
63 int index = m_model->rowCount();
64 if (vIndex.isValid() && vIndex.canConvert(QVariant::Int)) {
65 index = vIndex.toInt();
66 }
67 m_model->insert(index, this);
69 connect(m_model, &QObject::destroyed, this, [this]() {
70 m_model->remove(this);
71 m_model = nullptr;
72 });
73 Q_EMIT assigned();
74 }
77void Workspace::moveWindowsTo(Workspace *workspace)
79 WindowManagementPolicy::instance()->moveWorkspaceContentToWorkspace(workspace->m_workspace, m_workspace);
82void Workspace::activate()
84 WorkspaceManager::instance()->setActiveWorkspace(this);
87void Workspace::unassign()
89 assign(WorkspaceManager::instance());