~ubuntu-branches/ubuntu/wily/kwin/wily-proposed

« back to all changes in this revision

Viewing changes to placement.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2015-08-10 23:16:37 UTC
  • mfrom: (1.1.10)
  • Revision ID: package-import@ubuntu.com-20150810231637-5zb2tstjkez93hml
Tags: 4:5.3.95-0ubuntu1
new upstream beta release

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
/*!
57
57
  Places the client \a c according to the workspace's layout policy
58
58
 */
59
 
void Placement::place(Client* c, QRect& area)
 
59
void Placement::place(AbstractClient* c, QRect& area)
60
60
{
61
61
    Policy policy = c->rules()->checkPlacement(Default);
62
62
    if (policy != Default) {
76
76
        place(c, area, options->placement());
77
77
}
78
78
 
79
 
void Placement::place(Client* c, QRect& area, Policy policy, Policy nextPlacement)
 
79
void Placement::place(AbstractClient* c, QRect& area, Policy policy, Policy nextPlacement)
80
80
{
81
81
    if (policy == Unknown)
82
82
        policy = Default;
129
129
/*!
130
130
  Place the client \a c according to a simply "random" placement algorithm.
131
131
 */
132
 
void Placement::placeAtRandom(Client* c, const QRect& area, Policy /*next*/)
 
132
void Placement::placeAtRandom(AbstractClient* c, const QRect& area, Policy /*next*/)
133
133
{
134
134
    const int step  = 24;
135
135
    static int px = step;
168
168
}
169
169
 
170
170
// TODO: one day, there'll be C++11 ...
171
 
static inline bool isIrrelevant(const Client *client, const Client *regarding, int desktop)
 
171
static inline bool isIrrelevant(const AbstractClient *client, const AbstractClient *regarding, int desktop)
172
172
{
173
173
    if (!client)
174
174
        return true;
190
190
/*!
191
191
  Place the client \a c according to a really smart placement algorithm :-)
192
192
*/
193
 
void Placement::placeSmart(Client* c, const QRect& area, Policy /*next*/)
 
193
void Placement::placeSmart(AbstractClient* c, const QRect& area, Policy /*next*/)
194
194
{
195
195
    /*
196
196
     * SmartPlacement by Cristian Tibirna (tibirna@kde.org)
236
236
            cyt = y; cyb = y + ch;
237
237
            ToplevelList::ConstIterator l;
238
238
            for (l = workspace()->stackingOrder().constBegin(); l != workspace()->stackingOrder().constEnd() ; ++l) {
239
 
                Client *client = qobject_cast<Client*>(*l);
 
239
                AbstractClient *client = qobject_cast<AbstractClient*>(*l);
240
240
                if (isIrrelevant(client, c, desktop)) {
241
241
                    continue;
242
242
                }
285
285
            // compare to the position of each client on the same desk
286
286
            ToplevelList::ConstIterator l;
287
287
            for (l = workspace()->stackingOrder().constBegin(); l != workspace()->stackingOrder().constEnd() ; ++l) {
288
 
                Client *client = qobject_cast<Client*>(*l);
 
288
                AbstractClient *client = qobject_cast<AbstractClient*>(*l);
289
289
                if (isIrrelevant(client, c, desktop)) {
290
290
                    continue;
291
291
                }
316
316
            //test the position of each window on the desk
317
317
            ToplevelList::ConstIterator l;
318
318
            for (l = workspace()->stackingOrder().constBegin(); l != workspace()->stackingOrder().constEnd() ; ++l) {
319
 
                Client *client = qobject_cast<Client*>(*l);
 
319
                AbstractClient *client = qobject_cast<AbstractClient*>(*l);
320
320
                if (isIrrelevant(client, c, desktop)) {
321
321
                    continue;
322
322
                }
361
361
    }
362
362
}
363
363
 
364
 
QPoint Workspace::cascadeOffset(const Client *c) const
 
364
QPoint Workspace::cascadeOffset(const AbstractClient *c) const
365
365
{
366
366
    QRect area = clientArea(PlacementArea, c->geometry().center(), c->desktop());
367
367
    return QPoint(area.width()/48, area.height()/48);
370
370
/*!
371
371
  Place windows in a cascading order, remembering positions for each desktop
372
372
*/
373
 
void Placement::placeCascaded(Client* c, QRect& area, Policy nextPlacement)
 
373
void Placement::placeCascaded(AbstractClient* c, QRect& area, Policy nextPlacement)
374
374
{
375
375
    /* cascadePlacement by Cristian Tibirna (tibirna@kde.org) (30Jan98)
376
376
     */
451
451
/*!
452
452
  Place windows centered, on top of all others
453
453
*/
454
 
void Placement::placeCentered(Client* c, const QRect& area, Policy /*next*/)
 
454
void Placement::placeCentered(AbstractClient* c, const QRect& area, Policy /*next*/)
455
455
{
456
456
 
457
457
    // get the maximum allowed windows space and desk's origin
467
467
/*!
468
468
  Place windows in the (0,0) corner, on top of all others
469
469
*/
470
 
void Placement::placeZeroCornered(Client* c, const QRect& area, Policy /*next*/)
 
470
void Placement::placeZeroCornered(AbstractClient* c, const QRect& area, Policy /*next*/)
471
471
{
472
472
    // get the maximum allowed windows space and desk's origin
473
473
    c->move(checkArea(c, area).topLeft());
474
474
}
475
475
 
476
 
void Placement::placeUtility(Client* c, QRect& area, Policy /*next*/)
 
476
void Placement::placeUtility(AbstractClient* c, QRect& area, Policy /*next*/)
477
477
{
478
478
// TODO kwin should try to place utility windows next to their mainwindow,
479
479
// preferably at the right edge, and going down if there are more of them
483
483
    place(c, area, Default);
484
484
}
485
485
 
486
 
void Placement::placeOnScreenDisplay(Client* c, QRect& area)
 
486
void Placement::placeOnScreenDisplay(AbstractClient* c, QRect& area)
487
487
{
488
488
    // place at lower 1/3 of the screen
489
489
    const int x = area.left() + (area.width() -  c->width())  / 2;
492
492
    c->move(QPoint(x, y));
493
493
}
494
494
 
495
 
void Placement::placeDialog(Client* c, QRect& area, Policy nextPlacement)
 
495
void Placement::placeDialog(AbstractClient* c, QRect& area, Policy nextPlacement)
496
496
{
497
497
    placeOnMainWindow(c, area, nextPlacement);
498
498
}
499
499
 
500
 
void Placement::placeUnderMouse(Client* c, QRect& area, Policy /*next*/)
 
500
void Placement::placeUnderMouse(AbstractClient* c, QRect& area, Policy /*next*/)
501
501
{
502
502
    area = checkArea(c, area);
503
503
    QRect geom = c->geometry();
506
506
    c->keepInArea(area);   // make sure it's kept inside workarea
507
507
}
508
508
 
509
 
void Placement::placeOnMainWindow(Client* c, QRect& area, Policy nextPlacement)
 
509
void Placement::placeOnMainWindow(AbstractClient* c, QRect& area, Policy nextPlacement)
510
510
{
511
511
    if (nextPlacement == Unknown)
512
512
        nextPlacement = Centered;
513
513
    if (nextPlacement == Maximizing)   // maximize if needed
514
514
        placeMaximizing(c, area, NoPlacement);
515
515
    area = checkArea(c, area);
516
 
    ClientList mainwindows = c->mainClients();
517
 
    Client* place_on = NULL;
518
 
    Client* place_on2 = NULL;
 
516
    ClientList mainwindows;
 
517
    if (Client *client = qobject_cast<Client*>(c)) {
 
518
        mainwindows = client->mainClients();
 
519
    }
 
520
    AbstractClient* place_on = nullptr;
 
521
    AbstractClient* place_on2 = nullptr;
519
522
    int mains_count = 0;
520
523
    for (ClientList::ConstIterator it = mainwindows.constBegin();
521
524
            it != mainwindows.constEnd();
559
562
    c->keepInArea(area);   // make sure it's kept inside workarea
560
563
}
561
564
 
562
 
void Placement::placeMaximizing(Client* c, QRect& area, Policy nextPlacement)
 
565
void Placement::placeMaximizing(AbstractClient* c, QRect& area, Policy nextPlacement)
563
566
{
564
567
    if (nextPlacement == Unknown)
565
568
        nextPlacement = Smart;
568
571
            c->maximize(MaximizeFull);
569
572
        else { // if the geometry doesn't match default maximize area (xinerama case?),
570
573
            // it's probably better to use the given area
571
 
            c->setGeometry(area);
 
574
            if (Client *client = qobject_cast<Client*>(c)) {
 
575
                client->setGeometry(area);
 
576
            }
572
577
        }
573
578
    } else {
574
579
        c->resizeWithChecks(c->maxSize().boundedTo(area.size()));
610
615
    }
611
616
}
612
617
 
613
 
QRect Placement::checkArea(const Client* c, const QRect& area)
 
618
QRect Placement::checkArea(const AbstractClient* c, const QRect& area)
614
619
{
615
620
    if (area.isNull())
616
621
        return workspace()->clientArea(PlacementArea, c->geometry().center(), c->desktop());
865
870
    active_client->setQuickTileMode(Client::QuickTileBottom|Client::QuickTileRight, true);
866
871
}
867
872
 
868
 
int Workspace::packPositionLeft(const Client* cl, int oldx, bool left_edge) const
 
873
int Workspace::packPositionLeft(const AbstractClient* cl, int oldx, bool left_edge) const
869
874
{
870
875
    int newx = clientArea(MaximizeArea, cl).left();
871
876
    if (oldx <= newx)   // try another Xinerama screen
893
898
    return newx;
894
899
}
895
900
 
896
 
int Workspace::packPositionRight(const Client* cl, int oldx, bool right_edge) const
 
901
int Workspace::packPositionRight(const AbstractClient* cl, int oldx, bool right_edge) const
897
902
{
898
903
    int newx = clientArea(MaximizeArea, cl).right();
899
904
    if (oldx >= newx)   // try another Xinerama screen
921
926
    return newx;
922
927
}
923
928
 
924
 
int Workspace::packPositionUp(const Client* cl, int oldy, bool top_edge) const
 
929
int Workspace::packPositionUp(const AbstractClient* cl, int oldy, bool top_edge) const
925
930
{
926
931
    int newy = clientArea(MaximizeArea, cl).top();
927
932
    if (oldy <= newy)   // try another Xinerama screen
949
954
    return newy;
950
955
}
951
956
 
952
 
int Workspace::packPositionDown(const Client* cl, int oldy, bool bottom_edge) const
 
957
int Workspace::packPositionDown(const AbstractClient* cl, int oldy, bool bottom_edge) const
953
958
{
954
959
    int newy = clientArea(MaximizeArea, cl).bottom();
955
960
    if (oldy >= newy)   // try another Xinerama screen