all repos — fluxbox @ 716532dd47d718cb548da5f65b53a8b744ce235f

custom fork of the fluxbox windowmanager

Calculates timeouts of ClockTool based upon System Clock

Users expect time switches to happen upon system clock times. Calculating the
timeout for the next refresh of the shown time via the monotonic clock is
wrong: The monotonic clock yields values based upon some arbitrary point in
time which might be off a little bit to the system clock, a 'full' minute of
the monotonic clock might be in the midst of a system clock minute.
Mathias Gumz akira at fluxbox dot org
commit

716532dd47d718cb548da5f65b53a8b744ce235f

parent

e7bfc639323bf5d4b207323b6e2fd275dcb5d825

5 files changed, 36 insertions(+), 26 deletions(-)

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

@@ -70,12 +70,13 @@

uint64_t calcNextTimeout(const std::string& fmt_string) { - if (showSeconds(fmt_string)) { // microseconds till next full second - return FbTk::FbTime::remainingNext(FbTk::FbTime::IN_SECONDS); + uint64_t now = FbTk::FbTime::system(); + uint64_t unit = FbTk::FbTime::IN_SECONDS; + if (!showSeconds(fmt_string)) { // microseconds till next full minute + unit *= 60L; } - // microseconds until next full minute - return FbTk::FbTime::remainingNext(60L * FbTk::FbTime::IN_SECONDS); + return FbTk::FbTime::remainingNext(now, unit); }
M src/FbTk/FbTime.ccsrc/FbTk/FbTime.cc

@@ -21,6 +21,8 @@ // DEALINGS IN THE SOFTWARE.

#include "FbTime.hh" +#include <cstdlib> +#include <sys/time.h> #ifdef HAVE_CLOCK_GETTIME // linux|*bsd|solaris

@@ -28,16 +30,16 @@ #include <time.h>

namespace { -uint64_t _now() { +uint64_t _mono() { - uint64_t n = 0L; + uint64_t t = 0L; timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) { - n = (ts.tv_sec * FbTk::FbTime::IN_SECONDS) + (ts.tv_nsec / 1000L); + t = (ts.tv_sec * FbTk::FbTime::IN_SECONDS) + (ts.tv_nsec / 1000L); } - return n; + return t; } }

@@ -59,7 +61,7 @@ #include <mach/mach_time.h>

namespace { -uint64_t _now() { +uint64_t _mono() { // mach_absolute_time() * info.numer / info.denom yields // nanoseconds.

@@ -85,13 +87,15 @@

- -uint64_t FbTk::FbTime::now() { - return ::_now(); +uint64_t FbTk::FbTime::mono() { + return ::_mono(); } -uint64_t FbTk::FbTime::remainingNext(uint64_t unit) { - return (unit - (::_now() % unit) - 1); +uint64_t FbTk::FbTime::system() { + static timeval v; + gettimeofday(&v, NULL); + return (v.tv_sec * FbTk::FbTime::IN_SECONDS) + v.tv_usec; } +
M src/FbTk/FbTime.hhsrc/FbTk/FbTime.hh

@@ -34,7 +34,7 @@ #endif // HAVE_INTTYPES_H

namespace FbTk { -// time in micro-seconds, monotonic increasing +// time in micro-seconds // // interesting links: //

@@ -44,12 +44,17 @@

namespace FbTime { const uint64_t IN_MILLISECONDS = 1000L; - const uint64_t IN_SECONDS = 1000L * 1000L; + const uint64_t IN_SECONDS = 1000L * IN_MILLISECONDS; + const uint64_t IN_MINUTES = 60 * IN_SECONDS; - uint64_t now(); + uint64_t mono(); // point in time, always monotonic + uint64_t system(); // system time, might jump (DST, leap seconds) - // calculates the remaining microseconds up to the next full 'unit' - uint64_t remainingNext(uint64_t unit); + // calculates the remaining microseconds from 'now' up to the + // next full 'unit' + inline uint64_t remainingNext(uint64_t now, uint64_t unit) { + return (unit - (now % unit) - 1); + } } // namespace FbTime
M src/FbTk/Timer.ccsrc/FbTk/Timer.cc

@@ -117,7 +117,7 @@ // timer with 'm_interval != 0' we have to remove

// it from s_timerlist before restarting it stop(); - m_start = FbTk::FbTime::now(); + m_start = FbTk::FbTime::mono(); // interval timers have their timeout change every // time they are started!

@@ -158,7 +158,7 @@ FD_ZERO(&rfds);

FD_SET(fd, &rfds); bool overdue = false; - uint64_t now = FbTime::now(); + uint64_t now = FbTime::mono(); uint64_t end_time; // search for overdue timers

@@ -192,7 +192,7 @@ // (ordered) list of timers into a list and work on it.

static std::vector<FbTk::Timer*> timeouts; - now = FbTime::now(); + now = FbTime::mono(); for (it = s_timerlist.begin(); it != s_timerlist.end(); ++it ) { if (now < (*it)->getEndTime()) { break;
M src/Window.ccsrc/Window.cc

@@ -550,7 +550,7 @@ }

m_workspacesig.emit(*this); - m_creation_time = FbTk::FbTime::now(); + m_creation_time = FbTk::FbTime::mono(); frame().frameExtentSig().emit();

@@ -2206,7 +2206,7 @@ // don't let misbehaving clients (e.g. MPlayer) move/resize their windows

// just after creation if the user has a saved position/size if (m_creation_time) { - uint64_t now = FbTk::FbTime::now(); + uint64_t now = FbTk::FbTime::mono(); Remember& rinst = Remember::instance();

@@ -2310,12 +2310,12 @@ return;

} // otherwise, make a note that the user is typing - m_last_keypress_time = FbTk::FbTime::now(); + m_last_keypress_time = FbTk::FbTime::mono(); } bool FluxboxWindow::isTyping() const { - uint64_t diff = FbTk::FbTime::now() - m_last_keypress_time; + uint64_t diff = FbTk::FbTime::mono() - m_last_keypress_time; return ((diff / 1000) < screen().noFocusWhileTypingDelay()); }