17 #include "Workspace.h"
18 #include "WorkspaceModel.h"
19 #include "WorkspaceManager.h"
20 #include "TopLevelWindowModel.h"
23 #include "wmpolicyinterface.h"
25 int nextWorkspace = 0;
27 Workspace::Workspace(QObject *parent)
29 , m_workspace(WMPolicyInterface::instance()->createWorkspace())
32 setObjectName((QString(
"Wks%1").arg(nextWorkspace++)));
35 Workspace::Workspace(
const Workspace &other)
37 , m_workspace(other.m_workspace)
40 setObjectName(other.objectName());
42 connect(&other, &Workspace::activeChanged,
this, &Workspace::activeChanged);
45 Workspace::~Workspace()
48 m_model->remove(
this);
52 void 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]() {
80 void Workspace::unassign()
85 bool Workspace::isAssigned()
const
87 return m_model !=
nullptr;
90 bool Workspace::isSameAs(Workspace *wks)
const
92 if (!wks)
return false;
93 if (wks ==
this)
return true;
94 return wks->workspace() == workspace();
98 ConcreteWorkspace::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);
116 ConcreteWorkspace::~ConcreteWorkspace()
118 WorkspaceManager::instance()->destroyWorkspace(
this);
119 WMPolicyInterface::instance()->releaseWorkspace(m_workspace);
124 return m_windowModel.data();
127 void ConcreteWorkspace::activate()
129 WorkspaceManager::instance()->setActiveWorkspace(
this);
132 void ConcreteWorkspace::setCurrentOn(Screen *screen)
135 screen->setCurrentWorkspace(
this);
140 ProxyWorkspace::ProxyWorkspace(Workspace *
const workspace)
141 : Workspace(*workspace)
142 , m_original(workspace)
146 void ProxyWorkspace::assign(WorkspaceModel *model,
const QVariant &index)
148 Workspace::assign(model, index);
151 void ProxyWorkspace::unassign()
153 Workspace::unassign();
156 bool ProxyWorkspace::isActive()
const
158 return m_original ? m_original->isActive() :
false;
163 return m_original ? m_original->windowModel() :
nullptr;
166 void ProxyWorkspace::activate()
169 m_original->activate();
173 void ProxyWorkspace::setCurrentOn(Screen *screen)
175 if (screen && m_original) {
176 screen->setCurrentWorkspace(m_original);
A model of top-level surfaces.