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
77 * Clipboard notify type.
79 enum QemuClipboardNotifyType
{
80 QEMU_CLIPBOARD_UPDATE_INFO
,
84 * struct QemuClipboardNotify
86 * @type: the type of event.
87 * @info: a QemuClipboardInfo event.
89 * Clipboard notify data.
91 struct QemuClipboardNotify
{
92 QemuClipboardNotifyType type
;
94 QemuClipboardInfo
*info
;
99 * struct QemuClipboardInfo
101 * @refcount: reference counter.
102 * @owner: clipboard owner.
103 * @selection: clipboard selection.
104 * @types: clipboard data array (one entry per type).
105 * @has_serial: whether @serial is available.
106 * @serial: the grab serial counter.
108 * Clipboard content data and metadata.
110 struct QemuClipboardInfo
{
112 QemuClipboardPeer
*owner
;
113 QemuClipboardSelection selection
;
121 } types
[QEMU_CLIPBOARD_TYPE__COUNT
];
125 * qemu_clipboard_peer_register
127 * @peer: peer information.
129 * Register clipboard peer. Registering is needed for both active
130 * (set+grab clipboard) and passive (watch clipboard for updates)
131 * interaction with the qemu clipboard.
133 void qemu_clipboard_peer_register(QemuClipboardPeer
*peer
);
136 * qemu_clipboard_peer_unregister
138 * @peer: peer information.
140 * Unregister clipboard peer.
142 void qemu_clipboard_peer_unregister(QemuClipboardPeer
*peer
);
145 * qemu_clipboard_peer_owns
147 * @peer: peer information.
148 * @selection: clipboard selection.
150 * Return TRUE if the peer owns the clipboard.
152 bool qemu_clipboard_peer_owns(QemuClipboardPeer
*peer
,
153 QemuClipboardSelection selection
);
156 * qemu_clipboard_peer_release
158 * @peer: peer information.
159 * @selection: clipboard selection.
161 * If the peer owns the clipboard, release it.
163 void qemu_clipboard_peer_release(QemuClipboardPeer
*peer
,
164 QemuClipboardSelection selection
);
167 * qemu_clipboard_info
169 * @selection: clipboard selection.
171 * Return the current clipboard data & owner informations.
173 QemuClipboardInfo
*qemu_clipboard_info(QemuClipboardSelection selection
);
176 * qemu_clipboard_info_new
178 * @owner: clipboard owner.
179 * @selection: clipboard selection.
181 * Allocate a new QemuClipboardInfo and initialize it with the given
182 * @owner and @selection.
184 * QemuClipboardInfo is a reference-counted struct. The new struct is
185 * returned with a reference already taken (i.e. reference count is
188 QemuClipboardInfo
*qemu_clipboard_info_new(QemuClipboardPeer
*owner
,
189 QemuClipboardSelection selection
);
191 * qemu_clipboard_info_ref
193 * @info: clipboard info.
195 * Increase @info reference count.
197 QemuClipboardInfo
*qemu_clipboard_info_ref(QemuClipboardInfo
*info
);
200 * qemu_clipboard_info_unref
202 * @info: clipboard info.
204 * Decrease @info reference count. When the count goes down to zero
205 * free the @info struct itself and all clipboard data.
207 void qemu_clipboard_info_unref(QemuClipboardInfo
*info
);
210 * qemu_clipboard_update
212 * @info: clipboard info.
214 * Update the qemu clipboard. Notify all registered peers (including
215 * the clipboard owner) that the qemu clipboard has been updated.
217 * This is used for both new completely clipboard content and for
218 * clipboard data updates in response to qemu_clipboard_request()
221 void qemu_clipboard_update(QemuClipboardInfo
*info
);
224 * qemu_clipboard_request
226 * @info: clipboard info.
227 * @type: clipboard data type.
229 * Request clipboard content. Typically the clipboard owner only
230 * advertises the available data types and provides the actual data
233 void qemu_clipboard_request(QemuClipboardInfo
*info
,
234 QemuClipboardType type
);
237 * qemu_clipboard_set_data
239 * @peer: clipboard peer.
240 * @info: clipboard info.
241 * @type: clipboard data type.
244 * @update: notify peers about the update.
246 * Set clipboard content for the given @type. This function will make
247 * a copy of the content data and store that.
249 void qemu_clipboard_set_data(QemuClipboardPeer
*peer
,
250 QemuClipboardInfo
*info
,
251 QemuClipboardType type
,
256 G_DEFINE_AUTOPTR_CLEANUP_FUNC(QemuClipboardInfo
, qemu_clipboard_info_unref
)
258 #endif /* QEMU_CLIPBOARD_H */