From 8a93a33b9667d8b4a125992fd347e58fdf1542ba Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Sun, 29 Aug 2021 16:49:03 +0300 Subject: [PATCH] x11: Make sure that outputs are stored in xinerama order With the new output query algorithm, position of an output may not align with its xinerama index. This can be problem on x11 as some protocols, e.g. startup feedback, use xinerama indices to identify outputs. Technically, the RandR specification doesn't say that CRTCs are stored in the xinerama order, it only mentions that the first CRTC corresponds to the primary output. However, such assumption was made by kwin prior to output query changes, this change merely restores that behavior. --- .../platforms/x11/standalone/x11_output.cpp | 10 ++++++++++ src/plugins/platforms/x11/standalone/x11_output.h | 4 ++++ .../platforms/x11/standalone/x11_platform.cpp | 15 +++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/src/plugins/platforms/x11/standalone/x11_output.cpp b/src/plugins/platforms/x11/standalone/x11_output.cpp index 153bd74f5e..874105d372 100644 --- a/src/plugins/platforms/x11/standalone/x11_output.cpp +++ b/src/plugins/platforms/x11/standalone/x11_output.cpp @@ -23,6 +23,16 @@ QString X11Output::name() const return m_name; } +int X11Output::xineramaNumber() const +{ + return m_xineramaNumber; +} + +void X11Output::setXineramaNumber(int number) +{ + m_xineramaNumber = number; +} + QRect X11Output::geometry() const { return m_geometry; diff --git a/src/plugins/platforms/x11/standalone/x11_output.h b/src/plugins/platforms/x11/standalone/x11_output.h index 935f341327..1f2f82b69f 100644 --- a/src/plugins/platforms/x11/standalone/x11_output.h +++ b/src/plugins/platforms/x11/standalone/x11_output.h @@ -32,6 +32,9 @@ public: QString name() const override; + int xineramaNumber() const; + void setXineramaNumber(int number); + QRect geometry() const override; void setGeometry(QRect set); @@ -56,6 +59,7 @@ private: QSize m_physicalSize; int m_gammaRampSize; int m_refreshRate; + int m_xineramaNumber = 0; friend class X11StandalonePlatform; }; diff --git a/src/plugins/platforms/x11/standalone/x11_platform.cpp b/src/plugins/platforms/x11/standalone/x11_platform.cpp index 6738bbaf32..21aad82f28 100644 --- a/src/plugins/platforms/x11/standalone/x11_platform.cpp +++ b/src/plugins/platforms/x11/standalone/x11_platform.cpp @@ -533,6 +533,7 @@ void X11StandalonePlatform::doUpdateOutputs() output->setGammaRampSize(gamma.isNull() ? 0 : gamma->size); output->setGeometry(geometry); output->setRefreshRate(refreshRate * 1000); + output->setXineramaNumber(i); QSize physicalSize(outputInfo->mm_width, outputInfo->mm_height); switch (info->rotation) { @@ -578,6 +579,20 @@ void X11StandalonePlatform::doUpdateOutputs() delete output; } + // Make sure that the position of an output in m_outputs matches its xinerama index, there + // are X11 protocols that use xinerama indices to identify outputs. + std::sort(m_outputs.begin(), m_outputs.end(), [](const AbstractOutput *a, const AbstractOutput *b) { + const auto xa = qobject_cast(a); + if (!xa) { + return false; + } + const auto xb = qobject_cast(b); + if (!xb) { + return true; + } + return xa->xineramaNumber() < xb->xineramaNumber(); + }); + Q_EMIT screensQueried(); }