All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/2] Fix and re-enable GTK clipboard
@ 2026-04-26  7:52 Jindřich Makovička
  2026-04-26  7:52 ` [PATCH v3 1/2] ui/gtk: Use non-blocking clipboard retrieval Jindřich Makovička
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Jindřich Makovička @ 2026-04-26  7:52 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Paolo Bonzini, Daniel P. Berrangé,
	Philippe Mathieu-Daudé, Pierrick Bouvier, Jindrich Makovicka

The following patches change blocking clipboard retrieval function
calls in gtk-clipboard.c to non-blocking variants using callbacks to
avoid UI lockup. It is a follow-up to the patch proposed in the GitLab
issue

https://gitlab.com/qemu-project/qemu/-/work_items/1150

This version adds a similar change to gd_clipboard_request that also
uses the blocking clipboard API.

The second patch removes the gtk-clipboard flag, keeping the GTK
clipboard always enabled.

Signed-off-by: Jindrich Makovicka <makovick@gmail.com>
---
Changes in v3:
- Use gtk_clipboard_request_contents to avoid text conversion
  when we only need to check if the text is available.
- Link to v2: https://lore.kernel.org/qemu-devel/20260425-gtk-clipboard-v2-0-b098f3cf69cc@gmail.com

Changes in v2:
- Removed forgotten gtk-clipboard comment in meson_options.txt
- Link to v1: https://lore.kernel.org/qemu-devel/20260425-gtk-clipboard-v1-0-6bd99e708e14@gmail.com

---
Jindřich Makovička (2):
      ui/gtk: Use non-blocking clipboard retrieval
      ui/gtk: Keep GTK clipboard enabled

 meson.build        |  4 ----
 meson_options.txt  |  7 -------
 ui/gtk-clipboard.c | 52 +++++++++++++++++++++++++++++++++++++++-------------
 ui/gtk.c           |  2 --
 ui/meson.build     |  4 +---
 5 files changed, 40 insertions(+), 29 deletions(-)
---
base-commit: aa15257174da180c6a8a9d58f87319cfe61c5520
change-id: 20260425-gtk-clipboard-fdf99db13ac0

Best regards,
-- 
Jindrich Makovicka



^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v3 1/2] ui/gtk: Use non-blocking clipboard retrieval
  2026-04-26  7:52 [PATCH v3 0/2] Fix and re-enable GTK clipboard Jindřich Makovička
@ 2026-04-26  7:52 ` Jindřich Makovička
  2026-04-27  8:47   ` Marc-André Lureau
  2026-04-27  8:52   ` Marc-André Lureau
  2026-04-26  7:52 ` [PATCH v3 2/2] ui/gtk: Keep GTK clipboard enabled Jindřich Makovička
  2026-04-27  8:56 ` [PATCH v3 0/2] Fix and re-enable GTK clipboard Daniel P. Berrangé
  2 siblings, 2 replies; 10+ messages in thread
From: Jindřich Makovička @ 2026-04-26  7:52 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Paolo Bonzini, Daniel P. Berrangé,
	Philippe Mathieu-Daudé, Pierrick Bouvier, Jindrich Makovicka

Signed-off-by: Jindrich Makovicka <makovick@gmail.com>
---
 ui/gtk-clipboard.c | 52 +++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 39 insertions(+), 13 deletions(-)

diff --git a/ui/gtk-clipboard.c b/ui/gtk-clipboard.c
index 65d89ec601..691784697d 100644
--- a/ui/gtk-clipboard.c
+++ b/ui/gtk-clipboard.c
@@ -136,26 +136,54 @@ static void gd_clipboard_notify(Notifier *notifier, void *data)
     }
 }
 
+static void
+gd_clipboard_request_text_received_callback(GtkClipboard *clipboard,
+                                            const gchar *text,
+                                            gpointer data)
+{
+    QemuClipboardInfo *info = (QemuClipboardInfo *)data;
+
+    if (text) {
+        qemu_clipboard_set_data(info->owner, info, QEMU_CLIPBOARD_TYPE_TEXT,
+                                strlen(text), text, true);
+    }
+    qemu_clipboard_info_unref(info);
+}
+
 static void gd_clipboard_request(QemuClipboardInfo *info,
                                  QemuClipboardType type)
 {
     GtkDisplayState *gd = container_of(info->owner, GtkDisplayState, cbpeer);
-    char *text;
 
     switch (type) {
     case QEMU_CLIPBOARD_TYPE_TEXT:
-        text = gtk_clipboard_wait_for_text(gd->gtkcb[info->selection]);
-        if (text) {
-            qemu_clipboard_set_data(&gd->cbpeer, info, type,
-                                    strlen(text), text, true);
-            g_free(text);
-        }
+        qemu_clipboard_info_ref(info);
+        gtk_clipboard_request_text(gd->gtkcb[info->selection],
+                                   gd_clipboard_request_text_received_callback,
+                                   info);
         break;
     default:
         break;
     }
 }
 
+static void gd_clipboard_owner_change_contents_received_callback(
+    GtkClipboard *clipboard,
+    GtkSelectionData *selection_data,
+    gpointer data)
+{
+    QemuClipboardInfo *info = (QemuClipboardInfo *)data;
+
+    if (selection_data) {
+        if (gtk_selection_data_targets_include_text(selection_data)) {
+            info->types[QEMU_CLIPBOARD_TYPE_TEXT].available = true;
+        }
+    }
+
+    qemu_clipboard_update(info);
+    qemu_clipboard_info_unref(info);
+}
+
 static void gd_owner_change(GtkClipboard *clipboard,
                             GdkEvent *event,
                             gpointer data)
@@ -173,12 +201,10 @@ static void gd_owner_change(GtkClipboard *clipboard,
     switch (event->owner_change.reason) {
     case GDK_OWNER_CHANGE_NEW_OWNER:
         info = qemu_clipboard_info_new(&gd->cbpeer, s);
-        if (gtk_clipboard_wait_is_text_available(clipboard)) {
-            info->types[QEMU_CLIPBOARD_TYPE_TEXT].available = true;
-        }
-
-        qemu_clipboard_update(info);
-        qemu_clipboard_info_unref(info);
+        gtk_clipboard_request_contents(
+            clipboard, gdk_atom_intern_static_string("TARGETS"),
+            gd_clipboard_owner_change_contents_received_callback,
+            info);
         break;
     default:
         qemu_clipboard_peer_release(&gd->cbpeer, s);

-- 
2.53.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v3 2/2] ui/gtk: Keep GTK clipboard enabled
  2026-04-26  7:52 [PATCH v3 0/2] Fix and re-enable GTK clipboard Jindřich Makovička
  2026-04-26  7:52 ` [PATCH v3 1/2] ui/gtk: Use non-blocking clipboard retrieval Jindřich Makovička
@ 2026-04-26  7:52 ` Jindřich Makovička
  2026-04-27  8:56 ` [PATCH v3 0/2] Fix and re-enable GTK clipboard Daniel P. Berrangé
  2 siblings, 0 replies; 10+ messages in thread
From: Jindřich Makovička @ 2026-04-26  7:52 UTC (permalink / raw)
  To: qemu-devel
  Cc: Marc-André Lureau, Paolo Bonzini, Daniel P. Berrangé,
	Philippe Mathieu-Daudé, Pierrick Bouvier, Jindrich Makovicka

Signed-off-by: Jindrich Makovicka <makovick@gmail.com>
---
 meson.build       | 4 ----
 meson_options.txt | 7 -------
 ui/gtk.c          | 2 --
 ui/meson.build    | 4 +---
 4 files changed, 1 insertion(+), 16 deletions(-)

diff --git a/meson.build b/meson.build
index 096303f021..761c0436a3 100644
--- a/meson.build
+++ b/meson.build
@@ -1932,7 +1932,6 @@ endif
 gtk = not_found
 gtkx11 = not_found
 vte = not_found
-have_gtk_clipboard = get_option('gtk_clipboard').enabled()
 
 if get_option('gtk') \
              .disable_auto_if(not have_system) \
@@ -1954,8 +1953,6 @@ if get_option('gtk') \
                        method: 'pkg-config',
                        required: get_option('vte'))
     endif
-  elif have_gtk_clipboard
-    error('GTK clipboard requested, but GTK not found')
   endif
 endif
 
@@ -2475,7 +2472,6 @@ if glusterfs.found()
 endif
 config_host_data.set('CONFIG_GTK', gtk.found())
 config_host_data.set('CONFIG_VTE', vte.found())
-config_host_data.set('CONFIG_GTK_CLIPBOARD', have_gtk_clipboard)
 config_host_data.set('CONFIG_HEXAGON_IDEF_PARSER', get_option('hexagon_idef_parser'))
 config_host_data.set('CONFIG_LIBATTR', have_old_libattr)
 config_host_data.set('CONFIG_LIBCAP_NG', libcap_ng.found())
diff --git a/meson_options.txt b/meson_options.txt
index 31d5916cfc..286461129b 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -262,13 +262,6 @@ option('vnc_sasl', type : 'feature', value : 'auto',
        description: 'SASL authentication for VNC server')
 option('vte', type : 'feature', value : 'auto',
        description: 'vte support for the gtk UI')
-
-# GTK Clipboard implementation is disabled by default, since it may cause hangs
-# of the guest VCPUs. See gitlab issue 1150:
-# https://gitlab.com/qemu-project/qemu/-/issues/1150
-
-option('gtk_clipboard', type: 'feature', value : 'disabled',
-       description: 'clipboard support for the gtk UI (EXPERIMENTAL, MAY HANG)')
 option('xkbcommon', type : 'feature', value : 'auto',
        description: 'xkbcommon support')
 option('zstd', type : 'feature', value : 'auto',
diff --git a/ui/gtk.c b/ui/gtk.c
index 9ebe7e8df0..5e63c502ed 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -2601,9 +2601,7 @@ static void gtk_display_init(DisplayState *ds, DisplayOptions *opts)
         opts->u.gtk.show_tabs) {
         gtk_menu_item_activate(GTK_MENU_ITEM(s->show_tabs_item));
     }
-#ifdef CONFIG_GTK_CLIPBOARD
     gd_clipboard_init(s);
-#endif /* CONFIG_GTK_CLIPBOARD */
 
     /* GTK's event polling must happen on the main thread. */
     qemu_main = NULL;
diff --git a/ui/meson.build b/ui/meson.build
index 4e533d3046..6405e21d5d 100644
--- a/ui/meson.build
+++ b/ui/meson.build
@@ -111,9 +111,7 @@ if gtk.found()
 
   gtk_ss = ss.source_set()
   gtk_ss.add(gtk, vte, pixman, files('gtk.c'))
-  if have_gtk_clipboard
-    gtk_ss.add(files('gtk-clipboard.c'))
-  endif
+  gtk_ss.add(files('gtk-clipboard.c'))
   gtk_ss.add(when: x11, if_true: files('x_keymap.c'))
   gtk_ss.add(when: opengl, if_true: files('gtk-gl-area.c'))
   gtk_ss.add(when: [x11, opengl], if_true: files('gtk-egl.c'))

-- 
2.53.0



^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v3 1/2] ui/gtk: Use non-blocking clipboard retrieval
  2026-04-26  7:52 ` [PATCH v3 1/2] ui/gtk: Use non-blocking clipboard retrieval Jindřich Makovička
@ 2026-04-27  8:47   ` Marc-André Lureau
  2026-04-27 19:40     ` Jindrich Makovicka
  2026-04-27  8:52   ` Marc-André Lureau
  1 sibling, 1 reply; 10+ messages in thread
From: Marc-André Lureau @ 2026-04-27  8:47 UTC (permalink / raw)
  To: Jindřich Makovička
  Cc: qemu-devel, Paolo Bonzini, Daniel P. Berrangé,
	Philippe Mathieu-Daudé, Pierrick Bouvier

Hi

On Sun, Apr 26, 2026 at 11:52 AM Jindřich Makovička <makovick@gmail.com> wrote:
>
> Signed-off-by: Jindrich Makovicka <makovick@gmail.com>
> ---
>  ui/gtk-clipboard.c | 52 +++++++++++++++++++++++++++++++++++++++-------------
>  1 file changed, 39 insertions(+), 13 deletions(-)
>
> diff --git a/ui/gtk-clipboard.c b/ui/gtk-clipboard.c
> index 65d89ec601..691784697d 100644
> --- a/ui/gtk-clipboard.c
> +++ b/ui/gtk-clipboard.c
> @@ -136,26 +136,54 @@ static void gd_clipboard_notify(Notifier *notifier, void *data)
>      }
>  }
>
> +static void
> +gd_clipboard_request_text_received_callback(GtkClipboard *clipboard,
> +                                            const gchar *text,
> +                                            gpointer data)
> +{
> +    QemuClipboardInfo *info = (QemuClipboardInfo *)data;
> +
> +    if (text) {
> +        qemu_clipboard_set_data(info->owner, info, QEMU_CLIPBOARD_TYPE_TEXT,
> +                                strlen(text), text, true);
> +    }
> +    qemu_clipboard_info_unref(info);
> +}
> +
>  static void gd_clipboard_request(QemuClipboardInfo *info,
>                                   QemuClipboardType type)
>  {
>      GtkDisplayState *gd = container_of(info->owner, GtkDisplayState, cbpeer);
> -    char *text;
>
>      switch (type) {
>      case QEMU_CLIPBOARD_TYPE_TEXT:
> -        text = gtk_clipboard_wait_for_text(gd->gtkcb[info->selection]);
> -        if (text) {
> -            qemu_clipboard_set_data(&gd->cbpeer, info, type,
> -                                    strlen(text), text, true);
> -            g_free(text);
> -        }
> +        qemu_clipboard_info_ref(info);
> +        gtk_clipboard_request_text(gd->gtkcb[info->selection],
> +                                   gd_clipboard_request_text_received_callback,
> +                                   info);
>          break;
>      default:
>          break;
>      }
>  }
>
> +static void gd_clipboard_owner_change_contents_received_callback(
> +    GtkClipboard *clipboard,
> +    GtkSelectionData *selection_data,
> +    gpointer data)
> +{
> +    QemuClipboardInfo *info = (QemuClipboardInfo *)data;
> +
> +    if (selection_data) {
> +        if (gtk_selection_data_targets_include_text(selection_data)) {
> +            info->types[QEMU_CLIPBOARD_TYPE_TEXT].available = true;
> +        }
> +    }
> +
> +    qemu_clipboard_update(info);
> +    qemu_clipboard_info_unref(info);
> +}
> +
>  static void gd_owner_change(GtkClipboard *clipboard,
>                              GdkEvent *event,
>                              gpointer data)
> @@ -173,12 +201,10 @@ static void gd_owner_change(GtkClipboard *clipboard,
>      switch (event->owner_change.reason) {
>      case GDK_OWNER_CHANGE_NEW_OWNER:
>          info = qemu_clipboard_info_new(&gd->cbpeer, s);
> -        if (gtk_clipboard_wait_is_text_available(clipboard)) {
> -            info->types[QEMU_CLIPBOARD_TYPE_TEXT].available = true;
> -        }
> -
> -        qemu_clipboard_update(info);
> -        qemu_clipboard_info_unref(info);
> +        gtk_clipboard_request_contents(
> +            clipboard, gdk_atom_intern_static_string("TARGETS"),
> +            gd_clipboard_owner_change_contents_received_callback,
> +            info);

could you use gtk_clipboard_request_targets instead?

lgtm otherwise

>          break;
>      default:
>          qemu_clipboard_peer_release(&gd->cbpeer, s);
>
> --
> 2.53.0
>



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v3 1/2] ui/gtk: Use non-blocking clipboard retrieval
  2026-04-26  7:52 ` [PATCH v3 1/2] ui/gtk: Use non-blocking clipboard retrieval Jindřich Makovička
  2026-04-27  8:47   ` Marc-André Lureau
@ 2026-04-27  8:52   ` Marc-André Lureau
  2026-04-27 19:26     ` Jindrich Makovicka
  1 sibling, 1 reply; 10+ messages in thread
From: Marc-André Lureau @ 2026-04-27  8:52 UTC (permalink / raw)
  To: Jindřich Makovička
  Cc: qemu-devel, Paolo Bonzini, Daniel P. Berrangé,
	Philippe Mathieu-Daudé, Pierrick Bouvier

Hi Jindřich

On Sun, Apr 26, 2026 at 11:53 AM Jindřich Makovička <makovick@gmail.com> wrote:
>

Could you review & compare with the previous lost patch ("[PATCH v4]
ui/gtk-clipboard: async owner_change clipboard_request")

https://patchew.org/QEMU/20231206142243.510068-1-edmund.raile@proton.me/

thanks

> Signed-off-by: Jindrich Makovicka <makovick@gmail.com>
> ---
>  ui/gtk-clipboard.c | 52 +++++++++++++++++++++++++++++++++++++++-------------
>  1 file changed, 39 insertions(+), 13 deletions(-)
>
> diff --git a/ui/gtk-clipboard.c b/ui/gtk-clipboard.c
> index 65d89ec601..691784697d 100644
> --- a/ui/gtk-clipboard.c
> +++ b/ui/gtk-clipboard.c
> @@ -136,26 +136,54 @@ static void gd_clipboard_notify(Notifier *notifier, void *data)
>      }
>  }
>
> +static void
> +gd_clipboard_request_text_received_callback(GtkClipboard *clipboard,
> +                                            const gchar *text,
> +                                            gpointer data)
> +{
> +    QemuClipboardInfo *info = (QemuClipboardInfo *)data;
> +
> +    if (text) {
> +        qemu_clipboard_set_data(info->owner, info, QEMU_CLIPBOARD_TYPE_TEXT,
> +                                strlen(text), text, true);
> +    }
> +    qemu_clipboard_info_unref(info);
> +}
> +
>  static void gd_clipboard_request(QemuClipboardInfo *info,
>                                   QemuClipboardType type)
>  {
>      GtkDisplayState *gd = container_of(info->owner, GtkDisplayState, cbpeer);
> -    char *text;
>
>      switch (type) {
>      case QEMU_CLIPBOARD_TYPE_TEXT:
> -        text = gtk_clipboard_wait_for_text(gd->gtkcb[info->selection]);
> -        if (text) {
> -            qemu_clipboard_set_data(&gd->cbpeer, info, type,
> -                                    strlen(text), text, true);
> -            g_free(text);
> -        }
> +        qemu_clipboard_info_ref(info);
> +        gtk_clipboard_request_text(gd->gtkcb[info->selection],
> +                                   gd_clipboard_request_text_received_callback,
> +                                   info);
>          break;
>      default:
>          break;
>      }
>  }
>
> +static void gd_clipboard_owner_change_contents_received_callback(
> +    GtkClipboard *clipboard,
> +    GtkSelectionData *selection_data,
> +    gpointer data)
> +{
> +    QemuClipboardInfo *info = (QemuClipboardInfo *)data;
> +
> +    if (selection_data) {
> +        if (gtk_selection_data_targets_include_text(selection_data)) {
> +            info->types[QEMU_CLIPBOARD_TYPE_TEXT].available = true;
> +        }
> +    }
> +
> +    qemu_clipboard_update(info);
> +    qemu_clipboard_info_unref(info);
> +}
> +
>  static void gd_owner_change(GtkClipboard *clipboard,
>                              GdkEvent *event,
>                              gpointer data)
> @@ -173,12 +201,10 @@ static void gd_owner_change(GtkClipboard *clipboard,
>      switch (event->owner_change.reason) {
>      case GDK_OWNER_CHANGE_NEW_OWNER:
>          info = qemu_clipboard_info_new(&gd->cbpeer, s);
> -        if (gtk_clipboard_wait_is_text_available(clipboard)) {
> -            info->types[QEMU_CLIPBOARD_TYPE_TEXT].available = true;
> -        }
> -
> -        qemu_clipboard_update(info);
> -        qemu_clipboard_info_unref(info);
> +        gtk_clipboard_request_contents(
> +            clipboard, gdk_atom_intern_static_string("TARGETS"),
> +            gd_clipboard_owner_change_contents_received_callback,
> +            info);
>          break;
>      default:
>          qemu_clipboard_peer_release(&gd->cbpeer, s);
>
> --
> 2.53.0
>
>


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v3 0/2] Fix and re-enable GTK clipboard
  2026-04-26  7:52 [PATCH v3 0/2] Fix and re-enable GTK clipboard Jindřich Makovička
  2026-04-26  7:52 ` [PATCH v3 1/2] ui/gtk: Use non-blocking clipboard retrieval Jindřich Makovička
  2026-04-26  7:52 ` [PATCH v3 2/2] ui/gtk: Keep GTK clipboard enabled Jindřich Makovička
@ 2026-04-27  8:56 ` Daniel P. Berrangé
  2026-04-27 20:10   ` Jindrich Makovicka
  2 siblings, 1 reply; 10+ messages in thread
From: Daniel P. Berrangé @ 2026-04-27  8:56 UTC (permalink / raw)
  To: Jindřich Makovička
  Cc: qemu-devel, Marc-André Lureau, Paolo Bonzini,
	Philippe Mathieu-Daudé, Pierrick Bouvier

On Sun, Apr 26, 2026 at 09:52:32AM +0200, Jindřich Makovička wrote:
> The following patches change blocking clipboard retrieval function
> calls in gtk-clipboard.c to non-blocking variants using callbacks to
> avoid UI lockup. It is a follow-up to the patch proposed in the GitLab
> issue
> 
> https://gitlab.com/qemu-project/qemu/-/work_items/1150
> 
> This version adds a similar change to gd_clipboard_request that also
> uses the blocking clipboard API.
> 
> The second patch removes the gtk-clipboard flag, keeping the GTK
> clipboard always enabled.

I notice that the current code in git does not provide any command line
option to turn on/off the GTK clipboard sync.  Considering that VMs are
often used for untrusted workloads, or workloads that are less trusted
then the host OS, I would consider this GTK impl to be a security flaw
in QEMU if re-enabled as-is.

IMHO, before we remove the ifdefs in the code, the "DisplayGTK"  struct
needs to gain settings to control the clipboard synchronization, and it
should default to disabled.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v3 1/2] ui/gtk: Use non-blocking clipboard retrieval
  2026-04-27  8:52   ` Marc-André Lureau
@ 2026-04-27 19:26     ` Jindrich Makovicka
  2026-04-28  5:59       ` Jindrich Makovicka
  0 siblings, 1 reply; 10+ messages in thread
From: Jindrich Makovicka @ 2026-04-27 19:26 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel, Paolo Bonzini, Daniel P. Berrangé,
	Philippe Mathieu-Daudé, Pierrick Bouvier

Hi,

On Mon, 2026-04-27 at 12:52 +0400, Marc-André Lureau wrote:
> Hi Jindřich
> 
> On Sun, Apr 26, 2026 at 11:53 AM Jindřich Makovička
> <makovick@gmail.com> wrote:
> > 
> 
> Could you review & compare with the previous lost patch ("[PATCH v4]
> ui/gtk-clipboard: async owner_change clipboard_request")
> 
> https://patchew.org/QEMU/20231206142243.510068-1-edmund.raile@proton.me/

The GTK part of this patch is basically my v2, with both paths using 
gtk_clipboard_request_text .

Then there is the serial number checking I am not familiar
with. However, qemu_clipboard_check_serial seems to require info-
>has_serial set to true which is not done in this patch (only info-
>serial is set) so this half of serial number check is effectively no-
op.

Regards,
-- 
Jindrich Makovicka


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v3 1/2] ui/gtk: Use non-blocking clipboard retrieval
  2026-04-27  8:47   ` Marc-André Lureau
@ 2026-04-27 19:40     ` Jindrich Makovicka
  0 siblings, 0 replies; 10+ messages in thread
From: Jindrich Makovicka @ 2026-04-27 19:40 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel, Paolo Bonzini, Daniel P. Berrangé,
	Philippe Mathieu-Daudé, Pierrick Bouvier

Hi,

On Mon, 2026-04-27 at 12:47 +0400, Marc-André Lureau wrote:
> Hi
> >  static void gd_owner_change(GtkClipboard *clipboard,
> >                              GdkEvent *event,
> >                              gpointer data)
> > @@ -173,12 +201,10 @@ static void gd_owner_change(GtkClipboard
> > *clipboard,
> >      switch (event->owner_change.reason) {
> >      case GDK_OWNER_CHANGE_NEW_OWNER:
> >          info = qemu_clipboard_info_new(&gd->cbpeer, s);
> > -        if (gtk_clipboard_wait_is_text_available(clipboard)) {
> > -            info->types[QEMU_CLIPBOARD_TYPE_TEXT].available =
> > true;
> > -        }
> > -
> > -        qemu_clipboard_update(info);
> > -        qemu_clipboard_info_unref(info);
> > +        gtk_clipboard_request_contents(
> > +            clipboard, gdk_atom_intern_static_string("TARGETS"),
> > +            gd_clipboard_owner_change_contents_received_callback,
> > +            info);
> 
> could you use gtk_clipboard_request_targets instead?
> 
> lgtm otherwise

Sent as v4 .

Regards,
-- 
Jindrich Makovicka

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v3 0/2] Fix and re-enable GTK clipboard
  2026-04-27  8:56 ` [PATCH v3 0/2] Fix and re-enable GTK clipboard Daniel P. Berrangé
@ 2026-04-27 20:10   ` Jindrich Makovicka
  0 siblings, 0 replies; 10+ messages in thread
From: Jindrich Makovicka @ 2026-04-27 20:10 UTC (permalink / raw)
  To: Daniel P. Berrangé
  Cc: qemu-devel, Marc-André Lureau, Paolo Bonzini,
	Philippe Mathieu-Daudé, Pierrick Bouvier

Hi,

On Mon, 2026-04-27 at 09:56 +0100, Daniel P. Berrangé wrote:
> I notice that the current code in git does not provide any command
> line
> option to turn on/off the GTK clipboard sync.  Considering that VMs
> are
> often used for untrusted workloads, or workloads that are less
> trusted
> then the host OS, I would consider this GTK impl to be a security
> flaw
> in QEMU if re-enabled as-is.
> 
> IMHO, before we remove the ifdefs in the code, the "DisplayGTK" 
> struct
> needs to gain settings to control the clipboard synchronization, and
> it
> should default to disabled.

I added the option to the second patch in v5. Qemu now needs

-display gtk,clipboard=on

to turn the clipboard sharing on.

Regards,
-- 
Jindrich Makovicka


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v3 1/2] ui/gtk: Use non-blocking clipboard retrieval
  2026-04-27 19:26     ` Jindrich Makovicka
@ 2026-04-28  5:59       ` Jindrich Makovicka
  0 siblings, 0 replies; 10+ messages in thread
From: Jindrich Makovicka @ 2026-04-28  5:59 UTC (permalink / raw)
  To: Marc-André Lureau
  Cc: qemu-devel, Paolo Bonzini, Daniel P. Berrangé,
	Philippe Mathieu-Daudé, Pierrick Bouvier

On Mon, 2026-04-27 at 21:26 +0200, Jindrich Makovicka wrote:
> Hi,
> 
> On Mon, 2026-04-27 at 12:52 +0400, Marc-André Lureau wrote:
> > Hi Jindřich
> > 
> > On Sun, Apr 26, 2026 at 11:53 AM Jindřich Makovička
> > <makovick@gmail.com> wrote:
> > > 
> > 
> > Could you review & compare with the previous lost patch ("[PATCH
> > v4]
> > ui/gtk-clipboard: async owner_change clipboard_request")
> > 
> > https://patchew.org/QEMU/20231206142243.510068-1-edmund.raile@proton.me/
> 
> The GTK part of this patch is basically my v2, with both paths using 
> gtk_clipboard_request_text .
> 
> Then there is the serial number checking I am not familiar
> with. However, qemu_clipboard_check_serial seems to require info-
> > has_serial set to true which is not done in this patch (only info-
> > serial is set) so this half of serial number check is effectively
> > no-
> op.

I think the change below should work if we want to be safe from out-of-
order clipboard events, but I'd rather leave it to someone who has
experience with this feature (i.e. vdagent or dbus dev)

diff --git a/include/ui/gtk.h b/include/ui/gtk.h
index 3e6ce3cb48..321f02e656 100644
--- a/include/ui/gtk.h
+++ b/include/ui/gtk.h
@@ -149,6 +149,7 @@ struct GtkDisplayState {
     uint32_t cbpending[QEMU_CLIPBOARD_SELECTION__COUNT];
     GtkClipboard *gtkcb[QEMU_CLIPBOARD_SELECTION__COUNT];
     bool cbowner[QEMU_CLIPBOARD_SELECTION__COUNT];
+    uint32_t cb_serial_owner_change;
 
     DisplayOptions *opts;
 };
diff --git a/ui/gtk-clipboard.c b/ui/gtk-clipboard.c
index 463ed4e905..6a3b0dbb32 100644
--- a/ui/gtk-clipboard.c
+++ b/ui/gtk-clipboard.c
@@ -143,7 +143,7 @@
gd_clipboard_request_text_received_callback(GtkClipboard *clipboard,
 {
     QemuClipboardInfo *info = (QemuClipboardInfo *)data;
 
-    if (text) {
+    if (text && qemu_clipboard_check_serial(info, true)) {
         qemu_clipboard_set_data(info->owner, info,
QEMU_CLIPBOARD_TYPE_TEXT,
                                 strlen(text), text, true);
     }
@@ -202,6 +202,8 @@ static void gd_owner_change(GtkClipboard
*clipboard,
     switch (event->owner_change.reason) {
     case GDK_OWNER_CHANGE_NEW_OWNER:
         info = qemu_clipboard_info_new(&gd->cbpeer, s);
+        info->serial = ++gd->cb_serial_owner_change;
+        info->has_serial = true;
         gtk_clipboard_request_targets(
             clipboard,
             gd_clipboard_owner_change_targets_received_callback,

Regards,
-- 
Jindrich Makovicka


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-04-28  5:59 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-26  7:52 [PATCH v3 0/2] Fix and re-enable GTK clipboard Jindřich Makovička
2026-04-26  7:52 ` [PATCH v3 1/2] ui/gtk: Use non-blocking clipboard retrieval Jindřich Makovička
2026-04-27  8:47   ` Marc-André Lureau
2026-04-27 19:40     ` Jindrich Makovicka
2026-04-27  8:52   ` Marc-André Lureau
2026-04-27 19:26     ` Jindrich Makovicka
2026-04-28  5:59       ` Jindrich Makovicka
2026-04-26  7:52 ` [PATCH v3 2/2] ui/gtk: Keep GTK clipboard enabled Jindřich Makovička
2026-04-27  8:56 ` [PATCH v3 0/2] Fix and re-enable GTK clipboard Daniel P. Berrangé
2026-04-27 20:10   ` Jindrich Makovicka

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.