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 rollbackec7fe513c8
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:
parent
913244789f
commit
948e63eb60
3 changed files with 14 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Slot<void> > &cmd);
|
||||
|
||||
template<typename Functor>
|
||||
|
|
Loading…
Reference in a new issue