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

@ -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;