From f91ae3e97584767d273479c4013a43e279d77f40 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Tue, 9 Nov 2021 18:01:13 +0100 Subject: [PATCH] xwayland: Also follow the primary output We want to update the XRandR information so that X11 apps know which is the primary display, since some of them make use of it to position themselves. --- src/xwl/xwayland.cpp | 28 ++++++++++++++++++++++++++++ src/xwl/xwayland.h | 2 ++ 2 files changed, 30 insertions(+) diff --git a/src/xwl/xwayland.cpp b/src/xwl/xwayland.cpp index db64b4b8c5..80fd3fb0d2 100644 --- a/src/xwl/xwayland.cpp +++ b/src/xwl/xwayland.cpp @@ -14,9 +14,11 @@ #include "dnd.h" #include "xwldrophandler.h" +#include "abstract_output.h" #include "main_wayland.h" #include "options.h" #include "utils.h" +#include "platform.h" #include "wayland_server.h" #include "xcbutils.h" #include "xwayland_logging.h" @@ -215,6 +217,7 @@ void Xwayland::stop() void Xwayland::stopInternal() { + disconnect(kwinApp()->platform(), &Platform::primaryOutputChanged, this, &Xwayland::updatePrimary); Q_ASSERT(m_xwaylandProcess); m_app->setClosingX11Connection(true); @@ -400,9 +403,34 @@ void Xwayland::handleXwaylandReady() qputenv("XAUTHORITY", m_xAuthority.toUtf8()); m_app->setProcessStartupEnvironment(env); + connect(kwinApp()->platform(), &Platform::primaryOutputChanged, this, &Xwayland::updatePrimary); + updatePrimary(kwinApp()->platform()->primaryOutput()); + Xcb::sync(); // Trigger possible errors, there's still a chance to abort } +void Xwayland::updatePrimary(AbstractOutput *primaryOutput) +{ + Xcb::RandR::ScreenResources resources(rootWindow()); + xcb_randr_crtc_t *crtcs = resources.crtcs(); + if (!crtcs) { + return; + } + + for (int i = 0; i < resources->num_crtcs; ++i) { + Xcb::RandR::CrtcInfo crtcInfo(crtcs[i], resources->config_timestamp); + const QRect geometry = crtcInfo.rect(); + if (geometry.topLeft() == primaryOutput->geometry().topLeft()) { + auto outputs = crtcInfo.outputs(); + if (outputs && crtcInfo->num_outputs > 0) { + qCDebug(KWIN_XWL) << "Setting primary" << primaryOutput << outputs[0]; + xcb_randr_set_output_primary(kwinApp()->x11Connection(), rootWindow(), outputs[0]); + break; + } + } + } +} + void Xwayland::handleSelectionLostOwnership() { qCWarning(KWIN_XWL) << "Somebody else claimed ownership of WM_S0. This should never happen!"; diff --git a/src/xwl/xwayland.h b/src/xwl/xwayland.h index fc6f81131e..21c7675af1 100644 --- a/src/xwl/xwayland.h +++ b/src/xwl/xwayland.h @@ -20,6 +20,7 @@ class KSelectionOwner; namespace KWin { +class AbstractOutput; class ApplicationWaylandAbstract; class XwaylandSocket; @@ -115,6 +116,7 @@ private: void installSocketNotifier(); void uninstallSocketNotifier(); void maybeDestroyReadyNotifier(); + void updatePrimary(AbstractOutput *primaryOutput); bool startInternal(); void stopInternal();