From 2f33460864283e84bb8aed43941708eb2f583747 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 2 Apr 2026 07:14:36 +0000 Subject: [PATCH] Add operations==-3 cancel drag support to glfwStartDrag Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/eff7e2c8-ab7a-4967-95b5-e65631245701 Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com> --- glfw/cocoa_window.m | 11 +++++++++++ glfw/glfw3.h | 2 +- glfw/input.c | 1 + glfw/internal.h | 1 + glfw/wl_window.c | 6 ++++++ glfw/x11_window.c | 11 +++++++++++ 6 files changed, 31 insertions(+), 1 deletion(-) diff --git a/glfw/cocoa_window.m b/glfw/cocoa_window.m index 3f0c02962..baab680ca 100644 --- a/glfw/cocoa_window.m +++ b/glfw/cocoa_window.m @@ -4422,6 +4422,17 @@ _glfwPlatformStartDrag(_GLFWwindow* window, const GLFWimage* thumbnail) {@autore @end +void +_glfwPlatformCancelDrag(_GLFWwindow* window UNUSED) {@autoreleasepool{ + if (!_glfw.drag.window_id) return; + _GLFWwindow* drag_win = _glfwWindowForId(_glfw.drag.window_id); + if (drag_win) { + GLFWDragEvent ev = {.type = GLFW_DRAG_CANCELLED}; + _glfwInputDragSourceRequest(drag_win, &ev); + } + _glfwFreeDragSourceData(); +}} + void _glfwPlatformFreeDragSourceData(void) { if (_glfw.ns.drag_session) [_glfw.ns.drag_session release]; diff --git a/glfw/glfw3.h b/glfw/glfw3.h index 002e58b17..83890b617 100644 --- a/glfw/glfw3.h +++ b/glfw/glfw3.h @@ -4985,7 +4985,7 @@ GLFWAPI GLFWdragsourcefun glfwSetDragSourceCallback(GLFWwindow* window, GLFWdrag // Start a drag. If called with operations == -1 indicates that previously // requested data via GLFW_DRAG_DATA_REQUEST is ready. operations == -2 means -// that the drag image is changed. +// that the drag image is changed. operations == -3 cancels any existing drag. GLFWAPI int glfwStartDrag(GLFWwindow* window, const GLFWDragSourceItem *items, size_t mime_count, const GLFWimage* thumbnail, int operations, bool needs_toplevel_on_wayland); /*! @brief Returns whether the specified joystick is present. diff --git a/glfw/input.c b/glfw/input.c index 7f24f2137..c91eaf026 100644 --- a/glfw/input.c +++ b/glfw/input.c @@ -1190,6 +1190,7 @@ glfwStartDrag(GLFWwindow* handle, const GLFWDragSourceItem *items, size_t item_c _GLFW_REQUIRE_INIT_OR_RETURN(EINVAL); if (operations == -1) return _glfwPlatformDragDataReady(items[0].mime_type); if (operations == -2) return _glfwPlatformChangeDragImage(thumbnail); + if (operations == -3) { _glfwPlatformCancelDrag(window); return 0; } _glfwFreeDragSourceData(); _glfw.drag.instance_id++; if (!items || !item_count) return 0; diff --git a/glfw/internal.h b/glfw/internal.h index 3821b403f..ea8f64521 100644 --- a/glfw/internal.h +++ b/glfw/internal.h @@ -835,6 +835,7 @@ void _glfwPlatformEndDrop(GLFWwindow *w, GLFWDragOperationType op); int _glfwPlatformRequestDropData(_GLFWwindow *window, const char *mime); // Platform functions for drag source int _glfwPlatformStartDrag(_GLFWwindow* window, const GLFWimage* thumbnail); +void _glfwPlatformCancelDrag(_GLFWwindow* window); void _glfwFreeDragSourceData(void); void _glfwPlatformFreeDragSourceData(void); void _glfwInputDragSourceRequest(_GLFWwindow* window, GLFWDragEvent *ev); diff --git a/glfw/wl_window.c b/glfw/wl_window.c index c176915e9..ea0bc5983 100644 --- a/glfw/wl_window.c +++ b/glfw/wl_window.c @@ -3409,6 +3409,12 @@ static const struct wl_data_source_listener drag_source_listener = { .dnd_finished = drag_source_dnd_finished, }; +void +_glfwPlatformCancelDrag(_GLFWwindow* window UNUSED) { + if (!_glfw.drag.window_id) return; + cancel_drag(GLFW_DRAG_CANCELLED); +} + void _glfwPlatformFreeDragSourceData(void) { if (_glfw.wl.drag.drag_viewport) wp_viewport_destroy(_glfw.wl.drag.drag_viewport); diff --git a/glfw/x11_window.c b/glfw/x11_window.c index 1924f8abf..b8d1f6f83 100644 --- a/glfw/x11_window.c +++ b/glfw/x11_window.c @@ -4522,6 +4522,17 @@ _glfwPlatformStartDrag(_GLFWwindow* window, const GLFWimage* thumbnail) { return 0; } +void +_glfwPlatformCancelDrag(_GLFWwindow* window UNUSED) { + if (!_glfw.drag.window_id) return; + _GLFWwindow* drag_win = _glfwWindowForId(_glfw.drag.window_id); + if (drag_win) { + GLFWDragEvent ev = {.type = GLFW_DRAG_CANCELLED}; + _glfwInputDragSourceRequest(drag_win, &ev); + } + _glfwFreeDragSourceData(); +} + void _glfwPlatformFreeDragSourceData(void) { if (_glfw.x11.drag.active) {