From 3fb748e3db5b48c1e34b7237916671a7f2da8052 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 8 Apr 2026 20:49:10 +0530 Subject: [PATCH] Add cancelling of current drag offer --- docs/dnd-protocol.rst | 8 ++++++-- kitty/screen.c | 7 ++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/docs/dnd-protocol.rst b/docs/dnd-protocol.rst index 7b5cef9d2..d4aec9d7e 100644 --- a/docs/dnd-protocol.rst +++ b/docs/dnd-protocol.rst @@ -297,14 +297,18 @@ form:: This, is the data for the MIME type identified by ``idx`` which is a zero based index into the list of MIME types. The data should be chunkedusing the -``m`` key. End of data is denoted by ``m=0`` and an rmpty payload. If an error +``m`` key. End of data is denoted by ``m=0`` and an empty payload. If an error occurs the client should send:: - OSC _dnd_code ; t=E; ERR_CODE ST + OSC _dnd_code ; t=E:y=idx ; ERR_CODE ST Where ``ERR_CODE`` is a POSIX error code such as ``ENOENT`` if the MIME type is not found or ``EIO`` if an IO error occurred and so on. +If the client wants to cancel the full drag at any time, it should send: + + OSC _dnd_code ; t=E:y=-1 ST + Multiplexers ----------------- diff --git a/kitty/screen.c b/kitty/screen.c index d764a6bd8..c0e8864b2 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -1570,7 +1570,12 @@ screen_handle_dnd_command(Screen *self, const DnDCommand *cmd, const uint8_t *pa drag_process_item_data(w, cmd->cell_y, cmd->more, payload, cmd->payload_sz); } break; case 'E': { - drag_process_item_data(w, cmd->cell_y, -1, payload, cmd->payload_sz); + if (cmd->cell_y == -1) { + drag_free_offer(w); + if (global_state.drag_source.is_active && global_state.drag_source.from_window == w->id) { + cancel_current_drag_source(); + } + } else drag_process_item_data(w, cmd->cell_y, -1, payload, cmd->payload_sz); } break; } }