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
13#if QT_CONFIG(wayland_client_primary_selection)
14#include "qwaylandprimaryselectionv1_p.h"
15#endif
16
18
19namespace QtWaylandClient {
20
27
34
36{
38 if (!seat)
39 return &m_emptyData;
40
41 switch (mode) {
47 return offer->mimeData();
48 }
49 if (auto *dataDevice = seat->dataDevice()) {
52 if (auto *offer = dataDevice->selectionOffer())
53 return offer->mimeData();
54 }
55 return &m_emptyData;
61 return offer->mimeData();
62 }
63#if QT_CONFIG(wayland_client_primary_selection)
68 return offer->mimeData();
69 }
70#endif
71 return &m_emptyData;
72 default:
73 return &m_emptyData;
74 }
75}
76
78{
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))
93
98 delete oldMimeData;
99
100 switch (mode) {
101 case QClipboard::Clipboard:
106 } else if (auto *dataDevice = seat->dataDevice()) {
110 }
111 break;
112 case QClipboard::Selection:
117#if QT_CONFIG(wayland_client_primary_selection)
118 } else if (auto *selectionDevice = seat->primarySelectionDevice()) {
122#endif
123 }
124 break;
125 default:
126 break;
127 }
128}
129
131{
132 if (mode == QClipboard::Selection) {
134 if (!seat)
135 return false;
136 if (seat->dataControlDevice())
137 return true;
138#if QT_CONFIG(wayland_client_primary_selection)
140 return true;
141#endif
142 return false;
143 }
144 return mode == QClipboard::Clipboard;
145}
146
148{
150 if (!seat)
151 return false;
152
153 switch (mode) {
154 case QClipboard::Clipboard:
156 return true;
157 return seat->dataDevice() && seat->dataDevice()->selectionSource() != nullptr;
158 case QClipboard::Selection:
160 return true;
161#if QT_CONFIG(wayland_client_primary_selection)
163#endif
164 default:
165 return false;
166 }
167}
168
169}
170
171QT_END_NAMESPACE
Combined button and popup list for selecting options.