restrict return patch
This commit is contained in:
parent
2db2a8113f
commit
77b329af23
@ -2,6 +2,7 @@
|
||||
/* Default settings; can be overriden by command line. */
|
||||
|
||||
static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */
|
||||
static int restrict_return = 0; /* -r option; if 1, disables shift-return and ctrl-return */
|
||||
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 int centered = 0; /* -c option; centers dmenu on screen */
|
||||
|
6
dmenu.1
6
dmenu.1
@ -3,7 +3,7 @@
|
||||
dmenu \- dynamic menu
|
||||
.SH SYNOPSIS
|
||||
.B dmenu
|
||||
.RB [ \-bfsrv ]
|
||||
.RB [ \-bfsrRv ]
|
||||
.RB [ \-l
|
||||
.IR lines ]
|
||||
.RB [ \-h
|
||||
@ -55,6 +55,10 @@ dmenu matches menu items case sensitively.
|
||||
.B \-r
|
||||
dmenu will reject any input which would result in no matching option left.
|
||||
.TP
|
||||
.B \-R
|
||||
disables ctr-return and shift-return. this guarantees that dmenu prints to
|
||||
stdout only once, and it only prints an item read from stdin.
|
||||
.TP
|
||||
.BI \-l " lines"
|
||||
dmenu lists items vertically, with the given number of lines.
|
||||
.TP
|
||||
|
11
dmenu.c
11
dmenu.c
@ -611,6 +611,13 @@ insert:
|
||||
break;
|
||||
case XK_Return:
|
||||
case XK_KP_Enter:
|
||||
if (restrict_return) {
|
||||
if (!sel || ev->state & (ShiftMask | ControlMask))
|
||||
break;
|
||||
puts(sel->text);
|
||||
cleanup();
|
||||
exit(0);
|
||||
}
|
||||
puts((sel && !(ev->state & ShiftMask)) ? sel->text : text);
|
||||
if (!(ev->state & ControlMask)) {
|
||||
cleanup();
|
||||
@ -848,7 +855,7 @@ setup(void)
|
||||
static void
|
||||
usage(void)
|
||||
{
|
||||
die("usage: dmenu [-bfirv] [-l lines] [-h height] [-p prompt] [-fn font] [-m monitor]\n"
|
||||
die("usage: dmenu [-bfirRv] [-l lines] [-h height] [-p prompt] [-fn font] [-m monitor]\n"
|
||||
" [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]");
|
||||
}
|
||||
|
||||
@ -876,6 +883,8 @@ main(int argc, char *argv[])
|
||||
fstrstr = strstr;
|
||||
} else if (!strcmp(argv[i], "-r")) /* reject input which results in no match */
|
||||
reject_no_match = 1;
|
||||
else if (!strcmp(argv[i], "-R"))
|
||||
restrict_return = 1;
|
||||
else if (i + 1 == argc)
|
||||
usage();
|
||||
/* these options take one argument */
|
||||
|
65
patches/dmenu-restrictreturn-5.0.diff
Normal file
65
patches/dmenu-restrictreturn-5.0.diff
Normal file
@ -0,0 +1,65 @@
|
||||
diff --git a/config.def.h b/config.def.h
|
||||
index 1edb647..47c2f76 100644
|
||||
--- a/config.def.h
|
||||
+++ b/config.def.h
|
||||
@@ -2,6 +2,7 @@
|
||||
/* Default settings; can be overriden by command line. */
|
||||
|
||||
static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */
|
||||
+static int restrict_return = 0; /* -r option; if 1, disables shift-return and ctrl-return */
|
||||
/* -fn option overrides fonts[0]; default X11 font or font set */
|
||||
static const char *fonts[] = {
|
||||
"monospace:size=10"
|
||||
diff --git a/dmenu.1 b/dmenu.1
|
||||
index 323f93c..0dcafce 100644
|
||||
--- a/dmenu.1
|
||||
+++ b/dmenu.1
|
||||
@@ -3,7 +3,7 @@
|
||||
dmenu \- dynamic menu
|
||||
.SH SYNOPSIS
|
||||
.B dmenu
|
||||
-.RB [ \-bfiv ]
|
||||
+.RB [ \-bfirv ]
|
||||
.RB [ \-l
|
||||
.IR lines ]
|
||||
.RB [ \-m
|
||||
@@ -47,6 +47,10 @@ is faster, but will lock up X until stdin reaches end\-of\-file.
|
||||
.B \-i
|
||||
dmenu matches menu items case insensitively.
|
||||
.TP
|
||||
+.B \-r
|
||||
+disables ctr-return and shift-return. this guarantees that dmenu prints to
|
||||
+stdout only once, and it only prints an item read from stdin.
|
||||
+.TP
|
||||
.BI \-l " lines"
|
||||
dmenu lists items vertically, with the given number of lines.
|
||||
.TP
|
||||
diff --git a/dmenu.c b/dmenu.c
|
||||
index 65f25ce..a278680 100644
|
||||
--- a/dmenu.c
|
||||
+++ b/dmenu.c
|
||||
@@ -464,6 +464,13 @@ insert:
|
||||
break;
|
||||
case XK_Return:
|
||||
case XK_KP_Enter:
|
||||
+ if (restrict_return) {
|
||||
+ if (!sel || ev->state & (ShiftMask | ControlMask))
|
||||
+ break;
|
||||
+ puts(sel->text);
|
||||
+ cleanup();
|
||||
+ exit(0);
|
||||
+ }
|
||||
puts((sel && !(ev->state & ShiftMask)) ? sel->text : text);
|
||||
if (!(ev->state & ControlMask)) {
|
||||
cleanup();
|
||||
@@ -712,7 +719,9 @@ main(int argc, char *argv[])
|
||||
else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
|
||||
fstrncmp = strncasecmp;
|
||||
fstrstr = cistrstr;
|
||||
- } else if (i + 1 == argc)
|
||||
+ } else if (!strcmp(argv[i], "-r"))
|
||||
+ restrict_return = 1;
|
||||
+ else if (i + 1 == argc)
|
||||
usage();
|
||||
/* these options take one argument */
|
||||
else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */
|
Loading…
Reference in New Issue
Block a user