From b4005d0e979dfee976cc8aa2d869453651bd226a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 21 Mar 2026 09:06:24 +0530 Subject: [PATCH] Fix drop on clients. data should be requested only after the client actually requests it not on return from drop event callback --- glfw/cocoa_window.m | 12 ++++++------ kitty/glfw.c | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/glfw/cocoa_window.m b/glfw/cocoa_window.m index c645ef61b..f1342b457 100644 --- a/glfw/cocoa_window.m +++ b/glfw/cocoa_window.m @@ -1497,10 +1497,10 @@ - (BOOL)wantsPeriodicDraggingUpdates } static void -update_drop_state(_GLFWwindow *window, size_t accepted_count) { +update_drop_state(_GLFWwindow *window, size_t accepted_count, GLFWDropEventType t) { _GLFWDropData *d = &window->ns.drop_data; d->copy_mimes_count = accepted_count; - d->drag_accepted = accepted_count > 0; + if (t == GLFW_DROP_ENTER || t == GLFW_DROP_MOVE) d->drag_accepted = accepted_count > 0; } // Reset the working copy of mimes so the next callback sees the full original @@ -1582,7 +1582,7 @@ - (NSDragOperation)draggingEntered:(id )sender _GLFWDropData *d = &window->ns.drop_data; if (reset_drop_copy_mimes(d)) { size_t accepted_count = _glfwInputDropEvent(window, GLFW_DROP_ENTER, xpos, ypos, d->copy_mimes, d->copy_mimes_count, from_self); - update_drop_state(window, accepted_count); + update_drop_state(window, accepted_count, GLFW_DROP_ENTER); } return window->ns.drop_data.drag_accepted ? NSDragOperationGeneric : NSDragOperationNone; } @@ -1599,7 +1599,7 @@ - (NSDragOperation)draggingUpdated:(id )sender _GLFWDropData *d = &window->ns.drop_data; if (reset_drop_copy_mimes(d)) { size_t accepted_count = _glfwInputDropEvent(window, GLFW_DROP_MOVE, xpos, ypos, d->copy_mimes, d->copy_mimes_count, from_self); - update_drop_state(window, accepted_count); + update_drop_state(window, accepted_count, GLFW_DROP_MOVE); } return window->ns.drop_data.drag_accepted ? NSDragOperationGeneric : NSDragOperationNone; } @@ -1610,7 +1610,7 @@ - (void)draggingExited:(id )sender _GLFWDropData *d = &window->ns.drop_data; if (reset_drop_copy_mimes(d)) { size_t accepted_count = _glfwInputDropEvent(window, GLFW_DROP_LEAVE, 0, 0, d->copy_mimes, d->copy_mimes_count, from_self); - update_drop_state(window, accepted_count); + update_drop_state(window, accepted_count, GLFW_DROP_LEAVE); } free_drop_data(window); } @@ -1627,7 +1627,7 @@ - (BOOL)performDragOperation:(id )sender if (!reset_drop_copy_mimes(d)) return NO; size_t num_accepted = _glfwInputDropEvent(window, GLFW_DROP_DROP, xpos, ypos, d->copy_mimes, d->copy_mimes_count, from_self); if (d->copy_mimes) { - update_drop_state(window, num_accepted); + update_drop_state(window, num_accepted, GLFW_DROP_DROP); window->ns.drop_data.pasteboard = [[sender draggingPasteboard] retain]; for (size_t i = 0; i < num_accepted; i++) _glfwPlatformRequestDropData(window, d->copy_mimes[i]); diff --git a/kitty/glfw.c b/kitty/glfw.c index ad8f0d167..6cb03b3ee 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -830,6 +830,7 @@ on_drop(GLFWwindow *window, GLFWDropEvent *ev) { global_state.drop_dest.os_window_id = os_window->id; if (is_client_drop) { drop_move_on_child(w, ev->mimes, ev->num_mimes, true); + ev->num_mimes = 0; // we wait for the client to request MIMEs } else { if (ev->from_self) { if (global_state.drag_source.drag_data) {