From dc9bf889a6850a64c31ff9e6decac23c733db247 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 19 Apr 2026 12:52:00 +0530 Subject: [PATCH] Fix chunking of t=k not handling metadata present only on first chunk --- kitty/dnd.c | 11 +++++++++++ kitty/state.h | 1 + kitty_tests/dnd.py | 5 +++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/kitty/dnd.c b/kitty/dnd.c index e0a52d5b1..ffddb387a 100644 --- a/kitty/dnd.c +++ b/kitty/dnd.c @@ -1238,6 +1238,7 @@ drag_free_offer(Window *w) { ds.state = DRAG_SOURCE_NONE; ds.pre_sent_total_sz = 0; ds.images_sent_total_sz = 0; + zero_at_ptr(&ds.in_flight_remote_file_data); } static void @@ -1907,6 +1908,16 @@ void drag_remote_file_data( Window *w, int32_t x, int32_t y, int32_t X, int32_t Y, bool has_more, const uint8_t *payload, size_t payload_sz ) { + if (ds.in_flight_remote_file_data.active) { + x = ds.in_flight_remote_file_data.x; y = ds.in_flight_remote_file_data.y; + ds.in_flight_remote_file_data.Y = Y; ds.in_flight_remote_file_data.X = X; + } + if (!has_more) zero_at_ptr(&ds.in_flight_remote_file_data); + else if (!ds.in_flight_remote_file_data.active) { + ds.in_flight_remote_file_data.active = true; + ds.in_flight_remote_file_data.x = x; ds.in_flight_remote_file_data.y = y; + ds.in_flight_remote_file_data.Y = Y; ds.in_flight_remote_file_data.X = X; + } size_t item_idx = ds.num_mimes; for (size_t i = 0; i < ds.num_mimes; i++) { if (ds.items[i].requested_remote_files) { diff --git a/kitty/state.h b/kitty/state.h index 1564aca66..9712a84b0 100644 --- a/kitty/state.h +++ b/kitty/state.h @@ -319,6 +319,7 @@ typedef struct Window { struct { double x, y; monotonic_t at; } initial_left_press; char *mimes_buf; size_t num_mimes, bufsz; size_t total_remote_data_size; + struct { int32_t x, y, X, Y; bool active; } in_flight_remote_file_data; struct { const char *mime_type; uint8_t *optional_data; size_t data_size, data_capacity; base64_state base64_state; bool data_decode_initialized, is_uri_list, requested_remote_files; diff --git a/kitty_tests/dnd.py b/kitty_tests/dnd.py index 0ddedb133..234834f78 100644 --- a/kitty_tests/dnd.py +++ b/kitty_tests/dnd.py @@ -200,7 +200,7 @@ def client_drag_cancel(client_id: int = 0) -> bytes: def client_remote_file( - uri_idx: int, data_b64: str = '', *, + uri_idx: int = 0, data_b64: str = '', *, item_type: int = 0, more: bool = False, parent_handle: int = 0, entry_num: int = 0, client_id: int = 0, @@ -2935,7 +2935,7 @@ class TestDnDProtocol(BaseTest): b64_2 = standard_b64encode(chunk2).decode() parse_bytes(screen, client_remote_file(1, b64_1, item_type=2, more=True)) self._assert_no_output(cap, wid) - parse_bytes(screen, client_remote_file(1, b64_2, item_type=2)) + parse_bytes(screen, client_remote_file(data_b64=b64_2)) self._assert_no_output(cap, wid) # End of listing parse_bytes(screen, client_remote_file(1, '', item_type=2)) @@ -2945,6 +2945,7 @@ class TestDnDProtocol(BaseTest): b64 = standard_b64encode(b'c1').decode() parse_bytes(screen, client_remote_file( 1, b64, item_type=0, parent_handle=2, entry_num=1)) + self._assert_no_output(cap, wid) parse_bytes(screen, client_remote_file( 1, '', item_type=0, parent_handle=2, entry_num=1)) self._assert_no_output(cap, wid)