On 10/31/26 08:23, [email protected] wrote:
Add a "guest" flag to QemuClipboardPeer and set it on vdagent peer.

Use the flag to keep track of number of registered guest peers and
allow to query for their presence with
qemu_clipboard_guest_peer_present().

This change makes it possible for a clipboard peer to determine if
any guest side peers are present so they can tell whether a guest is
actually able to participate in clipboard exchange.

Signed-off-by: Lukasz Kornicki <[email protected]>
Message-ID: <[email protected]>
---
  include/ui/clipboard.h |  9 +++++++++
  ui/clipboard.c         | 17 +++++++++++++++++
  ui/vdagent.c           |  1 +
  3 files changed, 27 insertions(+)

diff --git a/include/ui/clipboard.h b/include/ui/clipboard.h
index 6166af513906..250f1d8ea53e 100644
--- a/include/ui/clipboard.h
+++ b/include/ui/clipboard.h
@@ -62,6 +62,7 @@ enum QemuClipboardSelection {
   * struct QemuClipboardPeer
   *
   * @name: peer name.
+ * @guest: is peer guest side.
   * @notifier: notifier for clipboard updates.
   * @request: callback for clipboard data requests.
   *
@@ -69,6 +70,7 @@ enum QemuClipboardSelection {
   */
  struct QemuClipboardPeer {
      const char *name;
+    bool guest;
      Notifier notifier;
      void (*request)(QemuClipboardInfo *info,
                      QemuClipboardType type);
@@ -179,6 +181,13 @@ void qemu_clipboard_peer_register(QemuClipboardPeer *peer);
   */
  void qemu_clipboard_peer_unregister(QemuClipboardPeer *peer);
+/**
+ * qemu_clipboard_guest_peer_present
+ *
+ * Return TRUE if a guest side clipboard peer is currently registered.
+ */
+bool qemu_clipboard_guest_peer_present(void);
+
  /**
   * qemu_clipboard_peer_owns
   *
diff --git a/ui/clipboard.c b/ui/clipboard.c
index 3d8f58a85508..f750b494eb6b 100644
--- a/ui/clipboard.c
+++ b/ui/clipboard.c
@@ -12,6 +12,8 @@ static VMChangeStateEntry *cb_change_state_entry = NULL;
static bool cb_reset_serial_on_resume = false; +static int guest_peer_count;
Rather than adding an extra global (that must be sync), why not simply
iterate the clipboard_notifiers?

Reviewed-by: Marc-AndrĂ© Lureau <[email protected]>

Good question. I wasn't positive if it was thread safe to walk the list at the time, hence going with a global counter felt like a safer bet since there are others like it.

It looks like this is not an issue and cost of recomputing seems reasonable.
Since the series was pulled, should I send in a separate patch fixing this?


Reply via email to