From 9259ec5732851dd66f7c598d629e3808ac7ab3d8 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Sun, 3 Nov 2002 14:29:34 +0000 Subject: new timer infrastructure. takes a function pointer for the timeout, with a void* parameter (useful for holding a class instance!) --- Makefile.am | 2 +- otk/Makefile.am | 19 ++---- otk/image.hh | 11 ++-- otk/imagecontrol.cc | 20 +++--- otk/timer.cc | 186 ++++++++++++++++++++++++++++++++++++++++++++++++++++ otk/timer.hh | 124 +++++++++++++++++++++++++++++++++++ src/Makefile.am | 2 +- src/blackbox.cc | 12 ++-- src/blackbox.hh | 7 +- src/openbox.hh | 8 +-- src/screen.cc | 5 +- src/timer.cc | 150 ------------------------------------------ src/timer.hh | 124 ----------------------------------- src/util.cc | 23 ------- src/util.hh | 2 - src/window.cc | 9 ++- src/window.hh | 8 +-- 17 files changed, 361 insertions(+), 351 deletions(-) create mode 100644 otk/timer.cc create mode 100644 otk/timer.hh delete mode 100644 src/timer.cc delete mode 100644 src/timer.hh diff --git a/Makefile.am b/Makefile.am index db649f90..7048d8f5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,6 @@ # Makefile.am for Openbox -SUBDIRS = intl po m4 data doc otk src util +SUBDIRS = intl po m4 data doc otk src MAINTAINERCLEANFILES = aclocal.m4 config.h.in configure Makefile.in stamp-h.in uninstall-local: diff --git a/otk/Makefile.am b/otk/Makefile.am index 7f862287..ada95b7f 100644 --- a/otk/Makefile.am +++ b/otk/Makefile.am @@ -5,7 +5,7 @@ INCLUDES= -I../src noinst_LIBRARIES=libotk.a libotk_a_SOURCES= color.cc display.cc font.cc gccache.cc image.cc \ - imagecontrol.cc rect.cc screeninfo.cc texture.cc + imagecontrol.cc rect.cc screeninfo.cc texture.cc timer.cc MAINTAINERCLEANFILES= Makefile.in @@ -13,16 +13,7 @@ distclean-local: rm -f *\~ *.orig *.rej .\#* # local dependencies -color.o: color.cc color.hh ../src/basedisplay.hh ../src/timer.hh ../src/util.hh -font.o: font.cc font.hh ../src/screen.hh color.hh texture.hh ../src/util.hh image.hh \ - ../src/timer.hh ../src/basedisplay.hh ../src/workspace.hh ../src/xatom.hh ../src/blackbox.hh \ - ../src/configuration.hh gccache.hh -gccache.o: gccache.cc gccache.hh ../src/basedisplay.hh ../src/timer.hh ../src/util.hh \ - color.hh -image.o: image.cc ../src/blackbox.hh ../src/basedisplay.hh ../src/timer.hh ../src/util.hh \ - ../src/configuration.hh ../src/xatom.hh gccache.hh color.hh image.hh texture.hh -imagecontrol.o: imagecontrol.cc ../src/blackbox.hh ../src/basedisplay.hh ../src/timer.hh \ - ../src/util.hh ../src/configuration.hh ../src/xatom.hh color.hh image.hh texture.hh -texture.o: texture.cc texture.hh color.hh ../src/util.hh ../src/basedisplay.hh \ - ../src/timer.hh image.hh ../src/screen.hh ../src/workspace.hh ../src/xatom.hh \ - ../src/blackbox.hh ../src/configuration.hh +color.o: color.cc color.hh display.hh screeninfo.hh rect.hh +gccache.o: gccache.cc gccache.hh display.hh color.hh assassin.hh \ + screeninfo.hh rect.hh +rect.o: rect.cc rect.hh diff --git a/otk/image.hh b/otk/image.hh index ac5794b5..ed99e124 100644 --- a/otk/image.hh +++ b/otk/image.hh @@ -11,7 +11,7 @@ extern "C" { #include "color.hh" #include "screeninfo.hh" -#include "src/timer.hh" +#include "timer.hh" namespace otk { @@ -66,7 +66,7 @@ public: }; -class BImageControl : public ob::TimeoutHandler { +class BImageControl { public: struct CachedImage { Pixmap pixmap; @@ -75,7 +75,8 @@ public: unsigned long pixel1, pixel2, texture; }; - BImageControl(const ScreenInfo *scrn, + BImageControl(OBTimerQueueManager *timermanager, + const ScreenInfo *scrn, bool _dither= False, int _cpc = 4, unsigned long cache_timeout = 300000l, unsigned long cmax = 200l); @@ -111,12 +112,12 @@ public: void setDither(bool d) { dither = d; } void setColorsPerChannel(int cpc); - virtual void timeout(void); + static void timeout(BImageControl *t); private: bool dither; const ScreenInfo *screeninfo; - ob::OBTimer *timer; + OBTimer *timer; Colormap colormap; diff --git a/otk/imagecontrol.cc b/otk/imagecontrol.cc index 7120f1cf..8cc6b2af 100644 --- a/otk/imagecontrol.cc +++ b/otk/imagecontrol.cc @@ -41,7 +41,8 @@ static unsigned long bsqrt(unsigned long x) { BImageControl *ctrl = 0; -BImageControl::BImageControl(const ScreenInfo *scrn, +BImageControl::BImageControl(OBTimerQueueManager *timermanager, + const ScreenInfo *scrn, bool _dither, int _cpc, unsigned long cache_timeout, unsigned long cmax) { @@ -53,12 +54,11 @@ BImageControl::BImageControl(const ScreenInfo *scrn, cache_max = cmax; if (cache_timeout) { - // XXX: FIX THIS - timer = 0;/*new BTimer(this); + timer = new OBTimer(timermanager, (OBTimeoutHandler)timeout, this); timer->setTimeout(cache_timeout); - timer->start();*/ + timer->start(); } else { - timer = (ob::OBTimer *) 0; + timer = (OBTimer *) 0; } colors = (XColor *) 0; @@ -420,7 +420,7 @@ Pixmap BImageControl::renderImage(unsigned int width, unsigned int height, "forcing cleanout\n"); #endif // DEBUG - timeout(); + timeout(this); } return pixmap; @@ -440,7 +440,7 @@ void BImageControl::removeImage(Pixmap pixmap) { } if (! timer) - timeout(); + timeout(this); } @@ -553,10 +553,10 @@ struct CacheCleaner { }; -void BImageControl::timeout(void) { +void BImageControl::timeout(BImageControl *t) { CacheCleaner cleaner; - std::for_each(cache.begin(), cache.end(), cleaner); - cache.remove_if(cleaner.ref_check); + std::for_each(t->cache.begin(), t->cache.end(), cleaner); + t->cache.remove_if(cleaner.ref_check); } } diff --git a/otk/timer.cc b/otk/timer.cc new file mode 100644 index 00000000..b2b85a66 --- /dev/null +++ b/otk/timer.cc @@ -0,0 +1,186 @@ +// -*- mode: C++; indent-tabs-mode: nil; -*- + +#ifdef HAVE_CONFIG_H +# include "../config.h" +#endif // HAVE_CONFIG_H + +#include "timer.hh" +#include "display.hh" +#include "util.hh" + +namespace otk { + +static timeval normalizeTimeval(const timeval &tm) +{ + timeval ret = tm; + + while (ret.tv_usec < 0) { + if (ret.tv_sec > 0) { + --ret.tv_sec; + ret.tv_usec += 1000000; + } else { + ret.tv_usec = 0; + } + } + + if (ret.tv_usec >= 1000000) { + ret.tv_sec += ret.tv_usec / 1000000; + ret.tv_usec %= 1000000; + } + + if (ret.tv_sec < 0) ret.tv_sec = 0; + + return ret; +} + + +OBTimer::OBTimer(OBTimerQueueManager *m, OBTimeoutHandler h, OBTimeoutData d) +{ + manager = m; + handler = h; + data = d; + + recur = timing = False; +} + + +OBTimer::~OBTimer(void) +{ + if (timing) stop(); +} + + +void OBTimer::setTimeout(long t) +{ + _timeout.tv_sec = t / 1000; + _timeout.tv_usec = t % 1000; + _timeout.tv_usec *= 1000; +} + + +void OBTimer::setTimeout(const timeval &t) +{ + _timeout.tv_sec = t.tv_sec; + _timeout.tv_usec = t.tv_usec; +} + + +void OBTimer::start(void) +{ + gettimeofday(&_start, 0); + + if (! timing) { + timing = True; + manager->addTimer(this); + } +} + + +void OBTimer::stop(void) +{ + timing = False; + + manager->removeTimer(this); +} + + +void OBTimer::halt(void) +{ + timing = False; +} + + +void OBTimer::fireTimeout(void) +{ + if (handler) + handler(data); +} + + +timeval OBTimer::timeRemaining(const timeval &tm) const +{ + timeval ret = endpoint(); + + ret.tv_sec -= tm.tv_sec; + ret.tv_usec -= tm.tv_usec; + + return normalizeTimeval(ret); +} + + +timeval OBTimer::endpoint(void) const +{ + timeval ret; + + ret.tv_sec = _start.tv_sec + _timeout.tv_sec; + ret.tv_usec = _start.tv_usec + _timeout.tv_usec; + + return normalizeTimeval(ret); +} + + +bool OBTimer::shouldFire(const timeval &tm) const +{ + timeval end = endpoint(); + + return ! ((tm.tv_sec < end.tv_sec) || + (tm.tv_sec == end.tv_sec && tm.tv_usec < end.tv_usec)); +} + + +void OBTimerQueueManager::fire() +{ + fd_set rfds; + timeval now, tm, *timeout = (timeval *) 0; + + const int xfd = ConnectionNumber(otk::OBDisplay::display); + + FD_ZERO(&rfds); + FD_SET(xfd, &rfds); // break on any x events + + if (! timerList.empty()) { + const OBTimer* const timer = timerList.top(); + + gettimeofday(&now, 0); + tm = timer->timeRemaining(now); + + timeout = &tm; + } + + select(xfd + 1, &rfds, 0, 0, timeout); + + // check for timer timeout + gettimeofday(&now, 0); + + // there is a small chance for deadlock here: + // *IF* the timer list keeps getting refreshed *AND* the time between + // timer->start() and timer->shouldFire() is within the timer's period + // then the timer will keep firing. This should be VERY near impossible. + while (! timerList.empty()) { + OBTimer *timer = timerList.top(); + if (! timer->shouldFire(now)) + break; + + timerList.pop(); + + timer->fireTimeout(); + timer->halt(); + if (timer->isRecurring()) + timer->start(); + } +} + + +void OBTimerQueueManager::addTimer(OBTimer *timer) +{ + assert(timer); + timerList.push(timer); +} + +void OBTimerQueueManager::removeTimer(OBTimer* timer) +{ + assert(timer); + timerList.release(timer); +} + +} diff --git a/otk/timer.hh b/otk/timer.hh new file mode 100644 index 00000000..2deeba58 --- /dev/null +++ b/otk/timer.hh @@ -0,0 +1,124 @@ +// -*- mode: C++; indent-tabs-mode: nil; -*- +#ifndef _BLACKBOX_Timer_hh +#define _BLACKBOX_Timer_hh + +extern "C" { +#ifdef TIME_WITH_SYS_TIME +# include +# include +#else // !TIME_WITH_SYS_TIME +# ifdef HAVE_SYS_TIME_H +# include +# else // !HAVE_SYS_TIME_H +# include +# endif // HAVE_SYS_TIME_H +#endif // TIME_WITH_SYS_TIME +} + +#include +#include +#include + +namespace otk { + +// forward declaration +class OBTimerQueueManager; + +typedef void *OBTimeoutData; +typedef void (*OBTimeoutHandler)(OBTimeoutData); + +class OBTimer { +private: + OBTimerQueueManager *manager; + OBTimeoutHandler handler; + OBTimeoutData data; + bool timing, recur; + + timeval _start, _timeout; + + OBTimer(const OBTimer&); + OBTimer& operator=(const OBTimer&); + +public: + OBTimer(OBTimerQueueManager *m, OBTimeoutHandler h, OBTimeoutData d); + virtual ~OBTimer(); + + void fireTimeout(); + + inline bool isTiming() const { return timing; } + inline bool isRecurring() const { return recur; } + + inline const timeval &getTimeout() const { return _timeout; } + inline const timeval &getStartTime() const { return _start; } + + timeval timeRemaining(const timeval &tm) const; + bool shouldFire(const timeval &tm) const; + timeval endpoint() const; + + inline void recurring(bool b) { recur = b; } + + void setTimeout(long t); + void setTimeout(const timeval &t); + + void start(); // manager acquires timer + void stop(); // manager releases timer + void halt(); // halts the timer + + bool operator<(const OBTimer& other) const + { return shouldFire(other.endpoint()); } +}; + + +template +class _timer_queue: protected std::priority_queue<_Tp, _Sequence, _Compare> { +public: + typedef std::priority_queue<_Tp, _Sequence, _Compare> _Base; + + _timer_queue(): _Base() {} + ~_timer_queue() {} + + void release(const _Tp& value) { + c.erase(std::remove(c.begin(), c.end(), value), c.end()); + // after removing the item we need to make the heap again + std::make_heap(c.begin(), c.end(), comp); + } + bool empty() const { return _Base::empty(); } + size_t size() const { return _Base::size(); } + void push(const _Tp& value) { _Base::push(value); } + void pop() { _Base::pop(); } + const _Tp& top() const { return _Base::top(); } +private: + // no copying! + _timer_queue(const _timer_queue&) {} + _timer_queue& operator=(const _timer_queue&) {} +}; + +struct TimerLessThan { + bool operator()(const OBTimer* const l, const OBTimer* const r) const { + return *r < *l; + } +}; + +typedef _timer_queue, TimerLessThan> TimerQueue; + +class OBTimerQueueManager { +private: + TimerQueue timerList; +public: + OBTimerQueueManager() {} + virtual ~OBTimerQueueManager() {} + + //! Will wait for and fire the next timer in the queue. + /*! + The function will stop waiting if an event is received from the X server. + */ + virtual void fire(); + + virtual void addTimer(OBTimer* timer); + virtual void removeTimer(OBTimer* timer); +}; + +} + +#endif // _BLACKBOX_Timer_hh diff --git a/src/Makefile.am b/src/Makefile.am index 4a5ea177..314d265f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -16,7 +16,7 @@ bin_PROGRAMS= openbox openbox_LDADD=../otk/libotk.a @LIBINTL@ openbox_SOURCES= configuration.cc screen.cc openbox.cc \ - timer.cc util.cc window.cc workspace.cc xatom.cc blackbox.cc \ + util.cc window.cc workspace.cc xatom.cc blackbox.cc \ main.cc MAINTAINERCLEANFILES= Makefile.in diff --git a/src/blackbox.cc b/src/blackbox.cc index 90d0d3cc..6d267b53 100644 --- a/src/blackbox.cc +++ b/src/blackbox.cc @@ -158,7 +158,9 @@ Blackbox::Blackbox(int argc, char **m_argv, char *rc) reconfigure_wait = False; - timer = new OBTimer(this); + timer = new otk::OBTimer(Openbox::instance->timerManager(), + (otk::OBTimeoutHandler)timeout, + this); timer->setTimeout(0l); } @@ -1151,11 +1153,11 @@ void Blackbox::saveStyleFilename(const string& filename) { } -void Blackbox::timeout(void) { - if (reconfigure_wait) - real_reconfigure(); +void Blackbox::timeout(Blackbox *t) { + if (t->reconfigure_wait) + t->real_reconfigure(); - reconfigure_wait = False; + t->reconfigure_wait = False; } diff --git a/src/blackbox.hh b/src/blackbox.hh index 947c0a99..00f70cb9 100644 --- a/src/blackbox.hh +++ b/src/blackbox.hh @@ -25,6 +25,7 @@ extern "C" { #include #include +#include "otk/timer.hh" #include "openbox.hh" #include "configuration.hh" #include "timer.hh" @@ -69,7 +70,7 @@ class Blackbox; class BlackboxWindow; class BWindowGroup; -class Blackbox : public Openbox, public TimeoutHandler { +class Blackbox : public Openbox { private: struct BCursor { Cursor session, move, ll_angle, lr_angle, ul_angle, ur_angle; @@ -109,7 +110,7 @@ private: BScreen *active_screen; BlackboxWindow *focused_window, *changing_window; - OBTimer *timer; + otk::OBTimer *timer; Configuration config; XAtom *xatom; @@ -213,7 +214,7 @@ public: virtual bool handleSignal(int sig); - virtual void timeout(void); + static void timeout(Blackbox *t); enum { B_AmericanDate = 1, B_EuropeanDate }; }; diff --git a/src/openbox.hh b/src/openbox.hh index 4649f7a9..76a7d973 100644 --- a/src/openbox.hh +++ b/src/openbox.hh @@ -10,7 +10,7 @@ extern "C" { #include #include "otk/screeninfo.hh" -#include "timer.hh" +#include "otk/timer.hh" namespace ob { @@ -35,8 +35,8 @@ private: char *_displayreq; // display requested by the user char *_argv0; // argv[0], how the program was called - OBTimerQueueManager _timermanager; // manages timers, so that they fire when - // their time elapses + otk::OBTimerQueueManager _timermanager; // manages timers, so that they fire + // when their time elapses RunState _state; // the state of the window manager @@ -62,7 +62,7 @@ public: //! Returns the state of the window manager (starting, exiting, etc). inline RunState state() const { return _state; } - inline OBTimerQueueManager *timerManager() { return &_timermanager; } + inline otk::OBTimerQueueManager *timerManager() { return &_timermanager; } void eventLoop(); diff --git a/src/screen.cc b/src/screen.cc index 7ac74c3c..f8b998e6 100644 --- a/src/screen.cc +++ b/src/screen.cc @@ -132,7 +132,8 @@ BScreen::BScreen(Blackbox *bb, unsigned int scrn) : ScreenInfo(scrn) { updateAvailableArea(); image_control = - new otk::BImageControl(this, True, blackbox->getColorsPerChannel(), + new otk::BImageControl(Openbox::instance->timerManager(), + this, True, blackbox->getColorsPerChannel(), blackbox->getCacheLife(), blackbox->getCacheMax()); image_control->installRootColormap(); root_colormap_installed = True; @@ -779,7 +780,7 @@ void BScreen::reconfigure(void) { bw->reconfigure(); } - image_control->timeout(); + otk::BImageControl::timeout(image_control); } diff --git a/src/timer.cc b/src/timer.cc deleted file mode 100644 index 856ac8f7..00000000 --- a/src/timer.cc +++ /dev/null @@ -1,150 +0,0 @@ -// -*- mode: C++; indent-tabs-mode: nil; -*- - -#ifdef HAVE_CONFIG_H -# include "../config.h" -#endif // HAVE_CONFIG_H - -#include "otk/display.hh" -#include "openbox.hh" -#include "timer.hh" -#include "util.hh" - -namespace ob { - -OBTimer::OBTimer(TimeoutHandler *h) { - handler = h; - - recur = timing = False; -} - - -OBTimer::~OBTimer(void) { - if (timing) stop(); -} - - -void OBTimer::setTimeout(long t) { - _timeout.tv_sec = t / 1000; - _timeout.tv_usec = t % 1000; - _timeout.tv_usec *= 1000; -} - - -void OBTimer::setTimeout(const timeval &t) { - _timeout.tv_sec = t.tv_sec; - _timeout.tv_usec = t.tv_usec; -} - - -void OBTimer::start(void) { - gettimeofday(&_start, 0); - - if (! timing) { - timing = True; - Openbox::instance->timerManager()->addTimer(this); - } -} - - -void OBTimer::stop(void) { - timing = False; - - Openbox::instance->timerManager()->removeTimer(this); -} - - -void OBTimer::halt(void) { - timing = False; -} - - -void OBTimer::fireTimeout(void) { - if (handler) - handler->timeout(); -} - - -timeval OBTimer::timeRemaining(const timeval &tm) const { - timeval ret = endpoint(); - - ret.tv_sec -= tm.tv_sec; - ret.tv_usec -= tm.tv_usec; - - return normalizeTimeval(ret); -} - - -timeval OBTimer::endpoint(void) const { - timeval ret; - - ret.tv_sec = _start.tv_sec + _timeout.tv_sec; - ret.tv_usec = _start.tv_usec + _timeout.tv_usec; - - return normalizeTimeval(ret); -} - - -bool OBTimer::shouldFire(const timeval &tm) const { - timeval end = endpoint(); - - return ! ((tm.tv_sec < end.tv_sec) || - (tm.tv_sec == end.tv_sec && tm.tv_usec < end.tv_usec)); -} - - -void OBTimerQueueManager::fire() -{ - fd_set rfds; - timeval now, tm, *timeout = (timeval *) 0; - - const int xfd = ConnectionNumber(otk::OBDisplay::display); - - FD_ZERO(&rfds); - FD_SET(xfd, &rfds); // break on any x events - - if (! timerList.empty()) { - const OBTimer* const timer = timerList.top(); - - gettimeofday(&now, 0); - tm = timer->timeRemaining(now); - - timeout = &tm; - } - - select(xfd + 1, &rfds, 0, 0, timeout); - - // check for timer timeout - gettimeofday(&now, 0); - - // there is a small chance for deadlock here: - // *IF* the timer list keeps getting refreshed *AND* the time between - // timer->start() and timer->shouldFire() is within the timer's period - // then the timer will keep firing. This should be VERY near impossible. - while (! timerList.empty()) { - OBTimer *timer = timerList.top(); - if (! timer->shouldFire(now)) - break; - - timerList.pop(); - - timer->fireTimeout(); - timer->halt(); - if (timer->isRecurring()) - timer->start(); - } -} - - -void OBTimerQueueManager::addTimer(OBTimer *timer) -{ - assert(timer); - timerList.push(timer); -} - -void OBTimerQueueManager::removeTimer(OBTimer* timer) -{ - assert(timer); - timerList.release(timer); -} - -} diff --git a/src/timer.hh b/src/timer.hh deleted file mode 100644 index 774d0e49..00000000 --- a/src/timer.hh +++ /dev/null @@ -1,124 +0,0 @@ -// -*- mode: C++; indent-tabs-mode: nil; -*- -#ifndef _BLACKBOX_Timer_hh -#define _BLACKBOX_Timer_hh - -extern "C" { -#ifdef TIME_WITH_SYS_TIME -# include -# include -#else // !TIME_WITH_SYS_TIME -# ifdef HAVE_SYS_TIME_H -# include -# else // !HAVE_SYS_TIME_H -# include -# endif // HAVE_SYS_TIME_H -#endif // TIME_WITH_SYS_TIME -} - -#include -#include -#include - -namespace ob { - -// forward declaration -class OBTimerQueueManager; - -class TimeoutHandler { -public: - virtual void timeout(void) = 0; -}; - -class OBTimer { -private: - TimeoutHandler *handler; - bool timing, recur; - - timeval _start, _timeout; - - OBTimer(const OBTimer&); - OBTimer& operator=(const OBTimer&); - -public: - OBTimer(TimeoutHandler *h); - virtual ~OBTimer(void); - - void fireTimeout(void); - - inline bool isTiming(void) const { return timing; } - inline bool isRecurring(void) const { return recur; } - - inline const timeval &getTimeout(void) const { return _timeout; } - inline const timeval &getStartTime(void) const { return _start; } - - timeval timeRemaining(const timeval &tm) const; - bool shouldFire(const timeval &tm) const; - timeval endpoint(void) const; - - inline void recurring(bool b) { recur = b; } - - void setTimeout(long t); - void setTimeout(const timeval &t); - - void start(void); // manager acquires timer - void stop(void); // manager releases timer - void halt(void); // halts the timer - - bool operator<(const OBTimer& other) const - { return shouldFire(other.endpoint()); } -}; - - -template -class _timer_queue: protected std::priority_queue<_Tp, _Sequence, _Compare> { -public: - typedef std::priority_queue<_Tp, _Sequence, _Compare> _Base; - - _timer_queue(void): _Base() {} - ~_timer_queue(void) {} - - void release(const _Tp& value) { - c.erase(std::remove(c.begin(), c.end(), value), c.end()); - // after removing the item we need to make the heap again - std::make_heap(c.begin(), c.end(), comp); - } - bool empty(void) const { return _Base::empty(); } - size_t size(void) const { return _Base::size(); } - void push(const _Tp& value) { _Base::push(value); } - void pop(void) { _Base::pop(); } - const _Tp& top(void) const { return _Base::top(); } -private: - // no copying! - _timer_queue(const _timer_queue&) {} - _timer_queue& operator=(const _timer_queue&) {} -}; - -struct TimerLessThan { - bool operator()(const OBTimer* const l, const OBTimer* const r) const { - return *r < *l; - } -}; - -typedef _timer_queue, TimerLessThan> TimerQueue; - -class OBTimerQueueManager { -private: - TimerQueue timerList; -public: - OBTimerQueueManager() {} - virtual ~OBTimerQueueManager() {} - - //! Will wait for and fire the next timer in the queue. - /*! - The function will stop waiting if an event is received from the X server. - */ - virtual void fire(); - - virtual void addTimer(OBTimer* timer); - virtual void removeTimer(OBTimer* timer); -}; - -} - -#endif // _BLACKBOX_Timer_hh diff --git a/src/util.cc b/src/util.cc index 6a6ac417..77913952 100644 --- a/src/util.cc +++ b/src/util.cc @@ -83,29 +83,6 @@ string textPropertyToString(Display *display, XTextProperty& text_prop) { } -timeval normalizeTimeval(const timeval &tm) { - timeval ret = tm; - - while (ret.tv_usec < 0) { - if (ret.tv_sec > 0) { - --ret.tv_sec; - ret.tv_usec += 1000000; - } else { - ret.tv_usec = 0; - } - } - - if (ret.tv_usec >= 1000000) { - ret.tv_sec += ret.tv_usec / 1000000; - ret.tv_usec %= 1000000; - } - - if (ret.tv_sec < 0) ret.tv_sec = 0; - - return ret; -} - - string itostring(unsigned long i) { if (i == 0) return string("0"); diff --git a/src/util.hh b/src/util.hh index 1e17657e..b6da7520 100644 --- a/src/util.hh +++ b/src/util.hh @@ -39,8 +39,6 @@ void bexec(const std::string& command, const std::string& displaystring); std::string textPropertyToString(Display *display, XTextProperty& text_prop); -timeval normalizeTimeval(const timeval &tm); - std::string itostring(unsigned long i); std::string itostring(long i); inline std::string itostring(unsigned int i) diff --git a/src/window.cc b/src/window.cc index 2e7ba087..035d2469 100644 --- a/src/window.cc +++ b/src/window.cc @@ -135,7 +135,9 @@ BlackboxWindow::BlackboxWindow(Blackbox *b, Window w, BScreen *s) { lastButtonPressTime = 0; - timer = new OBTimer(this); + timer = new otk::OBTimer(Openbox::instance->timerManager(), + (otk::OBTimeoutHandler)timeout, + this); timer->setTimeout(blackbox->getAutoRaiseDelay()); // get size, aspect, minimum/maximum size and other hints set by the @@ -3902,8 +3904,9 @@ void BlackboxWindow::restore(bool remap) { // timer for autoraise -void BlackboxWindow::timeout(void) { - screen->getWorkspace(blackbox_attrib.workspace)->raiseWindow(this); +void BlackboxWindow::timeout(BlackboxWindow *t) { + t->screen->getWorkspace(t->blackbox_attrib.workspace)->raiseWindow(t); + printf("TIMED OUT YA YAY\n"); } diff --git a/src/window.hh b/src/window.hh index c8ccc341..29818b43 100644 --- a/src/window.hh +++ b/src/window.hh @@ -12,8 +12,8 @@ extern "C" { #include +#include "otk/timer.hh" #include "blackbox.hh" -#include "timer.hh" #include "util.hh" #define MwmHintsFunctions (1l << 0) @@ -70,7 +70,7 @@ public: }; -class BlackboxWindow : public TimeoutHandler { +class BlackboxWindow { public: enum Function { Func_Resize = (1l << 0), Func_Move = (1l << 1), @@ -105,7 +105,7 @@ private: Blackbox *blackbox; BScreen *screen; XAtom *xatom; - OBTimer *timer; + otk::OBTimer *timer; BlackboxAttributes blackbox_attrib; Time lastButtonPressTime; // used for double clicks, when were we clicked @@ -405,7 +405,7 @@ public: void shapeEvent(XShapeEvent * /*unused*/); #endif // SHAPE - virtual void timeout(void); + static void timeout(BlackboxWindow *t); }; } -- cgit v1.2.3