[PATCH weston] clipboard: Only copy text into internal clipboard

Derek Foreman derekf at osg.samsung.com
Wed Jan 13 13:49:30 PST 2016


This is intended to fix an Xwayland + weston livelock.

When something is selected, clipboard_set_selection() copied the
first available type into an internal selection source.  When an
X application exits this clipboard would be made into the
current selection buffer, so the buffer doesn't disappear on
application exit.

However, xwm unsets the current selection if it's not text.

So if a non-text selection was active when an app exited, weston
would live lock itself switching between no selection and the clipboard
selection.

This instead checks for a text type and copies that if available.
If no text type is available, we don't copy the selection at all.

Signed-off-by: Derek Foreman <derekf at osg.samsung.com>
---
I don't have the firmest understanding of this part of the code,
so I'm not 100% sure what I've done here is the right thing. :)

 src/clipboard.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/clipboard.c b/src/clipboard.c
index da7dbb6..564aeb1 100644
--- a/src/clipboard.c
+++ b/src/clipboard.c
@@ -237,7 +237,7 @@ clipboard_set_selection(struct wl_listener *listener, void *data)
 		container_of(listener, struct clipboard, selection_listener);
 	struct weston_seat *seat = data;
 	struct weston_data_source *source = seat->selection_data_source;
-	const char **mime_types;
+	const char *mime_type = NULL, **type;
 	int p[2];
 
 	if (source == NULL) {
@@ -256,15 +256,19 @@ clipboard_set_selection(struct wl_listener *listener, void *data)
 
 	clipboard->source = NULL;
 
-	mime_types = source->mime_types.data;
+	wl_array_for_each(type, &source->mime_types) {
+                if (strcmp(*type, "text/plain") == 0 ||
+                    strcmp(*type, "text/plain;charset=utf-8") == 0)
+                        mime_type = *type;
+	}
 
-	if (!mime_types || pipe2(p, O_CLOEXEC) == -1)
+	if (!mime_type || pipe2(p, O_CLOEXEC) == -1)
 		return;
 
-	source->send(source, mime_types[0], p[1]);
+	source->send(source, mime_type, p[1]);
 
 	clipboard->source =
-		clipboard_source_create(clipboard, mime_types[0],
+		clipboard_source_create(clipboard, mime_type,
 					seat->selection_serial, p[0]);
 	if (clipboard->source == NULL) {
 		close(p[0]);
-- 
2.7.0.rc3



More information about the wayland-devel mailing list