dmenu/patches/dmenu-restrictreturn-5.0.diff
2023-01-04 21:46:34 -05:00

66 lines
1.9 KiB
Diff

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 */