From fc58fbaa71895d921f4dffee5424afd0933799e0 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Wed, 13 Jul 2022 19:41:25 +0300 Subject: [PATCH] Add conversion helpers between xinerama indices and output objects Currently, we implicitly assume that enabled outputs are stored in the xinerama order, but with ongoing refactorings, it's easy to break that assumption. Also, we are not going to change the DRM backend so it stores enabled outputs in the xinerama order. This change adds xinerama index conversion helpers in order to reduce the number of potential regressions with output refactorings. --- src/activation.cpp | 2 +- src/workspace.cpp | 7 ++++++- src/workspace.h | 2 ++ src/x11window.cpp | 10 +++++----- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/activation.cpp b/src/activation.cpp index ff3f98c2ba..84dbf62055 100644 --- a/src/activation.cpp +++ b/src/activation.cpp @@ -768,7 +768,7 @@ void X11Window::startupIdChanged() workspace()->sendWindowToDesktop(this, desktop, true); } if (asn_data.xinerama() != -1) { - Output *output = kwinApp()->platform()->findOutput(asn_data.xinerama()); + Output *output = workspace()->xineramaIndexToOutput(asn_data.xinerama()); if (output) { workspace()->sendWindowToOutput(this, output); } diff --git a/src/workspace.cpp b/src/workspace.cpp index d59805beca..57b569b73a 100644 --- a/src/workspace.cpp +++ b/src/workspace.cpp @@ -2248,7 +2248,7 @@ QRectF Workspace::clientArea(clientAreaOption opt, const Output *output, const V const Output *effectiveOutput = output; if (is_multihead) { - effectiveOutput = kwinApp()->platform()->findOutput(screen_number); + effectiveOutput = xineramaIndexToOutput(screen_number); } if (auto desktopIt = m_screenAreas.constFind(desktop); desktopIt != m_screenAreas.constEnd()) { @@ -2352,6 +2352,11 @@ int Workspace::oldDisplayHeight() const return olddisplaysize.height(); } +Output *Workspace::xineramaIndexToOutput(int index) const +{ + return kwinApp()->platform()->enabledOutputs().value(index); +} + Output *Workspace::activeOutput() const { if (options->activeMouseScreen()) { diff --git a/src/workspace.h b/src/workspace.h index 837ca8d21e..9f9b4a6d17 100644 --- a/src/workspace.h +++ b/src/workspace.h @@ -151,6 +151,8 @@ public: bool initializing() const; + Output *xineramaIndexToOutput(int index) const; + Output *activeOutput() const; void setActiveOutput(Output *output); void setActiveOutput(const QPointF &pos); diff --git a/src/x11window.cpp b/src/x11window.cpp index 6eb0f6daf8..dbf8c66252 100644 --- a/src/x11window.cpp +++ b/src/x11window.cpp @@ -619,7 +619,7 @@ bool X11Window::manage(xcb_window_t w, bool isMapped) } else { Output *output = nullptr; if (asn_data.xinerama() != -1) { - output = kwinApp()->platform()->findOutput(asn_data.xinerama()); + output = workspace()->xineramaIndexToOutput(asn_data.xinerama()); } if (!output) { output = workspace()->activeOutput(); @@ -4649,16 +4649,16 @@ QRect X11Window::fullscreenMonitorsArea(NETFullscreenMonitors requestedTopology) { QRect total; - if (auto output = kwinApp()->platform()->findOutput(requestedTopology.top)) { + if (auto output = workspace()->xineramaIndexToOutput(requestedTopology.top)) { total = total.united(output->geometry()); } - if (auto output = kwinApp()->platform()->findOutput(requestedTopology.bottom)) { + if (auto output = workspace()->xineramaIndexToOutput(requestedTopology.bottom)) { total = total.united(output->geometry()); } - if (auto output = kwinApp()->platform()->findOutput(requestedTopology.left)) { + if (auto output = workspace()->xineramaIndexToOutput(requestedTopology.left)) { total = total.united(output->geometry()); } - if (auto output = kwinApp()->platform()->findOutput(requestedTopology.right)) { + if (auto output = workspace()->xineramaIndexToOutput(requestedTopology.right)) { total = total.united(output->geometry()); }