diff options
author | Mathias Gumz <akira at fluxbox dot org> | 2012-08-28 08:51:55 (GMT) |
---|---|---|
committer | Mathias Gumz <akira at fluxbox dot org> | 2012-08-28 08:51:55 (GMT) |
commit | 541c8c407b7ba8dd10f85bb48bcb5900270b3f84 (patch) | |
tree | 71a6abc0f2a43bcfd33f80b3b30b878f234cbf05 /src/Window.cc | |
parent | 60a53113e05db443af4d520883ec3145680642a8 (diff) | |
download | fluxbox-541c8c407b7ba8dd10f85bb48bcb5900270b3f84.zip fluxbox-541c8c407b7ba8dd10f85bb48bcb5900270b3f84.tar.bz2 |
changed timing functions to use a monotonic increasing clock
gettimeofday() is subject to be changed on daylight-saving or to ntp-related
(think leap-seconds). even worse, it is subject to be changed BACK in time. this
is hard to fix correctly (see commit 45726d3016e and bug #3560509). it is
irrelevant for timers to know the nano-seconds since the epoch anyways.
Diffstat (limited to 'src/Window.cc')
-rw-r--r-- | src/Window.cc | 34 |
1 files changed, 11 insertions, 23 deletions
diff --git a/src/Window.cc b/src/Window.cc index 597bc08..33a4c9e 100644 --- a/src/Window.cc +++ b/src/Window.cc | |||
@@ -416,7 +416,7 @@ void FluxboxWindow::init() { | |||
416 | 416 | ||
417 | updateMWMHintsFromClient(*m_client); | 417 | updateMWMHintsFromClient(*m_client); |
418 | 418 | ||
419 | m_timer.setTimeout(fluxbox.getAutoRaiseDelay()); | 419 | m_timer.setTimeout(fluxbox.getAutoRaiseDelay() * FbTk::FbTime::IN_MILLISECONDS); |
420 | FbTk::RefCount<FbTk::Command<void> > raise_cmd(new FbTk::SimpleCommand<FluxboxWindow>(*this, | 420 | FbTk::RefCount<FbTk::Command<void> > raise_cmd(new FbTk::SimpleCommand<FluxboxWindow>(*this, |
421 | &FluxboxWindow::raise)); | 421 | &FluxboxWindow::raise)); |
422 | m_timer.setCommand(raise_cmd); | 422 | m_timer.setCommand(raise_cmd); |
@@ -538,9 +538,7 @@ void FluxboxWindow::init() { | |||
538 | 538 | ||
539 | m_workspacesig.emit(*this); | 539 | m_workspacesig.emit(*this); |
540 | 540 | ||
541 | struct timeval now; | 541 | m_creation_time = FbTk::FbTime::now(); |
542 | gettimeofday(&now, NULL); | ||
543 | m_creation_time = now.tv_sec; | ||
544 | 542 | ||
545 | frame().frameExtentSig().emit(); | 543 | frame().frameExtentSig().emit(); |
546 | 544 | ||
@@ -1049,15 +1047,10 @@ void FluxboxWindow::grabButtons() { | |||
1049 | void FluxboxWindow::reconfigure() { | 1047 | void FluxboxWindow::reconfigure() { |
1050 | 1048 | ||
1051 | applyDecorations(); | 1049 | applyDecorations(); |
1052 | |||
1053 | setFocusFlag(m_focused); | 1050 | setFocusFlag(m_focused); |
1054 | |||
1055 | moveResize(frame().x(), frame().y(), frame().width(), frame().height()); | 1051 | moveResize(frame().x(), frame().y(), frame().width(), frame().height()); |
1056 | 1052 | m_timer.setTimeout(Fluxbox::instance()->getAutoRaiseDelay() * FbTk::FbTime::IN_MILLISECONDS); | |
1057 | m_timer.setTimeout(Fluxbox::instance()->getAutoRaiseDelay()); | ||
1058 | |||
1059 | updateButtons(); | 1053 | updateButtons(); |
1060 | |||
1061 | frame().reconfigure(); | 1054 | frame().reconfigure(); |
1062 | menu().reconfigure(); | 1055 | menu().reconfigure(); |
1063 | 1056 | ||
@@ -2200,14 +2193,14 @@ void FluxboxWindow::configureRequestEvent(XConfigureRequestEvent &cr) { | |||
2200 | // don't let misbehaving clients (e.g. MPlayer) move/resize their windows | 2193 | // don't let misbehaving clients (e.g. MPlayer) move/resize their windows |
2201 | // just after creation if the user has a saved position/size | 2194 | // just after creation if the user has a saved position/size |
2202 | if (m_creation_time) { | 2195 | if (m_creation_time) { |
2203 | struct timeval now; | 2196 | |
2204 | gettimeofday(&now, NULL); | 2197 | uint64_t now = FbTk::FbTime::now(); |
2205 | 2198 | ||
2206 | Remember& rinst = Remember::instance(); | 2199 | Remember& rinst = Remember::instance(); |
2207 | 2200 | ||
2208 | if (now.tv_sec > m_creation_time + 1) | 2201 | if (now > (m_creation_time + FbTk::FbTime::IN_SECONDS)) { |
2209 | m_creation_time = 0; | 2202 | m_creation_time = 0; |
2210 | else if (rinst.isRemembered(*client, Remember::REM_MAXIMIZEDSTATE) || | 2203 | } else if (rinst.isRemembered(*client, Remember::REM_MAXIMIZEDSTATE) || |
2211 | rinst.isRemembered(*client, Remember::REM_FULLSCREENSTATE)) { | 2204 | rinst.isRemembered(*client, Remember::REM_FULLSCREENSTATE)) { |
2212 | cr.value_mask = cr.value_mask & ~(CWWidth | CWHeight); | 2205 | cr.value_mask = cr.value_mask & ~(CWWidth | CWHeight); |
2213 | cr.value_mask = cr.value_mask & ~(CWX | CWY); | 2206 | cr.value_mask = cr.value_mask & ~(CWX | CWY); |
@@ -2300,23 +2293,18 @@ void FluxboxWindow::keyPressEvent(XKeyEvent &ke) { | |||
2300 | // e.g., typed the command in a terminal | 2293 | // e.g., typed the command in a terminal |
2301 | if (ks == XK_KP_Enter || ks == XK_Return) { | 2294 | if (ks == XK_KP_Enter || ks == XK_Return) { |
2302 | // we'll actually reset the time for this one | 2295 | // we'll actually reset the time for this one |
2303 | m_last_keypress_time.tv_sec = 0; | 2296 | m_last_keypress_time = 0; |
2304 | return; | 2297 | return; |
2305 | } | 2298 | } |
2306 | 2299 | ||
2307 | // otherwise, make a note that the user is typing | 2300 | // otherwise, make a note that the user is typing |
2308 | gettimeofday(&m_last_keypress_time, 0); | 2301 | m_last_keypress_time = FbTk::FbTime::now(); |
2309 | } | 2302 | } |
2310 | 2303 | ||
2311 | bool FluxboxWindow::isTyping() const { | 2304 | bool FluxboxWindow::isTyping() const { |
2312 | timeval now; | ||
2313 | if (gettimeofday(&now, NULL) == -1) | ||
2314 | return false; | ||
2315 | |||
2316 | unsigned int diff = 1000*(now.tv_sec - m_last_keypress_time.tv_sec); | ||
2317 | diff += (now.tv_usec - m_last_keypress_time.tv_usec)/1000; | ||
2318 | 2305 | ||
2319 | return (diff < screen().noFocusWhileTypingDelay()); | 2306 | uint64_t diff = FbTk::FbTime::now() - m_last_keypress_time; |
2307 | return ((diff / 1000) < screen().noFocusWhileTypingDelay()); | ||
2320 | } | 2308 | } |
2321 | 2309 | ||
2322 | void FluxboxWindow::buttonPressEvent(XButtonEvent &be) { | 2310 | void FluxboxWindow::buttonPressEvent(XButtonEvent &be) { |