diff options
| -rw-r--r-- | Makefile | 8 | ||||
| -rw-r--r-- | README | 2 | ||||
| -rw-r--r-- | config.mk | 4 | ||||
| -rw-r--r-- | dinput.c | 2 | ||||
| -rw-r--r-- | dmenu.c | 2 | ||||
| -rw-r--r-- | draw/Makefile | 26 | ||||
| -rw-r--r-- | draw/cleanupdraw.c | 13 | ||||
| -rw-r--r-- | draw/draw.h | 34 | ||||
| -rw-r--r-- | draw/drawsquare.c | 19 | ||||
| -rw-r--r-- | draw/drawtext.c | 34 | ||||
| -rw-r--r-- | draw/eprint.c | 18 | ||||
| -rw-r--r-- | draw/getcolor.c | 13 | ||||
| -rw-r--r-- | draw/initfont.c | 36 | ||||
| -rw-r--r-- | draw/setupdraw.c | 16 | ||||
| -rw-r--r-- | draw/textnw.c | 14 | ||||
| -rw-r--r-- | draw/textw.c | 9 |
16 files changed, 8 insertions, 242 deletions
| @@ -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 | ||
| 23 | config.h: | 23 | config.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 | ||
| 31 | draw/libdraw.a: | ||
| 32 | @cd draw && make | ||
| 33 | |||
| 34 | clean: | 31 | clean: |
| 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 | ||
| 39 | dist: clean | 35 | dist: 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} |
| @@ -6,6 +6,8 @@ dmenu is a generic and efficient menu for X. | |||
| 6 | Requirements | 6 | Requirements |
| 7 | ------------ | 7 | ------------ |
| 8 | In order to build dmenu you need the Xlib header files. | 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 | Pasting the X selection to dmenu requires the sselp utility at runtime. | 11 | Pasting the X selection to dmenu requires the sselp utility at runtime. |
| 10 | 12 | ||
| 11 | 13 | ||
| @@ -15,8 +15,8 @@ XINERAMALIBS = -L${X11LIB} -lXinerama | |||
| 15 | XINERAMAFLAGS = -DXINERAMA | 15 | XINERAMAFLAGS = -DXINERAMA |
| 16 | 16 | ||
| 17 | # includes and libs | 17 | # includes and libs |
| 18 | INCS = -I. -Idraw -I/usr/include -I${X11INC} | 18 | INCS = -I. -I/usr/include -I${X11INC} |
| 19 | LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -Ldraw -ldraw ${XINERAMALIBS} | 19 | LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -ldraw ${XINERAMALIBS} |
| 20 | 20 | ||
| 21 | # flags | 21 | # flags |
| 22 | CPPFLAGS = -D_BSD_SOURCE -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} | 22 | CPPFLAGS = -D_BSD_SOURCE -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} |
| @@ -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); | |||
| 30 | static void setup(Bool topbar); | 31 | static void setup(Bool topbar); |
| 31 | 32 | ||
| 32 | #include "config.h" | 33 | #include "config.h" |
| 33 | #include "draw.h" | ||
| 34 | 34 | ||
| 35 | /* variables */ | 35 | /* variables */ |
| 36 | static char *prompt = NULL; | 36 | static char *prompt = NULL; |
| @@ -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); | |||
| 46 | static void setup(void); | 47 | static void setup(void); |
| 47 | 48 | ||
| 48 | #include "config.h" | 49 | #include "config.h" |
| 49 | #include "draw.h" | ||
| 50 | 50 | ||
| 51 | /* variables */ | 51 | /* variables */ |
| 52 | static char **argp = NULL; | 52 | static 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 | |||
| 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 | ||
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 | |||
| 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 | } | ||
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 */ | ||
| 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; | ||
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 | |||
| 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 | } | ||
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 | |||
| 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 | } | ||
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 | |||
| 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 | } | ||
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 | |||
| 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 | } | ||
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 | |||
| 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 | } | ||
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 | |||
| 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 | } | ||
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 | |||
| 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 | } | ||
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 | |||
| 6 | int | ||
| 7 | textw(DC *dc, const char *text) { | ||
| 8 | return textnw(dc, text, strlen(text)) + dc->font.height; | ||
| 9 | } | ||
