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>
This commit is contained in:
David Redondo 2022-10-18 11:57:22 +02:00
parent 6847a19e3e
commit d21b484354
3 changed files with 48 additions and 0 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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