all repos — openbox @ 30b899fc025e7fee283be7170bd642b509f5c7b5

openbox fork - make it a bit more like ryudo

converted all of the openbox class LinkedLists to STL objects
Dana Jansens danakj@orodu.net
commit

30b899fc025e7fee283be7170bd642b509f5c7b5

parent

57fb41c8060eaa2f29b25b08e3813b3dc140f165

4 files changed, 118 insertions(+), 219 deletions(-)

jump to
M src/Screen.ccsrc/Screen.cc

@@ -104,6 +104,7 @@

#include <strstream> #include <string> #include <algorithm> +#include <functional> using namespace std; static Bool running = True;

@@ -1155,6 +1156,11 @@ setDateFormat(resource.date_format);

setClock24Hour(resource.clock24hour); #endif // HAVE_STRFTIME setHideToolbar(resource.hide_toolbar); + + toolbar->save(); +#ifdef SLIT + slit->save(); +#endif // SLIT }

@@ -1541,14 +1547,12 @@ #ifdef SLIT

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(); }

@@ -2054,6 +2058,7 @@ netList::iterator it;

for (it = netizenList.begin(); it != netizenList.end(); ++it) (*it)->sendWindowFocus(f); } + void BScreen::updateNetizenWindowAdd(Window w, unsigned long p) { netList::iterator it;

@@ -2737,9 +2742,8 @@

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();
M src/Toolbar.ccsrc/Toolbar.cc

@@ -724,11 +724,11 @@ }

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());
M src/openbox.ccsrc/openbox.cc

@@ -189,25 +189,12 @@

masked_window = NULL; masked = None; - windowSearchList = new LinkedList<WindowSearch>; - menuSearchList = new LinkedList<MenuSearch>; - -#ifdef SLIT - slitSearchList = new LinkedList<SlitSearch>; -#endif // SLIT - - toolbarSearchList = new LinkedList<ToolbarSearch>; - groupSearchList = new LinkedList<WindowSearch>; - - menuTimestamps = new LinkedList<MenuTimestamp>; - load(); #ifdef HAVE_GETPID openbox_pid = XInternAtom(getXDisplay(), "_BLACKBOX_PID", False); #endif // HAVE_GETPID - screenList = new LinkedList<BScreen>; for (int i = 0; i < getNumberOfScreens(); i++) { BScreen *screen = new BScreen(*this, i, config);

@@ -216,16 +203,16 @@ delete screen;

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() { - while (screenList->count()) - delete screenList->remove(0); + for_each(screenList.begin(), screenList.end(), + PointerAssassin()); - while (menuTimestamps->count()) { - MenuTimestamp *ts = menuTimestamps->remove(0); - - 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 @@ delete [] resource.titlebar_layout;

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 @@

} else if ((tbar = searchToolbar(e->xbutton.window))) { tbar->buttonPressEvent(&e->xbutton); } else { - LinkedListIterator<BScreen> 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 @@ }

BScreen *Openbox::searchScreen(Window window) { - LinkedListIterator<BScreen> 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<WindowSearch> 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<WindowSearch> 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<MenuSearch> 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<ToolbarSearch> 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<SlitSearch> 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<WindowSearch> 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<WindowSearch> 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<MenuSearch> 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<ToolbarSearch> 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<SlitSearch> 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 @@ BaseDisplay::shutdown();

XSetInputFocus(getXDisplay(), PointerRoot, None, CurrentTime); - LinkedListIterator<BScreen> 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 @@ (resource.auto_raise_delay.tv_usec / 1000)));

config.setValue("session.cacheLife", (long)resource.cache_life / 60000); config.setValue("session.cacheMax", (long)resource.cache_max); - LinkedListIterator<BScreen> 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 @@ grab();

load(); - for (int i = 0, n = menuTimestamps->count(); i < n; i++) { - MenuTimestamp *ts = menuTimestamps->remove(0); - - if (ts) { - if (ts->filename) - delete [] ts->filename; - - delete ts; - } - } + for_each(menuTimestamps.begin(), menuTimestamps.end(), + PointerAssassin()); + menuTimestamps.clear(); - LinkedListIterator<BScreen> 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<MenuTimestamp> 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::real_rereadMenu() { - for (int i = 0, n = menuTimestamps->count(); i < n; i++) { - MenuTimestamp *ts = menuTimestamps->remove(0); - - if (ts) { - if (ts->filename) - delete [] ts->filename; - - delete ts; - } - } + std::for_each(menuTimestamps.begin(), menuTimestamps.end(), + PointerAssassin()); + menuTimestamps.clear(); - LinkedListIterator<BScreen> 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::setMenuFilename(const char *filename) { - Bool found = False; + bool found = false; - LinkedListIterator<MenuTimestamp> 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 @@

ts->filename = bstrdup(filename); ts->timestamp = buf.st_ctime; - menuTimestamps->insert(ts); + menuTimestamps.push_back(ts); } } }

@@ -1185,7 +1062,10 @@

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(); }
M src/openbox.hsrc/openbox.h

@@ -42,9 +42,11 @@ # endif // HAVE_SYS_TIME_H

#endif // TIME_WITH_SYS_TIME #include "Resource.h" -#include "LinkedList.h" #include "BaseDisplay.h" #include "Timer.h" + +#include <map> +#include <list> //forward declaration class BScreen;

@@ -74,6 +76,10 @@

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 @@ timeval auto_raise_delay;

unsigned long cache_life, cache_max; } resource; - typedef DataSearch<OpenboxWindow> WindowSearch; - LinkedList<WindowSearch> *windowSearchList, *groupSearchList; - typedef DataSearch<Basemenu> MenuSearch; - LinkedList<MenuSearch> *menuSearchList; - typedef DataSearch<Toolbar> ToolbarSearch; - LinkedList<ToolbarSearch> *toolbarSearchList; + typedef std::map<Window, OpenboxWindow*> WindowLookup; + typedef WindowLookup::value_type WindowLookupPair; + WindowLookup windowSearchList, groupSearchList; + + typedef std::map<Window, Basemenu*> MenuLookup; + typedef MenuLookup::value_type MenuLookupPair; + MenuLookup menuSearchList; + + typedef std::map<Window, Toolbar*> ToolbarLookup; + typedef ToolbarLookup::value_type ToolbarLookupPair; + ToolbarLookup toolbarSearchList; #ifdef SLIT - typedef DataSearch<Slit> SlitSearch; - LinkedList<SlitSearch> *slitSearchList; + typedef std::map<Window, Slit*> SlitLookup; + typedef SlitLookup::value_type SlitLookupPair; + SlitLookup slitSearchList; #endif // SLIT - LinkedList<MenuTimestamp> *menuTimestamps; - LinkedList<BScreen> *screenList; + typedef std::list<MenuTimestamp*> MenuTimestampList; + MenuTimestampList menuTimestamps; + + typedef std::list<BScreen*> ScreenList; + ScreenList screenList; BScreen *focused_screen; OpenboxWindow *masked_window;