Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwaylandprimaryselectionv1.cpp
Go to the documentation of this file.
1
// Copyright (C) 2019 The Qt Company Ltd.
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
"qwaylandprimaryselectionv1_p.h"
6
#
include
"qwaylandinputdevice_p.h"
7
#
include
"qwaylanddisplay_p.h"
8
#
include
"qwaylandmimehelper_p.h"
9
#
include
"qwaylandpipewritehelper_p.h"
10
11
#
include
<
QtGui
/
private
/
qguiapplication_p
.
h
>
12
13
#
include
<
qpa
/
qplatformclipboard
.
h
>
14
15
#
include
<
unistd
.
h
>
16
17
QT_BEGIN_NAMESPACE
18
using
namespace
std::chrono;
19
20
namespace
QtWaylandClient
{
21
22
QWaylandPrimarySelectionDeviceManagerV1
::QWaylandPrimarySelectionDeviceManagerV1(QWaylandDisplay *display, uint id, uint version)
23
: zwp_primary_selection_device_manager_v1(display->wl_registry(), id, qMin(version, uint(1)))
24
, m_display(display)
25
{
26
}
27
28
QWaylandPrimarySelectionDeviceManagerV1
::~
QWaylandPrimarySelectionDeviceManagerV1
()
29
{
30
destroy();
31
}
32
33
QWaylandPrimarySelectionDeviceV1
*
QWaylandPrimarySelectionDeviceManagerV1
::
createDevice
(QWaylandInputDevice *seat)
34
{
35
return
new
QWaylandPrimarySelectionDeviceV1(
this
, seat);
36
}
37
38
QWaylandPrimarySelectionOfferV1
::QWaylandPrimarySelectionOfferV1(QWaylandDisplay *display, ::zwp_primary_selection_offer_v1 *offer)
39
: zwp_primary_selection_offer_v1(offer)
40
, m_display(display)
41
, m_mimeData(
new
QWaylandMimeData(
this
))
42
{}
43
44
void
QWaylandPrimarySelectionOfferV1
::
startReceiving
(
const
QString &mimeType,
int
fd)
45
{
46
receive(mimeType, fd);
47
wl_display_flush(m_display->wl_display());
48
}
49
50
void
QWaylandPrimarySelectionOfferV1
::
zwp_primary_selection_offer_v1_offer
(
const
QString &mime_type)
51
{
52
m_mimeData->appendFormat(mime_type);
53
}
54
55
QWaylandPrimarySelectionDeviceV1
::QWaylandPrimarySelectionDeviceV1(
56
QWaylandPrimarySelectionDeviceManagerV1
*manager, QWaylandInputDevice *seat)
57
: QtWayland::zwp_primary_selection_device_v1(manager->get_device(seat->wl_seat()))
58
, m_display(manager->display())
59
, m_seat(seat)
60
{
61
}
62
63
QWaylandPrimarySelectionDeviceV1
::~
QWaylandPrimarySelectionDeviceV1
()
64
{
65
destroy();
66
}
67
68
void
QWaylandPrimarySelectionDeviceV1
::
invalidateSelectionOffer
()
69
{
70
if
(!m_selectionOffer)
71
return
;
72
73
m_selectionOffer.reset();
74
QGuiApplicationPrivate::platformIntegration()->clipboard()->emitChanged(QClipboard::Selection);
75
}
76
77
void
QWaylandPrimarySelectionDeviceV1
::setSelectionSource(
QWaylandPrimarySelectionSourceV1
*
source
)
78
{
79
if
(
source
) {
80
connect
(
source
, &
QWaylandPrimarySelectionSourceV1
::
cancelled
,
this
, [
this
]() {
81
m_selectionSource
.
reset
();
82
QGuiApplicationPrivate
::
platformIntegration
()->
clipboard
()->
emitChanged
(
QClipboard
::
Selection
);
83
});
84
}
85
set_selection
(
source
?
source
->
object
() :
nullptr
,
m_seat
->
serial
());
86
m_selectionSource
.
reset
(
source
);
87
}
88
89
void
QWaylandPrimarySelectionDeviceV1
::zwp_primary_selection_device_v1_data_offer(zwp_primary_selection_offer_v1 *offer)
90
{
91
new
QWaylandPrimarySelectionOfferV1(m_display, offer);
92
}
93
94
void
QWaylandPrimarySelectionDeviceV1
::zwp_primary_selection_device_v1_selection(zwp_primary_selection_offer_v1 *id)
95
{
96
97
if
(id)
98
m_selectionOffer.reset(
static_cast
<QWaylandPrimarySelectionOfferV1 *>(zwp_primary_selection_offer_v1_get_user_data(id)));
99
else
100
m_selectionOffer.reset();
101
102
QGuiApplicationPrivate::platformIntegration()->clipboard()->emitChanged(QClipboard::Selection);
103
}
104
105
QWaylandPrimarySelectionSourceV1
::
QWaylandPrimarySelectionSourceV1
(
QWaylandPrimarySelectionDeviceManagerV1
*
manager
,
QMimeData
*
mimeData
)
106
:
QtWayland
::
zwp_primary_selection_source_v1
(
manager
->
create_source
())
107
,
m_mimeData
(
mimeData
)
108
{
109
if
(!
mimeData
)
110
return
;
111
for
(
auto
&
format
:
mimeData
->
formats
())
112
offer
(
format
);
113
}
114
115
QWaylandPrimarySelectionSourceV1
::~
QWaylandPrimarySelectionSourceV1
()
116
{
117
destroy
();
118
}
119
120
void
QWaylandPrimarySelectionSourceV1
::
zwp_primary_selection_source_v1_send
(
const
QString
&
mime_type
,
int32_t
fd
)
121
{
122
QByteArray
content
=
QWaylandMimeHelper
::
getByteArray
(
m_mimeData
,
mime_type
);
123
if
(!
content
.
isEmpty
()) {
124
switch
(
QWaylandPipeWriteHelper
::
safeWriteWithTimeout
(
fd
,
content
.
constData
(),
content
.
size
(),
PIPE_BUF
, 5s)) {
125
case
QWaylandPipeWriteHelper
::
SafeWriteResult
::
Ok
:
126
break
;
127
case
QWaylandPipeWriteHelper
::
SafeWriteResult
::
Timeout
:
128
qWarning
() <<
"QWaylandPrimarySelectionSourceV1: timeout writing to pipe"
;
129
break
;
130
case
QWaylandPipeWriteHelper
::
SafeWriteResult
::
Closed
:
131
qWarning
() <<
"QWaylandPrimarySelectionSourceV1: peer closed pipe"
;
132
break
;
133
case
QWaylandPipeWriteHelper
::
SafeWriteResult
::
Error
:
134
qWarning
() <<
"QWaylandPrimarySelectionSourceV1: write() failed"
;
135
break
;
136
}
137
}
138
close
(
fd
);
139
}
140
141
}
// namespace QtWaylandClient
142
143
QT_END_NAMESPACE
144
145
#
include
"moc_qwaylandprimaryselectionv1_p.cpp"
QtWaylandClient::QWaylandPrimarySelectionDeviceManagerV1
Definition
qwaylandprimaryselectionv1_p.h:38
QtWaylandClient::QWaylandPrimarySelectionDeviceManagerV1::~QWaylandPrimarySelectionDeviceManagerV1
~QWaylandPrimarySelectionDeviceManagerV1()
Definition
qwaylandprimaryselectionv1.cpp:28
QtWaylandClient::QWaylandPrimarySelectionDeviceManagerV1::createDevice
QWaylandPrimarySelectionDeviceV1 * createDevice(QWaylandInputDevice *seat)
Definition
qwaylandprimaryselectionv1.cpp:33
QtWaylandClient::QWaylandPrimarySelectionDeviceV1
Definition
qwaylandprimaryselectionv1_p.h:86
QtWaylandClient::QWaylandPrimarySelectionDeviceV1::invalidateSelectionOffer
void invalidateSelectionOffer()
Definition
qwaylandprimaryselectionv1.cpp:68
QtWaylandClient::QWaylandPrimarySelectionDeviceV1::~QWaylandPrimarySelectionDeviceV1
~QWaylandPrimarySelectionDeviceV1() override
Definition
qwaylandprimaryselectionv1.cpp:63
QtWaylandClient::QWaylandPrimarySelectionOfferV1
Definition
qwaylandprimaryselectionv1_p.h:50
QtWaylandClient::QWaylandPrimarySelectionOfferV1::startReceiving
void startReceiving(const QString &mimeType, int fd) override
Definition
qwaylandprimaryselectionv1.cpp:44
QtWaylandClient::QWaylandPrimarySelectionOfferV1::zwp_primary_selection_offer_v1_offer
void zwp_primary_selection_offer_v1_offer(const QString &mime_type) override
Definition
qwaylandprimaryselectionv1.cpp:50
QtWaylandClient
Definition
qwaylandclientextension.h:16
qtbase
src
plugins
platforms
wayland
qwaylandprimaryselectionv1.cpp
Generated on
for Qt by
1.16.1