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
12#if QT_CONFIG(wayland_client_primary_selection)
13#include "qwaylandprimaryselectionv1_p.h"
14#endif
15
17
18namespace QtWaylandClient {
19
26
33
35{
37 if (!seat)
38 return &m_emptyData;
39
40 switch (mode) {
46 return offer->mimeData();
47 }
48 if (auto *dataDevice = seat->dataDevice()) {
51 if (auto *offer = dataDevice->selectionOffer())
52 return offer->mimeData();
53 }
54 return &m_emptyData;
60 return offer->mimeData();
61 }
62#if QT_CONFIG(wayland_client_primary_selection)
67 return offer->mimeData();
68 }
69#endif
70 return &m_emptyData;
71 default:
72 return &m_emptyData;
73 }
74}
75
77{
79 if (!seat) {
80 qCWarning(lcQpaWayland) << "Can't set clipboard contents with no wl_seats available";
81 return;
82 }
83
84 if (data && m_clientClipboard[mode] == data) // Already set before?
85 return;
86
87 static const QString plain = QStringLiteral("text/plain");
88 static const QString utf8 = QStringLiteral("text/plain;charset=utf-8");
89
90 if (data && data->hasFormat(plain) && !data->hasFormat(utf8))
92
97 delete oldMimeData;
98
99 switch (mode) {
100 case QClipboard::Clipboard:
105 } else if (auto *dataDevice = seat->dataDevice()) {
109 }
110 break;
111 case QClipboard::Selection:
116#if QT_CONFIG(wayland_client_primary_selection)
117 } else if (auto *selectionDevice = seat->primarySelectionDevice()) {
121#endif
122 }
123 break;
124 default:
125 break;
126 }
127}
128
130{
131 if (mode == QClipboard::Selection) {
133 if (!seat)
134 return false;
135 if (seat->dataControlDevice())
136 return true;
137#if QT_CONFIG(wayland_client_primary_selection)
139 return true;
140#endif
141 return false;
142 }
143 return mode == QClipboard::Clipboard;
144}
145
147{
149 if (!seat)
150 return false;
151
152 switch (mode) {
153 case QClipboard::Clipboard:
154 return seat->dataDevice() && seat->dataDevice()->selectionSource() != nullptr;
155 case QClipboard::Selection:
157 return true;
158#if QT_CONFIG(wayland_client_primary_selection)
160#endif
161 default:
162 return false;
163 }
164}
165
166}
167
168QT_END_NAMESPACE
Combined button and popup list for selecting options.