From 49bb00fb64a2af6c677530e07378dafe6d9cbfa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 9 Jun 2021 09:51:07 +0200 Subject: [PATCH] selection: add support for TEXT/STRING/UTF8_STRING mime-types in incoming offers We were already offering these mime types for our own clipboard data, but ignored them in incoming offers. Fixes paste issues from Geany. Closes #583 --- CHANGELOG.md | 2 ++ selection.c | 21 +++++++++++++++------ wayland.h | 4 ++++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd701ca2..1a1bb982 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -170,6 +170,8 @@ * IL+DL (`CSI Ps L` + `CSI Ps M`) now moves the cursor to column 0. * SS2 and SS3 (single shift) escape sequences behaving like locking shifts (https://codeberg.org/dnkl/foot/issues/580). +* `TEXT`+`STRING`+`UTF8_STRING` mime types not being recognized in + clipboard offers (https://codeberg.org/dnkl/foot/issues/583). ### Security diff --git a/selection.c b/selection.c index 21969208..555b32f2 100644 --- a/selection.c +++ b/selection.c @@ -31,6 +31,10 @@ static const char *const mime_type_map[] = { [DATA_OFFER_MIME_TEXT_PLAIN] = "text/plain", [DATA_OFFER_MIME_TEXT_UTF8] = "text/plain;charset=utf-8", [DATA_OFFER_MIME_URI_LIST] = "text/uri-list", + + [DATA_OFFER_MIME_TEXT_TEXT] = "TEXT", + [DATA_OFFER_MIME_TEXT_STRING] = "STRING", + [DATA_OFFER_MIME_TEXT_UTF8_STRING] = "UTF8_STRING", }; bool @@ -1428,9 +1432,9 @@ text_to_clipboard(struct seat *seat, struct terminal *term, char *text, uint32_t /* Configure source */ wl_data_source_offer(clipboard->data_source, mime_type_map[DATA_OFFER_MIME_TEXT_UTF8]); wl_data_source_offer(clipboard->data_source, mime_type_map[DATA_OFFER_MIME_TEXT_PLAIN]); - wl_data_source_offer(clipboard->data_source, "STRING"); - wl_data_source_offer(clipboard->data_source, "TEXT"); - wl_data_source_offer(clipboard->data_source, "UTF8_STRING"); + wl_data_source_offer(clipboard->data_source, mime_type_map[DATA_OFFER_MIME_TEXT_TEXT]);; + wl_data_source_offer(clipboard->data_source, mime_type_map[DATA_OFFER_MIME_TEXT_STRING]); + wl_data_source_offer(clipboard->data_source, mime_type_map[DATA_OFFER_MIME_TEXT_UTF8_STRING]); wl_data_source_add_listener(clipboard->data_source, &data_source_listener, seat); wl_data_device_set_selection(seat->data_device, clipboard->data_source, serial); @@ -1874,9 +1878,9 @@ text_to_primary(struct seat *seat, struct terminal *term, char *text, uint32_t s /* Configure source */ zwp_primary_selection_source_v1_offer(primary->data_source, mime_type_map[DATA_OFFER_MIME_TEXT_UTF8]); zwp_primary_selection_source_v1_offer(primary->data_source, mime_type_map[DATA_OFFER_MIME_TEXT_PLAIN]); - zwp_primary_selection_source_v1_offer(primary->data_source, "STRING"); - zwp_primary_selection_source_v1_offer(primary->data_source, "TEXT"); - zwp_primary_selection_source_v1_offer(primary->data_source, "UTF8_STRING"); + zwp_primary_selection_source_v1_offer(primary->data_source, mime_type_map[DATA_OFFER_MIME_TEXT_TEXT]); + zwp_primary_selection_source_v1_offer(primary->data_source, mime_type_map[DATA_OFFER_MIME_TEXT_STRING]); + zwp_primary_selection_source_v1_offer(primary->data_source, mime_type_map[DATA_OFFER_MIME_TEXT_UTF8_STRING]); zwp_primary_selection_source_v1_add_listener(primary->data_source, &primary_selection_source_listener, seat); zwp_primary_selection_device_v1_set_selection(seat->primary_selection_device, primary->data_source, serial); @@ -1988,6 +1992,8 @@ select_mime_type_for_offer(const char *_mime_type, switch (mime_type) { case DATA_OFFER_MIME_TEXT_PLAIN: + case DATA_OFFER_MIME_TEXT_TEXT: + case DATA_OFFER_MIME_TEXT_STRING: /* text/plain is our least preferred type. Only use if current * type is unset */ switch (*type) { @@ -2001,10 +2007,13 @@ select_mime_type_for_offer(const char *_mime_type, break; case DATA_OFFER_MIME_TEXT_UTF8: + case DATA_OFFER_MIME_TEXT_UTF8_STRING: /* text/plain;charset=utf-8 is preferred over text/plain */ switch (*type) { case DATA_OFFER_MIME_UNSET: case DATA_OFFER_MIME_TEXT_PLAIN: + case DATA_OFFER_MIME_TEXT_TEXT: + case DATA_OFFER_MIME_TEXT_STRING: *type = mime_type; break; diff --git a/wayland.h b/wayland.h index 4ec09544..6021497f 100644 --- a/wayland.h +++ b/wayland.h @@ -122,6 +122,10 @@ enum data_offer_mime_type { DATA_OFFER_MIME_TEXT_PLAIN, DATA_OFFER_MIME_TEXT_UTF8, DATA_OFFER_MIME_URI_LIST, + + DATA_OFFER_MIME_TEXT_TEXT, + DATA_OFFER_MIME_TEXT_STRING, + DATA_OFFER_MIME_TEXT_UTF8_STRING, }; struct wl_window;