Update dmenu to 5.2.
This commit is contained in:
parent
11bfdb58a1
commit
5e26689677
8 changed files with 1085 additions and 1086 deletions
|
@ -30,7 +30,7 @@ extern char *argv0;
|
|||
switch (argc_)
|
||||
|
||||
#define ARGEND }\
|
||||
}
|
||||
}
|
||||
|
||||
#define ARGC() argc_
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# dmenu version
|
||||
VERSION = 5.1
|
||||
VERSION = 5.2
|
||||
|
||||
# paths
|
||||
PREFIX = /usr/local
|
||||
|
|
|
@ -58,14 +58,14 @@ static Clr *scheme[SchemeLast];
|
|||
static int (*fstrncmp)(const char *, const char *, size_t) = strncmp;
|
||||
static char *(*fstrstr)(const char *, const char *) = strstr;
|
||||
|
||||
static unsigned int
|
||||
static unsigned int
|
||||
textw_clamp(const char *str, unsigned int n)
|
||||
{
|
||||
unsigned int w = drw_fontset_getwidth_clamp(drw, str, n) + lrpad;
|
||||
return MIN(w, n);
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
appenditem(struct item *item, struct item **list, struct item **last)
|
||||
{
|
||||
if (*last)
|
||||
|
@ -78,7 +78,7 @@ appenditem(struct item *item, struct item **list, struct item **last)
|
|||
*last = item;
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
calcoffsets(void)
|
||||
{
|
||||
int i, n;
|
||||
|
@ -96,7 +96,7 @@ calcoffsets(void)
|
|||
break;
|
||||
}
|
||||
|
||||
static int
|
||||
static int
|
||||
max_textw(void)
|
||||
{
|
||||
int len = 0;
|
||||
|
@ -105,7 +105,7 @@ max_textw(void)
|
|||
return len;
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
cleanup(void)
|
||||
{
|
||||
size_t i;
|
||||
|
@ -121,7 +121,7 @@ cleanup(void)
|
|||
XCloseDisplay(dpy);
|
||||
}
|
||||
|
||||
static char *
|
||||
static char *
|
||||
cistrstr(const char *h, const char *n)
|
||||
{
|
||||
size_t i;
|
||||
|
@ -139,7 +139,7 @@ cistrstr(const char *h, const char *n)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static int
|
||||
static int
|
||||
drawitem(struct item *item, int x, int y, int w)
|
||||
{
|
||||
if (item == sel)
|
||||
|
@ -152,7 +152,7 @@ drawitem(struct item *item, int x, int y, int w)
|
|||
return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
drawmenu(void)
|
||||
{
|
||||
unsigned int curpos;
|
||||
|
@ -201,7 +201,7 @@ drawmenu(void)
|
|||
drw_map(drw, win, 0, 0, mw, mh);
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
grabfocus(void)
|
||||
{
|
||||
struct timespec ts = { .tv_sec = 0, .tv_nsec = 10000000 };
|
||||
|
@ -218,7 +218,7 @@ grabfocus(void)
|
|||
die("cannot grab focus");
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
grabkeyboard(void)
|
||||
{
|
||||
struct timespec ts = { .tv_sec = 0, .tv_nsec = 1000000 };
|
||||
|
@ -236,7 +236,7 @@ grabkeyboard(void)
|
|||
die("cannot grab keyboard");
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
match(void)
|
||||
{
|
||||
static char **tokv = NULL;
|
||||
|
@ -290,7 +290,7 @@ match(void)
|
|||
calcoffsets();
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
insert(const char *str, ssize_t n)
|
||||
{
|
||||
if (strlen(text) + n > sizeof text - 1)
|
||||
|
@ -303,7 +303,7 @@ insert(const char *str, ssize_t n)
|
|||
match();
|
||||
}
|
||||
|
||||
static size_t
|
||||
static size_t
|
||||
nextrune(int inc)
|
||||
{
|
||||
ssize_t n;
|
||||
|
@ -314,7 +314,7 @@ nextrune(int inc)
|
|||
return n;
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
movewordedge(int dir)
|
||||
{
|
||||
if (dir < 0) { /* move cursor to the start of the word*/
|
||||
|
@ -330,7 +330,7 @@ movewordedge(int dir)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
keypress(XKeyEvent *ev)
|
||||
{
|
||||
char buf[32];
|
||||
|
@ -526,9 +526,9 @@ insert:
|
|||
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;
|
||||
}
|
||||
|
@ -537,7 +537,7 @@ draw:
|
|||
drawmenu();
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
paste(void)
|
||||
{
|
||||
char *p, *q;
|
||||
|
@ -555,21 +555,21 @@ paste(void)
|
|||
drawmenu();
|
||||
}
|
||||
|
||||
static 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;
|
||||
|
||||
/* 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)
|
||||
|
@ -577,7 +577,7 @@ readstdin(void)
|
|||
lines = MIN(lines, i);
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
run(void)
|
||||
{
|
||||
XEvent ev;
|
||||
|
@ -615,7 +615,7 @@ run(void)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
setup(void)
|
||||
{
|
||||
int x, y, i, j;
|
||||
|
@ -735,15 +735,14 @@ setup(void)
|
|||
drawmenu();
|
||||
}
|
||||
|
||||
static void
|
||||
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);
|
||||
exit(1);
|
||||
die("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
|
||||
" [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]");
|
||||
}
|
||||
|
||||
int
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
XWindowAttributes wa;
|
||||
|
|
|
@ -16,7 +16,7 @@ static const unsigned char utfmask[UTF_SIZ + 1] = {0xC0, 0x80, 0xE0, 0xF0, 0xF8}
|
|||
static const long utfmin[UTF_SIZ + 1] = { 0, 0, 0x80, 0x800, 0x10000};
|
||||
static const long utfmax[UTF_SIZ + 1] = {0x10FFFF, 0x7F, 0x7FF, 0xFFFF, 0x10FFFF};
|
||||
|
||||
static long
|
||||
static long
|
||||
utf8decodebyte(const char c, size_t *i)
|
||||
{
|
||||
for (*i = 0; *i < (UTF_SIZ + 1); ++(*i))
|
||||
|
@ -25,7 +25,7 @@ utf8decodebyte(const char c, size_t *i)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static size_t
|
||||
static size_t
|
||||
utf8validate(long *u, size_t i)
|
||||
{
|
||||
if (!BETWEEN(*u, utfmin[i], utfmax[i]) || BETWEEN(*u, 0xD800, 0xDFFF))
|
||||
|
@ -35,7 +35,7 @@ utf8validate(long *u, size_t i)
|
|||
return i;
|
||||
}
|
||||
|
||||
static size_t
|
||||
static size_t
|
||||
utf8decode(const char *c, long *u, size_t clen)
|
||||
{
|
||||
size_t i, j, len, type;
|
||||
|
@ -60,7 +60,7 @@ utf8decode(const char *c, long *u, size_t clen)
|
|||
return len;
|
||||
}
|
||||
|
||||
Drw *
|
||||
Drw *
|
||||
drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h)
|
||||
{
|
||||
Drw *drw = ecalloc(1, sizeof(Drw));
|
||||
|
@ -77,7 +77,7 @@ drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h
|
|||
return drw;
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
drw_resize(Drw *drw, unsigned int w, unsigned int h)
|
||||
{
|
||||
if (!drw)
|
||||
|
@ -90,7 +90,7 @@ drw_resize(Drw *drw, unsigned int w, unsigned int h)
|
|||
drw->drawable = XCreatePixmap(drw->dpy, drw->root, w, h, DefaultDepth(drw->dpy, drw->screen));
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
drw_free(Drw *drw)
|
||||
{
|
||||
XFreePixmap(drw->dpy, drw->drawable);
|
||||
|
@ -102,7 +102,7 @@ drw_free(Drw *drw)
|
|||
/* This function is an implementation detail. Library users should use
|
||||
* drw_fontset_create instead.
|
||||
*/
|
||||
static Fnt *
|
||||
static Fnt *
|
||||
xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern)
|
||||
{
|
||||
Fnt *font;
|
||||
|
@ -142,7 +142,7 @@ xfont_create(Drw *drw, const char *fontname, FcPattern *fontpattern)
|
|||
return font;
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
xfont_free(Fnt *font)
|
||||
{
|
||||
if (!font)
|
||||
|
@ -153,7 +153,7 @@ xfont_free(Fnt *font)
|
|||
free(font);
|
||||
}
|
||||
|
||||
Fnt*
|
||||
Fnt*
|
||||
drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount)
|
||||
{
|
||||
Fnt *cur, *ret = NULL;
|
||||
|
@ -171,7 +171,7 @@ drw_fontset_create(Drw* drw, const char *fonts[], size_t fontcount)
|
|||
return (drw->fonts = ret);
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
drw_fontset_free(Fnt *font)
|
||||
{
|
||||
if (font) {
|
||||
|
@ -180,7 +180,7 @@ drw_fontset_free(Fnt *font)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
drw_clr_create(Drw *drw, Clr *dest, const char *clrname)
|
||||
{
|
||||
if (!drw || !dest || !clrname)
|
||||
|
@ -194,7 +194,7 @@ drw_clr_create(Drw *drw, Clr *dest, const char *clrname)
|
|||
|
||||
/* Wrapper to create color schemes. The caller has to call free(3) on the
|
||||
* returned color scheme when done using it. */
|
||||
Clr *
|
||||
Clr *
|
||||
drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount)
|
||||
{
|
||||
size_t i;
|
||||
|
@ -209,21 +209,21 @@ drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount)
|
|||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
drw_setfontset(Drw *drw, Fnt *set)
|
||||
{
|
||||
if (drw)
|
||||
drw->fonts = set;
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
drw_setscheme(Drw *drw, Clr *scm)
|
||||
{
|
||||
if (drw)
|
||||
drw->scheme = scm;
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int invert)
|
||||
{
|
||||
if (!drw || !drw->scheme)
|
||||
|
@ -235,7 +235,7 @@ drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int
|
|||
XDrawRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w - 1, h - 1);
|
||||
}
|
||||
|
||||
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 i, ty, ellipsis_x = 0;
|
||||
|
@ -355,7 +355,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);
|
||||
|
@ -385,7 +384,7 @@ no_match:
|
|||
return x + (render ? w : 0);
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h)
|
||||
{
|
||||
if (!drw)
|
||||
|
@ -395,7 +394,7 @@ drw_map(Drw *drw, Window win, int x, int y, unsigned int w, unsigned int h)
|
|||
XSync(drw->dpy, False);
|
||||
}
|
||||
|
||||
unsigned int
|
||||
unsigned int
|
||||
drw_fontset_getwidth(Drw *drw, const char *text)
|
||||
{
|
||||
if (!drw || !drw->fonts || !text)
|
||||
|
@ -403,7 +402,7 @@ drw_fontset_getwidth(Drw *drw, const char *text)
|
|||
return drw_text(drw, 0, 0, 0, 0, 0, text, 0);
|
||||
}
|
||||
|
||||
unsigned int
|
||||
unsigned int
|
||||
drw_fontset_getwidth_clamp(Drw *drw, const char *text, unsigned int n)
|
||||
{
|
||||
unsigned int tmp = 0;
|
||||
|
@ -412,7 +411,7 @@ drw_fontset_getwidth_clamp(Drw *drw, const char *text, unsigned int n)
|
|||
return MIN(n, tmp);
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w, unsigned int *h)
|
||||
{
|
||||
XGlyphInfo ext;
|
||||
|
@ -427,7 +426,7 @@ drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned int *w,
|
|||
*h = font->h;
|
||||
}
|
||||
|
||||
Cur *
|
||||
Cur *
|
||||
drw_cur_create(Drw *drw, int shape)
|
||||
{
|
||||
Cur *cur;
|
||||
|
@ -440,7 +439,7 @@ drw_cur_create(Drw *drw, int shape)
|
|||
return cur;
|
||||
}
|
||||
|
||||
void
|
||||
void
|
||||
drw_cur_free(Drw *drw, Cur *cursor)
|
||||
{
|
||||
if (!cursor)
|
||||
|
|
|
@ -20,7 +20,7 @@ static int match = 0;
|
|||
static int flag[26];
|
||||
static struct stat old, new;
|
||||
|
||||
static void
|
||||
static void
|
||||
test(const char *path, const char *name)
|
||||
{
|
||||
struct stat st, ln;
|
||||
|
@ -48,7 +48,7 @@ test(const char *path, const char *name)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
fprintf(stderr, "usage: %s [-abcdefghlpqrsuvwx] "
|
||||
|
@ -56,7 +56,7 @@ usage(void)
|
|||
exit(2); /* like test(1) return > 1 on error */
|
||||
}
|
||||
|
||||
int
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
struct dirent *d;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue