diff options
| author | Peter Maydell <peter.maydell@linaro.org> | 2021-08-31 14:38:15 +0100 |
|---|---|---|
| committer | Peter Maydell <peter.maydell@linaro.org> | 2021-08-31 14:38:15 +0100 |
| commit | d52dff5d8048d4982437db9606c27bb4127cf9d0 (patch) | |
| tree | 3159620ffcdfd8df6cdf8d5963a63d87db5291c5 /ui/clipboard.c | |
| parent | ad22d0583300df420819e6c89b1c022b998fac8a (diff) | |
| parent | 90208bc9657b7e0f8a6bc6af82b69c65c97b2d64 (diff) | |
| download | focaccia-qemu-d52dff5d8048d4982437db9606c27bb4127cf9d0.tar.gz focaccia-qemu-d52dff5d8048d4982437db9606c27bb4127cf9d0.zip | |
Merge remote-tracking branch 'remotes/marcandre/tags/clip-pull-request' into staging
# gpg: Signature made Tue 31 Aug 2021 14:29:27 BST # gpg: using RSA key 87A9BD933F87C606D276F62DDAE8E10975969CE5 # gpg: issuer "marcandre.lureau@redhat.com" # gpg: Good signature from "Marc-André Lureau <marcandre.lureau@redhat.com>" [full] # gpg: aka "Marc-André Lureau <marcandre.lureau@gmail.com>" [full] # Primary key fingerprint: 87A9 BD93 3F87 C606 D276 F62D DAE8 E109 7596 9CE5 * remotes/marcandre/tags/clip-pull-request: ui/vdagent: add a migration blocker ui/gtk-clipboard: emit release clipboard events ui/vdagent: send release when no clipboard owner ui/gtk-clipboard: use qemu_clipboard_info helper ui/vdagent: send empty clipboard when unhandled ui/vdagent: use qemu_clipboard_info helper ui/vdagent: use qemu_clipboard_peer_release helper ui/vdagent: split clipboard recv message handling ui/vdagent: reset outbuf on disconnect ui/vdagent: disconnect handlers and reset state on finalize ui/clipboard: release owned grabs on unregister ui/clipboard: add qemu_clipboard_peer_release() helper ui/clipboard: add qemu_clipboard_peer_owns() helper ui/clipboard: add helper to retrieve current clipboard ui/gtk-clipboard: fix clipboard enum typo ui/gtk-clipboard: use existing macros ui/vdagent: remove copy-pasta comment ui/vdagent: fix leak on error path Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'ui/clipboard.c')
| -rw-r--r-- | ui/clipboard.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/ui/clipboard.c b/ui/clipboard.c index 3525b30178..d7b008d62a 100644 --- a/ui/clipboard.c +++ b/ui/clipboard.c @@ -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); @@ -11,12 +13,51 @@ void qemu_clipboard_peer_register(QemuClipboardPeer *peer) void qemu_clipboard_peer_unregister(QemuClipboardPeer *peer) { + int i; + + for (i = 0; i < QEMU_CLIPBOARD_SELECTION__COUNT; i++) { + qemu_clipboard_peer_release(peer, i); + } + notifier_remove(&peer->update); } +bool qemu_clipboard_peer_owns(QemuClipboardPeer *peer, + QemuClipboardSelection selection) +{ + QemuClipboardInfo *info = qemu_clipboard_info(selection); + + return info && info->owner == peer; +} + +void qemu_clipboard_peer_release(QemuClipboardPeer *peer, + QemuClipboardSelection selection) +{ + g_autoptr(QemuClipboardInfo) info = NULL; + + if (qemu_clipboard_peer_owns(peer, selection)) { + /* set empty clipboard info */ + info = qemu_clipboard_info_new(NULL, selection); + qemu_clipboard_update(info); + } +} + 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, |