@@ -39,13 +39,30 @@ Screen::Screen(qtmir::Screen* screen)
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− if (workspace->isActive()) activate();
48+ if (workspace->isActive()) {
50+ setCurrentWorkspace(workspace);
52+ if (!m_currentWorspace) {
53+ setCurrentWorkspace(workspace);
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();
62+ connect(this, &Screen::activeChanged, this, [this](bool active) {
63+ if (active && m_currentWorspace) {
64+ m_currentWorspace->activate();
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);
91+void Screen::resetCurrentWorkspace()
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);
74qtmir::OutputId Screen::outputId() const
100qtmir::OutputId Screen::outputId() const
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();
180+Workspace *Screen::currentWorkspace() const
182+ return m_currentWorspace.data();
185+void Screen::setCurrentWorkspace(Workspace *workspace)
187+ if (m_currentWorspace != workspace) {
188+ m_currentWorspace = workspace;
189+ Q_EMIT currentWorkspaceChanged(workspace);
154void Screen::sync(Screen *proxy)
193void Screen::sync(Screen *proxy)
156 if (!proxy) return;
195 if (!proxy) return;