shithub: zuke

Download patch

ref: d7a96d874a6323ea9475fdbd935ca58a00539b33
parent: 940115935451666e84f3e972a4fb4a7972b57d91
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Fri Feb 26 07:07:30 EST 2021

fix scrolling issues related to playback of the last track

--- a/zuke.c
+++ b/zuke.c
@@ -207,7 +207,7 @@
 static void
 updatescrollsz(void)
 {
-	scrollsz = (Dy(screen->r) - f->height - 4) / f->height - 1;
+	scrollsz = Dy(screen->r)/f->height - 2;
 }
 
 static void
@@ -222,6 +222,7 @@
 
 	lockdisplay(display);
 	updatescrollsz();
+	scroll = CLAMP(scroll, 0, pl->n - scrollsz);
 	left = screen->r.min.x;
 	if(scrollsz < pl->n) /* adjust for scrollbar */
 		left += Scrollwidth + 1;
@@ -947,11 +948,7 @@
 recenter(void)
 {
 	updatescrollsz();
-	scroll = pcur - scrollsz/2;
-	if(scroll < 0)
-		scroll = 0;
-	else if(scroll >= scrollsz)
-		scroll = scrollsz-1;
+	scroll = pcur - scrollsz/2 + 1;
 }
 
 static void
@@ -1282,7 +1279,7 @@
 				redraw(1);
 				break;
 			}else if(m.buttons == 16){
-				scroll = MIN(scroll+scrollsz/4+1, pl->n-scrollsz-1);
+				scroll = MIN(scroll+scrollsz/4+1, pl->n-scrollsz);
 				redraw(1);
 				break;
 			}
@@ -1302,7 +1299,7 @@
 					redraw(1);
 					break;
 				}else if(m.buttons == 4){
-					scroll = MIN(scroll+n+1, pl->n-scrollsz-1);
+					scroll = MIN(scroll+n+1, pl->n-scrollsz);
 					redraw(1);
 					break;
 				}else if(m.buttons == 2){
@@ -1323,7 +1320,7 @@
 				if(scrollsz >= pl->n)
 					break;
 				scroll = (m.xy.y - screen->r.min.y - Scrollheight/4)*(pl->n-scrollsz) / (Dy(screen->r)-Scrollheight/2);
-				scroll = CLAMP(scroll, 0, pl->n-scrollsz-1);
+				scroll = CLAMP(scroll, 0, pl->n-scrollsz);
 				redraw(1);
 			}else if(m.buttons == 1 || m.buttons == 2){
 				n += scroll;
@@ -1370,6 +1367,7 @@
 				break;
 			case Kend:
 				pcur = pl->n-1;
+				scroll = pl->n-scrollsz;
 				break;
 			case Khome:
 				pcur = 0;