mirror of
https://github.com/kovidgoyal/kitty.git
synced 2026-07-03 11:12:30 +08:00
When queueing dnd data to send to the client keep space available in the queue so that inut events are not dropped while the dnd is in progress
This commit is contained in:
@@ -370,17 +370,18 @@ static const unsigned write_buf_limit = 100 * 1024 * 1024;
|
||||
children_mutex(unlock);
|
||||
|
||||
void
|
||||
schedule_write_to_child_if_possible(id_type id, const char *data, size_t sz, bool *found, bool *too_much_data) {
|
||||
schedule_write_to_child_if_possible(id_type id, const char *data, size_t sz, bool *found, bool *too_much_data, size_t keep_space) {
|
||||
children_mutex(lock);
|
||||
ChildMonitor *self = the_monitor;
|
||||
*found = false; *too_much_data = false;
|
||||
size_t limit = write_buf_limit > keep_space ? write_buf_limit - keep_space : 0;
|
||||
for (size_t i = 0; i < self->count; i++) {
|
||||
if (children[i].id == id) {
|
||||
Screen *screen = children[i].screen;
|
||||
screen_mutex(lock, write);
|
||||
size_t space_left = screen->write_buf_sz - screen->write_buf_used;
|
||||
if (space_left < sz) {
|
||||
if (screen->write_buf_used + sz > write_buf_limit) {
|
||||
if (screen->write_buf_used + sz > limit) {
|
||||
*too_much_data = true;
|
||||
screen_mutex(unlock, write);
|
||||
break;
|
||||
|
||||
@@ -315,7 +315,7 @@ const char* cursor_as_sgr(const Cursor *);
|
||||
PyObject* cm_thread_write(PyObject *self, PyObject *args);
|
||||
bool schedule_write_to_child(id_type id, unsigned int num, ...);
|
||||
bool schedule_write_to_child_python(id_type id, const char *prefix, PyObject* tuple_of_str_or_bytes, const char *suffix);
|
||||
void schedule_write_to_child_if_possible(id_type id, const char *data, size_t sz, bool *found, bool *too_much_data);
|
||||
void schedule_write_to_child_if_possible(id_type id, const char *data, size_t sz, bool *found, bool *too_much_data, size_t keep_space);
|
||||
bool set_iutf8(int, bool);
|
||||
|
||||
DynamicColor colorprofile_to_color(const ColorProfile *self, DynamicColor entry, DynamicColor defval);
|
||||
|
||||
@@ -236,6 +236,8 @@ test_write_chunk(id_type id, const char *buf, size_t sz) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static const size_t keep_write_to_child_queue_space = 32 * 1024;
|
||||
|
||||
static size_t
|
||||
send_payload_to_child(id_type id, uint32_t client_id, const char *header, size_t header_sz, const char *data, const size_t data_sz, bool as_base64) {
|
||||
size_t offset = 0;
|
||||
@@ -246,7 +248,7 @@ send_payload_to_child(id_type id, uint32_t client_id, const char *header, size_t
|
||||
buf[header_sz++] = 0x1b; buf[header_sz++] = '\\';
|
||||
if (!test_write_chunk(id, buf, header_sz)) {
|
||||
bool found, too_much_data;
|
||||
schedule_write_to_child_if_possible(id, buf, header_sz, &found, &too_much_data);
|
||||
schedule_write_to_child_if_possible(id, buf, header_sz, &found, &too_much_data, keep_write_to_child_queue_space);
|
||||
if (too_much_data) return 0;
|
||||
}
|
||||
return 1;
|
||||
@@ -270,7 +272,7 @@ send_payload_to_child(id_type id, uint32_t client_id, const char *header, size_t
|
||||
buf[p++] = 0x1b; buf[p++] = '\\';
|
||||
if (!test_write_chunk(id, buf, p)) {
|
||||
bool found, too_much_data;
|
||||
schedule_write_to_child_if_possible(id, buf, p, &found, &too_much_data);
|
||||
schedule_write_to_child_if_possible(id, buf, p, &found, &too_much_data, keep_write_to_child_queue_space);
|
||||
if (too_much_data) break;
|
||||
if (!found) return data_sz;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user