From 71ee728bd7320b5cda753602a2e15ed37f266b9d Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Wed, 8 Sep 2021 18:54:08 +0200 Subject: [PATCH] screens pool: On Wayland the 0 screen id is not the primary There is no primary on Wayland, we were trying to make one up and making everything worse in turn. Instead, have the screen to connector mapping be stable across executions. Each screen will look as configured, which makes it all more predictable and we do not run into cases where we swap displays configurations because the other one happened to be the primary this time around. --- shell/screenpool.cpp | 21 ++++++++++++++------- shell/screenpool.h | 1 + shell/shellcorona.cpp | 7 +++---- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/shell/screenpool.cpp b/shell/screenpool.cpp index b41a2fd7f..7ed58f550 100644 --- a/shell/screenpool.cpp +++ b/shell/screenpool.cpp @@ -38,16 +38,18 @@ ScreenPool::ScreenPool(const KSharedConfig::Ptr &config, QObject *parent) void ScreenPool::load() { - m_primaryConnector = QString(); + m_primaryConnector.clear(); m_connectorForId.clear(); m_idForConnector.clear(); - QScreen *primary = qGuiApp->primaryScreen(); - if (primary) { - m_primaryConnector = primary->name(); - if (!m_primaryConnector.isEmpty()) { - m_connectorForId[0] = m_primaryConnector; - m_idForConnector[m_primaryConnector] = 0; + if (KWindowSystem::isPlatformX11()) { + QScreen *primary = qGuiApp->primaryScreen(); + if (primary) { + m_primaryConnector = primary->name(); + if (!m_primaryConnector.isEmpty()) { + m_connectorForId[0] = m_primaryConnector; + m_idForConnector[m_primaryConnector] = 0; + } } } @@ -86,6 +88,11 @@ QString ScreenPool::primaryConnector() const return m_primaryConnector; } +int ScreenPool::primaryScreenId() const +{ + return m_idForConnector.value(m_primaryConnector); +} + void ScreenPool::setPrimaryConnector(const QString &primary) { if (m_primaryConnector == primary) { diff --git a/shell/screenpool.h b/shell/screenpool.h index 278821cc4..135135389 100644 --- a/shell/screenpool.h +++ b/shell/screenpool.h @@ -24,6 +24,7 @@ public: void load(); ~ScreenPool() override; + int primaryScreenId() const; QString primaryConnector() const; void setPrimaryConnector(const QString &primary); diff --git a/shell/shellcorona.cpp b/shell/shellcorona.cpp index 5b33883f0..80df4bd67 100644 --- a/shell/shellcorona.cpp +++ b/shell/shellcorona.cpp @@ -662,11 +662,10 @@ void ShellCorona::load() // historically CustomContainments are treated as desktops } else if (containment->containmentType() == Plasma::Types::DesktopContainment || containment->containmentType() == Plasma::Types::CustomContainment) { - // FIXME ideally fix this, or at least document the crap out of it int screen = containment->lastScreen(); if (screen < 0) { - screen = 0; - qWarning() << "last screen is < 0 so putting containment on screen " << screen; + screen = m_screenPool->primaryScreenId(); + qWarning() << "last screen is unknown so putting containment on screen " << screen; } insertContainment(containment->activity(), screen, containment); } @@ -1292,7 +1291,7 @@ void ShellCorona::createWaitingPanels() // ignore non existing (yet?) screens int requestedScreen = cont->lastScreen(); if (requestedScreen < 0) { - requestedScreen = 0; + requestedScreen = m_desktopViewforId.cbegin().key(); } DesktopView *desktopView = m_desktopViewforId.value(requestedScreen);