18#include "WorkspaceModel.h"
19#include "WorkspaceManager.h"
20#include "TopLevelWindowModel.h"
23#include "wmpolicyinterface.h"
27Workspace::Workspace(QObject *parent)
29 , m_workspace(WMPolicyInterface::instance()->createWorkspace())
32 setObjectName((QString(
"Wks%1").arg(nextWorkspace++)));
35Workspace::Workspace(
const Workspace &other)
37 , m_workspace(other.m_workspace)
40 setObjectName(other.objectName());
42 connect(&other, &Workspace::activeChanged,
this, &Workspace::activeChanged);
45Workspace::~Workspace()
48 m_model->remove(
this);
52void Workspace::assign(WorkspaceModel *model,
const QVariant& vIndex)
54 if (m_model == model)
return;
57 disconnect(m_model, 0,
this, 0);
58 m_model->remove(
this);
64 int index = m_model->rowCount();
65 if (vIndex.isValid() && vIndex.canConvert(QVariant::Int)) {
66 index = vIndex.toInt();
68 m_model->insert(index,
this);
70 connect(m_model, &QObject::destroyed,
this, [
this]() {
80void Workspace::unassign()
85bool Workspace::isAssigned()
const
87 return m_model !=
nullptr;
90bool Workspace::isSameAs(Workspace *wks)
const
92 if (!wks)
return false;
93 if (wks ==
this)
return true;
94 return wks->workspace() == workspace();
98ConcreteWorkspace::ConcreteWorkspace(QObject *parent)
103 connect(WorkspaceManager::instance(), &WorkspaceManager::activeWorkspaceChanged,
this, [
this](Workspace* activeWorkspace) {
104 bool newActive = activeWorkspace ==
this;
105 if (newActive != m_active) {
106 m_active = newActive;
107 Q_EMIT activeChanged(m_active);
110 WMPolicyInterface::instance()->setActiveWorkspace(m_workspace);
116ConcreteWorkspace::~ConcreteWorkspace()
118 WorkspaceManager::instance()->destroyWorkspace(
this);
119 WMPolicyInterface::instance()->releaseWorkspace(m_workspace);
124 return m_windowModel.data();
127void ConcreteWorkspace::activate()
129 WorkspaceManager::instance()->setActiveWorkspace(
this);
132void ConcreteWorkspace::setCurrentOn(Screen *screen)
135 screen->setCurrentWorkspace(
this);
140ProxyWorkspace::ProxyWorkspace(Workspace *
const workspace)
141 : Workspace(*workspace)
142 , m_original(workspace)
146void ProxyWorkspace::assign(WorkspaceModel *model,
const QVariant &index)
148 Workspace::assign(model, index);
151void ProxyWorkspace::unassign()
153 Workspace::unassign();
156bool ProxyWorkspace::isActive()
const
158 return m_original ? m_original->isActive() :
false;
163 return m_original ? m_original->windowModel() :
nullptr;
166void ProxyWorkspace::activate()
169 m_original->activate();
173void ProxyWorkspace::setCurrentOn(Screen *screen)
175 if (screen && m_original) {
176 screen->setCurrentWorkspace(m_original);
A model of top-level surfaces.