aboutsummaryrefslogtreecommitdiff
path: root/src/Workspace.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/Workspace.cc')
-rw-r--r--src/Workspace.cc271
1 files changed, 220 insertions, 51 deletions
diff --git a/src/Workspace.cc b/src/Workspace.cc
index e136c32..85bd2aa 100644
--- a/src/Workspace.cc
+++ b/src/Workspace.cc
@@ -22,7 +22,7 @@
22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23// DEALINGS IN THE SOFTWARE. 23// DEALINGS IN THE SOFTWARE.
24 24
25// $Id: Workspace.cc,v 1.12 2002/02/26 22:34:49 fluxgen Exp $ 25// $Id: Workspace.cc,v 1.13 2002/03/19 14:30:43 fluxgen Exp $
26 26
27// use GNU extensions 27// use GNU extensions
28#ifndef _GNU_SOURCE 28#ifndef _GNU_SOURCE
@@ -343,8 +343,8 @@ void Workspace::setName(char *new_name) {
343} 343}
344 344
345//------------ shutdown --------- 345//------------ shutdown ---------
346// Calles restore on all windows 346// Calls restore on all windows
347// in the workspace and then 347// on the workspace and then
348// clears the windowList 348// clears the windowList
349//------------------------------- 349//-------------------------------
350void Workspace::shutdown(void) { 350void Workspace::shutdown(void) {
@@ -358,22 +358,17 @@ void Workspace::shutdown(void) {
358 358
359void Workspace::placeWindow(FluxboxWindow *win) { 359void Workspace::placeWindow(FluxboxWindow *win) {
360 Bool placed = False; 360 Bool placed = False;
361 int win_w = win->getWidth() + (screen->getBorderWidth2x() * 2), 361 int borderWidth4x = screen->getBorderWidth2x() * 2,
362 win_h = win->getHeight() + (screen->getBorderWidth2x() * 2),
363#ifdef SLIT 362#ifdef SLIT
364 slit_x = screen->getSlit()->getX() - screen->getBorderWidth(), 363 slit_x = screen->getSlit()->getX() - screen->getBorderWidth(),
365 slit_y = screen->getSlit()->getY() - screen->getBorderWidth(), 364 slit_y = screen->getSlit()->getY() - screen->getBorderWidth(),
366 slit_w = screen->getSlit()->getWidth() + 365 slit_w = screen->getSlit()->getWidth() + borderWidth4x,
367 (screen->getBorderWidth2x() * 2), 366 slit_h = screen->getSlit()->getHeight() + borderWidth4x,
368 slit_h = screen->getSlit()->getHeight() +
369 (screen->getBorderWidth2x() * 2),
370#endif // SLIT 367#endif // SLIT
371 toolbar_x = screen->getToolbar()->getX() - screen->getBorderWidth(), 368 toolbar_x = screen->getToolbar()->getX() - screen->getBorderWidth(),
372 toolbar_y = screen->getToolbar()->getY() - screen->getBorderWidth(), 369 toolbar_y = screen->getToolbar()->getY() - screen->getBorderWidth(),
373 toolbar_w = screen->getToolbar()->getWidth() + 370 toolbar_w = screen->getToolbar()->getWidth() + borderWidth4x,
374 (screen->getBorderWidth2x() * 2), 371 toolbar_h = screen->getToolbar()->getHeight() + borderWidth4x,
375 toolbar_h = screen->getToolbar()->getHeight() +
376 (screen->getBorderWidth2x() * 2),
377 place_x = 0, place_y = 0, change_x = 1, change_y = 1; 372 place_x = 0, place_y = 0, change_x = 1, change_y = 1;
378 373
379 if (screen->getColPlacementDirection() == BScreen::BOTTOMTOP) 374 if (screen->getColPlacementDirection() == BScreen::BOTTOMTOP)
@@ -381,43 +376,135 @@ void Workspace::placeWindow(FluxboxWindow *win) {
381 if (screen->getRowPlacementDirection() == BScreen::RIGHTLEFT) 376 if (screen->getRowPlacementDirection() == BScreen::RIGHTLEFT)
382 change_x = -1; 377 change_x = -1;
383 378
384 register int test_x, test_y, curr_w, curr_h; 379#ifdef XINERAMA
380 int head = 0,
381 head_x = 0,
382 head_y = 0;
383 int head_w, head_h;
384 if (screen->hasXinerama()) {
385 head = screen->getCurrHead();
386 head_x = screen->getHeadX(head);
387 head_y = screen->getHeadY(head);
388 head_w = screen->getHeadWidth(head);
389 head_h = screen->getHeadHeight(head);
390
391 } else { // no xinerama
392 head_w = screen->getWidth();
393 head_h = screen->getHeight();
394 }
395
396#endif // XINERAMA
397
398 int win_w = win->getWidth() + screen->getBorderWidth2x(),
399 win_h = win->getHeight() + screen->getBorderWidth2x();
400
401 if (win->hasTab()) {
402 if ((! win->isShaded()) &&
403 screen->getTabPlacement() == Tab::PLEFT ||
404 screen->getTabPlacement() == Tab::PRIGHT)
405 win_w += (screen->isTabRotateVertical())
406 ? screen->getTabHeight()
407 : screen->getTabWidth();
408 else // tab placement top or bottom or win is shaded
409 win_h += screen->getTabHeight();
410 }
411
412 register int test_x, test_y, curr_x, curr_y, curr_w, curr_h;
385 413
386 switch (screen->getPlacementPolicy()) { 414 switch (screen->getPlacementPolicy()) {
387 case BScreen::ROWSMARTPLACEMENT: { 415 case BScreen::ROWSMARTPLACEMENT: {
388 test_y = screen->getBorderWidth() + screen->getEdgeSnapThreshold(); 416 #ifdef XINERAMA
417 test_y = head_y;
418 #else // !XINERAMA
419 test_y = 0;
420 #endif // XINERAMA
389 if (screen->getColPlacementDirection() == BScreen::BOTTOMTOP) 421 if (screen->getColPlacementDirection() == BScreen::BOTTOMTOP)
422 #ifdef XINERAMA
423 test_y = (head_y + head_h) - win_h - test_y;
424 #else // !XINERAMA
390 test_y = screen->getHeight() - win_h - test_y; 425 test_y = screen->getHeight() - win_h - test_y;
426 #endif // XINERAMA
391 427
392 while (((screen->getColPlacementDirection() == BScreen::BOTTOMTOP) ? 428 while (((screen->getColPlacementDirection() == BScreen::BOTTOMTOP) ?
393 test_y > 0 : test_y + win_h < (signed) screen->getHeight()) && 429 #ifdef XINERAMA
394 ! placed) { 430 test_y >= head_y : test_y + win_h <= (head_y + head_h)) &&
395 test_x = screen->getBorderWidth() + screen->getEdgeSnapThreshold(); 431 #else // !XINERAMA
432 test_y > 0 : test_y + win_h < (signed) screen->getHeight()) &&
433 #endif // XINERAMA
434 ! placed) {
435
436 #ifdef XINERAMA
437 test_x = head_x;
438 #else // !XINERAMA
439 test_x = 0;
440 #endif // XINERAMA
396 if (screen->getRowPlacementDirection() == BScreen::RIGHTLEFT) 441 if (screen->getRowPlacementDirection() == BScreen::RIGHTLEFT)
442 #ifdef XINERAMA
443 test_x = (head_x + head_w) - win_w - test_x;
444 #else // !XINERAMA
397 test_x = screen->getWidth() - win_w - test_x; 445 test_x = screen->getWidth() - win_w - test_x;
446 #endif // XINERAMA
398 447
399 while (((screen->getRowPlacementDirection() == BScreen::RIGHTLEFT) ? 448 while (((screen->getRowPlacementDirection() == BScreen::RIGHTLEFT) ?
400 test_x > 0 : test_x + win_w < (signed) screen->getWidth()) && 449 #ifdef XINERAMA
401 ! placed) { 450 test_x >= head_x : test_x + win_w <= (head_x + head_w)) &&
451 #else // !XINERAMA
452 test_x > 0 : test_x + win_w < (signed) screen->getWidth()) &&
453 #endif // XINERAMA
454 ! placed) {
455
402 placed = True; 456 placed = True;
403 457
404 Windows::iterator it = windowList.begin(); 458 Windows::iterator it = windowList.begin();
405 Windows::iterator it_end = windowList.end(); 459 Windows::iterator it_end = windowList.end();
406 for (; it != it_end && placed; ++it) { 460
407 curr_w = (*it)->getWidth() + screen->getBorderWidth2x() + 461 for (; it != it_end && placed; ++it) {
408 screen->getBorderWidth2x(); 462 curr_x = (*it)->getXFrame();
463 curr_y = (*it)->getYFrame();
464 curr_w = (*it)->getWidth() + screen->getBorderWidth2x();
409 curr_h = 465 curr_h =
410 (((*it)->isShaded()) 466 (((*it)->isShaded())
411 ? (*it)->getTitleHeight() 467 ? (*it)->getTitleHeight()
412 : (*it)->getHeight()) + 468 : (*it)->getHeight()) +
413 screen->getBorderWidth2x() + 469 screen->getBorderWidth2x();
414 screen->getBorderWidth2x(); 470
415 471 if ((*it)->hasTab()) {
416 if ((*it)->getXFrame() < test_x + win_w && 472 if (! (*it)->isShaded()) { // not shaded window
417 (*it)->getXFrame() + curr_w > test_x && 473 switch(screen->getTabPlacement()) {
418 (*it)->getYFrame() < test_y + win_h && 474 case Tab::PTOP:
419 (*it)->getYFrame() + curr_h > test_y) 475 curr_y -= screen->getTabHeight();
476 case Tab::PBOTTOM:
477 curr_h += screen->getTabHeight();
478 break;
479 case Tab::PLEFT:
480 curr_x -= (screen->isTabRotateVertical())
481 ? screen->getTabHeight()
482 : screen->getTabWidth();
483 case Tab::PRIGHT:
484 curr_w += (screen->isTabRotateVertical())
485 ? screen->getTabHeight()
486 : screen->getTabWidth();
487 break;
488 default:
489 #ifdef DEBUG
490 cerr << __FILE__ << ":" <<__LINE__ << ": " <<
491 "Unsupported Placement" << endl;
492 #endif // DEBUG
493 break;
494 }
495 } else { // shaded window
496 if (screen->getTabPlacement() == Tab::PTOP)
497 curr_y -= screen->getTabHeight();
498 curr_h += screen->getTabHeight();
499 }
500 } // tab cheking done
501
502 if (curr_x < test_x + win_w &&
503 curr_x + curr_w > test_x &&
504 curr_y < test_y + win_h &&
505 curr_y + curr_h > test_y) {
420 placed = False; 506 placed = False;
507 }
421 } 508 }
422 509
423 if ((toolbar_x < test_x + win_w && 510 if ((toolbar_x < test_x + win_w &&
@@ -450,39 +537,96 @@ void Workspace::placeWindow(FluxboxWindow *win) {
450 break; } 537 break; }
451 538
452 case BScreen::COLSMARTPLACEMENT: { 539 case BScreen::COLSMARTPLACEMENT: {
453 test_x = screen->getBorderWidth() + screen->getEdgeSnapThreshold(); 540 #ifdef XINERAMA
541 test_x = head_x;
542 #else // !XINERAMA
543 test_x = 0;
544 #endif // XINERAMA
454 if (screen->getRowPlacementDirection() == BScreen::RIGHTLEFT) 545 if (screen->getRowPlacementDirection() == BScreen::RIGHTLEFT)
546 #ifdef XINERAMA
547 test_x = (head_x + head_w) - win_w - test_x;
548 #else // !XINERAMA
455 test_x = screen->getWidth() - win_w - test_x; 549 test_x = screen->getWidth() - win_w - test_x;
550 #endif // XINERAMA
456 551
457 while (((screen->getRowPlacementDirection() == BScreen::RIGHTLEFT) ? 552 while (((screen->getRowPlacementDirection() == BScreen::RIGHTLEFT) ?
458 test_x > 0 : test_x + win_w < (signed) screen->getWidth()) && 553 #ifdef XINERAMA
459 ! placed) { 554 test_x >= 0 : test_x + win_w <= (head_x + head_w)) &&
460 test_y = screen->getBorderWidth() + screen->getEdgeSnapThreshold(); 555 #else // !XINERAMA
556 test_x > 0 : test_x + win_w < (signed) screen->getWidth()) &&
557 #endif // XINERAMA
558 ! placed) {
559
560 #ifdef XINERAMA
561 test_y = head_y;
562 #else // !XINERAMA
563 test_y = 0;
564 #endif // XINERAMA
461 if (screen->getColPlacementDirection() == BScreen::BOTTOMTOP) 565 if (screen->getColPlacementDirection() == BScreen::BOTTOMTOP)
566 #ifdef XINERAMA
567 test_y = (head_y + head_h) - win_h - test_y;
568 #else // !XINERAMA
462 test_y = screen->getHeight() - win_h - test_y; 569 test_y = screen->getHeight() - win_h - test_y;
570 #endif // XINERAMA
463 571
464 while (((screen->getColPlacementDirection() == BScreen::BOTTOMTOP) ? 572 while (((screen->getColPlacementDirection() == BScreen::BOTTOMTOP) ?
465 test_y > 0 : test_y + win_h < (signed) screen->getHeight()) && 573 #ifdef XINERAMA
466 ! placed) { 574 test_y >= head_y : test_y + win_h <= (head_y + head_h)) &&
575 #else // !XINERAMA
576 test_y > 0 : test_y + win_h < (signed) screen->getHeight()) &&
577 #endif // XINERAMA
578 ! placed) {
467 placed = True; 579 placed = True;
468 580
469 Windows::iterator it = windowList.begin(); 581 Windows::iterator it = windowList.begin();
470 Windows::iterator it_end = windowList.end(); 582 Windows::iterator it_end = windowList.end();
471 for (; it != it_end && placed; ++it) { 583 for (; it != it_end && placed; ++it) {
472 curr_w = (*it)->getWidth() + screen->getBorderWidth2x() + 584 curr_x = (*it)->getXFrame();
473 screen->getBorderWidth2x(); 585 curr_y = (*it)->getYFrame();
586 curr_w = (*it)->getWidth() + screen->getBorderWidth2x();
474 curr_h = 587 curr_h =
475 (((*it)->isShaded()) 588 (((*it)->isShaded())
476 ? (*it)->getTitleHeight() 589 ? (*it)->getTitleHeight()
477 : (*it)->getHeight()) + 590 : (*it)->getHeight()) +
478 screen->getBorderWidth2x() + 591 screen->getBorderWidth2x();;
479 screen->getBorderWidth2x(); 592
480 593 if ((*it)->hasTab()) {
481 if ((*it)->getXFrame() < test_x + win_w && 594 if (! (*it)->isShaded()) { // not shaded window
482 (*it)->getXFrame() + curr_w > test_x && 595 switch(screen->getTabPlacement()) {
483 (*it)->getYFrame() < test_y + win_h && 596 case Tab::PTOP:
484 (*it)->getYFrame() + curr_h > test_y) 597 curr_y -= screen->getTabHeight();
598 case Tab::PBOTTOM:
599 curr_h += screen->getTabHeight();
600 break;
601 case Tab::PLEFT:
602 curr_x -= (screen->isTabRotateVertical())
603 ? screen->getTabHeight()
604 : screen->getTabWidth();
605 case Tab::PRIGHT:
606 curr_w += (screen->isTabRotateVertical())
607 ? screen->getTabHeight()
608 : screen->getTabWidth();
609 break;
610 default:
611 #ifdef DEBUG
612 cerr << __FILE__ << ":" <<__LINE__ << ": " <<
613 "Unsupported Placement" << endl;
614 #endif // DEBUG
615 break;
616 }
617 } else { // shaded window
618 if (screen->getTabPlacement() == Tab::PTOP)
619 curr_y -= screen->getTabHeight();
620 curr_h += screen->getTabHeight();
621 }
622 } // tab cheking done
623
624 if (curr_x < test_x + win_w &&
625 curr_x + curr_w > test_x &&
626 curr_y < test_y + win_h &&
627 curr_y + curr_h > test_y) {
485 placed = False; 628 placed = False;
629 }
486 } 630 }
487 631
488 if ((toolbar_x < test_x + win_w && 632 if ((toolbar_x < test_x + win_w &&
@@ -502,8 +646,6 @@ void Workspace::placeWindow(FluxboxWindow *win) {
502 if (placed) { 646 if (placed) {
503 place_x = test_x; 647 place_x = test_x;
504 place_y = test_y; 648 place_y = test_y;
505
506 break;
507 } 649 }
508 650
509 test_y += change_y; 651 test_y += change_y;
@@ -515,22 +657,49 @@ void Workspace::placeWindow(FluxboxWindow *win) {
515 break; } 657 break; }
516 } 658 }
517 659
660 // cascade placement or smart placement failed
518 if (! placed) { 661 if (! placed) {
662 #ifdef XINERAMA
663 if ((cascade_x > (head_w / 2)) ||
664 (cascade_y > (head_h / 2)))
665 #else // !XINERAMA
519 if (((unsigned) cascade_x > (screen->getWidth() / 2)) || 666 if (((unsigned) cascade_x > (screen->getWidth() / 2)) ||
520 ((unsigned) cascade_y > (screen->getHeight() / 2))) 667 ((unsigned) cascade_y > (screen->getHeight() / 2)))
521 cascade_x = cascade_y = 32; 668 #endif // XINERAMA
522 669
670 cascade_x = cascade_y = 32;
671#ifdef XINERAMA
672 place_x = head_x + cascade_x;
673 place_y = head_y + cascade_y;
674#else // !XINERAMA
523 place_x = cascade_x; 675 place_x = cascade_x;
524 place_y = cascade_y; 676 place_y = cascade_y;
525 677#endif // XINERAMA
526 cascade_x += win->getTitleHeight(); 678 cascade_x += win->getTitleHeight();
527 cascade_y += win->getTitleHeight(); 679 cascade_y += win->getTitleHeight();
528 } 680 }
529 681
682#ifdef XINERAMA
683 if (place_x + win_w > (head_x + head_w))
684 place_x = head_x + ((head_w - win_w) / 2);
685 if (place_y + win_h > (head_y + head_h))
686 place_y = head_y + ((head_h - win_h) / 2);
687#else // !XINERAMA
530 if (place_x + win_w > (signed) screen->getWidth()) 688 if (place_x + win_w > (signed) screen->getWidth())
531 place_x = (((signed) screen->getWidth()) - win_w) / 2; 689 place_x = (((signed) screen->getWidth()) - win_w) / 2;
532 if (place_y + win_h > (signed) screen->getHeight()) 690 if (place_y + win_h > (signed) screen->getHeight())
533 place_y = (((signed) screen->getHeight()) - win_h) / 2; 691 place_y = (((signed) screen->getHeight()) - win_h) / 2;
692#endif // XINERAMA
693
694 // fix window placement, think of tabs
695 if (win->hasTab()) {
696 if (screen->getTabPlacement() == Tab::PTOP)
697 place_y += screen->getTabHeight();
698 else if (screen->getTabPlacement() == Tab::PLEFT)
699 place_x += (screen->isTabRotateVertical())
700 ? screen->getTabHeight()
701 : screen->getTabWidth();
702 }
534 703
535 win->configure(place_x, place_y, win->getWidth(), win->getHeight()); 704 win->configure(place_x, place_y, win->getWidth(), win->getHeight());
536} 705}