From 9e2d42000f98790a71e41ca53616ff12c2f40623 Mon Sep 17 00:00:00 2001 From: "Anselm R. Garbe" Date: Thu, 6 Jul 2006 17:50:54 +0200 Subject: [PATCH] implemented blitz_selrequest handler which can be called after snarfing (which has to call XSetSelectionOwner) and receiving a SelectionRequest --- liblitz/blitz.c | 35 +++++++++++++++++++++++++++++++++++ liblitz/blitz.h | 1 + 2 files changed, 36 insertions(+) diff --git a/liblitz/blitz.c b/liblitz/blitz.c index 87321fa7..531a1bdd 100644 --- a/liblitz/blitz.c +++ b/liblitz/blitz.c @@ -7,9 +7,44 @@ #include #include #include +#include #include "blitz.h" +void +blitz_selrequest(Blitz *blitz, XSelectionRequestEvent *rq, char *text) +{ + /* + * PRECONDITION: + * 1. XSetSelectionOwner(blitz->dpy, XA_PRIMARY, w, CurrentTime); + * 2. Received SelectionRequest rq + */ + XEvent ev; + Atom target; + XTextProperty ct; + XICCEncodingStyle style; + char *cl[1]; + + ev.xselection.type = SelectionNotify; + ev.xselection.property = None; + ev.xselection.display = rq->display; + ev.xselection.requestor = rq->requestor; + ev.xselection.selection = rq->selection; + ev.xselection.target = rq->target; + ev.xselection.time = rq->time; + + if (rq->target == XA_STRING) { + style = XStringStyle; + target = XA_STRING; + } + cl[0] = text; + XmbTextListToTextProperty(blitz->dpy, cl, 1, style, &ct); + XChangeProperty(blitz->dpy, rq->requestor, rq->property, + target, 8, PropModeReplace, ct.value, ct.nitems); + ev.xselection.property = rq->property; + XSendEvent(blitz->dpy, rq->requestor, False, 0, &ev); +} + unsigned char * blitz_getselection(unsigned long offset, unsigned long *len, unsigned long *remain) { diff --git a/liblitz/blitz.h b/liblitz/blitz.h index 272e682b..a6cf4a1c 100644 --- a/liblitz/blitz.h +++ b/liblitz/blitz.h @@ -92,6 +92,7 @@ struct BlitzInput { /* blitz.c */ unsigned char *blitz_getselection(unsigned long offset, unsigned long *len, unsigned long *remain); +void blitz_selrequest(Blitz *blitz, XSelectionRequestEvent *rq, char *text); /* brush.c */ void blitz_draw_label(BlitzBrush *b, char *text);