GNOME Bugzilla – Bug 768007
wayland: copying from Xwayland pasting in Wayland native sometimes doesn't work
Last modified: 2016-06-27 09:43:53 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)
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).
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.
Changing the title to more correctly the less frequent of occurrence.
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.
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.
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.
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.
Works for me as well. I just found out about another issue so I filed bug 768082 but this seems unrelated.
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