diff options
author | fluxgen <fluxgen> | 2002-03-18 23:41:08 (GMT) |
---|---|---|
committer | fluxgen <fluxgen> | 2002-03-18 23:41:08 (GMT) |
commit | e6e1db0ad6caee1bb5c7f2542e0854d881a9308a (patch) | |
tree | 9ca76a63bedc446ce05b5e55a1084392fbfe2e63 | |
parent | c5bdfbfd500e93b69a19e53008bda7773db861e8 (diff) | |
download | fluxbox_paul-e6e1db0ad6caee1bb5c7f2542e0854d881a9308a.zip fluxbox_paul-e6e1db0ad6caee1bb5c7f2542e0854d881a9308a.tar.bz2 |
moved timer update to BTimer, update of timer is done i BTimer::updateTimers()
-rw-r--r-- | src/BaseDisplay.cc | 96 |
1 files changed, 4 insertions, 92 deletions
diff --git a/src/BaseDisplay.cc b/src/BaseDisplay.cc index 9a24081..6bcbd5e 100644 --- a/src/BaseDisplay.cc +++ b/src/BaseDisplay.cc | |||
@@ -22,9 +22,9 @@ | |||
22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
23 | // DEALINGS IN THE SOFTWARE. | 23 | // DEALINGS IN THE SOFTWARE. |
24 | 24 | ||
25 | // $Id: BaseDisplay.cc,v 1.7 2002/03/18 15:28:25 fluxgen Exp $ | 25 | // $Id: BaseDisplay.cc,v 1.8 2002/03/18 23:41:08 fluxgen Exp $ |
26 | 26 | ||
27 | // use some GNU extensions | 27 | // use GNU extensions |
28 | #ifndef _GNU_SOURCE | 28 | #ifndef _GNU_SOURCE |
29 | #define _GNU_SOURCE | 29 | #define _GNU_SOURCE |
30 | #endif // _GNU_SOURCE | 30 | #endif // _GNU_SOURCE |
@@ -35,6 +35,7 @@ | |||
35 | 35 | ||
36 | #include "BaseDisplay.hh" | 36 | #include "BaseDisplay.hh" |
37 | #include "i18n.hh" | 37 | #include "i18n.hh" |
38 | #include "Timer.hh" | ||
38 | 39 | ||
39 | #include <X11/Xutil.h> | 40 | #include <X11/Xutil.h> |
40 | #include <X11/cursorfont.h> | 41 | #include <X11/cursorfont.h> |
@@ -321,8 +322,6 @@ BaseDisplay::~BaseDisplay(void) { | |||
321 | void BaseDisplay::eventLoop(void) { | 322 | void BaseDisplay::eventLoop(void) { |
322 | run(); | 323 | run(); |
323 | 324 | ||
324 | int xfd = ConnectionNumber(m_display); | ||
325 | |||
326 | while ((! m_shutdown) && (! internal_error)) { | 325 | while ((! m_shutdown) && (! internal_error)) { |
327 | if (XPending(m_display)) { | 326 | if (XPending(m_display)) { |
328 | XEvent e; | 327 | XEvent e; |
@@ -346,75 +345,7 @@ void BaseDisplay::eventLoop(void) { | |||
346 | process_event(&e); | 345 | process_event(&e); |
347 | } | 346 | } |
348 | } else { | 347 | } else { |
349 | fd_set rfds; | 348 | BTimer::updateTimers(ConnectionNumber(m_display)); //handle all timers |
350 | timeval now, tm, *timeout = (timeval *) 0; | ||
351 | |||
352 | FD_ZERO(&rfds); | ||
353 | FD_SET(xfd, &rfds); | ||
354 | |||
355 | if (timerList.size() > 0) { | ||
356 | gettimeofday(&now, 0); | ||
357 | |||
358 | tm.tv_sec = tm.tv_usec = 0l; | ||
359 | |||
360 | BTimer *timer = timerList.front(); | ||
361 | |||
362 | tm.tv_sec = timer->getStartTime().tv_sec + | ||
363 | timer->getTimeout().tv_sec - now.tv_sec; | ||
364 | tm.tv_usec = timer->getStartTime().tv_usec + | ||
365 | timer->getTimeout().tv_usec - now.tv_usec; | ||
366 | |||
367 | while (tm.tv_usec >= 1000000) { | ||
368 | tm.tv_sec++; | ||
369 | tm.tv_usec -= 1000000; | ||
370 | } | ||
371 | |||
372 | while (tm.tv_usec < 0) { | ||
373 | if (tm.tv_sec > 0) { | ||
374 | tm.tv_sec--; | ||
375 | tm.tv_usec += 1000000; | ||
376 | } else { | ||
377 | tm.tv_usec = 0; | ||
378 | break; | ||
379 | } | ||
380 | } | ||
381 | |||
382 | timeout = &tm; | ||
383 | } | ||
384 | |||
385 | select(xfd + 1, &rfds, 0, 0, timeout); | ||
386 | |||
387 | // check for timer timeout | ||
388 | gettimeofday(&now, 0); | ||
389 | |||
390 | TimerList::iterator it = timerList.begin(); | ||
391 | //must check end ...the timer might remove | ||
392 | //it self from the list (should be fixed in the future) | ||
393 | for(; it != timerList.end(); ++it) { | ||
394 | |||
395 | tm.tv_sec = (*it)->getStartTime().tv_sec + | ||
396 | (*it)->getTimeout().tv_sec; | ||
397 | tm.tv_usec = (*it)->getStartTime().tv_usec + | ||
398 | (*it)->getTimeout().tv_usec; | ||
399 | |||
400 | if ((now.tv_sec < tm.tv_sec) || | ||
401 | (now.tv_sec == tm.tv_sec && now.tv_usec < tm.tv_usec)) | ||
402 | break; | ||
403 | |||
404 | (*it)->fireTimeout(); | ||
405 | |||
406 | // restart the current timer so that the start time is updated | ||
407 | if (! (*it)->doOnce()) | ||
408 | (*it)->start(); | ||
409 | else { | ||
410 | (*it)->stop(); | ||
411 | // must do this because the stupid cyclic dep | ||
412 | // between BaseDisplay and BTimer, the timer removes | ||
413 | // it self from the list | ||
414 | it--; | ||
415 | } | ||
416 | |||
417 | } | ||
418 | } | 349 | } |
419 | } | 350 | } |
420 | } | 351 | } |
@@ -445,27 +376,8 @@ void BaseDisplay::ungrab(void) { | |||
445 | } | 376 | } |
446 | 377 | ||
447 | 378 | ||
448 | void BaseDisplay::addTimer(BTimer *timer) { | ||
449 | assert(timer); | ||
450 | |||
451 | TimerList::iterator it = timerList.begin(); | ||
452 | TimerList::iterator it_end = timerList.end(); | ||
453 | int index = 0; | ||
454 | for (; it != it_end; ++it, ++index) { | ||
455 | if (((*it)->getTimeout().tv_sec > timer->getTimeout().tv_sec) || | ||
456 | (((*it)->getTimeout().tv_sec == timer->getTimeout().tv_sec) && | ||
457 | ((*it)->getTimeout().tv_usec >= timer->getTimeout().tv_usec))) { | ||
458 | break; | ||
459 | } | ||
460 | } | ||
461 | timerList.insert(it, timer); | ||
462 | } | ||
463 | 379 | ||
464 | 380 | ||
465 | void BaseDisplay::removeTimer(BTimer *timer) { | ||
466 | timerList.remove(timer); | ||
467 | } | ||
468 | |||
469 | 381 | ||
470 | ScreenInfo::ScreenInfo(BaseDisplay *d, int num) { | 382 | ScreenInfo::ScreenInfo(BaseDisplay *d, int num) { |
471 | basedisplay = d; | 383 | basedisplay = d; |