From 30b899fc025e7fee283be7170bd642b509f5c7b5 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Sun, 12 May 2002 20:46:02 +0000 Subject: [PATCH] converted all of the openbox class LinkedLists to STL objects --- src/Screen.cc | 24 +++-- src/Toolbar.cc | 4 +- src/openbox.cc | 272 ++++++++++++++----------------------------------- src/openbox.h | 37 +++++-- 4 files changed, 118 insertions(+), 219 deletions(-) diff --git a/src/Screen.cc b/src/Screen.cc index 73631fbf..60ae159e 100644 --- a/src/Screen.cc +++ b/src/Screen.cc @@ -104,6 +104,7 @@ #include #include #include +#include using namespace std; static Bool running = True; @@ -1155,6 +1156,11 @@ void BScreen::save() { setClock24Hour(resource.clock24hour); #endif // HAVE_STRFTIME setHideToolbar(resource.hide_toolbar); + + toolbar->save(); +#ifdef SLIT + slit->save(); +#endif // SLIT } @@ -1541,14 +1547,12 @@ void BScreen::reconfigure(void) { slit->reconfigure(); #endif // SLIT - wkspList::iterator wit; - for (wit = workspacesList.begin(); wit != workspacesList.end(); ++wit) - (*wit)->reconfigure(); + std::for_each(workspacesList.begin(), workspacesList.end(), + std::mem_fun(&Workspace::reconfigure)); - winList::iterator iit; - for (iit = iconList.begin(); iit != iconList.end(); ++iit) - if ((*iit)->validateClient()) - (*iit)->reconfigure(); + for (winList::iterator it = iconList.begin(); it != iconList.end(); ++it) + if ((*it)->validateClient()) + (*it)->reconfigure(); image_control->timeout(); } @@ -2055,6 +2059,7 @@ void BScreen::updateNetizenWindowFocus(void) { (*it)->sendWindowFocus(f); } + void BScreen::updateNetizenWindowAdd(Window w, unsigned long p) { netList::iterator it; for (it = netizenList.begin(); it != netizenList.end(); ++it) @@ -2737,9 +2742,8 @@ void BScreen::shutdown(void) { XSelectInput(getBaseDisplay().getXDisplay(), getRootWindow(), NoEventMask); XSync(getBaseDisplay().getXDisplay(), False); - wkspList::iterator it; - for (it = workspacesList.begin(); it != workspacesList.end(); ++it) - (*it)->shutdown(); + std::for_each(workspacesList.begin(), workspacesList.end(), + std::mem_fun(&Workspace::shutdown)); while (!iconList.empty()) iconList.front()->restore(); diff --git a/src/Toolbar.cc b/src/Toolbar.cc index 7e28fe62..5d5e924a 100644 --- a/src/Toolbar.cc +++ b/src/Toolbar.cc @@ -724,11 +724,11 @@ void Toolbar::checkClock(Bool redraw, Bool date) { void Toolbar::redrawWindowLabel(Bool redraw) { - if (screen.getOpenbox().focusedWindow()) { + OpenboxWindow *foc = screen.getOpenbox().focusedWindow(); + if (foc != (OpenboxWindow *) 0) { if (redraw) XClearWindow(display, frame.window_label); - OpenboxWindow *foc = screen.getOpenbox().focusedWindow(); if (foc->getScreen() != &screen) return; int dx = (frame.bevel_w * 2), dlen = strlen(*foc->getTitle()); diff --git a/src/openbox.cc b/src/openbox.cc index 3325bf38..8d3b1af1 100644 --- a/src/openbox.cc +++ b/src/openbox.cc @@ -189,25 +189,12 @@ Openbox::Openbox(int m_argc, char **m_argv, char *dpy_name, char *rc) masked_window = NULL; masked = None; - windowSearchList = new LinkedList; - menuSearchList = new LinkedList; - -#ifdef SLIT - slitSearchList = new LinkedList; -#endif // SLIT - - toolbarSearchList = new LinkedList; - groupSearchList = new LinkedList; - - menuTimestamps = new LinkedList; - load(); #ifdef HAVE_GETPID openbox_pid = XInternAtom(getXDisplay(), "_BLACKBOX_PID", False); #endif // HAVE_GETPID - screenList = new LinkedList; for (int i = 0; i < getNumberOfScreens(); i++) { BScreen *screen = new BScreen(*this, i, config); @@ -216,16 +203,16 @@ Openbox::Openbox(int m_argc, char **m_argv, char *dpy_name, char *rc) continue; } - screenList->insert(screen); + screenList.push_back(screen); } - if (! screenList->count()) { + if (screenList.empty()) { fprintf(stderr, i18n->getMessage(openboxSet, openboxNoManagableScreens, "Openbox::Openbox: no managable screens found, aborting.\n")); ::exit(3); } - focused_screen = screenList->first(); + focused_screen = screenList.front(); // save current settings and default values save(); @@ -244,17 +231,11 @@ Openbox::Openbox(int m_argc, char **m_argv, char *dpy_name, char *rc) Openbox::~Openbox() { - while (screenList->count()) - delete screenList->remove(0); - - while (menuTimestamps->count()) { - MenuTimestamp *ts = menuTimestamps->remove(0); + for_each(screenList.begin(), screenList.end(), + PointerAssassin()); - if (ts->filename) - delete [] ts->filename; - - delete ts; - } + for_each(menuTimestamps.begin(), menuTimestamps.end(), + PointerAssassin()); if (resource.menu_file) delete [] resource.menu_file; @@ -267,19 +248,7 @@ Openbox::~Openbox() { delete timer; - delete screenList; - delete menuTimestamps; - - delete windowSearchList; - delete menuSearchList; - delete toolbarSearchList; - delete groupSearchList; - delete [] rc_file; - -#ifdef SLIT - delete slitSearchList; -#endif // SLIT } @@ -323,9 +292,9 @@ void Openbox::process_event(XEvent *e) { } else if ((tbar = searchToolbar(e->xbutton.window))) { tbar->buttonPressEvent(&e->xbutton); } else { - LinkedListIterator it(screenList); - BScreen *screen = it.current(); - for (; screen; it++, screen = it.current()) { + ScreenList::iterator it; + for (it = screenList.begin(); it != screenList.end(); ++it) { + BScreen *screen = *it; if (e->xbutton.window == screen->getRootWindow()) { if (e->xbutton.button == 1) { if (! screen->isRootColormapInstalled()) @@ -774,170 +743,107 @@ Bool Openbox::handleSignal(int sig) { BScreen *Openbox::searchScreen(Window window) { - LinkedListIterator it(screenList); - - for (BScreen *curr = it.current(); curr; it++, curr = it.current()) { - if (curr->getRootWindow() == window) { - return curr; - } - } - + ScreenList::iterator it; + for (it = screenList.begin(); it != screenList.end(); ++it) + if ((*it)->getRootWindow() == window) + return *it; return (BScreen *) 0; } OpenboxWindow *Openbox::searchWindow(Window window) { - LinkedListIterator it(windowSearchList); - - for (WindowSearch *tmp = it.current(); tmp; it++, tmp = it.current()) { - if (tmp->getWindow() == window) { - return tmp->getData(); - } - } - - return (OpenboxWindow *) 0; + WindowLookup::iterator it = windowSearchList.find(window); + if (it == windowSearchList.end()) + return (OpenboxWindow *) 0; + return it->second; } OpenboxWindow *Openbox::searchGroup(Window window, OpenboxWindow *win) { - OpenboxWindow *w = (OpenboxWindow *) 0; - LinkedListIterator it(groupSearchList); - - for (WindowSearch *tmp = it.current(); tmp; it++, tmp = it.current()) { - if (tmp->getWindow() == window) { - w = tmp->getData(); - if (w->getClientWindow() != win->getClientWindow()) - return win; - } - } - + WindowLookup::iterator it = groupSearchList.find(window); + if (it != groupSearchList.end()) + if (it->second->getClientWindow() != win->getClientWindow()) + return win; return (OpenboxWindow *) 0; } Basemenu *Openbox::searchMenu(Window window) { - LinkedListIterator it(menuSearchList); - - for (MenuSearch *tmp = it.current(); tmp; it++, tmp = it.current()) { - if (tmp->getWindow() == window) - return tmp->getData(); - } - - return (Basemenu *) 0; + MenuLookup::iterator it = menuSearchList.find(window); + if (it == menuSearchList.end()) + return (Basemenu *) 0; + return it->second; } Toolbar *Openbox::searchToolbar(Window window) { - LinkedListIterator it(toolbarSearchList); - - for (ToolbarSearch *tmp = it.current(); tmp; it++, tmp = it.current()) { - if (tmp->getWindow() == window) - return tmp->getData(); - } - - return (Toolbar *) 0; + ToolbarLookup::iterator it = toolbarSearchList.find(window); + if (it == toolbarSearchList.end()) + return (Toolbar *) 0; + return it->second; } #ifdef SLIT Slit *Openbox::searchSlit(Window window) { - LinkedListIterator it(slitSearchList); - - for (SlitSearch *tmp = it.current(); tmp; it++, tmp = it.current()) { - if (tmp->getWindow() == window) - return tmp->getData(); - } - - return (Slit *) 0; + SlitLookup::iterator it = slitSearchList.find(window); + if (it == slitSearchList.end()) + return (Slit *) 0; + return it->second; } #endif // SLIT void Openbox::saveWindowSearch(Window window, OpenboxWindow *data) { - windowSearchList->insert(new WindowSearch(window, data)); + windowSearchList.insert(WindowLookupPair(window, data)); } void Openbox::saveGroupSearch(Window window, OpenboxWindow *data) { - groupSearchList->insert(new WindowSearch(window, data)); + groupSearchList.insert(WindowLookupPair(window, data)); } void Openbox::saveMenuSearch(Window window, Basemenu *data) { - menuSearchList->insert(new MenuSearch(window, data)); + menuSearchList.insert(MenuLookupPair(window, data)); } void Openbox::saveToolbarSearch(Window window, Toolbar *data) { - toolbarSearchList->insert(new ToolbarSearch(window, data)); + toolbarSearchList.insert(ToolbarLookupPair(window, data)); } #ifdef SLIT void Openbox::saveSlitSearch(Window window, Slit *data) { - slitSearchList->insert(new SlitSearch(window, data)); + slitSearchList.insert(SlitLookupPair(window, data)); } #endif // SLIT void Openbox::removeWindowSearch(Window window) { - LinkedListIterator it(windowSearchList); - for (WindowSearch *tmp = it.current(); tmp; it++, tmp = it.current()) { - if (tmp->getWindow() == window) { - windowSearchList->remove(tmp); - delete tmp; - break; - } - } + windowSearchList.erase(window); } void Openbox::removeGroupSearch(Window window) { - LinkedListIterator it(groupSearchList); - for (WindowSearch *tmp = it.current(); tmp; it++, tmp = it.current()) { - if (tmp->getWindow() == window) { - groupSearchList->remove(tmp); - delete tmp; - break; - } - } + groupSearchList.erase(window); } void Openbox::removeMenuSearch(Window window) { - LinkedListIterator it(menuSearchList); - for (MenuSearch *tmp = it.current(); tmp; it++, tmp = it.current()) { - if (tmp->getWindow() == window) { - menuSearchList->remove(tmp); - delete tmp; - break; - } - } + menuSearchList.erase(window); } void Openbox::removeToolbarSearch(Window window) { - LinkedListIterator it(toolbarSearchList); - for (ToolbarSearch *tmp = it.current(); tmp; it++, tmp = it.current()) { - if (tmp->getWindow() == window) { - toolbarSearchList->remove(tmp); - delete tmp; - break; - } - } + toolbarSearchList.erase(window); } #ifdef SLIT void Openbox::removeSlitSearch(Window window) { - LinkedListIterator it(slitSearchList); - for (SlitSearch *tmp = it.current(); tmp; it++, tmp = it.current()) { - if (tmp->getWindow() == window) { - slitSearchList->remove(tmp); - delete tmp; - break; - } - } + slitSearchList.erase(window); } #endif // SLIT @@ -961,9 +867,8 @@ void Openbox::shutdown() { XSetInputFocus(getXDisplay(), PointerRoot, None, CurrentTime); - LinkedListIterator it(screenList); - for (BScreen *s = it.current(); s; it++, s = it.current()) - s->shutdown(); + std::for_each(screenList.begin(), screenList.end(), + std::mem_fun(&BScreen::shutdown)); XSync(getXDisplay(), False); } @@ -988,14 +893,8 @@ void Openbox::save() { config.setValue("session.cacheLife", (long)resource.cache_life / 60000); config.setValue("session.cacheMax", (long)resource.cache_max); - LinkedListIterator it(screenList); - for (BScreen *s = it.current(); s != NULL; it++, s = it.current()) { - s->save(); - s->getToolbar()->save(); -#ifdef SLIT - s->getSlit()->save(); -#endif // SLIT - } + std::for_each(screenList.begin(), screenList.end(), + std::mem_fun(&BScreen::save)); config.setAutoSave(true); config.save(); @@ -1075,42 +974,27 @@ void Openbox::real_reconfigure() { load(); - for (int i = 0, n = menuTimestamps->count(); i < n; i++) { - MenuTimestamp *ts = menuTimestamps->remove(0); - - if (ts) { - if (ts->filename) - delete [] ts->filename; + for_each(menuTimestamps.begin(), menuTimestamps.end(), + PointerAssassin()); + menuTimestamps.clear(); - delete ts; - } - } - - LinkedListIterator it(screenList); - for (BScreen *screen = it.current(); screen; it++, screen = it.current()) { - screen->reconfigure(); - } + std::for_each(screenList.begin(), screenList.end(), + std::mem_fun(&BScreen::reconfigure)); ungrab(); } void Openbox::checkMenu() { - Bool reread = False; - LinkedListIterator it(menuTimestamps); - for (MenuTimestamp *tmp = it.current(); tmp && (! reread); - it++, tmp = it.current()) { + MenuTimestampList::iterator it; + for (it = menuTimestamps.begin(); it != menuTimestamps.end(); ++it) { struct stat buf; - if (! stat(tmp->filename, &buf)) { - if (tmp->timestamp != buf.st_ctime) - reread = True; - } else { - reread = True; + if (stat((*it)->filename, &buf) || (*it)->timestamp != buf.st_ctime) { + rereadMenu(); + return; } } - - if (reread) rereadMenu(); } @@ -1122,20 +1006,12 @@ void Openbox::rereadMenu() { void Openbox::real_rereadMenu() { - for (int i = 0, n = menuTimestamps->count(); i < n; i++) { - MenuTimestamp *ts = menuTimestamps->remove(0); + std::for_each(menuTimestamps.begin(), menuTimestamps.end(), + PointerAssassin()); + menuTimestamps.clear(); - if (ts) { - if (ts->filename) - delete [] ts->filename; - - delete ts; - } - } - - LinkedListIterator it(screenList); - for (BScreen *screen = it.current(); screen; it++, screen = it.current()) - screen->rereadMenu(); + std::for_each(screenList.begin(), screenList.end(), + std::mem_fun(&BScreen::rereadMenu)); } @@ -1149,14 +1025,15 @@ void Openbox::setStyleFilename(const char *filename) { void Openbox::setMenuFilename(const char *filename) { - Bool found = False; + bool found = false; - LinkedListIterator it(menuTimestamps); - for (MenuTimestamp *tmp = it.current(); tmp && (! found); - it++, tmp = it.current()) { - if (! strcmp(tmp->filename, filename)) found = True; - } - if (! found) { + MenuTimestampList::iterator it; + for (it = menuTimestamps.begin(); it != menuTimestamps.end(); ++it) + if (! strcmp((*it)->filename, filename)) { + found = true; + break; + } + if (!found) { struct stat buf; if (! stat(filename, &buf)) { @@ -1165,7 +1042,7 @@ void Openbox::setMenuFilename(const char *filename) { ts->filename = bstrdup(filename); ts->timestamp = buf.st_ctime; - menuTimestamps->insert(ts); + menuTimestamps.push_back(ts); } } } @@ -1185,7 +1062,10 @@ void Openbox::timeout() { OpenboxWindow *Openbox::focusedWindow() { if (focused_screen == (BScreen *) 0) return (OpenboxWindow *) 0; - return focused_screen->getCurrentWorkspace()->focusedWindow(); + Workspace *w = focused_screen->getCurrentWorkspace(); + if (w == (Workspace *) 0) + return (OpenboxWindow *) 0; + return w->focusedWindow(); } diff --git a/src/openbox.h b/src/openbox.h index 82abab7a..c62dfa2a 100644 --- a/src/openbox.h +++ b/src/openbox.h @@ -42,10 +42,12 @@ #endif // TIME_WITH_SYS_TIME #include "Resource.h" -#include "LinkedList.h" #include "BaseDisplay.h" #include "Timer.h" +#include +#include + //forward declaration class BScreen; class Openbox; @@ -74,6 +76,10 @@ public: class Openbox : public BaseDisplay, public TimeoutHandler { private: typedef struct MenuTimestamp { + virtual ~MenuTimestamp() { + if (filename != (char *) 0) + delete [] filename; + } char *filename; time_t timestamp; } MenuTimestamp; @@ -88,20 +94,29 @@ private: unsigned long cache_life, cache_max; } resource; - typedef DataSearch WindowSearch; - LinkedList *windowSearchList, *groupSearchList; - typedef DataSearch MenuSearch; - LinkedList *menuSearchList; - typedef DataSearch ToolbarSearch; - LinkedList *toolbarSearchList; + typedef std::map WindowLookup; + typedef WindowLookup::value_type WindowLookupPair; + WindowLookup windowSearchList, groupSearchList; + + typedef std::map MenuLookup; + typedef MenuLookup::value_type MenuLookupPair; + MenuLookup menuSearchList; + + typedef std::map ToolbarLookup; + typedef ToolbarLookup::value_type ToolbarLookupPair; + ToolbarLookup toolbarSearchList; #ifdef SLIT - typedef DataSearch SlitSearch; - LinkedList *slitSearchList; + typedef std::map SlitLookup; + typedef SlitLookup::value_type SlitLookupPair; + SlitLookup slitSearchList; #endif // SLIT - LinkedList *menuTimestamps; - LinkedList *screenList; + typedef std::list MenuTimestampList; + MenuTimestampList menuTimestamps; + + typedef std::list ScreenList; + ScreenList screenList; BScreen *focused_screen; OpenboxWindow *masked_window; -- 2.45.2