aboutsummaryrefslogtreecommitdiff
path: root/src/window
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-12-18 12:56:31 +0100
committerdec05eba <dec05eba@protonmail.com>2022-12-18 12:56:31 +0100
commitff4eb7bb389930e345b0beaadfd97d7a219dc30a (patch)
tree51f32e943886495e585c87b2d903939a3e8496c8 /src/window
parent6b1767cb3cc704b94acbc5b4ebf3ee8c5c2b9102 (diff)
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
Diffstat (limited to 'src/window')
-rw-r--r--src/window/window.c26
1 files changed, 10 insertions, 16 deletions
diff --git a/src/window/window.c b/src/window/window.c
index 6927992..df56c94 100644
--- a/src/window/window.c
+++ b/src/window/window.c
@@ -727,6 +727,11 @@ 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;
}
@@ -1134,23 +1139,14 @@ 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, offset/4, chunk_size, True, PropertyNewValue, &type, &format, &items, &remaining_bytes, &data) == Success) {
+ while(XGetWindowProperty(context->connection, xev.xselection.requestor, xev.xselection.property, 0, 0x1fffffff, 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);
@@ -1180,20 +1176,16 @@ 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 && num_items_bytes == 0/* && format == 8*/) {
+ if(got_data && items == 0) {
success = true;
goto done;
}
-
- if(remaining_bytes == 0)
- break;
}
}
@@ -1203,8 +1195,10 @@ 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;
}