ui/clipboard: add helper to retrieve current clipboard

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20210805135715.857938-6-marcandre.lureau@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
This commit is contained in:
Marc-André Lureau 2021-08-05 17:57:02 +04:00
parent 6b32aef09a
commit 684e64d36d
2 changed files with 24 additions and 0 deletions

View file

@ -109,6 +109,15 @@ void qemu_clipboard_peer_register(QemuClipboardPeer *peer);
*/
void qemu_clipboard_peer_unregister(QemuClipboardPeer *peer);
/**
* qemu_clipboard_info
*
* @selection: clipboard selection.
*
* Return the current clipboard data & owner informations.
*/
QemuClipboardInfo *qemu_clipboard_info(QemuClipboardSelection selection);
/**
* qemu_clipboard_info_new
*

View file

@ -4,6 +4,8 @@
static NotifierList clipboard_notifiers =
NOTIFIER_LIST_INITIALIZER(clipboard_notifiers);
static QemuClipboardInfo *cbinfo[QEMU_CLIPBOARD_SELECTION__COUNT];
void qemu_clipboard_peer_register(QemuClipboardPeer *peer)
{
notifier_list_add(&clipboard_notifiers, &peer->update);
@ -16,7 +18,20 @@ void qemu_clipboard_peer_unregister(QemuClipboardPeer *peer)
void qemu_clipboard_update(QemuClipboardInfo *info)
{
g_autoptr(QemuClipboardInfo) old = NULL;
assert(info->selection < QEMU_CLIPBOARD_SELECTION__COUNT);
notifier_list_notify(&clipboard_notifiers, info);
old = cbinfo[info->selection];
cbinfo[info->selection] = qemu_clipboard_info_ref(info);
}
QemuClipboardInfo *qemu_clipboard_info(QemuClipboardSelection selection)
{
assert(selection < QEMU_CLIPBOARD_SELECTION__COUNT);
return cbinfo[selection];
}
QemuClipboardInfo *qemu_clipboard_info_new(QemuClipboardPeer *owner,