diff options
author | dec05eba <dec05eba@protonmail.com> | 2022-09-10 00:06:03 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2022-09-10 00:06:03 +0200 |
commit | c44cf446ee68df18a4441e0080c99e7a856a13d3 (patch) | |
tree | be1e142291be296834f41d8f98d0c472b1a738bd | |
parent | d6a5f9c394aea65684aa9d340ef26849bf49a2cc (diff) |
Fix incorrect clipboard callback data
-rw-r--r-- | src/window/window.c | 13 |
1 files 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; } } |