X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=src%2FBaseDisplay.cc;h=28742e98a59a563a5286e6454cd18550ce860ecb;hb=63f8386dde9fb610492dd9a10d0a688f16d0dcf4;hp=b9143b77abc3a5b7a36672e636fbacad215fa1fa;hpb=251dd4034f3a3f11a190c06d7b69670dc87d219d;p=chaz%2Fopenbox diff --git a/src/BaseDisplay.cc b/src/BaseDisplay.cc index b9143b77..28742e98 100644 --- a/src/BaseDisplay.cc +++ b/src/BaseDisplay.cc @@ -88,9 +88,10 @@ #include "i18n.h" #include "BaseDisplay.h" -#include "LinkedList.h" #include "Timer.h" +#include + // X error handler to handle any and all X errors while the application is // running static Bool internal_error = False; @@ -244,7 +245,6 @@ BaseDisplay::BaseDisplay(const char *app_name, char *dpy_name) { ::exit(2); } - number_of_screens = ScreenCount(display); display_name = XDisplayName(dpy_name); #ifdef SHAPE @@ -336,13 +336,9 @@ BaseDisplay::BaseDisplay(const char *app_name, char *dpy_name) { XSetErrorHandler((XErrorHandler) handleXErrors); - timerList = new LinkedList; - - screenInfoList = new LinkedList; - for (int i = 0; i < number_of_screens; i++) { - ScreenInfo *screeninfo = new ScreenInfo(*this, i); - screenInfoList->insert(screeninfo); - } + screenInfoList.reserve(numberOfScreens()); + for (unsigned int s = 0; s < numberOfScreens(); s++) + screenInfoList.push_back(new ScreenInfo(*this, s)); #ifndef NOCLOBBER NumLockMask = ScrollLockMask = 0; @@ -390,20 +386,12 @@ BaseDisplay::BaseDisplay(const char *app_name, char *dpy_name) { BaseDisplay::~BaseDisplay(void) { - while (screenInfoList->count()) { - ScreenInfo *si = screenInfoList->first(); - - screenInfoList->remove(si); - delete si; - } - - delete screenInfoList; - + std::for_each(screenInfoList.begin(), screenInfoList.end(), + PointerAssassin()); // we don't create the BTimers, we don't delete them - while (timerList->count()) - timerList->remove(0); - - delete timerList; + + if (application_name != NULL) + delete [] application_name; XCloseDisplay(display); } @@ -437,12 +425,13 @@ void BaseDisplay::eventLoop(void) { FD_ZERO(&rfds); FD_SET(xfd, &rfds); - if (timerList->count()) { + if (!timerList.empty()) { gettimeofday(&now, 0); tm.tv_sec = tm.tv_usec = 0l; - BTimer *timer = timerList->first(); + BTimer *timer = timerList.front(); + ASSERT(timer != NULL); tm.tv_sec = timer->getStartTime().tv_sec + timer->getTimeout().tv_sec - now.tv_sec; @@ -472,8 +461,11 @@ void BaseDisplay::eventLoop(void) { // check for timer timeout gettimeofday(&now, 0); - LinkedListIterator it(timerList); - for(BTimer *timer = it.current(); timer; it++, timer = it.current()) { + TimerList::iterator it; + for (it = timerList.begin(); it != timerList.end(); ) { + BTimer *timer = *it; + ++it; // the timer may be removed from the list, so move ahead now + ASSERT(timer != NULL); tm.tv_sec = timer->getStartTime().tv_sec + timer->getTimeout().tv_sec; tm.tv_usec = timer->getStartTime().tv_usec + @@ -486,8 +478,12 @@ void BaseDisplay::eventLoop(void) { timer->fireTimeout(); // restart the current timer so that the start time is updated - if (! timer->doOnce()) timer->start(); - else timer->stop(); + if (! timer->doOnce()) + timer->start(); + else { + timer->stop(); +// delete timer; // USE THIS? + } } } } @@ -515,28 +511,27 @@ void BaseDisplay::grab(void) { void BaseDisplay::ungrab(void) { if (! --server_grabs) XUngrabServer(display); - - if (server_grabs < 0) server_grabs = 0; } void BaseDisplay::addTimer(BTimer *timer) { - if (! timer) return; + ASSERT(timer != (BTimer *) 0); - LinkedListIterator it(timerList); - int index = 0; - for (BTimer *tmp = it.current(); tmp; it++, index++, tmp = it.current()) + TimerList::iterator it; + for (it = timerList.begin(); it != timerList.end(); ++it) { + BTimer *tmp = *it; if ((tmp->getTimeout().tv_sec > timer->getTimeout().tv_sec) || ((tmp->getTimeout().tv_sec == timer->getTimeout().tv_sec) && (tmp->getTimeout().tv_usec >= timer->getTimeout().tv_usec))) break; + } - timerList->insert(timer, index); + timerList.insert(it, timer); } void BaseDisplay::removeTimer(BTimer *timer) { - timerList->remove(timer); + timerList.remove(timer); }