After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 768177 - CLIPBOARD target request after PRIMARY request times out. GDK_SELECTION_NOTIFY has wrong selection id
CLIPBOARD target request after PRIMARY request times out. GDK_SELECTION_NOTIF...
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Backend: Wayland
3.20.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2016-06-29 12:20 UTC by Caolan McNamara
Modified: 2016-07-02 16:58 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
this makes it work for me (1.49 KB, patch)
2016-06-29 12:20 UTC, Caolan McNamara
committed Details | Review
wayland: Separate selection buffers and other per-selection atom data (8.54 KB, patch)
2016-06-29 15:35 UTC, Carlos Garnacho
committed Details | Review

Description Caolan McNamara 2016-06-29 12:20:38 UTC
Created attachment 330565 [details] [review]
this makes it work for me

LibreOffice under wayland won't successfully paste from the CLIPBOARD after the PRIMARY selection is used to paste from another app into it.

I paste from PRIMARY and then immediately request the targets of CLIPBOARD: selection_buffer_notify generates a GDK_SELECTION_NOTIFY event for this CLIPBOARD request using selection_buffer_notify but sets the selection field to PRIMARY from the passed in SelectionBuffer.

So the notification dosn't match in _gtk_selection_notify at the info->selection == event->selection so the CLIPBOARD request is never satisfied
and times out.

The problem appears to be the cache used by _gdk_wayland_display_convert_selection of gdk/wayland/gdkselection-wayland.c where...

  buffer_data = g_hash_table_lookup (wayland_selection->selection_buffers,
                                     target);

...

  g_hash_table_insert (wayland_selection->selection_buffers,
                       GDK_ATOM_TO_POINTER (target),
                       buffer_data);

So the buffer_data for the PRIMARY selection was cached and reused for the CLIPBOARD selection. The attached patch "for for me(tm)" by just updating the selection of the cached buffer_data to the requested selection on retrieval
Comment 1 Carlos Garnacho 2016-06-29 15:34:44 UTC
Yikes, nice catch! However, I think the shared SelectionBuffer ht across all selections bring more issues than this, I think it's better to just separate buffers into the different selections. I'm attaching a patch doing so, would be great if you could try it and confirm it still fixes your issue.
Comment 2 Carlos Garnacho 2016-06-29 15:35:00 UTC
Created attachment 330600 [details] [review]
wayland: Separate selection buffers and other per-selection atom data

This has most notably impact in selection buffers, because those were
shared across all selection atoms. This turned out wrong on 2 situations:
- Because the selection atom was set at SelectionBuffer creation time, the
  GDK_SELECTION_NOTIFY events generated will have unexpected info if the
  buffer is attempted to be reused for another selection.
- Anytime different selections imply different stored content for the same
  target.

This is better separated into per-selection buffers, so it's not possible
to get collisions if a same target is used across different selections.
Comment 3 Caolan McNamara 2016-06-29 20:14:05 UTC
Yup, that works perfectly fine for me
Comment 4 Jonas Ådahl 2016-06-30 01:45:16 UTC
Review of attachment 330600 [details] [review]:

As far as I can tell, this looks correct to me (with one minor nit).

::: gdk/wayland/gdkselection-wayland.c
@@ +99,3 @@
 {
   /* Destination-side data */
+  SelectionData selections[3];

nit: Could just as well now add a ATOM_LAST or N_ATOMS to the enum, and use that instead of the 3s? Makes it more obvious what is in the arrays as well.
Comment 5 Carlos Garnacho 2016-06-30 11:51:11 UTC
Sure :), adding that and pushing.
Comment 6 Carlos Garnacho 2016-06-30 12:12:53 UTC
Attachment 330600 [details] pushed as 0d30ad2 - wayland: Separate selection buffers and other per-selection atom data