all repos — openbox @ 57fb41c8060eaa2f29b25b08e3813b3dc140f165

openbox fork - make it a bit more like ryudo

converted the remaining LinkedLists in Screen to STL objects.
Dana Jansens danakj@orodu.net
commit

57fb41c8060eaa2f29b25b08e3813b3dc140f165

parent

addc23faf57c6902a4d9ed2c83a21ada71de6aad

6 files changed, 101 insertions(+), 104 deletions(-)

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

@@ -1,3 +1,4 @@

+#include <iostream.h> // Screen.cc for Openbox // Copyright (c) 2001 Sean 'Shaleh' Perry <shaleh@debian.org> // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)

@@ -237,10 +238,6 @@

XDefineCursor(getBaseDisplay().getXDisplay(), getRootWindow(), openbox.getSessionCursor()); - workspaceNames = new LinkedList<char>; - workspacesList = new LinkedList<Workspace>; - iconList = new LinkedList<OpenboxWindow>; - image_control = new BImageControl(openbox, *this, True, openbox.getColorsPerChannel(), openbox.getCacheLife(), openbox.getCacheMax());

@@ -403,13 +400,14 @@

Workspace *wkspc = NULL; if (resource.workspaces != 0) { for (int i = 0; i < resource.workspaces; ++i) { - wkspc = new Workspace(*this, workspacesList->count()); - workspacesList->insert(wkspc); + wkspc = new Workspace(*this, workspacesList.size()); + workspacesList.push_back(wkspc); workspacemenu->insert(wkspc->getName(), wkspc->getMenu()); } } else { - wkspc = new Workspace(*this, workspacesList->count()); - workspacesList->insert(wkspc); + setWorkspaceCount(1); + wkspc = new Workspace(*this, workspacesList.size()); + workspacesList.push_back(wkspc); workspacemenu->insert(wkspc->getName(), wkspc->getMenu()); } saveWorkspaceNames();

@@ -418,7 +416,7 @@ workspacemenu->insert(i18n->getMessage(IconSet, IconIcons, "Icons"),

iconmenu); workspacemenu->update(); - current_workspace = workspacesList->first(); + current_workspace = workspacesList.front(); workspacemenu->setItemSelected(2, True); toolbar = new Toolbar(*this, config);

@@ -504,17 +502,10 @@ XDestroyWindow(getBaseDisplay().getXDisplay(), geom_window);

removeWorkspaceNames(); - while (workspacesList->count()) - delete workspacesList->remove(0); - - while (!rootmenuList.empty()) - rootmenuList.erase(rootmenuList.begin()); - - while (iconList->count()) - delete iconList->remove(0); - - while (!netizenList.empty()) - netizenList.erase(netizenList.begin()); + std::for_each(workspacesList.begin(), workspacesList.end(), + PointerAssassin()); + std::for_each(iconList.begin(), iconList.end(), PointerAssassin()); + std::for_each(netizenList.begin(), netizenList.end(), PointerAssassin()); #ifdef HAVE_STRFTIME if (resource.strftime_format)

@@ -532,10 +523,6 @@ #endif // SLIT

delete toolbar; delete image_control; - - delete workspacesList; - delete workspaceNames; - delete iconList; if (resource.wstyle.fontset) XFreeFontSet(getBaseDisplay().getXDisplay(), resource.wstyle.fontset);

@@ -1091,6 +1078,7 @@ s.rdbuf()->freeze(0);

} #else // !HAVE_STRFTIME + void BScreen::setDateFormat(int f) { resource.date_format = f; ostrstream s;

@@ -1099,6 +1087,7 @@ config.setValue(s.str(), resource.date_format == B_EuropeanDate ?

"European" : "American"); s.rdbuf()->freeze(0); } + void BScreen::setClock24Hour(Bool c) { resource.clock24hour = c;

@@ -1109,6 +1098,7 @@ s.rdbuf()->freeze(0);

} #endif // HAVE_STRFTIME + void BScreen::setHideToolbar(bool b) { resource.hide_toolbar = b; if (resource.hide_toolbar)

@@ -1120,17 +1110,17 @@ s << "session.screen" << getScreenNumber() << ".hideToolbar" << ends;

config.setValue(s.str(), resource.hide_toolbar ? "True" : "False"); s.rdbuf()->freeze(0); } + void BScreen::saveWorkspaceNames() { ostrstream rc, names; - for (int i = 0; i < resource.workspaces; i++) { - Workspace *w = getWorkspace(i); - if (w != NULL) { - names << w->getName(); - if (i < resource.workspaces-1) - names << ","; - } + wkspList::iterator it; + wkspList::iterator last = workspacesList.end() - 1; + for (it = workspacesList.begin(); it != workspacesList.end(); ++it) { + names << (*it)->getName(); + if (it != last) + names << ","; } names << ends;

@@ -1551,14 +1541,14 @@ #ifdef SLIT

slit->reconfigure(); #endif // SLIT - LinkedListIterator<Workspace> wit(workspacesList); - for (Workspace *w = wit.current(); w; wit++, w = wit.current()) - w->reconfigure(); + wkspList::iterator wit; + for (wit = workspacesList.begin(); wit != workspacesList.end(); ++wit) + (*wit)->reconfigure(); - LinkedListIterator<OpenboxWindow> iit(iconList); - for (OpenboxWindow *bw = iit.current(); bw; iit++, bw = iit.current()) - if (bw->validateClient()) - bw->reconfigure(); + winList::iterator iit; + for (iit = iconList.begin(); iit != iconList.end(); ++iit) + if ((*iit)->validateClient()) + (*iit)->reconfigure(); image_control->timeout(); }

@@ -1573,8 +1563,7 @@ }

void BScreen::removeWorkspaceNames(void) { - while (workspaceNames->count()) - delete [] workspaceNames->remove(0); + workspaceNames.clear(); }

@@ -1898,9 +1887,9 @@ void BScreen::addIcon(OpenboxWindow *w) {

if (! w) return; w->setWorkspace(-1); - w->setWindowNumber(iconList->count()); + w->setWindowNumber(iconList.size()); - iconList->insert(w); + iconList.push_back(w); iconmenu->insert((const char **) w->getIconTitle()); iconmenu->update();

@@ -1910,29 +1899,30 @@

void BScreen::removeIcon(OpenboxWindow *w) { if (! w) return; - iconList->remove(w->getWindowNumber()); + iconList.remove(w); iconmenu->remove(w->getWindowNumber()); iconmenu->update(); - LinkedListIterator<OpenboxWindow> it(iconList); - OpenboxWindow *bw = it.current(); - for (int i = 0; bw; it++, bw = it.current()) - bw->setWindowNumber(i++); + winList::iterator it = iconList.begin(); + for (int i = 0; it != iconList.end(); ++it, ++i) + (*it)->setWindowNumber(i); } OpenboxWindow *BScreen::getIcon(int index) { - if (index >= 0 && index < iconList->count()) - return iconList->find(index); + if (index < 0 || index >= iconList.size()) + return (OpenboxWindow *) 0; - return NULL; + winList::iterator it = iconList.begin(); + for (; index > 0; --index, ++it); // increment to index + return *it; } int BScreen::addWorkspace(void) { - Workspace *wkspc = new Workspace(*this, workspacesList->count()); - workspacesList->insert(wkspc); + Workspace *wkspc = new Workspace(*this, workspacesList.size()); + workspacesList.push_back(wkspc); setWorkspaceCount(workspaceCount()+1); saveWorkspaceNames();

@@ -1944,15 +1934,15 @@ toolbar->reconfigure();

updateNetizenWorkspaceCount(); - return workspacesList->count(); + return workspacesList.size(); } int BScreen::removeLastWorkspace(void) { - if (workspacesList->count() == 1) + if (workspacesList.size() == 1) return 0; - Workspace *wkspc = workspacesList->last(); + Workspace *wkspc = workspacesList.back(); if (current_workspace->getWorkspaceID() == wkspc->getWorkspaceID()) changeWorkspaceID(current_workspace->getWorkspaceID() - 1);

@@ -1962,8 +1952,9 @@

workspacemenu->remove(wkspc->getWorkspaceID() + 2); workspacemenu->update(); - workspacesList->remove(wkspc); + workspacesList.pop_back(); delete wkspc; + setWorkspaceCount(workspaceCount()-1); saveWorkspaceNames();

@@ -1971,7 +1962,7 @@ toolbar->reconfigure();

updateNetizenWorkspaceCount(); - return workspacesList->count(); + return workspacesList.size(); }

@@ -2015,11 +2006,11 @@

n->sendWorkspaceCount(); n->sendCurrentWorkspace(); - LinkedListIterator<Workspace> it(workspacesList); - for (Workspace *w = it.current(); w; it++, w = it.current()) { - for (int i = 0; i < w->getCount(); i++) - n->sendWindowAdd(w->getWindow(i)->getClientWindow(), - w->getWorkspaceID()); + wkspList::iterator it; + for (it = workspacesList.begin(); it != workspacesList.end(); ++it) { + for (int i = 0; i < (*it)->getCount(); i++) + n->sendWindowAdd((*it)->getWindow(i)->getClientWindow(), + (*it)->getWorkspaceID()); } Window f = ((openbox.focusedWindow()) ?

@@ -2101,15 +2092,15 @@

void BScreen::raiseWindows(Window *workspace_stack, int num) { Window *session_stack = new - Window[(num + workspacesList->count() + rootmenuList.size() + 13)]; + Window[(num + workspacesList.size() + rootmenuList.size() + 13)]; int i = 0, k = num; XRaiseWindow(getBaseDisplay().getXDisplay(), iconmenu->getWindowID()); *(session_stack + i++) = iconmenu->getWindowID(); - LinkedListIterator<Workspace> wit(workspacesList); - for (Workspace *tmp = wit.current(); tmp; wit++, tmp = wit.current()) - *(session_stack + i++) = tmp->getMenu()->getWindowID(); + wkspList::iterator it; + for (it = workspacesList.begin(); it != workspacesList.end(); ++it) + *(session_stack + i++) = (*it)->getMenu()->getWindowID(); *(session_stack + i++) = workspacemenu->getWindowID();

@@ -2150,19 +2141,14 @@ }

void BScreen::addWorkspaceName(const char *name) { - workspaceNames->insert(bstrdup(name)); + workspaceNames.push_back(name); } -char* BScreen::getNameOfWorkspace(int id) { - char *name = NULL; - if (id >= 0 && id < workspaceNames->count()) { - char *wkspc_name = workspaceNames->find(id); - - if (wkspc_name) - name = wkspc_name; - } - return name; +const char *BScreen::getNameOfWorkspace(int id) { + if (id < 0 || id >= workspaceNames.size()) + return (const char *) 0; + return workspaceNames[id].c_str(); }

@@ -2273,9 +2259,7 @@

void BScreen::InitMenu(void) { if (rootmenu) { - while (!rootmenuList.empty()) - rootmenuList.erase(rootmenuList.begin()); - + rootmenuList.clear(); while (rootmenu->getCount()) rootmenu->remove(0); } else {

@@ -2753,14 +2737,12 @@

XSelectInput(getBaseDisplay().getXDisplay(), getRootWindow(), NoEventMask); XSync(getBaseDisplay().getXDisplay(), False); - LinkedListIterator<Workspace> it(workspacesList); - for (Workspace *w = it.current(); w; it++, w = it.current()) - w->shutdown(); + wkspList::iterator it; + for (it = workspacesList.begin(); it != workspacesList.end(); ++it) + (*it)->shutdown(); - while (iconList->count()) { - iconList->first()->restore(); - delete iconList->first(); - } + while (!iconList.empty()) + iconList.front()->restore(); #ifdef SLIT slit->shutdown();
M src/Screen.hsrc/Screen.h

@@ -40,7 +40,6 @@

#include "BaseDisplay.h" #include "Configmenu.h" #include "Iconmenu.h" -#include "LinkedList.h" #include "Netizen.h" #include "Rootmenu.h" #include "Timer.h"

@@ -52,10 +51,14 @@ # include "Slit.h"

#endif // SLIT #include "Image.h" #include "Resource.h" +#include "Util.h" #include <list> +#include <vector> typedef std::list<Rootmenu *> menuList; typedef std::list<Netizen *> netList; +typedef std::vector<Workspace *> wkspList; +typedef std::vector<std::string> wkspNameList; // forward declaration class BScreen;

@@ -115,7 +118,7 @@ Rootmenu *rootmenu;

menuList rootmenuList; netList netizenList; - LinkedList<OpenboxWindow> *iconList; + winList iconList; // winList is declared in Workspace.h #ifdef SLIT Slit *slit;

@@ -128,8 +131,8 @@

unsigned int geom_w, geom_h; unsigned long event_mask; - LinkedList<char> *workspaceNames; - LinkedList<Workspace> *workspacesList; + wkspNameList workspaceNames; + wkspList workspacesList; struct resource { WindowStyle wstyle;

@@ -193,7 +196,10 @@ inline Toolbar *getToolbar() { return toolbar; }

Rect availableArea() const; - inline Workspace *getWorkspace(int w) { return workspacesList->find(w); } + inline Workspace *getWorkspace(int w) { + ASSERT(w < workspacesList.size()); + return workspacesList[w]; + } inline Workspace *getCurrentWorkspace() { return current_workspace; } inline Workspacemenu *getWorkspacemenu() { return workspacemenu; }

@@ -211,8 +217,8 @@ { return resource.border_width; }

inline const int getCurrentWorkspaceID() { return current_workspace->getWorkspaceID(); } - inline const int getWorkspaceCount() { return workspacesList->count(); } - inline const int getIconCount() { return iconList->count(); } + inline const int getWorkspaceCount() { return workspacesList.size(); } + inline const int getIconCount() { return iconList.size(); } inline const Bool &isRootColormapInstalled() const { return root_colormap_installed; }

@@ -291,7 +297,7 @@ void addNetizen(Netizen *);

void removeNetizen(Window); void addIcon(OpenboxWindow *); void removeIcon(OpenboxWindow *); - char* getNameOfWorkspace(int); + const char *getNameOfWorkspace(int); void changeWorkspaceID(int); void raiseWindows(Window *, int); void reassociateWindow(OpenboxWindow *, int, Bool);
M src/Util.hsrc/Util.h

@@ -29,4 +29,11 @@ #else // !DEBUG

# define ASSERT(x) #endif // DEBUG +struct PointerAssassin { + template<typename T> + inline void operator()(const T ptr) const { + delete ptr; + } +}; + #endif // __Util_hh
M src/Window.ccsrc/Window.cc

@@ -3054,6 +3054,8 @@ client.x, client.y);

XMapWindow(display, client.window); XFlush(display); + + delete this; }
M src/Workspace.ccsrc/Workspace.cc

@@ -71,8 +71,7 @@

lastfocus = (OpenboxWindow *) 0; name = (char *) 0; - char *tmp = screen.getNameOfWorkspace(id); - setName(tmp); + setName(screen.getNameOfWorkspace(id)); }

@@ -297,7 +296,7 @@ screen.changeWorkspaceID(id);

} -void Workspace::setName(char *new_name) { +void Workspace::setName(const char *new_name) { if (name) delete [] name;

@@ -316,10 +315,8 @@ }

void Workspace::shutdown(void) { - while (!_windows.empty()) { + while (!_windows.empty()) _windows[0]->restore(); - delete _windows[0]; - } } static rectList calcSpace(const Rect &win, const rectList &spaces) {

@@ -420,7 +417,8 @@ rectList::const_iterator siter;

spaces.push_back(space); //initially the entire screen is free //Find Free Spaces - for (winVect::iterator it = _windows.begin(); it != _windows.end(); ++it) + winVect::iterator it; + for (it = _windows.begin(); it != _windows.end(); ++it) spaces = calcSpace((*it)->area().Inflate(screen.getBorderWidth() * 4), spaces);

@@ -474,7 +472,8 @@ rectList::const_iterator siter;

spaces.push_back(space); //initially the entire screen is free //Find Free Spaces - for (winVect::iterator it = _windows.begin(); it != _windows.end(); ++it) + winVect::iterator it; + for (it = _windows.begin(); it != _windows.end(); ++it) spaces = calcSpace((*it)->area().Inflate(screen.getBorderWidth() * 4), spaces); //Sort spaces by preference

@@ -514,7 +513,8 @@ rectList::const_iterator siter;

spaces.push_back(space); //initially the entire screen is free //Find Free Spaces - for (winVect::iterator it = _windows.begin(); it != _windows.end(); ++it) + winVect::iterator it; + for (it = _windows.begin(); it != _windows.end(); ++it) spaces = calcSpace((*it)->area().Inflate(screen.getBorderWidth() * 4), spaces); //Sort spaces by user preference
M src/Workspace.hsrc/Workspace.h

@@ -85,7 +85,7 @@ void lowerWindow(OpenboxWindow *);

void reconfigure(); void update(); void setCurrent(void); - void setName(char *); + void setName(const char *); void shutdown(void); };