on xenial help sign in
Screen.currentWorkspace
1721c43Nick Dedekind
plugins/WindowManager/Screen.cpp+42−3
@@ -39,13 +39,30 @@ Screen::Screen(qtmir::Screen* screen)
39
39
40 // Connect the active workspace to activate the screen.
40 // Connect the active workspace to activate the screen.
41 connect(m_workspaces.data(), &WorkspaceModel::workspaceAdded, this, [this](Workspace* workspace) {
41 connect(m_workspaces.data(), &WorkspaceModel::workspaceAdded, this, [this](Workspace* workspace) {
42− connect(workspace, &Workspace::activeChanged, this, [this](bool active) {
42+ connect(workspace, &Workspace::activeChanged, this, [this, workspace](bool active) {
43− if (active) activate();
43+ if (active) {
44+ setCurrentWorkspace(workspace);
45+ activate();
46+ }
44 });
47 });
45− if (workspace->isActive()) activate();
48+ if (workspace->isActive()) {
49+ activate();
50+ setCurrentWorkspace(workspace);
51+ }
52+ if (!m_currentWorspace) {
53+ setCurrentWorkspace(workspace);
54+ }
46 });
55 });
47 connect(m_workspaces.data(), &WorkspaceModel::workspaceRemoved, this, [this](Workspace* workspace) {
56 connect(m_workspaces.data(), &WorkspaceModel::workspaceRemoved, this, [this](Workspace* workspace) {
48 disconnect(workspace, &Workspace::activeChanged, this, 0);
57 disconnect(workspace, &Workspace::activeChanged, this, 0);
58+ if (workspace == m_currentWorspace) {
59+ resetCurrentWorkspace();
60+ }
61+ });
62+ connect(this, &Screen::activeChanged, this, [this](bool active) {
63+ if (active && m_currentWorspace) {
64+ m_currentWorspace->activate();
65+ }
49 });
66 });
50
67
51 WorkspaceManager::instance()->createWorkspace()->assign(m_workspaces.data());
68 WorkspaceManager::instance()->createWorkspace()->assign(m_workspaces.data());
@@ -71,6 +88,15 @@ Screen::Screen(const Screen &other)
71 connect(m_wrapped, &qtmir::Screen::availableModesChanged, this, &Screen::availableModesChanged);
88 connect(m_wrapped, &qtmir::Screen::availableModesChanged, this, &Screen::availableModesChanged);
72}
89}
73
90
91+void Screen::resetCurrentWorkspace()
92+{
93+ auto newCurrent = m_workspaces->rowCount() > 0 ? m_workspaces->get(0) : nullptr;
94+ if (m_currentWorspace != newCurrent) {
95+ m_currentWorspace = newCurrent;
96+ Q_EMIT currentWorkspaceChanged(newCurrent);
97+ }
98+}
99+
74qtmir::OutputId Screen::outputId() const
100qtmir::OutputId Screen::outputId() const
75{
101{
76 return m_wrapped->outputId();
102 return m_wrapped->outputId();
@@ -151,6 +177,19 @@ WorkspaceModel *Screen::workspaces() const
151 return m_workspaces.data();
177 return m_workspaces.data();
152}
178}
153
179
180+Workspace *Screen::currentWorkspace() const
181+{
182+ return m_currentWorspace.data();
183+}
184+
185+void Screen::setCurrentWorkspace(Workspace *workspace)
186+{
187+ if (m_currentWorspace != workspace) {
188+ m_currentWorspace = workspace;
189+ Q_EMIT currentWorkspaceChanged(workspace);
190+ }
191+}
192+
154void Screen::sync(Screen *proxy)
193void Screen::sync(Screen *proxy)
155{
194{
156 if (!proxy) return;
195 if (!proxy) return;
plugins/WindowManager/Screen.h+10
@@ -13,6 +13,7 @@ class Screen : public qtmir::Screen
13{
13{
14 Q_OBJECT
14 Q_OBJECT
15 Q_PROPERTY(WorkspaceModel* workspaces READ workspaces CONSTANT)
15 Q_PROPERTY(WorkspaceModel* workspaces READ workspaces CONSTANT)
16+ Q_PROPERTY(Workspace* currentWorkspace READ currentWorkspace WRITE setCurrentWorkspace NOTIFY currentWorkspaceChanged)
16
17
17public:
18public:
18 explicit Screen(qtmir::Screen*const wrapped);
19 explicit Screen(qtmir::Screen*const wrapped);
@@ -41,16 +42,25 @@ public:
41
42
42 WorkspaceModel* workspaces() const;
43 WorkspaceModel* workspaces() const;
43
44
45+ Workspace *currentWorkspace() const;
46+ void setCurrentWorkspace(Workspace* workspace);
47+
44 void sync(Screen* proxy);
48 void sync(Screen* proxy);
45
49
46public Q_SLOTS:
50public Q_SLOTS:
47 void activate();
51 void activate();
48
52
53+Q_SIGNALS:
54+ void currentWorkspaceChanged(Workspace*);
55+
49protected:
56protected:
50 Screen(Screen const& other);
57 Screen(Screen const& other);
51
58
59+ void resetCurrentWorkspace();
60+
52 qtmir::Screen*const m_wrapped;
61 qtmir::Screen*const m_wrapped;
53 const QScopedPointer<WorkspaceModel> m_workspaces;
62 const QScopedPointer<WorkspaceModel> m_workspaces;
63+ QPointer<Workspace> m_currentWorspace;
54};
64};
55
65
56class ScreenProxy : public Screen
66class ScreenProxy : public Screen
qml/Shell.qml+1−1
@@ -277,7 +277,7 @@ StyledItem {
277 objectName: "topLevelSurfaceList"
277 objectName: "topLevelSurfaceList"
278 applicationManager: ApplicationManager // it's a singleton
278 applicationManager: ApplicationManager // it's a singleton
279 surfaceManager: SurfaceManager
279 surfaceManager: SurfaceManager
280− workspace: WorkspaceManager.activeWorkspace
280+ workspace: screenWindow.screen.currentWorkspace
281 }
281 }
282
282
283 Stage {
283 Stage {