diff options
author | rathnor <rathnor> | 2003-02-09 14:11:14 (GMT) |
---|---|---|
committer | rathnor <rathnor> | 2003-02-09 14:11:14 (GMT) |
commit | e3b99d4e485591df52b2398fce9adbcece2b9917 (patch) | |
tree | 44c14c5160e07e1af0671e141ae99cc1f2e66609 /src/FbTk/XLayer.cc | |
parent | 1a04cf1ce2649400d41c43024bd163a059cc426d (diff) | |
download | fluxbox-e3b99d4e485591df52b2398fce9adbcece2b9917.zip fluxbox-e3b99d4e485591df52b2398fce9adbcece2b9917.tar.bz2 |
fixing up of layer code
Diffstat (limited to 'src/FbTk/XLayer.cc')
-rw-r--r-- | src/FbTk/XLayer.cc | 203 |
1 files changed, 142 insertions, 61 deletions
diff --git a/src/FbTk/XLayer.cc b/src/FbTk/XLayer.cc index 6b1791f..b5e9756 100644 --- a/src/FbTk/XLayer.cc +++ b/src/FbTk/XLayer.cc | |||
@@ -20,7 +20,7 @@ | |||
20 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 20 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
21 | // DEALINGS IN THE SOFTWARE. | 21 | // DEALINGS IN THE SOFTWARE. |
22 | 22 | ||
23 | // $Id: XLayer.cc,v 1.4 2003/02/03 13:45:23 fluxgen Exp $ | 23 | // $Id: XLayer.cc,v 1.5 2003/02/09 14:11:14 rathnor Exp $ |
24 | 24 | ||
25 | #include "XLayer.hh" | 25 | #include "XLayer.hh" |
26 | #include "XLayerItem.hh" | 26 | #include "XLayerItem.hh" |
@@ -44,15 +44,24 @@ void XLayer::restack() { | |||
44 | // each LayerItem can contain several windows | 44 | // each LayerItem can contain several windows |
45 | iterator it = itemList().begin(); | 45 | iterator it = itemList().begin(); |
46 | iterator it_end = itemList().end(); | 46 | iterator it_end = itemList().end(); |
47 | it = itemList().begin(); | ||
48 | it_end = itemList().end(); | ||
47 | Window *winlist = new Window[num_windows]; | 49 | Window *winlist = new Window[num_windows]; |
48 | size_t j=0; | 50 | size_t j=0; |
49 | for (size_t window=0; it != it_end; ++it, window++) { | 51 | |
50 | winlist[window] = (*it)->window(); | 52 | // add all the windows from each item |
53 | for (size_t i=0; it != it_end; ++it, i++) { | ||
54 | XLayerItem::Windows::const_iterator wit = (*it)->getWindows().begin(); | ||
55 | XLayerItem::Windows::const_iterator wit_end = (*it)->getWindows().end(); | ||
56 | for (; wit != wit_end; ++wit, j++) { | ||
57 | winlist[j] = (*wit); | ||
58 | } | ||
51 | } | 59 | } |
52 | 60 | ||
53 | XRestackWindows(FbTk::App::instance()->display(), winlist, num_windows); | 61 | XRestackWindows(FbTk::App::instance()->display(), winlist, num_windows); |
54 | 62 | ||
55 | delete [] winlist; | 63 | delete [] winlist; |
64 | |||
56 | } | 65 | } |
57 | 66 | ||
58 | int XLayer::countWindows() { | 67 | int XLayer::countWindows() { |
@@ -60,70 +69,80 @@ int XLayer::countWindows() { | |||
60 | iterator it = itemList().begin(); | 69 | iterator it = itemList().begin(); |
61 | iterator it_end = itemList().end(); | 70 | iterator it_end = itemList().end(); |
62 | for (size_t i=0; it != it_end; ++it, i++) { | 71 | for (size_t i=0; it != it_end; ++it, i++) { |
63 | num_windows ++; // one window per item | 72 | num_windows += (*it)->numWindows(); |
64 | } | 73 | } |
65 | return num_windows; | 74 | return num_windows; |
66 | } | 75 | } |
67 | 76 | ||
68 | 77 | ||
78 | // Stack all windows associated with 'item' below the 'above' item | ||
69 | void XLayer::stackBelowItem(XLayerItem *item, XLayerItem *above) { | 79 | void XLayer::stackBelowItem(XLayerItem *item, XLayerItem *above) { |
70 | //!! What???? | ||
71 | 80 | ||
72 | // little optimisation | 81 | Window *winlist; |
73 | /* Window *winlist; | 82 | size_t winnum, size, num = item->numWindows(); |
74 | size_t i, size, num = item->numWindows(); | ||
75 | 83 | ||
84 | // if there are no windows provided for above us, | ||
85 | // then we must have to go right to the top of the stack | ||
76 | if (!above) { // must need to go right to top | 86 | if (!above) { // must need to go right to top |
77 | XRaiseWindow(FbTk::App::instance()->display(), item->getWindows().front()); | 87 | XRaiseWindow(FbTk::App::instance()->display(), item->getWindows().front()); |
88 | |||
89 | // if this XLayerItem has more than one window, | ||
90 | // then we'll stack the rest in under the front one too | ||
91 | // our size needs to be the number of windows in the group, since there isn't one above. | ||
78 | if (num > 1) { | 92 | if (num > 1) { |
79 | i = 0; | 93 | winnum = 0; |
80 | // stack relative to top one (just raised) | 94 | // stack relative to top one (just raised) |
81 | size = num; | 95 | size = num; |
82 | winlist = new Window[size]; | 96 | winlist = new Window[size]; |
83 | } else { | 97 | } else { |
98 | // we've raised the window, nothing else to do | ||
84 | return; | 99 | return; |
85 | } | 100 | } |
86 | } else { | 101 | } else { |
102 | // We do have a window to stack below | ||
87 | 103 | ||
88 | i=1; | 104 | // so we put it on top, and fill the rest of the array with the ones to go below it. |
89 | // stack relative to one above | 105 | winnum = 1; |
90 | |||
91 | size = num+1; | 106 | size = num+1; |
92 | winlist = new Window[size]; | 107 | winlist = new Window[size]; |
93 | winlist[0] = above->getWindows().front(); | 108 | winlist[0] = above->getWindows().back(); |
94 | } | 109 | } |
95 | 110 | ||
111 | // fill the rest of the array | ||
96 | XLayerItem::Windows::iterator it = item->getWindows().begin(); | 112 | XLayerItem::Windows::iterator it = item->getWindows().begin(); |
97 | XLayerItem::Windows::iterator it_end = item->getWindows().end(); | 113 | XLayerItem::Windows::iterator it_end = item->getWindows().end(); |
98 | for (; it != it_end; ++it, i++) { | 114 | for (; it != it_end; ++it, winnum++) { |
99 | winlist[i] = (*it); | 115 | winlist[winnum] = (*it); |
100 | } | 116 | } |
101 | 117 | ||
118 | // stack the windows | ||
102 | XRestackWindows(FbTk::App::instance()->display(), winlist, size); | 119 | XRestackWindows(FbTk::App::instance()->display(), winlist, size); |
103 | 120 | ||
104 | delete [] winlist; | 121 | delete [] winlist; |
105 | */ | 122 | |
106 | } | 123 | } |
107 | 124 | ||
108 | XLayer::iterator XLayer::insert(XLayerItem &item, unsigned int pos) { | 125 | XLayer::iterator XLayer::insert(XLayerItem &item, unsigned int pos) { |
109 | #ifdef DEBUG | 126 | #ifdef DEBUG |
110 | if (pos != 0)//!! Why???? | 127 | // at this point we don't support insertions into a layer other than at the top |
128 | if (pos != 0) | ||
111 | cerr<<__FILE__<<"("<<__LINE__<<"): Insert using non-zero position not valid in XLayer"<<endl; | 129 | cerr<<__FILE__<<"("<<__LINE__<<"): Insert using non-zero position not valid in XLayer"<<endl; |
112 | #endif // DEBUG | 130 | #endif // DEBUG |
113 | 131 | ||
114 | itemList().push_front(&item); | 132 | itemList().push_front(&item); |
115 | // restack below next window up | 133 | // restack below next window up |
116 | // item.setLayerIterator(itemList().begin()); | ||
117 | stackBelowItem(&item, m_manager.getLowestItemAboveLayer(m_layernum)); | 134 | stackBelowItem(&item, m_manager.getLowestItemAboveLayer(m_layernum)); |
118 | return itemList().begin(); | 135 | return itemList().begin(); |
119 | } | 136 | } |
120 | 137 | ||
121 | void XLayer::remove(XLayerItem &item) { | 138 | void XLayer::remove(XLayerItem &item) { |
122 | iterator it = itemList().begin(); | 139 | iterator it = itemList().begin(); |
123 | iterator it_end = itemList().end(); | 140 | iterator it_end = itemList().end(); |
124 | for (; it != it_end; ++it) { | 141 | for (; it != it_end; ++it) { |
125 | if (*it == &item) | 142 | if (*it == &item) { |
126 | itemList().erase(it); | 143 | itemList().erase(it); |
144 | break; | ||
145 | } | ||
127 | } | 146 | } |
128 | } | 147 | } |
129 | 148 | ||
@@ -141,7 +160,8 @@ void XLayer::cycleUp() { | |||
141 | } | 160 | } |
142 | 161 | ||
143 | void XLayer::cycleDown() { | 162 | void XLayer::cycleDown() { |
144 | // need to find highest visible window, and move it to bottom | 163 | // need to find lowest visible window, and move it to top |
164 | // so use a reverse iterator, and the same logic as cycleUp() | ||
145 | reverse_iterator it = itemList().rbegin(); | 165 | reverse_iterator it = itemList().rbegin(); |
146 | reverse_iterator it_end = itemList().rend(); | 166 | reverse_iterator it_end = itemList().rend(); |
147 | while (it != it_end && !(*it)->visible()) | 167 | while (it != it_end && !(*it)->visible()) |
@@ -159,80 +179,136 @@ void XLayer::stepUp(XLayerItem &item) { | |||
159 | if (&item == itemList().front()) | 179 | if (&item == itemList().front()) |
160 | return; // nothing to do | 180 | return; // nothing to do |
161 | 181 | ||
162 | //!! better stable and slow than buggy! | ||
163 | /* | ||
164 | // TODO: is there a better way of doing this? | 182 | // TODO: is there a better way of doing this? |
165 | iterator it = item.getLayerIterator(); | 183 | |
166 | it--; | 184 | // get our item |
167 | while ((*it) != itemList().front() && !(*it)->visible()) | 185 | iterator myit = std::find(itemList().begin(), itemList().end(), &item); |
186 | iterator it = myit; | ||
187 | |||
188 | // go to the one above it in our layer (top is front, so we decrement) | ||
189 | --it; | ||
190 | |||
191 | // keep going until we find one that is currently visible to the user | ||
192 | while (it != itemList().begin() && !(*it)->visible()) | ||
168 | --it; | 193 | --it; |
169 | 194 | ||
170 | if (*it == itemList().front() && !(*it)->visible()) { | 195 | if (it == itemList().begin() && !(*it)->visible()) { |
171 | // reached front item, but it wasn't visible, therefore it was already raised | 196 | // reached front item, but it wasn't visible, therefore it was already raised |
172 | //moveToBottom(item); | ||
173 | } else { | 197 | } else { |
174 | // it is the next visible item down, we need to be above it. | 198 | // it is the next visible item down, we need to be above it. |
175 | itemList().erase(item.getLayerIterator()); | 199 | // remove that item from the list and add it back to before it (the one we want to go above) |
176 | //itemList().insert(it, item); | 200 | |
177 | item.setLayerIterator(it = itemList().insert(it, &item)); | 201 | itemList().erase(myit); |
178 | if (*it == itemList().front()) { | 202 | itemList().insert(it, &item); |
203 | |||
204 | // if we've reached the top of the layer, we need to stack below the next one up | ||
205 | if (it == itemList().begin()) { | ||
179 | stackBelowItem(&item, m_manager.getLowestItemAboveLayer(m_layernum)); | 206 | stackBelowItem(&item, m_manager.getLowestItemAboveLayer(m_layernum)); |
180 | } else { | 207 | } else { |
181 | it--; | 208 | // otherwise go up one in this layer (i.e. above the one we want to go above) |
209 | --it; | ||
210 | // and stack below that. | ||
182 | stackBelowItem(&item, *it); | 211 | stackBelowItem(&item, *it); |
183 | } | 212 | } |
184 | } | 213 | } |
185 | */ | ||
186 | } | 214 | } |
187 | 215 | ||
188 | void XLayer::stepDown(XLayerItem &item) { | 216 | void XLayer::stepDown(XLayerItem &item) { |
189 | // need to find next visible window down, and put it below that | 217 | // need to find next visible window down, and put it below that |
218 | |||
219 | // if we're already the bottom of the layer | ||
190 | if (&item == itemList().back()) | 220 | if (&item == itemList().back()) |
191 | return; // nothing to do | 221 | return; // nothing to do |
192 | 222 | ||
193 | //!! better stable and slow than buggy! | 223 | // get our position |
194 | /* iterator it = item.getLayerIterator(); | 224 | iterator myit = std::find(itemList().begin(), itemList().end(), &item); |
225 | iterator it = myit; | ||
226 | |||
227 | // go one below it (top is front, so we must increment) | ||
195 | it++; | 228 | it++; |
196 | iterator it_end = itemList().end(); | 229 | iterator it_end = itemList().end(); |
230 | |||
231 | // keep going down until we find a visible one | ||
197 | while (it != it_end && !(*it)->visible()) | 232 | while (it != it_end && !(*it)->visible()) |
198 | ++it; | 233 | it++; |
199 | 234 | ||
235 | // if we didn't reach the end, then stack below the | ||
236 | // item that we found. | ||
200 | if (it != it_end) | 237 | if (it != it_end) |
201 | stackBelowItem(&item, *it); | 238 | stackBelowItem(&item, *it); |
202 | */ | 239 | // if we did reach the end, then there are no visible windows, so we don't do anything |
203 | } | 240 | } |
204 | 241 | ||
205 | //!! | ||
206 | void XLayer::raise(XLayerItem &item) { | 242 | void XLayer::raise(XLayerItem &item) { |
207 | // assume it is already in this layer | 243 | // assume it is already in this layer |
208 | 244 | ||
209 | if (&item == itemList().front()) | 245 | if (&item == itemList().front()) |
210 | return; // nothing to do | 246 | return; // nothing to do |
211 | 247 | ||
212 | // itemList().erase(item.getLayerIterator()); | 248 | iterator it = std::find(itemList().begin(), itemList().end(), &item); |
249 | if (it != itemList().end()) | ||
250 | itemList().erase(it); | ||
251 | #ifdef DEBUG | ||
252 | else { | ||
253 | cerr<<__FILE__<<"("<<__LINE__<<"): WARNING: raise on item not in layer["<<m_layernum<<"]"<<endl; | ||
254 | return; | ||
255 | } | ||
256 | #endif // DEBUG | ||
257 | |||
213 | itemList().push_front(&item); | 258 | itemList().push_front(&item); |
214 | // item.setLayerIterator(itemList().begin()); | ||
215 | stackBelowItem(&item, m_manager.getLowestItemAboveLayer(m_layernum)); | 259 | stackBelowItem(&item, m_manager.getLowestItemAboveLayer(m_layernum)); |
216 | 260 | ||
217 | } | 261 | } |
218 | 262 | ||
219 | void XLayer::lower(XLayerItem &item) { | 263 | void XLayer::lower(XLayerItem &item) { |
220 | // assume already in this layer | 264 | // assume already in this layer |
265 | |||
266 | // is it already the lowest? | ||
221 | if (&item == itemList().back()) | 267 | if (&item == itemList().back()) |
222 | return; // nothing to do | 268 | return; // nothing to do |
223 | 269 | ||
224 | //!! better stable and slow than buggy! | 270 | iterator it = std::find(itemList().begin(), itemList().end(), &item); |
225 | /* | 271 | if (it != itemList().end()) |
226 | itemList().erase(item.getLayerIterator()); | 272 | // remove this item |
273 | itemList().erase(it); | ||
274 | #ifdef DEBUG | ||
275 | else { | ||
276 | cerr<<__FILE__<<"("<<__LINE__<<"): WARNING: lower on item not in layer"<<endl; | ||
277 | return; | ||
278 | } | ||
279 | #endif // DEBUG | ||
280 | |||
281 | // add it to the bottom | ||
227 | itemList().push_back(&item); | 282 | itemList().push_back(&item); |
228 | iterator it = itemList().end(); | 283 | |
229 | it--; | 284 | // find the item we need to stack below |
230 | item.setLayerIterator(it); | 285 | // start at the end |
286 | it = itemList().end(); | ||
287 | |||
288 | // go up one so we have an object (which must exist, since at least this item is in the layer) | ||
231 | it--; | 289 | it--; |
232 | stackBelowItem(&item, *it); // must exist, otherwise item must == itemList().back() | 290 | |
233 | */ | 291 | // go down another one |
292 | // must exist, otherwise our item must == itemList().back() | ||
293 | it--; | ||
294 | |||
295 | // and restack our window below that one. | ||
296 | stackBelowItem(&item, *it); | ||
297 | } | ||
298 | |||
299 | void XLayer::raiseLayer(XLayerItem &item) { | ||
300 | m_manager.raiseLayer(item); | ||
301 | } | ||
302 | |||
303 | void XLayer::lowerLayer(XLayerItem &item) { | ||
304 | m_manager.lowerLayer(item); | ||
234 | } | 305 | } |
235 | 306 | ||
307 | void XLayer::moveToLayer(XLayerItem &item, int layernum) { | ||
308 | m_manager.moveToLayer(item, layernum); | ||
309 | } | ||
310 | |||
311 | |||
236 | XLayerItem *XLayer::getLowestItem() { | 312 | XLayerItem *XLayer::getLowestItem() { |
237 | if (itemList().empty()) | 313 | if (itemList().empty()) |
238 | return 0; | 314 | return 0; |
@@ -241,22 +317,27 @@ XLayerItem *XLayer::getLowestItem() { | |||
241 | } | 317 | } |
242 | 318 | ||
243 | XLayerItem *XLayer::getItemBelow(XLayerItem &item) { | 319 | XLayerItem *XLayer::getItemBelow(XLayerItem &item) { |
244 | //!! better stable and slow than buggy! | 320 | // get our iterator |
245 | /* iterator it = item.getLayerIterator(); | 321 | iterator it = std::find(itemList().begin(), itemList().end(), &item); |
246 | if (it == itemList().begin()) | ||
247 | return 0; | ||
248 | else | ||
249 | return *(--it); | ||
250 | */ | ||
251 | } | ||
252 | 322 | ||
253 | XLayerItem *XLayer::getItemAbove(XLayerItem &item) { | 323 | // go one lower |
254 | //!! better stable and slow than buggy! | ||
255 | /* iterator it = item.getLayerIterator(); | ||
256 | it++; | 324 | it++; |
325 | |||
326 | // if one lower is the end, there is no item below, otherwise we've got it | ||
257 | if (it == itemList().end()) | 327 | if (it == itemList().end()) |
258 | return 0; | 328 | return 0; |
259 | else | 329 | else |
260 | return *it; | 330 | return *it; |
261 | */ | 331 | } |
332 | |||
333 | XLayerItem *XLayer::getItemAbove(XLayerItem &item) { | ||
334 | // get our iterator | ||
335 | iterator it = std::find(itemList().begin(), itemList().end(), &item); | ||
336 | |||
337 | // if this is the beginning (top-most item), do nothing, otherwise give the next one up | ||
338 | // the list (which must be there since we aren't the beginning) | ||
339 | if (it == itemList().begin()) | ||
340 | return 0; | ||
341 | else | ||
342 | return *(--it); | ||
262 | } | 343 | } |