Skip to content

Commit aa57cef

Browse files
committed
More work on DnD protocol
1 parent ba95be8 commit aa57cef

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

kitty/dnd.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,10 @@ drag_free_offer(Window *w) {
10641064
for (size_t i=0; i < ds.num_mimes; i++) {
10651065
free(ds.items[i].optional_data);
10661066
if (ds.items[i].fd_plus_one > 0) safe_close(ds.items[i].fd_plus_one - 1, __FILE__, __LINE__);
1067+
if (ds.items[i].uri_list) {
1068+
for (size_t k = 0; k < ds.items[i].num_uris; k++) free((char*)ds.items[i].uri_list[k]);
1069+
free(ds.items[i].uri_list);
1070+
}
10671071
}
10681072
free(ds.items);
10691073
ds.items = NULL;
@@ -1471,11 +1475,35 @@ drag_process_item_data(Window *w, size_t idx, int has_more, const uint8_t *paylo
14711475
}
14721476
}
14731477

1478+
static const char**
1479+
parse_uri_list(int fd) {
1480+
(void)fd;
1481+
// TODO: Implement this, it should read the uri list from fd, parse
1482+
// it ignoring comments, see get_nth_file_url() for an example of
1483+
// parsing a uri list. If an error occurs it should call abrt() with
1484+
// appropriate error code and return NULL. The returned value should
1485+
// be a list of strings alloced by malloc with each string also
1486+
// alloced by malloc.
1487+
return NULL;
1488+
}
1489+
1490+
14741491
void
14751492
drag_remote_file_data(
14761493
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
14771494
) {
1478-
(void)w; (void)x; (void)y; (void)X; (void)Y; (void)has_more; (void)payload; (void)payload_sz;
1495+
size_t item_idx = ds.num_mimes;
1496+
for (size_t i = 0; i < ds.num_mimes; i++) {
1497+
if (ds.items[i].requested_remote_files) {
1498+
item_idx = i; break;
1499+
}
1500+
}
1501+
if (item_idx == ds.num_mimes || ds.items[item_idx].fd_plus_one == 0) abrt(EINVAL);
1502+
if (ds.items[item_idx].uri_list == NULL) {
1503+
ds.items[item_idx].uri_list = parse_uri_list(ds.items[item_idx].fd_plus_one-1);
1504+
if (!ds.items[item_idx].uri_list) return;
1505+
}
1506+
(void)x; (void)y; (void)X; (void)Y; (void)has_more; (void)payload; (void)payload_sz;
14791507
// TODO: Implement this
14801508
}
14811509
#undef img

kitty/state.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ typedef struct Window {
303303
struct {
304304
const char *mime_type; uint8_t *optional_data; size_t data_size, data_capacity; base64_state base64_state;
305305
bool data_decode_initialized, is_uri_list, requested_remote_files; int fd_plus_one;
306+
const char** uri_list; size_t num_uris;
306307
} *items;
307308
struct {
308309
int width, height, fmt; uint8_t *data; size_t sz, capacity; bool started; base64_state base64_state;

0 commit comments

Comments
 (0)