Adding tsv patch

This commit is contained in:
bakkeby 2021-05-15 12:51:58 +02:00
parent 79b9ae42d8
commit 93f5b58d4e
5 changed files with 54 additions and 11 deletions

View File

@ -15,6 +15,8 @@ Refer to [https://tools.suckless.org/dmenu/](https://tools.suckless.org/dmenu/)
### Changelog:
2021-05-15 - Added the tsv patch
2020-08-08 - Added the json, symbols, managed, morecolor, multi-selection and preselect patches
2020-08-05 - Added the grid, highlight, highpriority, dynamic options and numbers patches
@ -145,6 +147,10 @@ Refer to [https://tools.suckless.org/dmenu/](https://tools.suckless.org/dmenu/)
- [symbols](https://tools.suckless.org/dmenu/patches/symbols/)
- allows the symbols, which are printed in dmenu to indicate that either the input is too long or there are too many options to be shown in dmenu in one line, to be defined
- [tsv](https://tools.suckless.org/dmenu/patches/tsv/)
- makes dmenu split input lines at first tab character and only display first part, but it will perform matching on and output full lines as usual
- can be useful if you want to separate data and representation
- [vertfull](https://tools.suckless.org/dmenu/patches/vertfull/)
- prevents dmenu from indenting items at the same level as the prompt length

View File

@ -25,7 +25,7 @@ FREETYPEINC = /usr/include/freetype2
#EXTRAFLAGS=-D_GNU_SOURCE
# Uncomment this for the alpha patch / ALPHA_PATCH
#XRENDER = -lXrender
XRENDER = -lXrender
# Uncomment for the pango patch / PANGO_PATCH
#PANGOINC = `pkg-config --cflags xft pango pangoxft`

46
dmenu.c
View File

@ -71,6 +71,9 @@ enum {
struct item {
char *text;
#if TSV_PATCH
char *stext;
#endif // TSV_PATCH
struct item *left, *right;
#if NON_BLOCKING_STDIN_PATCH
struct item *next;
@ -283,8 +286,18 @@ drawitem(struct item *item, int x, int y, int w)
else
drw_setscheme(drw, scheme[SchemeNorm]);
r = drw_text(drw, x, y, w, bh, lrpad / 2
#if TSV_PATCH
, item->stext
#else
, item->text
#endif // TSV_PATCH
, 0
#if PANGO_PATCH
, True
#endif // PANGO_PATCH
);
#if PANGO_PATCH
r = drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0, True);
#else
r = drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
#endif // PANGO_PATCH
@ -304,7 +317,7 @@ drawmenu(void)
unsigned int curpos;
#endif // SCROLL_PATCH
struct item *item;
int x = 0, y = 0, w, rpad = 0;
int x = 0, y = 0, w, rpad = 0, itw = 0, stw = 0;
#if LINE_HEIGHT_PATCH && PANGO_PATCH
int fh = drw->font->h;
#elif LINE_HEIGHT_PATCH
@ -448,16 +461,23 @@ drawmenu(void)
#endif // PANGO_PATCH
}
x += w;
for (item = curr; item != next; item = item->right)
#if PANGO_PATCH && SYMBOLS_PATCH
x = drawitem(item, x, 0, MIN(TEXTWM(item->text), mw - x - TEXTW(symbol_2) - rpad));
for (item = curr; item != next; item = item->right) {
#if PANGO_PATCH && TSV_PATCH
itw = TEXTWM(item->stext);
#elif PANGO_PATCH
x = drawitem(item, x, 0, MIN(TEXTWM(item->text), mw - x - TEXTW(">") - rpad));
#elif SYMBOLS_PATCH
x = drawitem(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(symbol_2) - rpad));
itw = TEXTWM(item->text);
#elif TSV_PATCH
itw = TEXTW(item->stext);
#else
x = drawitem(item, x, 0, MIN(TEXTW(item->text), mw - x - TEXTW(">") - rpad));
#endif // PANGO_PATCH
itw = TEXTW(item->text);
#endif // PANGO_PATCH | TSV_PATCH
#if SYMBOLS_PATCH
stw = TEXTW(symbol_2);
#else
stw = TEXTW(">");
#endif // SYMBOLS_PATCH
x = drawitem(item, x, 0, MIN(itw, mw - x - stw - rpad));
}
if (next) {
#if SYMBOLS_PATCH
w = TEXTW(symbol_2);
@ -1093,6 +1113,12 @@ readstdin(void)
if (!(items[i].text = strdup(buf)))
#endif // JSON_PATCH
die("cannot strdup %u bytes:", strlen(buf) + 1);
#if TSV_PATCH
if ((p = strchr(buf, '\t')))
*p = '\0';
if (!(items[i].stext = strdup(buf)))
die("cannot strdup %u bytes:", strlen(buf) + 1);
#endif // TSV_PATCH
#if MULTI_SELECTION_PATCH
items[i].id = i; /* for multiselect */
#elif JSON_PATCH

View File

@ -1,2 +1,3 @@
#!/bin/sh
export _JAVA_AWT_WM_NONREPARENTING=1
exec $(dmenu_path | dmenu "$@")

View File

@ -237,6 +237,16 @@
*/
#define SYMBOLS_PATCH 0
/* With this patch dmenu will split input lines at first tab character and only display first
* part, but it will perform matching on and output full lines as usual.
*
* This can be useful if you want to separate data and representation, for example, a music
* player wrapper can display only a track title to user, but still supply full filename to
* the underlying script.
* https://tools.suckless.org/dmenu/patches/tsv/
*/
#define TSV_PATCH 0
/* This patch prevents dmenu from indenting items at the same level as the prompt length.
* https://tools.suckless.org/dmenu/patches/vertfull/
*/