refresh main screen only if necessary

This commit is contained in:
Andrzej Rybczak
2009-09-17 00:59:30 +00:00
parent ff84ba8d9d
commit 8109d26daf
5 changed files with 35 additions and 34 deletions

View File

@@ -106,9 +106,13 @@ void Clock::Update()
if (Width > size_t(COLS) || Height > MainHeight) if (Width > size_t(COLS) || Height > MainHeight)
myPlaylist->SwitchTo(); myPlaylist->SwitchTo();
time_t rawtime; static time_t now = 0, past;
time(&rawtime); time(&past);
tm *time = localtime(&rawtime); if (past <= now)
return;
time(&now);
tm *time = localtime(&now);
mask = 0; mask = 0;
Set(time->tm_sec % 10, 0); Set(time->tm_sec % 10, 0);
@@ -160,6 +164,7 @@ void Clock::Update()
} }
} }
} }
w->Refresh();
} }
void Clock::Prepare() void Clock::Prepare()

View File

@@ -466,6 +466,10 @@ namespace NCurses
/// ///
void HighlightColor(Color color) { itsHighlightColor = color; } void HighlightColor(Color color) { itsHighlightColor = color; }
/// @return state of highlighting
///
bool isHighlighted() { return highlightEnabled; }
/// Turns on/off highlighting /// Turns on/off highlighting
/// @param state state of hihglighting /// @param state state of hihglighting
/// ///

View File

@@ -166,7 +166,7 @@ int main(int argc, char *argv[])
Mpd.SetErrorHandler(NcmpcppErrorCallback, 0); Mpd.SetErrorHandler(NcmpcppErrorCallback, 0);
// local variables // local variables
int input; int input = 0;
bool main_exit = 0; bool main_exit = 0;
bool design_changed = 0; bool design_changed = 0;
@@ -285,7 +285,8 @@ int main(int argc, char *argv[])
// header stuff end // header stuff end
myScreen->Update(); myScreen->Update();
myScreen->RefreshWindow(); if (input != ERR)
myScreen->RefreshWindow();
myScreen->ReadKey(input); myScreen->ReadKey(input);
if (input == ERR) if (input == ERR)

View File

@@ -316,8 +316,6 @@ void Playlist::FixPositions(size_t beginning)
void Playlist::EnableHighlighting() void Playlist::EnableHighlighting()
{ {
Items->Highlighting(1); Items->Highlighting(1);
if (w == Items)
Items->Refresh();
UpdateTimer(); UpdateTimer();
} }

View File

@@ -70,8 +70,10 @@ void StatusbarApplyFilterImmediately(const std::wstring &ws)
{ {
static std::wstring cmp; static std::wstring cmp;
if (cmp != ws) if (cmp != ws)
{
myScreen->ApplyFilter(ToString((cmp = ws))); myScreen->ApplyFilter(ToString((cmp = ws)));
myScreen->RefreshWindow(); myScreen->RefreshWindow();
}
TraceMpdStatus(); TraceMpdStatus();
} }
@@ -113,10 +115,7 @@ void TraceMpdStatus()
static timeval past, now; static timeval past, now;
gettimeofday(&now, 0); gettimeofday(&now, 0);
if ((Mpd.Connected() if ((Mpd.Connected() && now.tv_sec > past.tv_sec) || UpdateStatusImmediately)
&& (/*(now.tv_sec == past.tv_sec && now.tv_usec >= past.tv_usec+500000) || */now.tv_sec > past.tv_sec))
|| UpdateStatusImmediately
)
{ {
Mpd.UpdateStatus(); Mpd.UpdateStatus();
BlockItemListUpdate = 0; BlockItemListUpdate = 0;
@@ -124,10 +123,15 @@ void TraceMpdStatus()
UpdateStatusImmediately = 0; UpdateStatusImmediately = 0;
gettimeofday(&past, 0); gettimeofday(&past, 0);
} }
wFooter->Refresh();
if (myScreen == myPlaylist && now.tv_sec == myPlaylist->Timer()+Config.playlist_disable_highlight_delay) if (myScreen->ActiveWindow() == myPlaylist->Items
myPlaylist->Items->Highlighting(!Config.playlist_disable_highlight_delay); && now.tv_sec == myPlaylist->Timer()+Config.playlist_disable_highlight_delay
&& myPlaylist->Items->isHighlighted()
&& Config.playlist_disable_highlight_delay)
{
myPlaylist->Items->Highlighting(0);
myPlaylist->Items->Refresh();
}
if (lock_statusbar_delay > 0) if (lock_statusbar_delay > 0)
{ {
@@ -234,13 +238,6 @@ void NcmpcppStatusChanged(Connection *, StatusChanges changed, void *)
myPlaylist->Items->at(pos).CopyPtr(0); myPlaylist->Items->at(pos).CopyPtr(0);
(*it)->NullMe(); (*it)->NullMe();
} }
if (myScreen == myPlaylist)
{
if (!playlist_length || myPlaylist->Items->Size() < myPlaylist->Items->GetHeight())
myPlaylist->Items->Window::Clear();
myPlaylist->Items->Refresh();
}
if (was_filtered) if (was_filtered)
{ {
myPlaylist->ApplyFilter(myPlaylist->Items->GetFilter()); myPlaylist->ApplyFilter(myPlaylist->Items->GetFilter());
@@ -253,9 +250,6 @@ void NcmpcppStatusChanged(Connection *, StatusChanges changed, void *)
Playlist::ReloadTotalLength = 1; Playlist::ReloadTotalLength = 1;
Playlist::ReloadRemaining = 1; Playlist::ReloadRemaining = 1;
if (myScreen == myPlaylist)
RedrawHeader = 1;
if (myPlaylist->Items->Empty()) if (myPlaylist->Items->Empty())
{ {
myPlaylist->Items->Reset(); myPlaylist->Items->Reset();
@@ -308,8 +302,7 @@ void NcmpcppStatusChanged(Connection *, StatusChanges changed, void *)
} }
if (changed.PlayerState) if (changed.PlayerState)
{ {
PlayerState mpd_state = Mpd.GetState(); switch (Mpd.GetState())
switch (mpd_state)
{ {
case psUnknown: case psUnknown:
{ {
@@ -351,8 +344,11 @@ void NcmpcppStatusChanged(Connection *, StatusChanges changed, void *)
} }
if (Config.new_design) if (Config.new_design)
{ {
*wHeader << XY(0, 1) << fmtBold << player_state << fmtBoldEnd; if (!myPlaylist->isPlaying())
wHeader->Refresh(); {
*wHeader << XY(0, 1) << fmtBold << player_state << fmtBoldEnd;
wHeader->Refresh();
}
} }
else if (!block_statusbar_update && Config.statusbar_visibility) else if (!block_statusbar_update && Config.statusbar_visibility)
{ {
@@ -387,9 +383,6 @@ void NcmpcppStatusChanged(Connection *, StatusChanges changed, void *)
playing_song_scroll_begin = 0; playing_song_scroll_begin = 0;
first_line_scroll_begin = 0; first_line_scroll_begin = 0;
second_line_scroll_begin = 0; second_line_scroll_begin = 0;
if (Mpd.GetState() == psPlay)
changed.ElapsedTime = 1;
} }
static time_t now, past = 0; static time_t now, past = 0;
time(&now); time(&now);
@@ -624,11 +617,11 @@ void NcmpcppStatusChanged(Connection *, StatusChanges changed, void *)
*wHeader << clEnd; *wHeader << clEnd;
wHeader->Refresh(); wHeader->Refresh();
} }
if (myScreen->ActiveWindow() == myPlaylist->Items)
myPlaylist->Items->Refresh();
*wFooter << fmtBoldEnd; *wFooter << fmtBoldEnd;
wFooter->GotoXY(sx, sy); wFooter->GotoXY(sx, sy);
wFooter->Refresh(); wFooter->Refresh();
if (changed.Playlist || changed.Database || changed.PlayerState || changed.SongID)
myScreen->RefreshWindow();
} }
Window &Statusbar() Window &Statusbar()