code deduplication
This commit is contained in:
parent
504fd5c4fa
commit
32cc4ba69b
3 changed files with 74 additions and 100 deletions
|
@ -114,28 +114,7 @@ void MultLayers::restack() {
|
||||||
if (!isUpdatable())
|
if (!isUpdatable())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int layernum=0, winnum=0, size = this->size();
|
XLayer::restack(m_layers);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int MultLayers::size() {
|
int MultLayers::size() {
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "MultLayers.hh"
|
#include "MultLayers.hh"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <numeric>
|
||||||
|
|
||||||
using std::find;
|
using std::find;
|
||||||
using namespace FbTk;
|
using namespace FbTk;
|
||||||
|
@ -36,6 +37,67 @@ using std::cerr;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
int sum_windows(int nr, XLayerItem* item) {
|
||||||
|
return nr + item->numWindows();
|
||||||
|
}
|
||||||
|
|
||||||
|
int count_windows(const FbTk::XLayer::ItemList& items) {
|
||||||
|
return std::accumulate(items.begin(), items.end(), 0, sum_windows);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void extract_windows_to_stack(const FbTk::XLayer::ItemList& items, XLayerItem* temp_raised, std::vector<Window>& stack) {
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void restack(const FbTk::XLayer::ItemList& items, XLayerItem* temp_raised) {
|
||||||
|
|
||||||
|
std::vector<Window> stack;
|
||||||
|
extract_windows_to_stack(items, temp_raised, stack);
|
||||||
|
|
||||||
|
if (!stack.empty())
|
||||||
|
XRestackWindows(FbTk::App::instance()->display(), &stack[0], stack.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
} // end of anonymous namespace
|
||||||
|
|
||||||
|
|
||||||
|
void XLayer::restack(const std::vector<XLayer*>& layers) {
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!stack.empty())
|
||||||
|
XRestackWindows(FbTk::App::instance()->display(), &stack[0], stack.size());
|
||||||
|
}
|
||||||
|
|
||||||
XLayer::XLayer(MultLayers &manager, int layernum):
|
XLayer::XLayer(MultLayers &manager, int layernum):
|
||||||
m_manager(manager), m_layernum(layernum), m_needs_restack(false) {
|
m_manager(manager), m_layernum(layernum), m_needs_restack(false) {
|
||||||
}
|
}
|
||||||
|
@ -45,76 +107,18 @@ XLayer::~XLayer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void XLayer::restack() {
|
void XLayer::restack() {
|
||||||
if (!m_manager.isUpdatable())
|
if (m_manager.isUpdatable()) {
|
||||||
return;
|
::restack(itemList(), 0);
|
||||||
|
|
||||||
int num_windows = countWindows();
|
|
||||||
|
|
||||||
// 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;
|
|
||||||
|
|
||||||
// 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
XRestackWindows(FbTk::App::instance()->display(), winlist, j);
|
|
||||||
|
|
||||||
delete [] winlist;
|
|
||||||
|
|
||||||
m_needs_restack = false;
|
m_needs_restack = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void XLayer::restackAndTempRaise(XLayerItem &item) {
|
void XLayer::restackAndTempRaise(XLayerItem &item) {
|
||||||
int num_windows = countWindows();
|
::restack(itemList(), &item);
|
||||||
|
|
||||||
// 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;
|
|
||||||
|
|
||||||
// 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
XRestackWindows(FbTk::App::instance()->display(), winlist, j);
|
|
||||||
|
|
||||||
delete [] winlist;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int XLayer::countWindows() {
|
int XLayer::countWindows() {
|
||||||
int num_windows = 0;
|
return ::count_windows(itemList());
|
||||||
iterator it = itemList().begin();
|
|
||||||
iterator it_end = itemList().end();
|
|
||||||
for (; it != it_end; ++it) {
|
|
||||||
num_windows += (*it)->numWindows();
|
|
||||||
}
|
|
||||||
return num_windows;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -132,28 +136,17 @@ void XLayer::stackBelowItem(XLayerItem &item, XLayerItem *above) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Window *winlist;
|
std::vector<Window> stack;
|
||||||
size_t winnum = 1, size = item.numWindows()+1;
|
|
||||||
|
|
||||||
// We do have a window to stack below
|
// 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.
|
// 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
|
// 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
|
// fill the rest of the array
|
||||||
XLayerItem::Windows::iterator it = item.getWindows().begin();
|
extract_windows_to_stack(item.getWindows(), stack);
|
||||||
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;
|
|
||||||
|
|
||||||
|
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
|
// We can't just use Restack here, because it won't do anything if they're
|
||||||
|
|
|
@ -68,6 +68,8 @@ public:
|
||||||
void lowerLayer(XLayerItem &item);
|
void lowerLayer(XLayerItem &item);
|
||||||
void moveToLayer(XLayerItem &item, int layernum);
|
void moveToLayer(XLayerItem &item, int layernum);
|
||||||
|
|
||||||
|
static void restack(const std::vector<XLayer*>& layers);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void restack();
|
void restack();
|
||||||
void restackAndTempRaise(XLayerItem &item);
|
void restackAndTempRaise(XLayerItem &item);
|
||||||
|
|
Loading…
Reference in a new issue