all repos — fluxbox @ 913244789fac779d8c4ce719d3e9534312feacc2

custom fork of the fluxbox windowmanager

fix clocktool lagging behind and skipping seconds

from time to time (...) time() might be off to gettimeofday() by a
second. the reason for this is that time() is usually implemented
by just returning the field 'second' of the struct that represents
the clock inside the kernel. gettimeofday() on the other hand also
takes the 'fraction' field (mostly 'nanoseconds') into account and
thus is closer to the current time than time().

the result of using time() was a perceived 'lag', sometimes the
clocktool even skipped a second. by using FbTk::FbTime()::system()
instead fixes the issue.
Mathias Gumz akira at fluxbox dot org
commit

913244789fac779d8c4ce719d3e9534312feacc2

parent

9b40943deaac2c72d3cc1c6ec4645a32562ab810

1 files changed, 13 insertions(+), 2 deletions(-)

jump to
M src/ClockTool.ccsrc/ClockTool.cc

@@ -247,9 +247,20 @@ }

void ClockTool::updateTime() { - time_t t = time(NULL); + // time() might result in a different seconds-since-epoch than + // gettimeofday() due to the fact that time() might be implemented by just + // returning the amount of elapsed full seconds without taking into + // account the sum of accumulated sub-seconds might be bigger than a + // second. in this situation time() is 1s behind gettimeofday() which would + // result in having the same 'text' and thus fluxbox would skip this + // round. reference: + // + // http://stackoverflow.com/questions/22917318/time-and-gettimeofday-return-different-seconds/23597725#23597725 + + uint64_t now = FbTk::FbTime::system(); + time_t t = static_cast<time_t>(now / 1000000L); - if (t != -1) { + if (t != static_cast<time_t>(-1)) { char buf[255]; int len;