2021-05-19 13:39:33 +08:00
|
|
|
#ifndef QEMU_CLIPBOARD_H
|
|
|
|
#define QEMU_CLIPBOARD_H
|
|
|
|
|
|
|
|
#include "qemu/notify.h"
|
|
|
|
|
2021-05-19 13:39:34 +08:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2021-05-19 13:39:33 +08:00
|
|
|
typedef enum QemuClipboardType QemuClipboardType;
|
2021-07-19 23:42:15 +08:00
|
|
|
typedef enum QemuClipboardNotifyType QemuClipboardNotifyType;
|
2021-05-19 13:39:33 +08:00
|
|
|
typedef enum QemuClipboardSelection QemuClipboardSelection;
|
|
|
|
typedef struct QemuClipboardPeer QemuClipboardPeer;
|
2021-07-19 23:42:15 +08:00
|
|
|
typedef struct QemuClipboardNotify QemuClipboardNotify;
|
2021-05-19 13:39:33 +08:00
|
|
|
typedef struct QemuClipboardInfo QemuClipboardInfo;
|
|
|
|
|
2021-05-19 13:39:34 +08:00
|
|
|
/**
|
|
|
|
* enum QemuClipboardType
|
|
|
|
*
|
|
|
|
* @QEMU_CLIPBOARD_TYPE_TEXT: text/plain; charset=utf-8
|
|
|
|
* @QEMU_CLIPBOARD_TYPE__COUNT: type count.
|
|
|
|
*/
|
2021-05-19 13:39:33 +08:00
|
|
|
enum QemuClipboardType {
|
2021-05-19 13:39:34 +08:00
|
|
|
QEMU_CLIPBOARD_TYPE_TEXT,
|
2021-05-19 13:39:33 +08:00
|
|
|
QEMU_CLIPBOARD_TYPE__COUNT,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* same as VD_AGENT_CLIPBOARD_SELECTION_* */
|
2021-05-19 13:39:34 +08:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2021-05-19 13:39:33 +08:00
|
|
|
enum QemuClipboardSelection {
|
|
|
|
QEMU_CLIPBOARD_SELECTION_CLIPBOARD,
|
|
|
|
QEMU_CLIPBOARD_SELECTION_PRIMARY,
|
|
|
|
QEMU_CLIPBOARD_SELECTION_SECONDARY,
|
|
|
|
QEMU_CLIPBOARD_SELECTION__COUNT,
|
|
|
|
};
|
|
|
|
|
2021-05-19 13:39:34 +08:00
|
|
|
/**
|
|
|
|
* struct QemuClipboardPeer
|
|
|
|
*
|
|
|
|
* @name: peer name.
|
2021-07-19 23:42:15 +08:00
|
|
|
* @notifier: notifier for clipboard updates.
|
2021-05-19 13:39:34 +08:00
|
|
|
* @request: callback for clipboard data requests.
|
|
|
|
*
|
|
|
|
* Clipboard peer description.
|
|
|
|
*/
|
2021-05-19 13:39:33 +08:00
|
|
|
struct QemuClipboardPeer {
|
|
|
|
const char *name;
|
2021-07-19 23:42:15 +08:00
|
|
|
Notifier notifier;
|
2021-05-19 13:39:33 +08:00
|
|
|
void (*request)(QemuClipboardInfo *info,
|
|
|
|
QemuClipboardType type);
|
|
|
|
};
|
|
|
|
|
2021-07-19 23:42:15 +08:00
|
|
|
/**
|
|
|
|
* enum QemuClipboardNotifyType
|
|
|
|
*
|
|
|
|
* @QEMU_CLIPBOARD_UPDATE_INFO: clipboard info update
|
2021-07-19 23:49:56 +08:00
|
|
|
* @QEMU_CLIPBOARD_RESET_SERIAL: reset clipboard serial
|
2021-07-19 23:42:15 +08:00
|
|
|
*
|
|
|
|
* Clipboard notify type.
|
|
|
|
*/
|
|
|
|
enum QemuClipboardNotifyType {
|
|
|
|
QEMU_CLIPBOARD_UPDATE_INFO,
|
2021-07-19 23:49:56 +08:00
|
|
|
QEMU_CLIPBOARD_RESET_SERIAL,
|
2021-07-19 23:42:15 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct QemuClipboardNotify
|
|
|
|
*
|
|
|
|
* @type: the type of event.
|
|
|
|
* @info: a QemuClipboardInfo event.
|
|
|
|
*
|
|
|
|
* Clipboard notify data.
|
|
|
|
*/
|
|
|
|
struct QemuClipboardNotify {
|
|
|
|
QemuClipboardNotifyType type;
|
|
|
|
union {
|
|
|
|
QemuClipboardInfo *info;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-05-19 13:39:34 +08:00
|
|
|
/**
|
|
|
|
* struct QemuClipboardInfo
|
|
|
|
*
|
|
|
|
* @refcount: reference counter.
|
|
|
|
* @owner: clipboard owner.
|
|
|
|
* @selection: clipboard selection.
|
|
|
|
* @types: clipboard data array (one entry per type).
|
2021-07-19 04:33:31 +08:00
|
|
|
* @has_serial: whether @serial is available.
|
|
|
|
* @serial: the grab serial counter.
|
2021-05-19 13:39:34 +08:00
|
|
|
*
|
|
|
|
* Clipboard content data and metadata.
|
|
|
|
*/
|
2021-05-19 13:39:33 +08:00
|
|
|
struct QemuClipboardInfo {
|
|
|
|
uint32_t refcount;
|
|
|
|
QemuClipboardPeer *owner;
|
|
|
|
QemuClipboardSelection selection;
|
2021-07-19 04:33:31 +08:00
|
|
|
bool has_serial;
|
|
|
|
uint32_t serial;
|
2021-05-19 13:39:33 +08:00
|
|
|
struct {
|
|
|
|
bool available;
|
|
|
|
bool requested;
|
|
|
|
size_t size;
|
|
|
|
void *data;
|
|
|
|
} types[QEMU_CLIPBOARD_TYPE__COUNT];
|
|
|
|
};
|
|
|
|
|
2021-05-19 13:39:34 +08:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2021-05-19 13:39:33 +08:00
|
|
|
void qemu_clipboard_peer_register(QemuClipboardPeer *peer);
|
2021-05-19 13:39:34 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* qemu_clipboard_peer_unregister
|
|
|
|
*
|
|
|
|
* @peer: peer information.
|
|
|
|
*
|
|
|
|
* Unregister clipboard peer.
|
|
|
|
*/
|
2021-05-19 13:39:33 +08:00
|
|
|
void qemu_clipboard_peer_unregister(QemuClipboardPeer *peer);
|
|
|
|
|
2021-08-05 21:57:03 +08:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2021-08-05 21:57:04 +08:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2021-08-05 21:57:02 +08:00
|
|
|
/**
|
|
|
|
* qemu_clipboard_info
|
|
|
|
*
|
|
|
|
* @selection: clipboard selection.
|
|
|
|
*
|
|
|
|
* Return the current clipboard data & owner informations.
|
|
|
|
*/
|
|
|
|
QemuClipboardInfo *qemu_clipboard_info(QemuClipboardSelection selection);
|
|
|
|
|
2021-07-21 19:19:13 +08:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2021-05-19 13:39:34 +08:00
|
|
|
/**
|
|
|
|
* 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).
|
|
|
|
*/
|
2021-05-19 13:39:33 +08:00
|
|
|
QemuClipboardInfo *qemu_clipboard_info_new(QemuClipboardPeer *owner,
|
|
|
|
QemuClipboardSelection selection);
|
2021-05-19 13:39:34 +08:00
|
|
|
/**
|
|
|
|
* qemu_clipboard_info_ref
|
|
|
|
*
|
|
|
|
* @info: clipboard info.
|
|
|
|
*
|
|
|
|
* Increase @info reference count.
|
|
|
|
*/
|
2021-05-19 13:39:33 +08:00
|
|
|
QemuClipboardInfo *qemu_clipboard_info_ref(QemuClipboardInfo *info);
|
2021-05-19 13:39:34 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2021-05-19 13:39:33 +08:00
|
|
|
void qemu_clipboard_info_unref(QemuClipboardInfo *info);
|
|
|
|
|
2021-05-19 13:39:34 +08:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2021-05-19 13:39:33 +08:00
|
|
|
void qemu_clipboard_update(QemuClipboardInfo *info);
|
2021-05-19 13:39:34 +08:00
|
|
|
|
2021-07-19 23:49:56 +08:00
|
|
|
/**
|
|
|
|
* qemu_clipboard_reset_serial
|
|
|
|
*
|
|
|
|
* Reset the clipboard serial.
|
|
|
|
*/
|
|
|
|
void qemu_clipboard_reset_serial(void);
|
|
|
|
|
2021-05-19 13:39:34 +08:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2021-05-19 13:39:33 +08:00
|
|
|
void qemu_clipboard_request(QemuClipboardInfo *info,
|
|
|
|
QemuClipboardType type);
|
|
|
|
|
2021-05-19 13:39:34 +08:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2021-05-19 13:39:33 +08:00
|
|
|
void qemu_clipboard_set_data(QemuClipboardPeer *peer,
|
|
|
|
QemuClipboardInfo *info,
|
|
|
|
QemuClipboardType type,
|
|
|
|
uint32_t size,
|
2021-06-16 22:19:54 +08:00
|
|
|
const void *data,
|
2021-05-19 13:39:33 +08:00
|
|
|
bool update);
|
|
|
|
|
2021-08-05 21:56:58 +08:00
|
|
|
G_DEFINE_AUTOPTR_CLEANUP_FUNC(QemuClipboardInfo, qemu_clipboard_info_unref)
|
|
|
|
|
2021-05-19 13:39:33 +08:00
|
|
|
#endif /* QEMU_CLIPBOARD_H */
|