sites

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

dmenu-noinput-5.2.diff (4826B)


      1 diff -up dmenu/config.def.h dmenu-noinput/config.def.h
      2 --- dmenu/config.def.h	2024-03-03 12:59:00.545293913 -0600
      3 +++ dmenu-noinput/config.def.h	2024-03-03 10:00:59.974900500 -0600
      4 @@ -2,6 +2,7 @@
      5  /* Default settings; can be overriden by command line. */
      6  
      7  static int topbar = 1;                      /* -b  option; if 0, dmenu appears at bottom     */
      8 +static int draw_input = 1;                  /* -noi option; if 0, the input will not be drawn by default */
      9  /* -fn option overrides fonts[0]; default X11 font or font set */
     10  static const char *fonts[] = {
     11  	"monospace:size=10"
     12 diff -up dmenu/dmenu.c dmenu-noinput/dmenu.c
     13 --- dmenu/dmenu.c	2024-03-03 12:59:00.545293913 -0600
     14 +++ dmenu-noinput/dmenu.c	2024-03-03 12:15:44.416277776 -0600
     15 @@ -147,7 +147,7 @@ drawmenu(void)
     16  {
     17  	unsigned int curpos;
     18  	struct item *item;
     19 -	int x = 0, y = 0, w;
     20 +	int x = 0, y = 0, w = 0;
     21  
     22  	drw_setscheme(drw, scheme[SchemeNorm]);
     23  	drw_rect(drw, 0, 0, mw, mh, 1, 1);
     24 @@ -156,15 +156,17 @@ drawmenu(void)
     25  		drw_setscheme(drw, scheme[SchemeSel]);
     26  		x = drw_text(drw, x, 0, promptw, bh, lrpad / 2, prompt, 0);
     27  	}
     28 -	/* draw input field */
     29 -	w = (lines > 0 || !matches) ? mw - x : inputw;
     30 -	drw_setscheme(drw, scheme[SchemeNorm]);
     31 -	drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0);
     32  
     33 -	curpos = TEXTW(text) - TEXTW(&text[cursor]);
     34 -	if ((curpos += lrpad / 2 - 1) < w) {
     35 +	if (draw_input) {
     36 +		w = (lines > 0 || !matches) ? mw - x : inputw;
     37  		drw_setscheme(drw, scheme[SchemeNorm]);
     38 -		drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0);
     39 +		drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0);
     40 +
     41 +		curpos = TEXTW(text) - TEXTW(&text[cursor]);
     42 +		if ((curpos += lrpad / 2 - 1) < w) {
     43 +			drw_setscheme(drw, scheme[SchemeNorm]);
     44 +			drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0);
     45 +		}
     46  	}
     47  
     48  	if (lines > 0) {
     49 @@ -178,8 +180,8 @@ drawmenu(void)
     50  		if (curr->left) {
     51  			drw_setscheme(drw, scheme[SchemeNorm]);
     52  			drw_text(drw, x, 0, w, bh, lrpad / 2, "<", 0);
     53 +			x += w;
     54  		}
     55 -		x += w;
     56  		for (item = curr; item != next; item = item->right)
     57  			x = drawitem(item, x, 0, textw_clamp(item->text, mw - x - TEXTW(">")));
     58  		if (next) {
     59 @@ -358,16 +360,19 @@ keypress(XKeyEvent *ev)
     60  		case XK_p: ksym = XK_Up;        break;
     61  
     62  		case XK_k: /* delete right */
     63 -			text[cursor] = '\0';
     64 -			match();
     65 +			if (draw_input) {
     66 +				text[cursor] = '\0';
     67 +				match();
     68 +			}
     69  			break;
     70  		case XK_u: /* delete left */
     71 -			insert(NULL, 0 - cursor);
     72 +			if (draw_input)
     73 +				insert(NULL, 0 - cursor);
     74  			break;
     75  		case XK_w: /* delete word */
     76 -			while (cursor > 0 && strchr(worddelimiters, text[nextrune(-1)]))
     77 +			while (cursor > 0 && strchr(worddelimiters, text[nextrune(-1)]) && draw_input)
     78  				insert(NULL, nextrune(-1) - cursor);
     79 -			while (cursor > 0 && !strchr(worddelimiters, text[nextrune(-1)]))
     80 +			while (cursor > 0 && !strchr(worddelimiters, text[nextrune(-1)]) && draw_input)
     81  				insert(NULL, nextrune(-1) - cursor);
     82  			break;
     83  		case XK_y: /* paste selection */
     84 @@ -414,23 +419,23 @@ keypress(XKeyEvent *ev)
     85  	switch(ksym) {
     86  	default:
     87  insert:
     88 -		if (!iscntrl((unsigned char)*buf))
     89 +		if (!iscntrl((unsigned char)*buf) && draw_input)
     90  			insert(buf, len);
     91  		break;
     92  	case XK_Delete:
     93  	case XK_KP_Delete:
     94 -		if (text[cursor] == '\0')
     95 +		if (text[cursor] == '\0' || !draw_input)
     96  			return;
     97  		cursor = nextrune(+1);
     98  		/* fallthrough */
     99  	case XK_BackSpace:
    100 -		if (cursor == 0)
    101 +		if (cursor == 0 || !draw_input)
    102  			return;
    103  		insert(NULL, nextrune(-1) - cursor);
    104  		break;
    105  	case XK_End:
    106  	case XK_KP_End:
    107 -		if (text[cursor] != '\0') {
    108 +		if (text[cursor] != '\0' && draw_input) {
    109  			cursor = strlen(text);
    110  			break;
    111  		}
    112 @@ -514,7 +519,7 @@ insert:
    113  		}
    114  		break;
    115  	case XK_Tab:
    116 -		if (!sel)
    117 +		if (!sel || !draw_input)
    118  			return;
    119  		cursor = strnlen(sel->text, sizeof text - 1);
    120  		memcpy(text, sel->text, cursor);
    121 @@ -677,7 +682,7 @@ setup(void)
    122  		mw = wa.width;
    123  	}
    124  	promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
    125 -	inputw = mw / 3; /* input width: ~33% of monitor width */
    126 +	inputw = !draw_input ? 0 : mw / 3; /* input width: ~33% of monitor width */
    127  	match();
    128  
    129  	/* create menu window */
    130 @@ -715,7 +720,7 @@ setup(void)
    131  static void
    132  usage(void)
    133  {
    134 -	die("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
    135 +	die("usage: dmenu [-bfiv] [-noi] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
    136  	    "             [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]");
    137  }
    138  
    139 @@ -734,6 +739,8 @@ main(int argc, char *argv[])
    140  			topbar = 0;
    141  		else if (!strcmp(argv[i], "-f"))   /* grabs keyboard before reading stdin */
    142  			fast = 1;
    143 +	        else if (!strcmp(argv[i], "-noi")) /* no input field. intended to be used with a prompt */
    144 +			draw_input = 0;
    145  		else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
    146  			fstrncmp = strncasecmp;
    147  			fstrstr = cistrstr;