-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathqwaylandlayershellsurface.cpp
More file actions
216 lines (179 loc) · 7.45 KB
/
Copy pathqwaylandlayershellsurface.cpp
File metadata and controls
216 lines (179 loc) · 7.45 KB
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later
#include "dsglobal.h"
#include "dlayershellwindow.h"
#include "qwaylandlayershellsurface_p.h"
#include <qwayland-wlr-layer-shell-unstable-v1.h>
#include <wayland-wlr-layer-shell-unstable-v1-client-protocol.h>
#include <QLoggingCategory>
#include <QtWaylandClient/private/qwaylandinputdevice_p.h>
#include <QtWaylandClient/private/qwaylandscreen_p.h>
#include <QtWaylandClient/private/qwaylandsurface_p.h>
#include <QtWaylandClient/private/qwaylandwindow_p.h>
#include <private/qwaylandnativeinterface_p.h>
Q_LOGGING_CATEGORY(layershellsurface, "dde.shell.layershell.surface")
DS_BEGIN_NAMESPACE
QWaylandLayerShellSurface::QWaylandLayerShellSurface(QtWayland::zwlr_layer_shell_v1 *shell, QtWaylandClient::QWaylandWindow *window)
: QtWaylandClient::QWaylandShellSurface(window)
, QtWayland::zwlr_layer_surface_v1()
, m_dlayerShellWindow(DLayerShellWindow::get(window->window()))
{
wl_output *output = nullptr;
if (m_dlayerShellWindow->screenConfiguration() == DLayerShellWindow::ScreenFromQWindow) {
auto waylandScreen = dynamic_cast<QtWaylandClient::QWaylandScreen*>(window->window()->screen()->handle());
connect(window->window(), &QWindow::screenChanged, this, [window](){
window->reset();
// make sure window has been cleaned completed
QMetaObject::invokeMethod(
window,
[window]() {
window->reinit();
},
Qt::QueuedConnection);
});
if (!waylandScreen) {
qCWarning(layershellsurface) << "failed to get screen for wayland";
} else {
output = waylandScreen->output();
}
}
m_surface = window->waylandSurface()->object();
init(shell->get_layer_surface(m_surface, output, m_dlayerShellWindow->layer(), m_dlayerShellWindow->scope()));
set_layer(m_dlayerShellWindow->layer());
connect(m_dlayerShellWindow, &DLayerShellWindow::layerChanged, this, [this, window](){
set_layer(m_dlayerShellWindow->layer());
window->waylandSurface()->commit();
});
set_anchor(m_dlayerShellWindow->anchors());
connect(m_dlayerShellWindow, &DLayerShellWindow::anchorsChanged, this,[this, window](){
trySetAnchorsAndSize();
});
set_exclusive_zone(m_dlayerShellWindow->exclusionZone());
connect(m_dlayerShellWindow, &DLayerShellWindow::exclusionZoneChanged, this,[this, window](){
set_exclusive_zone(m_dlayerShellWindow->exclusionZone());
window->waylandSurface()->commit();
});
set_margin(m_dlayerShellWindow->topMargin(), m_dlayerShellWindow->rightMargin(), m_dlayerShellWindow->bottomMargin(), m_dlayerShellWindow->leftMargin());
connect(m_dlayerShellWindow, &DLayerShellWindow::marginsChanged, this, [this](){
set_margin(m_dlayerShellWindow->topMargin(), m_dlayerShellWindow->rightMargin(), m_dlayerShellWindow->bottomMargin(), m_dlayerShellWindow->leftMargin());
});
set_keyboard_interactivity(m_dlayerShellWindow->keyboardInteractivity());
connect(m_dlayerShellWindow, &DLayerShellWindow::keyboardInteractivityChanged, this, [this, window](){
set_keyboard_interactivity(m_dlayerShellWindow->keyboardInteractivity());
window->waylandSurface()->commit();
});
calcAndSetRequestSize(window->surfaceSize());
if (m_requestSize.isValid()) {
set_size(m_requestSize.width(), m_requestSize.height());
}
m_ddeShellSurface.reset(TreeLandDDEShellManager::instance()->getDDEShellSurface(m_surface));
}
QWaylandLayerShellSurface::~QWaylandLayerShellSurface()
{
destroy();
}
void QWaylandLayerShellSurface::zwlr_layer_surface_v1_closed()
{
if (m_dlayerShellWindow->closeOnDismissed()) {
window()->window()->close();
}
}
void QWaylandLayerShellSurface::calcAndSetRequestSize(QSize requestSize)
{
auto anchors = m_dlayerShellWindow->anchors();
const bool horizontallyConstrained = anchors.testFlags({DLayerShellWindow::AnchorLeft, DLayerShellWindow::AnchorRight});
const bool verticallyConstrained = anchors.testFlags({DLayerShellWindow::AnchorTop, DLayerShellWindow::AnchorBottom});
m_requestSize = requestSize;
if (horizontallyConstrained) {
m_requestSize.setWidth(0);
}
if (verticallyConstrained) {
m_requestSize.setHeight(0);
}
}
bool QWaylandLayerShellSurface::anchorsSizeConflict() const
{
auto anchors = m_dlayerShellWindow->anchors();
const bool horizontallyConstrained = anchors.testFlags({DLayerShellWindow::AnchorLeft, DLayerShellWindow::AnchorRight});
const bool verticallyConstrained = anchors.testFlags({DLayerShellWindow::AnchorTop, DLayerShellWindow::AnchorBottom});
return (!horizontallyConstrained && m_requestSize.width() == 0) || (!verticallyConstrained && m_requestSize.height() == 0);
}
void QWaylandLayerShellSurface::trySetAnchorsAndSize()
{
if (!anchorsSizeConflict()) {
set_anchor(m_dlayerShellWindow->anchors());
set_size(m_requestSize.width(), m_requestSize.height());
window()->waylandSurface()->commit();
}
}
void QWaylandLayerShellSurface::zwlr_layer_surface_v1_configure(uint32_t serial, uint32_t width, uint32_t height)
{
ack_configure(serial);
m_pendingSize = QSize(width, height);
if (!m_configured) {
m_configured = true;
window()->resizeFromApplyConfigure(m_pendingSize);
#if QT_VERSION < QT_VERSION_CHECK(6, 7, 0)
window()->handleExpose(QRect(QPoint(), m_pendingSize));
#else
window()->sendRecursiveExposeEvent();
#endif
} else {
window()->applyConfigureWhenPossible();
}
}
void QWaylandLayerShellSurface::applyConfigure()
{
window()->resizeFromApplyConfigure(m_pendingSize);
}
void QWaylandLayerShellSurface::setWindowGeometry(const QRect &geometry)
{
calcAndSetRequestSize(geometry.size());
trySetAnchorsAndSize();
}
void QWaylandLayerShellSurface::attachPopup(QtWaylandClient::QWaylandShellSurface *popup)
{
std::any anyRole = popup->surfaceRole();
if (auto role = std::any_cast<::xdg_popup *>(&anyRole)) {
get_popup(*role);
} else {
qCWarning(layershellsurface) << "Cannot attach popup of unknown type";
}
}
bool QWaylandLayerShellSurface::resize(QtWaylandClient::QWaylandInputDevice *inputDevice, Qt::Edges edges)
{
if (!m_ddeShellSurface) {
m_ddeShellSurface.reset(TreeLandDDEShellManager::instance()->getDDEShellSurface(m_surface));
}
if (TreeLandDDEShellManager::instance()->isActive() && m_ddeShellSurface) {
m_ddeShellSurface->resize(inputDevice->wl_seat(), inputDevice->serial(), 1);
return true;
}
return false;
}
TreeLandDDEShellManager::TreeLandDDEShellManager()
: QWaylandClientExtensionTemplate<TreeLandDDEShellManager>(treeland_dde_shell_manager_v1_interface.version)
{
}
TreeLandDDEShellManager *TreeLandDDEShellManager::instance()
{
static TreeLandDDEShellManager _instance;
return &_instance;
}
DDEShellSurface *TreeLandDDEShellManager::getDDEShellSurface(struct ::wl_surface *surface)
{
if (isActive())
return new DDEShellSurface(this->get_shell_surface(surface));
return nullptr;
}
DDEShellSurface::DDEShellSurface(struct ::treeland_dde_shell_surface_v1 *object)
: QWaylandClientExtensionTemplate<DDEShellSurface>(treeland_dde_shell_surface_v1_interface.version)
, treeland_dde_shell_surface_v1(object)
{
}
DDEShellSurface::~DDEShellSurface()
{
destroy();
}
DS_END_NAMESPACE