From d6894046f1742da44ec1adc08723a434c74bb25d Mon Sep 17 00:00:00 2001 From: bakkeby Date: Mon, 17 May 2021 10:59:48 +0200 Subject: [PATCH] Adding restrict return patch --- README.md | 6 ++++++ config.def.h | 3 +++ dmenu.c | 11 +++++++++++ patches.def.h | 6 ++++++ 4 files changed, 26 insertions(+) diff --git a/README.md b/README.md index f1b3e21..96d3850 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,8 @@ dmenu, how to install it and how it works. ### Changelog: +2021-05-17 - Added the restrict return patch + 2021-05-15 - Added the tsv and printindex patches 2020-08-08 - Added the json, symbols, managed, morecolor, multi-selection and preselect patches @@ -179,6 +181,10 @@ dmenu, how to install it and how it works. - adds a new flag to dmenu with which text input will be rejected if it would result in no matching item + - [restrict-return](https://tools.suckless.org/dmenu/patches/restrict-return/) + - adds a '-1' option which disables Shift-Return and Ctrl-Return + - this guarantees that dmenu will only output one item, and that item was read from stdin + - [scroll](https://tools.suckless.org/dmenu/patches/scroll/) - this patch adds support for text scrolling - it doesn't append '...' for long input anymore as it can handle long text diff --git a/config.def.h b/config.def.h index b6b88f2..c070808 100644 --- a/config.def.h +++ b/config.def.h @@ -18,6 +18,9 @@ static int instant = 0; /* -n option; if 1, selects matchin static int center = 1; /* -c option; if 0, dmenu won't be centered on the screen */ static int min_width = 500; /* minimum width when centered */ #endif // CENTER_PATCH +#if RESTRICT_RETURN_PATCH +static int restrict_return = 0; /* -1 option; if 1, disables shift-return and ctrl-return */ +#endif // RESTRICT_RETURN_PATCH /* -fn option overrides fonts[0]; default X11 font or font set */ #if PANGO_PATCH static char font[] = "monospace 10"; diff --git a/dmenu.c b/dmenu.c index 93ad9f4..0d30f54 100644 --- a/dmenu.c +++ b/dmenu.c @@ -925,6 +925,10 @@ insert: break; case XK_Return: case XK_KP_Enter: + #if RESTRICT_RETURN_PATCH + if (restrict_return && (!sel || ev->state & (ShiftMask | ControlMask))) + break; + #endif // RESTRICT_RETURN_PATCH #if !MULTI_SELECTION_PATCH #if JSON_PATCH if (!printjsonssel(ev->state)) @@ -1512,6 +1516,9 @@ usage(void) #if REJECTNOMATCH_PATCH "R" // (changed from r to R due to conflict with INCREMENTAL_PATCH) #endif // REJECTNOMATCH_PATCH + #if RESTRICT_RETURN_PATCH + "1" + #endif // RESTRICT_RETURN_PATCH "] " #if MANAGED_PATCH "[-wm] " @@ -1630,6 +1637,10 @@ main(int argc, char *argv[]) } else if (!strcmp(argv[i], "-ix")) { /* adds ability to return index in list */ print_index = 1; #endif // PRINTINDEX_PATCH + #if RESTRICT_RETURN_PATCH + } else if (!strcmp(argv[i], "-1")) { + restrict_return = 1; + #endif // RESTRICT_RETURN_PATCH } else if (i + 1 == argc) usage(); /* these options take one argument */ diff --git a/patches.def.h b/patches.def.h index ce28aff..921bd04 100644 --- a/patches.def.h +++ b/patches.def.h @@ -233,6 +233,12 @@ */ #define REJECTNOMATCH_PATCH 0 +/* This patch adds a '-r' option which disables Shift-Return and Ctrl-Return. + * This guarantees that dmenu will only output one item, and that item was read from stdin. + * https://tools.suckless.org/dmenu/patches/restrict-return/ + */ +#define RESTRICT_RETURN_PATCH 0 + /* This patch adds support for text scrolling and no longer appends '...' for long input as * it can handle long text. * https://tools.suckless.org/dmenu/patches/scroll/