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