commit 914add4cedb75bab216b5702e34e71b45005f905
parent a75742a5b0fbbbbbe74f0912a39fc82c91911fd4
Author: Louis Burda <quent.burda@gmail.com>
Date: Sat, 5 Mar 2022 17:16:45 +0100
Simplify listnav, change pane on playing track seek
Diffstat:
2 files changed, 22 insertions(+), 9 deletions(-)
diff --git a/src/listnav.c b/src/listnav.c
@@ -3,10 +3,25 @@
#include <string.h>
+static void listnav_update_win(struct listnav *nav);
+
+void
+listnav_update_win(struct listnav *nav)
+{
+ nav->wmin = MAX(nav->wmax - nav->wlen, nav->min);
+ nav->wmax = MIN(nav->wmin + nav->wlen, nav->max);
+ nav->sel = MAX(MIN(nav->sel, nav->wmax - 1), nav->wmin);
+}
+
void
listnav_init(struct listnav *nav)
{
- memset(nav, 0, sizeof(struct listnav));
+ nav->sel = 0;
+ nav->min = 0;
+ nav->max = 0;
+ nav->wlen = 0;
+ nav->wmin = 0;
+ nav->wmax = 0;
}
void
@@ -16,7 +31,8 @@ listnav_update_bounds(struct listnav *nav, int min, int max)
nav->min = min;
nav->max = max;
- listnav_update_wlen(nav, MIN(nav->wlen, nav->max - nav->min));
+
+ listnav_update_win(nav);
}
void
@@ -24,13 +40,8 @@ listnav_update_wlen(struct listnav *nav, int wlen)
{
ASSERT(wlen >= 0);
- nav->wlen = MIN(wlen, nav->max - nav->min);
- if (nav->wmin < nav->min)
- nav->wmin = nav->min;
- if (nav->wmin + nav->wlen > nav->max)
- nav->wmin = nav->max - nav->wlen;
- nav->wmax = nav->wmin + nav->wlen;
- nav->sel = MAX(MIN(nav->sel, nav->wmax - 1), nav->wmin);
+ nav->wlen = wlen;
+ listnav_update_win(nav);
}
void
diff --git a/src/tui.c b/src/tui.c
@@ -1046,6 +1046,8 @@ main_input(wint_t c)
case L'N':
if (!seek_track_tag(player.track))
return;
+ track_show_playlist = false;
+ update_tracks_vis();
seek_track(player.track);
pane_sel = track_pane;
break;