From: marcandre.lureau@redhat.com
To: qemu-devel@nongnu.org
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>, kraxel@redhat.com
Subject: [PATCH v2 04/37] ui: generalize clipboard notifier
Date: Sun, 10 Oct 2021 01:08:05 +0400 [thread overview]
Message-ID: <20211009210838.2219430-5-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <20211009210838.2219430-1-marcandre.lureau@redhat.com>
From: Marc-André Lureau <marcandre.lureau@redhat.com>
Use a QemuClipboardNotify union type for extendable clipboard events.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
include/ui/clipboard.h | 32 ++++++++++++++++++++++++++++++--
ui/clipboard.c | 12 ++++++++----
ui/gtk-clipboard.c | 20 ++++++++++++++++----
ui/vdagent.c | 27 ++++++++++++++++++---------
ui/vnc-clipboard.c | 18 ++++++++++++++----
ui/vnc.c | 2 +-
ui/cocoa.m | 17 +++++++++++++----
7 files changed, 100 insertions(+), 28 deletions(-)
diff --git a/include/ui/clipboard.h b/include/ui/clipboard.h
index 6298986b15..d82cf31481 100644
--- a/include/ui/clipboard.h
+++ b/include/ui/clipboard.h
@@ -20,8 +20,10 @@
*/
typedef enum QemuClipboardType QemuClipboardType;
+typedef enum QemuClipboardNotifyType QemuClipboardNotifyType;
typedef enum QemuClipboardSelection QemuClipboardSelection;
typedef struct QemuClipboardPeer QemuClipboardPeer;
+typedef struct QemuClipboardNotify QemuClipboardNotify;
typedef struct QemuClipboardInfo QemuClipboardInfo;
/**
@@ -55,18 +57,44 @@ enum QemuClipboardSelection {
* struct QemuClipboardPeer
*
* @name: peer name.
- * @update: notifier for clipboard updates.
+ * @notifier: notifier for clipboard updates.
* @request: callback for clipboard data requests.
*
* Clipboard peer description.
*/
struct QemuClipboardPeer {
const char *name;
- Notifier update;
+ Notifier notifier;
void (*request)(QemuClipboardInfo *info,
QemuClipboardType type);
};
+/**
+ * enum QemuClipboardNotifyType
+ *
+ * @QEMU_CLIPBOARD_UPDATE_INFO: clipboard info update
+ *
+ * Clipboard notify type.
+ */
+enum QemuClipboardNotifyType {
+ QEMU_CLIPBOARD_UPDATE_INFO,
+};
+
+/**
+ * struct QemuClipboardNotify
+ *
+ * @type: the type of event.
+ * @info: a QemuClipboardInfo event.
+ *
+ * Clipboard notify data.
+ */
+struct QemuClipboardNotify {
+ QemuClipboardNotifyType type;
+ union {
+ QemuClipboardInfo *info;
+ };
+};
+
/**
* struct QemuClipboardInfo
*
diff --git a/ui/clipboard.c b/ui/clipboard.c
index d7b008d62a..743b39edf4 100644
--- a/ui/clipboard.c
+++ b/ui/clipboard.c
@@ -8,7 +8,7 @@ static QemuClipboardInfo *cbinfo[QEMU_CLIPBOARD_SELECTION__COUNT];
void qemu_clipboard_peer_register(QemuClipboardPeer *peer)
{
- notifier_list_add(&clipboard_notifiers, &peer->update);
+ notifier_list_add(&clipboard_notifiers, &peer->notifier);
}
void qemu_clipboard_peer_unregister(QemuClipboardPeer *peer)
@@ -18,8 +18,7 @@ void qemu_clipboard_peer_unregister(QemuClipboardPeer *peer)
for (i = 0; i < QEMU_CLIPBOARD_SELECTION__COUNT; i++) {
qemu_clipboard_peer_release(peer, i);
}
-
- notifier_remove(&peer->update);
+ notifier_remove(&peer->notifier);
}
bool qemu_clipboard_peer_owns(QemuClipboardPeer *peer,
@@ -44,10 +43,15 @@ void qemu_clipboard_peer_release(QemuClipboardPeer *peer,
void qemu_clipboard_update(QemuClipboardInfo *info)
{
+ QemuClipboardNotify notify = {
+ .type = QEMU_CLIPBOARD_UPDATE_INFO,
+ .info = info,
+ };
g_autoptr(QemuClipboardInfo) old = NULL;
+
assert(info->selection < QEMU_CLIPBOARD_SELECTION__COUNT);
- notifier_list_notify(&clipboard_notifiers, info);
+ notifier_list_notify(&clipboard_notifiers, ¬ify);
old = cbinfo[info->selection];
cbinfo[info->selection] = qemu_clipboard_info_ref(info);
diff --git a/ui/gtk-clipboard.c b/ui/gtk-clipboard.c
index 35b7a2c228..44ff810234 100644
--- a/ui/gtk-clipboard.c
+++ b/ui/gtk-clipboard.c
@@ -74,10 +74,9 @@ static void gd_clipboard_clear(GtkClipboard *clipboard,
gd->cbowner[s] = false;
}
-static void gd_clipboard_notify(Notifier *notifier, void *data)
+static void gd_clipboard_update_info(GtkDisplayState *gd,
+ QemuClipboardInfo *info)
{
- GtkDisplayState *gd = container_of(notifier, GtkDisplayState, cbpeer.update);
- QemuClipboardInfo *info = data;
QemuClipboardSelection s = info->selection;
bool self_update = info->owner == &gd->cbpeer;
@@ -118,6 +117,19 @@ static void gd_clipboard_notify(Notifier *notifier, void *data)
*/
}
+static void gd_clipboard_notify(Notifier *notifier, void *data)
+{
+ GtkDisplayState *gd =
+ container_of(notifier, GtkDisplayState, cbpeer.notifier);
+ QemuClipboardNotify *notify = data;
+
+ switch (notify->type) {
+ case QEMU_CLIPBOARD_UPDATE_INFO:
+ gd_clipboard_update_info(gd, notify->info);
+ return;
+ }
+}
+
static void gd_clipboard_request(QemuClipboardInfo *info,
QemuClipboardType type)
{
@@ -172,7 +184,7 @@ static void gd_owner_change(GtkClipboard *clipboard,
void gd_clipboard_init(GtkDisplayState *gd)
{
gd->cbpeer.name = "gtk";
- gd->cbpeer.update.notify = gd_clipboard_notify;
+ gd->cbpeer.notifier.notify = gd_clipboard_notify;
gd->cbpeer.request = gd_clipboard_request;
qemu_clipboard_peer_register(&gd->cbpeer);
diff --git a/ui/vdagent.c b/ui/vdagent.c
index 64e0017001..de827aad27 100644
--- a/ui/vdagent.c
+++ b/ui/vdagent.c
@@ -417,10 +417,9 @@ static void vdagent_send_empty_clipboard_data(VDAgentChardev *vd,
vdagent_send_clipboard_data(vd, info, type);
}
-static void vdagent_clipboard_notify(Notifier *notifier, void *data)
+static void vdagent_clipboard_update_info(VDAgentChardev *vd,
+ QemuClipboardInfo *info)
{
- VDAgentChardev *vd = container_of(notifier, VDAgentChardev, cbpeer.update);
- QemuClipboardInfo *info = data;
QemuClipboardSelection s = info->selection;
QemuClipboardType type;
bool self_update = info->owner == &vd->cbpeer;
@@ -449,6 +448,19 @@ static void vdagent_clipboard_notify(Notifier *notifier, void *data)
}
}
+static void vdagent_clipboard_notify(Notifier *notifier, void *data)
+{
+ VDAgentChardev *vd =
+ container_of(notifier, VDAgentChardev, cbpeer.notifier);
+ QemuClipboardNotify *notify = data;
+
+ switch (notify->type) {
+ case QEMU_CLIPBOARD_UPDATE_INFO:
+ vdagent_clipboard_update_info(vd, notify->info);
+ return;
+ }
+}
+
static void vdagent_clipboard_request(QemuClipboardInfo *info,
QemuClipboardType qtype)
{
@@ -658,9 +670,9 @@ static void vdagent_chr_recv_caps(VDAgentChardev *vd, VDAgentMessage *msg)
if (have_mouse(vd) && vd->mouse_hs) {
qemu_input_handler_activate(vd->mouse_hs);
}
- if (have_clipboard(vd) && vd->cbpeer.update.notify == NULL) {
+ if (have_clipboard(vd) && vd->cbpeer.notifier.notify == NULL) {
vd->cbpeer.name = "vdagent";
- vd->cbpeer.update.notify = vdagent_clipboard_notify;
+ vd->cbpeer.notifier.notify = vdagent_clipboard_notify;
vd->cbpeer.request = vdagent_clipboard_request;
qemu_clipboard_peer_register(&vd->cbpeer);
}
@@ -799,7 +811,7 @@ static void vdagent_disconnect(VDAgentChardev *vd)
if (vd->mouse_hs) {
qemu_input_handler_deactivate(vd->mouse_hs);
}
- if (vd->cbpeer.update.notify) {
+ if (vd->cbpeer.notifier.notify) {
qemu_clipboard_peer_unregister(&vd->cbpeer);
memset(&vd->cbpeer, 0, sizeof(vd->cbpeer));
}
@@ -807,11 +819,8 @@ static void vdagent_disconnect(VDAgentChardev *vd)
static void vdagent_chr_set_fe_open(struct Chardev *chr, int fe_open)
{
- VDAgentChardev *vd = QEMU_VDAGENT_CHARDEV(chr);
-
if (!fe_open) {
trace_vdagent_close();
- vdagent_disconnect(vd);
return;
}
diff --git a/ui/vnc-clipboard.c b/ui/vnc-clipboard.c
index 9f077965d0..41aeff1085 100644
--- a/ui/vnc-clipboard.c
+++ b/ui/vnc-clipboard.c
@@ -189,10 +189,8 @@ static void vnc_clipboard_provide(VncState *vs,
vnc_flush(vs);
}
-static void vnc_clipboard_notify(Notifier *notifier, void *data)
+static void vnc_clipboard_update_info(VncState *vs, QemuClipboardInfo *info)
{
- VncState *vs = container_of(notifier, VncState, cbpeer.update);
- QemuClipboardInfo *info = data;
QemuClipboardType type;
bool self_update = info->owner == &vs->cbpeer;
uint32_t flags = 0;
@@ -223,6 +221,18 @@ static void vnc_clipboard_notify(Notifier *notifier, void *data)
}
}
+static void vnc_clipboard_notify(Notifier *notifier, void *data)
+{
+ VncState *vs = container_of(notifier, VncState, cbpeer.notifier);
+ QemuClipboardNotify *notify = data;
+
+ switch (notify->type) {
+ case QEMU_CLIPBOARD_UPDATE_INFO:
+ vnc_clipboard_update_info(vs, notify->info);
+ return;
+ }
+}
+
static void vnc_clipboard_request(QemuClipboardInfo *info,
QemuClipboardType type)
{
@@ -317,7 +327,7 @@ void vnc_server_cut_text_caps(VncState *vs)
vnc_clipboard_send(vs, 2, caps);
vs->cbpeer.name = "vnc";
- vs->cbpeer.update.notify = vnc_clipboard_notify;
+ vs->cbpeer.notifier.notify = vnc_clipboard_notify;
vs->cbpeer.request = vnc_clipboard_request;
qemu_clipboard_peer_register(&vs->cbpeer);
}
diff --git a/ui/vnc.c b/ui/vnc.c
index af02522e84..9b603382e7 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -1354,7 +1354,7 @@ void vnc_disconnect_finish(VncState *vs)
/* last client gone */
vnc_update_server_surface(vs->vd);
}
- if (vs->cbpeer.update.notify) {
+ if (vs->cbpeer.notifier.notify) {
qemu_clipboard_peer_unregister(&vs->cbpeer);
}
diff --git a/ui/cocoa.m b/ui/cocoa.m
index 68a6302184..6745e3fc8c 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -1808,14 +1808,12 @@ static void cocoa_clipboard_request(QemuClipboardInfo *info,
static QemuClipboardPeer cbpeer = {
.name = "cocoa",
- .update = { .notify = cocoa_clipboard_notify },
+ .notifier = { .notify = cocoa_clipboard_notify },
.request = cocoa_clipboard_request
};
-static void cocoa_clipboard_notify(Notifier *notifier, void *data)
+static void cocoa_clipboard_update_info(QemuClipboardInfo *info)
{
- QemuClipboardInfo *info = data;
-
if (info->owner == &cbpeer || info->selection != QEMU_CLIPBOARD_SELECTION_CLIPBOARD) {
return;
}
@@ -1831,6 +1829,17 @@ static void cocoa_clipboard_notify(Notifier *notifier, void *data)
qemu_event_set(&cbevent);
}
+static void cocoa_clipboard_notify(Notifier *notifier, void *data)
+{
+ QemuClipboardNotify *notify = data;
+
+ switch (notify->event) {
+ case QEMU_CLIPBOARD_UPDATE_INFO:
+ cocoa_clipboard_update_info(notify->info);
+ return;
+ }
+}
+
static void cocoa_clipboard_request(QemuClipboardInfo *info,
QemuClipboardType type)
{
--
2.33.0.721.g106298f7f9
next prev parent reply other threads:[~2021-10-09 21:13 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-09 21:08 [PATCH v2 00/37] Add D-Bus display backend marcandre.lureau
2021-10-09 21:08 ` [PATCH v2 01/37] build-sys: move Spice configure handling to meson marcandre.lureau
2021-10-09 21:08 ` [PATCH v2 02/37] ui/vdagent: add CHECK_SPICE_PROTOCOL_VERSION marcandre.lureau
2021-10-09 21:08 ` [PATCH v2 03/37] ui/vdagent: replace #if 0 with protocol version check marcandre.lureau
2021-10-09 21:08 ` marcandre.lureau [this message]
2021-10-09 21:08 ` [PATCH v2 05/37] ui/vdagent: add serial capability support marcandre.lureau
2021-10-09 21:08 ` [PATCH v2 06/37] ui/clipboard: add qemu_clipboard_check_serial() marcandre.lureau
2021-10-09 21:08 ` [PATCH v2 07/37] ui/clipboard: add a clipboard reset serial event marcandre.lureau
2021-10-09 21:08 ` [PATCH v2 08/37] hw/display: report an error if virgl initialization failed marcandre.lureau
2021-12-17 12:40 ` Philippe Mathieu-Daudé
2021-10-09 21:08 ` [PATCH v2 09/37] virtio-gpu: use VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP marcandre.lureau
2021-12-17 12:51 ` Philippe Mathieu-Daudé
2021-10-09 21:08 ` [PATCH v2 10/37] ui: do not delay further remote resize marcandre.lureau
2021-10-09 21:08 ` [PATCH v2 11/37] ui: factor out qemu_console_set_display_gl_ctx() marcandre.lureau
2021-12-17 13:36 ` Philippe Mathieu-Daudé
2021-10-09 21:08 ` [PATCH v2 12/37] ui: associate GL context outside of display listener registration marcandre.lureau
2021-10-09 21:08 ` [PATCH v2 13/37] ui: make gl_block use a counter marcandre.lureau
2021-10-09 21:08 ` [PATCH v2 14/37] ui: add a gl-unblock warning timer marcandre.lureau
2021-10-09 21:08 ` [PATCH v2 15/37] ui: simplify gl unblock & flush marcandre.lureau
2021-10-09 21:08 ` [PATCH v2 16/37] ui: dispatch GL events to all listeners marcandre.lureau
2021-10-09 21:08 ` [PATCH v2 17/37] ui: split the GL context in a different object marcandre.lureau
2021-10-09 21:08 ` [PATCH v2 18/37] ui: move qemu_spice_fill_device_address to ui/util.c marcandre.lureau
2021-10-09 21:08 ` [PATCH v2 19/37] console: save current scanout details marcandre.lureau
2022-01-11 3:29 ` Akihiko Odaki
2022-01-11 8:23 ` Marc-André Lureau
2022-01-11 12:45 ` Akihiko Odaki
2021-10-09 21:08 ` [PATCH v2 20/37] scripts: teach modinfo to skip non-C sources marcandre.lureau
2021-10-09 21:08 ` [PATCH v2 21/37] docs/sphinx: add sphinx modules to include D-Bus documentation marcandre.lureau
2021-10-09 21:08 ` [PATCH v2 22/37] backends: move dbus-vmstate1.xml to backends/ marcandre.lureau
2021-10-09 21:08 ` [PATCH v2 23/37] docs: move D-Bus VMState documentation to source XML marcandre.lureau
2021-10-09 21:08 ` [PATCH v2 24/37] docs: add dbus-display documentation marcandre.lureau
2021-10-09 21:08 ` [PATCH v2 25/37] build-sys: set glib dependency version marcandre.lureau
2021-12-17 13:27 ` Philippe Mathieu-Daudé
2021-12-17 13:40 ` Marc-André Lureau
2021-12-17 14:36 ` Philippe Mathieu-Daudé
2021-10-09 21:08 ` [PATCH v2 26/37] ui: add a D-Bus display backend marcandre.lureau
2021-10-13 8:59 ` Marc-André Lureau
2021-10-09 21:08 ` [PATCH v2 27/37] ui/dbus: add p2p=on/off option marcandre.lureau
2021-10-09 21:08 ` [PATCH v2 28/37] tests/qtests: add qtest_qmp_add_client() marcandre.lureau
2021-10-09 21:08 ` [PATCH v2 29/37] tests: start dbus-display-test marcandre.lureau
2021-10-09 21:08 ` [PATCH v2 30/37] audio: add "dbus" audio backend marcandre.lureau
2021-10-09 21:08 ` [PATCH v2 31/37] ui/dbus: add clipboard interface marcandre.lureau
2021-10-09 21:08 ` [PATCH v2 32/37] chardev: teach socket to accept no addresses marcandre.lureau
2021-10-09 21:08 ` [PATCH v2 33/37] chardev: make socket derivable marcandre.lureau
2021-12-17 13:32 ` Philippe Mathieu-Daudé
2021-10-09 21:08 ` [PATCH v2 34/37] option: add g_auto for QemuOpts marcandre.lureau
2021-10-09 21:08 ` [PATCH v2 35/37] ui/dbus: add chardev backend & interface marcandre.lureau
2021-10-09 21:08 ` [PATCH v2 36/37] ui/dbus: register D-Bus VC handler marcandre.lureau
2021-12-17 13:35 ` Philippe Mathieu-Daudé
2021-12-17 14:21 ` Marc-André Lureau
2021-10-09 21:08 ` [PATCH v2 37/37] MAINTAINERS: update D-Bus section marcandre.lureau
2021-10-13 5:22 ` [PATCH v2 00/37] Add D-Bus display backend Gerd Hoffmann
2021-12-16 20:53 ` Marc-André Lureau
2021-12-17 7:05 ` Gerd Hoffmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211009210838.2219430-5-marcandre.lureau@redhat.com \
--to=marcandre.lureau@redhat.com \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).