detect minute-based strftime-formats (again)

the lag / skipping of the clock was not caused by faulty timer code
on fluxbox's side but by the behavior and inner workings of time().
since this is fixed now (913244789f) we can now rollback ec7fe513c8
and detect strftime-formats which need intervals of seconds or minutes.

minor: the small change to FbTk::Timer::setTimeout() reduces one
start() / stop() cycle for a running timer.
This commit is contained in:
Mathias Gumz 2014-05-12 12:17:00 +02:00
parent 913244789f
commit 948e63eb60
3 changed files with 14 additions and 6 deletions

View file

@ -52,10 +52,19 @@ const char SWITCHES_12_24H[] = "lIrkHT";
const char SWITCHES_24_12H[] = "kHTlIr"; const char SWITCHES_24_12H[] = "kHTlIr";
const char SWITCH_AM_PM[] = "pP"; const char SWITCH_AM_PM[] = "pP";
uint64_t calcNextTimeout() { int showSeconds(const std::string& fmt) {
return FbTk::StringUtil::findCharFromAlphabetAfterTrigger(
fmt, '%', SWITCHES_SECONDS, sizeof(SWITCHES_SECONDS), 0) != std::string::npos;
}
uint64_t calcNextTimeout(const std::string& fmt) {
uint64_t now = FbTk::FbTime::system(); uint64_t now = FbTk::FbTime::system();
uint64_t unit = FbTk::FbTime::IN_SECONDS; uint64_t unit = FbTk::FbTime::IN_SECONDS;
if (!showSeconds(fmt)) { // microseconds till next full minute
unit *= 60L;
}
return FbTk::FbTime::remainingNext(now, unit); return FbTk::FbTime::remainingNext(now, unit);
} }
@ -289,8 +298,7 @@ void ClockTool::updateTime() {
} }
restart_timer: restart_timer:
m_timer.setTimeout(calcNextTimeout()); m_timer.setTimeout(calcNextTimeout(*m_timeformat), true);
m_timer.start();
} }
// Just change things that affect the size // Just change things that affect the size

View file

@ -91,7 +91,7 @@ Timer::~Timer() {
} }
void Timer::setTimeout(uint64_t timeout) { void Timer::setTimeout(uint64_t timeout, bool force_start) {
bool was_timing = isTiming(); bool was_timing = isTiming();
if (was_timing) { if (was_timing) {
@ -99,7 +99,7 @@ void Timer::setTimeout(uint64_t timeout) {
} }
m_timeout = timeout; m_timeout = timeout;
if (was_timing) { if (force_start || was_timing) {
start(); start();
} }
} }

View file

@ -43,7 +43,7 @@ public:
~Timer(); ~Timer();
void fireOnce(bool once) { m_once = once; } void fireOnce(bool once) { m_once = once; }
void setTimeout(uint64_t timeout); void setTimeout(uint64_t timeout, bool force_start = false);
void setCommand(const RefCount<Slot<void> > &cmd); void setCommand(const RefCount<Slot<void> > &cmd);
template<typename Functor> template<typename Functor>