diff --git a/plugins/platforms/drm/drm_backend.h b/plugins/platforms/drm/drm_backend.h --- a/plugins/platforms/drm/drm_backend.h +++ b/plugins/platforms/drm/drm_backend.h @@ -92,6 +92,9 @@ QVector outputs() const { return m_outputs; } + QVector enabledOutputs() const { + return m_enabledOutputs; + } QVector planes() const { return m_planes; } @@ -126,7 +129,13 @@ void turnOutputsOn(); Q_SIGNALS: + /** + * Emitted whenever an output is removed/disabled + */ void outputRemoved(KWin::DrmOutput *output); + /** + * Emitted whenever an output is added/enabled + */ void outputAdded(KWin::DrmOutput *output); protected: @@ -158,8 +167,11 @@ QVector m_crtcs; // all connectors QVector m_connectors; - // currently active output pipelines (planes + crtc + encoder + connector) + // active output pipelines (planes + crtc + encoder + connector) QVector m_outputs; + // active and enabled pipelines (above + wl_output) + QVector m_enabledOutputs; + bool m_deleteBufferAfterPageFlip; bool m_atomicModeSetting = false; bool m_cursorEnabled = false; diff --git a/plugins/platforms/drm/drm_backend.cpp b/plugins/platforms/drm/drm_backend.cpp --- a/plugins/platforms/drm/drm_backend.cpp +++ b/plugins/platforms/drm/drm_backend.cpp @@ -127,7 +127,7 @@ void DrmBackend::turnOutputsOn() { m_dpmsFilter.reset(); - for (auto it = m_outputs.constBegin(), end = m_outputs.constEnd(); it != end; it++) { + for (auto it = m_enabledOutputs.constBegin(), end = m_enabledOutputs.constEnd(); it != end; it++) { (*it)->setDpms(DrmOutput::DpmsMode::On); } } @@ -138,7 +138,7 @@ // already disabled, all outputs are on return; } - for (auto it = m_outputs.constBegin(), end = m_outputs.constEnd(); it != end; it++) { + for (auto it = m_enabledOutputs.constBegin(), end = m_enabledOutputs.constEnd(); it != end; it++) { if (!(*it)->isDpmsEnabled()) { // dpms still disabled, need to keep the filter return; @@ -396,6 +396,7 @@ } DrmOutput *removed = *it; it = m_outputs.erase(it); + m_enabledOutputs.removeOne(removed); emit outputRemoved(removed); delete removed; } @@ -475,6 +476,7 @@ } std::sort(connectedOutputs.begin(), connectedOutputs.end(), [] (DrmOutput *a, DrmOutput *b) { return a->m_conn->id() < b->m_conn->id(); }); m_outputs = connectedOutputs; + m_enabledOutputs = connectedOutputs; readOutputsConfiguration(); if (!m_outputs.isEmpty()) { emit screensQueried(); @@ -518,18 +520,50 @@ void DrmBackend::configurationChangeRequested(KWayland::Server::OutputConfigurationInterface *config) { const auto changes = config->changes(); - for (auto it = changes.begin(); it != changes.end(); it++) { + bool countChanged = false; + //process all non-disabling changes + for (auto it = changes.begin(); it != changes.end(); it++) { KWayland::Server::OutputChangeSet *changeset = it.value(); auto drmoutput = findOutput(it.key()->uuid()); if (drmoutput == nullptr) { qCWarning(KWIN_DRM) << "Could NOT find DrmOutput matching " << it.key()->uuid(); - return; + continue; + } + if (changeset->enabledChanged() && changeset->enabled() == KWayland::Server::OutputDeviceInterface::Enablement::Enabled) { + drmoutput->setEnabled(true); + m_enabledOutputs << drmoutput; + emit outputAdded(drmoutput); + countChanged = true; } drmoutput->setChanges(changeset); } - emit screens()->changed(); + //process any disable requests + for (auto it = changes.begin(); it != changes.end(); it++) { + KWayland::Server::OutputChangeSet *changeset = it.value(); + if (changeset->enabledChanged() && changeset->enabled() == KWayland::Server::OutputDeviceInterface::Enablement::Disabled) { + if (m_enabledOutputs.count() == 1) { + qCWarning(KWIN_DRM) << "Not disabling final screen" << it.key()->uuid(); + continue; + } + auto drmoutput = findOutput(it.key()->uuid()); + if (drmoutput == nullptr) { + qCWarning(KWIN_DRM) << "Could NOT find DrmOutput matching " << it.key()->uuid(); + continue; + } + drmoutput->setEnabled(false); + m_enabledOutputs.removeOne(drmoutput); + emit outputRemoved(drmoutput); + countChanged = true; + } + } + + if (countChanged) { + emit screensQueried(); + } else { + emit screens()->changed(); + } // KCoreAddons needs kwayland's 2b3f9509ac1 to not crash if (KCoreAddons::version() >= QT_VERSION_CHECK(5, 39, 0)) { config->setApplied(); @@ -706,11 +740,11 @@ void DrmBackend::outputDpmsChanged() { - if (m_outputs.isEmpty()) { + if (m_enabledOutputs.isEmpty()) { return; } bool enabled = false; - for (auto it = m_outputs.constBegin(); it != m_outputs.constEnd(); ++it) { + for (auto it = m_enabledOutputs.constBegin(); it != m_enabledOutputs.constEnd(); ++it) { enabled = enabled || (*it)->isDpmsEnabled(); } setOutputsEnabled(enabled); diff --git a/plugins/platforms/drm/drm_output.h b/plugins/platforms/drm/drm_output.h --- a/plugins/platforms/drm/drm_output.h +++ b/plugins/platforms/drm/drm_output.h @@ -75,6 +75,15 @@ bool present(DrmBuffer *buffer); void pageFlipped(); + /** + * Enable or disable the output. + * This differs from setDpms as it also + * removes the wl_output + * The default is on + */ + void setEnabled(bool enabled); + bool isEnabled() const; + /** * This sets the changes and tests them against the DRM output */ diff --git a/plugins/platforms/drm/drm_output.cpp b/plugins/platforms/drm/drm_output.cpp --- a/plugins/platforms/drm/drm_output.cpp +++ b/plugins/platforms/drm/drm_output.cpp @@ -183,6 +183,26 @@ return m_scale; } +void DrmOutput::setEnabled(bool enabled) +{ + if (enabled == isEnabled()) { + return; + } + if (enabled) { + setDpms(DpmsMode::On); + initOutput(); + } else { + setDpms(DpmsMode::Off); + delete m_waylandOutput.data(); + } + m_waylandOutputDevice->setEnabled(enabled ? + KWayland::Server::OutputDeviceInterface::Enablement::Enabled : KWayland::Server::OutputDeviceInterface::Enablement::Disabled); +} + +bool DrmOutput::isEnabled() const +{ + return !m_waylandOutput.isNull(); +} static KWayland::Server::OutputInterface::DpmsMode toWaylandDpmsMode(DrmOutput::DpmsMode mode) { @@ -272,8 +292,6 @@ m_internal = connector->connector_type == DRM_MODE_CONNECTOR_LVDS || connector->connector_type == DRM_MODE_CONNECTOR_eDP; - setDpms(DpmsMode::On); - if (m_internal) { connect(kwinApp(), &Application::screensCreated, this, [this] { @@ -297,8 +315,8 @@ m_physicalSize = physicalSize; initOutputDevice(connector); - initOutput(); + setEnabled(true); return true; } @@ -784,18 +802,13 @@ bool DrmOutput::commitChanges() { Q_ASSERT(!m_waylandOutputDevice.isNull()); - Q_ASSERT(!m_waylandOutput.isNull()); if (m_changeset.isNull()) { qCDebug(KWIN_DRM) << "no changes"; // No changes to an output is an entirely valid thing return true; } - - if (m_changeset->enabledChanged()) { - qCDebug(KWIN_DRM) << "Setting enabled:"; - m_waylandOutputDevice->setEnabled(m_changeset->enabled()); - } + //enabledChanged is handled by drmbackend if (m_changeset->modeChanged()) { qCDebug(KWIN_DRM) << "Setting new mode:" << m_changeset->mode(); m_waylandOutputDevice->setCurrentMode(m_changeset->mode()); diff --git a/plugins/platforms/drm/screens_drm.cpp b/plugins/platforms/drm/screens_drm.cpp --- a/plugins/platforms/drm/screens_drm.cpp +++ b/plugins/platforms/drm/screens_drm.cpp @@ -43,41 +43,41 @@ QRect DrmScreens::geometry(int screen) const { - const auto outputs = m_backend->outputs(); + const auto outputs = m_backend->enabledOutputs(); if (screen >= outputs.size()) { return QRect(); } return outputs.at(screen)->geometry(); } qreal DrmScreens::scale(int screen) const { - const auto outputs = m_backend->outputs(); + const auto outputs = m_backend->enabledOutputs(); if (screen >= outputs.size()) { return 1; } return outputs.at(screen)->scale(); } QSize DrmScreens::size(int screen) const { - const auto outputs = m_backend->outputs(); + const auto outputs = m_backend->enabledOutputs(); if (screen >= outputs.size()) { return QSize(); } return outputs.at(screen)->geometry().size(); } void DrmScreens::updateCount() { - setCount(m_backend->outputs().size()); + setCount(m_backend->enabledOutputs().size()); } int DrmScreens::number(const QPoint &pos) const { int bestScreen = 0; int minDistance = INT_MAX; - const auto outputs = m_backend->outputs(); + const auto outputs = m_backend->enabledOutputs(); for (int i = 0; i < outputs.size(); ++i) { const QRect &geo = outputs.at(i)->geometry(); if (geo.contains(pos)) { @@ -97,43 +97,43 @@ QString DrmScreens::name(int screen) const { - const auto outputs = m_backend->outputs(); + const auto outputs = m_backend->enabledOutputs(); if (screen >= outputs.size()) { return Screens::name(screen); } return outputs.at(screen)->name(); } float DrmScreens::refreshRate(int screen) const { - const auto outputs = m_backend->outputs(); + const auto outputs = m_backend->enabledOutputs(); if (screen >= outputs.size()) { return Screens::refreshRate(screen); } return outputs.at(screen)->currentRefreshRate() / 1000.0f; } QSizeF DrmScreens::physicalSize(int screen) const { - const auto outputs = m_backend->outputs(); + const auto outputs = m_backend->enabledOutputs(); if (screen >= outputs.size()) { return Screens::physicalSize(screen); } return outputs.at(screen)->physicalSize(); } bool DrmScreens::isInternal(int screen) const { - const auto outputs = m_backend->outputs(); + const auto outputs = m_backend->enabledOutputs(); if (screen >= outputs.size()) { return false; } return outputs.at(screen)->isInternal(); } bool DrmScreens::supportsTransformations(int screen) const { - const auto outputs = m_backend->outputs(); + const auto outputs = m_backend->enabledOutputs(); if (screen >= outputs.size()) { return false; }