Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qwaylandclientextension.h
Go to the documentation of this file.
1// Copyright (C) 2017 Erik Larsson.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QWAYLANDCLIENTEXTENSION_H
5#define QWAYLANDCLIENTEXTENSION_H
6
7#include <QtCore/QObject>
8#include <QtWaylandClient/qtwaylandclientglobal.h>
9
10struct wl_interface;
11struct wl_registry;
12
14
15namespace QtWaylandClient {
17}
18
21
22class Q_WAYLANDCLIENT_EXPORT QWaylandClientExtension : public QObject
23{
25 Q_DECLARE_PRIVATE(QWaylandClientExtension)
26 Q_PROPERTY(int protocolVersion READ version NOTIFY versionChanged)
27 Q_PROPERTY(bool active READ isActive NOTIFY activeChanged)
28public:
29 QWaylandClientExtension(const int version);
31
32 QtWaylandClient::QWaylandIntegration *integration() const;
33 int version() const;
34 bool isActive() const;
35
36 virtual const struct wl_interface *extensionInterface() const = 0;
37 virtual void bind(struct ::wl_registry *registry, int id, int version) = 0;
38protected:
39 void setVersion(const int version);
41 void versionChanged();
42 void activeChanged();
43
44protected Q_SLOTS:
45 void initialize();
46};
47
48
49template<typename T, auto destruct = nullptr>
50class Q_WAYLANDCLIENT_EXPORT QWaylandClientExtensionTemplate : public QWaylandClientExtension
51{
52 Q_DECLARE_PRIVATE(QWaylandClientExtensionTemplate)
53
54public:
56 {
57 if constexpr (destruct != nullptr) {
59 if (!isActive()) {
60 std::invoke(destruct, static_cast<T *>(this));
61 }
62 });
63 }
64 }
65
67 {
68 if constexpr (destruct != nullptr) {
69 if (isActive()) {
70 std::invoke(destruct, static_cast<T *>(this));
71 }
72 }
73 }
74
75 const struct wl_interface *extensionInterface() const override
76 {
77 return T::interface();
78 }
79
80 void bind(struct ::wl_registry *registry, int id, int ver) override
81 {
82 T* instance = static_cast<T *>(this);
83 // Make sure lowest version is used of the supplied version from the
84 // developer and the version specified in the protocol and also the
85 // compositor version.
86 if (this->version() > T::interface()->version) {
87 qWarning("Supplied protocol version to QWaylandClientExtensionTemplate is higher than the version of the protocol, using protocol version instead.");
88 }
89 int minVersion = qMin(ver, qMin(T::interface()->version, this->version()));
90 setVersion(minVersion);
91 instance->init(registry, id, minVersion);
92 }
93};
94
96
97#endif // QWAYLANDCLIENTEXTENSION_H
bool isActive
\inmodule QtCore
Definition qobject.h:103
void bind(struct ::wl_registry *registry, int id, int ver) override
const struct wl_interface * extensionInterface() const override
format setVersion(3, 2)
Combined button and popup list for selecting options.
static bool initialize()
Definition qctf.cpp:94
#define qWarning
Definition qlogging.h:166
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
QT_BEGIN_NAMESPACE const int protocolVersion
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_SLOTS
#define Q_SIGNALS
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)
socketLayer bind(QHostAddress::Any, 4000)