sites

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

dmenu-tmenu-20240811-475d809.diff (3229B)


      1 From a90fe0dcad642e4c314d08a86f0848c7c5bc87cb Mon Sep 17 00:00:00 2001
      2 From: Robert Bilski <robert@rbilski.com>
      3 Date: Sun, 11 Aug 2024 16:27:58 +0200
      4 Subject: [PATCH] Update tmenu patch
      5 
      6 ---
      7  config.def.h |  3 +++
      8  dmenu.1      |  3 +++
      9  dmenu.c      | 25 +++++++++++++++++++------
     10  3 files changed, 25 insertions(+), 6 deletions(-)
     11 
     12 diff --git a/config.def.h b/config.def.h
     13 index 1edb647..805d8c4 100644
     14 --- a/config.def.h
     15 +++ b/config.def.h
     16 @@ -21,3 +21,6 @@ static unsigned int lines      = 0;
     17   * for example: " /?\"&[]"
     18   */
     19  static const char worddelimiters[] = " ";
     20 +
     21 +/* delimiter for tmenu */
     22 +static char valuedelimiter = '\t';
     23 diff --git a/dmenu.1 b/dmenu.1
     24 index 323f93c..fb22ed3 100644
     25 --- a/dmenu.1
     26 +++ b/dmenu.1
     27 @@ -47,6 +47,9 @@ is faster, but will lock up X until stdin reaches end\-of\-file.
     28  .B \-i
     29  dmenu matches menu items case insensitively.
     30  .TP
     31 +.BI \-d " tmenu delimiter"
     32 +when used in a line, the value after the delimiter will be displayed. When selected, the value before the delimiter will be output. Only uses a single char as the delimiter.
     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 40f93e0..a456425 100644
     39 --- a/dmenu.c
     40 +++ b/dmenu.c
     41 @@ -28,7 +28,7 @@
     42  enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
     43  
     44  struct item {
     45 -	char *text;
     46 +	char *text, *value;
     47  	struct item *left, *right;
     48  	int out;
     49  };
     50 @@ -103,8 +103,8 @@ cleanup(void)
     51  	XUngrabKey(dpy, AnyKey, AnyModifier, root);
     52  	for (i = 0; i < SchemeLast; i++)
     53  		free(scheme[i]);
     54 -	for (i = 0; items && items[i].text; ++i)
     55 -		free(items[i].text);
     56 +	for (i = 0; items && items[i].value; ++i)
     57 +		free(items[i].value);
     58  	free(items);
     59  	drw_free(drw);
     60  	XSync(dpy, False);
     61 @@ -489,7 +489,7 @@ insert:
     62  		break;
     63  	case XK_Return:
     64  	case XK_KP_Enter:
     65 -		puts((sel && !(ev->state & ShiftMask)) ? sel->text : text);
     66 +		puts((sel && !(ev->state & ShiftMask)) ? sel->value : text);
     67  		if (!(ev->state & ControlMask)) {
     68  			cleanup();
     69  			exit(0);
     70 @@ -564,11 +564,22 @@ readstdin(void)
     71  		if (!(items[i].text = strdup(line)))
     72  			die("strdup:");
     73  
     74 +		if (!(items[i].value = strdup(line)))
     75 +			die("strdup:");
     76 +
     77 +		if ((items[i].text = strchr(items[i].value, valuedelimiter))) {
     78 +			items[i].text[0] = '\0';
     79 +			items[i].text++;
     80 +		} else {
     81 +			items[i].text = items[i].value;
     82 +		}
     83  		items[i].out = 0;
     84  	}
     85  	free(line);
     86 -	if (items)
     87 +	if (items) {
     88  		items[i].text = NULL;
     89 +		items[i].value = NULL;
     90 +	}
     91  	lines = MIN(lines, i);
     92  }
     93  
     94 @@ -715,7 +726,7 @@ setup(void)
     95  static void
     96  usage(void)
     97  {
     98 -	die("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
     99 +	die("usage: dmenu [-bfiv] [-d tmenu-delim] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
    100  	    "             [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]");
    101  }
    102  
    103 @@ -740,6 +751,8 @@ main(int argc, char *argv[])
    104  		} else if (i + 1 == argc)
    105  			usage();
    106  		/* these options take one argument */
    107 +		else if (!strcmp(argv[i], "-d"))   /* delimiter for tmenu */
    108 +			valuedelimiter = argv[++i][0];
    109  		else if (!strcmp(argv[i], "-l"))   /* number of lines in vertical list */
    110  			lines = atoi(argv[++i]);
    111  		else if (!strcmp(argv[i], "-m"))
    112 -- 
    113 2.46.0
    114