in synch mode, chew up 100% cpu, cuz we cant select on the display's fd

This commit is contained in:
Dana Jansens 2003-01-07 19:24:38 +00:00
parent 6062fe404c
commit a2de94e91e
6 changed files with 33 additions and 24 deletions

View file

@ -65,8 +65,8 @@ int OBDisplay::xerrorHandler(Display *d, XErrorEvent *e)
{ {
XGetErrorText(d, e->error_code, errtxt, 128); XGetErrorText(d, e->error_code, errtxt, 128);
printf("X Error: %s\n", errtxt); printf("X Error: %s\n", errtxt);
if (e->error_code != BadWindow) // if (e->error_code != BadWindow)
abort(); // abort();
} }
#else #else
(void)d; (void)d;

View file

@ -104,14 +104,14 @@ void OtkEventDispatcher::dispatchEvents(void)
if (e.xfocus.detail == NotifyNonlinear) { if (e.xfocus.detail == NotifyNonlinear) {
focus = e.xfocus.window; focus = e.xfocus.window;
unfocus = None; unfocus = None;
//printf("FocusIn focus=%lx unfocus=%lx\n", focus, unfocus); printf("FocusIn focus=%lx unfocus=%lx\n", focus, unfocus);
} }
} else if (e.type == FocusOut) { } else if (e.type == FocusOut) {
// any other types are not ones we're interested in // any other types are not ones we're interested in
if (e.xfocus.detail == NotifyNonlinear) { if (e.xfocus.detail == NotifyNonlinear) {
unfocus = e.xfocus.window; unfocus = e.xfocus.window;
focus = None; focus = None;
//printf("FocusOut focus=%lx unfocus=%lx\n", focus, unfocus); printf("FocusOut focus=%lx unfocus=%lx\n", focus, unfocus);
} }
// madly compress all crossing events // madly compress all crossing events
} else if (e.type == EnterNotify) { } else if (e.type == EnterNotify) {
@ -120,14 +120,14 @@ void OtkEventDispatcher::dispatchEvents(void)
// any other types are not ones we're interested in // any other types are not ones we're interested in
enter = e.xcrossing.window; enter = e.xcrossing.window;
enter_root = e.xcrossing.root; enter_root = e.xcrossing.root;
//printf("Enter enter=%lx leave=%lx\n", enter, leave); printf("Enter enter=%lx leave=%lx\n", enter, leave);
} }
} else if (e.type == LeaveNotify) { } else if (e.type == LeaveNotify) {
// any other types are not ones we're interested in // any other types are not ones we're interested in
if (e.xcrossing.mode == NotifyNormal) { if (e.xcrossing.mode == NotifyNormal) {
leave = e.xcrossing.window; leave = e.xcrossing.window;
leave_root = e.xcrossing.root; leave_root = e.xcrossing.root;
//printf("Leave enter=%lx leave=%lx\n", enter, leave); printf("Leave enter=%lx leave=%lx\n", enter, leave);
} }
} else { } else {
// normal events // normal events
@ -137,7 +137,7 @@ void OtkEventDispatcher::dispatchEvents(void)
if (unfocus != None) { if (unfocus != None) {
// the last focus event was an FocusOut, so where the hell is the focus at? // the last focus event was an FocusOut, so where the hell is the focus at?
//printf("UNFOCUSING: %lx\n", unfocus); printf("UNFOCUSING: %lx\n", unfocus);
_focus_e.xfocus.type = FocusOut; _focus_e.xfocus.type = FocusOut;
_focus_e.xfocus.window = unfocus; _focus_e.xfocus.window = unfocus;
dispatch(_focus_e.xfocus.window, _focus_e); dispatch(_focus_e.xfocus.window, _focus_e);
@ -146,13 +146,13 @@ void OtkEventDispatcher::dispatchEvents(void)
} else if (focus != None && focus != _focus) { } else if (focus != None && focus != _focus) {
// the last focus event was a FocusIn, so unfocus what used to be focus and // the last focus event was a FocusIn, so unfocus what used to be focus and
// focus this new target // focus this new target
//printf("FOCUSING: %lx\n", focus); printf("FOCUSING: %lx\n", focus);
_focus_e.xfocus.type = FocusIn; _focus_e.xfocus.type = FocusIn;
_focus_e.xfocus.window = focus; _focus_e.xfocus.window = focus;
dispatch(_focus_e.xfocus.window, _focus_e); dispatch(_focus_e.xfocus.window, _focus_e);
if (_focus != None) { if (_focus != None) {
//printf("UNFOCUSING: %lx\n", _focus); printf("UNFOCUSING: %lx\n", _focus);
_focus_e.xfocus.type = FocusOut; _focus_e.xfocus.type = FocusOut;
_focus_e.xfocus.window = _focus; _focus_e.xfocus.window = _focus;
dispatch(_focus_e.xfocus.window, _focus_e); dispatch(_focus_e.xfocus.window, _focus_e);

View file

@ -12501,11 +12501,17 @@ static PyObject *_wrap_delete_OBTimerQueueManager(PyObject *self, PyObject *args
static PyObject *_wrap_OBTimerQueueManager_fire(PyObject *self, PyObject *args) { static PyObject *_wrap_OBTimerQueueManager_fire(PyObject *self, PyObject *args) {
PyObject *resultobj; PyObject *resultobj;
otk::OBTimerQueueManager *arg1 = (otk::OBTimerQueueManager *) 0 ; otk::OBTimerQueueManager *arg1 = (otk::OBTimerQueueManager *) 0 ;
bool arg2 = (bool) true ;
PyObject * obj0 = 0 ; PyObject * obj0 = 0 ;
PyObject * obj1 = 0 ;
if(!PyArg_ParseTuple(args,(char *)"O:OBTimerQueueManager_fire",&obj0)) goto fail; if(!PyArg_ParseTuple(args,(char *)"O|O:OBTimerQueueManager_fire",&obj0,&obj1)) goto fail;
if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_otk__OBTimerQueueManager,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail; if ((SWIG_ConvertPtr(obj0,(void **) &arg1, SWIGTYPE_p_otk__OBTimerQueueManager,SWIG_POINTER_EXCEPTION | 0 )) == -1) SWIG_fail;
(arg1)->fire(); if (obj1) {
arg2 = (bool) PyInt_AsLong(obj1);
if (PyErr_Occurred()) SWIG_fail;
}
(arg1)->fire(arg2);
Py_INCREF(Py_None); resultobj = Py_None; Py_INCREF(Py_None); resultobj = Py_None;
return resultobj; return resultobj;

View file

@ -9,7 +9,7 @@
namespace otk { namespace otk {
void OBTimerQueueManager::fire() void OBTimerQueueManager::fire(bool wait)
{ {
fd_set rfds; fd_set rfds;
timeval now, tm, *timeout = (timeval *) 0; timeval now, tm, *timeout = (timeval *) 0;
@ -19,6 +19,7 @@ void OBTimerQueueManager::fire()
FD_ZERO(&rfds); FD_ZERO(&rfds);
FD_SET(xfd, &rfds); // break on any x events FD_SET(xfd, &rfds); // break on any x events
if (wait) {
if (! timerList.empty()) { if (! timerList.empty()) {
const OBTimer* const timer = timerList.top(); const OBTimer* const timer = timerList.top();
@ -29,6 +30,7 @@ void OBTimerQueueManager::fire()
} }
select(xfd + 1, &rfds, 0, 0, timeout); select(xfd + 1, &rfds, 0, 0, timeout);
}
// check for timer timeout // check for timer timeout
gettimeofday(&now, 0); gettimeofday(&now, 0);

View file

@ -22,11 +22,12 @@ public:
//! Destroys the OBTimerQueueManager //! Destroys the OBTimerQueueManager
virtual ~OBTimerQueueManager() {} virtual ~OBTimerQueueManager() {}
//! Will wait for and fire the next timer in the queue. //! Fire the next timer in the queue.
/*! /*!
The function will stop waiting if an event is received from the X server. @param wait If true, this function will wait for the next timer, breaking
on any events from the X server.
*/ */
virtual void fire(); virtual void fire(bool wait = true);
//! Adds a new timer to the queue //! Adds a new timer to the queue
/*! /*!

View file

@ -306,7 +306,7 @@ void Openbox::showHelp()
void Openbox::eventLoop() void Openbox::eventLoop()
{ {
while (!_shutdown) { while (!_shutdown) {
_timermanager.fire(); _timermanager.fire(!_sync); // wait if not in sync mode
dispatchEvents(); // from OtkEventDispatcher dispatchEvents(); // from OtkEventDispatcher
XFlush(otk::OBDisplay::display); // flush here before we go wait for timers XFlush(otk::OBDisplay::display); // flush here before we go wait for timers
} }