all repos — fluxbox @ 32cc4ba69b78b496524b11cd9f76328820ccaef1

custom fork of the fluxbox windowmanager

code deduplication
Mathias Gumz akira at fluxbox dot org
commit

32cc4ba69b78b496524b11cd9f76328820ccaef1

parent

504fd5c4fac2ef8d7df7ea61baccc00977ea4f7b

3 files changed, 67 insertions(+), 93 deletions(-)

jump to
M src/FbTk/MultLayers.ccsrc/FbTk/MultLayers.cc

@@ -114,28 +114,7 @@ void MultLayers::restack() {

if (!isUpdatable()) return; - int layernum=0, winnum=0, size = this->size(); - - Window *winlist = new Window[size]; - for (layernum=0; layernum < static_cast<signed>(m_layers.size()); layernum++) { - - XLayer::ItemList::iterator it = m_layers[layernum]->getItemList().begin(); - XLayer::ItemList::iterator it_end = m_layers[layernum]->getItemList().end(); - - // add all windows from each layeritem in each layer - for (; it != it_end; ++it) { - XLayerItem::Windows::const_iterator wit = (*it)->getWindows().begin(); - XLayerItem::Windows::const_iterator wit_end = (*it)->getWindows().end(); - for (; wit != wit_end; ++wit) { - if ((*wit)->window()) - winlist[winnum++] = (*wit)->window(); - } - } - } - - XRestackWindows(FbTk::App::instance()->display(), winlist, winnum); - - delete [] winlist; + XLayer::restack(m_layers); } int MultLayers::size() {
M src/FbTk/XLayer.ccsrc/FbTk/XLayer.cc

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

#include "MultLayers.hh" #include <iostream> +#include <numeric> using std::find; using namespace FbTk;

@@ -36,85 +37,88 @@ using std::cerr;

using std::endl; #endif // DEBUG -XLayer::XLayer(MultLayers &manager, int layernum): - m_manager(manager), m_layernum(layernum), m_needs_restack(false) { +namespace { + +int sum_windows(int nr, XLayerItem* item) { + return nr + item->numWindows(); } -XLayer::~XLayer() { - +int count_windows(const FbTk::XLayer::ItemList& items) { + return std::accumulate(items.begin(), items.end(), 0, sum_windows); } -void XLayer::restack() { - if (!m_manager.isUpdatable()) - return; - int num_windows = countWindows(); +void extract_windows_to_stack(const XLayerItem::Windows& windows, std::vector<Window>& stack) { + XLayerItem::Windows::const_iterator i = windows.begin(); + XLayerItem::Windows::const_iterator end = windows.end(); + for (; i != end; ++i) { + Window w = (*i)->window(); + if (w) + stack.push_back(w); + } +} - // each LayerItem can contain several windows - iterator it = itemList().begin(); - iterator it_end = itemList().end(); - Window *winlist = new Window[num_windows]; - size_t j=0; +void extract_windows_to_stack(const FbTk::XLayer::ItemList& items, XLayerItem* temp_raised, std::vector<Window>& stack) { - // add all the windows from each item - for (; it != it_end; ++it) { - XLayerItem::Windows::const_iterator wit = (*it)->getWindows().begin(); - XLayerItem::Windows::const_iterator wit_end = (*it)->getWindows().end(); - for (; wit != wit_end; ++wit) { - if ((*wit)->window()) - winlist[j++] = (*wit)->window(); + if (temp_raised) { // add windows that go on top + extract_windows_to_stack(temp_raised->getWindows(), stack); + } + + FbTk::XLayer::ItemList::const_iterator it = items.begin(); + FbTk::XLayer::ItemList::const_iterator it_end = items.end(); + for (; it != it_end; ++it) { // add all the windows from each other item + if (*it == temp_raised) { + continue; } + extract_windows_to_stack((*it)->getWindows(), stack); } +} - XRestackWindows(FbTk::App::instance()->display(), winlist, j); +void restack(const FbTk::XLayer::ItemList& items, XLayerItem* temp_raised) { - delete [] winlist; + std::vector<Window> stack; + extract_windows_to_stack(items, temp_raised, stack); - m_needs_restack = false; + if (!stack.empty()) + XRestackWindows(FbTk::App::instance()->display(), &stack[0], stack.size()); } -void XLayer::restackAndTempRaise(XLayerItem &item) { - int num_windows = countWindows(); +} // end of anonymous namespace + - // each LayerItem can contain several windows - iterator it = itemList().begin(); - iterator it_end = itemList().end(); - Window *winlist = new Window[num_windows]; - size_t j=0; +void XLayer::restack(const std::vector<XLayer*>& layers) { - // add windows that go on top - XLayerItem::Windows::const_iterator wit = item.getWindows().begin(); - XLayerItem::Windows::const_iterator wit_end = item.getWindows().end(); - for (; wit != wit_end; ++wit) { - if ((*wit)->window()) - winlist[j++] = (*wit)->window(); + std::vector<Window> stack; + std::vector<XLayer*>::const_iterator l; + for (l = layers.begin(); l != layers.end(); ++l) { + extract_windows_to_stack((*l)->getItemList(), 0, stack); } - // add all the windows from each other item - for (; it != it_end; ++it) { - if (*it == &item) - continue; - wit = (*it)->getWindows().begin(); - wit_end = (*it)->getWindows().end(); - for (; wit != wit_end; ++wit) { - if ((*wit)->window()) - winlist[j++] = (*wit)->window(); - } + if (!stack.empty()) + XRestackWindows(FbTk::App::instance()->display(), &stack[0], stack.size()); +} + +XLayer::XLayer(MultLayers &manager, int layernum): + m_manager(manager), m_layernum(layernum), m_needs_restack(false) { +} + +XLayer::~XLayer() { + +} + +void XLayer::restack() { + if (m_manager.isUpdatable()) { + ::restack(itemList(), 0); + m_needs_restack = false; } +} - XRestackWindows(FbTk::App::instance()->display(), winlist, j); - - delete [] winlist; +void XLayer::restackAndTempRaise(XLayerItem &item) { + ::restack(itemList(), &item); } int XLayer::countWindows() { - int num_windows = 0; - iterator it = itemList().begin(); - iterator it_end = itemList().end(); - for (; it != it_end; ++it) { - num_windows += (*it)->numWindows(); - } - return num_windows; + return ::count_windows(itemList()); }

@@ -132,28 +136,17 @@ restack();

return; } - Window *winlist; - size_t winnum = 1, size = item.numWindows()+1; + std::vector<Window> stack; // We do have a window to stack below // so we put it on top, and fill the rest of the array with the ones to go below it. - winlist = new Window[size]; // assume that above's window exists - winlist[0] = above->getWindows().back()->window(); + stack.push_back(above->getWindows().back()->window()); // fill the rest of the array - XLayerItem::Windows::iterator it = item.getWindows().begin(); - XLayerItem::Windows::iterator it_end = item.getWindows().end(); - for (; it != it_end; ++it) { - if ((*it)->window()) - winlist[winnum++] = (*it)->window(); - } - - // stack the windows - XRestackWindows(FbTk::App::instance()->display(), winlist, winnum); - - delete [] winlist; + extract_windows_to_stack(item.getWindows(), stack); + XRestackWindows(FbTk::App::instance()->display(), &stack[0], stack.size()); } // We can't just use Restack here, because it won't do anything if they're
M src/FbTk/XLayer.hhsrc/FbTk/XLayer.hh

@@ -68,6 +68,8 @@ void raiseLayer(XLayerItem &item);

void lowerLayer(XLayerItem &item); void moveToLayer(XLayerItem &item, int layernum); + static void restack(const std::vector<XLayer*>& layers); + private: void restack(); void restackAndTempRaise(XLayerItem &item);