diff --git a/glfw/cocoa_window.m b/glfw/cocoa_window.m index a3c890922..09ba085f1 100644 --- a/glfw/cocoa_window.m +++ b/glfw/cocoa_window.m @@ -878,6 +878,7 @@ static void _glfwUpdateNotchCover(_GLFWwindow*); - (instancetype)initWithWindow:(_GLFWwindow*)initWindow mimeType:(const char*)mime instanceId:(GLFWid)iid; - (void)request_drag_data; +- (void)promised_data_ready:(const char*)data sz:(size_t)sz type:(int)type; - (void)end_transfer:(int)errorCode; - (void)end_transfer_with_error:(NSError*)err; - (bool)is_mimetype:(const char*)mime_type; @@ -4460,6 +4461,24 @@ _glfwPlatformStartDrag(_GLFWwindow* window, const GLFWimage* thumbnail) {@autore - (bool)is_mimetype:(const char*)q { return strcmp(q, mimeType) == 0; } +- (void)promised_data_ready:(const char*)path sz:(size_t)sz type:(int)type { + if (file_handle) [file_handle release]; + file_handle = nil; + // TODO: erase file at file_url + switch (type) { + case 0: + // Create a hard link to path at file_url + break; + case 1: + // Create a symlink to the same destination as the symlink at path + default: + // copy the directory at path to file_url recursively using hard + // links for files. + break; + } + [self end_transfer:0]; +} + - (void)request_drag_data { if (instanceId != _glfw.drag.instance_id) { [self end_transfer:EINVAL]; return; } _GLFWwindow *window = _glfwWindowForId(_glfw.drag.window_id); @@ -4506,6 +4525,8 @@ _glfwPlatformStartDrag(_GLFWwindow* window, const GLFWimage* thumbnail) {@autore - (void)dealloc { free(mimeType); mimeType = NULL; + if (file_handle) [file_handle release]; + file_handle = nil; if (file_url) [file_url release]; file_url = nil; [self end_transfer:EINVAL]; @@ -4602,11 +4623,15 @@ _glfwPlatformChangeDragImage(const GLFWimage *thumbnail) {@autoreleasepool{ return 0; }} + int -_glfwPlatformDragDataReady(const char *mime_type) { +_glfwPlatformDragDataReady(const char *mime_type, const char *data, size_t sz, int type) { if (!file_promise_providers) return 0; for (GLFWFilePromiseProviderDelegate *d in file_promise_providers) { - if ([d is_mimetype:mime_type]) [d request_drag_data]; + if ([d is_mimetype:mime_type]) { + if (type == -1) [d request_drag_data]; + else [d promised_data_ready:data sz:sz type:type]; + } } return 0; } diff --git a/glfw/input.c b/glfw/input.c index 314c58299..f370129e4 100644 --- a/glfw/input.c +++ b/glfw/input.c @@ -1190,7 +1190,7 @@ glfwStartDrag(GLFWwindow* handle, const GLFWDragSourceItem *items, size_t item_c _GLFWwindow* window = (_GLFWwindow*) handle; assert(window != NULL); _GLFW_REQUIRE_INIT_OR_RETURN(EINVAL); - if (operations == -1) return _glfwPlatformDragDataReady(items[0].mime_type); + if (operations == -1) return _glfwPlatformDragDataReady(items[0].mime_type, items[0].optional_data, items[0].data_size, items[0].type); if (operations == -2) return _glfwPlatformChangeDragImage(thumbnail); if (operations == -3) { _glfwPlatformCancelDrag(window); return 0; } _glfwFreeDragSourceData(); diff --git a/glfw/internal.h b/glfw/internal.h index 535d50054..9d3c19183 100644 --- a/glfw/internal.h +++ b/glfw/internal.h @@ -840,7 +840,7 @@ void _glfwPlatformCancelDrag(_GLFWwindow* window); void _glfwFreeDragSourceData(void); void _glfwPlatformFreeDragSourceData(void); void _glfwInputDragSourceRequest(_GLFWwindow* window, GLFWDragEvent *ev); -int _glfwPlatformDragDataReady(const char *mime_type); +int _glfwPlatformDragDataReady(const char *mime_type, const char *data, size_t sz, int type); int _glfwPlatformChangeDragImage(const GLFWimage *thumbnail); diff --git a/glfw/null_window.c b/glfw/null_window.c index 1c3c90b00..fcba784a6 100644 --- a/glfw/null_window.c +++ b/glfw/null_window.c @@ -547,7 +547,8 @@ _glfwPlatformStartDrag(_GLFWwindow* window, const GLFWimage* thumbnail) { return ENOTSUP; } void _glfwPlatformFreeDragSourceData(void) {} -int _glfwPlatformDragDataReady(const char *mime_type) { (void) mime_type; return 0; } +int +_glfwPlatformDragDataReady(const char *mime_type UNUSED, const char *data UNUSED, size_t sz UNUSED, int type UNUSED) { return 0; } int _glfwPlatformChangeDragImage(const GLFWimage *thumbnail) { (void)thumbnail; return 0; } const char** _glfwPlatformGetDropMimeTypes(GLFWDropData* drop UNUSED, int* count) diff --git a/glfw/wl_window.c b/glfw/wl_window.c index 4d2fa7150..9d0dbeb4c 100644 --- a/glfw/wl_window.c +++ b/glfw/wl_window.c @@ -3343,7 +3343,7 @@ _glfwPlatformChangeDragImage(const GLFWimage *thumbnail) { } int -_glfwPlatformDragDataReady(const char *mime_type) { +_glfwPlatformDragDataReady(const char *mime_type, const char *data UNUSED, size_t sz UNUSED, int type UNUSED) { for (size_t i = 0; i < _glfw.wl.drag.count; i++) { if (strcmp(dr.mime_type, mime_type) == 0) { if (!dr.watch_id) dr.watch_id = add_drag_watch(dr.fd); diff --git a/glfw/x11_window.c b/glfw/x11_window.c index 718f24bcc..ecc94ae2e 100644 --- a/glfw/x11_window.c +++ b/glfw/x11_window.c @@ -4614,7 +4614,7 @@ _glfwPlatformChangeDragImage(const GLFWimage *thumbnail) { } int -_glfwPlatformDragDataReady(const char *mime_type) { +_glfwPlatformDragDataReady(const char *mime_type, const char *data UNUSED, size_t sz UNUSED, int type UNUSED) { // Find the pending request for this MIME type for (size_t i = 0; i < _glfw.x11.drag.pending_count; i++) { if (_glfw.x11.drag.pending_requests[i].inflight && diff --git a/kitty/dnd.c b/kitty/dnd.c index 2ebb0e35f..15d2536f4 100644 --- a/kitty/dnd.c +++ b/kitty/dnd.c @@ -1835,7 +1835,7 @@ open_item_tmpfile(void) { static int notify_drag_data_ready_to_read(const char *mime_type) { - return notify_drag_data_ready(global_state.drag_source.from_os_window, mime_type, NULL, 0, 0); + return notify_drag_data_ready(global_state.drag_source.from_os_window, mime_type, NULL, 0, -1); }