aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile8
-rw-r--r--README2
-rw-r--r--config.mk4
-rw-r--r--dinput.c2
-rw-r--r--dmenu.c2
-rw-r--r--draw/Makefile26
-rw-r--r--draw/cleanupdraw.c13
-rw-r--r--draw/draw.h34
-rw-r--r--draw/drawsquare.c19
-rw-r--r--draw/drawtext.c34
-rw-r--r--draw/eprint.c18
-rw-r--r--draw/getcolor.c13
-rw-r--r--draw/initfont.c36
-rw-r--r--draw/setupdraw.c16
-rw-r--r--draw/textnw.c14
-rw-r--r--draw/textw.c9
16 files changed, 8 insertions, 242 deletions
diff --git a/Makefile b/Makefile
index 90f178b..0f29652 100644
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,7 @@ options:
18 @echo CC $< 18 @echo CC $<
19 @${CC} -c ${CFLAGS} $< 19 @${CC} -c ${CFLAGS} $<
20 20
21${OBJ}: config.h config.mk draw/libdraw.a 21${OBJ}: config.h config.mk
22 22
23config.h: 23config.h:
24 @echo creating $@ from config.def.h 24 @echo creating $@ from config.def.h
@@ -28,18 +28,14 @@ config.h:
28 @echo CC -o $@ 28 @echo CC -o $@
29 @${CC} -o $@ $< ${LDFLAGS} 29 @${CC} -o $@ $< ${LDFLAGS}
30 30
31draw/libdraw.a:
32 @cd draw && make
33
34clean: 31clean:
35 @echo cleaning 32 @echo cleaning
36 @rm -f dinput dmenu ${OBJ} dmenu-${VERSION}.tar.gz 33 @rm -f dinput dmenu ${OBJ} dmenu-${VERSION}.tar.gz
37 @cd draw && make clean
38 34
39dist: clean 35dist: clean
40 @echo creating dist tarball 36 @echo creating dist tarball
41 @mkdir -p dmenu-${VERSION} 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 @tar -cf dmenu-${VERSION}.tar dmenu-${VERSION} 39 @tar -cf dmenu-${VERSION}.tar dmenu-${VERSION}
44 @gzip dmenu-${VERSION}.tar 40 @gzip dmenu-${VERSION}.tar
45 @rm -rf dmenu-${VERSION} 41 @rm -rf dmenu-${VERSION}
diff --git a/README b/README
index b11fc08..3706ef1 100644
--- a/README
+++ b/README
@@ -6,6 +6,8 @@ dmenu is a generic and efficient menu for X.
6Requirements 6Requirements
7------------ 7------------
8In order to build dmenu you need the Xlib header files. 8In order to build dmenu you need the Xlib header files.
9You also need libdraw, available from http://hg.suckless.org/libdraw
10
9Pasting the X selection to dmenu requires the sselp utility at runtime. 11Pasting the X selection to dmenu requires the sselp utility at runtime.
10 12
11 13
diff --git a/config.mk b/config.mk
index 431754e..c8bbdcd 100644
--- a/config.mk
+++ b/config.mk
@@ -15,8 +15,8 @@ XINERAMALIBS = -L${X11LIB} -lXinerama
15XINERAMAFLAGS = -DXINERAMA 15XINERAMAFLAGS = -DXINERAMA
16 16
17# includes and libs 17# includes and libs
18INCS = -I. -Idraw -I/usr/include -I${X11INC} 18INCS = -I. -I/usr/include -I${X11INC}
19LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -Ldraw -ldraw ${XINERAMALIBS} 19LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -ldraw ${XINERAMALIBS}
20 20
21# flags 21# flags
22CPPFLAGS = -D_BSD_SOURCE -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} 22CPPFLAGS = -D_BSD_SOURCE -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
diff --git a/dinput.c b/dinput.c
index 6b78598..64ce036 100644
--- a/dinput.c
+++ b/dinput.c
@@ -12,6 +12,7 @@
12#ifdef XINERAMA 12#ifdef XINERAMA
13#include <X11/extensions/Xinerama.h> 13#include <X11/extensions/Xinerama.h>
14#endif 14#endif
15#include <draw.h>
15 16
16/* macros */ 17/* macros */
17#define CLEANMASK(mask) (mask & ~(numlockmask | LockMask)) 18#define CLEANMASK(mask) (mask & ~(numlockmask | LockMask))
@@ -30,7 +31,6 @@ static void run(void);
30static void setup(Bool topbar); 31static void setup(Bool topbar);
31 32
32#include "config.h" 33#include "config.h"
33#include "draw.h"
34 34
35/* variables */ 35/* variables */
36static char *prompt = NULL; 36static char *prompt = NULL;
diff --git a/dmenu.c b/dmenu.c
index 764e0f0..c353c60 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -13,6 +13,7 @@
13#ifdef XINERAMA 13#ifdef XINERAMA
14#include <X11/extensions/Xinerama.h> 14#include <X11/extensions/Xinerama.h>
15#endif 15#endif
16#include <draw.h>
16 17
17/* macros */ 18/* macros */
18#define CLEANMASK(mask) (mask & ~(numlockmask | LockMask)) 19#define CLEANMASK(mask) (mask & ~(numlockmask | LockMask))
@@ -46,7 +47,6 @@ static void run(void);
46static void setup(void); 47static void setup(void);
47 48
48#include "config.h" 49#include "config.h"
49#include "draw.h"
50 50
51/* variables */ 51/* variables */
52static char **argp = NULL; 52static char **argp = NULL;
diff --git a/draw/Makefile b/draw/Makefile
deleted file mode 100644
index 4b39490..0000000
--- a/draw/Makefile
+++ /dev/null
@@ -1,26 +0,0 @@
1# libdraw - dynamic drawing library
2# See LICENSE file for copyright and license details.
3
4include ../config.mk
5
6SRC = cleanupdraw.c drawsquare.c drawtext.c eprint.c getcolor.c initfont.c \
7setupdraw.c textnw.c textw.c
8OBJ = ${SRC:.c=.o}
9
10all: libdraw.a
11
12.c.o:
13 @echo CC $<
14 @${CC} -c ${CFLAGS} $<
15
16${OBJ}: ../config.mk draw.h
17
18libdraw.a: ${OBJ}
19 @echo AR $@
20 @ar cr $@ $+
21
22clean:
23 @echo cleaning libdraw
24 @rm -f libdraw.a ${OBJ}
25
26.PHONY: all options clean
diff --git a/draw/cleanupdraw.c b/draw/cleanupdraw.c
deleted file mode 100644
index 28bce13..0000000
--- a/draw/cleanupdraw.c
+++ /dev/null
@@ -1,13 +0,0 @@
1/* See LICENSE file for copyright and license details. */
2#include <X11/Xlib.h>
3#include "draw.h"
4
5void
6cleanupdraw(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}
diff --git a/draw/draw.h b/draw/draw.h
deleted file mode 100644
index f282392..0000000
--- a/draw/draw.h
+++ /dev/null
@@ -1,34 +0,0 @@
1/* See LICENSE file for copyright and license details. */
2#include <X11/Xlib.h>
3
4/* enums */
5enum { ColBorder, ColFG, ColBG, ColLast };
6
7/* typedefs */
8typedef 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 */
23void cleanupdraw(DC *dc);
24void drawsquare(DC *dc, Bool filled, unsigned long col[ColLast], Bool invert);
25void drawtext(DC *dc, const char *text, unsigned long col[ColLast], Bool invert);
26void eprint(const char *fmt, ...);
27unsigned long getcolor(DC *dc, const char *colstr);
28void initfont(DC *dc, const char *fontstr);
29void setupdraw(DC *dc, Window w);
30int textnw(DC *dc, const char *text, unsigned int len);
31int textw(DC *dc, const char *text);
32
33/* variables */
34extern const char *progname;
diff --git a/draw/drawsquare.c b/draw/drawsquare.c
deleted file mode 100644
index 8899043..0000000
--- a/draw/drawsquare.c
+++ /dev/null
@@ -1,19 +0,0 @@
1/* See LICENSE file for copyright and license details. */
2#include <X11/Xlib.h>
3#include "draw.h"
4
5void
6drawsquare(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}
diff --git a/draw/drawtext.c b/draw/drawtext.c
deleted file mode 100644
index d347b36..0000000
--- a/draw/drawtext.c
+++ /dev/null
@@ -1,34 +0,0 @@
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
8void
9drawtext(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}
diff --git a/draw/eprint.c b/draw/eprint.c
deleted file mode 100644
index 3094b61..0000000
--- a/draw/eprint.c
+++ /dev/null
@@ -1,18 +0,0 @@
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
7const char *progname;
8
9void
10eprint(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}
diff --git a/draw/getcolor.c b/draw/getcolor.c
deleted file mode 100644
index c0e5d21..0000000
--- a/draw/getcolor.c
+++ /dev/null
@@ -1,13 +0,0 @@
1/* See LICENSE file for copyright and license details. */
2#include <X11/Xlib.h>
3#include "draw.h"
4
5unsigned long
6getcolor(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}
diff --git a/draw/initfont.c b/draw/initfont.c
deleted file mode 100644
index 77d3182..0000000
--- a/draw/initfont.c
+++ /dev/null
@@ -1,36 +0,0 @@
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
7void
8initfont(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}
diff --git a/draw/setupdraw.c b/draw/setupdraw.c
deleted file mode 100644
index 7dd5012..0000000
--- a/draw/setupdraw.c
+++ /dev/null
@@ -1,16 +0,0 @@
1/* See LICENSE file for copyright and license details. */
2#include <X11/Xlib.h>
3#include "draw.h"
4
5void
6setupdraw(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}
diff --git a/draw/textnw.c b/draw/textnw.c
deleted file mode 100644
index 9c0c122..0000000
--- a/draw/textnw.c
+++ /dev/null
@@ -1,14 +0,0 @@
1/* See LICENSE file for copyright and license details. */
2#include <X11/Xlib.h>
3#include "draw.h"
4
5int
6textnw(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}
diff --git a/draw/textw.c b/draw/textw.c
deleted file mode 100644
index a8407f6..0000000
--- a/draw/textw.c
+++ /dev/null
@@ -1,9 +0,0 @@
1/* See LICENSE file for copyright and license details. */
2#include <string.h>
3#include <X11/Xlib.h>
4#include "draw.h"
5
6int
7textw(DC *dc, const char *text) {
8 return textnw(dc, text, strlen(text)) + dc->font.height;
9}