1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qwaylandnativeinterface_p.h"
#include "qwaylanddisplay_p.h"
#include "qwaylandwindow_p.h"
#include "qwaylandshellintegration_p.h"
#include "qwaylandsubsurface_p.h"
#include "qwaylandextendedsurface_p.h"
#include "qwaylandintegration_p.h"
#include "qwaylanddisplay_p.h"
#include "qwaylandwindowmanagerintegration_p.h"
#include "qwaylandscreen_p.h"
#include "qwaylandinputdevice_p.h"
#include <QtGui/private/qguiapplication_p.h>
#include <QtGui/QScreen>
#include <QtWaylandClient/private/qwaylandclientbufferintegration_p.h>
#if QT_CONFIG(vulkan)
#include <QtWaylandClient/private/qwaylandvulkanwindow_p.h>
#endif
QT_BEGIN_NAMESPACE
namespace QtWaylandClient {
QWaylandNativeInterface::QWaylandNativeInterface(QWaylandIntegration *integration)
: m_integration(integration)
{
}
void *QWaylandNativeInterface::nativeResourceForIntegration(const QByteArray &resourceString)
{
QByteArray lowerCaseResource = resourceString.toLower();
if (lowerCaseResource == "display" || lowerCaseResource == "wl_display" || lowerCaseResource == "nativedisplay")
return m_integration->display()->wl_display();
if (lowerCaseResource == "compositor")
return const_cast<wl_compositor *>(m_integration->display()->wl_compositor());
if (lowerCaseResource == "server_buffer_integration")
return m_integration->serverBufferIntegration();
if (lowerCaseResource == "egldisplay" && m_integration->clientBufferIntegration())
return m_integration->clientBufferIntegration()->nativeResource(QWaylandClientBufferIntegration::EglDisplay);
if (lowerCaseResource == "wl_seat")
return m_integration->display()->defaultInputDevice()->wl_seat();
if (lowerCaseResource == "wl_keyboard") {
auto *keyboard = m_integration->display()->defaultInputDevice()->keyboard();
if (keyboard)
return keyboard->wl_keyboard();
return nullptr;
}
if (lowerCaseResource == "wl_pointer") {
auto *pointer = m_integration->display()->defaultInputDevice()->pointer();
if (pointer)
return pointer->wl_pointer();
return nullptr;
}
if (lowerCaseResource == "wl_touch") {
auto *touch = m_integration->display()->defaultInputDevice()->touch();
if (touch)
return touch->wl_touch();
return nullptr;
}
if (lowerCaseResource == "serial")
return reinterpret_cast<void *>(quintptr(m_integration->display()->defaultInputDevice()->serial()));
return nullptr;
}
void *QWaylandNativeInterface::nativeResourceForWindow(const QByteArray &resourceString, QWindow *window)
{
QByteArray lowerCaseResource = resourceString.toLower();
if (lowerCaseResource == "display")
return m_integration->display()->wl_display();
if (lowerCaseResource == "compositor")
return const_cast<wl_compositor *>(m_integration->display()->wl_compositor());
if (lowerCaseResource == "surface") {
QWaylandWindow *w = static_cast<QWaylandWindow*>(window->handle());
return w ? w->wlSurface() : nullptr;
}
if (lowerCaseResource == "egldisplay" && m_integration->clientBufferIntegration())
return m_integration->clientBufferIntegration()->nativeResource(QWaylandClientBufferIntegration::EglDisplay);
#if QT_CONFIG(vulkan)
if (lowerCaseResource == "vksurface") {
if (window->surfaceType() == QSurface::VulkanSurface && window->handle()) {
// return a pointer to the VkSurfaceKHR value, not the value itself
return static_cast<QWaylandVulkanWindow *>(window->handle())->surface();
}
}
#endif
if (auto shellIntegration = m_integration->shellIntegration())
return shellIntegration->nativeResourceForWindow(resourceString, window);
return nullptr;
}
void *QWaylandNativeInterface::nativeResourceForScreen(const QByteArray &resourceString, QScreen *screen)
{
QByteArray lowerCaseResource = resourceString.toLower();
if (lowerCaseResource == "output")
return ((QWaylandScreen *) screen->handle())->output();
return nullptr;
}
#if QT_CONFIG(opengl)
void *QWaylandNativeInterface::nativeResourceForContext(const QByteArray &resource, QOpenGLContext *context)
{
#if QT_CONFIG(opengl)
QByteArray lowerCaseResource = resource.toLower();
if (lowerCaseResource == "eglconfig" && m_integration->clientBufferIntegration())
return m_integration->clientBufferIntegration()->nativeResourceForContext(QWaylandClientBufferIntegration::EglConfig, context->handle());
if (lowerCaseResource == "eglcontext" && m_integration->clientBufferIntegration())
return m_integration->clientBufferIntegration()->nativeResourceForContext(QWaylandClientBufferIntegration::EglContext, context->handle());
if (lowerCaseResource == "egldisplay" && m_integration->clientBufferIntegration())
return m_integration->clientBufferIntegration()->nativeResourceForContext(QWaylandClientBufferIntegration::EglDisplay, context->handle());
#endif
return nullptr;
}
#endif // opengl
QPlatformNativeInterface::NativeResourceForWindowFunction QWaylandNativeInterface::nativeResourceFunctionForWindow(const QByteArray &resource)
{
QByteArray lowerCaseResource = resource.toLower();
if (lowerCaseResource == "setmargins") {
return NativeResourceForWindowFunction(reinterpret_cast<void *>(setWindowMargins));
}
return nullptr;
}
QVariantMap QWaylandNativeInterface::windowProperties(QPlatformWindow *window) const
{
QWaylandWindow *waylandWindow = static_cast<QWaylandWindow *>(window);
return waylandWindow->properties();
}
QVariant QWaylandNativeInterface::windowProperty(QPlatformWindow *window, const QString &name) const
{
QWaylandWindow *waylandWindow = static_cast<QWaylandWindow *>(window);
return waylandWindow->property(name);
}
QVariant QWaylandNativeInterface::windowProperty(QPlatformWindow *window, const QString &name, const QVariant &defaultValue) const
{
QWaylandWindow *waylandWindow = static_cast<QWaylandWindow *>(window);
return waylandWindow->property(name, defaultValue);
}
void QWaylandNativeInterface::setWindowProperty(QPlatformWindow *window, const QString &name, const QVariant &value)
{
QWaylandWindow *wlWindow = static_cast<QWaylandWindow*>(window);
wlWindow->sendProperty(name, value);
}
void QWaylandNativeInterface::emitWindowPropertyChanged(QPlatformWindow *window, const QString &name)
{
emit windowPropertyChanged(window,name);
}
void QWaylandNativeInterface::setWindowMargins(QWindow *window, const QMargins &margins)
{
QWaylandWindow *wlWindow = static_cast<QWaylandWindow*>(window->handle());
wlWindow->setCustomMargins(margins);
}
}
QT_END_NAMESPACE
|