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
This commit is contained in:
Daniel Eklöf 2021-06-09 09:51:07 +02:00
parent 2a75da4143
commit 49bb00fb64
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
3 changed files with 21 additions and 6 deletions

View file

@ -170,6 +170,8 @@
* IL+DL (`CSI Ps L` + `CSI Ps M`) now moves the cursor to column 0. * 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 * SS2 and SS3 (single shift) escape sequences behaving like locking
shifts (https://codeberg.org/dnkl/foot/issues/580). 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 ### Security

View file

@ -31,6 +31,10 @@ static const char *const mime_type_map[] = {
[DATA_OFFER_MIME_TEXT_PLAIN] = "text/plain", [DATA_OFFER_MIME_TEXT_PLAIN] = "text/plain",
[DATA_OFFER_MIME_TEXT_UTF8] = "text/plain;charset=utf-8", [DATA_OFFER_MIME_TEXT_UTF8] = "text/plain;charset=utf-8",
[DATA_OFFER_MIME_URI_LIST] = "text/uri-list", [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 bool
@ -1428,9 +1432,9 @@ text_to_clipboard(struct seat *seat, struct terminal *term, char *text, uint32_t
/* Configure source */ /* 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_UTF8]);
wl_data_source_offer(clipboard->data_source, mime_type_map[DATA_OFFER_MIME_TEXT_PLAIN]); 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, mime_type_map[DATA_OFFER_MIME_TEXT_TEXT]);;
wl_data_source_offer(clipboard->data_source, "TEXT"); wl_data_source_offer(clipboard->data_source, mime_type_map[DATA_OFFER_MIME_TEXT_STRING]);
wl_data_source_offer(clipboard->data_source, "UTF8_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_source_add_listener(clipboard->data_source, &data_source_listener, seat);
wl_data_device_set_selection(seat->data_device, clipboard->data_source, serial); 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 */ /* 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_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, 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, mime_type_map[DATA_OFFER_MIME_TEXT_TEXT]);
zwp_primary_selection_source_v1_offer(primary->data_source, "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, "UTF8_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_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); 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) { switch (mime_type) {
case DATA_OFFER_MIME_TEXT_PLAIN: 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 /* text/plain is our least preferred type. Only use if current
* type is unset */ * type is unset */
switch (*type) { switch (*type) {
@ -2001,10 +2007,13 @@ select_mime_type_for_offer(const char *_mime_type,
break; break;
case DATA_OFFER_MIME_TEXT_UTF8: case DATA_OFFER_MIME_TEXT_UTF8:
case DATA_OFFER_MIME_TEXT_UTF8_STRING:
/* text/plain;charset=utf-8 is preferred over text/plain */ /* text/plain;charset=utf-8 is preferred over text/plain */
switch (*type) { switch (*type) {
case DATA_OFFER_MIME_UNSET: case DATA_OFFER_MIME_UNSET:
case DATA_OFFER_MIME_TEXT_PLAIN: case DATA_OFFER_MIME_TEXT_PLAIN:
case DATA_OFFER_MIME_TEXT_TEXT:
case DATA_OFFER_MIME_TEXT_STRING:
*type = mime_type; *type = mime_type;
break; break;

View file

@ -122,6 +122,10 @@ enum data_offer_mime_type {
DATA_OFFER_MIME_TEXT_PLAIN, DATA_OFFER_MIME_TEXT_PLAIN,
DATA_OFFER_MIME_TEXT_UTF8, DATA_OFFER_MIME_TEXT_UTF8,
DATA_OFFER_MIME_URI_LIST, DATA_OFFER_MIME_URI_LIST,
DATA_OFFER_MIME_TEXT_TEXT,
DATA_OFFER_MIME_TEXT_STRING,
DATA_OFFER_MIME_TEXT_UTF8_STRING,
}; };
struct wl_window; struct wl_window;