1 #ifndef QEMU_CLIPBOARD_H
2 #define QEMU_CLIPBOARD_H
4 #include "qemu/notify.h"
9 * The header ``ui/clipboard.h`` declares the qemu clipboard interface.
11 * All qemu elements which want use the clipboard can register as
12 * clipboard peer. Subsequently they can set the clipboard content
13 * and get notifications for clipboard updates.
15 * Typical users are user interfaces (gtk), remote access protocols
16 * (vnc) and devices talking to the guest (vdagent).
18 * Even though the design allows different data types only plain text
19 * is supported for now.
22 typedef enum QemuClipboardType QemuClipboardType
;
23 typedef enum QemuClipboardNotifyType QemuClipboardNotifyType
;
24 typedef enum QemuClipboardSelection QemuClipboardSelection
;
25 typedef struct QemuClipboardPeer QemuClipboardPeer
;
26 typedef struct QemuClipboardNotify QemuClipboardNotify
;
27 typedef struct QemuClipboardInfo QemuClipboardInfo
;
30 * enum QemuClipboardType
32 * @QEMU_CLIPBOARD_TYPE_TEXT: text/plain; charset=utf-8
33 * @QEMU_CLIPBOARD_TYPE__COUNT: type count.
35 enum QemuClipboardType
{
36 QEMU_CLIPBOARD_TYPE_TEXT
,
37 QEMU_CLIPBOARD_TYPE__COUNT
,
40 /* same as VD_AGENT_CLIPBOARD_SELECTION_* */
42 * enum QemuClipboardSelection
44 * @QEMU_CLIPBOARD_SELECTION_CLIPBOARD: clipboard (explitcit cut+paste).
45 * @QEMU_CLIPBOARD_SELECTION_PRIMARY: primary selection (select + middle mouse button).
46 * @QEMU_CLIPBOARD_SELECTION_SECONDARY: secondary selection (dunno).
47 * @QEMU_CLIPBOARD_SELECTION__COUNT: selection count.
49 enum QemuClipboardSelection
{
50 QEMU_CLIPBOARD_SELECTION_CLIPBOARD
,
51 QEMU_CLIPBOARD_SELECTION_PRIMARY
,
52 QEMU_CLIPBOARD_SELECTION_SECONDARY
,
53 QEMU_CLIPBOARD_SELECTION__COUNT
,
57 * struct QemuClipboardPeer
60 * @notifier: notifier for clipboard updates.
61 * @request: callback for clipboard data requests.
63 * Clipboard peer description.
65 struct QemuClipboardPeer
{
68 void (*request
)(QemuClipboardInfo
*info
,
69 QemuClipboardType type
);
73 * enum QemuClipboardNotifyType
75 * @QEMU_CLIPBOARD_UPDATE_INFO: clipboard info update
76 * @QEMU_CLIPBOARD_RESET_SERIAL: reset clipboard serial
78 * Clipboard notify type.
80 enum QemuClipboardNotifyType
{
81 QEMU_CLIPBOARD_UPDATE_INFO
,
82 QEMU_CLIPBOARD_RESET_SERIAL
,
86 * struct QemuClipboardNotify
88 * @type: the type of event.
89 * @info: a QemuClipboardInfo event.
91 * Clipboard notify data.
93 struct QemuClipboardNotify
{
94 QemuClipboardNotifyType type
;
96 QemuClipboardInfo
*info
;
101 * struct QemuClipboardInfo
103 * @refcount: reference counter.
104 * @owner: clipboard owner.
105 * @selection: clipboard selection.
106 * @types: clipboard data array (one entry per type).
107 * @has_serial: whether @serial is available.
108 * @serial: the grab serial counter.
110 * Clipboard content data and metadata.
112 struct QemuClipboardInfo
{
114 QemuClipboardPeer
*owner
;
115 QemuClipboardSelection selection
;
123 } types
[QEMU_CLIPBOARD_TYPE__COUNT
];
127 * qemu_clipboard_peer_register
129 * @peer: peer information.
131 * Register clipboard peer. Registering is needed for both active
132 * (set+grab clipboard) and passive (watch clipboard for updates)
133 * interaction with the qemu clipboard.
135 void qemu_clipboard_peer_register(QemuClipboardPeer
*peer
);
138 * qemu_clipboard_peer_unregister
140 * @peer: peer information.
142 * Unregister clipboard peer.
144 void qemu_clipboard_peer_unregister(QemuClipboardPeer
*peer
);
147 * qemu_clipboard_peer_owns
149 * @peer: peer information.
150 * @selection: clipboard selection.
152 * Return TRUE if the peer owns the clipboard.
154 bool qemu_clipboard_peer_owns(QemuClipboardPeer
*peer
,
155 QemuClipboardSelection selection
);
158 * qemu_clipboard_peer_release
160 * @peer: peer information.
161 * @selection: clipboard selection.
163 * If the peer owns the clipboard, release it.
165 void qemu_clipboard_peer_release(QemuClipboardPeer
*peer
,
166 QemuClipboardSelection selection
);
169 * qemu_clipboard_info
171 * @selection: clipboard selection.
173 * Return the current clipboard data & owner informations.
175 QemuClipboardInfo
*qemu_clipboard_info(QemuClipboardSelection selection
);
178 * qemu_clipboard_check_serial
180 * @info: clipboard info.
181 * @client: whether to check from the client context and priority.
183 * Return TRUE if the @info has a higher serial than the current clipboard.
185 bool qemu_clipboard_check_serial(QemuClipboardInfo
*info
, bool client
);
188 * qemu_clipboard_info_new
190 * @owner: clipboard owner.
191 * @selection: clipboard selection.
193 * Allocate a new QemuClipboardInfo and initialize it with the given
194 * @owner and @selection.
196 * QemuClipboardInfo is a reference-counted struct. The new struct is
197 * returned with a reference already taken (i.e. reference count is
200 QemuClipboardInfo
*qemu_clipboard_info_new(QemuClipboardPeer
*owner
,
201 QemuClipboardSelection selection
);
203 * qemu_clipboard_info_ref
205 * @info: clipboard info.
207 * Increase @info reference count.
209 QemuClipboardInfo
*qemu_clipboard_info_ref(QemuClipboardInfo
*info
);
212 * qemu_clipboard_info_unref
214 * @info: clipboard info.
216 * Decrease @info reference count. When the count goes down to zero
217 * free the @info struct itself and all clipboard data.
219 void qemu_clipboard_info_unref(QemuClipboardInfo
*info
);
222 * qemu_clipboard_update
224 * @info: clipboard info.
226 * Update the qemu clipboard. Notify all registered peers (including
227 * the clipboard owner) that the qemu clipboard has been updated.
229 * This is used for both new completely clipboard content and for
230 * clipboard data updates in response to qemu_clipboard_request()
233 void qemu_clipboard_update(QemuClipboardInfo
*info
);
236 * qemu_clipboard_reset_serial
238 * Reset the clipboard serial.
240 void qemu_clipboard_reset_serial(void);
243 * qemu_clipboard_request
245 * @info: clipboard info.
246 * @type: clipboard data type.
248 * Request clipboard content. Typically the clipboard owner only
249 * advertises the available data types and provides the actual data
252 void qemu_clipboard_request(QemuClipboardInfo
*info
,
253 QemuClipboardType type
);
256 * qemu_clipboard_set_data
258 * @peer: clipboard peer.
259 * @info: clipboard info.
260 * @type: clipboard data type.
263 * @update: notify peers about the update.
265 * Set clipboard content for the given @type. This function will make
266 * a copy of the content data and store that.
268 void qemu_clipboard_set_data(QemuClipboardPeer
*peer
,
269 QemuClipboardInfo
*info
,
270 QemuClipboardType type
,
275 G_DEFINE_AUTOPTR_CLEANUP_FUNC(QemuClipboardInfo
, qemu_clipboard_info_unref
)
277 #endif /* QEMU_CLIPBOARD_H */