dmenu-tsv-alt-5.3.diff (3540B)
1 From abc8bfeaaa5e62ce957d8a33ad1f5ca7c793513e Mon Sep 17 00:00:00 2001 2 From: Max Schillinger <maxschillinger@web.de> 3 Date: Sat, 13 Jul 2024 21:06:57 +0200 4 Subject: [PATCH] tsv-alt patch for dmenu 5.3 5 6 --- 7 config.def.h | 5 +++++ 8 dmenu.1 | 6 +++++- 9 dmenu.c | 21 ++++++++++++++------- 10 3 files changed, 24 insertions(+), 8 deletions(-) 11 12 diff --git a/config.def.h b/config.def.h 13 index 1edb647..bd0fcef 100644 14 --- a/config.def.h 15 +++ b/config.def.h 16 @@ -21,3 +21,8 @@ static unsigned int lines = 0; 17 * for example: " /?\"&[]" 18 */ 19 static const char worddelimiters[] = " "; 20 + 21 +/* tsv-alt: reverse the order of tab separation. 22 + * 0 = display<TAB>output. 1 = output<TAB>display 23 + * can be reversed with -r as well */ 24 +static int revtab = 0; 25 diff --git a/dmenu.1 b/dmenu.1 26 index 323f93c..e767276 100644 27 --- a/dmenu.1 28 +++ b/dmenu.1 29 @@ -3,7 +3,7 @@ 30 dmenu \- dynamic menu 31 .SH SYNOPSIS 32 .B dmenu 33 -.RB [ \-bfiv ] 34 +.RB [ \-bfirv ] 35 .RB [ \-l 36 .IR lines ] 37 .RB [ \-m 38 @@ -80,6 +80,10 @@ prints version information to stdout, then exits. 39 .TP 40 .BI \-w " windowid" 41 embed into windowid. 42 +.TP 43 +.B \-r 44 +tsv-alt: reverse the behavior of tab separation. 45 +.TP 46 .SH USAGE 47 dmenu is completely controlled by the keyboard. Items are selected using the 48 arrow keys, page up, page down, home, and end. 49 diff --git a/dmenu.c b/dmenu.c 50 index 40f93e0..bee6b19 100644 51 --- a/dmenu.c 52 +++ b/dmenu.c 53 @@ -29,6 +29,7 @@ enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */ 54 55 struct item { 56 char *text; 57 + char *otext; 58 struct item *left, *right; 59 int out; 60 }; 61 @@ -104,7 +105,7 @@ cleanup(void) 62 for (i = 0; i < SchemeLast; i++) 63 free(scheme[i]); 64 for (i = 0; items && items[i].text; ++i) 65 - free(items[i].text); 66 + free(revtab ? items[i].otext : items[i].text); 67 free(items); 68 drw_free(drw); 69 XSync(dpy, False); 70 @@ -489,7 +490,7 @@ insert: 71 break; 72 case XK_Return: 73 case XK_KP_Enter: 74 - puts((sel && !(ev->state & ShiftMask)) ? sel->text : text); 75 + puts((sel && !(ev->state & ShiftMask)) ? sel->otext : text); 76 if (!(ev->state & ControlMask)) { 77 cleanup(); 78 exit(0); 79 @@ -548,7 +549,7 @@ paste(void) 80 static void 81 readstdin(void) 82 { 83 - char *line = NULL; 84 + char *line = NULL, *tmp; 85 size_t i, itemsiz = 0, linesiz = 0; 86 ssize_t len; 87 88 @@ -561,14 +562,18 @@ readstdin(void) 89 } 90 if (line[len - 1] == '\n') 91 line[len - 1] = '\0'; 92 - if (!(items[i].text = strdup(line))) 93 + if (!(items[i].text = items[i].otext = strdup(line))) 94 die("strdup:"); 95 96 + if ((tmp = strchr(items[i].text, '\t'))) { 97 + *tmp++ = '\0'; 98 + revtab ? (items[i].text = tmp) : (items[i].otext = tmp); 99 + } 100 items[i].out = 0; 101 } 102 free(line); 103 if (items) 104 - items[i].text = NULL; 105 + items[i].text = items[i].otext = NULL; 106 lines = MIN(lines, i); 107 } 108 109 @@ -715,7 +720,7 @@ setup(void) 110 static void 111 usage(void) 112 { 113 - die("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" 114 + die("usage: dmenu [-bfirv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" 115 " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]"); 116 } 117 118 @@ -737,7 +742,9 @@ main(int argc, char *argv[]) 119 else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */ 120 fstrncmp = strncasecmp; 121 fstrstr = cistrstr; 122 - } else if (i + 1 == argc) 123 + } else if (!strcmp(argv[i], "-r")) /* reverse the tab separation */ 124 + revtab = (!revtab); 125 + else if (i + 1 == argc) 126 usage(); 127 /* these options take one argument */ 128 else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */ 129 -- 130 2.45.2 131