From a87441b91ae8a79647d4638365f71ab9f2b6209c Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 2 May 2026 17:16:27 +0530 Subject: [PATCH] Fix failing test --- docs/dnd-protocol.rst | 2 ++ kitty/screen.c | 21 +++++++++++++++++---- kitty/screen.h | 4 ++++ kitty_tests/dnd_kitten.py | 1 + 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/docs/dnd-protocol.rst b/docs/dnd-protocol.rst index 5e6c942b0..3a927d88f 100644 --- a/docs/dnd-protocol.rst +++ b/docs/dnd-protocol.rst @@ -26,6 +26,8 @@ Subsequent chunks may optionally omit all metadata except the ``m`` and ``i`` keys. While a chunked transfer is in progress it is a protocol error to for the sending side to send any protocol related escape codes other than chunked ones. +In particular, this means that the receiving side should use the metadata from +the first chunk in a chain of chunks only. All integer values used in this escape code must be 32-bit signed or unsigned integers encoded in decimal representation. diff --git a/kitty/screen.c b/kitty/screen.c index 401f79410..d297e60f6 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -176,6 +176,7 @@ static Line* range_line_(Screen *self, int y); void screen_reset(Screen *self) { screen_pause_rendering(self, false, 0); + self->dnd_chunking.active = false; self->extra_cursors.count = 0; zero_at_ptr(&self->extra_cursors.color); self->extra_cursors.dirty = true; self->main_pointer_shape_stack.count = 0; self->alternate_pointer_shape_stack.count = 0; if (self->linebuf == self->alt_linebuf) screen_toggle_screen_buffer(self, true, true); @@ -1523,10 +1524,22 @@ screen_mark_potential_url_drag(Screen *self) { } void -screen_handle_dnd_command(Screen *self, const DnDCommand *cmd, const uint8_t *payload) { - if (!self->window_id) return; - Window *w = window_for_window_id(self->window_id); - if (!w) return; +screen_handle_dnd_command(Screen *self, const DnDCommand *cmd_, const uint8_t *payload) { + Window *w; + if (!self->window_id || !(w = window_for_window_id(self->window_id))) return; + const DnDCommand *cmd; DnDCommand copy; + if (self->dnd_chunking.active) { + copy = self->dnd_chunking.metadata; + copy.more = cmd_->more; copy.payload_sz = cmd_->payload_sz; + cmd = © + self->dnd_chunking.active = cmd->more != 0; + } else { + cmd = cmd_; + if (cmd_->more) { + self->dnd_chunking.active = true; + self->dnd_chunking.metadata = *cmd_; + } + } switch(cmd->type) { case 'a': if (cmd->cell_x == 1) drop_register_machine_id(w, payload, cmd->payload_sz); diff --git a/kitty/screen.h b/kitty/screen.h index d2554b5a7..dee5402aa 100644 --- a/kitty/screen.h +++ b/kitty/screen.h @@ -207,6 +207,10 @@ typedef struct { ListOfChars *lc; monotonic_t parsing_at; ExtraCursors extra_cursors; + struct { + bool active; + DnDCommand metadata; + } dnd_chunking; } Screen; #define pixel_scroll_enabled(screen) (OPT(pixel_scroll) && !screen->paused_rendering.expires_at && screen->linebuf == screen->main_linebuf) diff --git a/kitty_tests/dnd_kitten.py b/kitty_tests/dnd_kitten.py index ecb91286b..62f5f362f 100644 --- a/kitty_tests/dnd_kitten.py +++ b/kitty_tests/dnd_kitten.py @@ -339,6 +339,7 @@ def test_dnd_kitten_drag(self): self.img_drag_data = None def read_drag_data(self, mime): + # self.pty.log_data_flow = True ans = b'' while True: try: