From 5e005228889a1e62170f1cf66f9af0c5ebafe645 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigrid=20Hafl=C3=ADnud=C3=B3ttir?= Date: Thu, 13 Aug 2020 11:21:19 +0200 Subject: [PATCH] show where zuke would seek if the user would press on the seek bar --- zuke.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/zuke.c b/zuke.c index b412548..3e20b22 100644 --- a/zuke.c +++ b/zuke.c @@ -62,6 +62,8 @@ static int mincolwidth[7]; static char *cols = "AatD"; static int *shuffle; static Rectangle seekbar; +static int seekmx, newseekmx; +static double seekoff; /* ms */ static char *covers[] = {"folder", "cover", "Cover", "scans/CD", "Scans/Front", "Covers/Front"}; static char *menu3i[] = { @@ -252,9 +254,10 @@ redraw(int full) msec = MIN(msec, getmeta(pcurplaying)->duration); snprint(tmp, sizeof(tmp), "%s%P/%P %d%%", shuffle != nil ? "∫ " : "", - (int)msec/1000, + (int)(newseekmx >= 0 ? seekoff : msec)/1000, getmeta(pcurplaying)->duration/1000, volume); + seekmx = newseekmx; }else{ snprint(tmp, sizeof(tmp), "%s%P %d%%", shuffle != nil ? "∫ " : "", @@ -920,9 +923,20 @@ threadmain(int argc, char **argv) for(;;){ ev: oldpcur = pcur; + if(seekmx != newseekmx) + redraw(0); switch(alt(a)){ case 0: + if(ptinrect(m.xy, seekbar)){ + seekoff = getmeta(pcurplaying)->duration * (double)(m.xy.x-1-seekbar.min.x) / (double)Dx(seekbar); + if(seekoff < 0) + seekoff = 0; + newseekmx = m.xy.x-1; + }else{ + newseekmx = -1; + } + if(m.buttons != 2) scrolling = 0; if(m.buttons == 0) @@ -937,16 +951,15 @@ ev: break; } - n = (m.xy.y - screen->r.min.y)/f->height; if(oldbuttons == 0 && !scrolling && ptinrect(m.xy, insetrect(seekbar, -4))){ - m.xy.x--; - if(ptinrect(m.xy, seekbar)){ - double off = getmeta(pcurplaying)->duration * (double)(m.xy.x-seekbar.min.x) / (double)Dx(seekbar); - seekrel(playercurr, off/1000.0 - byteswritten/Bps); - } + if(ptinrect(m.xy, seekbar)) + seekrel(playercurr, seekoff/1000.0 - byteswritten/Bps); break; } + + n = (m.xy.y - screen->r.min.y)/f->height; + if(oldbuttons == 0 && m.xy.x <= screen->r.min.x+Scrollwidth){ if(m.buttons == 1){ scroll = MAX(0, scroll-n-1); -- 2.30.1