summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Makefile10
-rw-r--r--gridsel.c47
-rw-r--r--util.c38
-rw-r--r--util.h2
4 files changed, 2 insertions, 95 deletions
diff --git a/Makefile b/Makefile
index b38889b..e324e5b 100644
--- a/Makefile
+++ b/Makefile
@@ -7,12 +7,10 @@ WMSRC = bar.c client.c cmd.c draw.c event.c key.c util.c wm.c
7WMOBJ = ${WMSRC:.c=.o} 7WMOBJ = ${WMSRC:.c=.o}
8MENSRC = menu.c draw.c util.c 8MENSRC = menu.c draw.c util.c
9MENOBJ = ${MENSRC:.c=.o} 9MENOBJ = ${MENSRC:.c=.o}
10SELSRC = gridsel.c util.c
11SELOBJ = ${SELSRC:.c=.o}
12MAN1 = gridwm.1 gridmenu.1 10MAN1 = gridwm.1 gridmenu.1
13BIN = gridwm gridmenu gridsel 11BIN = gridwm gridmenu
14 12
15all: config gridwm gridmenu gridsel 13all: config gridwm gridmenu
16 @echo finished 14 @echo finished
17 15
18config: 16config:
@@ -36,10 +34,6 @@ gridwm: ${WMOBJ}
36 @echo LD $@ 34 @echo LD $@
37 @${CC} -o $@ ${WMOBJ} ${LDFLAGS} 35 @${CC} -o $@ ${WMOBJ} ${LDFLAGS}
38 36
39gridsel: ${SELOBJ}
40 @echo LD $@
41 @${CC} -o $@ ${SELOBJ} ${LDFLAGS}
42
43clean: 37clean:
44 rm -f gridwm gridmenu *.o core 38 rm -f gridwm gridmenu *.o core
45 39
diff --git a/gridsel.c b/gridsel.c
deleted file mode 100644
index c76105e..0000000
--- a/gridsel.c
+++ /dev/null
@@ -1,47 +0,0 @@
1/*
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
4 */
5
6#include <stdlib.h>
7#include <stdio.h>
8#include <string.h>
9
10#include <util.h>
11
12static char version[] = "gridsel - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n";
13
14static void
15usage()
16{
17 fprintf(stderr, "%s\n", "usage: gridsel [-v]\n");
18 exit(1);
19}
20
21int
22main(int argc, char **argv)
23{
24 unsigned char *data;
25 unsigned long i, offset, len, remain;
26
27 /* command line args */
28 if(argc > 1) {
29 if(!strncmp(argv[1], "-v", 3)) {
30 fprintf(stdout, "%s", version);
31 exit(0);
32 } else
33 usage();
34 }
35 len = offset = remain = 0;
36 do {
37 data = getselection(offset, &len, &remain);
38 for(i = 0; i < len; i++)
39 putchar(data[i]);
40 offset += len;
41 free(data);
42 }
43 while(remain);
44 if(offset)
45 putchar('\n');
46 return 0;
47}
diff --git a/util.c b/util.c
index 2cc2d4d..76ba5ab 100644
--- a/util.c
+++ b/util.c
@@ -10,7 +10,6 @@
10#include <sys/types.h> 10#include <sys/types.h>
11#include <sys/wait.h> 11#include <sys/wait.h>
12#include <unistd.h> 12#include <unistd.h>
13#include <X11/Xatom.h>
14 13
15#include "util.h" 14#include "util.h"
16 15
@@ -139,40 +138,3 @@ pipe_spawn(char *buf, unsigned int len, Display *dpy, char *argv[])
139 } 138 }
140 wait(0); 139 wait(0);
141} 140}
142
143
144unsigned char *
145getselection(unsigned long offset, unsigned long *len, unsigned long *remain)
146{
147 Display *dpy;
148 Atom xa_clip_string;
149 Window w;
150 XEvent ev;
151 Atom typeret;
152 int format;
153 unsigned char *data;
154 unsigned char *result = NULL;
155
156 dpy = XOpenDisplay(0);
157 if(!dpy)
158 return NULL;
159 xa_clip_string = XInternAtom(dpy, "_SEL_STRING", False);
160 w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 200, 200,
161 1, CopyFromParent, CopyFromParent);
162 XConvertSelection(dpy, XA_PRIMARY, XA_STRING, xa_clip_string,
163 w, CurrentTime);
164 XFlush(dpy);
165 XNextEvent(dpy, &ev);
166 if(ev.type == SelectionNotify && ev.xselection.property != None) {
167 XGetWindowProperty(dpy, w, ev.xselection.property, offset, 4096L, False,
168 AnyPropertyType, &typeret, &format, len, remain, &data);
169 if(*len) {
170 result = emalloc(sizeof(unsigned char) * *len);
171 memcpy(result, data, *len);
172 }
173 XDeleteProperty(dpy, w, ev.xselection.property);
174 }
175 XDestroyWindow(dpy, w);
176 XCloseDisplay(dpy);
177 return result;
178}
diff --git a/util.h b/util.h
index 00f0714..76fc09f 100644
--- a/util.h
+++ b/util.h
@@ -18,7 +18,5 @@ extern void failed_assert(char *a, char *file, int line);
18extern void pipe_spawn(char *buf, unsigned int len, Display *dpy, char *argv[]); 18extern void pipe_spawn(char *buf, unsigned int len, Display *dpy, char *argv[]);
19extern void spawn(Display *dpy, char *argv[]); 19extern void spawn(Display *dpy, char *argv[]);
20extern void swap(void **p1, void **p2); 20extern void swap(void **p1, void **p2);
21extern unsigned char *getselection(unsigned long offset, unsigned long *len,
22 unsigned long *remain);
23extern unsigned int tokenize(char **result, unsigned int reslen, 21extern unsigned int tokenize(char **result, unsigned int reslen,
24 char *str, char delim); 22 char *str, char delim);