commit 9e2d42000f98790a71e41ca53616ff12c2f40623
parent 3465b463fa923a33ed695e96dbbccda2613cff6c
Author: Anselm R. Garbe <garbeam@wmii.de>
Date: Thu, 6 Jul 2006 17:50:54 +0200
implemented blitz_selrequest handler which can be called after snarfing (which has to call XSetSelectionOwner) and receiving a SelectionRequest
Diffstat:
2 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/liblitz/blitz.c b/liblitz/blitz.c
@@ -7,9 +7,44 @@
#include <cext.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
+#include <X11/Xutil.h>
#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
@@ -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);