From 48c68c40585c9610a2e5fc24242099861caf81db Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Fri, 29 Oct 2021 14:10:38 -0700 Subject: [PATCH] add INCR per SO post --- xclipget.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/xclipget.c b/xclipget.c index e0ddb02..c1ba77c 100644 --- a/xclipget.c +++ b/xclipget.c @@ -14,6 +14,7 @@ Bool PrintSelection(Display *display, Window window, const char *bufname, const incrid = XInternAtom(display, "INCR", False); XEvent event; + XSelectInput (display, window, PropertyChangeMask); XConvertSelection(display, bufid, fmtid, propid, window, CurrentTime); do { XNextEvent(display, &event); @@ -21,15 +22,24 @@ Bool PrintSelection(Display *display, Window window, const char *bufname, const if (event.xselection.property) { - XGetWindowProperty(display, window, propid, 0, LONG_MAX/4, False, AnyPropertyType, + XGetWindowProperty(display, window, propid, 0, LONG_MAX/4, True, AnyPropertyType, &fmtid, &resbits, &ressize, &restail, (unsigned char**)&result); + if (fmtid != incrid) + printf("%.*s", (int)ressize, result); + XFree(result); if (fmtid == incrid) - printf("Buffer is too large and INCR reading is not implemented yet.\n"); - else - printf("%.*s", (int)ressize, result); + do { + do { + XNextEvent(display, &event); + } while (event.type != PropertyNotify || event.xproperty.atom != propid || event.xproperty.state != PropertyNewValue); + + XGetWindowProperty(display, window, propid, 0, LONG_MAX/4, True, AnyPropertyType, + &fmtid, &resbits, &ressize, &restail, (unsigned char**)&result); + printf("%.*s", (int)ressize, result); + XFree(result); + } while (ressize > 0); - XFree(result); return True; } else // request failed, e.g. owner can't convert to the target format