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 768007 - wayland: copying from Xwayland pasting in Wayland native sometimes doesn't work
wayland: copying from Xwayland pasting in Wayland native sometimes doesn't work
Status: RESOLVED FIXED
Product: mutter
Classification: Core
Component: wayland
unspecified
Other Linux
: Normal normal
: ---
Assigned To: mutter-maint
mutter-maint
Depends on:
Blocks:
 
 
Reported: 2016-06-24 13:31 UTC by Olivier Fourdan
Modified: 2016-06-27 09:43 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
xwayland: Use CurrentTime on all XConvertSelection calls (1.42 KB, patch)
2016-06-25 11:31 UTC, Carlos Garnacho
committed Details | Review

Description Olivier Fourdan 2016-06-24 13:31:40 UTC
Description:

Copying from emacs (X11) and pasting in Wayland native (gnome-terminal, gedit does not work.

Steps to reproduce:

1. Select some text in gnome-terminal and copy it to the buffer (Ctrl-Shift-C)
2. Paste into the same window (Ctrl-Shift-V), it works
3. Start emacs (X11) or NEdit (X11)
4. Select some text in Emacs and copy to buffer (M-w) or NEdit (Xtrl-C)
5. Paste in gnome-terminal or gedit

Actual result:

The old text copied from the Wayland application is pasted instead of the new one from the X11 application

Expected result:

The newly copied text from the X11 application (Emacs, NEdit) is pasted into the Wayland application (gnome-terminal, gedit)
Comment 1 Jonas Ådahl 2016-06-24 15:13:22 UTC
Is this about certain clients only or in general? Because I have no problems copying from an X11 client (such as gitk) and pasting into a Wayland client (such as gnome-trminal).
Comment 2 Olivier Fourdan 2016-06-24 15:26:14 UTC
I think it's just some clients, I cannot reproduce with a gtk app with X11 backend for example (e.g. GDK_BACKEND=x11 mousepad).

But this only occurs under some circumstances, like you copy something from a Wayland native app first, then redo the same with an X11 app, then try to paste to get the content initially copied from the Wayland app.
Comment 3 Jonas Ådahl 2016-06-24 15:34:04 UTC
Changing the title to more correctly the less frequent of occurrence.
Comment 4 Jonas Ådahl 2016-06-24 15:46:19 UTC
nedit just freezes directly when interacting with it, but with emacs I can reproduce it. What I did was:

 1. start gedit (using wayland backend)
 2. enter some text in gedit
 3. copy that text
 4. start emacs
 5. paste that text
 6. write some more text in emacs
 7. select and copy that newly written text
 8. go back to gedit and paste

This would result in gedit pasting the text itself had previously copied, not the text emacs copied. I don't know whether step 2, 3 and 5 is necessary to make the pasting fail.

Opening any other X11 client (such as GDK_BACKEND=x11 gtk3-demo) and pasting there correctly pastes the text copied in emacs.

Anyhow, I suspect it has something to do with how Emacs (and Nedit I guess) places things in the clipboard that is incompatible with our clipboard bridge. CC:ing Carlos as he might have a better idea of what might go wrong.
Comment 5 Carlos Garnacho 2016-06-25 11:30:44 UTC
When a X11 client sets something on a selection, the expected order of events is:

- meta_xwayland_selection_handle_xfixes_selection_notify() gets called, notifying of the new selection owner
- In that function we request the TARGETS target, so we know the mimetypes handled by the X11 client
- meta_xwayland_selection_handle_selection_notify() gets called when the client fills the selection with the TARGETS content
- When the focus moves to a wayland client, we have the info available to create the bridge MetaWaylandDataSource

In this case I see it breaking in step 3, we get a SelectionNotify event, but it has event->target = None (implying the conversion failed).

This seems to come down to the timestamp used in the XConvertSelection call, the timestamp is mistakenly used here (that stored timestamp is meant to honor the TIMESTAMP target), and it can certainly be old enough for clients to actually reject the operation.

I'm attaching a patch fixing this.
Comment 6 Carlos Garnacho 2016-06-25 11:31:22 UTC
Created attachment 330354 [details] [review]
xwayland: Use CurrentTime on all XConvertSelection calls

The call fetching the targets mistakenly used the timestamp meant
to back up the TIMESTAMP atom (hence, it's the timestamp at which
the selection is *owned* by the compositor, on behalf of a wayland
client).

This timestamp is actually only updated when the compositor gets
to own the selection, so it's a randomly late timestamp to retrieve
the TARGETS atom content, which certain clients might end up
ignoring.
Comment 7 Jonas Ådahl 2016-06-25 13:11:45 UTC
Review of attachment 330354 [details] [review]:

I'm no X clipboard expert, but with Carlos explanation of whats going on, this patch looks correct to me.
Comment 8 Jonas Ådahl 2016-06-25 13:11:52 UTC
Review of attachment 330354 [details] [review]:

I'm no X clipboard expert, but with Carlos explanation of whats going on, this patch looks correct to me.
Comment 9 Olivier Fourdan 2016-06-27 07:33:40 UTC
Works for me as well. I just found out about another issue so I filed bug 768082 but this seems unrelated.
Comment 10 Carlos Garnacho 2016-06-27 09:43:49 UTC
Yup, that's indeed another issue :). I'm pushing this for now.

Attachment 330354 [details] pushed as 21fd87c - xwayland: Use CurrentTime on all XConvertSelection calls