Fix drag & drop in Wayland with some applications

Drag & drop worked with GTK3 apps but not QT5 (pcmanfm-qt for eg)
as files are separated by '\n' instead of '\r\n'.

Resolve by supporting both (follow up to T99737).
This commit is contained in:
Campbell Barton 2022-08-04 22:33:22 +10:00
parent cdd718dbb2
commit 727cc426bc
Notes: blender-bot 2023-02-14 08:08:54 +01:00
Referenced by issue #99737, Drag and drop does not work with the wayland backend
1 changed files with 9 additions and 3 deletions

View File

@ -1227,7 +1227,9 @@ static void data_device_handle_drop(void *data, struct wl_data_device * /*wl_dat
if (mime_receive == mime_text_uri) {
static constexpr const char *file_proto = "file://";
static constexpr const char *crlf = "\r\n";
/* NOTE: some applications CRLF (`\r\n`) GTK3 for e.g. & others don't `pcmanfm-qt`.
* So support both, once `\n` is found, strip the preceding `\r` if found. */
static constexpr const char *lf = "\n";
GHOST_WindowWayland *win = ghost_wl_surface_user_data(surface);
std::vector<std::string> uris;
@ -1236,12 +1238,16 @@ static void data_device_handle_drop(void *data, struct wl_data_device * /*wl_dat
while (true) {
pos = data.find(file_proto, pos);
const size_t start = pos + sizeof(file_proto) - 1;
pos = data.find(crlf, pos);
const size_t end = pos;
pos = data.find(lf, pos);
if (pos == std::string::npos) {
break;
}
/* Account for 'CRLF' case. */
size_t end = pos;
if (data[end - 1] == '\r') {
end -= 1;
}
uris.push_back(data.substr(start, end - start));
CLOG_INFO(LOG, 2, "drop_read_uris pos=%zu, text_uri=\"%s\"", start, uris.back().c_str());
}