libdraw now has own repo 26b9f3de
Connor Lane Smith · 2010-06-30 01:36 16 file(s) · +8 −242
Makefile +2 −6
18 18
	@echo CC $<
19 19
	@${CC} -c ${CFLAGS} $<
20 20
21 -
${OBJ}: config.h config.mk draw/libdraw.a
21 +
${OBJ}: config.h config.mk
22 22
23 23
config.h:
24 24
	@echo creating $@ from config.def.h
28 28
	@echo CC -o $@
29 29
	@${CC} -o $@ $< ${LDFLAGS}
30 30
31 -
draw/libdraw.a:
32 -
	@cd draw && make
33 -
34 31
clean:
35 32
	@echo cleaning
36 33
	@rm -f dinput dmenu ${OBJ} dmenu-${VERSION}.tar.gz
37 -
	@cd draw && make clean
38 34
39 35
dist: clean
40 36
	@echo creating dist tarball
41 37
	@mkdir -p dmenu-${VERSION}
42 -
	@cp -R LICENSE Makefile README config.mk dmenu.1 config.def.h dmenu_path dmenu_run draw ${SRC} dmenu-${VERSION}
38 +
	@cp -R LICENSE Makefile README config.mk dmenu.1 config.def.h dmenu_path dmenu_run ${SRC} dmenu-${VERSION}
43 39
	@tar -cf dmenu-${VERSION}.tar dmenu-${VERSION}
44 40
	@gzip dmenu-${VERSION}.tar
45 41
	@rm -rf dmenu-${VERSION}
README +2 −0
6 6
Requirements
7 7
------------
8 8
In order to build dmenu you need the Xlib header files.
9 +
You also need libdraw, available from http://hg.suckless.org/libdraw
10 +
9 11
Pasting the X selection to dmenu requires the sselp utility at runtime.
10 12
11 13
config.mk +2 −2
15 15
XINERAMAFLAGS = -DXINERAMA
16 16
17 17
# includes and libs
18 -
INCS = -I. -Idraw -I/usr/include -I${X11INC}
19 -
LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -Ldraw -ldraw ${XINERAMALIBS}
18 +
INCS = -I. -I/usr/include -I${X11INC}
19 +
LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -ldraw ${XINERAMALIBS}
20 20
21 21
# flags
22 22
CPPFLAGS = -D_BSD_SOURCE -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
dinput.c +1 −1
12 12
#ifdef XINERAMA
13 13
#include <X11/extensions/Xinerama.h>
14 14
#endif
15 +
#include <draw.h>
15 16
16 17
/* macros */
17 18
#define CLEANMASK(mask)         (mask & ~(numlockmask | LockMask))
30 31
static void setup(Bool topbar);
31 32
32 33
#include "config.h"
33 -
#include "draw.h"
34 34
35 35
/* variables */
36 36
static char *prompt = NULL;
dmenu.c +1 −1
13 13
#ifdef XINERAMA
14 14
#include <X11/extensions/Xinerama.h>
15 15
#endif
16 +
#include <draw.h>
16 17
17 18
/* macros */
18 19
#define CLEANMASK(mask)         (mask & ~(numlockmask | LockMask))
46 47
static void setup(void);
47 48
48 49
#include "config.h"
49 -
#include "draw.h"
50 50
51 51
/* variables */
52 52
static char **argp = NULL;
draw/Makefile (deleted) +0 −26
1 -
# libdraw - dynamic drawing library
2 -
# See LICENSE file for copyright and license details.
3 -
4 -
include ../config.mk
5 -
6 -
SRC = cleanupdraw.c drawsquare.c drawtext.c eprint.c getcolor.c initfont.c \
7 -
setupdraw.c textnw.c textw.c
8 -
OBJ = ${SRC:.c=.o}
9 -
10 -
all: libdraw.a
11 -
12 -
.c.o:
13 -
	@echo CC $<
14 -
	@${CC} -c ${CFLAGS} $<
15 -
16 -
${OBJ}: ../config.mk draw.h
17 -
18 -
libdraw.a: ${OBJ}
19 -
	@echo AR $@
20 -
	@ar cr $@ $+
21 -
22 -
clean:
23 -
	@echo cleaning libdraw
24 -
	@rm -f libdraw.a ${OBJ}
25 -
26 -
.PHONY: all options clean
draw/cleanupdraw.c (deleted) +0 −13
1 -
/* See LICENSE file for copyright and license details. */
2 -
#include <X11/Xlib.h>
3 -
#include "draw.h"
4 -
5 -
void
6 -
cleanupdraw(DC *dc) {
7 -
	if(dc->font.set)
8 -
		XFreeFontSet(dc->dpy, dc->font.set);
9 -
	else
10 -
		XFreeFont(dc->dpy, dc->font.xfont);
11 -
	XFreePixmap(dc->dpy, dc->drawable);
12 -
	XFreeGC(dc->dpy, dc->gc);
13 -
}
draw/draw.h (deleted) +0 −34
1 -
/* See LICENSE file for copyright and license details. */
2 -
#include <X11/Xlib.h>
3 -
4 -
/* enums */
5 -
enum { ColBorder, ColFG, ColBG, ColLast };
6 -
7 -
/* typedefs */
8 -
typedef struct {
9 -
	int x, y, w, h;
10 -
	Drawable drawable;
11 -
	Display *dpy;
12 -
	GC gc;
13 -
	struct {
14 -
		XFontStruct *xfont;
15 -
		XFontSet set;
16 -
		int ascent;
17 -
		int descent;
18 -
		int height;
19 -
	} font;
20 -
} DC; /* draw context */
21 -
22 -
/* forward declarations */
23 -
void cleanupdraw(DC *dc);
24 -
void drawsquare(DC *dc, Bool filled, unsigned long col[ColLast], Bool invert);
25 -
void drawtext(DC *dc, const char *text, unsigned long col[ColLast], Bool invert);
26 -
void eprint(const char *fmt, ...);
27 -
unsigned long getcolor(DC *dc, const char *colstr);
28 -
void initfont(DC *dc, const char *fontstr);
29 -
void setupdraw(DC *dc, Window w);
30 -
int textnw(DC *dc, const char *text, unsigned int len);
31 -
int textw(DC *dc, const char *text);
32 -
33 -
/* variables */
34 -
extern const char *progname;
draw/drawsquare.c (deleted) +0 −19
1 -
/* See LICENSE file for copyright and license details. */
2 -
#include <X11/Xlib.h>
3 -
#include "draw.h"
4 -
5 -
void
6 -
drawsquare(DC *dc, Bool filled, unsigned long col[ColLast], Bool invert) {
7 -
	int n;
8 -
	XRectangle r = { dc->x, dc->y, dc->w, dc->h };
9 -
10 -
	XSetForeground(dc->dpy, dc->gc, col[invert ? ColBG : ColFG]);
11 -
	n = ((dc->font.ascent + dc->font.descent + 2) / 4) + (filled ? 1 : 0);
12 -
	r.width = r.height = n;
13 -
	r.x = dc->x + 1;
14 -
	r.y = dc->y + 1;
15 -
	if(filled)
16 -
		XFillRectangles(dc->dpy, dc->drawable, dc->gc, &r, 1);
17 -
	else
18 -
		XDrawRectangles(dc->dpy, dc->drawable, dc->gc, &r, 1);
19 -
}
draw/drawtext.c (deleted) +0 −34
1 -
/* See LICENSE file for copyright and license details. */
2 -
#include <string.h>
3 -
#include <X11/Xlib.h>
4 -
#include "draw.h"
5 -
6 -
#define MIN(a, b)               ((a) < (b) ? (a) : (b))
7 -
8 -
void
9 -
drawtext(DC *dc, const char *text, unsigned long col[ColLast], Bool invert) {
10 -
	char buf[256];
11 -
	int i, x, y, h, len, olen;
12 -
	XRectangle r = { dc->x, dc->y, dc->w, dc->h };
13 -
14 -
	XSetForeground(dc->dpy, dc->gc, col[invert ? ColFG : ColBG]);
15 -
	XFillRectangles(dc->dpy, dc->drawable, dc->gc, &r, 1);
16 -
	if(!text)
17 -
		return;
18 -
	olen = strlen(text);
19 -
	h = dc->font.height;
20 -
	y = dc->y + ((h+2) / 2) - (h / 2) + dc->font.ascent;
21 -
	x = dc->x + (h / 2);
22 -
	/* shorten text if necessary */
23 -
	for(len = MIN(olen, sizeof buf); len && textnw(dc, text, len) > dc->w - h; len--);
24 -
	if(!len)
25 -
		return;
26 -
	memcpy(buf, text, len);
27 -
	if(len < olen)
28 -
		for(i = len; i && i > len - 3; buf[--i] = '.');
29 -
	XSetForeground(dc->dpy, dc->gc, col[invert ? ColBG : ColFG]);
30 -
	if(dc->font.set)
31 -
		XmbDrawString(dc->dpy, dc->drawable, dc->font.set, dc->gc, x, y, buf, len);
32 -
	else
33 -
		XDrawString(dc->dpy, dc->drawable, dc->gc, x, y, buf, len);
34 -
}
draw/eprint.c (deleted) +0 −18
1 -
/* See LICENSE file for copyright and license details. */
2 -
#include <stdarg.h>
3 -
#include <stdio.h>
4 -
#include <stdlib.h>
5 -
#include "draw.h"
6 -
7 -
const char *progname;
8 -
9 -
void
10 -
eprint(const char *fmt, ...) {
11 -
	va_list ap;
12 -
13 -
	fprintf(stderr, "%s: ", progname);
14 -
	va_start(ap, fmt);
15 -
	vfprintf(stderr, fmt, ap);
16 -
	va_end(ap);
17 -
	exit(EXIT_FAILURE);
18 -
}
draw/getcolor.c (deleted) +0 −13
1 -
/* See LICENSE file for copyright and license details. */
2 -
#include <X11/Xlib.h>
3 -
#include "draw.h"
4 -
5 -
unsigned long
6 -
getcolor(DC *dc, const char *colstr) {
7 -
	Colormap cmap = DefaultColormap(dc->dpy, DefaultScreen(dc->dpy));
8 -
	XColor color;
9 -
10 -
	if(!XAllocNamedColor(dc->dpy, cmap, colstr, &color, &color))
11 -
		eprint("cannot allocate color '%s'\n", colstr);
12 -
	return color.pixel;
13 -
}
draw/initfont.c (deleted) +0 −36
1 -
/* See LICENSE file for copyright and license details. */
2 -
#include <X11/Xlib.h>
3 -
#include "draw.h"
4 -
5 -
#define MAX(a, b)               ((a) > (b) ? (a) : (b))
6 -
7 -
void
8 -
initfont(DC *dc, const char *fontstr) {
9 -
	char *def, **missing = NULL;
10 -
	int i, n;
11 -
12 -
	if(!fontstr || !*fontstr)
13 -
		eprint("cannot load null font\n");
14 -
	dc->font.set = XCreateFontSet(dc->dpy, fontstr, &missing, &n, &def);
15 -
	if(missing)
16 -
		XFreeStringList(missing);
17 -
	if(dc->font.set) {
18 -
		XFontStruct **xfonts;
19 -
		char **font_names;
20 -
		dc->font.ascent = dc->font.descent = 0;
21 -
		n = XFontsOfFontSet(dc->font.set, &xfonts, &font_names);
22 -
		for(i = 0; i < n; i++) {
23 -
			dc->font.ascent = MAX(dc->font.ascent, (*xfonts)->ascent);
24 -
			dc->font.descent = MAX(dc->font.descent, (*xfonts)->descent);
25 -
			xfonts++;
26 -
		}
27 -
	}
28 -
	else {
29 -
		if(!(dc->font.xfont = XLoadQueryFont(dc->dpy, fontstr))
30 -
		&& !(dc->font.xfont = XLoadQueryFont(dc->dpy, "fixed")))
31 -
			eprint("cannot load font '%s'\n", fontstr);
32 -
		dc->font.ascent = dc->font.xfont->ascent;
33 -
		dc->font.descent = dc->font.xfont->descent;
34 -
	}
35 -
	dc->font.height = dc->font.ascent + dc->font.descent;
36 -
}
draw/setupdraw.c (deleted) +0 −16
1 -
/* See LICENSE file for copyright and license details. */
2 -
#include <X11/Xlib.h>
3 -
#include "draw.h"
4 -
5 -
void
6 -
setupdraw(DC *dc, Window w) {
7 -
	XWindowAttributes wa;
8 -
9 -
	XGetWindowAttributes(dc->dpy, w, &wa);
10 -
	dc->drawable = XCreatePixmap(dc->dpy, w, wa.width, wa.height,
11 -
		DefaultDepth(dc->dpy, DefaultScreen(dc->dpy)));
12 -
	dc->gc = XCreateGC(dc->dpy, w, 0, NULL);
13 -
	XSetLineAttributes(dc->dpy, dc->gc, 1, LineSolid, CapButt, JoinMiter);
14 -
	if(!dc->font.set)
15 -
		XSetFont(dc->dpy, dc->gc, dc->font.xfont->fid);
16 -
}
draw/textnw.c (deleted) +0 −14
1 -
/* See LICENSE file for copyright and license details. */
2 -
#include <X11/Xlib.h>
3 -
#include "draw.h"
4 -
5 -
int
6 -
textnw(DC *dc, const char *text, unsigned int len) {
7 -
	XRectangle r;
8 -
9 -
	if(dc->font.set) {
10 -
		XmbTextExtents(dc->font.set, text, len, NULL, &r);
11 -
		return r.width;
12 -
	}
13 -
	return XTextWidth(dc->font.xfont, text, len);
14 -
}
draw/textw.c (deleted) +0 −9
1 -
/* See LICENSE file for copyright and license details. */
2 -
#include <string.h>
3 -
#include <X11/Xlib.h>
4 -
#include "draw.h"
5 -
6 -
int
7 -
textw(DC *dc, const char *text) {
8 -
	return textnw(dc, text, strlen(text)) + dc->font.height;
9 -
}