aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
authorMathias Gumz <akira at fluxbox dot org>2011-02-23 20:45:50 (GMT)
committerMathias Gumz <akira at fluxbox dot org>2011-02-23 20:45:50 (GMT)
commit32cc4ba69b78b496524b11cd9f76328820ccaef1 (patch)
treee3d78692478c4f84fdfd712049e6830d427bb084 /src/FbTk
parent504fd5c4fac2ef8d7df7ea61baccc00977ea4f7b (diff)
downloadfluxbox_paul-32cc4ba69b78b496524b11cd9f76328820ccaef1.zip
fluxbox_paul-32cc4ba69b78b496524b11cd9f76328820ccaef1.tar.bz2
code deduplication
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/MultLayers.cc23
-rw-r--r--src/FbTk/XLayer.cc137
-rw-r--r--src/FbTk/XLayer.hh2
3 files changed, 68 insertions, 94 deletions
diff --git a/src/FbTk/MultLayers.cc b/src/FbTk/MultLayers.cc
index 6469a14..0f0748f 100644
--- a/src/FbTk/MultLayers.cc
+++ b/src/FbTk/MultLayers.cc
@@ -114,28 +114,7 @@ void MultLayers::restack() {
114 if (!isUpdatable()) 114 if (!isUpdatable())
115 return; 115 return;
116 116
117 int layernum=0, winnum=0, size = this->size(); 117 XLayer::restack(m_layers);
118
119 Window *winlist = new Window[size];
120 for (layernum=0; layernum < static_cast<signed>(m_layers.size()); layernum++) {
121
122 XLayer::ItemList::iterator it = m_layers[layernum]->getItemList().begin();
123 XLayer::ItemList::iterator it_end = m_layers[layernum]->getItemList().end();
124
125 // add all windows from each layeritem in each layer
126 for (; it != it_end; ++it) {
127 XLayerItem::Windows::const_iterator wit = (*it)->getWindows().begin();
128 XLayerItem::Windows::const_iterator wit_end = (*it)->getWindows().end();
129 for (; wit != wit_end; ++wit) {
130 if ((*wit)->window())
131 winlist[winnum++] = (*wit)->window();
132 }
133 }
134 }
135
136 XRestackWindows(FbTk::App::instance()->display(), winlist, winnum);
137
138 delete [] winlist;
139} 118}
140 119
141int MultLayers::size() { 120int MultLayers::size() {
diff --git a/src/FbTk/XLayer.cc b/src/FbTk/XLayer.cc
index b1bc14c..21790cb 100644
--- a/src/FbTk/XLayer.cc
+++ b/src/FbTk/XLayer.cc
@@ -27,6 +27,7 @@
27#include "MultLayers.hh" 27#include "MultLayers.hh"
28 28
29#include <iostream> 29#include <iostream>
30#include <numeric>
30 31
31using std::find; 32using std::find;
32using namespace FbTk; 33using namespace FbTk;
@@ -36,85 +37,88 @@ using std::cerr;
36using std::endl; 37using std::endl;
37#endif // DEBUG 38#endif // DEBUG
38 39
39XLayer::XLayer(MultLayers &manager, int layernum): 40namespace {
40 m_manager(manager), m_layernum(layernum), m_needs_restack(false) {
41}
42 41
43XLayer::~XLayer() { 42int sum_windows(int nr, XLayerItem* item) {
43 return nr + item->numWindows();
44}
44 45
46int count_windows(const FbTk::XLayer::ItemList& items) {
47 return std::accumulate(items.begin(), items.end(), 0, sum_windows);
45} 48}
46 49
47void XLayer::restack() {
48 if (!m_manager.isUpdatable())
49 return;
50 50
51 int num_windows = countWindows(); 51void extract_windows_to_stack(const XLayerItem::Windows& windows, std::vector<Window>& stack) {
52 XLayerItem::Windows::const_iterator i = windows.begin();
53 XLayerItem::Windows::const_iterator end = windows.end();
54 for (; i != end; ++i) {
55 Window w = (*i)->window();
56 if (w)
57 stack.push_back(w);
58 }
59}
52 60
53 // each LayerItem can contain several windows 61void extract_windows_to_stack(const FbTk::XLayer::ItemList& items, XLayerItem* temp_raised, std::vector<Window>& stack) {
54 iterator it = itemList().begin();
55 iterator it_end = itemList().end();
56 Window *winlist = new Window[num_windows];
57 size_t j=0;
58 62
59 // add all the windows from each item 63 if (temp_raised) { // add windows that go on top
60 for (; it != it_end; ++it) { 64 extract_windows_to_stack(temp_raised->getWindows(), stack);
61 XLayerItem::Windows::const_iterator wit = (*it)->getWindows().begin(); 65 }
62 XLayerItem::Windows::const_iterator wit_end = (*it)->getWindows().end(); 66
63 for (; wit != wit_end; ++wit) { 67 FbTk::XLayer::ItemList::const_iterator it = items.begin();
64 if ((*wit)->window()) 68 FbTk::XLayer::ItemList::const_iterator it_end = items.end();
65 winlist[j++] = (*wit)->window(); 69 for (; it != it_end; ++it) { // add all the windows from each other item
70 if (*it == temp_raised) {
71 continue;
66 } 72 }
73 extract_windows_to_stack((*it)->getWindows(), stack);
67 } 74 }
75}
68 76
69 XRestackWindows(FbTk::App::instance()->display(), winlist, j); 77void restack(const FbTk::XLayer::ItemList& items, XLayerItem* temp_raised) {
70 78
71 delete [] winlist; 79 std::vector<Window> stack;
80 extract_windows_to_stack(items, temp_raised, stack);
72 81
73 m_needs_restack = false; 82 if (!stack.empty())
83 XRestackWindows(FbTk::App::instance()->display(), &stack[0], stack.size());
74} 84}
75 85
76void XLayer::restackAndTempRaise(XLayerItem &item) { 86} // end of anonymous namespace
77 int num_windows = countWindows();
78 87
79 // each LayerItem can contain several windows
80 iterator it = itemList().begin();
81 iterator it_end = itemList().end();
82 Window *winlist = new Window[num_windows];
83 size_t j=0;
84
85 // add windows that go on top
86 XLayerItem::Windows::const_iterator wit = item.getWindows().begin();
87 XLayerItem::Windows::const_iterator wit_end = item.getWindows().end();
88 for (; wit != wit_end; ++wit) {
89 if ((*wit)->window())
90 winlist[j++] = (*wit)->window();
91 }
92 88
93 // add all the windows from each other item 89void XLayer::restack(const std::vector<XLayer*>& layers) {
94 for (; it != it_end; ++it) { 90
95 if (*it == &item) 91 std::vector<Window> stack;
96 continue; 92 std::vector<XLayer*>::const_iterator l;
97 wit = (*it)->getWindows().begin(); 93 for (l = layers.begin(); l != layers.end(); ++l) {
98 wit_end = (*it)->getWindows().end(); 94 extract_windows_to_stack((*l)->getItemList(), 0, stack);
99 for (; wit != wit_end; ++wit) {
100 if ((*wit)->window())
101 winlist[j++] = (*wit)->window();
102 }
103 } 95 }
104 96
105 XRestackWindows(FbTk::App::instance()->display(), winlist, j); 97 if (!stack.empty())
98 XRestackWindows(FbTk::App::instance()->display(), &stack[0], stack.size());
99}
106 100
107 delete [] winlist; 101XLayer::XLayer(MultLayers &manager, int layernum):
102 m_manager(manager), m_layernum(layernum), m_needs_restack(false) {
108} 103}
109 104
110int XLayer::countWindows() { 105XLayer::~XLayer() {
111 int num_windows = 0; 106
112 iterator it = itemList().begin(); 107}
113 iterator it_end = itemList().end(); 108
114 for (; it != it_end; ++it) { 109void XLayer::restack() {
115 num_windows += (*it)->numWindows(); 110 if (m_manager.isUpdatable()) {
111 ::restack(itemList(), 0);
112 m_needs_restack = false;
116 } 113 }
117 return num_windows; 114}
115
116void XLayer::restackAndTempRaise(XLayerItem &item) {
117 ::restack(itemList(), &item);
118}
119
120int XLayer::countWindows() {
121 return ::count_windows(itemList());
118} 122}
119 123
120 124
@@ -132,28 +136,17 @@ void XLayer::stackBelowItem(XLayerItem &item, XLayerItem *above) {
132 return; 136 return;
133 } 137 }
134 138
135 Window *winlist; 139 std::vector<Window> stack;
136 size_t winnum = 1, size = item.numWindows()+1;
137 140
138 // We do have a window to stack below 141 // We do have a window to stack below
139 // so we put it on top, and fill the rest of the array with the ones to go below it. 142 // so we put it on top, and fill the rest of the array with the ones to go below it.
140 winlist = new Window[size];
141 // assume that above's window exists 143 // assume that above's window exists
142 winlist[0] = above->getWindows().back()->window(); 144 stack.push_back(above->getWindows().back()->window());
143 145
144 // fill the rest of the array 146 // fill the rest of the array
145 XLayerItem::Windows::iterator it = item.getWindows().begin(); 147 extract_windows_to_stack(item.getWindows(), stack);
146 XLayerItem::Windows::iterator it_end = item.getWindows().end();
147 for (; it != it_end; ++it) {
148 if ((*it)->window())
149 winlist[winnum++] = (*it)->window();
150 }
151
152 // stack the windows
153 XRestackWindows(FbTk::App::instance()->display(), winlist, winnum);
154
155 delete [] winlist;
156 148
149 XRestackWindows(FbTk::App::instance()->display(), &stack[0], stack.size());
157} 150}
158 151
159// We can't just use Restack here, because it won't do anything if they're 152// We can't just use Restack here, because it won't do anything if they're
diff --git a/src/FbTk/XLayer.hh b/src/FbTk/XLayer.hh
index ba5406b..3b7e45f 100644
--- a/src/FbTk/XLayer.hh
+++ b/src/FbTk/XLayer.hh
@@ -68,6 +68,8 @@ public:
68 void lowerLayer(XLayerItem &item); 68 void lowerLayer(XLayerItem &item);
69 void moveToLayer(XLayerItem &item, int layernum); 69 void moveToLayer(XLayerItem &item, int layernum);
70 70
71 static void restack(const std::vector<XLayer*>& layers);
72
71private: 73private:
72 void restack(); 74 void restack();
73 void restackAndTempRaise(XLayerItem &item); 75 void restackAndTempRaise(XLayerItem &item);