1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
|
#ifndef QEMU_CLIPBOARD_H
#define QEMU_CLIPBOARD_H
#include "qemu/notify.h"
/**
* DOC: Introduction
*
* The header ``ui/clipboard.h`` declares the qemu clipboard interface.
*
* All qemu elements which want use the clipboard can register as
* clipboard peer. Subsequently they can set the clipboard content
* and get notifications for clipboard updates.
*
* Typical users are user interfaces (gtk), remote access protocols
* (vnc) and devices talking to the guest (vdagent).
*
* Even though the design allows different data types only plain text
* is supported for now.
*/
typedef enum QemuClipboardType QemuClipboardType;
typedef enum QemuClipboardNotifyType QemuClipboardNotifyType;
typedef enum QemuClipboardSelection QemuClipboardSelection;
typedef struct QemuClipboardPeer QemuClipboardPeer;
typedef struct QemuClipboardNotify QemuClipboardNotify;
typedef struct QemuClipboardInfo QemuClipboardInfo;
/**
* enum QemuClipboardType
*
* @QEMU_CLIPBOARD_TYPE_TEXT: text/plain; charset=utf-8
* @QEMU_CLIPBOARD_TYPE__COUNT: type count.
*/
enum QemuClipboardType {
QEMU_CLIPBOARD_TYPE_TEXT,
QEMU_CLIPBOARD_TYPE__COUNT,
};
/* same as VD_AGENT_CLIPBOARD_SELECTION_* */
/**
* enum QemuClipboardSelection
*
* @QEMU_CLIPBOARD_SELECTION_CLIPBOARD: clipboard (explitcit cut+paste).
* @QEMU_CLIPBOARD_SELECTION_PRIMARY: primary selection (select + middle mouse button).
* @QEMU_CLIPBOARD_SELECTION_SECONDARY: secondary selection (dunno).
* @QEMU_CLIPBOARD_SELECTION__COUNT: selection count.
*/
enum QemuClipboardSelection {
QEMU_CLIPBOARD_SELECTION_CLIPBOARD,
QEMU_CLIPBOARD_SELECTION_PRIMARY,
QEMU_CLIPBOARD_SELECTION_SECONDARY,
QEMU_CLIPBOARD_SELECTION__COUNT,
};
/**
* struct QemuClipboardPeer
*
* @name: peer name.
* @notifier: notifier for clipboard updates.
* @request: callback for clipboard data requests.
*
* Clipboard peer description.
*/
struct QemuClipboardPeer {
const char *name;
Notifier notifier;
void (*request)(QemuClipboardInfo *info,
QemuClipboardType type);
};
/**
* enum QemuClipboardNotifyType
*
* @QEMU_CLIPBOARD_UPDATE_INFO: clipboard info update
* @QEMU_CLIPBOARD_RESET_SERIAL: reset clipboard serial
*
* Clipboard notify type.
*/
enum QemuClipboardNotifyType {
QEMU_CLIPBOARD_UPDATE_INFO,
QEMU_CLIPBOARD_RESET_SERIAL,
};
/**
* struct QemuClipboardNotify
*
* @type: the type of event.
* @info: a QemuClipboardInfo event.
*
* Clipboard notify data.
*/
struct QemuClipboardNotify {
QemuClipboardNotifyType type;
union {
QemuClipboardInfo *info;
};
};
/**
* struct QemuClipboardInfo
*
* @refcount: reference counter.
* @owner: clipboard owner.
* @selection: clipboard selection.
* @types: clipboard data array (one entry per type).
* @has_serial: whether @serial is available.
* @serial: the grab serial counter.
*
* Clipboard content data and metadata.
*/
struct QemuClipboardInfo {
uint32_t refcount;
QemuClipboardPeer *owner;
QemuClipboardSelection selection;
bool has_serial;
uint32_t serial;
struct {
bool available;
bool requested;
size_t size;
void *data;
} types[QEMU_CLIPBOARD_TYPE__COUNT];
};
/**
* qemu_clipboard_peer_register
*
* @peer: peer information.
*
* Register clipboard peer. Registering is needed for both active
* (set+grab clipboard) and passive (watch clipboard for updates)
* interaction with the qemu clipboard.
*/
void qemu_clipboard_peer_register(QemuClipboardPeer *peer);
/**
* qemu_clipboard_peer_unregister
*
* @peer: peer information.
*
* Unregister clipboard peer.
*/
void qemu_clipboard_peer_unregister(QemuClipboardPeer *peer);
/**
* qemu_clipboard_peer_owns
*
* @peer: peer information.
* @selection: clipboard selection.
*
* Return TRUE if the peer owns the clipboard.
*/
bool qemu_clipboard_peer_owns(QemuClipboardPeer *peer,
QemuClipboardSelection selection);
/**
* qemu_clipboard_peer_release
*
* @peer: peer information.
* @selection: clipboard selection.
*
* If the peer owns the clipboard, release it.
*/
void qemu_clipboard_peer_release(QemuClipboardPeer *peer,
QemuClipboardSelection selection);
/**
* qemu_clipboard_info
*
* @selection: clipboard selection.
*
* Return the current clipboard data & owner informations.
*/
QemuClipboardInfo *qemu_clipboard_info(QemuClipboardSelection selection);
/**
* qemu_clipboard_check_serial
*
* @info: clipboard info.
* @client: whether to check from the client context and priority.
*
* Return TRUE if the @info has a higher serial than the current clipboard.
*/
bool qemu_clipboard_check_serial(QemuClipboardInfo *info, bool client);
/**
* qemu_clipboard_info_new
*
* @owner: clipboard owner.
* @selection: clipboard selection.
*
* Allocate a new QemuClipboardInfo and initialize it with the given
* @owner and @selection.
*
* QemuClipboardInfo is a reference-counted struct. The new struct is
* returned with a reference already taken (i.e. reference count is
* one).
*/
QemuClipboardInfo *qemu_clipboard_info_new(QemuClipboardPeer *owner,
QemuClipboardSelection selection);
/**
* qemu_clipboard_info_ref
*
* @info: clipboard info.
*
* Increase @info reference count.
*/
QemuClipboardInfo *qemu_clipboard_info_ref(QemuClipboardInfo *info);
/**
* qemu_clipboard_info_unref
*
* @info: clipboard info.
*
* Decrease @info reference count. When the count goes down to zero
* free the @info struct itself and all clipboard data.
*/
void qemu_clipboard_info_unref(QemuClipboardInfo *info);
/**
* qemu_clipboard_update
*
* @info: clipboard info.
*
* Update the qemu clipboard. Notify all registered peers (including
* the clipboard owner) that the qemu clipboard has been updated.
*
* This is used for both new completely clipboard content and for
* clipboard data updates in response to qemu_clipboard_request()
* calls.
*/
void qemu_clipboard_update(QemuClipboardInfo *info);
/**
* qemu_clipboard_reset_serial
*
* Reset the clipboard serial.
*/
void qemu_clipboard_reset_serial(void);
/**
* qemu_clipboard_request
*
* @info: clipboard info.
* @type: clipboard data type.
*
* Request clipboard content. Typically the clipboard owner only
* advertises the available data types and provides the actual data
* only on request.
*/
void qemu_clipboard_request(QemuClipboardInfo *info,
QemuClipboardType type);
/**
* qemu_clipboard_set_data
*
* @peer: clipboard peer.
* @info: clipboard info.
* @type: clipboard data type.
* @size: data size.
* @data: data blob.
* @update: notify peers about the update.
*
* Set clipboard content for the given @type. This function will make
* a copy of the content data and store that.
*/
void qemu_clipboard_set_data(QemuClipboardPeer *peer,
QemuClipboardInfo *info,
QemuClipboardType type,
uint32_t size,
const void *data,
bool update);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(QemuClipboardInfo, qemu_clipboard_info_unref)
#endif /* QEMU_CLIPBOARD_H */
|