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
qwaylanddatacontrolv1.cpp
Go to the documentation of this file.
1
// Copyright (C) 2024 Jie Liu <liujie01@kylinos.cn>
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
include
"qwaylanddatacontrolv1_p.h"
6
#
include
"qwaylandinputdevice_p.h"
7
#
include
"qwaylanddisplay_p.h"
8
#
include
"qwaylandmimehelper_p.h"
9
10
#
include
<
QtGui
/
private
/
qguiapplication_p
.
h
>
11
12
#
include
<
qpa
/
qplatformclipboard
.
h
>
13
14
#
include
<
signal
.
h
>
15
#
include
<
unistd
.
h
>
16
17
QT_BEGIN_NAMESPACE
18
19
namespace
QtWaylandClient
{
20
21
QWaylandDataControlManagerV1
::
QWaylandDataControlManagerV1
(QWaylandDisplay *display, uint id, uint version)
22
:
zwlr_data_control_manager_v1
(
display
->
wl_registry
(),
id
,
qMin
(
version
,
uint
(2)))
23
,
m_display
(
display
)
24
{
25
}
26
27
QWaylandDataControlDeviceV1
*
QWaylandDataControlManagerV1
::
createDevice
(QWaylandInputDevice *seat)
28
{
29
return
new
QWaylandDataControlDeviceV1(
this
, seat);
30
}
31
32
QWaylandDataControlOfferV1
::
QWaylandDataControlOfferV1
(QWaylandDisplay *display, ::zwlr_data_control_offer_v1 *offer)
33
:
zwlr_data_control_offer_v1
(
offer
)
34
,
m_display
(
display
)
35
,
m_mimeData
(
new
QWaylandMimeData
(
this
))
36
{}
37
38
void
QWaylandDataControlOfferV1
::
startReceiving
(
const
QString &mimeType,
int
fd)
39
{
40
receive(mimeType, fd);
41
wl_display_flush(m_display->wl_display());
42
}
43
44
void
QWaylandDataControlOfferV1
::
zwlr_data_control_offer_v1_offer
(
const
QString &mime_type)
45
{
46
m_mimeData->appendFormat(mime_type);
47
}
48
49
QWaylandDataControlDeviceV1
::QWaylandDataControlDeviceV1(
50
QWaylandDataControlManagerV1
*manager, QWaylandInputDevice *seat)
51
: QtWayland::zwlr_data_control_device_v1(manager->get_data_device(seat->wl_seat()))
52
, m_display(manager->display())
53
, m_seat(seat)
54
{
55
}
56
57
QWaylandDataControlDeviceV1
::~
QWaylandDataControlDeviceV1
()
58
{
59
destroy();
60
}
61
62
void
QWaylandDataControlDeviceV1
::
invalidateSelectionOffer
()
63
{
64
if
(!m_selectionOffer)
65
return
;
66
67
m_selectionOffer.reset();
68
QGuiApplicationPrivate::platformIntegration()->clipboard()->emitChanged(QClipboard::Clipboard);
69
}
70
71
void
QWaylandDataControlDeviceV1
::setSelectionSource(
QWaylandDataControlSourceV1
*
source
)
72
{
73
if
(
source
) {
74
connect
(
source
, &
QWaylandDataControlSourceV1
::
cancelled
,
this
, [
this
]() {
75
m_selectionSource
.
reset
();
76
QGuiApplicationPrivate
::
platformIntegration
()->
clipboard
()->
emitChanged
(
QClipboard
::
Clipboard
);
77
});
78
}
79
set_selection
(
source
?
source
->
object
() :
nullptr
);
80
m_selectionSource
.
reset
(
source
);
81
}
82
83
void
QWaylandDataControlDeviceV1
::setPrimarySelectionSource(
QWaylandDataControlSourceV1
*
source
)
84
{
85
if
(
source
) {
86
connect
(
source
, &
QWaylandDataControlSourceV1
::
cancelled
,
this
, [
this
]() {
87
m_primarySelectionSource
.
reset
();
88
QGuiApplicationPrivate
::
platformIntegration
()->
clipboard
()->
emitChanged
(
QClipboard
::
Selection
);
89
});
90
}
91
set_primary_selection
(
source
?
source
->
object
() :
nullptr
);
92
m_primarySelectionSource
.
reset
(
source
);
93
}
94
95
void
QWaylandDataControlDeviceV1
::zwlr_data_control_device_v1_data_offer(zwlr_data_control_offer_v1 *offer)
96
{
97
new
QWaylandDataControlOfferV1(m_display, offer);
98
}
99
100
void
QWaylandDataControlDeviceV1
::zwlr_data_control_device_v1_selection(zwlr_data_control_offer_v1 *id)
101
{
102
if
(!id)
103
m_selectionOffer.reset();
104
else
105
m_selectionOffer.reset(
static_cast
<QWaylandDataControlOfferV1 *>(zwlr_data_control_offer_v1_get_user_data(id)));
106
107
// The selection event may be sent before platfrmIntegration is set.
108
if
(
auto
* integration = QGuiApplicationPrivate::platformIntegration())
109
integration->clipboard()->emitChanged(QClipboard::Clipboard);
110
}
111
112
void
QWaylandDataControlDeviceV1
::
zwlr_data_control_device_v1_finished
()
113
{
114
m_selectionOffer.reset();
115
m_primarySelectionOffer.reset();
116
QGuiApplicationPrivate::platformIntegration()->clipboard()->emitChanged(QClipboard::Clipboard);
117
}
118
119
void
QWaylandDataControlDeviceV1
::zwlr_data_control_device_v1_primary_selection(
struct
::zwlr_data_control_offer_v1 *id)
120
{
121
if
(!id)
122
m_primarySelectionOffer.reset();
123
else
124
m_primarySelectionOffer.reset(
static_cast
<QWaylandDataControlOfferV1 *>(zwlr_data_control_offer_v1_get_user_data(id)));
125
126
// The selection event may be sent before platfrmIntegration is set.
127
if
(
auto
* integration = QGuiApplicationPrivate::platformIntegration())
128
integration->clipboard()->emitChanged(QClipboard::Selection);
129
}
130
131
QWaylandDataControlSourceV1
::
QWaylandDataControlSourceV1
(
QWaylandDataControlManagerV1
*
manager
,
QMimeData
*
mimeData
)
132
:
QtWayland
::
zwlr_data_control_source_v1
(
manager
->
create_data_source
())
133
,
m_mimeData
(
mimeData
)
134
{
135
if
(!
mimeData
)
136
return
;
137
const
auto
formats
=
QInternalMimeData
::
formatsHelper
(
mimeData
);
138
for
(
const
QString
&
format
:
formats
)
139
offer
(
format
);
140
}
141
142
QWaylandDataControlSourceV1
::~
QWaylandDataControlSourceV1
()
143
{
144
destroy
();
145
}
146
147
void
QWaylandDataControlSourceV1
::
zwlr_data_control_source_v1_send
(
const
QString
&
mime_type
,
int32_t
fd
)
148
{
149
QByteArray
content
=
QWaylandMimeHelper
::
getByteArray
(
m_mimeData
,
mime_type
);
150
if
(!
content
.
isEmpty
()) {
151
// Create a sigpipe handler that does nothing, or clients may be forced to terminate
152
// if the pipe is closed in the other end.
153
struct
sigaction
action
= {};
154
struct
sigaction
oldAction
= {};
155
action
.sa_handler = SIG_IGN;
156
sigemptyset
(&
action
.
sa_mask
);
157
action
.
sa_flags
= 0;
158
159
sigaction
(SIGPIPE, &
action
, &
oldAction
);
160
ssize_t
unused
=
write
(
fd
,
content
.
constData
(),
size_t
(
content
.
size
()));
161
Q_UNUSED
(
unused
);
162
sigaction
(SIGPIPE, &
oldAction
,
nullptr
);
163
}
164
close
(
fd
);
165
}
166
167
}
// namespace QtWaylandClient
168
169
QT_END_NAMESPACE
QtWaylandClient::QWaylandDataControlDeviceV1
Definition
qwaylanddatacontrolv1_p.h:88
QtWaylandClient::QWaylandDataControlDeviceV1::invalidateSelectionOffer
void invalidateSelectionOffer()
Definition
qwaylanddatacontrolv1.cpp:62
QtWaylandClient::QWaylandDataControlDeviceV1::~QWaylandDataControlDeviceV1
~QWaylandDataControlDeviceV1() override
Definition
qwaylanddatacontrolv1.cpp:57
QtWaylandClient::QWaylandDataControlDeviceV1::zwlr_data_control_device_v1_finished
void zwlr_data_control_device_v1_finished() override
Definition
qwaylanddatacontrolv1.cpp:112
QtWaylandClient::QWaylandDataControlManagerV1
Definition
qwaylanddatacontrolv1_p.h:40
QtWaylandClient::QWaylandDataControlManagerV1::QWaylandDataControlManagerV1
QWaylandDataControlManagerV1(QWaylandDisplay *display, uint id, uint version)
Definition
qwaylanddatacontrolv1.cpp:21
QtWaylandClient::QWaylandDataControlManagerV1::createDevice
QWaylandDataControlDeviceV1 * createDevice(QWaylandInputDevice *seat)
Definition
qwaylanddatacontrolv1.cpp:27
QtWaylandClient::QWaylandDataControlOfferV1
Definition
qwaylanddatacontrolv1_p.h:51
QtWaylandClient::QWaylandDataControlOfferV1::QWaylandDataControlOfferV1
QWaylandDataControlOfferV1(QWaylandDisplay *display, ::zwlr_data_control_offer_v1 *offer)
Definition
qwaylanddatacontrolv1.cpp:32
QtWaylandClient::QWaylandDataControlOfferV1::startReceiving
void startReceiving(const QString &mimeType, int fd) override
Definition
qwaylanddatacontrolv1.cpp:38
QtWaylandClient::QWaylandDataControlOfferV1::zwlr_data_control_offer_v1_offer
void zwlr_data_control_offer_v1_offer(const QString &mime_type) override
Definition
qwaylanddatacontrolv1.cpp:44
QtWaylandClient
Definition
qwaylandclientextension.h:16
qtbase
src
plugins
platforms
wayland
qwaylanddatacontrolv1.cpp
Generated on
for Qt by
1.18.0