summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorDavid Redondo <qt@david-redondo.de>2022-10-18 11:57:22 +0200
committerDavid Redondo <qt@david-redondo.de>2022-11-29 13:45:35 +0200
commitd21b48435436759c4e86cd8db15af8bedba6c552 (patch)
tree1dac98576f6037d0adf9f70510dbf4d3c766f5d8 /src/gui
parent6847a19e3edc76cce6ca0f0c25e520db591cedb9 (diff)
Add QNativeInterface::Private::QWaylandWindow
Allows to access the wl_surface, the setCustomMargins functions and the object corresponding to the surface role of the surface. Also adds the xdg activation token functionality as it is needed by another change in qtbase. If the type passed to surfaceRole does not match the actual type of the current surface role nullptr is returned. QVariant is not used for transferring the surface role object because it requires Q_DECLARE_OPAQUE_POINTER for storing and retrieving from the QVariant. However QtWayland uses a plugin system for shell integrations with known external plugins so it is not possible to centrally do this for every possible pointer type. The alternative would be that plugin and consumer delcare it both which does not make for an ergonomic API. Change-Id: I6f4e036846485ba1895e7435bb28827b83249024 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/kernel/qplatformwindow_p.h33
-rw-r--r--src/gui/kernel/qwindow.cpp4
-rw-r--r--src/gui/platform/unix/qunixnativeinterface.cpp11
3 files changed, 48 insertions, 0 deletions
diff --git a/src/gui/kernel/qplatformwindow_p.h b/src/gui/kernel/qplatformwindow_p.h
index 62dc87779e..7a57c888e2 100644
--- a/src/gui/kernel/qplatformwindow_p.h
+++ b/src/gui/kernel/qplatformwindow_p.h
@@ -20,6 +20,12 @@
#include <QtCore/qrect.h>
#include <QtCore/qnativeinterface.h>
+#if defined(Q_OS_UNIX)
+#include <any>
+
+struct wl_surface;
+#endif
+
QT_BEGIN_NAMESPACE
class QMargins;
@@ -89,6 +95,33 @@ struct Q_GUI_EXPORT QWindowsWindow
};
#endif // Q_OS_WIN
+#if defined(Q_OS_UNIX)
+struct Q_GUI_EXPORT QWaylandWindow : public QObject
+{
+ Q_OBJECT
+public:
+ QT_DECLARE_NATIVE_INTERFACE(QWaylandWindow, 1, QWindow)
+
+ virtual wl_surface *surface() const = 0;
+ virtual void setCustomMargins(const QMargins &margins) = 0;
+ virtual void requestXdgActivationToken(uint serial) = 0;
+ template<typename T>
+ T *surfaceRole() const
+ {
+ std::any anyRole = _surfaceRole();
+ auto role = std::any_cast<T *>(&anyRole);
+ return role ? *role : nullptr;
+ }
+signals:
+ void surfaceCreated();
+ void surfaceDestroyed();
+ void xdgActivationTokenCreated(const QString &token);
+
+protected:
+ virtual std::any _surfaceRole() const = 0;
+};
+#endif
+
} // QNativeInterface::Private
QT_END_NAMESPACE
diff --git a/src/gui/kernel/qwindow.cpp b/src/gui/kernel/qwindow.cpp
index 13e2051e14..29976613aa 100644
--- a/src/gui/kernel/qwindow.cpp
+++ b/src/gui/kernel/qwindow.cpp
@@ -3027,6 +3027,10 @@ void *QWindow::resolveInterface(const char *name, int revision) const
QT_NATIVE_INTERFACE_RETURN_IF(QCocoaWindow, platformWindow);
#endif
+#if defined(Q_OS_UNIX)
+ QT_NATIVE_INTERFACE_RETURN_IF(QWaylandWindow, platformWindow);
+#endif
+
return nullptr;
}
diff --git a/src/gui/platform/unix/qunixnativeinterface.cpp b/src/gui/platform/unix/qunixnativeinterface.cpp
index 1b9c6eb4f0..1cca97b34c 100644
--- a/src/gui/platform/unix/qunixnativeinterface.cpp
+++ b/src/gui/platform/unix/qunixnativeinterface.cpp
@@ -269,6 +269,17 @@ QT_DEFINE_NATIVE_INTERFACE(QWaylandApplication);
QT_DEFINE_PRIVATE_NATIVE_INTERFACE(QWaylandScreen);
+/*!
+ \class QNativeInterface::QWaylandWindow
+ \since 6.5
+ \internal
+ \brief Native interface to a Wayland window.
+ \inmodule QtGui
+ \ingroup native-interfaces
+*/
+
+QT_DEFINE_PRIVATE_NATIVE_INTERFACE(QWaylandWindow);
+
#endif // Q_OS_UNIX
QT_END_NAMESPACE