actions: allow action chains to be used for seeking
This commit is contained in:
1
NEWS
1
NEWS
@@ -1,4 +1,5 @@
|
|||||||
ncmpcpp-0.7.5 (????-??-??)
|
ncmpcpp-0.7.5 (????-??-??)
|
||||||
|
* Action chains can be now used for seeking.
|
||||||
|
|
||||||
ncmpcpp 0.7.4 (2016-04-17)
|
ncmpcpp 0.7.4 (2016-04-17)
|
||||||
* Fetching lyrics from lyricwiki.org was fixed.
|
* Fetching lyrics from lyricwiki.org was fixed.
|
||||||
|
|||||||
@@ -2830,9 +2830,34 @@ void seek()
|
|||||||
int old_timeout = wFooter->getTimeout();
|
int old_timeout = wFooter->getTimeout();
|
||||||
wFooter->setTimeout(BaseScreen::defaultWindowTimeout);
|
wFooter->setTimeout(BaseScreen::defaultWindowTimeout);
|
||||||
|
|
||||||
auto seekForward = &Actions::get(Actions::Type::SeekForward);
|
// Accept single action of a given type or action chain for which all actions
|
||||||
auto seekBackward = &Actions::get(Actions::Type::SeekBackward);
|
// can be run and one of them is of the given type. This will still not work
|
||||||
|
// in some contrived cases, but allows for more flexibility than accepting
|
||||||
|
// single actions only.
|
||||||
|
auto hasRunnableAction = [](BindingsConfiguration::BindingIteratorPair &bindings, Actions::Type type) {
|
||||||
|
bool success = false;
|
||||||
|
for (auto binding = bindings.first; binding != bindings.second; ++binding)
|
||||||
|
{
|
||||||
|
auto &actions = binding->actions();
|
||||||
|
for (const auto &action : actions)
|
||||||
|
{
|
||||||
|
if (action->canBeRun())
|
||||||
|
{
|
||||||
|
if (action->type() == type)
|
||||||
|
success = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
success = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (success)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
};
|
||||||
|
|
||||||
SeekingInProgress = true;
|
SeekingInProgress = true;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
@@ -2843,16 +2868,14 @@ void seek()
|
|||||||
: Config.seek_time;
|
: Config.seek_time;
|
||||||
|
|
||||||
NC::Key::Type input = readKey(*wFooter);
|
NC::Key::Type input = readKey(*wFooter);
|
||||||
|
|
||||||
auto k = Bindings.get(input);
|
auto k = Bindings.get(input);
|
||||||
if (k.first == k.second || !k.first->isSingle()) // no single action?
|
if (hasRunnableAction(k, Actions::Type::SeekForward))
|
||||||
break;
|
|
||||||
auto a = k.first->action();
|
|
||||||
if (a == seekForward)
|
|
||||||
{
|
{
|
||||||
if (songpos < Status::State::totalTime())
|
if (songpos < Status::State::totalTime())
|
||||||
songpos = std::min(songpos + howmuch, Status::State::totalTime());
|
songpos = std::min(songpos + howmuch, Status::State::totalTime());
|
||||||
}
|
}
|
||||||
else if (a == seekBackward)
|
else if (hasRunnableAction(k, Actions::Type::SeekBackward))
|
||||||
{
|
{
|
||||||
if (songpos > 0)
|
if (songpos > 0)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user