1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qwaylandwindowmanagerintegration_p.h"
5#include "qwaylandscreen_p.h"
6#include "qwaylandwindow_p.h"
7#include "qwaylanddisplay_p.h"
8#include "qwaylandshellsurface_p.h"
9
10#include <stdint.h>
11#include <QtCore/QEvent>
12#include <QtCore/QHash>
13#include <QtCore/QUrl>
14#include <qpa/qplatformnativeinterface.h>
15#include <qpa/qplatformwindow.h>
16#include <QtGui/QtEvents>
17#include <QtGui/QGuiApplication>
18
19#include <QDebug>
20
21QT_BEGIN_NAMESPACE
22
23namespace QtWaylandClient {
24
25class QWaylandWindowManagerIntegrationPrivate {
26public:
27 QWaylandWindowManagerIntegrationPrivate(QWaylandDisplay *waylandDisplay);
28 bool m_blockPropertyUpdates = false;
29 QWaylandDisplay *m_waylandDisplay = nullptr;
30 QHash<QWindow*, QVariantMap> m_queuedProperties;
31 bool m_showIsFullScreen = false;
32};
33
34QWaylandWindowManagerIntegrationPrivate::QWaylandWindowManagerIntegrationPrivate(QWaylandDisplay *waylandDisplay)
35 : m_waylandDisplay(waylandDisplay)
36{
37
38}
39
40QWaylandWindowManagerIntegration::QWaylandWindowManagerIntegration(QWaylandDisplay *waylandDisplay)
41 : d_ptr(new QWaylandWindowManagerIntegrationPrivate(waylandDisplay))
42{
43 waylandDisplay->addRegistryListener(listener: &wlHandleListenerGlobal, data: this);
44}
45
46QWaylandWindowManagerIntegration::~QWaylandWindowManagerIntegration()
47{
48
49}
50
51bool QWaylandWindowManagerIntegration::showIsFullScreen() const
52{
53 Q_D(const QWaylandWindowManagerIntegration);
54 return d->m_showIsFullScreen;
55}
56
57void QWaylandWindowManagerIntegration::wlHandleListenerGlobal(void *data, wl_registry *registry, uint32_t id, const QString &interface, uint32_t version)
58{
59 Q_UNUSED(version);
60 if (interface == QStringLiteral("qt_windowmanager"))
61 static_cast<QWaylandWindowManagerIntegration *>(data)->init(registry, id, 1);
62}
63
64void QWaylandWindowManagerIntegration::windowmanager_hints(int32_t showIsFullScreen)
65{
66 Q_D(QWaylandWindowManagerIntegration);
67 d->m_showIsFullScreen = showIsFullScreen;
68}
69
70void QWaylandWindowManagerIntegration::windowmanager_quit()
71{
72 QGuiApplication::quit();
73}
74
75void QWaylandWindowManagerIntegration::openUrl_helper(const QUrl &url)
76{
77 Q_ASSERT(isInitialized());
78 QString data = url.toString();
79
80 static const int chunkSize = 128;
81 while (!data.isEmpty()) {
82 QString chunk = data.left(n: chunkSize);
83 data = data.mid(position: chunkSize);
84 if (chunk.at(i: chunk.size() - 1).isHighSurrogate() && !data.isEmpty()) {
85 chunk.append(c: data.at(i: 0));
86 data = data.mid(position: 1);
87 }
88 open_url(!data.isEmpty(), chunk);
89 }
90}
91
92bool QWaylandWindowManagerIntegration::openUrl(const QUrl &url)
93{
94 if (isInitialized()) {
95 openUrl_helper(url);
96 return true;
97 }
98 return QGenericUnixServices::openUrl(url);
99}
100
101bool QWaylandWindowManagerIntegration::openDocument(const QUrl &url)
102{
103 if (isInitialized()) {
104 openUrl_helper(url);
105 return true;
106 }
107 return QGenericUnixServices::openDocument(url);
108}
109
110QString QWaylandWindowManagerIntegration::portalWindowIdentifier(QWindow *window)
111{
112 if (window && window->handle()) {
113 auto shellSurface = static_cast<QWaylandWindow *>(window->handle())->shellSurface();
114 if (shellSurface) {
115 const QString handle = shellSurface->externWindowHandle();
116 return QLatin1String("wayland:") + handle;
117 }
118 }
119 return QString();
120}
121}
122
123QT_END_NAMESPACE
124
125#include "moc_qwaylandwindowmanagerintegration_p.cpp"
126

source code of qtwayland/src/client/qwaylandwindowmanagerintegration.cpp