mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-06 03:18:13 +00:00
wayland: Add additional MIME types for text drag & drop
Previously, it only specifically accepted "text/plain;charset=utf8", which caused it to reject valid text from certain apps.
This commit is contained in:
@@ -142,8 +142,13 @@ char *Wayland_GetPrimarySelectionText(SDL_VideoDevice *_this)
|
||||
primary_selection_device = video_data->input->primary_selection_device;
|
||||
if (primary_selection_device->selection_source) {
|
||||
text = Wayland_primary_selection_source_get_data(primary_selection_device->selection_source, TEXT_MIME, &length);
|
||||
} else if (Wayland_primary_selection_offer_has_mime(primary_selection_device->selection_offer, TEXT_MIME)) {
|
||||
text = Wayland_primary_selection_offer_receive(primary_selection_device->selection_offer, TEXT_MIME, &length);
|
||||
} else {
|
||||
for (size_t i = 0; i < SDL_arraysize(text_mime_types); i++) {
|
||||
if (Wayland_primary_selection_offer_has_mime(primary_selection_device->selection_offer, text_mime_types[i])) {
|
||||
text = Wayland_primary_selection_offer_receive(primary_selection_device->selection_offer, text_mime_types[i], &length);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,7 +170,14 @@ bool Wayland_HasPrimarySelectionText(SDL_VideoDevice *_this)
|
||||
if (primary_selection_device->selection_source) {
|
||||
result = true;
|
||||
} else {
|
||||
result = Wayland_primary_selection_offer_has_mime(primary_selection_device->selection_offer, TEXT_MIME);
|
||||
size_t mime_count = 0;
|
||||
const char **mime_types = Wayland_GetTextMimeTypes(_this, &mime_count);
|
||||
for (size_t i = 0; i < mime_count; i++) {
|
||||
if (Wayland_primary_selection_offer_has_mime(primary_selection_device->selection_offer, mime_types[i])) {
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
@@ -85,6 +85,7 @@ typedef struct
|
||||
uint32_t drag_serial;
|
||||
SDL_WaylandDataOffer *drag_offer;
|
||||
SDL_WaylandDataOffer *selection_offer;
|
||||
const char *mime_type;
|
||||
bool has_mime_file, has_mime_text;
|
||||
SDL_Window *dnd_window;
|
||||
|
||||
|
@@ -34,6 +34,7 @@
|
||||
#include "SDL_waylandevents_c.h"
|
||||
#include "SDL_waylandwindow.h"
|
||||
#include "SDL_waylandmouse.h"
|
||||
#include "SDL_waylandclipboard.h"
|
||||
|
||||
#include "pointer-constraints-unstable-v1-client-protocol.h"
|
||||
#include "relative-pointer-unstable-v1-client-protocol.h"
|
||||
@@ -2258,17 +2259,25 @@ static void data_device_handle_enter(void *data, struct wl_data_device *wl_data_
|
||||
#ifdef SDL_USE_LIBDBUS
|
||||
if (Wayland_data_offer_has_mime(data_device->drag_offer, FILE_PORTAL_MIME)) {
|
||||
data_device->has_mime_file = true;
|
||||
data_device->mime_type = FILE_PORTAL_MIME;
|
||||
wl_data_offer_accept(id, serial, FILE_PORTAL_MIME);
|
||||
}
|
||||
#endif
|
||||
if (Wayland_data_offer_has_mime(data_device->drag_offer, FILE_MIME)) {
|
||||
data_device->has_mime_file = true;
|
||||
data_device->mime_type = FILE_MIME;
|
||||
wl_data_offer_accept(id, serial, FILE_MIME);
|
||||
}
|
||||
|
||||
if (Wayland_data_offer_has_mime(data_device->drag_offer, TEXT_MIME)) {
|
||||
size_t mime_count = 0;
|
||||
const char **text_mime_types = Wayland_GetTextMimeTypes(SDL_GetVideoDevice(), &mime_count);
|
||||
for (size_t i = 0; i < mime_count; ++i) {
|
||||
if (Wayland_data_offer_has_mime(data_device->drag_offer, text_mime_types[i])) {
|
||||
data_device->has_mime_text = true;
|
||||
wl_data_offer_accept(id, serial, TEXT_MIME);
|
||||
data_device->mime_type = text_mime_types[i];
|
||||
wl_data_offer_accept(id, serial, text_mime_types[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// SDL only supports "copy" style drag and drop
|
||||
@@ -2411,9 +2420,7 @@ static void data_device_handle_drop(void *data, struct wl_data_device *wl_data_d
|
||||
* non paths that are not visible to the application
|
||||
*/
|
||||
if (!drop_handled) {
|
||||
const char *mime_type = data_device->has_mime_file ? FILE_MIME : (data_device->has_mime_text ? TEXT_MIME : "");
|
||||
void *buffer = Wayland_data_offer_receive(data_device->drag_offer,
|
||||
mime_type, &length);
|
||||
void *buffer = Wayland_data_offer_receive(data_device->drag_offer, data_device->mime_type, &length);
|
||||
if (data_device->has_mime_file) {
|
||||
if (buffer) {
|
||||
char *saveptr = NULL;
|
||||
|
Reference in New Issue
Block a user