From 1c5fb8b22d77a022ef026741eb3d5eb90ab60dad Mon Sep 17 00:00:00 2001 From: Matt Low Date: Wed, 16 Oct 2019 22:29:05 +0400 Subject: [PATCH] Only update scroll position on successful status update. Set scroll_index to 0 when not playing or paused. --- mpd_control.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mpd_control.c b/mpd_control.c index b5a6099..c089a19 100644 --- a/mpd_control.c +++ b/mpd_control.c @@ -88,10 +88,11 @@ print_status(struct mpd_connection *conn, struct worker_meta *meta) play_icon = ""; break; default: + meta->scroll_index = 0; printf("\n"); mpd_status_free(status); fflush(stdout); - return 0; + return 1; } const bool repeat = mpd_status_get_repeat(status); @@ -161,7 +162,6 @@ print_status(struct mpd_connection *conn, struct worker_meta *meta) &meta->scroll_index, meta->scroll_length); } else { // Else we'll just print it out normally and reset the scroll index - meta->scroll_index = 0; sprintf(label, "%s - %s", artist, title); } @@ -185,9 +185,10 @@ status_loop(void* worker_meta) handle_error(conn, true); long long start = current_timestamp(); - print_status(conn, meta); - meta->scroll_index++; + if (print_status(conn, meta) == 0) { + meta->scroll_index++; + } usleep((meta->update_interval - (current_timestamp() - start)) * 1000); }