From 8682e4087b74ff9ef63163ad71ca18123749efa0 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 28 Oct 2024 13:40:26 +1100 Subject: [PATCH] GHOST/Wayland: support pasting images from a copied file Support pasting images into Blender which have been copied from a file manager (matching macOS). --- intern/ghost/intern/GHOST_SystemWayland.cc | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/intern/ghost/intern/GHOST_SystemWayland.cc b/intern/ghost/intern/GHOST_SystemWayland.cc index 3b134e8e249..1810a9bf066 100644 --- a/intern/ghost/intern/GHOST_SystemWayland.cc +++ b/intern/ghost/intern/GHOST_SystemWayland.cc @@ -7967,6 +7967,28 @@ GHOST_TSuccess GHOST_SystemWayland::hasClipboardImage(void) const if (data_offer->types.count(ghost_wl_mime_img_png)) { return GHOST_kSuccess; } + if (data_offer->types.count(ghost_wl_mime_text_uri)) { + const bool nil_terminate = true; + size_t data_buf_len = 0; + char *data = system_clipboard_get( + display_, nil_terminate, ghost_wl_mime_text_uri, &data_buf_len); + + GHOST_TSuccess result = GHOST_kFailure; + + if (data) { + std::vector uris = gwl_clipboard_uri_ranges(data, data_buf_len); + if (!uris.empty()) { + const std::string_view &uri = uris.front(); + char *filepath = GHOST_URL_decode_alloc(uri.data(), uri.size()); + if (IMB_ispic(filepath)) { + result = GHOST_kSuccess; + } + free(filepath); + } + free(data); + } + return result; + } } return GHOST_kFailure; @@ -8003,6 +8025,23 @@ uint *GHOST_SystemWayland::getClipboardImage(int *r_width, int *r_height) const free(data); } } + else if (data_offer->types.count(ghost_wl_mime_text_uri)) { + const bool nil_terminate = true; + size_t data_len = 0; + char *data = system_clipboard_get( + display_, nil_terminate, ghost_wl_mime_text_uri, &data_len); + + if (data) { + std::vector uris = gwl_clipboard_uri_ranges(data, data_len); + if (!uris.empty()) { + const std::string_view &uri = uris.front(); + char *filepath = GHOST_URL_decode_alloc(uri.data(), uri.size()); + ibuf = IMB_loadiffname(filepath, IB_rect, nullptr); + free(filepath); + } + free(data); + } + } if (ibuf) { *r_width = ibuf->x;