all repos — fluxbox @ 12e1ef78265a621dc51f7b9af245d81431835dcc

custom fork of the fluxbox windowmanager

code deduplication by using <algorithm> and FbTk/STLUtil.hh
Mathias Gumz akira at fluxbox dot org
commit

12e1ef78265a621dc51f7b9af245d81431835dcc

parent

ba316aa18a8813958cedea1cc4d54452e40c4b59

M src/FbTk/Container.ccsrc/FbTk/Container.cc

@@ -26,6 +26,7 @@ #include "Button.hh"

#include "TextUtils.hh" #include "EventManager.hh" #include "CompareEqual.hh" +#include "STLUtil.hh" #include <algorithm>

@@ -78,7 +79,7 @@ m_item_list.push_back(item);

} else if (pos == 0) { m_item_list.push_front(item); } else { - ItemList::iterator it = m_item_list.begin(); + ItemList::iterator it = begin(); for (; pos != 0; ++it, --pos) continue;

@@ -104,12 +105,10 @@ int newindex = (index + movement) % static_cast<signed>(size);

if (newindex < 0) // neg wrap newindex += size; - ItemList::iterator it = std::find(m_item_list.begin(), - m_item_list.end(), - item); + ItemList::iterator it = std::find(begin(), end(), item); m_item_list.erase(it); - for (it = m_item_list.begin(); newindex >= 0; ++it, --newindex) { + for (it = begin(); newindex >= 0; ++it, --newindex) { if (newindex == 0) { break; }

@@ -143,12 +142,11 @@ x, y, &dest_x, &dest_y,

&itemwin)) return false; - ItemList::iterator it = find_if(m_item_list.begin(), - m_item_list.end(), + ItemList::iterator it = find_if(begin(), end(), CompareWindow(&FbWindow::window, itemwin)); // not found :( - if (it == m_item_list.end()) + if (it == end()) return false; Window child_return = 0;

@@ -162,8 +160,8 @@ return true;

} bool Container::removeItem(Item item) { - ItemList::iterator it = m_item_list.begin(); - ItemList::iterator it_end = m_item_list.end(); + ItemList::iterator it = begin(); + ItemList::iterator it_end = end(); for (; it != it_end && (*it) != item; ++it); if (it == it_end)

@@ -178,7 +176,7 @@ bool Container::removeItem(int index) {

if (index < 0 || index > size()) return false; - ItemList::iterator it = m_item_list.begin(); + ItemList::iterator it = begin(); for (; index != 0; ++it, --index) continue;

@@ -247,12 +245,11 @@ exposeEvent(event);

return true; } - ItemList::iterator it = find_if(m_item_list.begin(), - m_item_list.end(), + ItemList::iterator it = find_if(begin(), end(), CompareWindow(&FbWindow::window, event.window)); // not found :( - if (it == m_item_list.end()) + if (it == end()) return false; (*it)->exposeEvent(event);

@@ -265,12 +262,11 @@ // we don't have a buttonrelease event atm

return true; } - ItemList::iterator it = find_if(m_item_list.begin(), - m_item_list.end(), + ItemList::iterator it = find_if(begin(), end(), CompareWindow(&FbWindow::window, event.window)); // not found :( - if (it == m_item_list.end()) + if (it == end()) return false; (*it)->buttonPressEvent(event);

@@ -283,12 +279,11 @@ // we don't have a buttonrelease event atm

return true; } - ItemList::iterator it = find_if(m_item_list.begin(), - m_item_list.end(), + ItemList::iterator it = find_if(begin(), end(), CompareWindow(&FbWindow::window, event.window)); // not found :( - if (it == m_item_list.end()) + if (it == end()) return false; (*it)->buttonReleaseEvent(event);

@@ -360,8 +355,8 @@ }

} - ItemList::iterator it = m_item_list.begin(); - const ItemList::iterator it_end = m_item_list.end(); + ItemList::iterator it = begin(); + const ItemList::iterator it_end = end(); int rounding_error = 0;

@@ -442,41 +437,26 @@ return 1;

} void Container::for_each(std::mem_fun_t<void, FbWindow> function) { - std::for_each(m_item_list.begin(), - m_item_list.end(), - function); + std::for_each(begin(), end(), function); } void Container::setAlpha(unsigned char alpha) { FbWindow::setAlpha(alpha); - ItemList::iterator it = m_item_list.begin(); - ItemList::iterator it_end = m_item_list.end(); - for (; it != it_end; ++it) - (*it)->setAlpha(alpha); + STLUtil::forAll(m_item_list, std::bind2nd(std::mem_fun(&Button::setAlpha), alpha)); } void Container::parentMoved() { FbWindow::parentMoved(); - ItemList::iterator it = m_item_list.begin(); - ItemList::iterator it_end = m_item_list.end(); - for (; it != it_end; ++it) - (*it)->parentMoved(); + STLUtil::forAll(m_item_list, std::mem_fun(&Button::parentMoved)); } void Container::invalidateBackground() { FbWindow::invalidateBackground(); - ItemList::iterator it = m_item_list.begin(); - ItemList::iterator it_end = m_item_list.end(); - for (; it != it_end; ++it) - (*it)->invalidateBackground(); + STLUtil::forAll(m_item_list, std::mem_fun(&Button::invalidateBackground)); } void Container::clear() { - ItemList::iterator it = m_item_list.begin(); - ItemList::iterator it_end = m_item_list.end(); - for (; it != it_end; ++it) - (*it)->clear(); - + STLUtil::forAll(m_item_list, std::mem_fun(&Button::clear)); } void Container::setOrientation(Orientation orient) {

@@ -484,11 +464,7 @@ if (m_orientation == orient)

return; FbWindow::invalidateBackground(); - - ItemList::iterator it = m_item_list.begin(); - ItemList::iterator it_end = m_item_list.end(); - for (; it != it_end; ++it) - (*it)->setOrientation(orient); + STLUtil::forAll(m_item_list, std::bind2nd(std::mem_fun(&Button::setOrientation), orient)); if (((m_orientation == ROT0 || m_orientation == ROT180) && (orient == ROT90 || orient == ROT270)) ||
M src/FbTk/STLUtil.hhsrc/FbTk/STLUtil.hh

@@ -68,6 +68,33 @@ delete it->second;

a.clear(); } + +template <typename C, typename F> +F forAll(C& c, F f) { + typedef typename C::iterator iterator; + iterator i = c.begin(); + iterator e = c.end(); + for (; i != e; i++) { + f(*i); + } + return f; +} + +template <typename C, typename I, typename F> +F forAllIf(C& c, I i, F f) { + typedef typename C::iterator iterator; + iterator it = c.begin(); + iterator end = c.end(); + for (; it != end; it++) { + if (i(*it)) + f(*it); + } + return f; +} + + + + } // end namespace STLUtil } // end namespace FbTk
M src/FbTk/Theme.ccsrc/FbTk/Theme.cc

@@ -27,6 +27,7 @@ #include "StringUtil.hh"

#include "FileUtil.hh" #include "I18n.hh" #include "Image.hh" +#include "STLUtil.hh" #ifdef HAVE_CSTDIO #include <cstdio>

@@ -50,13 +51,11 @@ m_tm.loadTheme(*tm);

} void operator ()(ThemeManager::ThemeList &tmlist) { - for_each(tmlist.begin(), tmlist.end(), - *this); + STLUtil::forAll(tmlist, *this); // send reconfiguration signal to theme and listeners ThemeManager::ThemeList::iterator it = tmlist.begin(); ThemeManager::ThemeList::iterator it_end = tmlist.end(); for (; it != it_end; ++it) { - (*it)->reconfigTheme(); (*it)->reconfigSig().notify(); } }

@@ -174,9 +173,7 @@

// get list and go throu all the resources and load them // and then reconfigure them if (screen_num < 0 || screen_num > m_max_screens) { - for_each(m_themes.begin(), - m_themes.end(), - load_theme_helper); + STLUtil::forAll(m_themes, load_theme_helper); } else { load_theme_helper(m_themes[screen_num]); }
M src/FbWinFrame.ccsrc/FbWinFrame.cc

@@ -29,6 +29,7 @@ #include "FbTk/Compose.hh"

#include "FbTk/Transparent.hh" #include "FbTk/CompareEqual.hh" #include "FbTk/TextUtils.hh" +#include "FbTk/STLUtil.hh" #include "FbWinFrameTheme.hh" #include "Screen.hh"

@@ -41,6 +42,8 @@

using std::max; using std::mem_fun; using std::string; + +using FbTk::STLUtil::forAll; FbWinFrame::FbWinFrame(BScreen &screen, WindowState &state, FocusableTheme<FbWinFrameTheme> &theme):

@@ -439,12 +442,8 @@ m_label.parentMoved();

m_titlebar.parentMoved(); - for_each(m_buttons_left.begin(), - m_buttons_left.end(), - mem_fun(&FbTk::Button::parentMoved)); - for_each(m_buttons_right.begin(), - m_buttons_right.end(), - mem_fun(&FbTk::Button::parentMoved)); + forAll(m_buttons_left, mem_fun(&FbTk::Button::parentMoved)); + forAll(m_buttons_right, mem_fun(&FbTk::Button::parentMoved)); } if (m_use_handle) {

@@ -463,13 +462,8 @@ void FbWinFrame::clearAll() {

if (m_use_titlebar) { redrawTitlebar(); - - for_each(m_buttons_left.begin(), - m_buttons_left.end(), - mem_fun(&FbTk::Button::clear)); - for_each(m_buttons_right.begin(), - m_buttons_right.end(), - mem_fun(&FbTk::Button::clear)); + forAll(m_buttons_left, mem_fun(&FbTk::Button::clear)); + forAll(m_buttons_right, mem_fun(&FbTk::Button::clear)); } else if (m_tabmode == EXTERNAL && m_use_tabs) m_tab_container.clear();
M src/IconbarTool.ccsrc/IconbarTool.cc

@@ -48,6 +48,9 @@ #include "FbTk/ImageControl.hh"

#include "FbTk/MacroCommand.hh" #include "FbTk/MenuSeparator.hh" #include "FbTk/Util.hh" +#include "FbTk/STLUtil.hh" +#include "FbTk/Select2nd.hh" +#include "FbTk/Compose.hh" #include <typeinfo> #include <iterator>

@@ -465,10 +468,9 @@ void IconbarTool::updateSizing() {

m_icon_container.setBorderWidth(m_theme.border().width()); m_icon_container.setBorderColor(m_theme.border().color()); - IconMap::iterator icon_it = m_icons.begin(); - const IconMap::iterator icon_it_end = m_icons.end(); - for (; icon_it != icon_it_end; ++icon_it) - icon_it->second->reconfigTheme(); + FbTk::STLUtil::forAll(m_icons, + FbTk::Compose(std::mem_fun(&IconButton::reconfigTheme), + FbTk::Select2nd<IconMap::value_type>())); }
M src/fluxbox.ccsrc/fluxbox.cc

@@ -387,10 +387,7 @@ addAtomHandler(new Remember()); // for remembering window attribs

#endif // REMEMBER // init all "screens" - ScreenList::iterator it = m_screen_list.begin(); - ScreenList::iterator it_end = m_screen_list.end(); - for(; it != it_end; ++it) - initScreen(*it); + STLUtil::forAll(m_screen_list, bind1st(mem_fun(&Fluxbox::initScreen), this)); XAllowEvents(disp, ReplayPointer, CurrentTime);

@@ -435,11 +432,9 @@ void Fluxbox::initScreen(BScreen *screen) {

// now we can create menus (which needs this screen to be in screen_list) screen->initMenus(); - screen->initWindows(); // attach screen signals to this - join(screen->workspaceAreaSig(), FbTk::MemFun(*this, &Fluxbox::workspaceAreaChanged));

@@ -458,11 +453,7 @@ join(screen->workspaceCountSig(),

FbTk::MemFun(*this, &Fluxbox::workspaceCountChanged)); // initiate atomhandler for screen specific stuff - for (AtomHandlerContainerIt it= m_atomhandler.begin(); - it != m_atomhandler.end(); - it++) { - (*it)->initForScreen(*screen); - } + STLUtil::forAll(m_atomhandler, bind2nd(mem_fun(&AtomHandler::initForScreen), *screen)); FocusControl::revertFocus(*screen); // make sure focus style is correct

@@ -984,11 +975,9 @@ client = dynamic_cast<WinClient *>(&winsub->win());

} if (fbwin && &fbwin->stateSig() == changedsub) { // state signal - for (AtomHandlerContainerIt it= m_atomhandler.begin(); - it != m_atomhandler.end(); ++it) { - if ((*it)->update()) - (*it)->updateState(*fbwin); - } + STLUtil::forAllIf(m_atomhandler, mem_fun(&AtomHandler::update), + bind2nd(mem_fun(&AtomHandler::updateState), *fbwin)); + // if window changed to iconic state // add to icon list if (fbwin->isIconic()) {

@@ -1009,17 +998,11 @@ true);

} } } else if (fbwin && &fbwin->layerSig() == changedsub) { // layer signal - AtomHandlerContainerIt it= m_atomhandler.begin(); - for (; it != m_atomhandler.end(); ++it) { - if ((*it)->update()) - (*it)->updateLayer(*fbwin); - } + STLUtil::forAllIf(m_atomhandler, mem_fun(&AtomHandler::update), + bind2nd(mem_fun(&AtomHandler::updateLayer), *fbwin)); } else if (fbwin && &fbwin->dieSig() == changedsub) { // window death signal - AtomHandlerContainerIt it= m_atomhandler.begin(); - for (; it != m_atomhandler.end(); ++it) { - if ((*it)->update()) - (*it)->updateFrameClose(*fbwin); - } + STLUtil::forAllIf(m_atomhandler, mem_fun(&AtomHandler::update), + bind2nd(mem_fun(&AtomHandler::updateFrameClose), *fbwin)); // make sure each workspace get this BScreen &scr = fbwin->screen();

@@ -1027,17 +1010,11 @@ scr.removeWindow(fbwin);

if (FocusControl::focusedFbWindow() == fbwin) FocusControl::setFocusedFbWindow(0); } else if (fbwin && &fbwin->workspaceSig() == changedsub) { // workspace signal - for (AtomHandlerContainerIt it= m_atomhandler.begin(); - it != m_atomhandler.end(); ++it) { - if ((*it)->update()) - (*it)->updateWorkspace(*fbwin); - } + STLUtil::forAllIf(m_atomhandler, mem_fun(&AtomHandler::update), + bind2nd(mem_fun(&AtomHandler::updateClientClose), *fbwin)); } else if (client && &client->dieSig() == changedsub) { // client death - for (AtomHandlerContainerIt it= m_atomhandler.begin(); - it != m_atomhandler.end(); ++it) { - if ((*it)->update()) - (*it)->updateClientClose(*client); - } + STLUtil::forAllIf(m_atomhandler, mem_fun(&AtomHandler::update), + bind2nd(mem_fun(&AtomHandler::updateClientClose), *client)); BScreen &screen = client->screen();

@@ -1066,19 +1043,12 @@ win.stateSig().attach(this);

win.workspaceSig().attach(this); win.layerSig().attach(this); win.dieSig().attach(this); - for (AtomHandlerContainerIt it= m_atomhandler.begin(); - it != m_atomhandler.end(); ++it) { - (*it)->setupFrame(win); - } + STLUtil::forAll(m_atomhandler, bind2nd(mem_fun(&AtomHandler::setupFrame), win)); } void Fluxbox::attachSignals(WinClient &winclient) { winclient.dieSig().attach(this); - - for (AtomHandlerContainerIt it= m_atomhandler.begin(); - it != m_atomhandler.end(); ++it) { - (*it)->setupClient(winclient); - } + STLUtil::forAll(m_atomhandler, bind2nd(mem_fun(&AtomHandler::setupClient), winclient)); } BScreen *Fluxbox::searchScreen(Window window) {

@@ -1178,9 +1148,7 @@ m_shutdown = true;

XSetInputFocus(FbTk::App::instance()->display(), PointerRoot, None, CurrentTime); - //send shutdown to all screens - for_each(m_screen_list.begin(), - m_screen_list.end(), mem_fun(&BScreen::shutdown)); + STLUtil::forAll(m_screen_list, mem_fun(&BScreen::shutdown)); sync(false); }

@@ -1353,32 +1321,21 @@ ScreenList::iterator screen_it_end = m_screen_list.end();

for (; screen_it != screen_it_end; ++screen_it) load_rc(*(*screen_it)); - // reconfigure all screens - for_each(m_screen_list.begin(), m_screen_list.end(), mem_fun(&BScreen::reconfigure)); - - //reconfigure keys + STLUtil::forAll(m_screen_list, mem_fun(&BScreen::reconfigure)); m_key->reconfigure(); - - // and atomhandlers - for (AtomHandlerContainerIt it= m_atomhandler.begin(); - it != m_atomhandler.end(); - it++) { - (*it)->reconfigure(); - } + STLUtil::forAll(m_atomhandler, mem_fun(&AtomHandler::reconfigure)); } BScreen *Fluxbox::findScreen(int id) { - ScreenList::iterator it = m_screen_list.begin(); - ScreenList::iterator it_end = m_screen_list.end(); - for (; it != it_end; ++it) { - if ((*it)->screenNumber() == id) - break; - } + + BScreen* result = 0; + ScreenList::iterator it = find_if(m_screen_list.begin(), m_screen_list.end(), + FbTk::CompareEqual<BScreen>(&BScreen::screenNumber, id)); - if (it == m_screen_list.end()) - return 0; + if (it != m_screen_list.end()) + result = *it; - return *it; + return result; } void Fluxbox::timed_reconfigure() {

@@ -1426,48 +1383,33 @@ return it != m_window_search.end();

} void Fluxbox::updateFrameExtents(FluxboxWindow &win) { - AtomHandlerContainerIt it = m_atomhandler.begin(); - AtomHandlerContainerIt it_end = m_atomhandler.end(); - for (; it != it_end; ++it ) { - (*it)->updateFrameExtents(win); - } + STLUtil::forAll(m_atomhandler, bind2nd(mem_fun(&AtomHandler::updateFrameExtents), win)); } void Fluxbox::workspaceCountChanged( BScreen& screen ) { - for (AtomHandlerContainerIt it= m_atomhandler.begin(); - it != m_atomhandler.end(); ++it) { - if ((*it)->update()) - (*it)->updateWorkspaceCount(screen); - } + STLUtil::forAllIf(m_atomhandler, mem_fun(&AtomHandler::update), + bind2nd(mem_fun(&AtomHandler::updateWorkspaceCount), screen)); } void Fluxbox::workspaceChanged( BScreen& screen ) { - for (AtomHandlerContainerIt it= m_atomhandler.begin(); - it != m_atomhandler.end(); ++it) { - if ((*it)->update()) - (*it)->updateCurrentWorkspace(screen); - } + STLUtil::forAllIf(m_atomhandler, mem_fun(&AtomHandler::update), + bind2nd(mem_fun(&AtomHandler::updateCurrentWorkspace), screen)); } void Fluxbox::workspaceNamesChanged(BScreen &screen) { - for (AtomHandlerContainerIt it= m_atomhandler.begin(); - it != m_atomhandler.end(); ++it) { - if ((*it)->update()) - (*it)->updateWorkspaceNames(screen); - } + STLUtil::forAllIf(m_atomhandler, mem_fun(&AtomHandler::update), + bind2nd(mem_fun(&AtomHandler::updateWorkspaceNames), screen)); } void Fluxbox::clientListChanged(BScreen &screen) { - for (AtomHandlerContainerIt it= m_atomhandler.begin(); - it != m_atomhandler.end(); ++it) { - if ((*it)->update()) - (*it)->updateClientList(screen); - } + STLUtil::forAllIf(m_atomhandler, mem_fun(&AtomHandler::update), + bind2nd(mem_fun(&AtomHandler::updateClientList), screen)); } void Fluxbox::focusedWindowChanged(BScreen &screen, FluxboxWindow* win, WinClient* client) { + for (AtomHandlerContainerIt it= m_atomhandler.begin(); it != m_atomhandler.end(); it++) { (*it)->updateFocusedWindow(screen, client ? client->window() : 0 );

@@ -1475,9 +1417,7 @@ }

} void Fluxbox::workspaceAreaChanged(BScreen &screen) { - for (AtomHandlerContainerIt it= m_atomhandler.begin(); - it != m_atomhandler.end(); ++it) { - if ((*it)->update()) - (*it)->updateWorkarea(screen); - } + STLUtil::forAllIf(m_atomhandler, mem_fun(&AtomHandler::update), + bind2nd(mem_fun(&AtomHandler::updateWorkarea), screen)); } +