Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

[wayland] Fix custom tooltip position on Wayland

Dmitry Kazakovb93021834cbb
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1ac6802d24..505dc79599 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -924,14 +924,11 @@ if (NOT WIN32 AND NOT APPLE AND NOT ANDROID AND NOT HAIKU)
PURPOSE "Optionally used to provide crash reporting on Linux")
find_package(X11 REQUIRED COMPONENTS Xinput)
- set(HAVE_X11 TRUE)
- add_definitions(-DHAVE_X11)
-
else()
set(HAVE_DBUS FALSE)
- set(HAVE_X11 FALSE)
endif()
+set (HAVE_X11 ${X11_FOUND})
add_definitions(
-DQT_USE_QSTRINGBUILDER
diff --git a/KoConfig.h.cmake b/KoConfig.h.cmake
index 6cd184c4ef..ddefc42614 100644
--- a/KoConfig.h.cmake
+++ b/KoConfig.h.cmake
@@ -58,5 +58,11 @@
/* Defines if KCrash is present */
#cmakedefine HAVE_KCRASH 1
+/* Defines if X11 libraries are present */
+#cmakedefine HAVE_X11 1
+
+/* Defines if Wayland support is present in Qt */
+#cmakedefine HAVE_WAYLAND 1
+
/* This variable contains the path to the root of the build directory */
#define KRITA_BUILD_DIR "${CMAKE_BINARY_DIR}"
diff --git a/libs/image/kis_threaded_text_rendering_workaround.h b/libs/image/kis_threaded_text_rendering_workaround.h
index 66a7466743..507b142815 100644
--- a/libs/image/kis_threaded_text_rendering_workaround.h
+++ b/libs/image/kis_threaded_text_rendering_workaround.h
@@ -7,6 +7,8 @@
#ifndef __KIS_THREADED_TEXT_RENDERING_WORKAROUND_H
#define __KIS_THREADED_TEXT_RENDERING_WORKAROUND_H
+#include <KoConfig.h>
+
/**
* There is a bug in Qt/X11 which prevents the QPainter::drawText() call
* be used in any non-gui thread, even when
diff --git a/libs/resourcewidgets/KisIconToolTip.cpp b/libs/resourcewidgets/KisIconToolTip.cpp
index 9a45fc9b16..9ccf7a2a5c 100644
--- a/libs/resourcewidgets/KisIconToolTip.cpp
+++ b/libs/resourcewidgets/KisIconToolTip.cpp
@@ -19,7 +19,8 @@
#include "KoCheckerBoardPainter.h"
-KisIconToolTip::KisIconToolTip()
+KisIconToolTip::KisIconToolTip(QWidget *parent)
+ : KoItemToolTip(parent)
{
}
diff --git a/libs/resourcewidgets/KisIconToolTip.h b/libs/resourcewidgets/KisIconToolTip.h
index 57161397ee..c13b9cd1fa 100644
--- a/libs/resourcewidgets/KisIconToolTip.h
+++ b/libs/resourcewidgets/KisIconToolTip.h
@@ -19,7 +19,7 @@ class KRITARESOURCEWIDGETS_EXPORT KisIconToolTip: public KoItemToolTip
{
public:
- KisIconToolTip();
+ KisIconToolTip(QWidget *parent);
~KisIconToolTip() override;
void setFixedToolTipThumbnailSize(const QSize &size);
diff --git a/libs/resourcewidgets/KisResourceItemListView.cpp b/libs/resourcewidgets/KisResourceItemListView.cpp
index eb9886599d..7da4225121 100644
--- a/libs/resourcewidgets/KisResourceItemListView.cpp
+++ b/libs/resourcewidgets/KisResourceItemListView.cpp
@@ -16,6 +16,8 @@
struct Q_DECL_HIDDEN KisResourceItemListView::Private
{
+ Private(KisResourceItemListView *_q) : tip(_q) {}
+
ListViewMode viewMode = ListViewMode::IconGrid;
bool strictSelectionMode {false};
KisIconToolTip tip;
@@ -28,7 +30,7 @@ struct Q_DECL_HIDDEN KisResourceItemListView::Private
KisResourceItemListView::KisResourceItemListView(QWidget *parent)
: QListView(parent)
- , m_d(new Private)
+ , m_d(new Private(this))
{
setSelectionMode(QAbstractItemView::SingleSelection);
setContextMenuPolicy(Qt::DefaultContextMenu);
@@ -204,7 +206,7 @@ bool KisResourceItemListView::viewportEvent(QEvent *event)
QModelIndex index = model()->buddy(indexAt(he->pos()));
if (index.isValid()) {
option.rect = visualRect(index);
- m_d->tip.showTip(this, he->pos(), option, index);
+ m_d->tip.showTip(he->pos(), option, index);
return true;
}
m_d->tip.hide();
diff --git a/libs/resourcewidgets/KisResourceItemListWidget.cpp b/libs/resourcewidgets/KisResourceItemListWidget.cpp
index 251a0c79ed..3e90b2c197 100644
--- a/libs/resourcewidgets/KisResourceItemListWidget.cpp
+++ b/libs/resourcewidgets/KisResourceItemListWidget.cpp
@@ -19,6 +19,7 @@
struct Q_DECL_HIDDEN KisResourceItemListWidget::Private
{
+ Private(KisResourceItemListWidget *_q) : tip(_q) {}
ListViewMode viewMode = ListViewMode::IconGrid;
bool strictSelectionMode {false};
KisIconToolTip tip;
@@ -29,7 +30,7 @@ struct Q_DECL_HIDDEN KisResourceItemListWidget::Private
KisResourceItemListWidget::KisResourceItemListWidget(QWidget *parent)
: QListWidget(parent)
- , m_d(new Private)
+ , m_d(new Private(this))
{
setSelectionMode(QAbstractItemView::ExtendedSelection);
setContextMenuPolicy(Qt::DefaultContextMenu);
diff --git a/libs/resourcewidgets/KisResourceItemView.cpp b/libs/resourcewidgets/KisResourceItemView.cpp
index 22f97ee2b8..191bbcdcb8 100644
--- a/libs/resourcewidgets/KisResourceItemView.cpp
+++ b/libs/resourcewidgets/KisResourceItemView.cpp
@@ -19,6 +19,7 @@
KisResourceItemView::KisResourceItemView(QWidget *parent)
: QTableView(parent)
+ , m_tip(this)
{
setSelectionMode(QAbstractItemView::SingleSelection);
verticalHeader()->hide();
@@ -50,7 +51,7 @@ bool KisResourceItemView::viewportEvent(QEvent *event)
QModelIndex index = model()->buddy(indexAt(he->pos()));
if (index.isValid()) {
option.rect = visualRect(index);
- m_tip.showTip(this, he->pos(), option, index);
+ m_tip.showTip(he->pos(), option, index);
return true;
}
}
diff --git a/libs/ui/opengl/KisOpenGLModeProber.cpp b/libs/ui/opengl/KisOpenGLModeProber.cpp
index bfcbead58d..b49786640a 100644
--- a/libs/ui/opengl/KisOpenGLModeProber.cpp
+++ b/libs/ui/opengl/KisOpenGLModeProber.cpp
@@ -13,6 +13,7 @@
#include <QOpenGLFunctions>
#include <QWindow>
#include <QColorSpace>
+#include <KoConfig.h>
#ifdef HAVE_HDR
// for fetching the legacy 80-nits PQ space
diff --git a/libs/ui/opengl/kis_opengl.cpp b/libs/ui/opengl/kis_opengl.cpp
index 9b1c48a2ea..5f8746e964 100644
--- a/libs/ui/opengl/kis_opengl.cpp
+++ b/libs/ui/opengl/kis_opengl.cpp
@@ -29,6 +29,8 @@
#include <QSettings>
#include <QScreen>
+#include <KoConfig.h>
+
#include <klocalizedstring.h>
#include <KisRepaintDebugger.h>
diff --git a/libs/widgetutils/CMakeLists.txt b/libs/widgetutils/CMakeLists.txt
index 00f3c84d9f..6d44ab7f69 100644
--- a/libs/widgetutils/CMakeLists.txt
+++ b/libs/widgetutils/CMakeLists.txt
@@ -173,8 +173,19 @@ target_link_libraries(kritawidgetutils
if (QT_MAJOR_VERSION STREQUAL "6")
target_link_libraries(kritawidgetutils PRIVATE KF6::ColorScheme)
+
+ if (HAVE_WAYLAND)
+ set_source_files_properties(
+ KoItemToolTip.cpp
+ PROPERTIES
+ INCLUDE_DIRECTORIES
+ "${Qt6WaylandGlobalPrivate_INCLUDE_DIRS};${Qt6WaylandClient_PRIVATE_INCLUDE_DIRS};${Qt6Gui_PRIVATE_INCLUDE_DIRS}"
+ )
+ endif()
endif()
+
+
set_target_properties(kritawidgetutils
PROPERTIES VERSION ${GENERIC_KRITA_LIB_VERSION} SOVERSION ${GENERIC_KRITA_LIB_SOVERSION}
)
diff --git a/libs/widgetutils/KoItemToolTip.cpp b/libs/widgetutils/KoItemToolTip.cpp
index 96ef29c2e8..118f28be7a 100644
--- a/libs/widgetutils/KoItemToolTip.cpp
+++ b/libs/widgetutils/KoItemToolTip.cpp
@@ -6,88 +6,149 @@
#include "KoItemToolTip.h"
#include <QApplication>
-#include <QBasicTimer>
+#include <QTimer>
#include <QModelIndex>
#include <QPainter>
#include <QPaintEvent>
#include <QPersistentModelIndex>
#include <QStyleOptionViewItem>
#include <QTextDocument>
-#include <QTimerEvent>
#include <QToolTip>
#include <QScreen>
+// for HAVE_WAYLAND
+#include <KoConfig.h>
+
+#if defined HAVE_WAYLAND && QT_VERSION >= QT_VERSION_CHECK(6, 11, 0)
+#define HAVE_QT_PRIVATE_TOOLTIP_POSITION_API
+#endif
+
+#ifdef HAVE_QT_PRIVATE_TOOLTIP_POSITION_API
+#include <QtWaylandClient/private/qwaylandwindow_p.h>
+#endif
+
+#include <kis_assert.h>
+
+
class Q_DECL_HIDDEN KoItemToolTip::Private
{
public:
- QTextDocument *document;
+ std::unique_ptr<QTextDocument> document;
QPersistentModelIndex index;
QPoint pos;
- QBasicTimer timer;
-
- Private(): document(0) { }
+ QTimer timer;
};
-KoItemToolTip::KoItemToolTip()
- : d(new Private)
+KoItemToolTip::KoItemToolTip(QWidget *parent)
+ : QFrame(parent, Qt::FramelessWindowHint | Qt::ToolTip | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint)
+ , d(new Private)
{
- d->document = new QTextDocument(this);
- setWindowFlags(Qt::FramelessWindowHint | Qt::ToolTip
- | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
- QApplication::instance()->installEventFilter(this);
+ Q_ASSERT(parent);
+
+ d->timer.setSingleShot(true);
+ d->timer.setInterval(10000);
+ connect(&d->timer, &QTimer::timeout, this, &KoItemToolTip::hide);
+
+ d->document.reset(new QTextDocument(this));
+
+ parent->installEventFilter(this);
}
KoItemToolTip::~KoItemToolTip()
{
- delete d;
}
-void KoItemToolTip::showTip(QWidget *widget, const QPoint &pos, const QStyleOptionViewItem &option, const QModelIndex &index)
+void KoItemToolTip::showTip(const QPoint &pos, const QStyleOptionViewItem &option, const QModelIndex &index)
{
- QTextDocument *doc = createDocument(index);
+ std::unique_ptr<QTextDocument> doc(createDocument(index));
QPoint p = (isVisible() && index == d->index) ? d->pos : pos;
- if (!isVisible() || index != d->index || doc->toHtml() != d->document->toHtml())
- {
+ if (!isVisible() || index != d->index || doc->toHtml() != d->document->toHtml()) {
d->pos = p;
d->index = index;
- delete d->document;
- d->document = doc;
- updatePosition(widget, p, option);
+ d->document.swap(doc);
+ updatePosition(p, option);
if (!isVisible())
show();
else
update();
- d->timer.start(10000, this);
}
- else
- delete doc;
+
+ d->timer.start();
}
-void KoItemToolTip::updatePosition(QWidget *widget, const QPoint &pos, const QStyleOptionViewItem &option)
+void KoItemToolTip::updatePosition(const QPoint &pos, const QStyleOptionViewItem &option)
{
- QScreen *screen = widget->screen();
- const QRect drect = screen->availableGeometry();
- const QSize size = sizeHint();
- const int width = size.width(), height = size.height();
+ QWidget *widget = parentWidget();
+ KIS_SAFE_ASSERT_RECOVER_RETURN(widget);
+
const QPoint gpos = widget->mapToGlobal(pos);
- const QRect irect(widget->mapToGlobal(option.rect.topLeft()), option.rect.size());
+ const QSize size = sizeHint();
+
+ // resize **must** come before `setParentControlGeometry()`, otherwise
+ // compositor will place the window incorrectly!
+ resize(size);
- int y = gpos.y() + 20;
- if (y + height > drect.bottom())
- y = qMax(drect.top(), irect.top() - height);
+ // make sure that all the platform-specific structures for the window
+ // are created (i.e. QWaylandWindow) before trying to request them
+ // via `windowHandle()->handle()`
+ create();
- int x;
- if (gpos.x() + width < drect.right())
- x = gpos.x();
- else
- x = qMax(drect.left(), gpos.x() - width);
+#ifdef HAVE_QT_PRIVATE_TOOLTIP_POSITION_API
- move(x, y);
+ if (auto waylandWindow = dynamic_cast<QNativeInterface::Private::QWaylandWindow *>(windowHandle()->handle())) {
- resize(sizeHint());
- }
+ const QPoint parentPos = widget->window()->mapFromGlobal(gpos);
+ const QRect gravityRect(parentPos.x() - 20, parentPos.y() - 20, 40, 40);
+ waylandWindow->setParentControlGeometry(gravityRect);
+ waylandWindow->setExtendedWindowType(QNativeInterface::Private::QWaylandWindow::ToolTip);
+ } else
+#endif /* HAVE_QT_PRIVATE_TOOLTIP_POSITION_API */
+
+ {
+ QScreen *screen = widget->screen();
+ const QRect availableRect = screen->availableGeometry();
+ const int width = size.width(), height = size.height();
+ const QRect itemRect(widget->mapToGlobal(option.rect.topLeft()), option.rect.size());
+
+ int y = gpos.y() + 20;
+ if (y + height > availableRect.bottom()) {
+ y = itemRect.bottom();
+
+ if (y + height > availableRect.bottom()) {
+ y = gpos.y() - 20 - height;
+
+ if (y < availableRect.top()) {
+ y = itemRect.top() - height;
+
+ if (y < availableRect.top()) {
+ y = availableRect.top();
+ }
+ }
+ }
+ }
+
+ int x = gpos.x() + 20;
+ if (x + width > availableRect.right()) {
+ x = itemRect.right();
+
+ if (x + width > availableRect.right()) {
+ x = gpos.x() - 20 - width;
+
+ if (x < availableRect.left()) {
+ x = itemRect.left() - width;
+
+ if (x < availableRect.left()) {
+ x = availableRect.left();
+ }
+ }
+ }
+ }
+
+ move(QPoint(x, y));
+ }
+}
QSize KoItemToolTip::sizeHint() const
{
@@ -101,24 +162,10 @@ void KoItemToolTip::paintEvent(QPaintEvent*)
p.drawRect(0, 0, width() - 1, height() - 1);
}
-void KoItemToolTip::timerEvent(QTimerEvent *e)
-{
- if (e->timerId() == d->timer.timerId()) {
- hide();
- }
-}
-
bool KoItemToolTip::eventFilter(QObject *object, QEvent *event)
{
switch(event->type())
{
- case QEvent::KeyPress:
- case QEvent::KeyRelease:
- case QEvent::MouseButtonPress:
- case QEvent::MouseButtonRelease:
- case QEvent::FocusIn:
- case QEvent::FocusOut:
- case QEvent::Enter:
case QEvent::Leave:
hide();
default: break;
diff --git a/libs/widgetutils/KoItemToolTip.h b/libs/widgetutils/KoItemToolTip.h
index f9d55a2531..de073bb76a 100644
--- a/libs/widgetutils/KoItemToolTip.h
+++ b/libs/widgetutils/KoItemToolTip.h
@@ -24,9 +24,9 @@ class KRITAWIDGETUTILS_EXPORT KoItemToolTip : public QFrame
{
Q_OBJECT
public:
- KoItemToolTip();
+ KoItemToolTip(QWidget *parent);
~KoItemToolTip() override;
- void showTip(QWidget *widget, const QPoint &pos, const QStyleOptionViewItem &option, const QModelIndex &index);
+ void showTip(const QPoint &pos, const QStyleOptionViewItem &option, const QModelIndex &index);
protected:
@@ -55,16 +55,15 @@ protected:
private:
class Private;
- Private* const d;
+ std::unique_ptr<Private> const d;
- void updatePosition(QWidget *widget, const QPoint &pos, const QStyleOptionViewItem &option);
+ void updatePosition(const QPoint &pos, const QStyleOptionViewItem &option);
public:
QSize sizeHint() const override;
protected:
void paintEvent(QPaintEvent *e) override;
- void timerEvent(QTimerEvent *e) override;
bool eventFilter(QObject *object, QEvent *event) override;
};
diff --git a/plugins/dockers/animation/KisAnimTimelineFramesView.cpp b/plugins/dockers/animation/KisAnimTimelineFramesView.cpp
index d10891e819..20ae53be39 100644
--- a/plugins/dockers/animation/KisAnimTimelineFramesView.cpp
+++ b/plugins/dockers/animation/KisAnimTimelineFramesView.cpp
@@ -80,6 +80,7 @@ struct KisAnimTimelineFramesView::Private
, modifiersCatcher(0)
, kineticScrollInfiniteFrameUpdater()
, selectionChangedCompressor(300, KisSignalCompressor::FIRST_INACTIVE)
+ , tip(_q)
{
kineticScrollInfiniteFrameUpdater.setTimerType(Qt::CoarseTimer);
}
@@ -1012,7 +1013,7 @@ void KisAnimTimelineFramesView::mousePressEvent(QMouseEvent *event)
#endif
option.rect = visualRect(index);
// The offset of the headers is needed to get the correct position inside the view.
- m_d->tip.showTip(this, event->pos() + QPoint(verticalHeader()->width(), horizontalHeader()->height()), option, index);
+ m_d->tip.showTip(event->pos() + QPoint(verticalHeader()->width(), horizontalHeader()->height()), option, index);
}
event->accept();
@@ -1090,7 +1091,7 @@ void KisAnimTimelineFramesView::mouseMoveEvent(QMouseEvent *e)
#endif
option.rect = visualRect(index);
// The offset of the headers is needed to get the correct position inside the view.
- m_d->tip.showTip(this, e->pos() + QPoint(verticalHeader()->width(), horizontalHeader()->height()), option, index);
+ m_d->tip.showTip(e->pos() + QPoint(verticalHeader()->width(), horizontalHeader()->height()), option, index);
}
e->accept();
diff --git a/plugins/dockers/layerdocker/NodeDelegate.cpp b/plugins/dockers/layerdocker/NodeDelegate.cpp
index b338c6e99e..99b0251943 100644
--- a/plugins/dockers/layerdocker/NodeDelegate.cpp
+++ b/plugins/dockers/layerdocker/NodeDelegate.cpp
@@ -41,7 +41,7 @@ typedef KisBaseNode::Property* OptionalProperty;
class NodeDelegate::Private
{
public:
- Private(NodeDelegate *_q) : q(_q), view(0), edit(0) { }
+ Private(NodeDelegate *_q, NodeView *_view) : q(_q), view(_view), edit(0), tip(_view) { }
NodeDelegate *q;
@@ -88,10 +88,8 @@ public:
NodeDelegate::NodeDelegate(NodeView *view, QObject *parent)
: QAbstractItemDelegate(parent)
- , d(new Private(this))
+ , d(new Private(this, view))
{
- d->view = view;
-
QApplication::instance()->installEventFilter(this);
connect(KisConfigNotifier::instance(), SIGNAL(configChanged()), SLOT(slotConfigChanged()));
connect(this, SIGNAL(resetVisibilityStasis()), SLOT(slotResetState()));
@@ -1161,12 +1159,10 @@ bool NodeDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const Q
hoveredProperty->id == KisLayerPropertiesIcons::layerColorSpaceMismatch.id())) {
QToolTip::showText(helpEvent->globalPos(), hoveredProperty->state.toString(), d->view);
} else {
- d->tip.showTip(d->view, helpEvent->pos(), option, index);
+ d->tip.showTip(helpEvent->pos(), option, index);
}
}
return true;
- } else if (event->type() == QEvent::Leave) {
- d->tip.hide();
}
return false;
diff --git a/plugins/dockers/layerdocker/NodeToolTip.cpp b/plugins/dockers/layerdocker/NodeToolTip.cpp
index e439ef8fee..ccc3f3fc69 100644
--- a/plugins/dockers/layerdocker/NodeToolTip.cpp
+++ b/plugins/dockers/layerdocker/NodeToolTip.cpp
@@ -15,7 +15,8 @@
#include <kis_base_node.h>
#include <kis_layer_properties_icons.h>
-NodeToolTip::NodeToolTip()
+NodeToolTip::NodeToolTip(QWidget *widget)
+ : KoItemToolTip(widget)
{
}
diff --git a/plugins/dockers/layerdocker/NodeToolTip.h b/plugins/dockers/layerdocker/NodeToolTip.h
index c076b9663f..f62b14515e 100644
--- a/plugins/dockers/layerdocker/NodeToolTip.h
+++ b/plugins/dockers/layerdocker/NodeToolTip.h
@@ -20,7 +20,7 @@ class NodeToolTip: public KoItemToolTip
Q_OBJECT
public:
- NodeToolTip();
+ NodeToolTip(QWidget *widget);
~NodeToolTip() override;
protected:
diff --git a/plugins/dockers/layerdocker/NodeView.cpp b/plugins/dockers/layerdocker/NodeView.cpp
index db80a5ba73..4b60268873 100644
--- a/plugins/dockers/layerdocker/NodeView.cpp
+++ b/plugins/dockers/layerdocker/NodeView.cpp
@@ -17,6 +17,7 @@
#include <kis_icon.h>
#include <ksharedconfig.h>
#include <KisKineticScroller.h>
+#include <KoConfig.h>
#include <QtDebug>
#include <QContextMenuEvent>
diff --git a/plugins/platforms/wayland/waylandcolormanagement/WAYLAND_HACKING.md b/plugins/platforms/wayland/waylandcolormanagement/WAYLAND_HACKING.md
index 8e33dddf25..fc54704e7a 100644
--- a/plugins/platforms/wayland/waylandcolormanagement/WAYLAND_HACKING.md
+++ b/plugins/platforms/wayland/waylandcolormanagement/WAYLAND_HACKING.md
@@ -129,3 +129,85 @@ KRITA_FORCE_WAYLAND_INTERFACES=wp_color_manager_v1
```
Note: The extension will **NOT** function properly if you do this.
+
+# Troubleshooting
+
+## Window placement and popup positioning on Wayland
+
+On Wayland toplevel windows **do not know** their position on screen. They use a fake
+global coordinate system, where the window is "pinned" to the toplevel corner of the
+current screen. I.e. in a single-monitor setup, the global position of any toplevel
+window will always be (0,0). And on dual-monitor setup with FullHD displays, the position
+of a window will always be (0,0) when placed on the left screen, and (1920, 0)
+when placed on the right screen.
+
+This means that we cannot manually position `Qt::Popup` and `Qt::ToolTip` windows on
+screen. The calls to `widget->move()` will work in this parent-related fake coordinate
+system, not related to the actual position on screen.
+
+The proper way to acheve that on Wayland is to use `xdg_positioner` interface. Which
+is (surprise!) not available in the public Qt's API. Here is how to do that with the
+private API:
+
+```cpp
+
+// for HAVE_WAYLAND
+#include <KoConfig.h>
+
+#ifdef HAVE_WAYLAND
+#include <QtWaylandClient/private/qwaylandwindow_p.h>
+#endif
+
+QPoint gpos = somePreferredPointInGlobalCoordinates;
+const QSize size = somePreferredSizeOfThePopup;
+
+// resize **must** come before `setParentControlGeometry()`, otherwise
+// compositor will place the window incorrectly!
+resize(size);
+
+// make sure that all the platform-specific structures for the window
+// are created (i.e. QWaylandWindow) before trying to request them
+// via `windowHandle()->handle()`
+create();
+
+#ifdef HAVE_WAYLAND
+
+if (auto waylandWindow =
+ dynamic_cast<QNativeInterface::Private::QWaylandWindow *>(windowHandle()->handle())) {
+
+ // the positioner rect is measured in the coordinates of the nearest
+ // native parent window
+ const QPoint parentPos = parentWidget()->window()->mapFromGlobal(gpos);
+ QRect gravityRect(parentPos.x() - 20, parentPos.y() - 20, 40, 40);
+ waylandWindow->setParentControlGeometry(gravityRect);
+ waylandWindow->setExtendedWindowType(QNativeInterface::Private::QWaylandWindow::ToolTip);
+
+} else
+
+#endif /* HAVE_WAYLAND */
+
+{
+ QScreen *screen = widget->screen();
+ const QRect availableRect = screen->availableGeometry();
+
+ QRect newRect(gpos, size);
+ newSize = kisEnsureInRect(newRect, availableGeometry);
+
+ move(newSize.topLeft());
+}
+
+```
+
+In the corresponding CMakeLists.txt you should also add the private include
+directories path to this compilation unit:
+
+```cmake
+if (HAVE_WAYLAND)
+ set_source_files_properties(
+ KoItemToolTip.cpp
+ PROPERTIES
+ INCLUDE_DIRECTORIES
+ "${Qt6WaylandGlobalPrivate_INCLUDE_DIRS};${Qt6WaylandClient_PRIVATE_INCLUDE_DIRS};${Qt6Gui_PRIVATE_INCLUDE_DIRS}"
+ )
+endif()
+```
\ No newline at end of file