diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..97ba8b9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +*.o +*.orig +*.rej +dmenu +config.h +dmenu_path +dmenu_run +stest diff --git a/Makefile b/Makefile index 458c524..a03a95c 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,13 @@ include config.mk SRC = drw.c dmenu.c stest.c util.c OBJ = $(SRC:.c=.o) -all: dmenu stest +all: options dmenu stest + +options: + @echo dmenu build options: + @echo "CFLAGS = $(CFLAGS)" + @echo "LDFLAGS = $(LDFLAGS)" + @echo "CC = $(CC)" .c.o: $(CC) -c $(CFLAGS) $< @@ -55,4 +61,4 @@ uninstall: $(DESTDIR)$(MANPREFIX)/man1/dmenu.1\ $(DESTDIR)$(MANPREFIX)/man1/stest.1 -.PHONY: all clean dist install uninstall +.PHONY: all options clean dist install uninstall diff --git a/config.def.h b/config.def.h index 8ddc0b3..e63c997 100644 --- a/config.def.h +++ b/config.def.h @@ -5,7 +5,7 @@ static int topbar = 1; /* -b option; if 0, dmenu appears a static int fuzzy = 1; /* -F option; if 0, dmenu doesn't use fuzzy matching */ /* -fn option overrides fonts[0]; default X11 font or font set */ static const char *fonts[] = { - "Hack Nerd Font:size=14", + "monospace:size=14", "NotoColorEmoji:pixelsize=48:antialias=true:autohint=true" }; static const char *prompt = NULL; /* -p option; prompt to the left of input field */ diff --git a/config.h b/config.h deleted file mode 100644 index 8ddc0b3..0000000 --- a/config.h +++ /dev/null @@ -1,25 +0,0 @@ -/* See LICENSE file for copyright and license details. */ -/* Default settings; can be overriden by command line. */ - -static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */ -static int fuzzy = 1; /* -F option; if 0, dmenu doesn't use fuzzy matching */ -/* -fn option overrides fonts[0]; default X11 font or font set */ -static const char *fonts[] = { - "Hack Nerd Font:size=14", - "NotoColorEmoji:pixelsize=48:antialias=true:autohint=true" -}; -static const char *prompt = NULL; /* -p option; prompt to the left of input field */ -static const char *colors[SchemeLast][2] = { - /* fg bg */ - [SchemeNorm] = { "#ebdbb2", "#282828" }, - [SchemeSel] = { "#ffffff", "#005577" }, - [SchemeOut] = { "#000000", "#00ffff" }, -}; -/* -l option; if nonzero, dmenu uses vertical list with given number of lines */ -static unsigned int lines = 0; - -/* - * Characters not considered part of a word while deleting words - * for example: " /?\"&[]" - */ -static const char worddelimiters[] = " "; diff --git a/config.mk b/config.mk index 6a19175..fd6ff05 100644 --- a/config.mk +++ b/config.mk @@ -1,5 +1,5 @@ # dmenu version -VERSION = 5.3 +VERSION = 5.2 # paths PREFIX = /usr/local diff --git a/dmenu b/dmenu deleted file mode 100755 index 1b775ae..0000000 Binary files a/dmenu and /dev/null differ diff --git a/dmenu.1 b/dmenu.1 index 323f93c..5684e20 100644 --- a/dmenu.1 +++ b/dmenu.1 @@ -22,6 +22,8 @@ dmenu \- dynamic menu .IR color ] .RB [ \-w .IR windowid ] +.RB [ \-it +.IR text ] .P .BR dmenu_run " ..." .SH DESCRIPTION @@ -80,6 +82,9 @@ prints version information to stdout, then exits. .TP .BI \-w " windowid" embed into windowid. +.TP +.BI \-it " text". +start with initial text input. .SH USAGE dmenu is completely controlled by the keyboard. Items are selected using the arrow keys, page up, page down, home, and end. diff --git a/dmenu.c b/dmenu.c index 17c732a..24c1558 100644 --- a/dmenu.c +++ b/dmenu.c @@ -23,6 +23,7 @@ /* macros */ #define INTERSECT(x,y,w,h,r) (MAX(0, MIN((x)+(w),(r).x_org+(r).width) - MAX((x),(r).x_org)) \ * MAX(0, MIN((y)+(h),(r).y_org+(r).height) - MAX((y),(r).y_org))) +#define LENGTH(X) (sizeof X / sizeof X[0]) #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad) /* enums */ @@ -803,7 +804,8 @@ static void usage(void) { die("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" - " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]"); + " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n" + " [-it text]\n"); } int @@ -847,7 +849,10 @@ main(int argc, char *argv[]) colors[SchemeSel][ColFg] = argv[++i]; else if (!strcmp(argv[i], "-w")) /* embedding window id */ embed = argv[++i]; - else + else if (!strcmp(argv[i], "-it")) { /* embedding window id */ + const char * text = argv[++i]; + insert(text, strlen(text)); + } else usage(); if (!setlocale(LC_CTYPE, "") || !XSupportsLocale()) diff --git a/dmenu.o b/dmenu.o deleted file mode 100644 index c53306d..0000000 Binary files a/dmenu.o and /dev/null differ diff --git a/dmenu_path b/dmenu_path deleted file mode 100755 index 3a7cda7..0000000 --- a/dmenu_path +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh - -cachedir="${XDG_CACHE_HOME:-"$HOME/.cache"}" -cache="$cachedir/dmenu_run" - -[ ! -e "$cachedir" ] && mkdir -p "$cachedir" - -IFS=: -if stest -dqr -n "$cache" $PATH; then - stest -flx $PATH | sort -u | tee "$cache" -else - cat "$cache" -fi diff --git a/dmenu_run b/dmenu_run deleted file mode 100755 index 834ede5..0000000 --- a/dmenu_run +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -dmenu_path | dmenu "$@" | ${SHELL:-"/bin/sh"} & diff --git a/drw.c b/drw.c index 78a2b27..a58a2b4 100644 --- a/drw.c +++ b/drw.c @@ -238,8 +238,8 @@ drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int int drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lpad, const char *text, int invert) { - int ty, ellipsis_x = 0; - unsigned int tmpw, ew, ellipsis_w = 0, ellipsis_len, hash, h0, h1; + int i, ty, ellipsis_x = 0; + unsigned int tmpw, ew, ellipsis_w = 0, ellipsis_len; XftDraw *d = NULL; Fnt *usedfont, *curfont, *nextfont; int utf8strlen, utf8charlen, render = x || y || w || h; @@ -251,7 +251,9 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp XftResult result; int charexists = 0, overflow = 0; /* keep track of a couple codepoints for which we have no match. */ - static unsigned int nomatches[128], ellipsis_width; + enum { nomatches_len = 64 }; + static struct { long codepoint[nomatches_len]; unsigned int idx; } nomatches; + static unsigned int ellipsis_width = 0; if (!drw || (render && (!drw->scheme || !w)) || !text || !drw->fonts) return 0; @@ -336,14 +338,11 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp * character must be drawn. */ charexists = 1; - hash = (unsigned int)utf8codepoint; - hash = ((hash >> 16) ^ hash) * 0x21F0AAAD; - hash = ((hash >> 15) ^ hash) * 0xD35A2D97; - h0 = ((hash >> 15) ^ hash) % LENGTH(nomatches); - h1 = (hash >> 17) % LENGTH(nomatches); - /* avoid expensive XftFontMatch call when we know we won't find a match */ - if (nomatches[h0] == utf8codepoint || nomatches[h1] == utf8codepoint) - goto no_match; + for (i = 0; i < nomatches_len; ++i) { + /* avoid calling XftFontMatch if we know we won't find a match */ + if (utf8codepoint == nomatches.codepoint[i]) + goto no_match; + } fccharset = FcCharSetCreate(); FcCharSetAddChar(fccharset, utf8codepoint); @@ -372,7 +371,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, unsigned int lp curfont->next = usedfont; } else { xfont_free(usedfont); - nomatches[nomatches[h0] ? h1 : h0] = utf8codepoint; + nomatches.codepoint[++nomatches.idx % nomatches_len] = utf8codepoint; no_match: usedfont = drw->fonts; } diff --git a/drw.o b/drw.o deleted file mode 100644 index f8e0139..0000000 Binary files a/drw.o and /dev/null differ diff --git a/patches/dmenu-initialtext-4.7.diff b/patches/dmenu-initialtext-4.7.diff new file mode 100644 index 0000000..3d84708 --- /dev/null +++ b/patches/dmenu-initialtext-4.7.diff @@ -0,0 +1,49 @@ +diff --git a/dmenu.1 b/dmenu.1 +index 9eab758..b4947f9 100644 +--- a/dmenu.1 ++++ b/dmenu.1 +@@ -22,6 +22,8 @@ dmenu \- dynamic menu + .IR color ] + .RB [ \-w + .IR windowid ] ++.RB [ \-it ++.IR text ] + .P + .BR dmenu_run " ..." + .SH DESCRIPTION +@@ -80,6 +82,9 @@ prints version information to stdout, then exits. + .TP + .BI \-w " windowid" + embed into windowid. ++.TP ++.BI \-it " text". ++start with initial text input. + .SH USAGE + dmenu is completely controlled by the keyboard. Items are selected using the + arrow keys, page up, page down, home, and end. +diff --git a/dmenu.c b/dmenu.c +index d605ab4..0564dfe 100644 +--- a/dmenu.c ++++ b/dmenu.c +@@ -637,7 +637,8 @@ static void + usage(void) + { + fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" +- " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr); ++ " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n" ++ " [-it text]\n", stderr); + exit(1); + } + +@@ -680,7 +681,10 @@ main(int argc, char *argv[]) + colors[SchemeSel][ColFg] = argv[++i]; + else if (!strcmp(argv[i], "-w")) /* embedding window id */ + embed = argv[++i]; +- else ++ else if (!strcmp(argv[i], "-it")) { /* embedding window id */ ++ const char * text = argv[++i]; ++ insert(text, strlen(text)); ++ } else + usage(); + + if (!setlocale(LC_CTYPE, "") || !XSupportsLocale()) diff --git a/stest b/stest index 2ea6c38..2da67fa 100755 Binary files a/stest and b/stest differ diff --git a/stest.o b/stest.o deleted file mode 100644 index b5e34a1..0000000 Binary files a/stest.o and /dev/null differ diff --git a/util.h b/util.h index c0a50d4..f633b51 100644 --- a/util.h +++ b/util.h @@ -3,7 +3,6 @@ #define MAX(A, B) ((A) > (B) ? (A) : (B)) #define MIN(A, B) ((A) < (B) ? (A) : (B)) #define BETWEEN(X, A, B) ((A) <= (X) && (X) <= (B)) -#define LENGTH(X) (sizeof (X) / sizeof (X)[0]) void die(const char *fmt, ...); void *ecalloc(size_t nmemb, size_t size); diff --git a/util.o b/util.o deleted file mode 100644 index a36344b..0000000 Binary files a/util.o and /dev/null differ