Fix drop on clients. data should be requested only after the client actually requests it not on return from drop event callback

This commit is contained in:
Kovid Goyal
2026-03-21 09:06:24 +05:30
parent 59117ff5fd
commit b4005d0e97
2 changed files with 7 additions and 6 deletions

View File

@@ -1497,10 +1497,10 @@ free_drop_data(_GLFWwindow *window) {
} }
static void 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; _GLFWDropData *d = &window->ns.drop_data;
d->copy_mimes_count = accepted_count; 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 // Reset the working copy of mimes so the next callback sees the full original
@@ -1582,7 +1582,7 @@ reset_drop_copy_mimes(_GLFWDropData *d) {
_GLFWDropData *d = &window->ns.drop_data; _GLFWDropData *d = &window->ns.drop_data;
if (reset_drop_copy_mimes(d)) { 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); 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; return window->ns.drop_data.drag_accepted ? NSDragOperationGeneric : NSDragOperationNone;
} }
@@ -1599,7 +1599,7 @@ reset_drop_copy_mimes(_GLFWDropData *d) {
_GLFWDropData *d = &window->ns.drop_data; _GLFWDropData *d = &window->ns.drop_data;
if (reset_drop_copy_mimes(d)) { 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); 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; return window->ns.drop_data.drag_accepted ? NSDragOperationGeneric : NSDragOperationNone;
} }
@@ -1610,7 +1610,7 @@ reset_drop_copy_mimes(_GLFWDropData *d) {
_GLFWDropData *d = &window->ns.drop_data; _GLFWDropData *d = &window->ns.drop_data;
if (reset_drop_copy_mimes(d)) { 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); 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); free_drop_data(window);
} }
@@ -1627,7 +1627,7 @@ reset_drop_copy_mimes(_GLFWDropData *d) {
if (!reset_drop_copy_mimes(d)) return NO; 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); size_t num_accepted = _glfwInputDropEvent(window, GLFW_DROP_DROP, xpos, ypos, d->copy_mimes, d->copy_mimes_count, from_self);
if (d->copy_mimes) { 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]; window->ns.drop_data.pasteboard = [[sender draggingPasteboard] retain];
for (size_t i = 0; i < num_accepted; i++) for (size_t i = 0; i < num_accepted; i++)
_glfwPlatformRequestDropData(window, d->copy_mimes[i]); _glfwPlatformRequestDropData(window, d->copy_mimes[i]);

View File

@@ -830,6 +830,7 @@ on_drop(GLFWwindow *window, GLFWDropEvent *ev) {
global_state.drop_dest.os_window_id = os_window->id; global_state.drop_dest.os_window_id = os_window->id;
if (is_client_drop) { if (is_client_drop) {
drop_move_on_child(w, ev->mimes, ev->num_mimes, true); drop_move_on_child(w, ev->mimes, ev->num_mimes, true);
ev->num_mimes = 0; // we wait for the client to request MIMEs
} else { } else {
if (ev->from_self) { if (ev->from_self) {
if (global_state.drag_source.drag_data) { if (global_state.drag_source.drag_data) {