~ubuntu-branches/ubuntu/trusty/compiz/trusty

« back to all changes in this revision

Viewing changes to plugins/scaleaddon/src/scaleaddon.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2013-08-22 06:58:07 UTC
  • mto: This revision was merged to the branch mainline in revision 3352.
  • Revision ID: package-import@ubuntu.com-20130822065807-17nlzez0d30y09so
Tags: upstream-0.9.10+13.10.20130822
ImportĀ upstreamĀ versionĀ 0.9.10+13.10.20130822

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
void
39
39
ScaleAddonWindow::renderTitle ()
40
40
{
 
41
    ADDON_SCREEN (screen);
 
42
 
 
43
    int titleOpt = as->optionGetWindowTitle ();
 
44
 
 
45
    if (!textAvailable                                                          ||
 
46
        titleOpt == ScaleaddonOptions::WindowTitleNoDisplay                     ||
 
47
        !sWindow->hasSlot ()                                                    ||
 
48
        (titleOpt == ScaleaddonOptions::WindowTitleHighlightedWindowOnly &&
 
49
         as->highlightedWindow != window->id ()))
 
50
    return;
 
51
 
 
52
    text.clear ();
41
53
    CompText::Attrib attrib;
42
 
    float            scale;
43
 
    int              titleOpt;
44
 
 
45
 
    ADDON_SCREEN (screen);
46
 
 
47
 
    if (!textAvailable)
48
 
        return;
49
 
 
50
 
    text.clear ();
51
 
 
52
 
    if (!sWindow->hasSlot ())
53
 
        return;
54
 
 
55
 
    titleOpt = as->optionGetWindowTitle ();
56
 
 
57
 
    if (titleOpt == ScaleaddonOptions::WindowTitleNoDisplay)
58
 
        return;
59
 
 
60
 
    if (titleOpt == ScaleaddonOptions::WindowTitleHighlightedWindowOnly &&
61
 
        as->highlightedWindow != window->id ())
62
 
    {
63
 
        return;
64
 
    }
65
 
 
66
 
    scale = sWindow->getSlot ().scale;
 
54
 
 
55
    float scale = sWindow->getSlot ().scale;
67
56
    attrib.maxWidth = window->width () * scale;
68
57
    attrib.maxHeight = window->height () * scale;
69
58
 
75
64
    attrib.color[3] = as->optionGetFontColorAlpha ();
76
65
 
77
66
    attrib.flags = CompText::WithBackground | CompText::Ellipsized;
 
67
 
78
68
    if (as->optionGetTitleBold ())
79
69
        attrib.flags |= CompText::StyleBold;
80
70
 
93
83
void
94
84
ScaleAddonWindow::drawTitle (const GLMatrix &transform)
95
85
{
96
 
    float         x, y, width, height;
97
86
    ScalePosition pos = sWindow->getCurrentPosition ();
98
87
    CompRect      geom = window->borderRect ();
99
88
 
100
 
    width  = text.getWidth ();
101
 
    height = text.getHeight ();
 
89
    float width  = text.getWidth ();
 
90
    float height = text.getHeight ();
102
91
 
103
 
    x = pos.x () + window->x () + geom.width () * pos.scale / 2 - width / 2;
104
 
    y = pos.y () + window->y () + geom.height () * pos.scale / 2 - height / 2;
 
92
    float x = pos.x () + window->x () + geom.width () * pos.scale / 2 - width / 2;
 
93
    float y = pos.y () + window->y () + geom.height () * pos.scale / 2 - height / 2;
105
94
 
106
95
    text.draw (transform, floor (x), floor (y), 1.0f);
107
96
}
109
98
void
110
99
ScaleAddonWindow::drawHighlight (const GLMatrix &transform)
111
100
{
112
 
    GLint         oldBlendSrc, oldBlendDst;
113
 
    GLushort colorData[4];
114
 
    GLfloat  vertexData[12];
 
101
    if (rescaled)
 
102
        return;
 
103
 
 
104
    GLint          oldBlendSrc, oldBlendDst;
 
105
    GLushort       colorData[4];
 
106
    GLfloat        vertexData[12];
115
107
    GLVertexBuffer *streamingBuffer = GLVertexBuffer::streamingBuffer ();
116
 
    float         x, y, width, height;
117
 
    ScalePosition pos = sWindow->getCurrentPosition ();
118
 
    CompRect      geom = window->borderRect ();
 
108
    ScalePosition  pos = sWindow->getCurrentPosition ();
 
109
    CompRect       geom = window->borderRect ();
119
110
 
120
111
    ADDON_SCREEN (screen);
121
112
 
123
114
    GLint oldBlendSrcAlpha, oldBlendDstAlpha;
124
115
#endif
125
116
 
126
 
    if (rescaled)
127
 
        return;
128
 
 
129
 
    x      = pos.x () + window->x () - (window->border ().left * pos.scale);
130
 
    y      = pos.y () + window->y () - (window->border ().top * pos.scale);
131
 
    width  = geom.width () * pos.scale;
132
 
    height = geom.height () * pos.scale;
 
117
    float x      = pos.x () + window->x () - (window->border ().left * pos.scale);
 
118
    float y      = pos.y () + window->y () - (window->border ().top * pos.scale);
 
119
    float width  = geom.width () * pos.scale;
 
120
    float height = geom.height () * pos.scale;
133
121
 
134
122
    /* we use a poor replacement for roundf()
135
123
     * (available in C99 only) here */
195
183
{
196
184
    if (highlightedWindow != lastHighlightedWindow)
197
185
    {
198
 
        CompWindow *w;
 
186
        CompWindow *w = screen->findWindow (highlightedWindow);
199
187
 
200
 
        w = screen->findWindow (highlightedWindow);
201
188
        if (w)
202
189
        {
203
190
            ADDON_WINDOW (w);
206
193
        }
207
194
 
208
195
        w = screen->findWindow (lastHighlightedWindow);
 
196
 
209
197
        if (w)
210
198
        {
211
199
            ADDON_WINDOW (w);
222
210
                               CompAction::State  state,
223
211
                               CompOption::Vector options)
224
212
{
225
 
    CompWindow *w;
226
 
 
227
213
    if (!sScreen->hasGrab ())
228
214
        return false;
229
215
 
230
 
    w = screen->findWindow (highlightedWindow);
 
216
    CompWindow *w = screen->findWindow (highlightedWindow);
 
217
 
231
218
    if (w)
232
219
        w->close (screen->getCurrentTime ());
233
220
 
239
226
                              CompAction::State  state,
240
227
                              CompOption::Vector options)
241
228
{
242
 
    CompWindow *w;
243
 
 
244
229
    if (!sScreen->hasGrab ())
245
230
        return false;
246
231
 
247
 
    w = screen->findWindow (highlightedWindow);
 
232
    CompWindow *w = screen->findWindow (highlightedWindow);
 
233
 
248
234
    if (w)
249
235
    {
250
 
        int       x, y, xOffset, yOffset;
251
 
        CompPoint vp;
252
 
 
253
 
        vp = w->defaultViewport ();
254
 
 
255
 
        xOffset = (screen->vp ().x () - vp.x ()) * screen->width ();
256
 
        yOffset = (screen->vp ().y () - vp.y ()) * screen->height ();
257
 
 
258
 
        x = w->x () + xOffset;
259
 
        y = w->y () + yOffset;
 
236
        CompPoint vp = w->defaultViewport ();
 
237
 
 
238
        int xOffset = (screen->vp ().x () - vp.x ()) * screen->width ();
 
239
        int yOffset = (screen->vp ().y () - vp.y ()) * screen->height ();
 
240
 
 
241
        int x = w->x () + xOffset;
 
242
        int y = w->y () + yOffset;
260
243
 
261
244
        if (optionGetConstrainPullToScreen ())
262
245
        {
281
264
 
282
265
        if (x != w->x () || y != w->y ())
283
266
        {
284
 
            ScalePosition pos, oldPos;
 
267
            ScalePosition pos;
285
268
            ADDON_WINDOW (w);
286
269
 
287
 
            oldPos = aw->sWindow->getCurrentPosition ();
 
270
            ScalePosition oldPos = aw->sWindow->getCurrentPosition ();
288
271
 
289
272
            w->moveToViewportPosition (x, y, true);
290
273
 
291
274
            /* Select this window when ending scale */
292
275
            aw->sWindow->scaleSelectWindow ();
293
276
 
294
 
            /* stop scaled window dissapearing */
 
277
            /* stop scaled window disappearing */
295
278
            pos.setX (oldPos.x () - xOffset);
296
279
            pos.setY (oldPos.y () - yOffset);
297
280
 
304
287
                o.push_back (CompOption ("root", CompOption::TypeInt));
305
288
                o[0].value ().set ((int) screen->root ());
306
289
 
307
 
                opt = CompOption::findOption (sScreen->getOptions (),
308
 
                                              "initiate_key", 0);
 
290
                opt = CompOption::findOption (sScreen->getOptions (), "initiate_key", 0);
 
291
 
309
292
                action = &opt->value ().action ();
310
293
 
311
294
                if (action->terminate ())
337
320
                              CompAction::State  state,
338
321
                              CompOption::Vector options)
339
322
{
340
 
    CompWindow *w;
341
 
 
342
323
    if (!sScreen->hasGrab ())
343
324
        return false;
344
325
 
345
 
    w = screen->findWindow (highlightedWindow);
 
326
    CompWindow *w = screen->findWindow (highlightedWindow);
 
327
 
346
328
    if (w)
347
329
    {
348
 
        CompRect output;
349
 
        int      head;
350
 
 
351
330
        ADDON_WINDOW (w);
352
331
 
353
332
        if (!aw->sWindow->hasSlot ())
354
333
            return false;
355
334
 
356
 
        head   = screen->outputDeviceForPoint (aw->sWindow->getSlot ().pos ());
357
 
        output = screen->outputDevs ()[head];
 
335
        int      head   = screen->outputDeviceForPoint (aw->sWindow->getSlot ().pos ());
 
336
        CompRect output = screen->outputDevs ()[head];
358
337
 
359
338
        /* damage old rect */
360
339
        aw->cWindow->addDamage ();
362
341
        if (!aw->rescaled)
363
342
        {
364
343
            ScaleSlot slot = aw->sWindow->getSlot ();
365
 
            int       x1, x2, y1, y2;
366
344
            CompRect  geom = w->borderRect ();
367
345
 
368
346
            aw->oldAbove = w->next;
372
350
            aw->origSlot = slot;
373
351
            aw->rescaled = true;
374
352
 
375
 
            x1 = output.centerX () - geom.width () / 2 + w->border ().left;
376
 
            y1 = output.centerY () - geom.height () / 2 + w->border ().top;
377
 
            x2 = slot.x () + geom.width ();
378
 
            y2 = slot.y () + geom.height ();
 
353
            int x1 = output.centerX () - geom.width () / 2 + w->border ().left;
 
354
            int y1 = output.centerY () - geom.height () / 2 + w->border ().top;
 
355
            int x2 = slot.x () + geom.width ();
 
356
            int y2 = slot.y () + geom.height ();
379
357
 
380
358
            slot.scale = 1.0f;
381
359
            slot.setGeometry (x1, y1, x2 - x1, y2 - y1);
411
389
    case PropertyNotify:
412
390
        if (event->xproperty.atom == XA_WM_NAME && sScreen->hasGrab ())
413
391
        {
414
 
            CompWindow *w;
 
392
            CompWindow *w = screen->findWindow (event->xproperty.window);
415
393
 
416
 
            w = screen->findWindow (event->xproperty.window);
417
394
            if (w)
418
395
            {
419
396
                ADDON_WINDOW (w);
421
398
                aw->cWindow->addDamage ();
422
399
            }
423
400
        }
 
401
 
424
402
        break;
 
403
 
425
404
    case MotionNotify:
426
405
        if (sScreen->hasGrab ())
427
406
        {
429
408
            checkWindowHighlight ();
430
409
        }
431
410
        break;
 
411
 
432
412
    default:
433
413
        break;
434
414
    }
449
429
 
450
430
    if (state == ScaleScreen::Wait || state == ScaleScreen::Out)
451
431
    {
452
 
        if (as->optionGetWindowHighlight ())
453
 
        {
454
 
            if (window->id () == as->highlightedWindow)
455
 
                drawHighlight (transform);
456
 
        }
 
432
        if (as->optionGetWindowHighlight () &&
 
433
            window->id () == as->highlightedWindow)
 
434
            drawHighlight (transform);
457
435
 
458
436
        if (textAvailable)
459
437
            drawTitle (transform);
508
486
    if ((strcmp (pluginName, "scale") == 0) &&
509
487
        (strcmp (eventName, "activate") == 0))
510
488
    {
511
 
        bool activated =
512
 
            CompOption::getBoolOptionNamed (options, "active", false);
 
489
        bool activated = CompOption::getBoolOptionNamed (options, "active", false);
513
490
 
514
491
        if (activated)
515
492
        {
570
547
                               int        x,
571
548
                               int        y)
572
549
{
573
 
    int    x1, y1, x2, y2;
574
550
    int    overlapX, overlapY;
575
551
    int    xMin, xMax, yMin, yMax;
576
552
    double result = -0.01;
578
554
    SCALE_SCREEN ();
579
555
    ADDON_SCREEN ();
580
556
 
581
 
    x1 = x;
582
 
    y1 = y;
583
 
    x2 = x1 + WIN_W (ss->windows[win]) * as->scale;
584
 
    y2 = y1 + WIN_H (ss->windows[win]) * as->scale;
 
557
    int x1 = x;
 
558
    int y1 = y;
 
559
    int x2 = x1 + WIN_W (ss->windows[win]) * as->scale;
 
560
    int y2 = y1 + WIN_H (ss->windows[win]) * as->scale;
585
561
 
586
 
    for (int i = 0; i < ss->nWindows; i++)
 
562
    for (int i = 0; i < ss->nWindows; ++i)
587
563
    {
588
564
        if (i == win)
589
565
            continue;
591
567
        overlapX = overlapY = 0;
592
568
        xMax = MAX (ss->slots[i].x1, x1);
593
569
        xMin = MIN (ss->slots[i].x1 + WIN_W (ss->windows[i]) * as->scale, x2);
 
570
 
594
571
        if (xMax <= xMin)
595
572
            overlapX = xMin - xMax;
596
573
 
612
589
                                         int        *bestX,
613
590
                                         int        areaWidth)
614
591
{
615
 
    int    i, y1, y2, w;
616
592
    double bestOverlap = 1e31, overlap;
617
593
 
618
594
    SCALE_SCREEN ();
619
595
    ADDON_SCREEN ();
620
596
 
621
 
    y1 = ss->slots[win].y1;
622
 
    y2 = ss->slots[win].y1 + WIN_H (ss->windows[win]) * as->scale;
 
597
    int y1 = ss->slots[win].y1;
 
598
    int y2 = ss->slots[win].y1 + WIN_H (ss->windows[win]) * as->scale;
623
599
 
624
 
    w = WIN_W (ss->windows[win]) * as->scale;
 
600
    int w = WIN_W (ss->windows[win]) * as->scale;
625
601
    *bestX = ss->slots[win].x1;
626
602
 
627
 
    for (i = 0; i < ss->nWindows; i++)
 
603
    for (int i = 0; i < ss->nWindows; ++i)
628
604
    {
629
605
        CompWindow *lw = ss->windows[i];
 
606
 
630
607
        if (i == win)
631
608
            continue;
632
609
 
635
612
        {
636
613
            if (ss->slots[i].x1 - w >= 0)
637
614
            {
638
 
                double overlap;
639
 
                
640
 
                overlap = layoutOrganicCalculateOverlap (s, win,
641
 
                                                         ss->slots[i].x1 - w,
642
 
                                                         y1);
 
615
                double overlap = layoutOrganicCalculateOverlap (s, win,
 
616
                                                                ss->slots[i].x1 - w,
 
617
                                                                y1);
643
618
 
644
619
                if (overlap < bestOverlap)
645
620
                {
647
622
                    bestOverlap = overlap;
648
623
                }
649
624
            }
 
625
 
650
626
            if (WIN_W (lw) * as->scale + ss->slots[i].x1 + w < areaWidth)
651
627
            {
652
 
                double overlap;
653
 
                
654
 
                overlap = layoutOrganicCalculateOverlap (s, win,
655
 
                                                         ss->slots[i].x1 +
656
 
                                                         WIN_W (lw) * as->scale,
657
 
                                                         y1);
 
628
                double overlap = layoutOrganicCalculateOverlap (s, win,
 
629
                                                                ss->slots[i].x1 +
 
630
                                                                WIN_W (lw) * as->scale,
 
631
                                                                y1);
658
632
 
659
633
                if (overlap < bestOverlap)
660
634
                {
666
640
    }
667
641
 
668
642
    overlap = layoutOrganicCalculateOverlap (s, win, 0, y1);
 
643
 
669
644
    if (overlap < bestOverlap)
670
645
    {
671
646
        *bestX = 0;
673
648
    }
674
649
 
675
650
    overlap = layoutOrganicCalculateOverlap (s, win, areaWidth - w, y1);
 
651
 
676
652
    if (overlap < bestOverlap)
677
653
    {
678
654
        *bestX = areaWidth - w;
688
664
                                       int        *bestY,
689
665
                                       int        areaHeight)
690
666
{
691
 
    int    i, x1, x2, h;
692
667
    double bestOverlap = 1e31, overlap;
693
668
 
694
669
    SCALE_SCREEN ();
695
670
    ADDON_SCREEN ();
696
671
 
697
 
    x1 = ss->slots[win].x1;
698
 
    x2 = ss->slots[win].x1 + WIN_W (ss->windows[win]) * as->scale;
699
 
    h = WIN_H (ss->windows[win]) * as->scale;
 
672
    int x1 = ss->slots[win].x1;
 
673
    int x2 = ss->slots[win].x1 + WIN_W (ss->windows[win]) * as->scale;
 
674
    int h = WIN_H (ss->windows[win]) * as->scale;
700
675
    *bestY = ss->slots[win].y1;
701
676
 
702
 
    for (i = 0; i < ss->nWindows; i++)
 
677
    for (int i = 0; i < ss->nWindows; ++i)
703
678
    {
704
679
        CompWindow *w = ss->windows[i];
705
680
 
711
686
        {
712
687
            if (ss->slots[i].y1 - h >= 0 && ss->slots[i].y1 < areaHeight)
713
688
            {
714
 
                double overlap;
715
 
                overlap = layoutOrganicCalculateOverlap (s, win, x1,
716
 
                                                         ss->slots[i].y1 - h);
 
689
                double overlap = layoutOrganicCalculateOverlap (s, win, x1,
 
690
                                                                ss->slots[i].y1 - h);
717
691
                if (overlap < bestOverlap)
718
692
                {
719
693
                    *bestY = ss->slots[i].y1 - h;
720
694
                    bestOverlap = overlap;
721
695
                }
722
696
            }
 
697
 
723
698
            if (WIN_H (w) * as->scale + ss->slots[i].y1 > 0 &&
724
699
                WIN_H (w) * as->scale + h + ss->slots[i].y1 < areaHeight)
725
700
            {
726
 
                double overlap;
727
 
                
728
 
                overlap = layoutOrganicCalculateOverlap (s, win, x1,
729
 
                                                         WIN_H (w) * as->scale +
730
 
                                                         ss->slots[i].y1);
 
701
                double overlap = layoutOrganicCalculateOverlap (s, win, x1,
 
702
                                                                WIN_H (w) * as->scale +
 
703
                                                                ss->slots[i].y1);
731
704
 
732
705
                if (overlap < bestOverlap)
733
706
                {
739
712
    }
740
713
 
741
714
    overlap = layoutOrganicCalculateOverlap (s, win, x1, 0);
 
715
 
742
716
    if (overlap < bestOverlap)
743
717
    {
744
718
        *bestY = 0;
746
720
    }
747
721
 
748
722
    overlap = layoutOrganicCalculateOverlap (s, win, x1, areaHeight - h);
 
723
 
749
724
    if (overlap < bestOverlap)
750
725
    {
751
726
        *bestY = areaHeight - h;
769
744
    do
770
745
    {
771
746
        improvement = false;
772
 
        for (i = 0; i < ss->nWindows; i++)
 
747
 
 
748
        for (i = 0; i < ss->nWindows; ++i)
773
749
        {
774
750
            bool improved;
775
751
 
807
783
    while (improvement);
808
784
 
809
785
    totalOverlap = 0.0;
810
 
    for (i = 0; i < ss->nWindows; i++)
 
786
 
 
787
    for (i = 0; i < ss->nWindows; ++i)
811
788
    {
812
789
        totalOverlap += layoutOrganicCalculateOverlap (s, i,
813
790
                                                       ss->slots[i].x1,
822
799
                            int        areaWidth,
823
800
                            int        areaHeight)
824
801
{
825
 
    int        i, spacing;
826
802
    CompWindow *w;
827
803
 
828
804
    SCALE_SCREEN ();
829
805
    ADDON_SCREEN ();
830
806
 
831
 
    spacing = ss->opt[SCALE_SCREEN_OPTION_SPACING].value.i;
 
807
    int spacing = ss->opt[SCALE_SCREEN_OPTION_SPACING].value.i;
832
808
 
833
809
    while (layoutOrganicLocalSearch (s, areaWidth, areaHeight))
834
810
    {
835
 
        for (i = 0; i < ss->nWindows; i++)
 
811
        for (int i = 0; i < ss->nWindows; ++i)
836
812
        {
837
 
            int centerX, centerY;
838
 
            int newX, newY, newWidth, newHeight;
839
 
 
840
813
            w = ss->windows[i];
841
814
 
842
 
            centerX = ss->slots[i].x1 + WIN_W (w) / 2;
843
 
            centerY = ss->slots[i].y1 + WIN_H (w) / 2;
 
815
            int centerX = ss->slots[i].x1 + WIN_W (w) / 2;
 
816
            int centerY = ss->slots[i].y1 + WIN_H (w) / 2;
844
817
 
845
 
            newWidth = (int)((1.0 - ORGANIC_STEP) *
 
818
            int newWidth = (int)((1.0 - ORGANIC_STEP) *
846
819
                             (double)WIN_W (w)) - spacing / 2;
847
 
            newHeight = (int)((1.0 - ORGANIC_STEP) *
 
820
            int newHeight = (int)((1.0 - ORGANIC_STEP) *
848
821
                              (double)WIN_H (w)) - spacing / 2;
849
 
            newX = centerX - (newWidth / 2);
850
 
            newY = centerY - (newHeight / 2);
 
822
            int newX = centerX - (newWidth / 2);
 
823
            int newY = centerY - (newHeight / 2);
851
824
 
852
825
            ss->slots[i].x1 = newX;
853
826
            ss->slots[i].y1 = newY;
862
835
layoutOrganicThumbs (CompScreen *s)
863
836
{
864
837
    CompWindow *w;
865
 
    int        i, moMode;
 
838
    int        i;
866
839
    XRectangle workArea;
867
840
 
868
841
    SCALE_SCREEN ();
869
842
    ADDON_SCREEN ();
870
843
 
871
 
    moMode = ss->opt[SCALE_SCREEN_OPTION_MULTIOUTPUT_MODE].value.i;
 
844
    int moMode = ss->opt[SCALE_SCREEN_OPTION_MULTIOUTPUT_MODE].value.i;
872
845
 
873
 
    switch (moMode) {
 
846
    switch (moMode)
 
847
    {
874
848
    case SCALE_MOMODE_ALL:
875
849
        workArea = s->workArea;
876
850
        break;
 
851
 
877
852
    case SCALE_MOMODE_CURRENT:
878
853
    default:
879
854
        workArea = s->outputDev[s->currentOutputDev].workArea;
885
860
    qsort (ss->windows, ss->nWindows, sizeof(CompWindow *),
886
861
           organicCompareWindows);
887
862
 
888
 
    for (i = 0; i < ss->nWindows; i++)
 
863
    for (i = 0; i < ss->nWindows; ++i)
889
864
    {
890
865
        w = ss->windows[i];
891
866
        SCALE_WINDOW (w);
924
899
 
925
900
    layoutOrganicRemoveOverlap (s, workArea.width - workArea.x,
926
901
                                workArea.height - workArea.y);
927
 
    for (i = 0; i < ss->nWindows; i++)
 
902
    for (i = 0; i < ss->nWindows; ++i)
928
903
    {
929
904
        w = ss->windows[i];
930
905
        SCALE_WINDOW (w);
959
934
{
960
935
    if (border.intersects (targets[w]))
961
936
        return true;
 
937
 
962
938
    // Is there a better way to do this?
963
939
    std::map <ScaleWindow *, CompRegion>::const_iterator i;
 
940
 
964
941
    for (i = targets.begin (); i != targets.end (); ++i)
965
942
    {
966
943
        if (w == (*i).first)
967
944
            continue;
 
945
 
968
946
        if (targets[w].intersects ((*i).second))
969
947
            return true;
970
948
    }
974
952
bool
975
953
ScaleAddonScreen::layoutNaturalThumbs ()
976
954
{
977
 
    ScaleScreen::WindowList windows = ScaleScreen::get (screen)->getWindows ();
978
 
    bool overlapping;
979
 
    CompRect area = screen->workArea ();
980
 
    CompRect bounds = area;
 
955
    ScaleScreen::WindowList              windows = ScaleScreen::get (screen)->getWindows ();
 
956
    bool                                 overlapping;
 
957
    CompRect                             area = screen->workArea ();
 
958
    CompRect                             bounds = area;
981
959
    std::map <ScaleWindow *, CompRegion> targets;
982
 
    std::map <ScaleWindow *, int> directions;
983
 
    int                           direction = 0;
984
 
    int                           iterCount = 0;
 
960
    std::map <ScaleWindow *, int>        directions;
 
961
    int                                  direction = 0;
 
962
    int                                  iterCount = 0;
985
963
 
986
964
    if (windows.size () == 1)
987
965
    {
1001
979
        // Reuse the unused "slot" as a preferred direction attribute. This is used when the window
1002
980
        // is on the edge of the screen to try to use as much screen real estate as possible.
1003
981
        directions[w] = direction;
1004
 
        direction++;
 
982
 
 
983
        ++direction;
 
984
 
1005
985
        if (direction == 4)
1006
986
            direction = 0;
1007
987
    }
1009
989
    do
1010
990
    {
1011
991
        overlapping = false;
 
992
 
1012
993
        foreach (ScaleWindow *w, windows)
1013
994
        {
1014
995
            foreach (ScaleWindow *e, windows)
1058
1039
                            ySection = (directions[w] % 2 ? 2 : 0);
1059
1040
                    }
1060
1041
                    
1061
 
                    if (xSection == 0 && ySection == 0)
 
1042
                    if (xSection == 0 && ySection == 0)
1062
1043
                    {
1063
1044
                        moveX = bounds.left () - targets[w].boundingRect ().centerX ();
1064
1045
                        moveY = bounds.top () - targets[w].boundingRect ().centerY ();
1065
1046
                    }
1066
 
                    if (xSection == 2 && ySection == 0)
 
1047
                    if (xSection == 2 && ySection == 0)
1067
1048
                    {
1068
1049
                        moveX = bounds.right () - targets[w].boundingRect ().centerX ();
1069
1050
                        moveY = bounds.top () - targets[w].boundingRect ().centerY ();
1070
1051
                    }
1071
 
                    if (xSection == 2 && ySection == 2)
 
1052
                    if (xSection == 2 && ySection == 2)
1072
1053
                    {
1073
1054
                        moveX = bounds.right () - targets[w].boundingRect ().centerX ();
1074
1055
                        moveY = bounds.bottom () - targets[w].boundingRect ().centerY ();
1075
1056
                    }
1076
 
                    if (xSection == 0 && ySection == 2)
 
1057
                    if (xSection == 0 && ySection == 2)
1077
1058
                    {
1078
1059
                        moveX = bounds.left () - targets[w].boundingRect ().centerX ();
1079
1060
                        moveY = bounds.right () - targets[w].boundingRect ().centerY ();
1080
1061
                    }
1081
 
                    if (moveX != 0 || moveY != 0)
1082
 
                        targets[w].translate (moveX, moveY);
 
1062
                    if (moveX != 0 || moveY != 0)
 
1063
                        targets[w].translate (moveX, moveY);
1083
1064
                    */
1084
1065
                }
1085
1066
                
1094
1075
    // Work out scaling by getting the most top-left and most bottom-right window coords.
1095
1076
    // The 20's and 10's are so that the windows don't touch the edge of the screen.
1096
1077
    double scale;
 
1078
 
1097
1079
    if (bounds == area)
1098
 
        scale = 1.0; // Don't add borders to the screen
 
1080
        scale = 1.0; // Don't add borders to the screen
1099
1081
    else if (area.width () / double (bounds.width ()) < area.height () / double (bounds.height ()))
1100
 
        scale = (area.width () - 20) / double (bounds.width ());
 
1082
        scale = (area.width () - 20) / double (bounds.width ());
1101
1083
    else
1102
 
        scale = (area.height () - 20) / double (bounds.height ());
 
1084
        scale = (area.height () - 20) / double (bounds.height ());
 
1085
 
1103
1086
    // Make bounding rect fill the screen size for later steps
1104
1087
    bounds = CompRect (
1105
 
        bounds.x () - (area.width () - 20 - bounds.width () * scale ) / 2 - 10 / scale,
1106
 
        bounds.y () - (area.height () - 20 - bounds.height () * scale ) / 2 - 10 / scale,
1107
 
        area.width () / scale,
1108
 
        area.height () / scale
1109
 
        );
1110
 
    
 
1088
                 bounds.x () - (area.width () - 20 - bounds.width () * scale ) / 2 - 10 / scale,
 
1089
                 bounds.y () - (area.height () - 20 - bounds.height () * scale ) / 2 - 10 / scale,
 
1090
                 area.width () / scale,
 
1091
                 area.height () / scale
 
1092
                 );
 
1093
 
1111
1094
    // Move all windows back onto the screen and set their scale
1112
1095
    foreach (ScaleWindow *w, windows)
1113
1096
    {
1114
 
        targets[w] = CompRect (
1115
 
            (targets[w].boundingRect ().x () - bounds.x () ) * scale + area.x (),
1116
 
            (targets[w].boundingRect ().y () - bounds.y ()) * scale + area.y (),
1117
 
            targets[w].boundingRect ().width () * scale,
1118
 
            targets[w].boundingRect ().height () * scale
1119
 
            );
 
1097
        targets[w] = CompRect (
 
1098
                         (targets[w].boundingRect ().x () - bounds.x () ) * scale + area.x (),
 
1099
                         (targets[w].boundingRect ().y () - bounds.y ()) * scale + area.y (),
 
1100
                         targets[w].boundingRect ().width () * scale,
 
1101
                         targets[w].boundingRect ().height () * scale
 
1102
                         );
 
1103
 
1120
1104
        ScaleSlot slt (targets[w].boundingRect ());
1121
1105
        slt.scale = scale;
1122
1106
        slt.filled = true;
1135
1119
    borderRegion ^= areaRegion;
1136
1120
 
1137
1121
    bool moved = false;
 
1122
 
1138
1123
    do
1139
1124
    {
1140
1125
        moved = false;
 
1126
 
1141
1127
        foreach (ScaleWindow *w, windows)
1142
1128
        {
1143
1129
            CompRegion oldRegion;
1144
 
            
 
1130
 
1145
1131
            // This may cause some slight distortion if the windows are enlarged a large amount
1146
1132
            int widthDiff = optionGetNaturalPrecision ();
1147
1133
            int heightDiff = ((w->window->height () / w->window->width ()) * 
1148
1134
            (targets[w].boundingRect ().width() + widthDiff)) - targets[w].boundingRect ().height ();
1149
1135
            int xDiff = widthDiff / 2;  // Also move a bit in the direction of the enlarge, allows the
1150
1136
            int yDiff = heightDiff / 2; // center windows to be enlarged if there is gaps on the side.
1151
 
            
 
1137
 
1152
1138
            // Attempt enlarging to the top-right
1153
1139
            oldRegion = targets[w];
1154
1140
            targets[w] = CompRegion (
1157
1143
                                     targets[w].boundingRect ().width () + widthDiff,
1158
1144
                                     targets[w].boundingRect ().height () + heightDiff
1159
1145
                                        );
 
1146
 
1160
1147
            if (isOverlappingAny (w, targets, borderRegion))
1161
1148
                targets[w] = oldRegion;
1162
1149
            else
1163
1150
                moved = true;
1164
 
            
 
1151
 
1165
1152
            // Attempt enlarging to the bottom-right
1166
1153
            oldRegion = targets[w];
1167
1154
            targets[w] = CompRegion(
1174
1161
                targets[w] = oldRegion;
1175
1162
            else
1176
1163
                moved = true;
1177
 
                
 
1164
 
1178
1165
            // Attempt enlarging to the bottom-left
1179
1166
            oldRegion = targets[w];
1180
1167
            targets[w] = CompRegion (
1183
1170
                                    targets[w].boundingRect ().width() + widthDiff,
1184
1171
                                    targets[w].boundingRect ().height() + heightDiff
1185
1172
                                    );
 
1173
 
1186
1174
            if (isOverlappingAny (w, targets, borderRegion))
1187
1175
                targets[w] = oldRegion;
1188
1176
            else
1189
1177
                moved = true;
1190
 
                    
 
1178
 
1191
1179
            // Attempt enlarging to the top-left
1192
1180
            oldRegion = targets[w];
1193
1181
            targets[w] = CompRegion (
1196
1184
                                    targets[w].boundingRect ().width() + widthDiff,
1197
1185
                                    targets[w].boundingRect ().height() + heightDiff
1198
1186
                                    );
 
1187
 
1199
1188
            if (isOverlappingAny (w, targets, borderRegion))
1200
1189
                targets[w] = oldRegion;
1201
1190
            else
1202
1191
                moved = true;
1203
1192
        }
1204
1193
        
1205
 
        iterCount++;
 
1194
        ++iterCount;
1206
1195
    }
1207
1196
    while (moved && iterCount < 100);
1208
1197
 
1225
1214
    }
1226
1215
 
1227
1216
    return true;
1228
 
 
1229
1217
}
1230
1218
 
1231
1219
bool
1238
1226
    case LayoutModeNatural:
1239
1227
        status = layoutNaturalThumbs ();
1240
1228
        break;
 
1229
 
1241
1230
    case LayoutModeNormal:
1242
1231
    default:
1243
1232
        status = sScreen->layoutSlotsAndAssignWindows ();
1268
1257
                }
1269
1258
            }
1270
1259
            break;
 
1260
 
1271
1261
        default:
1272
1262
            break;
1273
1263
    }
1324
1314
bool
1325
1315
ScaleAddonPluginVTable::init ()
1326
1316
{
1327
 
    if (!CompPlugin::checkPluginABI ("core", CORE_ABIVERSION) ||
1328
 
        !CompPlugin::checkPluginABI ("composite", COMPIZ_COMPOSITE_ABI) ||
1329
 
        !CompPlugin::checkPluginABI ("opengl", COMPIZ_OPENGL_ABI) ||
1330
 
        !CompPlugin::checkPluginABI ("scale", COMPIZ_SCALE_ABI))
1331
 
        return false;
1332
 
 
1333
 
    if (!CompPlugin::checkPluginABI ("text", COMPIZ_TEXT_ABI))
 
1317
    if (CompPlugin::checkPluginABI ("text", COMPIZ_TEXT_ABI))
 
1318
        textAvailable = true;
 
1319
    else
1334
1320
    {
1335
1321
        compLogMessage ("scaleaddon", CompLogLevelInfo,
1336
1322
                        "Text Plugin not loaded, no text will be drawn.");
1337
1323
        textAvailable = false;
1338
1324
    }
1339
 
    else
1340
 
        textAvailable = true;
1341
 
 
1342
 
    return true;
 
1325
 
 
1326
    if (CompPlugin::checkPluginABI ("core", CORE_ABIVERSION)            &&
 
1327
        CompPlugin::checkPluginABI ("composite", COMPIZ_COMPOSITE_ABI)  &&
 
1328
        CompPlugin::checkPluginABI ("opengl", COMPIZ_OPENGL_ABI)        &&
 
1329
        CompPlugin::checkPluginABI ("scale", COMPIZ_SCALE_ABI))
 
1330
        return true;
 
1331
 
 
1332
    return false;
1343
1333
}