mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 22:28:24 +02:00
Fix GLFW_DRAG_FINSHED never firing after GLFW_DRAG_DROPPED on macOS
Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/5f783d91-e095-4f98-9d13-9d6359889ea2 Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
46c83298e3
commit
2b4c51707f
@@ -4141,6 +4141,14 @@ void _glfwCocoaPostEmptyEvent(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Drag source implementation {{{
|
// Drag source implementation {{{
|
||||||
|
|
||||||
|
// Forward declarations for drag-finish helpers used in GLFWDraggingSource methods
|
||||||
|
static void fire_drag_finished(void);
|
||||||
|
static void schedule_drag_finish_timer(void);
|
||||||
|
static GLFWid drag_finish_window_id = 0;
|
||||||
|
static GLFWDragOperationType drag_finish_action = 0;
|
||||||
|
static NSTimer *drag_finish_timer = nil;
|
||||||
|
|
||||||
@implementation GLFWDraggingSource
|
@implementation GLFWDraggingSource
|
||||||
- (NSDragOperation)draggingSession:(NSDraggingSession*)session
|
- (NSDragOperation)draggingSession:(NSDraggingSession*)session
|
||||||
sourceOperationMaskForDraggingContext:(NSDraggingContext)context
|
sourceOperationMaskForDraggingContext:(NSDraggingContext)context
|
||||||
@@ -4200,13 +4208,54 @@ void _glfwCocoaPostEmptyEvent(void) {
|
|||||||
ev.type = GLFW_DRAG_DROPPED; break;
|
ev.type = GLFW_DRAG_DROPPED; break;
|
||||||
}
|
}
|
||||||
_glfwInputDragSourceRequest(window, &ev);
|
_glfwInputDragSourceRequest(window, &ev);
|
||||||
|
if (ev.type == GLFW_DRAG_DROPPED) {
|
||||||
|
drag_finish_window_id = _glfw.drag.window_id;
|
||||||
|
drag_finish_action = ev.action;
|
||||||
|
if (operation == NSDragOperationNone || !file_promise_providers || [file_promise_providers count] == 0) {
|
||||||
|
fire_drag_finished();
|
||||||
|
} else {
|
||||||
|
schedule_drag_finish_timer();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if (operation == NSDragOperationNone) _glfwFreeDragSourceData();
|
if (operation == NSDragOperationNone) _glfwFreeDragSourceData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
static NSMutableArray<GLFWFilePromiseProviderDelegate*> *file_promise_providers = nil;
|
static NSMutableArray<GLFWFilePromiseProviderDelegate*> *file_promise_providers = nil;
|
||||||
|
|
||||||
|
static void
|
||||||
|
fire_drag_finished(void) {
|
||||||
|
if (drag_finish_timer) {
|
||||||
|
[drag_finish_timer invalidate];
|
||||||
|
drag_finish_timer = nil;
|
||||||
|
}
|
||||||
|
if (!drag_finish_window_id) return;
|
||||||
|
GLFWid wid = drag_finish_window_id;
|
||||||
|
GLFWDragOperationType action = drag_finish_action;
|
||||||
|
drag_finish_window_id = 0;
|
||||||
|
drag_finish_action = 0;
|
||||||
|
_GLFWwindow *window = _glfwWindowForId(wid);
|
||||||
|
if (window) {
|
||||||
|
GLFWDragEvent ev = {.type=GLFW_DRAG_FINSHED, .action=action};
|
||||||
|
_glfwInputDragSourceRequest(window, &ev);
|
||||||
|
}
|
||||||
|
_glfwFreeDragSourceData();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
schedule_drag_finish_timer(void) {
|
||||||
|
if (drag_finish_timer) {
|
||||||
|
[drag_finish_timer invalidate];
|
||||||
|
drag_finish_timer = nil;
|
||||||
|
}
|
||||||
|
drag_finish_timer = [NSTimer scheduledTimerWithTimeInterval:2.0 repeats:NO block:^(NSTimer *t UNUSED) {
|
||||||
|
drag_finish_timer = nil;
|
||||||
|
fire_drag_finished();
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
set_image_for_dragging_item(NSDraggingItem *draggingItem, const GLFWimage *thumbnail, NSWindow *window) {
|
set_image_for_dragging_item(NSDraggingItem *draggingItem, const GLFWimage *thumbnail, NSWindow *window) {
|
||||||
CGFloat scaleFactor = 1.0;
|
CGFloat scaleFactor = 1.0;
|
||||||
@@ -4386,6 +4435,13 @@ _glfwPlatformStartDrag(_GLFWwindow* window, const GLFWimage* thumbnail) {@autore
|
|||||||
completion_handler = nil;
|
completion_handler = nil;
|
||||||
}
|
}
|
||||||
[file_promise_providers removeObject:self];
|
[file_promise_providers removeObject:self];
|
||||||
|
if (drag_finish_window_id) {
|
||||||
|
if (!file_promise_providers || [file_promise_providers count] == 0) {
|
||||||
|
fire_drag_finished();
|
||||||
|
} else {
|
||||||
|
schedule_drag_finish_timer();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)end_transfer:(int)errorCode {
|
- (void)end_transfer:(int)errorCode {
|
||||||
@@ -4500,6 +4556,12 @@ _glfwPlatformCancelDrag(_GLFWwindow* window UNUSED) {@autoreleasepool{
|
|||||||
|
|
||||||
void
|
void
|
||||||
_glfwPlatformFreeDragSourceData(void) {
|
_glfwPlatformFreeDragSourceData(void) {
|
||||||
|
if (drag_finish_timer) {
|
||||||
|
[drag_finish_timer invalidate];
|
||||||
|
drag_finish_timer = nil;
|
||||||
|
}
|
||||||
|
drag_finish_window_id = 0;
|
||||||
|
drag_finish_action = 0;
|
||||||
if (_glfw.ns.drag_session) [_glfw.ns.drag_session release];
|
if (_glfw.ns.drag_session) [_glfw.ns.drag_session release];
|
||||||
_glfw.ns.drag_session = nil;
|
_glfw.ns.drag_session = nil;
|
||||||
if (_glfw.ns.drag_view) [_glfw.ns.drag_view release];
|
if (_glfw.ns.drag_view) [_glfw.ns.drag_view release];
|
||||||
|
|||||||
Reference in New Issue
Block a user