shithub: zuke

Download patch

ref: 97b5812b636750164c1c4a250a3488a90c47dc0f
parent: 8d2b1527e5a83ba5c91191656fafb25866ec74ac
author: Sigrid Haflínudóttir <[email protected]>
date: Mon Oct 12 08:42:48 EDT 2020

status: adjust width according to song duration and max volume so it stays the same when seeking

--- a/zuke.c
+++ b/zuke.c
@@ -175,7 +175,7 @@
 	Image *col;
 	Point p, sp;
 	Rectangle sel, r;
-	int i, j, left, right, scrollcenter;
+	int i, j, left, right, scrollcenter, w;
 	char tmp[32];
 
 	lockdisplay(display);
@@ -265,6 +265,11 @@
 
 	vlong msec = 0;
 	if(pcurplaying >= 0){
+		snprint(tmp, sizeof(tmp), "%s%P/%P 100%%",
+			shuffle != nil ? "∫ " : "",
+			getmeta(pcurplaying)->duration/1000,
+			getmeta(pcurplaying)->duration/1000);
+		w = stringwidth(f, tmp);
 		msec = byteswritten*1000/Bps;
 		if(getmeta(pcurplaying)->duration != 0){
 			msec = MIN(msec, getmeta(pcurplaying)->duration);
@@ -280,17 +285,20 @@
 				(int)msec/1000,
 				volume);
 		}
-	}else
+	}else{
+		snprint(tmp, sizeof(tmp), "%s%d%%", shuffle != nil ? "∫ " : "", 100);
+		w = stringwidth(f, tmp);
 		snprint(tmp, sizeof(tmp), "%s%d%%", shuffle != nil ? "∫ " : "", volume);
+	}
 	r = screen->r;
-	right = r.max.x - stringwidth(f, tmp) - 4;
+	right = r.max.x - w - 4;
 	r.min.x = left;
 	r.min.y = r.max.y - f->height - 4;
 	if(pcurplaying < 0 || getmeta(pcurplaying)->duration == 0)
 		r.min.x = right;
 	draw(screen, r, colors[Dblow].im, nil, ZP);
+	p = addpt(Pt(r.max.x-stringwidth(f, tmp)-4, r.min.y), Pt(2, 2));
 	r.max.x = right;
-	p = addpt(Pt(right, r.min.y), Pt(2, 2));
 	string(screen, p, colors[Dfhigh].im, sp, f, tmp);
 	sel = r;
 	yield();