From 1247a7b6984f6248f130837a211336f4f66149f0 Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Thu, 24 Feb 2022 05:36:26 +0100 Subject: [PATCH] output changes: handle to-be-enabled outputs first This prevents situations where we have no enabled outputs --- src/backends/drm/drm_backend.cpp | 21 ++++++++++++++++----- src/platform.cpp | 12 ++++++++++++ 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/backends/drm/drm_backend.cpp b/src/backends/drm/drm_backend.cpp index 73c59a81ad..2c1f3704b7 100644 --- a/src/backends/drm/drm_backend.cpp +++ b/src/backends/drm/drm_backend.cpp @@ -635,7 +635,8 @@ DrmGpu *DrmBackend::findGpuByFd(int fd) const bool DrmBackend::applyOutputChanges(const WaylandOutputConfig &config) { - QVector changed; + QVector toBeEnabled; + QVector toBeDisabled; for (const auto &gpu : qAsConst(m_gpus)) { const auto &outputs = gpu->outputs(); for (const auto &o : outputs) { @@ -645,10 +646,17 @@ bool DrmBackend::applyOutputChanges(const WaylandOutputConfig &config) continue; } output->queueChanges(config); - changed << output; + if (config.constChangeSet(output)->enabled) { + toBeEnabled << output; + } else { + toBeDisabled << output; + } } if (!gpu->testPendingConfiguration()) { - for (const auto &output : qAsConst(changed)) { + for (const auto &output : qAsConst(toBeEnabled)) { + output->revertQueuedChanges(); + } + for (const auto &output : qAsConst(toBeDisabled)) { output->revertQueuedChanges(); } return false; @@ -656,7 +664,10 @@ bool DrmBackend::applyOutputChanges(const WaylandOutputConfig &config) } // first, apply changes to drm outputs. // This may remove the placeholder output and thus change m_outputs! - for (const auto &output : qAsConst(changed)) { + for (const auto &output : qAsConst(toBeEnabled)) { + output->applyQueuedChanges(config); + } + for (const auto &output : qAsConst(toBeDisabled)) { output->applyQueuedChanges(config); } // only then apply changes to the virtual outputs @@ -664,7 +675,7 @@ bool DrmBackend::applyOutputChanges(const WaylandOutputConfig &config) if (!qobject_cast(output)) { output->applyChanges(config); } - }; + } if (Compositor::compositing()) { Compositor::self()->scene()->addRepaintFull(); } diff --git a/src/platform.cpp b/src/platform.cpp index aef6043139..7752b2e110 100644 --- a/src/platform.cpp +++ b/src/platform.cpp @@ -152,7 +152,19 @@ void Platform::requestOutputsChange(KWaylandServer::OutputConfigurationV2Interfa bool Platform::applyOutputChanges(const WaylandOutputConfig &config) { const auto availableOutputs = outputs(); + QVector toBeEnabledOutputs; + QVector toBeDisabledOutputs; for (const auto &output : availableOutputs) { + if (config.constChangeSet(qobject_cast(output))->enabled) { + toBeEnabledOutputs << output; + } else { + toBeDisabledOutputs << output; + } + } + for (const auto &output : toBeEnabledOutputs) { + static_cast(output)->applyChanges(config); + } + for (const auto &output : toBeDisabledOutputs) { static_cast(output)->applyChanges(config); } return true;