dmenu-restrictreturn-5.0.diff (1956B)
1 diff --git a/config.def.h b/config.def.h 2 index 1edb647..47c2f76 100644 3 --- a/config.def.h 4 +++ b/config.def.h 5 @@ -2,6 +2,7 @@ 6 /* Default settings; can be overriden by command line. */ 7 8 static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */ 9 +static int restrict_return = 0; /* -r option; if 1, disables shift-return and ctrl-return */ 10 /* -fn option overrides fonts[0]; default X11 font or font set */ 11 static const char *fonts[] = { 12 "monospace:size=10" 13 diff --git a/dmenu.1 b/dmenu.1 14 index 323f93c..0dcafce 100644 15 --- a/dmenu.1 16 +++ b/dmenu.1 17 @@ -3,7 +3,7 @@ 18 dmenu \- dynamic menu 19 .SH SYNOPSIS 20 .B dmenu 21 -.RB [ \-bfiv ] 22 +.RB [ \-bfirv ] 23 .RB [ \-l 24 .IR lines ] 25 .RB [ \-m 26 @@ -47,6 +47,10 @@ is faster, but will lock up X until stdin reaches end\-of\-file. 27 .B \-i 28 dmenu matches menu items case insensitively. 29 .TP 30 +.B \-r 31 +disables ctr-return and shift-return. this guarantees that dmenu prints to 32 +stdout only once, and it only prints an item read from stdin. 33 +.TP 34 .BI \-l " lines" 35 dmenu lists items vertically, with the given number of lines. 36 .TP 37 diff --git a/dmenu.c b/dmenu.c 38 index 65f25ce..a278680 100644 39 --- a/dmenu.c 40 +++ b/dmenu.c 41 @@ -464,6 +464,13 @@ insert: 42 break; 43 case XK_Return: 44 case XK_KP_Enter: 45 + if (restrict_return) { 46 + if (!sel || ev->state & (ShiftMask | ControlMask)) 47 + break; 48 + puts(sel->text); 49 + cleanup(); 50 + exit(0); 51 + } 52 puts((sel && !(ev->state & ShiftMask)) ? sel->text : text); 53 if (!(ev->state & ControlMask)) { 54 cleanup(); 55 @@ -712,7 +719,9 @@ main(int argc, char *argv[]) 56 else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */ 57 fstrncmp = strncasecmp; 58 fstrstr = cistrstr; 59 - } else if (i + 1 == argc) 60 + } else if (!strcmp(argv[i], "-r")) 61 + restrict_return = 1; 62 + else if (i + 1 == argc) 63 usage(); 64 /* these options take one argument */ 65 else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */