new timers, timer manager
This commit is contained in:
parent
c5f62494f1
commit
373de009f7
10 changed files with 50 additions and 90 deletions
|
@ -116,7 +116,7 @@ public:
|
||||||
private:
|
private:
|
||||||
bool dither;
|
bool dither;
|
||||||
const ScreenInfo *screeninfo;
|
const ScreenInfo *screeninfo;
|
||||||
ob::BTimer *timer;
|
ob::OBTimer *timer;
|
||||||
|
|
||||||
Colormap colormap;
|
Colormap colormap;
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ BImageControl::BImageControl(const ScreenInfo *scrn,
|
||||||
timer->setTimeout(cache_timeout);
|
timer->setTimeout(cache_timeout);
|
||||||
timer->start();*/
|
timer->start();*/
|
||||||
} else {
|
} else {
|
||||||
timer = (ob::BTimer *) 0;
|
timer = (ob::OBTimer *) 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
colors = (XColor *) 0;
|
colors = (XColor *) 0;
|
||||||
|
|
|
@ -158,7 +158,7 @@ Blackbox::Blackbox(int argc, char **m_argv, char *rc)
|
||||||
|
|
||||||
reconfigure_wait = False;
|
reconfigure_wait = False;
|
||||||
|
|
||||||
timer = new BTimer(this, this);
|
timer = new OBTimer(this);
|
||||||
timer->setTimeout(0l);
|
timer->setTimeout(0l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1215,14 +1215,4 @@ void Blackbox::setFocusedWindow(BlackboxWindow *win) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Blackbox::addTimer(BTimer *timer) {
|
|
||||||
(void)timer;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void Blackbox::removeTimer(BTimer *timer) {
|
|
||||||
(void)timer;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,7 +69,7 @@ class Blackbox;
|
||||||
class BlackboxWindow;
|
class BlackboxWindow;
|
||||||
class BWindowGroup;
|
class BWindowGroup;
|
||||||
|
|
||||||
class Blackbox : public Openbox, public TimeoutHandler, public TimerQueueManager {
|
class Blackbox : public Openbox, public TimeoutHandler {
|
||||||
private:
|
private:
|
||||||
struct BCursor {
|
struct BCursor {
|
||||||
Cursor session, move, ll_angle, lr_angle, ul_angle, ur_angle;
|
Cursor session, move, ll_angle, lr_angle, ul_angle, ur_angle;
|
||||||
|
@ -109,7 +109,7 @@ private:
|
||||||
|
|
||||||
BScreen *active_screen;
|
BScreen *active_screen;
|
||||||
BlackboxWindow *focused_window, *changing_window;
|
BlackboxWindow *focused_window, *changing_window;
|
||||||
BTimer *timer;
|
OBTimer *timer;
|
||||||
Configuration config;
|
Configuration config;
|
||||||
XAtom *xatom;
|
XAtom *xatom;
|
||||||
|
|
||||||
|
@ -216,9 +216,6 @@ public:
|
||||||
virtual void timeout(void);
|
virtual void timeout(void);
|
||||||
|
|
||||||
enum { B_AmericanDate = 1, B_EuropeanDate };
|
enum { B_AmericanDate = 1, B_EuropeanDate };
|
||||||
|
|
||||||
virtual void addTimer(BTimer *timer);
|
|
||||||
virtual void removeTimer(BTimer *timer);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -208,50 +208,13 @@ void Openbox::showHelp()
|
||||||
|
|
||||||
void Openbox::eventLoop()
|
void Openbox::eventLoop()
|
||||||
{
|
{
|
||||||
const int xfd = ConnectionNumber(otk::OBDisplay::display);
|
|
||||||
|
|
||||||
while (_state == State_Normal) {
|
while (_state == State_Normal) {
|
||||||
if (XPending(otk::OBDisplay::display)) {
|
if (XPending(otk::OBDisplay::display)) {
|
||||||
XEvent e;
|
XEvent e;
|
||||||
XNextEvent(otk::OBDisplay::display, &e);
|
XNextEvent(otk::OBDisplay::display, &e);
|
||||||
process_event(&e);
|
process_event(&e);
|
||||||
} else {
|
} else {
|
||||||
fd_set rfds;
|
_timermanager.fire();
|
||||||
timeval now, tm, *timeout = (timeval *) 0;
|
|
||||||
|
|
||||||
FD_ZERO(&rfds);
|
|
||||||
FD_SET(xfd, &rfds);
|
|
||||||
|
|
||||||
/* if (! timerList.empty()) {
|
|
||||||
const BTimer* 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()) {
|
|
||||||
BTimer *timer = timerList.top();
|
|
||||||
if (! timer->shouldFire(now))
|
|
||||||
break;
|
|
||||||
|
|
||||||
timerList.pop();
|
|
||||||
|
|
||||||
timer->fireTimeout();
|
|
||||||
timer->halt();
|
|
||||||
if (timer->isRecurring())
|
|
||||||
timer->start();
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ extern "C" {
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "otk/screeninfo.hh"
|
#include "otk/screeninfo.hh"
|
||||||
|
#include "timer.hh"
|
||||||
|
|
||||||
namespace ob {
|
namespace ob {
|
||||||
|
|
||||||
|
@ -34,6 +35,9 @@ private:
|
||||||
char *_displayreq; // display requested by the user
|
char *_displayreq; // display requested by the user
|
||||||
char *_argv0; // argv[0], how the program was called
|
char *_argv0; // argv[0], how the program was called
|
||||||
|
|
||||||
|
OBTimerQueueManager _timermanager; // manages timers, so that they fire when
|
||||||
|
// their time elapses
|
||||||
|
|
||||||
RunState _state; // the state of the window manager
|
RunState _state; // the state of the window manager
|
||||||
|
|
||||||
ScreenInfoList _screenInfoList; // info for all screens on the display
|
ScreenInfoList _screenInfoList; // info for all screens on the display
|
||||||
|
@ -58,6 +62,8 @@ public:
|
||||||
//! Returns the state of the window manager (starting, exiting, etc).
|
//! Returns the state of the window manager (starting, exiting, etc).
|
||||||
inline RunState state() const { return _state; }
|
inline RunState state() const { return _state; }
|
||||||
|
|
||||||
|
inline OBTimerQueueManager *timerManager() { return &_timermanager; }
|
||||||
|
|
||||||
void eventLoop();
|
void eventLoop();
|
||||||
|
|
||||||
// XXX: TEMPORARY!#!@%*!^#*!#!#!
|
// XXX: TEMPORARY!#!@%*!^#*!#!#!
|
||||||
|
|
38
src/timer.cc
38
src/timer.cc
|
@ -5,66 +5,66 @@
|
||||||
#endif // HAVE_CONFIG_H
|
#endif // HAVE_CONFIG_H
|
||||||
|
|
||||||
#include "otk/display.hh"
|
#include "otk/display.hh"
|
||||||
|
#include "openbox.hh"
|
||||||
#include "timer.hh"
|
#include "timer.hh"
|
||||||
#include "util.hh"
|
#include "util.hh"
|
||||||
|
|
||||||
namespace ob {
|
namespace ob {
|
||||||
|
|
||||||
BTimer::BTimer(OBTimerQueueManager *m, TimeoutHandler *h) {
|
OBTimer::OBTimer(TimeoutHandler *h) {
|
||||||
manager = m;
|
|
||||||
handler = h;
|
handler = h;
|
||||||
|
|
||||||
recur = timing = False;
|
recur = timing = False;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BTimer::~BTimer(void) {
|
OBTimer::~OBTimer(void) {
|
||||||
if (timing) stop();
|
if (timing) stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BTimer::setTimeout(long t) {
|
void OBTimer::setTimeout(long t) {
|
||||||
_timeout.tv_sec = t / 1000;
|
_timeout.tv_sec = t / 1000;
|
||||||
_timeout.tv_usec = t % 1000;
|
_timeout.tv_usec = t % 1000;
|
||||||
_timeout.tv_usec *= 1000;
|
_timeout.tv_usec *= 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BTimer::setTimeout(const timeval &t) {
|
void OBTimer::setTimeout(const timeval &t) {
|
||||||
_timeout.tv_sec = t.tv_sec;
|
_timeout.tv_sec = t.tv_sec;
|
||||||
_timeout.tv_usec = t.tv_usec;
|
_timeout.tv_usec = t.tv_usec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BTimer::start(void) {
|
void OBTimer::start(void) {
|
||||||
gettimeofday(&_start, 0);
|
gettimeofday(&_start, 0);
|
||||||
|
|
||||||
if (! timing) {
|
if (! timing) {
|
||||||
timing = True;
|
timing = True;
|
||||||
manager->addTimer(this);
|
Openbox::instance->timerManager()->addTimer(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BTimer::stop(void) {
|
void OBTimer::stop(void) {
|
||||||
timing = False;
|
timing = False;
|
||||||
|
|
||||||
manager->removeTimer(this);
|
Openbox::instance->timerManager()->removeTimer(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BTimer::halt(void) {
|
void OBTimer::halt(void) {
|
||||||
timing = False;
|
timing = False;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void BTimer::fireTimeout(void) {
|
void OBTimer::fireTimeout(void) {
|
||||||
if (handler)
|
if (handler)
|
||||||
handler->timeout();
|
handler->timeout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
timeval BTimer::timeRemaining(const timeval &tm) const {
|
timeval OBTimer::timeRemaining(const timeval &tm) const {
|
||||||
timeval ret = endpoint();
|
timeval ret = endpoint();
|
||||||
|
|
||||||
ret.tv_sec -= tm.tv_sec;
|
ret.tv_sec -= tm.tv_sec;
|
||||||
|
@ -74,7 +74,7 @@ timeval BTimer::timeRemaining(const timeval &tm) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
timeval BTimer::endpoint(void) const {
|
timeval OBTimer::endpoint(void) const {
|
||||||
timeval ret;
|
timeval ret;
|
||||||
|
|
||||||
ret.tv_sec = _start.tv_sec + _timeout.tv_sec;
|
ret.tv_sec = _start.tv_sec + _timeout.tv_sec;
|
||||||
|
@ -84,7 +84,7 @@ timeval BTimer::endpoint(void) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool BTimer::shouldFire(const timeval &tm) const {
|
bool OBTimer::shouldFire(const timeval &tm) const {
|
||||||
timeval end = endpoint();
|
timeval end = endpoint();
|
||||||
|
|
||||||
return ! ((tm.tv_sec < end.tv_sec) ||
|
return ! ((tm.tv_sec < end.tv_sec) ||
|
||||||
|
@ -92,7 +92,7 @@ bool BTimer::shouldFire(const timeval &tm) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OBTimerQueueManager::go()
|
void OBTimerQueueManager::fire()
|
||||||
{
|
{
|
||||||
fd_set rfds;
|
fd_set rfds;
|
||||||
timeval now, tm, *timeout = (timeval *) 0;
|
timeval now, tm, *timeout = (timeval *) 0;
|
||||||
|
@ -103,7 +103,7 @@ void OBTimerQueueManager::go()
|
||||||
FD_SET(xfd, &rfds); // break on any x events
|
FD_SET(xfd, &rfds); // break on any x events
|
||||||
|
|
||||||
if (! timerList.empty()) {
|
if (! timerList.empty()) {
|
||||||
const BTimer* const timer = timerList.top();
|
const OBTimer* const timer = timerList.top();
|
||||||
|
|
||||||
gettimeofday(&now, 0);
|
gettimeofday(&now, 0);
|
||||||
tm = timer->timeRemaining(now);
|
tm = timer->timeRemaining(now);
|
||||||
|
@ -121,7 +121,7 @@ void OBTimerQueueManager::go()
|
||||||
// timer->start() and timer->shouldFire() is within the timer's period
|
// timer->start() and timer->shouldFire() is within the timer's period
|
||||||
// then the timer will keep firing. This should be VERY near impossible.
|
// then the timer will keep firing. This should be VERY near impossible.
|
||||||
while (! timerList.empty()) {
|
while (! timerList.empty()) {
|
||||||
BTimer *timer = timerList.top();
|
OBTimer *timer = timerList.top();
|
||||||
if (! timer->shouldFire(now))
|
if (! timer->shouldFire(now))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -135,13 +135,13 @@ void OBTimerQueueManager::go()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OBTimerQueueManager::addTimer(BTimer *timer)
|
void OBTimerQueueManager::addTimer(OBTimer *timer)
|
||||||
{
|
{
|
||||||
assert(timer);
|
assert(timer);
|
||||||
timerList.push(timer);
|
timerList.push(timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void OBTimerQueueManager::removeTimer(BTimer* timer)
|
void OBTimerQueueManager::removeTimer(OBTimer* timer)
|
||||||
{
|
{
|
||||||
assert(timer);
|
assert(timer);
|
||||||
timerList.release(timer);
|
timerList.release(timer);
|
||||||
|
|
30
src/timer.hh
30
src/timer.hh
|
@ -29,20 +29,19 @@ public:
|
||||||
virtual void timeout(void) = 0;
|
virtual void timeout(void) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BTimer {
|
class OBTimer {
|
||||||
private:
|
private:
|
||||||
OBTimerQueueManager *manager;
|
|
||||||
TimeoutHandler *handler;
|
TimeoutHandler *handler;
|
||||||
bool timing, recur;
|
bool timing, recur;
|
||||||
|
|
||||||
timeval _start, _timeout;
|
timeval _start, _timeout;
|
||||||
|
|
||||||
BTimer(const BTimer&);
|
OBTimer(const OBTimer&);
|
||||||
BTimer& operator=(const BTimer&);
|
OBTimer& operator=(const OBTimer&);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BTimer(OBTimerQueueManager *m, TimeoutHandler *h);
|
OBTimer(TimeoutHandler *h);
|
||||||
virtual ~BTimer(void);
|
virtual ~OBTimer(void);
|
||||||
|
|
||||||
void fireTimeout(void);
|
void fireTimeout(void);
|
||||||
|
|
||||||
|
@ -65,7 +64,7 @@ public:
|
||||||
void stop(void); // manager releases timer
|
void stop(void); // manager releases timer
|
||||||
void halt(void); // halts the timer
|
void halt(void); // halts the timer
|
||||||
|
|
||||||
bool operator<(const BTimer& other) const
|
bool operator<(const OBTimer& other) const
|
||||||
{ return shouldFire(other.endpoint()); }
|
{ return shouldFire(other.endpoint()); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -95,12 +94,13 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TimerLessThan {
|
struct TimerLessThan {
|
||||||
bool operator()(const BTimer* const l, const BTimer* const r) const {
|
bool operator()(const OBTimer* const l, const OBTimer* const r) const {
|
||||||
return *r < *l;
|
return *r < *l;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef _timer_queue<BTimer*, std::vector<BTimer*>, TimerLessThan> TimerQueue;
|
typedef _timer_queue<OBTimer*,
|
||||||
|
std::vector<OBTimer*>, TimerLessThan> TimerQueue;
|
||||||
|
|
||||||
class OBTimerQueueManager {
|
class OBTimerQueueManager {
|
||||||
private:
|
private:
|
||||||
|
@ -108,11 +108,15 @@ private:
|
||||||
public:
|
public:
|
||||||
OBTimerQueueManager() {}
|
OBTimerQueueManager() {}
|
||||||
virtual ~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 go();
|
virtual void addTimer(OBTimer* timer);
|
||||||
|
virtual void removeTimer(OBTimer* timer);
|
||||||
virtual void addTimer(BTimer* timer);
|
|
||||||
virtual void removeTimer(BTimer* timer);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -135,7 +135,7 @@ BlackboxWindow::BlackboxWindow(Blackbox *b, Window w, BScreen *s) {
|
||||||
|
|
||||||
lastButtonPressTime = 0;
|
lastButtonPressTime = 0;
|
||||||
|
|
||||||
timer = new BTimer(blackbox, this);
|
timer = new OBTimer(this);
|
||||||
timer->setTimeout(blackbox->getAutoRaiseDelay());
|
timer->setTimeout(blackbox->getAutoRaiseDelay());
|
||||||
|
|
||||||
// get size, aspect, minimum/maximum size and other hints set by the
|
// get size, aspect, minimum/maximum size and other hints set by the
|
||||||
|
|
|
@ -105,7 +105,7 @@ private:
|
||||||
Blackbox *blackbox;
|
Blackbox *blackbox;
|
||||||
BScreen *screen;
|
BScreen *screen;
|
||||||
XAtom *xatom;
|
XAtom *xatom;
|
||||||
BTimer *timer;
|
OBTimer *timer;
|
||||||
BlackboxAttributes blackbox_attrib;
|
BlackboxAttributes blackbox_attrib;
|
||||||
|
|
||||||
Time lastButtonPressTime; // used for double clicks, when were we clicked
|
Time lastButtonPressTime; // used for double clicks, when were we clicked
|
||||||
|
|
Loading…
Reference in a new issue