~smspillaz/testing/unitydialog

« back to all changes in this revision

Viewing changes to src/unitydialog.cpp

  • Committer: Sam Spilsbury
  • Date: 2010-11-22 06:13:15 UTC
  • Revision ID: sam.spilsbury@canonical.com-20101122061315-clvaewqpb8d5081y
Be a little bit smarter about how we sync windows

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
20
 * GNU General Public License for more details.
21
21
 *
22
 
 * TODO:
23
 
 *  -> Fix parent resizing when child does
24
 
 *  -> Constrain resizes (if possible)
25
 
 *  -> Fix weird placement of dialogs (they must always be in the center)
26
 
 *  -> Add a match expression handler for "transientdialog" windows
27
22
 *
28
23
 **/
29
24
 
45
40
 
46
41
 
47
42
UnityDialogExp::UnityDialogExp (const CompString &str) :
48
 
    value (strtol (str.c_str () + 17, NULL, 0))
 
43
    value (strtol (str.c_str (), NULL, 0))
49
44
{
50
45
}
51
46
 
54
49
{
55
50
    UnityDialogWindow *udw = UnityDialogWindow::get (w);
56
51
 
57
 
    return ((value && udw->mParent) || (!value && !udw->mParent));
 
52
    return ((value && udw->transientParent ()) || (!value && !udw->transientParent ()));
58
53
}
59
54
 
60
55
CompMatch::Expression *
61
 
UnityDialogScreen::matchInitExp (CompString &str)
 
56
UnityDialogScreen::matchInitExp (const CompString &str)
62
57
{
63
58
    /* Create a new match object */
64
59
 
72
67
UnityDialogScreen::matchExpHandlerChanged ()
73
68
{
74
69
    screen->matchExpHandlerChanged ();
 
70
 
 
71
    foreach (CompWindow *w, screen->windows ())
 
72
    {
 
73
        if (UnityDialogWindow::get (w)->mParent ||
 
74
            UnityDialogWindow::get (w)->mTransients.size ())
 
75
            screen->matchPropertyChanged (w);
 
76
    }
 
77
}
 
78
 
 
79
void
 
80
moveTransientToRect (CompWindow *cw,
 
81
                     CompRect &currentRect, bool sync)
 
82
{
 
83
    CompPoint pos = UnityDialogWindow::get (cw)->getCenteredPositionForRect (currentRect);
 
84
 
 
85
    UnityDialogWindow::get (cw)->mSkipNotify = true;
 
86
    cw->move (pos.x () - cw->x (),
 
87
              pos.y () - cw->y (),
 
88
              true);
 
89
    if (sync)
 
90
        cw->syncPosition ();
 
91
    UnityDialogWindow::get (cw)->setMaxConstrainingAreas ();
 
92
    UnityDialogWindow::get (cw)->mSkipNotify = false;
 
93
    UnityDialogWindow::get (cw)->moveTransientsToRect (cw->serverGeometry (), sync);
75
94
}
76
95
 
77
96
void
397
416
{
398
417
    window->moveNotify (dx, dy, immediate);
399
418
 
400
 
    if (!mSkipNotify && window->grabbed ())
 
419
    if (!mSkipNotify)
401
420
    {
402
421
        CompRect geometry;
403
422
        CompWindow *syncWindow = mParent ? mParent : window;
404
 
        moveParent (CompPoint (dx, dy), immediate, false);
405
 
 
 
423
        UnityDialogWindow *usw = UnityDialogWindow::get (syncWindow);
 
424
        moveParent (CompPoint (dx, dy), immediate, !window->grabbed ());
406
425
 
407
426
        geometry = CompRect (syncWindow->x (),
408
427
                             syncWindow->y (),
409
428
                             syncWindow->serverGeometry ().width (),
410
429
                             syncWindow->serverGeometry ().height ());
411
430
 
412
 
        UnityDialogWindow::get (syncWindow)->moveTransientsToRect (geometry, false);
 
431
        usw->moveTransientsToRect (geometry, false);
413
432
    }
414
433
}
415
434
 
475
494
{
476
495
    /* Center transients (leave a bit more space
477
496
     * below) */
 
497
 
478
498
    foreach (CompWindow *cw, mTransients)
479
499
    {
480
 
        CompPoint pos = UnityDialogWindow::get (cw)->getCenteredPositionForRect (currentRect);
481
 
 
482
 
        UnityDialogWindow::get (cw)->mSkipNotify = true;
483
 
        cw->move (pos.x () - cw->x (),
484
 
                  pos.y () - cw->y (),
485
 
                  true);
486
 
        if (sync)
487
 
            cw->syncPosition ();
488
 
        UnityDialogWindow::get (cw)->setMaxConstrainingAreas ();
489
 
        UnityDialogWindow::get (cw)->mSkipNotify = false;
490
 
        UnityDialogWindow::get (cw)->moveTransientsToRect (cw->serverGeometry (), sync);
 
500
        moveTransientToRect (cw, currentRect, sync);
491
501
    }
492
502
}
493
503
 
510
520
    }
511
521
}
512
522
 
 
523
CompWindow *
 
524
UnityDialogWindow::transientParent ()
 
525
{
 
526
    if (window->transientFor ())
 
527
    {
 
528
        CompWindow *parent = screen->findWindow (window->transientFor ());
 
529
 
 
530
        if (parent &&
 
531
            UnityDialogScreen::get (screen)->optionGetMatch ().evaluate (window))
 
532
            return parent;
 
533
    }
 
534
 
 
535
    return NULL;
 
536
}
513
537
 
514
538
bool
515
539
UnityDialogWindow::place (CompPoint &pos)
516
540
{
 
541
    CompWindow *parent;
 
542
 
517
543
    /* If this window is a transient for some other window,
518
544
     * increment the transient count and
519
545
     * enable the dimming on that other window */
520
546
 
521
 
    if (window->transientFor ())
522
 
    {
523
 
        CompWindow *parent = screen->findWindow (window->transientFor ());
 
547
    if ((parent = transientParent ()) != NULL)
 
548
        UnityDialogWindow::get (parent)->addTransient (window);
524
549
 
525
 
        if (parent &&
526
 
            UnityDialogScreen::get (screen)->optionGetMatch ().evaluate (window))
527
 
            UnityDialogWindow::get (parent)->addTransient (window);
528
 
    }
 
550
    /* We need to check the final parent window */
529
551
 
530
552
    if (mParent)
531
553
    {
583
605
                                      event->xclient.data.l[3]);
584
606
                UnityDialogWindow *udw = UnityDialogWindow::get (w);
585
607
 
586
 
                udw->moveTransientsToRect (currentRect, false);
 
608
                udw->moveTransientsToRect (currentRect, true);
587
609
 
588
610
            }
589
611
        default: