dmenu

Mahdi's build of dmenu
git clone git://mahdi.pw/dmenu.git
Log | Files | Refs | README | LICENSE

commit 9aee149e34532922d09c7a0f8fdfd16b8d6ee358
parent c61036548411483a6284f095a028930f76bbd834
Author: Mahdi Mirzade <me@mahdi.pw>
Date:   Wed, 12 Oct 2022 21:17:24 +0330

Update to 5.2

Diffstat:
MMakefile | 6++++--
Mconfig.h | 12++++++------
Mconfig.mk | 7++++---
Mdmenu.c | 34++++++++++++++--------------------
Rdmenu_run.hist -> dmenu_run_history | 0
Mdrw.c | 14--------------
Mutil.c | 23++++++++++++-----------
7 files changed, 40 insertions(+), 56 deletions(-)

diff --git a/Makefile b/Makefile @@ -34,7 +34,7 @@ clean: dist: clean mkdir -p dmenu-$(VERSION) cp LICENSE Makefile README arg.h config.def.h config.mk dmenu.1\ - drw.h util.h dmenu_path dmenu_run stest.1 $(SRC)\ + drw.h util.h dmenu_path dmenu_run dmenu_run_history stest.1 $(SRC)\ dmenu-$(VERSION) tar -cf dmenu-$(VERSION).tar dmenu-$(VERSION) gzip dmenu-$(VERSION).tar @@ -42,10 +42,11 @@ dist: clean install: all mkdir -p $(DESTDIR)$(PREFIX)/bin - cp -f dmenu dmenu_path dmenu_run stest $(DESTDIR)$(PREFIX)/bin + cp -f dmenu dmenu_path dmenu_run dmenu_run_history stest $(DESTDIR)$(PREFIX)/bin chmod 755 $(DESTDIR)$(PREFIX)/bin/dmenu chmod 755 $(DESTDIR)$(PREFIX)/bin/dmenu_path chmod 755 $(DESTDIR)$(PREFIX)/bin/dmenu_run + chmod 755 $(DESTDIR)$(PREFIX)/bin/dmenu_run_history chmod 755 $(DESTDIR)$(PREFIX)/bin/stest mkdir -p $(DESTDIR)$(MANPREFIX)/man1 sed "s/VERSION/$(VERSION)/g" < dmenu.1 > $(DESTDIR)$(MANPREFIX)/man1/dmenu.1 @@ -57,6 +58,7 @@ uninstall: rm -f $(DESTDIR)$(PREFIX)/bin/dmenu\ $(DESTDIR)$(PREFIX)/bin/dmenu_path\ $(DESTDIR)$(PREFIX)/bin/dmenu_run\ + $(DESTDIR)$(PREFIX)/bin/dmenu_run_history\ $(DESTDIR)$(PREFIX)/bin/stest\ $(DESTDIR)$(MANPREFIX)/man1/dmenu.1\ $(DESTDIR)$(MANPREFIX)/man1/stest.1 diff --git a/config.h b/config.h @@ -49,12 +49,12 @@ static const unsigned int alphas[SchemeLast][2] = { */ ResourcePref resources[] = { { "font", STRING, &font }, - { "color12", STRING, &normfgcolor }, - { "color0", STRING, &normbgcolor }, - { "color11", STRING, &normhlcolor }, - { "color0", STRING, &selfgcolor }, - { "color12", STRING, &selbgcolor }, - { "color8", STRING, &selhlcolor }, + { "foreground", STRING, &normfgcolor }, + { "background", STRING, &normbgcolor }, + { "color1", STRING, &normhlcolor }, + { "foreground", STRING, &selfgcolor }, + { "color8", STRING, &selbgcolor }, + { "color1", STRING, &selhlcolor }, { "prompt", STRING, &prompt }, }; diff --git a/config.mk b/config.mk @@ -1,12 +1,12 @@ # dmenu version -VERSION = 5.1 +VERSION = 5.2 # paths PREFIX = /usr/local MANPREFIX = $(PREFIX)/share/man -X11INC = /usr/X11R6/include -X11LIB = /usr/X11R6/lib +X11INC = /usr/include +X11LIB = /usr/lib BDINC = /usr/include/fribidi @@ -19,6 +19,7 @@ FREETYPELIBS = -lfontconfig -lXft FREETYPEINC = /usr/include/freetype2 # OpenBSD (uncomment) #FREETYPEINC = $(X11INC)/freetype2 +#MANPREFIX = ${PREFIX}/man BDLIBS = -lfribidi diff --git a/dmenu.c b/dmenu.c @@ -614,9 +614,9 @@ keypress(XKeyEvent *ev) case XK_Tab: if (!sel) return; - strncpy(text, sel->text, sizeof text - 1); - text[sizeof text - 1] = '\0'; - cursor = strlen(text); + cursor = strnlen(sel->text, sizeof text - 1); + memcpy(text, sel->text, cursor); + text[cursor] = '\0'; match(); break; } @@ -646,22 +646,22 @@ paste(void) static void readstdin(void) { - char buf[sizeof text], *p; - size_t i, size = 0; + char *line = NULL; + size_t i, junk, size = 0; + ssize_t len; if (passwd) { inputw = lines = 0; return; } /* read each line from stdin and add it to the item list */ - for (i = 0; fgets(buf, sizeof buf, stdin); i++) { + for (i = 0; (len = getline(&line, &junk, stdin)) != -1; i++, line = NULL) { if (i + 1 >= size / sizeof *items) if (!(items = realloc(items, (size += BUFSIZ)))) die("cannot realloc %zu bytes:", size); - if ((p = strchr(buf, '\n'))) - *p = '\0'; - if (!(items[i].text = strdup(buf))) - die("cannot strdup %zu bytes:", strlen(buf) + 1); + if (line[len - 1] == '\n') + line[len - 1] = '\0'; + items[i].text = line; items[i].out = 0; } if (items) @@ -770,7 +770,7 @@ static void setup(void) { int x, y, i, j; - unsigned int du, tmp; + unsigned int du; XSetWindowAttributes swa; XIM xim; Window w, dw, *dws; @@ -835,12 +835,7 @@ setup(void) mw = wa.width; } promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0; - for (item = items; item && item->text; ++item) { - if ((tmp = textw_clamp(item->text, mw/3)) > inputw) { - if ((inputw = tmp) == mw/3) - break; - } - } + inputw = mw / 3; /* input width: ~33% of monitor width */ match(); /* create menu window */ @@ -881,9 +876,8 @@ setup(void) static void usage(void) { - fputs("usage: dmenu [-bfivP] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" - " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid] [-n number] [-bw number]\n", stderr); - exit(1); + die("usage: dmenu [-bfivP] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" + " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid] [-n number] [-bw number]"); } int diff --git a/dmenu_run.hist b/dmenu_run_history diff --git a/drw.c b/drw.c @@ -136,19 +136,6 @@ xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern) die("no font specified."); } - /* Do not allow using color fonts. This is a workaround for a BadLength - * error from Xft with color glyphs. Modelled on the Xterm workaround. See - * https://bugzilla.redhat.com/show_bug.cgi?id=1498269 - * https://lists.suckless.org/dev/1701/30932.html - * https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=916349 - * and lots more all over the internet. - */ - //FcBool iscol; - //if(FcPatternGetBool(xfont->pattern, FC_COLOR, 0, &iscol) == FcResultMatch && iscol) { - // XftFontClose(drw->dpy, xfont); - // return NULL; - //} - font = ecalloc(1, sizeof(Fnt)); font->xfont = xfont; font->pattern = pattern; @@ -370,7 +357,6 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp fcpattern = FcPatternDuplicate(drw->fonts->pattern); FcPatternAddCharSet(fcpattern, FC_CHARSET, fccharset); FcPatternAddBool(fcpattern, FC_SCALABLE, FcTrue); - //FcPatternAddBool(fcpattern, FC_COLOR, FcFalse); FcConfigSubstitute(NULL, fcpattern, FcMatchPattern); FcDefaultSubstitute(fcpattern); diff --git a/util.c b/util.c @@ -6,18 +6,9 @@ #include "util.h" -void * -ecalloc(size_t nmemb, size_t size) -{ - void *p; - - if (!(p = calloc(nmemb, size))) - die("calloc:"); - return p; -} - void -die(const char *fmt, ...) { +die(const char *fmt, ...) +{ va_list ap; va_start(ap, fmt); @@ -33,3 +24,13 @@ die(const char *fmt, ...) { exit(1); } + +void * +ecalloc(size_t nmemb, size_t size) +{ + void *p; + + if (!(p = calloc(nmemb, size))) + die("calloc:"); + return p; +}