More work on DnD kitten

This commit is contained in:
Kovid Goyal 2026-05-13 08:25:14 +05:30
parent b28712bfae
commit c909809bb4
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
7 changed files with 34 additions and 8 deletions

View file

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

2
glfw/input.c vendored
View file

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

2
glfw/internal.h vendored
View file

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

3
glfw/null_window.c vendored
View file

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

2
glfw/wl_window.c vendored
View file

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

2
glfw/x11_window.c vendored
View file

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

View file

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