Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
qwldatadevice.cpp
Go to the documentation of this file.
1
// Copyright (C) 2017 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
// Qt-Security score:critical reason:network-protocol
4
5
#
include
"qwldatadevice_p.h"
6
7
#
include
"qwldatasource_p.h"
8
#
include
"qwldataoffer_p.h"
9
#
include
"qwaylandsurface_p.h"
10
#
include
"qwldatadevicemanager_p.h"
11
12
#
if
QT_CONFIG
(
draganddrop
)
13
#
include
"qwaylanddrag.h"
14
#
endif
15
#
include
"qwaylandview.h"
16
#
include
<
QtWaylandCompositor
/
QWaylandClient
>
17
#
include
<
QtWaylandCompositor
/
private
/
qwaylandcompositor_p
.
h
>
18
#
include
<
QtWaylandCompositor
/
private
/
qwaylandseat_p
.
h
>
19
#
include
<
QtWaylandCompositor
/
private
/
qwaylandpointer_p
.
h
>
20
21
#
include
<
QtCore
/
QPointF
>
22
#
include
<
QDebug
>
23
24
QT_BEGIN_NAMESPACE
25
26
namespace
QtWayland
{
27
28
DataDevice
::
DataDevice
(QWaylandSeat *seat)
29
:
m_compositor
(
seat
->
compositor
())
30
,
m_seat
(
seat
)
31
{
32
}
33
34
void
DataDevice
::
setFocus
(QWaylandClient *focusClient)
35
{
36
if
(!focusClient)
37
return
;
38
39
Resource *resource = resourceMap().value(focusClient->client());
40
41
if
(!resource)
42
return
;
43
44
if
(m_selectionSource) {
45
DataOffer
*offer =
new
DataOffer
(m_selectionSource, resource);
46
send_selection(resource->handle, offer->resource()->handle);
47
}
48
}
49
50
void
DataDevice
::
sourceDestroyed
(
DataSource
*source)
51
{
52
if
(m_selectionSource == source)
53
m_selectionSource =
nullptr
;
54
55
if
(m_dragDataSource == source)
56
m_dragDataSource =
nullptr
;
57
}
58
59
#
if
QT_CONFIG
(
draganddrop
)
60
void
DataDevice
::
setDragFocus
(
QWaylandSurface
*
focus
,
const
QPointF
&
localPosition
)
61
{
62
if
(
m_dragFocusResource
) {
63
send_leave
(
m_dragFocusResource
->
handle
);
64
m_dragFocus
=
nullptr
;
65
m_dragFocusResource
=
nullptr
;
66
}
67
68
if
(!
focus
)
69
return
;
70
71
if
(!
m_dragDataSource
&&
m_dragClient
!=
focus
->
waylandClient
())
72
return
;
73
74
Resource
*
resource
=
resourceMap
().
value
(
focus
->
waylandClient
());
75
76
if
(!
resource
)
77
return
;
78
79
uint32_t
serial
=
m_compositor
->
nextSerial
();
80
81
DataOffer
*
offer
=
m_dragDataSource
?
new
DataOffer
(
m_dragDataSource
,
resource
) :
nullptr
;
82
83
if
(
m_dragDataSource
&& !
offer
)
84
return
;
85
86
if
(
offer
) {
87
send_enter
(
resource
->
handle
,
serial
,
focus
->
resource
(),
88
wl_fixed_from_double
(
localPosition
.
x
()),
wl_fixed_from_double
(
localPosition
.
y
()),
89
offer
->
resource
()->
handle
);
90
}
91
92
m_dragFocus
=
focus
;
93
m_dragFocusResource
=
resource
;
94
}
95
96
QWaylandSurface
*
DataDevice
::
dragIcon
()
const
97
{
98
return
m_dragIcon
;
99
}
100
101
QWaylandSurface
*
DataDevice
::
dragOrigin
()
const
102
{
103
return
m_dragOrigin
;
104
}
105
106
void
DataDevice
::
dragMove
(
QWaylandSurface
*
target
,
const
QPointF
&
pos
)
107
{
108
if
(
target
!=
m_dragFocus
)
109
setDragFocus
(
target
,
pos
);
110
if
(!
target
|| !
m_dragFocusResource
)
111
return
;
112
uint
time
=
m_compositor
->
currentTimeMsecs
();
//### should be serial
113
send_motion
(
m_dragFocusResource
->
handle
,
time
,
114
wl_fixed_from_double
(
pos
.
x
()),
wl_fixed_from_double
(
pos
.
y
()));
115
}
116
117
void
DataDevice
::
drop
()
118
{
119
if
(
m_dragFocusResource
) {
120
send_drop
(
m_dragFocusResource
->
handle
);
121
setDragFocus
(
nullptr
,
QPoint
());
122
}
else
if
(
m_dragDataSource
) {
123
m_dragDataSource
->
cancel
();
124
}
125
m_dragOrigin
=
nullptr
;
126
setDragIcon
(
nullptr
);
127
}
128
129
void
DataDevice
::
cancelDrag
()
130
{
131
setDragFocus
(
nullptr
,
QPoint
());
132
}
133
134
void
DataDevice
::
data_device_start_drag
(
Resource
*
resource
,
struct
::
wl_resource
*
source
,
struct
::
wl_resource
*
origin
,
struct
::
wl_resource
*
icon
,
uint32_t
serial
)
135
{
136
m_dragClient
=
resource
->
client
();
137
m_dragDataSource
=
source
?
DataSource
::
fromResource
(
source
) :
nullptr
;
138
if
(
m_dragDataSource
)
139
m_dragDataSource
->
setDevice
(
this
);
140
m_dragOrigin
=
QWaylandSurface
::
fromResource
(
origin
);
141
QWaylandDrag
*
drag
=
m_seat
->
drag
();
142
setDragIcon
(
icon
?
QWaylandSurface
::
fromResource
(
icon
) :
nullptr
);
143
Q_EMIT
drag
->
dragStarted
();
144
Q_EMIT
m_dragOrigin
->
dragStarted
(
drag
);
145
146
Q_UNUSED
(
serial
);
147
//### need to verify that we have an implicit grab with this serial
148
}
149
150
void
DataDevice
::
data_device_destroy_resource
(
Resource
*
resource
)
151
{
152
if
(
m_dragFocusResource
==
resource
) {
153
m_dragFocusResource
=
nullptr
;
154
m_dragFocus
=
nullptr
;
155
}
156
}
157
158
void
DataDevice
::
setDragIcon
(
QWaylandSurface
*
icon
)
159
{
160
if
(
icon
==
m_dragIcon
)
161
return
;
162
m_dragIcon
=
icon
;
163
Q_EMIT
m_seat
->
drag
()->
iconChanged
();
164
}
165
#
endif
// QT_CONFIG(draganddrop)
166
167
void
DataDevice
::data_device_set_selection(Resource *,
struct
::wl_resource *source, uint32_t serial)
168
{
169
Q_UNUSED(serial);
170
171
DataSource
*dataSource = source ? DataSource::fromResource(source) :
nullptr
;
172
173
if
(m_selectionSource)
174
m_selectionSource
->
cancel
(
)
;
175
176
m_selectionSource = dataSource;
177
QWaylandCompositorPrivate::get(m_compositor)->dataDeviceManager()->setCurrentSelectionSource(m_selectionSource);
178
if
(m_selectionSource)
179
m_selectionSource
->
setDevice
(
this
)
;
180
181
QWaylandClient *focusClient = m_seat->keyboard()->focusClient();
182
Resource *resource = focusClient ? resourceMap().value(focusClient->client()) : 0;
183
184
if
(resource && m_selectionSource) {
185
DataOffer
*offer =
new
DataOffer
(m_selectionSource, resource);
186
send_selection(resource->handle, offer->resource()->handle);
187
}
else
if
(resource) {
188
send_selection(resource->handle,
nullptr
);
189
}
190
}
191
192
193
}
194
195
QT_END_NAMESPACE
QtWayland::DataDevice
Definition
qwldatadevice_p.h:35
QtWayland::DataDevice::DataDevice
DataDevice(QWaylandSeat *seat)
Definition
qwldatadevice.cpp:28
QtWayland::DataDevice::sourceDestroyed
void sourceDestroyed(DataSource *source)
Definition
qwldatadevice.cpp:50
QtWayland::DataDevice::setFocus
void setFocus(QWaylandClient *client)
Definition
qwldatadevice.cpp:34
QtWayland::DataOffer
Definition
qwldataoffer_p.h:33
QtWayland::DataSource
Definition
qwldatasource_p.h:35
QtWayland::DataSource::cancel
void cancel()
Definition
qwldatasource.cpp:53
QtWayland::DataSource::setDevice
void setDevice(DataDevice *device)
Definition
qwldatasource.cpp:63
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
QtWayland
Definition
qwaylanddisplay_p.h:54
qtwayland
src
compositor
wayland_wrapper
qwldatadevice.cpp
Generated on
for Qt by
1.18.0