1 | // Copyright (C) 2017 The Qt Company Ltd. |
2 | // Copyright (C) 2017 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com> |
3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
4 | |
5 | #include <QtCore/QObject> |
6 | #include <QtCore/QUrl> |
7 | |
8 | #include <QtWaylandCompositor/QWaylandCompositor> |
9 | #include <QtWaylandCompositor/QWaylandClient> |
10 | |
11 | #include "qwaylandqtwindowmanager.h" |
12 | #include "qwaylandqtwindowmanager_p.h" |
13 | |
14 | QT_BEGIN_NAMESPACE |
15 | |
16 | QWaylandQtWindowManagerPrivate::QWaylandQtWindowManagerPrivate() |
17 | { |
18 | } |
19 | |
20 | void QWaylandQtWindowManagerPrivate::windowmanager_bind_resource(Resource *resource) |
21 | { |
22 | send_hints(resource->handle, static_cast<int32_t>(showIsFullScreen)); |
23 | } |
24 | |
25 | void QWaylandQtWindowManagerPrivate::windowmanager_destroy_resource(Resource *resource) |
26 | { |
27 | urls.remove(resource); |
28 | } |
29 | |
30 | void QWaylandQtWindowManagerPrivate::windowmanager_open_url(Resource *resource, uint32_t remaining, const QString &newUrl) |
31 | { |
32 | Q_Q(QWaylandQtWindowManager); |
33 | |
34 | QWaylandCompositor *compositor = static_cast<QWaylandCompositor *>(q->extensionContainer()); |
35 | if (!compositor) { |
36 | qWarning() << "Failed to find QWaylandCompositor from QWaylandQtWindowManager::windowmanager_open_url()" ; |
37 | return; |
38 | } |
39 | |
40 | QString url = urls.value(resource, QString()); |
41 | |
42 | url.append(s: newUrl); |
43 | |
44 | if (remaining) |
45 | urls.insert(resource, url); |
46 | else { |
47 | urls.remove(resource); |
48 | q->openUrl(client: QWaylandClient::fromWlClient(compositor, wlClient: resource->client()), url: QUrl(url)); |
49 | } |
50 | } |
51 | |
52 | QWaylandQtWindowManager::QWaylandQtWindowManager() |
53 | : QWaylandCompositorExtensionTemplate<QWaylandQtWindowManager>(*new QWaylandQtWindowManagerPrivate()) |
54 | { |
55 | } |
56 | |
57 | QWaylandQtWindowManager::QWaylandQtWindowManager(QWaylandCompositor *compositor) |
58 | : QWaylandCompositorExtensionTemplate<QWaylandQtWindowManager>(compositor, *new QWaylandQtWindowManagerPrivate()) |
59 | { |
60 | } |
61 | |
62 | bool QWaylandQtWindowManager::showIsFullScreen() const |
63 | { |
64 | Q_D(const QWaylandQtWindowManager); |
65 | return d->showIsFullScreen; |
66 | } |
67 | |
68 | void QWaylandQtWindowManager::setShowIsFullScreen(bool value) |
69 | { |
70 | Q_D(QWaylandQtWindowManager); |
71 | |
72 | if (d->showIsFullScreen == value) |
73 | return; |
74 | |
75 | d->showIsFullScreen = value; |
76 | const auto resMap = d->resourceMap(); |
77 | for (QWaylandQtWindowManagerPrivate::Resource *resource : resMap) { |
78 | d->send_hints(resource->handle, static_cast<int32_t>(d->showIsFullScreen)); |
79 | } |
80 | Q_EMIT showIsFullScreenChanged(); |
81 | } |
82 | |
83 | void QWaylandQtWindowManager::sendQuitMessage(QWaylandClient *client) |
84 | { |
85 | Q_D(QWaylandQtWindowManager); |
86 | QWaylandQtWindowManagerPrivate::Resource *resource = d->resourceMap().value(client->client()); |
87 | |
88 | if (resource) |
89 | d->send_quit(resource->handle); |
90 | } |
91 | |
92 | void QWaylandQtWindowManager::initialize() |
93 | { |
94 | Q_D(QWaylandQtWindowManager); |
95 | |
96 | QWaylandCompositorExtensionTemplate::initialize(); |
97 | QWaylandCompositor *compositor = static_cast<QWaylandCompositor *>(extensionContainer()); |
98 | if (!compositor) { |
99 | qWarning() << "Failed to find QWaylandCompositor when initializing QWaylandQtWindowManager" ; |
100 | return; |
101 | } |
102 | d->init(compositor->display(), 1); |
103 | } |
104 | |
105 | const struct wl_interface *QWaylandQtWindowManager::interface() |
106 | { |
107 | return QWaylandQtWindowManagerPrivate::interface(); |
108 | } |
109 | |
110 | QByteArray QWaylandQtWindowManager::interfaceName() |
111 | { |
112 | return QWaylandQtWindowManagerPrivate::interfaceName(); |
113 | } |
114 | |
115 | QT_END_NAMESPACE |
116 | |
117 | #include "moc_qwaylandqtwindowmanager.cpp" |
118 | |