X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;ds=sidebyside;f=src%2FTimer.cc;h=8cd4714eb00b14bfaeec07ebd06e1d0fe2a673b1;hb=ae093dba2fb97124bb4af3eaf4070b46f07dfd74;hp=95985a0159c780e46430db03d749ee3ed4516ab1;hpb=dfc5f034581f5a26cba5c4811500438f89f0634a;p=chaz%2Fopenbox diff --git a/src/Timer.cc b/src/Timer.cc index 95985a01..8cd4714e 100644 --- a/src/Timer.cc +++ b/src/Timer.cc @@ -33,10 +33,7 @@ #include "BaseDisplay.h" #include "Timer.h" -BTimer::BTimer(BaseDisplay *d, TimeoutHandler *h) { - display = d; - handler = h; - +BTimer::BTimer(BaseDisplay &d, TimeoutHandler &h) : display(d), handler(h) { once = timing = False; } @@ -49,6 +46,10 @@ void BTimer::setTimeout(long t) { _timeout.tv_usec = t; _timeout.tv_usec -= (_timeout.tv_sec * 1000); _timeout.tv_usec *= 1000; + if (timing) { + display.removeTimer(this); + display.addTimer(this); // reorder the display + } } void BTimer::setTimeout(timeval t) { @@ -61,16 +62,18 @@ void BTimer::start(void) { if (! timing) { timing = True; - display->addTimer(this); + display.addTimer(this); } } void BTimer::stop(void) { - timing = False; + if (timing) { + timing = False; - display->removeTimer(this); + display.removeTimer(this); + } } void BTimer::fireTimeout(void) { - if (handler) handler->timeout(); + handler.timeout(); }