From 0f103807733b080f1ec4b4c94927c1462293db59 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 22 Feb 2026 07:34:27 +0530 Subject: [PATCH] Cocoa backend: distinguish between cancelling drop by esc key/dragging to trash and dropping in unsupported place --- glfw/cocoa_window.m | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/glfw/cocoa_window.m b/glfw/cocoa_window.m index 4c4557865..b527d7f95 100644 --- a/glfw/cocoa_window.m +++ b/glfw/cocoa_window.m @@ -823,6 +823,7 @@ - (bool)is_mimetype:(const char*)mime_type; @end @interface GLFWDraggingSource : NSObject { + NSPoint start_point; } @end @@ -3930,7 +3931,8 @@ - (NSDragOperation)draggingSession:(NSDraggingSession*)session - (void)draggingSession:(NSDraggingSession *)session willBeginAtPoint:(NSPoint)screenPoint { - (void)session; (void)screenPoint; + (void)session; + start_point = screenPoint; } - (void)draggingSession:(NSDraggingSession *)session @@ -3944,7 +3946,7 @@ - (void)draggingSession:(NSDraggingSession *)session endedAtPoint:(NSPoint)screenPoint operation:(NSDragOperation)operation { - (void)session; (void)screenPoint; + (void)session; _GLFWwindow *window = _glfwWindowForId(_glfw.drag.window_id); if (window) { GLFWDragEvent ev = {0}; @@ -3954,7 +3956,17 @@ - (void)draggingSession:(NSDraggingSession *)session case NSDragOperationNone: break; default: ev.action = GLFW_DRAG_OPERATION_GENERIC; break; } - ev.type = (operation == NSDragOperationNone) ? GLFW_DRAG_CANCELLED : GLFW_DRAG_DROPPED; + switch (operation) { + case NSDragOperationDelete: ev.type = GLFW_DRAG_CANCELLED; break; + case NSDragOperationNone: { + NSEvent *currentEvent = [NSApp currentEvent]; + if (currentEvent.type == NSEventTypeKeyDown && currentEvent.keyCode == 53) { + ev.type = GLFW_DRAG_CANCELLED; + } else ev.type = GLFW_DRAG_DROPPED; + } break; + default: + ev.type = GLFW_DRAG_DROPPED; break; + } _glfwInputDragSourceRequest(window, &ev); if (operation == NSDragOperationNone) _glfwFreeDragSourceData(); }