From 8fe8d4420a43c8600226e8d2eb8590bd3d4b569a Mon Sep 17 00:00:00 2001 From: Tsu Jan Date: Wed, 21 Aug 2024 18:40:13 +0330 Subject: [PATCH] Fixed main popup positions under Wayland MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … for bottom and right panels. The problem was that some Wayland compositors returned global coordinates when anchors were applied, while some others (perhaps KWin) didn't. So, the patch uses local coordinates and changes them to the global ones in the end. --- panel/lxqtpanel.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/panel/lxqtpanel.cpp b/panel/lxqtpanel.cpp index f4144ff41..545617bb4 100644 --- a/panel/lxqtpanel.cpp +++ b/panel/lxqtpanel.cpp @@ -1416,28 +1416,35 @@ Plugin* LXQtPanel::findPlugin(const ILXQtPanelPlugin* iPlugin) const ************************************************/ QRect LXQtPanel::calculatePopupWindowPos(QPoint const & absolutePos, QSize const & windowSize) const { - int x = absolutePos.x(), y = absolutePos.y(); + // Using of anchors makes coordinates be absolute under some Wayland compositors. + // Therefore, to cover both X11 and Wayland, we first use the local coordinates + // and then map them to the global coordinates. + QPoint localPos = mapFromGlobal(absolutePos); + int x = localPos.x(), y = localPos.y(); switch (position()) { case ILXQtPanel::PositionTop: - y = mGeometry.bottom(); + y = mGeometry.height(); break; case ILXQtPanel::PositionBottom: - y = mGeometry.top() - windowSize.height(); + y = -windowSize.height(); break; case ILXQtPanel::PositionLeft: - x = mGeometry.right(); + x = mGeometry.width(); break; case ILXQtPanel::PositionRight: - x = mGeometry.left() - windowSize.width(); + x = -windowSize.width(); break; } - QRect res(QPoint(x, y), windowSize); + QRect res(mapToGlobal(QPoint(x, y)), windowSize); + + if (qGuiApp->nativeInterface()) + return res; QRect panelScreen; const auto screens = QApplication::screens(); @@ -1479,7 +1486,7 @@ QRect LXQtPanel::calculatePopupWindowPos(const ILXQtPanelPlugin *plugin, const Q } // Note: assuming there are not contentMargins around the "BackgroundWidget" (LXQtPanelWidget) - return calculatePopupWindowPos(mGeometry.topLeft() + panel_plugin->geometry().topLeft(), windowSize); + return calculatePopupWindowPos(mapToGlobal(panel_plugin->geometry().topLeft()), windowSize); }