on xenial help sign in
Screen.currentWorkspace
commit1721c43c30908fb854aeec1e8ae4b3cf30cd0450 authorNick Dedekind <nick.dedekind@canonical.com> dateWed 8 Mar 2017, 15:29 (10 years ago) parent20b95b0
3 files changed+53−4
plugins/WindowManager/Screen.cpp+42−3 plugins/WindowManager/Screen.h+10 qml/Shell.qml+1−1
plugins/WindowManager/Screen.cpp+42−3
@@ -39,13 +39,30 @@ Screen::Screen(qtmir::Screen* screen)
3939
4040 // Connect the active workspace to activate the screen.
4141 connect(m_workspaces.data(), &WorkspaceModel::workspaceAdded, this, [this](Workspace* workspace) {
42− connect(workspace, &Workspace::activeChanged, this, [this](bool active) {
43− if (active) activate();
42+ connect(workspace, &Workspace::activeChanged, this, [this, workspace](bool active) {
43+ if (active) {
44+ setCurrentWorkspace(workspace);
45+ activate();
46+ }
4447 });
45− if (workspace->isActive()) activate();
48+ if (workspace->isActive()) {
49+ activate();
50+ setCurrentWorkspace(workspace);
51+ }
52+ if (!m_currentWorspace) {
53+ setCurrentWorkspace(workspace);
54+ }
4655 });
4756 connect(m_workspaces.data(), &WorkspaceModel::workspaceRemoved, this, [this](Workspace* workspace) {
4857 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+ }
4966 });
5067
5168 WorkspaceManager::instance()->createWorkspace()->assign(m_workspaces.data());
@@ -71,6 +88,15 @@ Screen::Screen(const Screen &other)
7188 connect(m_wrapped, &qtmir::Screen::availableModesChanged, this, &Screen::availableModesChanged);
7289}
7390
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+
74100qtmir::OutputId Screen::outputId() const
75101{
76102 return m_wrapped->outputId();
@@ -151,6 +177,19 @@ WorkspaceModel *Screen::workspaces() const
151177 return m_workspaces.data();
152178}
153179
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+
154193void Screen::sync(Screen *proxy)
155194{
156195 if (!proxy) return;
plugins/WindowManager/Screen.h+10
@@ -13,6 +13,7 @@ class Screen : public qtmir::Screen
1313{
1414 Q_OBJECT
1515 Q_PROPERTY(WorkspaceModel* workspaces READ workspaces CONSTANT)
16+ Q_PROPERTY(Workspace* currentWorkspace READ currentWorkspace WRITE setCurrentWorkspace NOTIFY currentWorkspaceChanged)
1617
1718public:
1819 explicit Screen(qtmir::Screen*const wrapped);
@@ -41,16 +42,25 @@ public:
4142
4243 WorkspaceModel* workspaces() const;
4344
45+ Workspace *currentWorkspace() const;
46+ void setCurrentWorkspace(Workspace* workspace);
47+
4448 void sync(Screen* proxy);
4549
4650public Q_SLOTS:
4751 void activate();
4852
53+Q_SIGNALS:
54+ void currentWorkspaceChanged(Workspace*);
55+
4956protected:
5057 Screen(Screen const& other);
5158
59+ void resetCurrentWorkspace();
60+
5261 qtmir::Screen*const m_wrapped;
5362 const QScopedPointer<WorkspaceModel> m_workspaces;
63+ QPointer<Workspace> m_currentWorspace;
5464};
5565
5666class ScreenProxy : public Screen
qml/Shell.qml+1−1
@@ -277,7 +277,7 @@ StyledItem {
277277 objectName: "topLevelSurfaceList"
278278 applicationManager: ApplicationManager // it's a singleton
279279 surfaceManager: SurfaceManager
280− workspace: WorkspaceManager.activeWorkspace
280+ workspace: screenWindow.screen.currentWorkspace
281281 }
282282
283283 Stage {