From eb7bb70749079490da090a5ad01fd4546195378e Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sun, 18 Dec 2022 14:15:54 +0100 Subject: Revert "Do lazy get clipboard version, get as much data as possible at once. This seems to be the only reliable method and other programs do this" This reverts commit ff4eb7bb389930e345b0beaadfd97d7a219dc30a. --- src/window/window.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'src/window') diff --git a/src/window/window.c b/src/window/window.c index df56c94..6927992 100644 --- a/src/window/window.c +++ b/src/window/window.c @@ -727,11 +727,6 @@ static void mgl_window_on_receive_event(mgl_window *self, XEvent *xev, mgl_event return; } case SelectionClear: { - if(self->clipboard_string) { - free(self->clipboard_string); - self->clipboard_string = NULL; - self->clipboard_size = 0; - } event->type = MGL_EVENT_UNKNOWN; return; } @@ -1139,14 +1134,23 @@ bool mgl_window_get_clipboard(mgl_window *self, mgl_clipboard_callback callback, } } else if(xev.xselection.target == requested_clipboard_type) { bool got_data = false; + long chunk_size = 65536; + + //XDeleteProperty(context->connection, self->window, x11_context->incr_atom); + //XFlush(context->connection); while(mgl_clock_get_elapsed_time_seconds(&timeout_timer) < timeout_seconds) { + unsigned long offset = 0; + + /* offset is specified in XGetWindowProperty as a multiple of 32-bit (4 bytes) */ /* TODO: Wait for PropertyNotify event instead */ - while(XGetWindowProperty(context->connection, xev.xselection.requestor, xev.xselection.property, 0, 0x1fffffff, True, PropertyNewValue, &type, &format, &items, &remaining_bytes, &data) == Success) { + while(XGetWindowProperty(context->connection, xev.xselection.requestor, xev.xselection.property, offset/4, chunk_size, True, PropertyNewValue, &type, &format, &items, &remaining_bytes, &data) == Success) { if(mgl_clock_get_elapsed_time_seconds(&timeout_timer) >= timeout_seconds) break; if(type == x11_context->incr_atom) { + if(data) + chunk_size = *(long*)data; XDeleteProperty(context->connection, self->window, x11_context->incr_atom); XFlush(context->connection); XFree(data); @@ -1176,16 +1180,20 @@ bool mgl_window_get_clipboard(mgl_window *self, mgl_clipboard_callback callback, } } } + offset += num_items_bytes; if(data) { XFree(data); data = NULL; } - if(got_data && items == 0) { + if(got_data && num_items_bytes == 0/* && format == 8*/) { success = true; goto done; } + + if(remaining_bytes == 0) + break; } } @@ -1195,10 +1203,8 @@ bool mgl_window_get_clipboard(mgl_window *self, mgl_clipboard_callback callback, } done: - if(requested_clipboard_type) { + if(requested_clipboard_type) XDeleteProperty(context->connection, self->window, requested_clipboard_type); - XFlush(context->connection); - } return success; } -- cgit v1.2.3