shithub: dmenu

Download patch

ref: 8f50f11f51de6dd07f97db4a3e4b1b956af83313
parent: 0345e2a2c1399739a1629a7e6385b005e05d69a7
author: glenda <glenda@9front.local>
date: Mon Sep 6 06:28:17 EDT 2021

dmenu: do not redraw when the list did not change

--- a/dmenu.c
+++ b/dmenu.c
@@ -154,12 +154,13 @@
 filter(char **lines, int nlines)
 {
 	char *buf, *words[64], **l, **m;
-	int nwords;
+	int nwords, old;
 
 	if((buf = smprint("%S", kbinput)) == nil)
 		sysfatal("malloc");
 	nwords = tokenize(buf, words, sizeof words / sizeof *words);
 
+	old = nmatches;
 	nmatches = 0;
 	m = matches;
 	for(l = lines; l < lines + nlines; l++)
@@ -171,7 +172,10 @@
 	selected = 0;
 	scroll = 0;
 	free(buf);
-	eresized(0); /* possibly different lines: redraw everything */
+	if (nmatches == old)  /* optimization */
+		drawprompt();
+	else
+		eresized(0);
 }
 
 static void
@@ -257,17 +261,17 @@
 static void
 mselect(Point pt)
 {
-	int old, sel = pointtoline(pt);
+	int old, new = pointtoline(pt);
 
-	if(sel < 0)
-		sel = 0;
-	if(nmatches > 0 && sel >= nmatches)
-		sel = nmatches - 1;
-	if(sel != selected){
+	if(new < 0)
+		new = 0;
+	if(nmatches > 0 && new >= nmatches)
+		new = nmatches - 1;
+	if(new != selected){
 		old = selected;
-		selected = sel;
+		selected = new;
 		drawline(old);
-		drawline(sel);
+		drawline(new);
 	}
 }
 
@@ -331,9 +335,11 @@
 			case Ctl('U'):
 				kbclear();
 				break;
+			case Ctl('P'):
 			case Kup:
 				kbmove(-1);
 				break;
+			case Ctl('N'):
 			case Kdown:
 				kbmove(+1);
 				break;