sites

public wiki contents of suckless.org
git clone git://git.suckless.org/sites
Log | Files | Refs

dmenu-noescape-20230328-dfbbf7f.diff (1813B)


      1 From 5622f9497f5dca83035443a0a00e89c63862b15b Mon Sep 17 00:00:00 2001
      2 From: Aaron Z├╝ger <contact@azureorange.xyz>
      3 Date: Tue, 28 Mar 2023 18:05:36 +0200
      4 Subject: [PATCH] Added the -no-escape flag which will stop the escape key from
      5  exiting dmenu.
      6 
      7 ---
      8  dmenu.c | 14 +++++++++++---
      9  1 file changed, 11 insertions(+), 3 deletions(-)
     10 
     11 diff --git a/dmenu.c b/dmenu.c
     12 index 4e7df12..203d9bf 100644
     13 --- a/dmenu.c
     14 +++ b/dmenu.c
     15 @@ -1,6 +1,7 @@
     16  /* See LICENSE file for copyright and license details. */
     17  #include <ctype.h>
     18  #include <locale.h>
     19 +#include <stdbool.h>
     20  #include <stdio.h>
     21  #include <stdlib.h>
     22  #include <string.h>
     23 @@ -53,6 +54,8 @@ static XIC xic;
     24  static Drw *drw;
     25  static Clr *scheme[SchemeLast];
     26  
     27 +static bool no_escape = false;
     28 +
     29  #include "config.h"
     30  
     31  static int (*fstrncmp)(const char *, const char *, size_t) = strncmp;
     32 @@ -447,8 +450,10 @@ insert:
     33  		sel = matchend;
     34  		break;
     35  	case XK_Escape:
     36 -		cleanup();
     37 -		exit(1);
     38 +        if (no_escape == false) {
     39 +		    cleanup();
     40 +		    exit(1);
     41 +        }
     42  	case XK_Home:
     43  	case XK_KP_Home:
     44  		if (sel == matches) {
     45 @@ -716,6 +721,7 @@ static void
     46  usage(void)
     47  {
     48  	die("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
     49 +        "             [-no-escape]\n"
     50  	    "             [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]");
     51  }
     52  
     53 @@ -737,7 +743,9 @@ main(int argc, char *argv[])
     54  		else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
     55  			fstrncmp = strncasecmp;
     56  			fstrstr = cistrstr;
     57 -		} else if (i + 1 == argc)
     58 +        } else if (!strcmp(argv[i], "-no-escape"))   /* disable escape */
     59 +			no_escape = !no_escape;
     60 +		else if (i + 1 == argc)
     61  			usage();
     62  		/* these options take one argument */
     63  		else if (!strcmp(argv[i], "-l"))   /* number of lines in vertical list */
     64 -- 
     65 2.40.0
     66