From afd525ced034b55ae1f89f6e899a79a58bc5e493 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Thu, 18 Nov 2021 17:12:37 +0100 Subject: [PATCH] Improve our reaction when primary changes Ensure we sanitise the input so a client can't randomly crash KWin that way. --- src/platform.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/platform.cpp b/src/platform.cpp index 6d9494517a..0bc8c87d88 100644 --- a/src/platform.cpp +++ b/src/platform.cpp @@ -158,8 +158,15 @@ void Platform::requestOutputsChange(KWaylandServer::OutputConfigurationV2Interfa } if (applyOutputChanges(cfg)) { - if (config->primaryChanged()) { - setPrimaryOutput(findOutput(config->primary()->uuid())); + if (config->primaryChanged() || !primaryOutput()->isEnabled()) { + auto requestedPrimaryOutput = findOutput(config->primary()->uuid()); + if (requestedPrimaryOutput && requestedPrimaryOutput->isEnabled()) { + setPrimaryOutput(requestedPrimaryOutput); + } else { + auto defaultPrimaryOutput = enabledOutputs().constFirst(); + qCWarning(KWIN_CORE) << "Requested invalid primary screen, using" << defaultPrimaryOutput; + setPrimaryOutput(defaultPrimaryOutput); + } } Q_EMIT screens()->changed(); config->setApplied();