summaryrefslogtreecommitdiffstats
path: root/src/widgets/kernel/qtooltip.cpp
diff options
context:
space:
mode:
authorDavid Edmundson <[email protected]>2023-05-25 22:25:46 +0100
committerDavid Edmundson <[email protected]>2025-10-14 00:02:02 +0100
commit4eed22e67ed98ec2565be84a4838955af0faf8b0 (patch)
tree406c45e7a0d046ba7cf67e52553f426a3a803fe2 /src/widgets/kernel/qtooltip.cpp
parent6bb3171e312d1caf3c29c00bcd2cc366b98a5bd1 (diff)
widgets: Pass popup semantic information to Wayland
On Wayland applications do not know their own window positions, this means that popups cannot stay on screen by themselves. When a window tries to go offscreen the way the window is adjusted is context-specific: - The first menu will be kept on screen by moving the x position until it all fits. - A submenu is too close to the screen edge, the menu will open on the opposite side of the parent menu to avoid obscuring it. - A combo box drop downs will vertically flip to the other side of the originating combobox. The Wayland API requires the application to provide semantic hints about the area in which the popup should be placed, along with hints about in which direction we should try to place the popup and how to handle being constrained. At a QPA level we don't know the location of individual widgets so this needs forwarding explicitly. Rather than exposing all possible positioning information, it is inferred from the window type at a QPA level, this required extending windowType to have more explicit values. Ideally this needs to be application-facing API as there are third-party comboboxes, but for now it is private with Qt's default controls opting into it. Task-number: QTBUG-99618 Task-number: QTBUG-124810 Fixes: QTBUG-135883 Change-Id: I49a2f18d1bfe1b755f259627722e076d58c13e8f Reviewed-by: David Redondo <[email protected]>
Diffstat (limited to 'src/widgets/kernel/qtooltip.cpp')
-rw-r--r--src/widgets/kernel/qtooltip.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/widgets/kernel/qtooltip.cpp b/src/widgets/kernel/qtooltip.cpp
index 9e6aaf4b95f..d989feb7f91 100644
--- a/src/widgets/kernel/qtooltip.cpp
+++ b/src/widgets/kernel/qtooltip.cpp
@@ -20,6 +20,8 @@
#if QT_CONFIG(style_stylesheet)
#include <private/qstylesheetstyle_p.h>
#endif
+#include <qpa/qplatformwindow.h>
+#include <qpa/qplatformwindow_p.h>
#include <qlabel.h>
#include <QtWidgets/private/qlabel_p.h>
@@ -386,6 +388,17 @@ void QTipLabel::placeTip(const QPoint &pos, QWidget *w)
p += offset;
+#if QT_CONFIG(wayland)
+ create();
+ if (auto waylandWindow = dynamic_cast<QNativeInterface::Private::QWaylandWindow*>(windowHandle()->handle())) {
+ // based on the existing code below, by default position at 'p' stored at the bottom right of our rect
+ // then flip to the other arbitrary 4x24 space if constrained
+ const QRect controlGeometry(QRect(p.x() - 4, p.y() - 24, 4, 24));
+ waylandWindow->setParentControlGeometry(controlGeometry);
+ waylandWindow->setExtendedWindowType(QNativeInterface::Private::QWaylandWindow::ToolTip);
+ }
+#endif
+
QRect screenRect = screen->geometry();
if (p.x() + this->width() > screenRect.x() + screenRect.width())
p.rx() -= 4 + this->width();