From 476d751251c8571e11260b7c712c885f4191d717 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Thu, 28 Mar 2024 04:11:43 +0400 Subject: [PATCH] Let Wayland to use QGuiApplication::screenAt Looks like it works correctly nowadays --- ui/widgets/popup_menu.cpp | 6 ++---- ui/widgets/tooltip.cpp | 7 +++++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/ui/widgets/popup_menu.cpp b/ui/widgets/popup_menu.cpp index 3a79351..1c9c7f9 100644 --- a/ui/widgets/popup_menu.cpp +++ b/ui/widgets/popup_menu.cpp @@ -958,9 +958,7 @@ bool PopupMenu::prepareGeometryFor(const QPoint &p) { bool PopupMenu::prepareGeometryFor(const QPoint &p, PopupMenu *parent) { const auto usingScreenGeometry = !::Platform::IsWayland(); - const auto screen = usingScreenGeometry - ? QGuiApplication::screenAt(p) - : nullptr; + const auto screen = QGuiApplication::screenAt(p); if ((usingScreenGeometry && !screen) || (!parent && ::Platform::IsMac() @@ -1002,7 +1000,7 @@ bool PopupMenu::prepareGeometryFor(const QPoint &p, PopupMenu *parent) { _additionalMenuPadding.left() - _st.shadow.extend.left(), 0), _padding.top() - _topShift); - auto r = screen ? screen->availableGeometry() : QRect(); + auto r = usingScreenGeometry ? screen->availableGeometry() : QRect(); const auto parentWidth = _parent ? _parent->inner().width() : 0; if (style::RightToLeft()) { const auto badLeft = !r.isNull() && w.x() - width() < r.x() - _margins.left(); diff --git a/ui/widgets/tooltip.cpp b/ui/widgets/tooltip.cpp index 73af93a..44dcd93 100644 --- a/ui/widgets/tooltip.cpp +++ b/ui/widgets/tooltip.cpp @@ -77,7 +77,7 @@ Tooltip::~Tooltip() { void Tooltip::popup(const QPoint &m, const QString &text, const style::Tooltip *st) { const auto usingScreenGeometry = !::Platform::IsWayland(); - const auto screen = usingScreenGeometry ? QGuiApplication::screenAt(m) : nullptr; + const auto screen = QGuiApplication::screenAt(m); if (usingScreenGeometry && !screen) { Hide(); return; @@ -118,10 +118,13 @@ void Tooltip::popup(const QPoint &m, const QString &text, const style::Tooltip * p.setX(m.x() - (s.width() / 2)); } - // adjust tooltip position if (screen) { createWinId(); windowHandle()->setScreen(screen); + } + + // adjust tooltip position + if (usingScreenGeometry) { const auto r = screen->availableGeometry(); if (r.x() + r.width() - _st->skip < p.x() + s.width() && p.x() + s.width() > m.x()) { p.setX(qMax(r.x() + r.width() - int32(_st->skip) - s.width(), m.x() - s.width()));