Cocoa backend: distinguish between cancelling drop by esc key/dragging to trash and dropping in unsupported place

This commit is contained in:
Kovid Goyal 2026-02-22 07:34:27 +05:30
parent f91da73b95
commit 0f10380773
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C

View file

@ -823,6 +823,7 @@ - (bool)is_mimetype:(const char*)mime_type;
@end
@interface GLFWDraggingSource : NSObject <NSDraggingSource> {
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();
}