Merge branch 'copilot/modify-glfwstartdrag-cancel' of https://github.com/kovidgoyal/kitty

This commit is contained in:
Kovid Goyal 2026-04-02 12:47:55 +05:30
commit d1d7a442b6
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
6 changed files with 31 additions and 1 deletions

View file

@ -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];

2
glfw/glfw3.h vendored
View file

@ -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.

1
glfw/input.c vendored
View file

@ -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;

1
glfw/internal.h vendored
View file

@ -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);

6
glfw/wl_window.c vendored
View file

@ -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);

11
glfw/x11_window.c vendored
View file

@ -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) {