Lomiri
Loading...
Searching...
No Matches
WindowManagementPolicy.cpp
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 */
16
17#include "WindowManagementPolicy.h"
18
19WindowManagementPolicy::WindowManagementPolicy(const miral::WindowManagerTools &tools, std::shared_ptr<qtmir::WindowManagementPolicyPrivate> dd)
20 : qtmir::WindowManagementPolicy(tools, dd)
21 , m_dummyWorkspace(this->tools.create_workspace())
22{
23 wmPolicyInterface = this;
24
25 // we must always have a active workspace.
26 m_activeWorkspace = m_dummyWorkspace;
27}
28
29void WindowManagementPolicy::advise_new_window(miral::WindowInfo const& window_info)
30{
31 qtmir::WindowManagementPolicy::advise_new_window(window_info);
32
33 auto const parent = window_info.parent();
34
35 auto activeWorkspace = m_activeWorkspace.lock();
36 if (!parent && activeWorkspace) {
37 tools.add_tree_to_workspace(window_info.window(), activeWorkspace);
38 }
39}
40
41std::shared_ptr<miral::Workspace> WindowManagementPolicy::createWorkspace()
42{
43 auto workspace = tools.create_workspace();
44 m_workspaces.insert(workspace);
45
46 if (m_activeWorkspace.lock() == m_dummyWorkspace) {
47 tools.move_workspace_content_to_workspace(workspace, m_dummyWorkspace);
48 m_activeWorkspace = workspace;
49 }
50 return workspace;
51}
52
53void WindowManagementPolicy::releaseWorkspace(const std::shared_ptr<miral::Workspace> &workspace)
54{
55 auto iter = m_workspaces.find(workspace);
56 if (iter != m_workspaces.end()) m_workspaces.erase(iter);
57
58 if (m_workspaces.size() == 0) {
59 m_activeWorkspace = m_dummyWorkspace;
60 tools.move_workspace_content_to_workspace(m_dummyWorkspace, workspace);
61 }
62}
63
64void WindowManagementPolicy::setActiveWorkspace(const std::shared_ptr<miral::Workspace> &workspace)
65{
66 if (m_activeWorkspace.lock() == workspace)
67 return;
68 m_activeWorkspace = workspace ? workspace : m_dummyWorkspace;
69}