[dmenu] patch: instant

This commit is contained in:
dogeystamp 2024-01-02 13:17:31 -05:00
parent 9bc4a077ec
commit 369bcafd08
3 changed files with 16 additions and 3 deletions

View File

@ -1,6 +1,7 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
/* Default settings; can be overriden by command line. */ /* Default settings; can be overriden by command line. */
static int instant = 0;
static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */ static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */
static const unsigned int alpha = 0xff; /* Amount of opacity. 0xff is opaque */ static const unsigned int alpha = 0xff; /* Amount of opacity. 0xff is opaque */
/* -fn option overrides fonts[0]; default X11 font or font set */ /* -fn option overrides fonts[0]; default X11 font or font set */

View File

@ -3,7 +3,7 @@
dmenu \- dynamic menu dmenu \- dynamic menu
.SH SYNOPSIS .SH SYNOPSIS
.B dmenu .B dmenu
.RB [ \-bfiv ] .RB [ \-bfinv ]
.RB [ \-l .RB [ \-l
.IR lines ] .IR lines ]
.RB [ \-m .RB [ \-m
@ -47,6 +47,9 @@ is faster, but will lock up X until stdin reaches end\-of\-file.
.B \-i .B \-i
dmenu matches menu items case insensitively. dmenu matches menu items case insensitively.
.TP .TP
.B \-n
dmenu instantly selects if only one match.
.TP
.BI \-l " lines" .BI \-l " lines"
dmenu lists items vertically, with the given number of lines. dmenu lists items vertically, with the given number of lines.
.TP .TP

View File

@ -287,6 +287,13 @@ match(void)
matchend = substrend; matchend = substrend;
} }
curr = sel = matches; curr = sel = matches;
if(instant && matches && matches==matchend && !lsubstr) {
puts(matches->text);
cleanup();
exit(0);
}
calcoffsets(); calcoffsets();
} }
@ -727,7 +734,7 @@ setup(void)
static void static void
usage(void) usage(void)
{ {
die("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" die("usage: dmenu [-bfinv] [-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]");
} }
@ -749,7 +756,9 @@ main(int argc, char *argv[])
else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */ else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
fstrncmp = strncasecmp; fstrncmp = strncasecmp;
fstrstr = cistrstr; fstrstr = cistrstr;
} else if (i + 1 == argc) } else if (!strcmp(argv[i], "-n")) /* instant select only match */
instant = 1;
else if (i + 1 == argc)
usage(); usage();
/* these options take one argument */ /* these options take one argument */
else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */ else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */