From 05bf53d0abda580039445e1e69fe066a3446a4fd Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Mon, 13 Feb 2017 10:45:41 +0100 Subject: [PATCH] Seek immediately after invoking appropriate action once --- NEWS | 1 + src/actions.cpp | 36 +++++++++++++++++++++--------------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/NEWS b/NEWS index 19154e0..9faa854 100644 --- a/NEWS +++ b/NEWS @@ -24,6 +24,7 @@ ncmpcpp-0.8 (????-??-??) * Added test that checks if lyrics fetchers work (available via command line parameter --test-lyrics-fetchers). * Fixed fetching lyrics from justsomelyrics.com. * Added support for fetching lyrics from jah-lyrics.com and plyrics.com. +* Seek immediately after invoking appropriate action once. ncmpcpp-0.7.7 (2016-10-31) * Fixed compilation on 32bit platforms. diff --git a/src/actions.cpp b/src/actions.cpp index e66b9a6..71329f0 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -84,7 +84,7 @@ bool scrollTagCanBeRun(NC::List *&list, const SongList *&songs); void scrollTagUpRun(NC::List *list, const SongList *songs, MPD::Song::GetFunction get); void scrollTagDownRun(NC::List *list, const SongList *songs, MPD::Song::GetFunction get); -void seek(); +void seek(SearchDirection sd); void findItem(const SearchDirection direction); void listsChangeFinisher(); @@ -1033,7 +1033,7 @@ bool SeekForward::canBeRun() void SeekForward::run() { - seek(); + seek(SearchDirection::Forward); } bool SeekBackward::canBeRun() @@ -1043,7 +1043,7 @@ bool SeekBackward::canBeRun() void SeekBackward::run() { - seek(); + seek(SearchDirection::Backward); } bool ToggleDisplayMode::canBeRun() @@ -2876,7 +2876,7 @@ void scrollTagDownRun(NC::List *list, const SongList *songs, MPD::Song::GetFunct } } -void seek() +void seek(SearchDirection sd) { using Global::wHeader; using Global::wFooter; @@ -2894,7 +2894,7 @@ void seek() unsigned songpos = Status::State::elapsedTime(); auto t = Timer; - + int old_timeout = wFooter->getTimeout(); wFooter->setTimeout(BaseScreen::defaultWindowTimeout); @@ -2938,14 +2938,9 @@ void seek() NC::Key::Type input = readKey(*wFooter); - auto k = Bindings.get(input); - if (hasRunnableAction(k, Actions::Type::SeekForward)) - { - if (songpos < Status::State::totalTime()) - songpos = std::min(songpos + howmuch, Status::State::totalTime()); - } - else if (hasRunnableAction(k, Actions::Type::SeekBackward)) + switch (sd) { + case SearchDirection::Backward: if (songpos > 0) { if (songpos < howmuch) @@ -2953,10 +2948,13 @@ void seek() else songpos -= howmuch; } - } - else break; - + case SearchDirection::Forward: + if (songpos < Status::State::totalTime()) + songpos = std::min(songpos + howmuch, Status::State::totalTime()); + break; + }; + std::string tracklength; // FIXME: merge this with the code in status.cpp switch (Config.design) @@ -2998,6 +2996,14 @@ void seek() } Progressbar::draw(songpos, Status::State::totalTime()); wFooter->refresh(); + + auto k = Bindings.get(input); + if (hasRunnableAction(k, Actions::Type::SeekBackward)) + sd = SearchDirection::Backward; + else if (hasRunnableAction(k, Actions::Type::SeekForward)) + sd = SearchDirection::Forward; + else + break; } SeekingInProgress = false; Mpd.Seek(Status::State::currentSongPosition(), songpos); -- 2.11.4.GIT