Hacky patch to add xpaste support to dmenu is attached.
Key: ( ControlMask | XK_i )
This is just a little mockup with sselp and dmenu, it works, but should probably
be revised and reduced.
--pancake
On Sun, 17 Jun 2007 13:56:21 +0400
Alexander Polakov <[EMAIL PROTECTED]> wrote:
> * pancake <[EMAIL PROTECTED]> [070616 22:00]:
> > It can be possible to add 'x paste' support to dmenu? would be nice if
> > possible
> > to copy a string and paste it to a dmenu entry. (handle shift+insert and get
> > the string from the clipboard?).
> >
> > Thanks
> >
> > --pancake
> You can use getselection() from
> http://www.suckless.org/download/sselp-0.1.tar.gz.
> --
> Alexander Polakov | http://polachok.livejournal.com
diff -r 90f0e34e7f11 main.c
--- a/main.c Thu Feb 08 14:10:17 2007 +0100
+++ b/main.c Sun Jun 17 14:10:16 2007 +0200
@@ -12,6 +12,8 @@
#include <unistd.h>
#include <sys/select.h>
#include <sys/time.h>
+#include <X11/Xatom.h>
+#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>
@@ -43,6 +45,52 @@ static Item *curr = NULL;
static Item *curr = NULL;
static Window root;
static Window win;
+
+static void *
+emallocz(unsigned int size) {
+ void *res = calloc(1, size);
+
+ if(!res) {
+ fprintf(stderr, "fatal: could not malloc() %u bytes\n", size);
+ exit(EXIT_FAILURE);
+ }
+ return res;
+}
+
+static unsigned char *
+getselection(unsigned long offset, unsigned long *len, unsigned long *remain) {
+ Display *dpy;
+ Atom xa_clip_string;
+ Window w;
+ XEvent ev;
+ Atom typeret;
+ int format;
+ unsigned char *data;
+ unsigned char *result = NULL;
+
+ dpy = XOpenDisplay(NULL);
+ if(!dpy)
+ return NULL;
+ xa_clip_string = XInternAtom(dpy, "BLITZ_SEL_STRING", False);
+ w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 200, 200,
+ 1, CopyFromParent, CopyFromParent);
+ XConvertSelection(dpy, XA_PRIMARY, XA_STRING, xa_clip_string,
+ w, CurrentTime);
+ XFlush(dpy);
+ XNextEvent(dpy, &ev);
+ if(ev.type == SelectionNotify && ev.xselection.property != None) {
+ XGetWindowProperty(dpy, w, ev.xselection.property, offset, 4096L, False,
+ AnyPropertyType, &typeret, &format, len, remain, &data);
+ if(*len) {
+ result = emallocz(sizeof(unsigned char) * *len);
+ memcpy(result, data, *len);
+ }
+ XDeleteProperty(dpy, w, ev.xselection.property);
+ }
+ XDestroyWindow(dpy, w);
+ XCloseDisplay(dpy);
+ return result;
+}
static void
calcoffsets(void) {
@@ -162,6 +210,25 @@ kpress(XKeyEvent * e) {
|| IsMiscFunctionKey(ksym) || IsPFKey(ksym)
|| IsPrivateKeypadKey(ksym))
return;
+
+ /* handle clipboard */
+ if ((e->state & ControlMask) && (ksym == XK_i)) {
+ int len, offset, remain;
+ char *data;
+ len = offset = remain = 0;
+ do {
+ data = getselection(offset, &len, &remain);
+ for(i = 0; i < len; i++)
+ text[i] = data[i];
+ offset += len;
+ free(data);
+ }
+ while(remain);
+ text[len]='\0';
+ match(text);
+ drawmenu();
+ return;
+ }
/* first check if a control mask is omitted */
if(e->state & ControlMask) {
switch (ksym) {
@@ -489,3 +556,4 @@ UninitializedEnd:
XCloseDisplay(dpy);
return ret;
}
+