diff --git a/src/clock.cpp b/src/clock.cpp index 1350a0fd..eab64180 100644 --- a/src/clock.cpp +++ b/src/clock.cpp @@ -24,7 +24,6 @@ #ifdef ENABLE_CLOCK -#include "display.h" #include "global.h" #include "playlist.h" #include "settings.h" @@ -136,7 +135,7 @@ void Clock::Update() { w->GotoXY(2*j+2, i); } - if (Global::Config.clock_display_seconds || j < 18) + if (Config.clock_display_seconds || j < 18) *w << " "; } } diff --git a/src/clock.h b/src/clock.h index 177dc312..6129a340 100644 --- a/src/clock.h +++ b/src/clock.h @@ -40,6 +40,7 @@ class Clock : public Screen virtual std::string Title(); virtual void Update(); + virtual void Scroll() { } protected: static void Prepare(); diff --git a/src/display.cpp b/src/display.cpp index 1d0098be..0838dfba 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -23,7 +23,6 @@ #include "helpers.h" #include "playlist.h" -using Global::Config; using MPD::Song; using std::string; diff --git a/src/global.h b/src/global.h index 7f9c3335..030b0884 100644 --- a/src/global.h +++ b/src/global.h @@ -30,9 +30,6 @@ namespace Global { - extern ncmpcpp_config Config; - extern ncmpcpp_keys Key; - extern BasicScreen *myScreen; extern BasicScreen *myOldScreen; diff --git a/src/helpers.cpp b/src/helpers.cpp index 97711562..3ce227db 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -25,10 +25,10 @@ #include "global.h" #include "helpers.h" #include "playlist.h" +#include "status_checker.h" #include "tag_editor.h" using namespace MPD; -using Global::Config; using Global::Mpd; using Global::wFooter; using std::string; diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index d357baca..e6af1b00 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -60,9 +60,6 @@ using std::make_pair; using std::string; using std::vector; -ncmpcpp_config Global::Config; -ncmpcpp_keys Global::Key; - BasicScreen *Global::myScreen; BasicScreen *Global::myOldScreen; @@ -311,83 +308,25 @@ int main(int argc, char *argv[]) // key mapping beginning - if ( - Keypressed(input, Key.Up) -#ifdef ENABLE_CLOCK - && myScreen != myClock -# endif // ENABLE_CLOCK - ) + if (Keypressed(input, Key.Up)) { - if (!Config.fancy_scrolling - && (myScreen->Cmp() == myLibrary->Artists - || myScreen->Cmp() == myPlaylistEditor->List -# ifdef HAVE_TAGLIB_H - || myScreen->Cmp() == myTagEditor->LeftColumn -# endif // HAVE_TAGLIB_H - ) - ) - { - myWindow->Main()->SetTimeout(50); - while (Keypressed(input, Key.Up)) - { - myWindow->Main()->Scroll(wUp); - myWindow->Main()->Refresh(); - myWindow->Main()->ReadKey(input); - } - myWindow->Main()->SetTimeout(ncmpcpp_window_timeout); - } - else - myWindow->Main()->Scroll(wUp); + myScreen->Scroll(wUp, Key.Up); } - else if ( - Keypressed(input, Key.Down) -#ifdef ENABLE_CLOCK - && myScreen != myClock -# endif // ENABLE_CLOCK - ) + else if (Keypressed(input, Key.Down)) { - if (!Config.fancy_scrolling - && (myScreen->Cmp() == myLibrary->Artists - || myScreen->Cmp() == myPlaylistEditor->List -# ifdef HAVE_TAGLIB_H - || myScreen->Cmp() == myTagEditor->LeftColumn -# endif // HAVE_TAGLIB_H - ) - ) - { - myWindow->Main()->SetTimeout(50); - while (Keypressed(input, Key.Down)) - { - myWindow->Main()->Scroll(wDown); - myWindow->Main()->Refresh(); - myWindow->Main()->ReadKey(input); - } - myWindow->Main()->SetTimeout(ncmpcpp_window_timeout); - } - else - myWindow->Main()->Scroll(wDown); + myScreen->Scroll(wDown, Key.Down); } - else if ( - Keypressed(input, Key.PageUp) -#ifdef ENABLE_CLOCK - && myScreen != myClock -# endif // ENABLE_CLOCK - ) + else if (Keypressed(input, Key.PageUp)) { - myWindow->Main()->Scroll(wPageUp); + myScreen->Scroll(wPageUp, Key.PageUp); } - else if ( - Keypressed(input, Key.PageDown) -#ifdef ENABLE_CLOCK - && myScreen != myClock -# endif // ENABLE_CLOCK - ) + else if (Keypressed(input, Key.PageDown)) { - myWindow->Main()->Scroll(wPageDown); + myScreen->Scroll(wPageDown, Key.PageDown); } else if (Keypressed(input, Key.Home)) { - myWindow->Main()->Scroll(wHome); + myScreen->Scroll(wHome); } else if (Keypressed(input, Key.End)) { @@ -437,21 +376,7 @@ int main(int argc, char *argv[]) wFooter->MoveTo(0, footer_start_y); wFooter->Resize(COLS, wFooter->GetHeight()); -# ifdef HAVE_TAGLIB_H - if (myScreen == myLibrary) - { - myLibrary->Refresh(); - } - else if (myScreen == myTagEditor) - { - myTagEditor->Refresh(); - } - else -# endif // HAVE_TAGLIB_H - if (myScreen == myPlaylistEditor) - { - myPlaylistEditor->Refresh(); - } + myScreen->Refresh(); header_update_status = 1; PlayerState mpd_state = Mpd->GetState(); StatusChanges changes; diff --git a/src/screen.h b/src/screen.h index 74e52edd..1fec3e33 100644 --- a/src/screen.h +++ b/src/screen.h @@ -24,6 +24,8 @@ #include "window.h" #include "menu.h" #include "mpdpp.h" +#include "helpers.h" +#include "status_checker.h" class BasicScreen { @@ -41,6 +43,7 @@ class BasicScreen virtual void Update() { } virtual void Refresh() = 0; + virtual void Scroll(Where, const int * = 0) = 0; virtual void EnterPressed() { } virtual void SpacePressed() { } @@ -62,6 +65,7 @@ template class Screen : public BasicScreen WindowType *&Main(); virtual void Refresh(); + virtual void Scroll(Where where, const int *); protected: WindowType *w; @@ -83,5 +87,24 @@ template void Screen::Refresh() w->Display(); } +template void Screen::Scroll(Where where, const int *key) +{ + if (!Config.fancy_scrolling && key) + { + int in = key[0]; + w->SetTimeout(ncmpcpp_window_timeout/10); + while (Keypressed(in, key)) + { + TraceMpdStatus(); + w->Scroll(where); + w->Refresh(); + w->ReadKey(in); + } + w->SetTimeout(ncmpcpp_window_timeout); + } + else + w->Scroll(where); +} + #endif diff --git a/src/settings.cpp b/src/settings.cpp index d78d8ecb..b2ab85b6 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -30,6 +30,9 @@ using std::string; const string config_file = config_dir + "config"; const string keys_config_file = config_dir + "keys"; +ncmpcpp_config Config; +ncmpcpp_keys Key; + namespace { void GetKeys(string &line, int *key) diff --git a/src/settings.h b/src/settings.h index 5a69a686..74211ac7 100644 --- a/src/settings.h +++ b/src/settings.h @@ -162,6 +162,9 @@ struct ncmpcpp_config int lyrics_db; }; +extern ncmpcpp_config Config; +extern ncmpcpp_keys Key; + void CreateConfigDir(); void DefaultKeys(ncmpcpp_keys &); void DefaultConfiguration(ncmpcpp_config &);