aboutsummaryrefslogtreecommitdiff
path: root/src/Workspace.cc
blob: ad67c8b0833076801602b5e078a63a954a33d9bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
// Workspace.cc for Fluxbox
// Copyright (c) 2001 - 2002 Henrik Kinnunen (fluxgen@linuxmail.org)
//
// Workspace.cc for Blackbox - an X11 Window manager
// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.	IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

// $Id: Workspace.cc,v 1.24 2002/08/16 11:02:41 fluxgen Exp $

#include "Workspace.hh"

#include "i18n.hh"
#include "fluxbox.hh"
#include "Clientmenu.hh"
#include "Screen.hh"
#include "Toolbar.hh"
#include "Window.hh"
#include "Windowmenu.hh"
#include "StringUtil.hh"

// use GNU extensions
#ifndef	 _GNU_SOURCE
#define	 _GNU_SOURCE
#endif // _GNU_SOURCE

#ifdef HAVE_CONFIG_H
#include "../config.h"
#endif // HAVE_CONFIG_H

#include <X11/Xlib.h>
#include <X11/Xatom.h>

#include <cstdio>
#include <cstring>

#include <algorithm>
#include <iostream>

using namespace std;

Workspace::GroupList Workspace::m_groups;

Workspace::Workspace(BScreen *scrn, unsigned int i):
screen(scrn),
lastfocus(0),
m_clientmenu(this),
m_name(""),
m_id(i),
cascade_x(32), cascade_y(32) {

	setName(screen->getNameOfWorkspace(m_id));

}


Workspace::~Workspace() {

}


int Workspace::addWindow(FluxboxWindow *w, bool place) {
	if (! w)
		return -1;

	if (place)
		placeWindow(w);

	w->setWorkspace(m_id);
	w->setWindowNumber(windowList.size());

	stackingList.push_front(w);

	//insert window after the currently focused window	
	//FluxboxWindow *focused = Fluxbox::instance()->getFocusedWindow();	

	//if there isn't any window that's focused, just add it to the end of the list
	/*
	if (focused == 0) {
		windowList.push_back(w);
		//Add client to clientmenu
		m_clientmenu.insert(w->getTitle().c_str());
	} else {
		Windows::iterator it = windowList.begin();
		size_t client_insertpoint=0;
		for (; it != windowList.end(); ++it, ++client_insertpoint) {
			if (*it == focused) {
				++it;				
				break;
			}
		}

		windowList.insert(it, w);
		//Add client to clientmenu
		m_clientmenu.insert(w->getTitle().c_str(), client_insertpoint);
		

	}
	*/
	//add to list
	m_clientmenu.insert(w->getTitle().c_str());
	windowList.push_back(w);
	
	//update menugraphics
	m_clientmenu.update();
	
	screen->updateNetizenWindowAdd(w->getClientWindow(), m_id);

	raiseWindow(w);

	return w->getWindowNumber();
}


int Workspace::removeWindow(FluxboxWindow *w) {
	if (! w) 
		return -1;

	stackingList.remove(w);

	if (w->isFocused()) {
		if (screen->isSloppyFocus()) {
			Fluxbox::instance()->setFocusedWindow(0); // set focused window to none
		} else if (w->isTransient() && w->getTransientFor() &&
				w->getTransientFor()->isVisible()) {
			if (w->getTransientFor() == w) // FATAL ERROR, this should not happend
				abort();
			w->getTransientFor()->setInputFocus();
		} else {
			FluxboxWindow *top = 0;
			if (stackingList.size()!=0)
				top = stackingList.front();

			if (!top || !top->setInputFocus()) {
				Fluxbox::instance()->setFocusedWindow(0); // set focused window to none
				XSetInputFocus(Fluxbox::instance()->getXDisplay(),
					screen->getToolbar()->getWindowID(),
					RevertToParent, CurrentTime);						
			}
		}
	}
	
	if (lastfocus == w)
		lastfocus = 0;

	//could be faster?
	Windows::iterator it = windowList.begin();
	Windows::iterator it_end = windowList.end();
	for (; it != it_end; ++it) {
		if (*it == w) {
			windowList.erase(it);
			break;
		}
	}

	m_clientmenu.remove(w->getWindowNumber());
	m_clientmenu.update();

	screen->updateNetizenWindowDel(w->getClientWindow());

	{
		Windows::iterator it = windowList.begin();
		Windows::const_iterator it_end = windowList.end();
		for (int i = 0; it != it_end; ++it, ++i) {
			(*it)->setWindowNumber(i);
		}
	}

	return windowList.size();
}


void Workspace::showAll(void) {
	WindowStack::iterator it = stackingList.begin();
	WindowStack::iterator it_end = stackingList.end();
	for (; it != it_end; ++it) {
		(*it)->deiconify(False, False);
	}
}


void Workspace::hideAll(void) {
	WindowStack::reverse_iterator it = stackingList.rbegin();
	WindowStack::reverse_iterator it_end = stackingList.rend();
	for (; it != it_end; ++it) {
		if (! (*it)->isStuck())
			(*it)->withdraw();
	}
}


void Workspace::removeAll(void) {
	Windows::iterator it = windowList.begin();
	Windows::const_iterator it_end = windowList.end();
	for (; it != it_end; ++it) {
		(*it)->iconify();
	}
}


void Workspace::raiseWindow(FluxboxWindow *w) {
	FluxboxWindow *win = (FluxboxWindow *) 0, *bottom = w;

	while (bottom->isTransient() && bottom->getTransientFor() &&
			bottom->getTransientFor() != bottom) //prevent infinite loop
		bottom = bottom->getTransientFor();

	int i = 1;
	win = bottom;
	while (win->hasTransient() && win->getTransient() &&
			win->getTransient() != win) {//prevent infinite loop
		win = win->getTransient();

		i++;
	}

	Window *nstack = new Window[i], *curr = nstack;
	Workspace *wkspc;

	win = bottom;
	while (True) {
		*(curr++) = win->getFrameWindow();
		screen->updateNetizenWindowRaise(win->getClientWindow());

		if (! win->isIconic()) {
			wkspc = screen->getWorkspace(win->getWorkspaceNumber());
			wkspc->stackingList.remove(win);
			wkspc->stackingList.push_front(win);
		}

		if (! win->hasTransient() || ! win->getTransient() ||
			win->getTransient() == win) //prevent infinite loop
			break;
		
		win = win->getTransient();
	}

	screen->raiseWindows(nstack, i);

	delete [] nstack;
}

void Workspace::lowerWindow(FluxboxWindow *w) {
	FluxboxWindow *win = (FluxboxWindow *) 0, *bottom = w;

	while (bottom->isTransient() && bottom->getTransientFor()
			&& bottom->getTransientFor() != bottom) //prevent infinite loop
		bottom = bottom->getTransientFor();

	int i = 1;
	win = bottom;
	while (win->hasTransient() && win->getTransient() && 
			win->getTransient() != win) { //prevent infinite loop
		win = win->getTransient();

		i++;
	}

	Window *nstack = new Window[i], *curr = nstack;
	Workspace *wkspc;

	while (True) {
		*(curr++) = win->getFrameWindow();
		screen->updateNetizenWindowLower(win->getClientWindow());

		if (! win->isIconic()) {
			wkspc = screen->getWorkspace(win->getWorkspaceNumber());
			wkspc->stackingList.remove(win);
			wkspc->stackingList.push_back(win);
		}

		if (! win->getTransientFor() || 
			win->getTransientFor() == win)//prevent infinite loop
			break;

		win = win->getTransientFor();
	}

	Fluxbox::instance()->grab();

	XLowerWindow(screen->getBaseDisplay()->getXDisplay(), *nstack);
	XRestackWindows(screen->getBaseDisplay()->getXDisplay(), nstack, i);

	Fluxbox::instance()->ungrab();

	delete [] nstack;
}


void Workspace::reconfigure(void) {
	m_clientmenu.reconfigure();

	Windows::iterator it = windowList.begin();
	Windows::iterator it_end = windowList.end();
	for (; it != it_end; ++it) {
		if ((*it)->validateClient())
			(*it)->reconfigure();
	}
}


const FluxboxWindow *Workspace::getWindow(unsigned int index) const {
	if (index < windowList.size())
		return windowList[index];
	return 0;
}

FluxboxWindow *Workspace::getWindow(unsigned int index) {
	if (index < windowList.size())
		return windowList[index];
	return 0;
}


int Workspace::getCount() const {
	return windowList.size();
}

namespace {
// helper class for checkGrouping
class FindInGroup {
public:
	FindInGroup(const FluxboxWindow &w):m_w(w) { }
	bool operator ()(const string &name) {
		return (name == m_w.instanceName());
	}
private:
	const FluxboxWindow &m_w;
};

};

//Note: this function doesn't check if the window is groupable
void Workspace::checkGrouping(FluxboxWindow &win) {
#ifdef DEBUG
	cerr<<__FILE__<<"("<<__LINE__<<"): Checking grouping. ("<<win.instanceName()<<"/"<<
		win.className()<<")"<<endl;	
#endif // DEBUG

	// go throu every group and search for matching win instancename
	GroupList::iterator g(m_groups.begin());
	GroupList::iterator g_end(m_groups.end());
	for (; g != g_end; ++g) {
		Group::iterator name((*g).begin());
		Group::iterator name_end((*g).end());
		for (; name != name_end; ++name) {

			if ((*name) != win.instanceName())
				continue;

			// find a window with the specific name
			Windows::iterator wit(getWindowList().begin());
			Windows::iterator wit_end(getWindowList().end());
			for (; wit != wit_end; ++wit) {
#ifdef DEBUG
				cerr<<__FILE__<<" check group with : "<<(*wit)->instanceName()<<endl;
#endif // DEBUG
				if (find_if((*g).begin(), (*g).end(), FindInGroup(*(*wit))) != (*g).end()) {
					//toggle tab on
					if ((*wit)->getTab() == 0)
						(*wit)->setTab(true);
					if (win.getTab() == 0)
						win.setTab(true);
					(*wit)->getTab()->insert(win.getTab());

					return; // grouping done
				}
			}

		}

	}
}

bool Workspace::loadGroups(const std::string &filename) {
	ifstream infile(filename.c_str());
	if (!infile)
		return false;
	m_groups.clear(); // erase old groups

	// load new groups
	while (!infile.eof()) {
		string line;
		vector<string> names;
		getline(infile, line);
		StringUtil::stringtok(names, line);
		m_groups.push_back(names);
	}
	
	return true;
}

void Workspace::update() {
	m_clientmenu.update();
	screen->getToolbar()->redrawWindowLabel(True);
}


bool Workspace::isCurrent() const{
	return (m_id == screen->getCurrentWorkspaceID());
}


bool Workspace::isLastWindow(FluxboxWindow *w) const{
	return (w == windowList.back());
}

void Workspace::setCurrent(void) {
	screen->changeWorkspaceID(m_id);
}


void Workspace::setName(const std::string &name) {
	if (name.size() != 0) {
		m_name = name;
	} else { //if name == 0 then set default name from nls
		char tname[128];
		sprintf(tname, I18n::instance()->
			getMessage(
			FBNLS::WorkspaceSet, FBNLS::WorkspaceDefaultNameFormat,
			"Workspace %d"), m_id + 1); //m_id starts at 0
		m_name = tname;
	}
	
	screen->updateWorkspaceNamesAtom();
	
	m_clientmenu.setLabel(m_name.c_str());
	m_clientmenu.update();
}

//------------ shutdown ---------
// Calls restore on all windows
// on the workspace and then
// clears the windowList
//-------------------------------
void Workspace::shutdown() {
	// note: when the window dies it'll remove it self from the list
	while (!windowList.empty()) {
		windowList.back()->restore(true); // restore with remap
		delete windowList.back(); //delete window (the window removes it self from windowList)
	}
}


void Workspace::placeWindow(FluxboxWindow *win) {
	Bool placed = False;
	int borderWidth4x = screen->getBorderWidth2x() * 2,
#ifdef		SLIT
		slit_x = screen->getSlit()->x() - screen->getBorderWidth(),
		slit_y = screen->getSlit()->y() - screen->getBorderWidth(),
		slit_w = screen->getSlit()->width() + borderWidth4x,
		slit_h = screen->getSlit()->height() + borderWidth4x,
#endif // SLIT
		toolbar_x = screen->getToolbar()->getX() - screen->getBorderWidth(),
		toolbar_y = screen->getToolbar()->getY() - screen->getBorderWidth(),
		toolbar_w = screen->getToolbar()->getWidth() + borderWidth4x,
		toolbar_h = screen->getToolbar()->getHeight() + borderWidth4x,
		place_x = 0, place_y = 0, change_x = 1, change_y = 1;

	if (screen->getColPlacementDirection() == BScreen::BOTTOMTOP)
		change_y = -1;
	if (screen->getRowPlacementDirection() == BScreen::RIGHTLEFT)
		change_x = -1;

#ifdef XINERAMA
	int head = 0,
			head_x = 0,
			head_y = 0;
	int head_w, head_h;
	if (screen->hasXinerama()) {
		head = screen->getCurrHead();
		head_x = screen->getHeadX(head);
		head_y = screen->getHeadY(head);
		head_w = screen->getHeadWidth(head);
		head_h = screen->getHeadHeight(head);

	} else { // no xinerama
		head_w = screen->getWidth();
		head_h = screen->getHeight();
	}

#endif // XINERAMA

	int win_w = win->getWidth() + screen->getBorderWidth2x(),
			win_h = win->getHeight() + screen->getBorderWidth2x();

	if (win->hasTab()) {
		if ((! win->isShaded()) &&
				screen->getTabPlacement() == Tab::PLEFT ||
				screen->getTabPlacement() == Tab::PRIGHT)
			win_w += (screen->isTabRotateVertical())
				? screen->getTabHeight()
				: screen->getTabWidth();
		else // tab placement top or bottom or win is shaded
			win_h += screen->getTabHeight();
	}

	register int test_x, test_y, curr_x, curr_y, curr_w, curr_h;

	switch (screen->getPlacementPolicy()) {
	case BScreen::ROWSMARTPLACEMENT: {
	#ifdef XINERAMA
		test_y = head_y;
	#else // !XINERAMA
		test_y = 0;
	#endif // XINERAMA
		if (screen->getColPlacementDirection() == BScreen::BOTTOMTOP)
		#ifdef XINERAMA
			test_y = (head_y + head_h) - win_h - test_y;
		#else // !XINERAMA
			test_y = screen->getHeight() - win_h - test_y;
		#endif // XINERAMA

		while (((screen->getColPlacementDirection() == BScreen::BOTTOMTOP) ?
			#ifdef XINERAMA
				test_y >= head_y : test_y + win_h <= (head_y + head_h)) &&
			#else // !XINERAMA
				test_y > 0 : test_y + win_h < (signed) screen->getHeight()) &&
			#endif // XINERAMA
				! placed) {

		#ifdef XINERAMA
			test_x = head_x;
		#else // !XINERAMA
			test_x = 0;
		#endif // XINERAMA
			if (screen->getRowPlacementDirection() == BScreen::RIGHTLEFT)
			#ifdef XINERAMA
				test_x = (head_x + head_w) - win_w - test_x;
			#else // !XINERAMA
				test_x = screen->getWidth() - win_w - test_x;
			#endif // XINERAMA

			while (((screen->getRowPlacementDirection() == BScreen::RIGHTLEFT) ?
				#ifdef XINERAMA
					test_x >= head_x : test_x + win_w <= (head_x + head_w)) &&
				#else // !XINERAMA
					test_x > 0 : test_x + win_w < (signed) screen->getWidth()) &&
				#endif // XINERAMA
					! placed) {

				placed = True;

				Windows::iterator it = windowList.begin();
				Windows::iterator it_end = windowList.end();

				for (; it != it_end && placed; ++it) {
					curr_x = (*it)->getXFrame();
					curr_y = (*it)->getYFrame();
					curr_w = (*it)->getWidth() + screen->getBorderWidth2x();
					curr_h =
						(((*it)->isShaded())
							? (*it)->getTitleHeight()
							: (*it)->getHeight()) +
							screen->getBorderWidth2x();	

					if ((*it)->hasTab()) {
						if (! (*it)->isShaded()) { // not shaded window
							switch(screen->getTabPlacement()) {
							case Tab::PTOP:
								curr_y -= screen->getTabHeight();
							case Tab::PBOTTOM:
								curr_h += screen->getTabHeight();
								break;
							case Tab::PLEFT:
								curr_x -= (screen->isTabRotateVertical())
									? screen->getTabHeight()
									: screen->getTabWidth();
							case Tab::PRIGHT:
								curr_w += (screen->isTabRotateVertical())
									? screen->getTabHeight()
									: screen->getTabWidth();
								break;
							}
						} else { // shaded window
							if (screen->getTabPlacement() == Tab::PTOP)
								curr_y -= screen->getTabHeight();
							curr_h += screen->getTabHeight();
						}
					} // tab cheking done

					if (curr_x < test_x + win_w &&
							curr_x + curr_w > test_x &&
							curr_y < test_y + win_h &&
							curr_y + curr_h > test_y) {
						placed = False;
					}
				}

				if ((toolbar_x < test_x + win_w &&
						 toolbar_x + toolbar_w > test_x &&
						 toolbar_y < test_y + win_h &&
						 toolbar_y + toolbar_h > test_y)
#ifdef		SLIT
						 ||
						(slit_x < test_x + win_w &&
						 slit_x + slit_w > test_x &&
						 slit_y < test_y + win_h &&
						 slit_y + slit_h > test_y)
#endif // SLIT
					)
					placed = False;

				if (placed) {
					place_x = test_x;
					place_y = test_y;

					break;
				}

				test_x += change_x;
			}

			test_y += change_y;
		}

		break; }

	case BScreen::COLSMARTPLACEMENT: {
	#ifdef XINERAMA
		test_x = head_x;
	#else // !XINERAMA
		test_x = 0;
	#endif // XINERAMA
		if (screen->getRowPlacementDirection() == BScreen::RIGHTLEFT)
		#ifdef XINERAMA
			test_x = (head_x + head_w) - win_w - test_x;
		#else // !XINERAMA
			test_x = screen->getWidth() - win_w - test_x;
		#endif // XINERAMA

		while (((screen->getRowPlacementDirection() == BScreen::RIGHTLEFT) ?
			#ifdef XINERAMA
				test_x >= 0 : test_x + win_w <= (head_x + head_w)) &&
			#else // !XINERAMA
				test_x > 0 : test_x + win_w < (signed) screen->getWidth()) &&
			#endif // XINERAMA
				! placed) {

		#ifdef XINERAMA
			test_y = head_y;
		#else // !XINERAMA
			test_y = 0;
		#endif // XINERAMA
			if (screen->getColPlacementDirection() == BScreen::BOTTOMTOP)
			#ifdef XINERAMA
				test_y = (head_y + head_h) - win_h - test_y;
			#else // !XINERAMA
				test_y = screen->getHeight() - win_h - test_y;
			#endif // XINERAMA

			while (((screen->getColPlacementDirection() == BScreen::BOTTOMTOP) ?
				#ifdef XINERAMA
					test_y >= head_y : test_y + win_h <= (head_y + head_h)) &&
				#else // !XINERAMA
					test_y > 0 : test_y + win_h < (signed) screen->getHeight()) &&
				#endif // XINERAMA
					! placed) {
				placed = True;

				Windows::iterator it = windowList.begin();
				Windows::iterator it_end = windowList.end();
				for (; it != it_end && placed; ++it) {
					curr_x = (*it)->getXFrame();
					curr_y = (*it)->getYFrame();
					curr_w = (*it)->getWidth() + screen->getBorderWidth2x();
					curr_h =
						(((*it)->isShaded())
							? (*it)->getTitleHeight()
							: (*it)->getHeight()) +
							screen->getBorderWidth2x();;

					if ((*it)->hasTab()) {
						if (! (*it)->isShaded()) { // not shaded window
							switch(screen->getTabPlacement()) {
							case Tab::PTOP:
								curr_y -= screen->getTabHeight();
							case Tab::PBOTTOM:
								curr_h += screen->getTabHeight();
								break;
							case Tab::PLEFT:
								curr_x -= (screen->isTabRotateVertical())
									? screen->getTabHeight()
									: screen->getTabWidth();
							case Tab::PRIGHT:
								curr_w += (screen->isTabRotateVertical())
									? screen->getTabHeight()
									: screen->getTabWidth();
								break;
							default:
								#ifdef DEBUG
								cerr << __FILE__ << ":" <<__LINE__ << ": " <<
									"Unsupported Placement" << endl;
								#endif // DEBUG
								break;
							}
						} else { // shaded window
							if (screen->getTabPlacement() == Tab::PTOP)
								curr_y -= screen->getTabHeight();
							curr_h += screen->getTabHeight();
						}
					} // tab cheking done

					if (curr_x < test_x + win_w &&
							curr_x + curr_w > test_x &&
							curr_y < test_y + win_h &&
							curr_y + curr_h > test_y) {
						placed = False;
					}
				}

				if ((toolbar_x < test_x + win_w &&
						toolbar_x + toolbar_w > test_x &&
						toolbar_y < test_y + win_h &&
						toolbar_y + toolbar_h > test_y)
#ifdef		SLIT
						||
						(slit_x < test_x + win_w &&
						slit_x + slit_w > test_x &&
						slit_y < test_y + win_h &&
						slit_y + slit_h > test_y)
#endif // SLIT
						)
					placed = False;

			if (placed) {
				place_x = test_x;
				place_y = test_y;
			}

			test_y += change_y;
		}

		test_x += change_x;
	 }

	 break; }
	}

	// cascade placement or smart placement failed
	if (! placed) {
	#ifdef XINERAMA
		if ((cascade_x > (head_w / 2)) ||
				(cascade_y > (head_h / 2)))
	#else // !XINERAMA
		if (((unsigned) cascade_x > (screen->getWidth() / 2)) ||
				((unsigned) cascade_y > (screen->getHeight() / 2)))
	#endif // XINERAMA

			cascade_x = cascade_y = 32;
#ifdef XINERAMA
		place_x = head_x + cascade_x;
		place_y = head_y + cascade_y;
#else // !XINERAMA
		place_x = cascade_x;
		place_y = cascade_y;
#endif // XINERAMA
		cascade_x += win->getTitleHeight();
		cascade_y += win->getTitleHeight();
	}

#ifdef XINERAMA
	if (place_x + win_w > (head_x + head_w))
		place_x = head_x + ((head_w - win_w) / 2);
	if (place_y + win_h > (head_y + head_h))
		place_y = head_y + ((head_h - win_h) / 2);
#else // !XINERAMA
	if (place_x + win_w > (signed) screen->getWidth())
		place_x = (((signed) screen->getWidth()) - win_w) / 2;
	if (place_y + win_h > (signed) screen->getHeight())
		place_y = (((signed) screen->getHeight()) - win_h) / 2;
#endif // XINERAMA

	// fix window placement, think of tabs
	if (win->hasTab()) {
		if (screen->getTabPlacement() == Tab::PTOP) 
			place_y += screen->getTabHeight();
		else if (screen->getTabPlacement() == Tab::PLEFT)
			place_x += (screen->isTabRotateVertical())
				? screen->getTabHeight()
				: screen->getTabWidth();
	}

	win->configure(place_x, place_y, win->getWidth(), win->getHeight());
}