From c44cf446ee68df18a4441e0080c99e7a856a13d3 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 10 Sep 2022 00:06:03 +0200 Subject: Fix incorrect clipboard callback data --- src/window/window.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/window/window.c b/src/window/window.c index a7c9a71..285b255 100644 --- a/src/window/window.c +++ b/src/window/window.c @@ -955,7 +955,7 @@ bool mgl_window_get_clipboard(mgl_window *self, mgl_clipboard_callback callback, Atom type; int format; unsigned long items; - unsigned long remaining_bytes; + unsigned long remaining_bytes = 32768; unsigned char *data = NULL; if(xev.xselection.target == XA_TARGETS && requested_clipboard_type == None) { @@ -975,7 +975,9 @@ bool mgl_window_get_clipboard(mgl_window *self, mgl_clipboard_callback callback, } else if(xev.xselection.target == requested_clipboard_type) { bool success = true; unsigned long offset = 0; - while(XGetWindowProperty(context->connection, self->window, x11_context->clipboard_atom, offset, 32768, False, AnyPropertyType, &type, &format, &items, &remaining_bytes, &data) == Success && data) { + + /* offset is specified in XGetWindowProperty as a multiple of 32-bit (4 bytes) */ + while(XGetWindowProperty(context->connection, self->window, x11_context->clipboard_atom, offset/4, 32768, False, AnyPropertyType, &type, &format, &items, &remaining_bytes, &data) == Success && data) { const mgl_clipboard_type clipboard_type = atom_type_to_supported_clipboard_type(x11_context, type, format); if(type != x11_context->incr_atom && clipboard_type != -1) { if(!callback(data, items, clipboard_type, userdata)) { @@ -986,11 +988,18 @@ bool mgl_window_get_clipboard(mgl_window *self, mgl_clipboard_callback callback, offset += (items * (format/8)); // format is the bit size of the data XFree(data); + if(remaining_bytes == 0) + break; + if(mgl_clock_get_elapsed_time_seconds(&timeout_timer) >= timeout_seconds) { success = false; break; } } + + if(remaining_bytes != 0) + success = false; + return success; } } -- cgit v1.2.3