diff --git a/src/workspace.cpp b/src/workspace.cpp index 0d7f5f5741..a2732361e9 100644 --- a/src/workspace.cpp +++ b/src/workspace.cpp @@ -213,14 +213,12 @@ void Workspace::init() } Platform *platform = kwinApp()->platform(); - connect(platform, &Platform::outputEnabled, this, &Workspace::slotOutputEnabled); - connect(platform, &Platform::outputDisabled, this, &Workspace::slotOutputDisabled); + connect(platform, &Platform::outputAdded, this, &Workspace::slotPlatformOutputAdded); + connect(platform, &Platform::outputRemoved, this, &Workspace::slotPlatformOutputRemoved); const QVector outputs = platform->outputs(); for (Output *output : outputs) { - if (output->isEnabled()) { - slotOutputEnabled(output); - } + slotPlatformOutputAdded(output); } m_screens->init(); @@ -1380,11 +1378,34 @@ Output *Workspace::outputAt(const QPointF &pos) const return bestOutput; } -void Workspace::slotOutputEnabled(Output *output) +void Workspace::slotPlatformOutputAdded(Output *output) { if (output->isNonDesktop()) { return; } + + if (output->isEnabled()) { + addOutput(output); + } + + connect(output, &Output::enabledChanged, this, [this, output]() { + if (output->isEnabled()) { + addOutput(output); + } else { + removeOutput(output); + } + }); +} + +void Workspace::slotPlatformOutputRemoved(Output *output) +{ + if (!output->isNonDesktop()) { + removeOutput(output); + } +} + +void Workspace::addOutput(Output *output) +{ if (!m_activeOutput) { m_activeOutput = output; } @@ -1405,14 +1426,12 @@ void Workspace::slotOutputEnabled(Output *output) Q_EMIT outputAdded(output); } -void Workspace::slotOutputDisabled(Output *output) +void Workspace::removeOutput(Output *output) { - if (output->isNonDesktop()) { + if (!m_outputs.removeOne(output)) { return; } - m_outputs.removeOne(output); - if (m_activeOutput == output) { m_activeOutput = outputAt(output->geometry().center()); } diff --git a/src/workspace.h b/src/workspace.h index 389327bb00..8e641d809a 100644 --- a/src/workspace.h +++ b/src/workspace.h @@ -539,8 +539,8 @@ private Q_SLOTS: void slotCurrentDesktopChangingCancelled(); void slotDesktopAdded(VirtualDesktop *desktop); void slotDesktopRemoved(VirtualDesktop *desktop); - void slotOutputEnabled(Output *output); - void slotOutputDisabled(Output *output); + void slotPlatformOutputAdded(Output *output); + void slotPlatformOutputRemoved(Output *output); Q_SIGNALS: /** @@ -619,6 +619,9 @@ private: Unmanaged *createUnmanaged(xcb_window_t windowId); void addUnmanaged(Unmanaged *c); + void addOutput(Output *output); + void removeOutput(Output *output); + void addWaylandWindow(Window *window); void removeWaylandWindow(Window *window);