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
qwaylandclipboard.cpp
Go to the documentation of this file.
1
// Copyright (C) 2016 The Qt Company Ltd.
2
// Copyright (C) 2024 Jie Liu <liujie01@kylinos.cn>
3
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
// Qt-Security score:significant reason:default
5
6
#
include
"qwaylandclipboard_p.h"
7
#
include
"qwaylanddisplay_p.h"
8
#
include
"qwaylandinputdevice_p.h"
9
#
include
"qwaylanddatacontrolv1_p.h"
10
#
include
"qwaylanddataoffer_p.h"
11
#
include
"qwaylanddatasource_p.h"
12
#
include
"qwaylanddatadevice_p.h"
13
#
if
QT_CONFIG
(
wayland_client_primary_selection
)
14
#
include
"qwaylandprimaryselectionv1_p.h"
15
#
endif
16
17
QT_BEGIN_NAMESPACE
18
19
namespace
QtWaylandClient
{
20
21
QWaylandClipboard
::
QWaylandClipboard
(
QWaylandDisplay
*
display
)
22
:
mDisplay
(
display
)
23
{
24
m_clientClipboard
[
QClipboard
::
Clipboard
] =
nullptr
;
25
m_clientClipboard
[
QClipboard
::
Selection
] =
nullptr
;
26
}
27
28
QWaylandClipboard
::~
QWaylandClipboard
()
29
{
30
if
(
m_clientClipboard
[
QClipboard
::
Clipboard
] !=
m_clientClipboard
[
QClipboard
::
Selection
])
31
delete
m_clientClipboard
[
QClipboard
::
Clipboard
];
32
delete
m_clientClipboard
[
QClipboard
::
Selection
];
33
}
34
35
QMimeData
*
QWaylandClipboard
::
mimeData
(
QClipboard
::
Mode
mode
)
36
{
37
auto
*
seat
=
mDisplay
->
currentInputDevice
();
38
if
(!
seat
)
39
return
&
m_emptyData
;
40
41
switch
(
mode
) {
42
case
QClipboard
::
Clipboard
:
43
if
(
auto
*
dataControlDevice
=
seat
->
dataControlDevice
()) {
44
if
(
dataControlDevice
->
selectionSource
())
45
return
m_clientClipboard
[
QClipboard
::
Clipboard
];
46
if
(
auto
*
offer
=
dataControlDevice
->
selectionOffer
())
47
return
offer
->
mimeData
();
48
}
49
if
(
auto
*
dataDevice
=
seat
->
dataDevice
()) {
50
if
(
dataDevice
->
selectionSource
())
51
return
m_clientClipboard
[
QClipboard
::
Clipboard
];
52
if
(
auto
*
offer
=
dataDevice
->
selectionOffer
())
53
return
offer
->
mimeData
();
54
}
55
return
&
m_emptyData
;
56
case
QClipboard
::
Selection
:
57
if
(
auto
*
dataControlDevice
=
seat
->
dataControlDevice
()) {
58
if
(
dataControlDevice
->
primarySelectionSource
())
59
return
m_clientClipboard
[
QClipboard
::
Selection
];
60
if
(
auto
*
offer
=
dataControlDevice
->
primarySelectionOffer
())
61
return
offer
->
mimeData
();
62
}
63
#
if
QT_CONFIG
(
wayland_client_primary_selection
)
64
if
(
auto
*
selectionDevice
=
seat
->
primarySelectionDevice
()) {
65
if
(
selectionDevice
->
selectionSource
())
66
return
m_clientClipboard
[
QClipboard
::
Selection
];
67
if
(
auto
*
offer
=
selectionDevice
->
selectionOffer
())
68
return
offer
->
mimeData
();
69
}
70
#
endif
71
return
&
m_emptyData
;
72
default
:
73
return
&
m_emptyData
;
74
}
75
}
76
77
void
QWaylandClipboard
::
setMimeData
(
QMimeData
*
data
,
QClipboard
::
Mode
mode
)
78
{
79
auto
*
seat
=
mDisplay
->
currentInputDevice
();
80
if
(!
seat
) {
81
qCWarning
(
lcQpaWayland
) <<
"Can't set clipboard contents with no wl_seats available"
;
82
return
;
83
}
84
85
if
(
data
&&
m_clientClipboard
[
mode
] ==
data
)
// Already set before?
86
return
;
87
88
static
const
QString
plain
=
QStringLiteral
(
"text/plain"
);
89
static
const
QString
utf8
=
QStringLiteral
(
"text/plain;charset=utf-8"
);
90
91
if
(
data
&&
data
->
hasFormat
(
plain
) && !
data
->
hasFormat
(
utf8
))
92
data
->
setData
(
utf8
,
data
->
data
(
plain
));
93
94
auto
oldMimeData
=
std
::
exchange
(
m_clientClipboard
[
mode
],
data
);
95
const
auto
otherMode
=
mode
==
QClipboard
::
Clipboard
?
QClipboard
::
Selection
96
:
QClipboard
::
Clipboard
;
97
if
(
oldMimeData
!=
m_clientClipboard
[
otherMode
])
98
delete
oldMimeData
;
99
100
switch
(
mode
) {
101
case
QClipboard
::
Clipboard
:
102
if
(
auto
*
dataControlDevice
=
seat
->
dataControlDevice
()) {
103
dataControlDevice
->
setSelectionSource
(
data
?
new
QWaylandDataControlSourceV1
(
mDisplay
->
dataControlManager
(),
104
m_clientClipboard
[
QClipboard
::
Clipboard
]) :
nullptr
);
105
emitChanged
(
mode
);
106
}
else
if
(
auto
*
dataDevice
=
seat
->
dataDevice
()) {
107
dataDevice
->
setSelectionSource
(
data
?
new
QWaylandDataSource
(
mDisplay
->
dndSelectionHandler
(),
108
m_clientClipboard
[
QClipboard
::
Clipboard
]) :
nullptr
);
109
emitChanged
(
mode
);
110
}
111
break
;
112
case
QClipboard
::
Selection
:
113
if
(
auto
*
dataControlDevice
=
seat
->
dataControlDevice
()) {
114
dataControlDevice
->
setPrimarySelectionSource
(
data
?
new
QWaylandDataControlSourceV1
(
mDisplay
->
dataControlManager
(),
115
m_clientClipboard
[
QClipboard
::
Selection
]) :
nullptr
);
116
emitChanged
(
mode
);
117
#
if
QT_CONFIG
(
wayland_client_primary_selection
)
118
}
else
if
(
auto
*
selectionDevice
=
seat
->
primarySelectionDevice
()) {
119
selectionDevice
->
setSelectionSource
(
data
?
new
QWaylandPrimarySelectionSourceV1
(
mDisplay
->
primarySelectionManager
(),
120
m_clientClipboard
[
QClipboard
::
Selection
]) :
nullptr
);
121
emitChanged
(
mode
);
122
#
endif
123
}
124
break
;
125
default
:
126
break
;
127
}
128
}
129
130
bool
QWaylandClipboard
::
supportsMode
(
QClipboard
::
Mode
mode
)
const
131
{
132
if
(
mode
==
QClipboard
::
Selection
) {
133
auto
*
seat
=
mDisplay
->
currentInputDevice
();
134
if
(!
seat
)
135
return
false
;
136
if
(
seat
->
dataControlDevice
())
137
return
true
;
138
#
if
QT_CONFIG
(
wayland_client_primary_selection
)
139
if
(
seat
->
primarySelectionDevice
())
140
return
true
;
141
#
endif
142
return
false
;
143
}
144
return
mode
==
QClipboard
::
Clipboard
;
145
}
146
147
bool
QWaylandClipboard
::
ownsMode
(
QClipboard
::
Mode
mode
)
const
148
{
149
QWaylandInputDevice
*
seat
=
mDisplay
->
currentInputDevice
();
150
if
(!
seat
)
151
return
false
;
152
153
switch
(
mode
) {
154
case
QClipboard
::
Clipboard
:
155
if
(
seat
->
dataControlDevice
() &&
seat
->
dataControlDevice
()->
selectionSource
() !=
nullptr
)
156
return
true
;
157
return
seat
->
dataDevice
() &&
seat
->
dataDevice
()->
selectionSource
() !=
nullptr
;
158
case
QClipboard
::
Selection
:
159
if
(
seat
->
dataControlDevice
() &&
seat
->
dataControlDevice
()->
primarySelectionSource
() !=
nullptr
)
160
return
true
;
161
#
if
QT_CONFIG
(
wayland_client_primary_selection
)
162
return
seat
->
primarySelectionDevice
() &&
seat
->
primarySelectionDevice
()->
selectionSource
() !=
nullptr
;
163
#
endif
164
default
:
165
return
false
;
166
}
167
}
168
169
}
170
171
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qrandomaccessasyncfile_darwin.mm:17
QtWaylandClient
Definition
qwaylandclientextension.h:16
qtbase
src
plugins
platforms
wayland
qwaylandclipboard.cpp
Generated on
for Qt by
1.16.1