diff --git a/src/actions.cpp b/src/actions.cpp index 6f1f223a..84a5a138 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -127,7 +127,6 @@ void Action::SetResizeFlags() void Action::ResizeScreen() { using Global::MainHeight; - using Global::RedrawHeader; using Global::RedrawStatusbar; using Global::wHeader; using Global::wFooter; @@ -152,7 +151,6 @@ void Action::ResizeScreen() } # endif - RedrawHeader = true; MainHeight = LINES-(Config.new_design ? 7 : 4); ValidateScreenSize(); @@ -194,6 +192,7 @@ void Action::ResizeScreen() DesignChanged = 0; ShowMessage("User interface: %s", Config.new_design ? "Alternative" : "Classic"); } + DrawHeader(); wFooter->refresh(); refresh(); } @@ -737,11 +736,10 @@ void MasterScreen::Run() { using Global::myInactiveScreen; using Global::myLockedScreen; - using Global::RedrawHeader; myInactiveScreen = myScreen; myScreen = myLockedScreen; - RedrawHeader = true; + DrawHeader(); } bool SlaveScreen::canBeRun() const @@ -759,11 +757,10 @@ void SlaveScreen::Run() { using Global::myInactiveScreen; using Global::myLockedScreen; - using Global::RedrawHeader; myScreen = myInactiveScreen; myInactiveScreen = myLockedScreen; - RedrawHeader = true; + DrawHeader(); } void VolumeUp::Run() @@ -1229,15 +1226,13 @@ bool JumpToPlayingSong::canBeRun() const void JumpToPlayingSong::Run() { - using Global::RedrawHeader; - if (myScreen == myPlaylist) myPlaylist->Items->highlight(myPlaylist->NowPlaying); else if (myScreen == myBrowser) { const MPD::Song *s = myPlaylist->NowPlayingSong(); myBrowser->LocateSong(*s); - RedrawHeader = true; + DrawHeader(); } else if (myScreen == myLibrary) { @@ -1882,7 +1877,6 @@ bool ApplyFilter::canBeRun() const void ApplyFilter::Run() { - using Global::RedrawHeader; using Global::wFooter; Filterable *f = dynamic_cast(myScreen); @@ -1908,7 +1902,7 @@ void ApplyFilter::Run() { myPlaylist->EnableHighlighting(); Playlist::ReloadTotalLength = true; - RedrawHeader = true; + DrawHeader(); } ListsChangeFinisher(); } diff --git a/src/browser.cpp b/src/browser.cpp index f84b8186..ab3eb38e 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -40,7 +40,6 @@ using namespace std::placeholders; using Global::MainHeight; using Global::MainStartY; using Global::myScreen; -using Global::RedrawHeader; using MPD::itDirectory; using MPD::itSong; @@ -116,7 +115,7 @@ void Browser::SwitchTo() if (myScreen != this && myScreen->isTabbable()) Global::myPrevScreen = myScreen; myScreen = this; - RedrawHeader = true; + DrawHeader(); } std::basic_string Browser::Title() @@ -146,7 +145,7 @@ void Browser::EnterPressed() } else GetDirectory(item.name, itsBrowsedDir); - RedrawHeader = true; + DrawHeader(); break; } case itSong: @@ -236,7 +235,7 @@ void Browser::MouseButtonPressed(MEVENT me) if (me.bstate & BUTTON1_PRESSED) { GetDirectory(w->current().value().name); - RedrawHeader = true; + DrawHeader(); } else { @@ -574,7 +573,7 @@ void Browser::ChangeBrowseMode() itsBrowsedDir.resize(itsBrowsedDir.length()-1); w->reset(); GetDirectory(itsBrowsedDir); - RedrawHeader = true; + DrawHeader(); } bool Browser::deleteItem(const MPD::Item &item) diff --git a/src/clock.cpp b/src/clock.cpp index 866d1c19..377a2925 100644 --- a/src/clock.cpp +++ b/src/clock.cpp @@ -102,7 +102,7 @@ void Clock::SwitchTo() if (myScreen != this && myScreen->isTabbable()) Global::myPrevScreen = myScreen; myScreen = this; - Global::RedrawHeader = true; + DrawHeader(); Prepare(); itsPane->refresh(); // clearing screen apparently fixes the problem with last digits being misrendered diff --git a/src/global.cpp b/src/global.cpp index 169b752a..ef2481a4 100644 --- a/src/global.cpp +++ b/src/global.cpp @@ -35,7 +35,6 @@ size_t Global::MainHeight; bool Global::ShowMessages = false; bool Global::SeekingInProgress = false; -bool Global::RedrawHeader = true; bool Global::RedrawStatusbar = true; std::string Global::VolumeState; diff --git a/src/global.h b/src/global.h index 37af2246..834a6208 100644 --- a/src/global.h +++ b/src/global.h @@ -61,9 +61,6 @@ namespace Global // indicates whether seeking action in currently in progress extern bool SeekingInProgress; - // indicates whether header should be immediately repainted - extern bool RedrawHeader; - // indicates whether statusbar should be immediately repainted extern bool RedrawStatusbar; diff --git a/src/help.cpp b/src/help.cpp index 0f47150e..65f9035f 100644 --- a/src/help.cpp +++ b/src/help.cpp @@ -24,6 +24,7 @@ #include "global.h" #include "help.h" #include "settings.h" +#include "status.h" using Global::MainHeight; using Global::MainStartY; @@ -129,8 +130,7 @@ void Help::SwitchTo() if (myScreen != this && myScreen->isTabbable()) Global::myPrevScreen = myScreen; myScreen = this; - Global::RedrawHeader = true; - + DrawHeader(); } std::basic_string Help::Title() diff --git a/src/lastfm.cpp b/src/lastfm.cpp index 9fa775ec..be62c313 100644 --- a/src/lastfm.cpp +++ b/src/lastfm.cpp @@ -105,8 +105,7 @@ void Lastfm::SwitchTo() myOldScreen = myScreen; myScreen = this; - - Global::RedrawHeader = true; + DrawHeader(); } void Lastfm::Load() diff --git a/src/lyrics.cpp b/src/lyrics.cpp index 461d4ba6..90177ddf 100644 --- a/src/lyrics.cpp +++ b/src/lyrics.cpp @@ -80,7 +80,7 @@ void Lyrics::Update() const MPD::Song *s = myPlaylist->NowPlayingSong(); if (s && !s->getArtist().empty() && !s->getTitle().empty()) { - Global::RedrawHeader = true; + DrawHeader(); itsScrollBegin = 0; itsSong = *s; Load(); @@ -129,7 +129,7 @@ void Lyrics::SwitchTo() itsSong = *s; Load(); - Global::RedrawHeader = true; + DrawHeader(); } else { diff --git a/src/media_library.cpp b/src/media_library.cpp index 6624be91..ca2eaeae 100644 --- a/src/media_library.cpp +++ b/src/media_library.cpp @@ -205,7 +205,7 @@ void MediaLibrary::SwitchTo() if (myScreen != this && myScreen->isTabbable()) Global::myPrevScreen = myScreen; myScreen = this; - Global::RedrawHeader = true; + DrawHeader(); markSongsInPlaylist(songsProxyList()); Refresh(); } diff --git a/src/ncmpcpp.cpp b/src/ncmpcpp.cpp index 4fd41e98..145cf416 100644 --- a/src/ncmpcpp.cpp +++ b/src/ncmpcpp.cpp @@ -84,7 +84,6 @@ int main(int argc, char **argv) using Global::wHeader; using Global::wFooter; - using Global::RedrawHeader; using Global::ShowMessages; using Global::VolumeState; using Global::Timer; @@ -237,32 +236,10 @@ int main(int argc, char **argv) && (myScreen == myPlaylist || myScreen == myBrowser || myScreen == myLyrics) ) { - RedrawHeader = true; + DrawHeader(); gettimeofday(&past, 0); } - if (Config.header_visibility && RedrawHeader) - { - if (Config.new_design) - { - std::basic_string title = myScreen->Title(); - *wHeader << NC::XY(0, 3) << wclrtoeol; - *wHeader << NC::fmtBold << Config.alternative_ui_separator_color; - mvwhline(wHeader->raw(), 2, 0, 0, COLS); - mvwhline(wHeader->raw(), 4, 0, 0, COLS); - *wHeader << NC::XY((COLS-NC::Window::length(title))/2, 3); - *wHeader << Config.header_color << title << NC::clEnd; - *wHeader << NC::clEnd << NC::fmtBoldEnd; - } - else - { - *wHeader << NC::XY(0, 0) << wclrtoeol << NC::fmtBold << myScreen->Title() << NC::fmtBoldEnd; - *wHeader << Config.volume_color; - *wHeader << NC::XY(wHeader->getWidth()-VolumeState.length(), 0) << VolumeState; - *wHeader << NC::clEnd; - } - wHeader->refresh(); - RedrawHeader = false; - } + // header stuff end if (input != Key::noOp) diff --git a/src/outputs.cpp b/src/outputs.cpp index eb5a3652..f25579e9 100644 --- a/src/outputs.cpp +++ b/src/outputs.cpp @@ -65,8 +65,7 @@ void Outputs::SwitchTo() Global::myPrevScreen = myScreen; myScreen = this; w->Window::clear(); - - Global::RedrawHeader = true; + DrawHeader(); } void Outputs::Resize() diff --git a/src/playlist.cpp b/src/playlist.cpp index 84330095..e0bf9c8f 100644 --- a/src/playlist.cpp +++ b/src/playlist.cpp @@ -121,7 +121,7 @@ void Playlist::SwitchTo() EnableHighlighting(); if (w != Items) // even if sorting window is active, background has to be refreshed anyway Items->display(); - Global::RedrawHeader = true; + DrawHeader(); } void Playlist::Resize() diff --git a/src/playlist_editor.cpp b/src/playlist_editor.cpp index f3f69264..7e519a0e 100644 --- a/src/playlist_editor.cpp +++ b/src/playlist_editor.cpp @@ -132,7 +132,7 @@ void PlaylistEditor::SwitchTo() if (myScreen != this && myScreen->isTabbable()) Global::myPrevScreen = myScreen; myScreen = this; - Global::RedrawHeader = true; + DrawHeader(); markSongsInPlaylist(contentProxyList()); Refresh(); } diff --git a/src/search_engine.cpp b/src/search_engine.cpp index 4ce6df7c..2a060b17 100644 --- a/src/search_engine.cpp +++ b/src/search_engine.cpp @@ -148,8 +148,7 @@ void SearchEngine::SwitchTo() if (myScreen != this && myScreen->isTabbable()) Global::myPrevScreen = myScreen; myScreen = this; - Global::RedrawHeader = true; - + DrawHeader(); markSongsInPlaylist(getProxySongList()); } diff --git a/src/song_info.cpp b/src/song_info.cpp index fa11e69a..f5dc0ac5 100644 --- a/src/song_info.cpp +++ b/src/song_info.cpp @@ -93,8 +93,7 @@ void SongInfo::SwitchTo() myOldScreen = myScreen; myScreen = this; - - Global::RedrawHeader = true; + DrawHeader(); w->clear(); w->reset(); diff --git a/src/status.cpp b/src/status.cpp index 1274a61e..26880fe6 100644 --- a/src/status.cpp +++ b/src/status.cpp @@ -643,6 +643,31 @@ void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges changed, void *) ApplyToVisibleWindows(&BasicScreen::RefreshWindow); } +void DrawHeader() +{ + if (!Config.header_visibility) + return; + if (Config.new_design) + { + std::basic_string title = myScreen->Title(); + *wHeader << NC::XY(0, 3) << wclrtoeol; + *wHeader << NC::fmtBold << Config.alternative_ui_separator_color; + mvwhline(wHeader->raw(), 2, 0, 0, COLS); + mvwhline(wHeader->raw(), 4, 0, 0, COLS); + *wHeader << NC::XY((COLS-NC::Window::length(title))/2, 3); + *wHeader << Config.header_color << title << NC::clEnd; + *wHeader << NC::clEnd << NC::fmtBoldEnd; + } + else + { + *wHeader << NC::XY(0, 0) << wclrtoeol << NC::fmtBold << myScreen->Title() << NC::fmtBoldEnd; + *wHeader << Config.volume_color; + *wHeader << NC::XY(wHeader->getWidth()-VolumeState.length(), 0) << VolumeState; + *wHeader << NC::clEnd; + } + wHeader->refresh(); +} + NC::Window &Statusbar() { *wFooter << NC::XY(0, Config.statusbar_visibility) << wclrtoeol; diff --git a/src/status.h b/src/status.h index 428b74fa..f3af6970 100644 --- a/src/status.h +++ b/src/status.h @@ -40,6 +40,8 @@ void TraceMpdStatus(); void NcmpcppStatusChanged(MPD::Connection *, MPD::StatusChanges, void *); void NcmpcppErrorCallback(MPD::Connection *, int, const char *, void *); +void DrawHeader(); + NC::Window &Statusbar(); void DrawProgressbar(unsigned elapsed, unsigned time); void ShowMessage(const char *, ...) GNUC_PRINTF(1, 2); diff --git a/src/tag_editor.cpp b/src/tag_editor.cpp index 0e488aea..c8bdf6ab 100644 --- a/src/tag_editor.cpp +++ b/src/tag_editor.cpp @@ -225,7 +225,7 @@ void TagEditor::SwitchTo() if (myScreen != this && myScreen->isTabbable()) Global::myPrevScreen = myScreen; myScreen = this; - Global::RedrawHeader = true; + DrawHeader(); Refresh(); } diff --git a/src/tiny_tag_editor.cpp b/src/tiny_tag_editor.cpp index e90af775..d7fbb6e0 100644 --- a/src/tiny_tag_editor.cpp +++ b/src/tiny_tag_editor.cpp @@ -82,7 +82,7 @@ void TinyTagEditor::SwitchTo() myOldScreen = myScreen; myScreen = this; - Global::RedrawHeader = true; + DrawHeader(); } else { diff --git a/src/visualizer.cpp b/src/visualizer.cpp index 802a3240..a3e9844e 100644 --- a/src/visualizer.cpp +++ b/src/visualizer.cpp @@ -81,6 +81,7 @@ void Visualizer::SwitchTo() if (myScreen != this && myScreen->isTabbable()) Global::myPrevScreen = myScreen; myScreen = this; + DrawHeader(); w->clear(); SetFD(); @@ -90,7 +91,6 @@ void Visualizer::SwitchTo() if (itsFifo >= 0) Global::wFooter->setTimeout(WindowTimeout); - Global::RedrawHeader = true; } void Visualizer::Resize()