From 948e63eb600e173815a9ddedd2951db56fe51611 Mon Sep 17 00:00:00 2001 From: Mathias Gumz Date: Mon, 12 May 2014 12:17:00 +0200 Subject: 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. --- src/ClockTool.cc | 14 +++++++++++--- src/FbTk/Timer.cc | 4 ++-- src/FbTk/Timer.hh | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/ClockTool.cc b/src/ClockTool.cc index 514d45d..f11a793 100644 --- a/src/ClockTool.cc +++ b/src/ClockTool.cc @@ -52,10 +52,19 @@ const char SWITCHES_12_24H[] = "lIrkHT"; const char SWITCHES_24_12H[] = "kHTlIr"; 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 unit = FbTk::FbTime::IN_SECONDS; + if (!showSeconds(fmt)) { // microseconds till next full minute + unit *= 60L; + } return FbTk::FbTime::remainingNext(now, unit); } @@ -289,8 +298,7 @@ void ClockTool::updateTime() { } restart_timer: - m_timer.setTimeout(calcNextTimeout()); - m_timer.start(); + m_timer.setTimeout(calcNextTimeout(*m_timeformat), true); } // Just change things that affect the size diff --git a/src/FbTk/Timer.cc b/src/FbTk/Timer.cc index 1806557..61875f7 100644 --- a/src/FbTk/Timer.cc +++ b/src/FbTk/Timer.cc @@ -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(); if (was_timing) { @@ -99,7 +99,7 @@ void Timer::setTimeout(uint64_t timeout) { } m_timeout = timeout; - if (was_timing) { + if (force_start || was_timing) { start(); } } diff --git a/src/FbTk/Timer.hh b/src/FbTk/Timer.hh index 4bdd13a..8904a85 100644 --- a/src/FbTk/Timer.hh +++ b/src/FbTk/Timer.hh @@ -43,7 +43,7 @@ public: ~Timer(); 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 > &cmd); template -- cgit v0.11.2