]> icculus.org git repositories - mikachu/openbox.git/blob - src/Workspace.cc
new row and column placement, using a modified bestfit. These don't work right yet...
[mikachu/openbox.git] / src / Workspace.cc
1 // Workspace.cc for Openbox
2 // Copyright (c) 2002 - 2002 Ben Jansens (ben@orodu.net)
3 // Copyright (c) 2001 Sean 'Shaleh' Perry <shaleh@debian.org>
4 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a
7 // copy of this software and associated documentation files (the "Software"),
8 // to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 // and/or sell copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 // DEALINGS IN THE SOFTWARE.
23
24 // stupid macros needed to access some functions in version 2 of the GNU C
25 // library
26 #ifndef   _GNU_SOURCE
27 #define   _GNU_SOURCE
28 #endif // _GNU_SOURCE
29
30 #ifdef    HAVE_CONFIG_H
31 #  include "../config.h"
32 #endif // HAVE_CONFIG_H
33
34 #include <X11/Xlib.h>
35 #include <X11/Xatom.h>
36
37 #include "i18n.h"
38 #include "openbox.h"
39 #include "Clientmenu.h"
40 #include "Screen.h"
41 #include "Toolbar.h"
42 #include "Window.h"
43 #include "Workspace.h"
44
45 #include "Windowmenu.h"
46 #include "Geometry.h"
47 #include "Util.h"
48
49 #ifdef    HAVE_STDIO_H
50 #  include <stdio.h>
51 #endif // HAVE_STDIO_H
52
53 #ifdef    HAVE_STDLIB_H
54 #  include <stdlib.h>
55 #endif // HAVE_STDLIB_H
56
57 #ifdef    HAVE_STRING_H
58 #  include <string.h>
59 #endif // HAVE_STRING_H
60
61 #include <vector>
62 #include <algorithm>
63 typedef vector<Rect> rectList;
64
65 Workspace::Workspace(BScreen &scrn, int i) : screen(scrn) {
66
67   cascade_x = cascade_y = 32;
68
69   id = i;
70
71   stackingList = new LinkedList<OpenboxWindow>;
72   windowList = new LinkedList<OpenboxWindow>;
73   clientmenu = new Clientmenu(*this);
74
75   lastfocus = (OpenboxWindow *) 0;
76
77   name = (char *) 0;
78   char *tmp = screen.getNameOfWorkspace(id);
79   setName(tmp);
80 }
81
82
83 Workspace::~Workspace(void) {
84   delete stackingList;
85   delete windowList;
86   delete clientmenu;
87
88   if (name)
89     delete [] name;
90 }
91
92
93 const int Workspace::addWindow(OpenboxWindow *w, Bool place) {
94   if (! w) return -1;
95
96   if (place) placeWindow(w);
97
98   w->setWorkspace(id);
99   w->setWindowNumber(windowList->count());
100
101   stackingList->insert(w, 0);
102   windowList->insert(w);
103
104   clientmenu->insert((const char **) w->getTitle());
105   clientmenu->update();
106
107   screen.updateNetizenWindowAdd(w->getClientWindow(), id);
108
109   raiseWindow(w);
110
111   return w->getWindowNumber();
112 }
113
114
115 const int Workspace::removeWindow(OpenboxWindow *w) {
116   if (! w) return -1;
117
118   stackingList->remove(w);
119
120   if (w->isFocused()) {
121     if (w->isTransient() && w->getTransientFor() &&
122         w->getTransientFor()->isVisible()) {
123       w->getTransientFor()->setInputFocus();
124     } else if (screen.sloppyFocus()) {
125       screen.getOpenbox().setFocusedWindow((OpenboxWindow *) 0);
126     } else {
127       OpenboxWindow *top = stackingList->first();
128       if (! top || ! top->setInputFocus()) {
129         screen.getOpenbox().setFocusedWindow((OpenboxWindow *) 0);
130         XSetInputFocus(screen.getOpenbox().getXDisplay(),
131                        screen.getToolbar()->getWindowID(),
132                        RevertToParent, CurrentTime);
133       }
134     }
135   }
136   
137   if (lastfocus == w)
138     lastfocus = (OpenboxWindow *) 0;
139
140   windowList->remove(w->getWindowNumber());
141   clientmenu->remove(w->getWindowNumber());
142   clientmenu->update();
143
144   screen.updateNetizenWindowDel(w->getClientWindow());
145
146   LinkedListIterator<OpenboxWindow> it(windowList);
147   OpenboxWindow *bw = it.current();
148   for (int i = 0; bw; it++, i++, bw = it.current())
149     bw->setWindowNumber(i);
150
151   return windowList->count();
152 }
153
154
155 void Workspace::showAll(void) {
156   LinkedListIterator<OpenboxWindow> it(stackingList);
157   for (OpenboxWindow *bw = it.current(); bw; it++, bw = it.current())
158     bw->deiconify(False, False);
159 }
160
161
162 void Workspace::hideAll(void) {
163   LinkedList<OpenboxWindow> lst;
164
165   LinkedListIterator<OpenboxWindow> it(stackingList);
166   for (OpenboxWindow *bw = it.current(); bw; it++, bw = it.current())
167     lst.insert(bw, 0);
168
169   LinkedListIterator<OpenboxWindow> it2(&lst);
170   for (OpenboxWindow *bw = it2.current(); bw; it2++, bw = it2.current())
171     if (! bw->isStuck())
172       bw->withdraw();
173 }
174
175
176 void Workspace::removeAll(void) {
177   LinkedListIterator<OpenboxWindow> it(windowList);
178   for (OpenboxWindow *bw = it.current(); bw; it++, bw = it.current())
179     bw->iconify();
180 }
181
182
183 void Workspace::raiseWindow(OpenboxWindow *w) {
184   OpenboxWindow *win = (OpenboxWindow *) 0, *bottom = w;
185
186   while (bottom->isTransient() && bottom->getTransientFor())
187     bottom = bottom->getTransientFor();
188
189   int i = 1;
190   win = bottom;
191   while (win->hasTransient() && win->getTransient()) {
192     win = win->getTransient();
193
194     i++;
195   }
196
197   Window *nstack = new Window[i], *curr = nstack;
198   Workspace *wkspc;
199
200   win = bottom;
201   while (True) {
202     *(curr++) = win->getFrameWindow();
203     screen.updateNetizenWindowRaise(win->getClientWindow());
204
205     if (! win->isIconic()) {
206       wkspc = screen.getWorkspace(win->getWorkspaceNumber());
207       wkspc->stackingList->remove(win);
208       wkspc->stackingList->insert(win, 0);
209     }
210
211     if (! win->hasTransient() || ! win->getTransient())
212       break;
213
214     win = win->getTransient();
215   }
216
217   screen.raiseWindows(nstack, i);
218
219   delete [] nstack;
220 }
221
222
223 void Workspace::lowerWindow(OpenboxWindow *w) {
224   OpenboxWindow *win = (OpenboxWindow *) 0, *bottom = w;
225
226   while (bottom->isTransient() && bottom->getTransientFor())
227     bottom = bottom->getTransientFor();
228
229   int i = 1;
230   win = bottom;
231   while (win->hasTransient() && win->getTransient()) {
232     win = win->getTransient();
233
234     i++;
235   }
236
237   Window *nstack = new Window[i], *curr = nstack;
238   Workspace *wkspc;
239
240   while (True) {
241     *(curr++) = win->getFrameWindow();
242     screen.updateNetizenWindowLower(win->getClientWindow());
243
244     if (! win->isIconic()) {
245       wkspc = screen.getWorkspace(win->getWorkspaceNumber());
246       wkspc->stackingList->remove(win);
247       wkspc->stackingList->insert(win);
248     }
249
250     if (! win->getTransientFor())
251       break;
252
253     win = win->getTransientFor();
254   }
255
256   screen.getOpenbox().grab();
257
258   XLowerWindow(screen.getBaseDisplay().getXDisplay(), *nstack);
259   XRestackWindows(screen.getBaseDisplay().getXDisplay(), nstack, i);
260
261   screen.getOpenbox().ungrab();
262
263   delete [] nstack;
264 }
265
266
267 void Workspace::reconfigure(void) {
268   clientmenu->reconfigure();
269
270   LinkedListIterator<OpenboxWindow> it(windowList);
271   for (OpenboxWindow *bw = it.current(); bw; it++, bw = it.current()) {
272     if (bw->validateClient())
273       bw->reconfigure();
274   }
275 }
276
277
278 OpenboxWindow *Workspace::getWindow(int index) {
279   if ((index >= 0) && (index < windowList->count()))
280     return windowList->find(index);
281   else
282     return 0;
283 }
284
285
286 const int Workspace::getCount(void) {
287   return windowList->count();
288 }
289
290
291 void Workspace::update(void) {
292   clientmenu->update();
293   screen.getToolbar()->redrawWindowLabel(True);
294 }
295
296
297 Bool Workspace::isCurrent(void) {
298   return (id == screen.getCurrentWorkspaceID());
299 }
300
301
302 Bool Workspace::isLastWindow(OpenboxWindow *w) {
303   return (w == windowList->last());
304 }
305
306 void Workspace::setCurrent(void) {
307   screen.changeWorkspaceID(id);
308 }
309
310
311 void Workspace::setName(char *new_name) {
312   if (name)
313     delete [] name;
314
315   if (new_name) {
316     name = bstrdup(new_name);
317   } else {
318     name = new char[128];
319     sprintf(name, i18n->getMessage(WorkspaceSet, WorkspaceDefaultNameFormat,
320                                    "Workspace %d"), id + 1);
321   }
322   
323   clientmenu->setLabel(name);
324   clientmenu->update();
325   screen.saveWorkspaceNames();
326 }
327
328
329 void Workspace::shutdown(void) {
330   while (windowList->count()) {
331     windowList->first()->restore();
332     delete windowList->first();
333   }
334 }
335
336 static rectList calcSpace(const Rect &win, const rectList &spaces) {
337   rectList result;
338   rectList::const_iterator siter;
339   for(siter=spaces.begin(); siter!=spaces.end(); ++siter) {
340     if(win.Intersect(*siter)) {
341       //Check for space to the left of the window
342       if(win.origin().x() > siter->x())
343         result.push_back(Rect(siter->x(), siter->y(),
344                               win.origin().x() - siter->x() - 1,
345                               siter->h()));
346       //Check for space above the window
347       if(win.origin().y() > siter->y())
348         result.push_back(Rect(siter->x(), siter->y(),
349                               siter->w(),
350                               win.origin().y() - siter->y() - 1));
351       //Check for space to the right of the window
352       if((win.origin().x()+win.size().w()) <
353          (siter->x()+siter->w()))
354         result.push_back(Rect(win.origin().x() + win.size().w() + 1,
355                               siter->y(),
356                               siter->x() + siter->w() -
357                               win.origin().x() - win.size().w() - 1,
358                               siter->h()));
359       //Check for space below the window
360       if((win.origin().y()+win.size().h()) <
361          (siter->y()+siter->h()))
362         result.push_back(Rect(siter->x(),
363                               win.origin().y() + win.size().h() + 1,
364                               siter->w(),
365                               siter->y() + siter->h()-
366                               win.origin().y() - win.size().h() - 1));
367
368     }
369     else
370       result.push_back(*siter);
371   }
372   return result;
373 }
374
375
376 bool incWidth(const Rect &first, const Rect &second) {
377   return first.x() < second.x();
378 }
379
380
381 bool decWidth(const Rect &first, const Rect &second) {
382   if (second.x() == first.x())
383      return second.w() < first.w();
384   return second.x() < first.x();
385 }
386
387
388 bool incHeight(const Rect &first, const Rect &second) {
389   return first.y() < second.y();
390 }
391
392
393 bool decHeight(const Rect &first, const Rect &second) {
394   if (second.y() == first.y())
395      return second.h() < first.h();
396   return second.y() < first.y();
397 }
398
399
400 //BestFitPlacement finds the smallest free space that fits the window
401 //to be placed. It currentl ignores whether placement is right to left or top
402 //to bottom.
403 Point *Workspace::bestFitPlacement(const Size &win_size, const Rect &space) {
404   const Rect *best;
405   rectList spaces;
406   LinkedListIterator<OpenboxWindow> it(windowList);
407   rectList::const_iterator siter;
408   spaces.push_back(space); //initially the entire screen is free
409   it.reset();
410   
411   //Find Free Spaces
412   for (OpenboxWindow *cur=it.current(); cur!=NULL; it++, cur=it.current())
413      spaces = calcSpace(cur->area().Inflate(screen.getBorderWidth() * 4),
414                         spaces);
415   
416   //Find first space that fits the window
417   best = NULL;
418   for (siter=spaces.begin(); siter!=spaces.end(); ++siter) {
419     if ((siter->w() >= win_size.w()) && (siter->h() >= win_size.h())) {
420       if (best == NULL)
421         best = siter;
422       else if (win_size.w() * win_size.h() - siter->w() * siter->h() <
423                best->w() + best->h())
424         best = siter;
425     }
426   }
427   if (best != NULL) {
428     Point *pt = new Point(best->origin());
429     if (screen.colPlacementDirection() != BScreen::TopBottom)
430       pt->setY(pt->y() + (best->h() - win_size.h()));
431     if (screen.rowPlacementDirection() != BScreen::LeftRight)
432       pt->setX(pt->x() + (best->w() - win_size.w()));
433     return pt;
434   } else
435     return NULL; //fall back to cascade
436 }
437
438
439 Point *Workspace::rowSmartPlacement(const Size &win_size, const Rect &space) {
440   const Rect *best;
441   rectList spaces;
442   LinkedListIterator<OpenboxWindow> it(windowList);
443   rectList::const_iterator siter;
444   spaces.push_back(space); //initially the entire screen is free
445   it.reset();
446   
447   //Find Free Spaces
448   for (OpenboxWindow *cur=it.current(); cur!=NULL; it++, cur=it.current())
449      spaces = calcSpace(cur->area().Inflate(screen.getBorderWidth() * 4),
450                         spaces);
451   
452   //Sort the spaces by placement choice
453   if (screen.rowPlacementDirection() == BScreen::TopBottom)
454      sort(spaces.begin(),spaces.end(),incHeight);
455   else
456      sort(spaces.begin(),spaces.end(),decHeight);
457
458   //Find first space that fits the window
459   best = NULL;
460   for (siter=spaces.begin(); siter!=spaces.end(); ++siter)
461     if ((siter->w() >= win_size.w()) && (siter->h() >= win_size.h())) {
462       best = siter;
463       break;
464     }
465
466   if (best != NULL) {
467     Point *pt = new Point(best->origin());
468     if (screen.colPlacementDirection() != BScreen::TopBottom)
469       pt->setY(pt->y() + (best->h() - win_size.h()));
470     if (screen.rowPlacementDirection() != BScreen::LeftRight)
471       pt->setX(pt->x() + (best->w() - win_size.w()));
472     return pt;
473   } else
474     return NULL; //fall back to cascade
475 }
476
477 /*
478 inline Point *Workspace::rowSmartPlacement(const Size &win_size,
479                                            const Rect &space){
480   bool placed=false;
481   int test_x, test_y, place_x = 0, place_y = 0;
482   int start_pos = 0;
483   int change_y =
484      ((screen.colPlacementDirection() == BScreen::TopBottom) ? 1 : -1);
485   int change_x =
486      ((screen.rowPlacementDirection() == BScreen::LeftRight) ? 1 : -1);
487   int delta_x = 8, delta_y = 8;
488   LinkedListIterator<OpenboxWindow> it(windowList);
489
490   test_y = (screen.colPlacementDirection() == BScreen::TopBottom) ?
491     start_pos : screen.size().h() - win_size.h() - start_pos;
492
493   while(!placed &&
494         ((screen.colPlacementDirection() == BScreen::BottomTop) ?
495          test_y > 0 : test_y + win_size.h() < (signed) space.h())) {
496     test_x = (screen.rowPlacementDirection() == BScreen::LeftRight) ?
497       start_pos : space.w() - win_size.w() - start_pos;
498     while (!placed &&
499            ((screen.rowPlacementDirection() == BScreen::RightLeft) ?
500             test_x > 0 : test_x + win_size.w() < (signed) space.w())) {
501       placed = true;
502
503       it.reset();
504       for (OpenboxWindow *curr = it.current(); placed && curr;
505            it++, curr = it.current()) {
506         int curr_w = curr->size().w() + (screen.getBorderWidth() * 4);
507         int curr_h = curr->size().h() + (screen.getBorderWidth() * 4);
508
509         if (curr->origin().x() < test_x + win_size.w() &&
510             curr->origin().x() + curr_w > test_x &&
511             curr->origin().y() < test_y + win_size.h() &&
512             curr->origin().y() + curr_h > test_y) {
513           placed = false;
514         }
515       }
516
517       // Removed code for checking toolbar and slit
518       // The space passed in should not include either
519
520       if (placed) {
521         place_x = test_x;
522         place_y = test_y;
523
524         break;
525       }   
526
527       test_x += (change_x * delta_x);
528     }
529
530     test_y += (change_y * delta_y);
531   }
532   if (placed)
533     return new Point(place_x, place_y);
534   else
535     return NULL; // fall back to cascade
536 }
537 */
538
539 Point *Workspace::colSmartPlacement(const Size &win_size, const Rect &space) {
540   const Rect *best;
541   rectList spaces;
542   LinkedListIterator<OpenboxWindow> it(windowList);
543   rectList::const_iterator siter;
544   spaces.push_back(space); //initially the entire screen is free
545   it.reset();
546   
547   //Find Free Spaces
548   for (OpenboxWindow *cur=it.current(); cur!=NULL; it++, cur=it.current())
549      spaces = calcSpace(cur->area().Inflate(screen.getBorderWidth() * 4),
550                         spaces);
551   
552   //Sort the spaces by placement choice
553   if (screen.rowPlacementDirection() == BScreen::LeftRight)
554      sort(spaces.begin(),spaces.end(),incWidth);
555   else
556      sort(spaces.begin(),spaces.end(),decWidth);
557
558   //Find first space that fits the window
559   best = NULL;
560   for (siter=spaces.begin(); siter!=spaces.end(); ++siter)
561     if ((siter->w() >= win_size.w()) && (siter->h() >= win_size.h())) {
562       best = siter;
563       break;
564     }
565
566   if (best != NULL) {
567     Point *pt = new Point(best->origin());
568     if (screen.colPlacementDirection() != BScreen::TopBottom)
569       pt->setY(pt->y() + (best->h() - win_size.h()));
570     if (screen.rowPlacementDirection() != BScreen::LeftRight)
571       pt->setX(pt->x() + (best->w() - win_size.w()));
572     return pt;
573   } else
574     return NULL; //fall back to cascade
575 }
576
577 /*
578 inline Point * Workspace::colSmartPlacement(const Size &win_size,
579                                             const Rect &space){
580   Point *pt;
581   bool placed=false;
582   int test_x, test_y;
583   int start_pos = 0;
584   int change_y =
585     ((screen.colPlacementDirection() == BScreen::TopBottom) ? 1 : -1);
586   int change_x =
587     ((screen.rowPlacementDirection() == BScreen::LeftRight) ? 1 : -1);
588   int delta_x = 8, delta_y = 8;
589   LinkedListIterator<OpenboxWindow> it(windowList);
590
591   test_x = (screen.rowPlacementDirection() == BScreen::LeftRight) ?
592     start_pos : screen.size().w() - win_size.w() - start_pos;
593
594   while(!placed &&
595         ((screen.rowPlacementDirection() == BScreen::RightLeft) ?
596          test_x > 0 : test_x + win_size.w() < (signed) space.w())) {
597     test_y = (screen.colPlacementDirection() == BScreen::TopBottom) ?
598       start_pos : screen.size().h() - win_size.h() - start_pos;
599
600     while(!placed &&
601           ((screen.colPlacementDirection() == BScreen::BottomTop) ?
602            test_y > 0 : test_y + win_size.h() < (signed) space.h())){
603
604       placed = true;
605
606       it.reset();
607       for (OpenboxWindow *curr = it.current(); placed && curr;
608            it++, curr = it.current()) {
609         int curr_w = curr->size().w() + (screen.getBorderWidth() * 4);
610         int curr_h = curr->size().h() + (screen.getBorderWidth() * 4);
611
612         if (curr->origin().x() < test_x + win_size.w() &&
613             curr->origin().x() + curr_w > test_x &&
614             curr->origin().y() < test_y + win_size.h() &&
615             curr->origin().y() + curr_h > test_y) {
616           placed = False;
617         }
618       }
619
620       // Removed code checking for intersection with Toolbar and Slit
621       // The space passed to this method should not include either
622
623       if (placed) {
624         pt= new Point(test_x,test_y);
625
626         break;
627       }
628
629       test_y += (change_y * delta_y);
630     }
631
632     test_x += (change_x * delta_x);
633   }
634   if (placed)
635     return pt;
636   else
637     return NULL;
638 }
639 */
640
641 Point *const Workspace::cascadePlacement(const OpenboxWindow *const win){
642   if (((unsigned) cascade_x > (screen.size().w() / 2)) ||
643       ((unsigned) cascade_y > (screen.size().h() / 2)))
644     cascade_x = cascade_y = 32;
645
646   cascade_x += win->getTitleHeight();
647   cascade_y += win->getTitleHeight();
648
649   return new Point(cascade_x, cascade_y);
650 }
651
652
653 void Workspace::placeWindow(OpenboxWindow *win) {
654   ASSERT(win != NULL);
655
656   // the following code is temporary and will be taken care of by Screen in the
657   // future (with the NETWM 'strut')
658   Rect space(0, 0, screen.size().w(), screen.size().h());
659
660 #ifdef    SLIT
661   Slit *slit = screen.getSlit();
662   Toolbar *toolbar = screen.getToolbar();
663   int tbarh = screen.hideToolbar() ? 0 :
664     toolbar->getExposedHeight() + screen.getBorderWidth() * 2;
665   bool tbartop;
666   switch (toolbar->placement()) {
667   case Toolbar::TopLeft:
668   case Toolbar::TopCenter:
669   case Toolbar::TopRight:
670     tbartop = true;
671     break;
672   case Toolbar::BottomLeft:
673   case Toolbar::BottomCenter:
674   case Toolbar::BottomRight:
675     tbartop = false;
676     break;
677   default:
678     ASSERT(false);      // unhandled placement
679   }
680   if ((slit->direction() == Slit::Horizontal &&
681        (slit->placement() == Slit::TopLeft ||
682         slit->placement() == Slit::TopRight)) ||
683       slit->placement() == Slit::TopCenter) {
684     // exclude top
685     if (tbartop) {
686       space.setY(slit->area().y());
687       space.setH(space.h() - space.y());
688     } else
689       space.setH(space.h() - tbarh);
690     space.setY(space.y() + slit->area().h() + screen.getBorderWidth() * 2);
691     space.setH(space.h() - (slit->area().h() + screen.getBorderWidth() * 2));
692   } else if ((slit->direction() == Slit::Vertical &&
693               (slit->placement() == Slit::TopRight ||
694                slit->placement() == Slit::BottomRight)) ||
695              slit->placement() == Slit::CenterRight) {
696     // exclude right
697     space.setW(space.w() - (slit->area().w() + screen.getBorderWidth() * 2));
698     if (tbartop)
699       space.setY(space.y() + tbarh);
700     space.setH(space.h() - tbarh);
701   } else if ((slit->direction() == Slit::Horizontal &&
702               (slit->placement() == Slit::BottomLeft ||
703                slit->placement() == Slit::BottomRight)) ||
704              slit->placement() == Slit::BottomCenter) {
705     // exclude bottom
706     space.setH(space.h() - (screen.size().h() - slit->area().y()));
707   } else {// if ((slit->direction() == Slit::Vertical &&
708     //      (slit->placement() == Slit::TopLeft ||
709     //       slit->placement() == Slit::BottomLeft)) ||
710     //     slit->placement() == Slit::CenterLeft)
711     // exclude left
712     space.setX(slit->area().w() + screen.getBorderWidth() * 2);
713     space.setW(space.w() - (slit->area().w() + screen.getBorderWidth() * 2));
714     if (tbartop)
715       space.setY(space.y() + tbarh);
716     space.setH(space.h() - tbarh);
717   }
718 #else // !SLIT
719   Toolbar *toolbar = screen.getToolbar();
720   int tbarh = screen.hideToolbar() ? 0 :
721     toolbar->getExposedHeight() + screen.getBorderWidth() * 2;
722   switch (toolbar->placement()) {
723   case Toolbar::TopLeft:
724   case Toolbar::TopCenter:
725   case Toolbar::TopRight:
726     space.setY(toolbar->getExposedHeight());
727     space.setH(space.h() - toolbar->getExposedHeight());
728     break;
729   case Toolbar::BottomLeft:
730   case Toolbar::BottomCenter:
731   case Toolbar::BottomRight:
732     space.setH(space.h() - tbarh);
733     break;
734   default:
735     ASSERT(false);      // unhandled placement
736   }
737 #endif // SLIT
738
739   const int win_w = win->size().w() + (screen.getBorderWidth() * 4),
740   win_h = win->size().h() + (screen.getBorderWidth() * 4),
741   start_pos = 0,
742   change_y =
743     ((screen.colPlacementDirection() == BScreen::TopBottom) ? 1 : -1),
744   change_x =
745     ((screen.rowPlacementDirection() == BScreen::LeftRight) ? 1 : -1),
746     delta_x = 8, delta_y = 8;
747
748   LinkedListIterator<OpenboxWindow> it(windowList);
749
750   Size window_size(win->size().w()+screen.getBorderWidth() * 4,
751                    win->size().h()+screen.getBorderWidth() * 4);
752   Point *place = NULL;
753
754   switch (screen.placementPolicy()) {
755   case BScreen::BestFitPlacement:
756     place = bestFitPlacement(window_size, space);
757     break;
758   case BScreen::RowSmartPlacement:
759     place = rowSmartPlacement(window_size, space);
760     break;
761   case BScreen::ColSmartPlacement:
762     place = colSmartPlacement(window_size, space);
763     break;
764   } // switch
765
766   if (place == NULL)
767     place = cascadePlacement(win);
768  
769   ASSERT(place != NULL);  
770   if (place->x() + win_w > (signed) screen.size().w())
771     place->setX(((signed) screen.size().w() - win_w) / 2);
772   if (place->y() + win_h > (signed) screen.size().h())
773     place->setY(((signed) screen.size().h() - win_h) / 2);
774
775   win->configure(place->x(), place->y(), win->size().w(), win->size().h());
776   delete place;
777 }