added gridsel to gridwm 26e134b8
Anselm R. Garbe · 2006-07-11 13:21 7 file(s) · +99 −13
Makefile +8 −2
7 7
WMOBJ = ${WMSRC:.c=.o}
8 8
MENSRC = menu.c draw.c util.c
9 9
MENOBJ = ${MENSRC:.c=.o}
10 +
SELSRC = gridsel.c util.c
11 +
SELOBJ = ${SELSRC:.c=.o}
10 12
MAN1 = gridwm.1 gridmenu.1
11 -
BIN = gridwm gridmenu     
13 +
BIN = gridwm gridmenu gridsel 
12 14
13 -
all: config gridwm gridmenu
15 +
all: config gridwm gridmenu gridsel
14 16
	@echo finished
15 17
16 18
config:
33 35
gridwm: ${WMOBJ}
34 36
	@echo LD $@
35 37
	@${CC} -o $@ ${WMOBJ} ${LDFLAGS}
38 +
39 +
gridsel: ${SELOBJ}
40 +
	@echo LD $@
41 +
	@${CC} -o $@ ${SELOBJ} ${LDFLAGS}
36 42
37 43
clean:
38 44
	rm -f gridwm gridmenu *.o core
config.h +3 −0
9 9
#define BORDERCOLOR	"#000000"
10 10
#define STATUSCMD	"echo -n `date` `uptime | sed 's/.*://; s/,//g'`" \
11 11
					" `acpi | awk '{print $4}' | sed 's/,//'`"
12 +
#define PLCMD		"`ls -lL /bin /sbin /usr/bin /usr/local/bin 2>/dev/null | awk 'NF>2 && $1 ~ /^[^d].*x/ {print $NF}' | sort | uniq | gridmenu`"
13 +
12 14
#define KEYS		\
13 15
	{ Mod1Mask, XK_Return, run, "xterm -u8 -bg black -fg white -fn '-*-terminus-medium-*-*-*-14-*-*-*-*-*-iso10646-*'" }, \
16 +
	{ Mod1Mask, XK_p, run, PLCMD }, \
14 17
	{ Mod1Mask | ShiftMask, XK_q, quit, NULL},
15 18
event.c +2 −4
81 81
static void
82 82
destroynotify(XEvent *e)
83 83
{
84 -
#if 0
85 84
	Client *c;
86 85
	XDestroyWindowEvent *ev = &e->xdestroywindow;
87 86
88 -
	if((c = client_of_win(ev->window)))
89 -
		destroy_client(c);
90 -
#endif
87 +
	if((c = getclient(ev->window)))
88 +
		unmanage(c);
91 89
}
92 90
93 91
static void
gridsel.c (added) +47 −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 +
12 +
static char version[] = "gridsel - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n";
13 +
14 +
static void
15 +
usage()
16 +
{
17 +
	fprintf(stderr, "%s\n", "usage: gridsel [-v]\n");
18 +
	exit(1);
19 +
}
20 +
21 +
int
22 +
main(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 +
}
menu.c +0 −7
356 356
	char *maxname;
357 357
	XEvent ev;
358 358
359 -
	char buf[256];
360 -
361 -
	pipe_spawn(buf, sizeof(buf), NULL, STATUSCMD);
362 -
	fputs(buf, stderr);
363 -
364 -
	return 0;
365 -
366 359
	/* command line args */
367 360
	for(i = 1; i < argc; i++) {
368 361
		if (argv[i][0] == '-')
util.c +38 −0
10 10
#include <sys/types.h>
11 11
#include <sys/wait.h>
12 12
#include <unistd.h>
13 +
#include <X11/Xatom.h>
13 14
14 15
#include "util.h"
15 16
147 148
	}
148 149
	wait(0);
149 150
}
151 +
152 +
153 +
unsigned char *
154 +
getselection(unsigned long offset, unsigned long *len, unsigned long *remain)
155 +
{
156 +
	Display *dpy;
157 +
	Atom xa_clip_string;
158 +
	Window w;
159 +
	XEvent ev;
160 +
	Atom typeret;
161 +
	int format;
162 +
	unsigned char *data;
163 +
	unsigned char *result = NULL;
164 +
165 +
	dpy = XOpenDisplay(0);
166 +
	if(!dpy)
167 +
		return NULL;
168 +
	xa_clip_string = XInternAtom(dpy, "_SEL_STRING", False);
169 +
	w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 200, 200,
170 +
			1, CopyFromParent, CopyFromParent);
171 +
	XConvertSelection(dpy, XA_PRIMARY, XA_STRING, xa_clip_string,
172 +
			w, CurrentTime);
173 +
	XFlush(dpy);
174 +
	XNextEvent(dpy, &ev);
175 +
	if(ev.type == SelectionNotify && ev.xselection.property != None) {
176 +
		XGetWindowProperty(dpy, w, ev.xselection.property, offset, 4096L, False,
177 +
				AnyPropertyType, &typeret, &format, len, remain, &data);
178 +
		if(*len) {
179 +
			result = emalloc(sizeof(unsigned char) * *len);
180 +
			memcpy(result, data, *len);
181 +
		}
182 +
		XDeleteProperty(dpy, w, ev.xselection.property);
183 +
	}
184 +
	XDestroyWindow(dpy, w);
185 +
	XCloseDisplay(dpy);
186 +
	return result;
187 +
}
util.h +1 −0
17 17
void pipe_spawn(char *buf, unsigned int len, Display *dpy, const char *cmd);
18 18
extern void spawn(Display *dpy, const char *cmd);
19 19
extern void swap(void **p1, void **p2);
20 +
unsigned char *getselection(unsigned long offset, unsigned long *len, unsigned long *remain);