use one global timer instead of several local ones
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
#ifdef ENABLE_CLOCK
|
||||
|
||||
#include <cstring>
|
||||
#include <sys/time.h>
|
||||
|
||||
#include "global.h"
|
||||
#include "playlist.h"
|
||||
@@ -105,13 +106,12 @@ void Clock::Update()
|
||||
if (Width > size_t(COLS) || Height > MainHeight)
|
||||
myPlaylist->SwitchTo();
|
||||
|
||||
static time_t now = 0, past;
|
||||
time(&past);
|
||||
if (past <= now)
|
||||
static timeval past = { 0, 0 };
|
||||
if (Timer.tv_sec <= past.tv_sec)
|
||||
return;
|
||||
time(&now);
|
||||
gettimeofday(&past, 0);
|
||||
|
||||
tm *time = localtime(&now);
|
||||
tm *time = localtime(&past.tv_sec);
|
||||
|
||||
mask = 0;
|
||||
Set(time->tm_sec % 10, 0);
|
||||
|
||||
@@ -49,6 +49,8 @@ namespace Global
|
||||
extern bool RedrawStatusbar;
|
||||
|
||||
extern std::string VolumeState;
|
||||
|
||||
extern timeval Timer;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -277,7 +277,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
std::string screen_title;
|
||||
|
||||
timeval now, past;
|
||||
timeval past = { 0, 0 };
|
||||
// local variables end
|
||||
|
||||
# ifndef WIN32
|
||||
@@ -285,8 +285,6 @@ int main(int argc, char *argv[])
|
||||
signal(SIGWINCH, sighandler);
|
||||
# endif // !WIN32
|
||||
|
||||
gettimeofday(&now, 0);
|
||||
|
||||
MEVENT mouse_event;
|
||||
mouseinterval(0);
|
||||
if (Config.mouse_support)
|
||||
@@ -328,13 +326,12 @@ int main(int argc, char *argv[])
|
||||
MessagesAllowed = 1;
|
||||
|
||||
// header stuff
|
||||
gettimeofday(&past, 0);
|
||||
if (((past.tv_sec == now.tv_sec && past.tv_usec >= now.tv_usec+500000) || past.tv_sec > now.tv_sec)
|
||||
if (((Timer.tv_sec == past.tv_sec && Timer.tv_usec >= past.tv_usec+500000) || Timer.tv_sec > past.tv_sec)
|
||||
&& (myScreen == myPlaylist || myScreen == myBrowser || myScreen == myLyrics)
|
||||
)
|
||||
{
|
||||
RedrawHeader = 1;
|
||||
gettimeofday(&now, 0);
|
||||
gettimeofday(&past, 0);
|
||||
}
|
||||
if (Config.header_visibility && RedrawHeader)
|
||||
{
|
||||
|
||||
@@ -40,11 +40,13 @@
|
||||
using namespace Global;
|
||||
using namespace MPD;
|
||||
|
||||
std::string Global::VolumeState;
|
||||
|
||||
bool Global::UpdateStatusImmediately = 0;
|
||||
bool Global::RedrawStatusbar = 0;
|
||||
|
||||
std::string Global::VolumeState;
|
||||
|
||||
timeval Global::Timer;
|
||||
|
||||
namespace
|
||||
{
|
||||
time_t time_of_statusbar_lock;
|
||||
@@ -122,10 +124,10 @@ void UnlockStatusbar()
|
||||
|
||||
void TraceMpdStatus()
|
||||
{
|
||||
static timeval past, now;
|
||||
static timeval past = { 0, 0 };
|
||||
|
||||
gettimeofday(&now, 0);
|
||||
if (Mpd.Connected() && (Mpd.SupportsIdle() || now.tv_sec > past.tv_sec || UpdateStatusImmediately))
|
||||
gettimeofday(&Global::Timer, 0);
|
||||
if (Mpd.Connected() && (Mpd.SupportsIdle() || Timer.tv_sec > past.tv_sec || UpdateStatusImmediately))
|
||||
{
|
||||
Mpd.UpdateStatus();
|
||||
BlockItemListUpdate = 0;
|
||||
@@ -135,7 +137,7 @@ void TraceMpdStatus()
|
||||
}
|
||||
|
||||
if (myScreen->ActiveWindow() == myPlaylist->Items
|
||||
&& now.tv_sec == myPlaylist->Timer()+Config.playlist_disable_highlight_delay
|
||||
&& Timer.tv_sec == myPlaylist->Timer()+Config.playlist_disable_highlight_delay
|
||||
&& myPlaylist->Items->isHighlighted()
|
||||
&& Config.playlist_disable_highlight_delay)
|
||||
{
|
||||
@@ -145,7 +147,7 @@ void TraceMpdStatus()
|
||||
|
||||
if (lock_statusbar_delay > 0)
|
||||
{
|
||||
if (now.tv_sec >= time_of_statusbar_lock+lock_statusbar_delay)
|
||||
if (Timer.tv_sec >= time_of_statusbar_lock+lock_statusbar_delay)
|
||||
{
|
||||
lock_statusbar_delay = -1;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user