~townsend/compiz/fix-auto-vp-switch-0.9.10

« back to all changes in this revision

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

  • Committer: MC Return
  • Date: 2013-06-29 09:36:01 UTC
  • mfrom: (3750 0.9.10)
  • mto: This revision was merged to the branch mainline in revision 3770.
  • Revision ID: mc.return@gmx.net-20130629093601-trksogeaxli98ln9
MergedĀ latestĀ lp:compiz

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 
37
37
COMPIZ_PLUGIN_20090315 (expo, ExpoPluginVTable);
38
38
 
39
 
#define sigmoid(x) (1.0f / (1.0f + exp (-5.5f * 2 * ((x) - 0.5))))
 
39
#define sigmoid(x) (1.0f / (1.0f + exp (-11.0f * ((x) - 0.5f))))
40
40
#define sigmoidProgress(x) ((sigmoid (x) - sigmoid (0)) / \
41
41
                            (sigmoid (1) - sigmoid (0)))
42
42
 
43
43
#define interpolate(a, b, val) (((val) * (a)) + ((1 - (val)) * (b)))
44
44
 
45
45
bool
46
 
ExpoScreen::dndInit (CompAction          *action,
47
 
                     CompAction::State   state,
48
 
                     CompOption::Vector& options)
 
46
ExpoScreen::dndInit (CompAction         *action,
 
47
                     CompAction::State  state,
 
48
                     CompOption::Vector &options)
49
49
{
50
50
    if (expoMode)
51
51
    {
60
60
}
61
61
 
62
62
bool
63
 
ExpoScreen::dndFini (CompAction          *action,
64
 
                     CompAction::State   state,
65
 
                     CompOption::Vector& options)
 
63
ExpoScreen::dndFini (CompAction         *action,
 
64
                     CompAction::State  state,
 
65
                     CompOption::Vector &options)
66
66
{
67
67
    if (dndState == DnDDuring || dndState == DnDStart)
68
68
    {
82
82
}
83
83
 
84
84
bool
85
 
ExpoScreen::doExpo (CompAction          *action,
86
 
                    CompAction::State   state,
87
 
                    CompOption::Vector& options)
 
85
ExpoScreen::doExpo (CompAction         *action,
 
86
                    CompAction::State  state,
 
87
                    CompOption::Vector &options)
88
88
{
89
89
    if (screen->otherGrabExist ("expo", NULL))
90
90
        return false;
104
104
        dndState  = DnDNone;
105
105
        dndWindow = NULL;
106
106
 
107
 
        selectedVp = screen->vp ();
108
 
        lastSelectedVp = screen->vp ();
109
 
        origVp     = screen->vp ();
 
107
        selectedVp     = screen->vp ();
 
108
        lastSelectedVp = selectedVp;
 
109
        origVp         = selectedVp;
110
110
 
111
111
        screen->addAction (&optionGetDndButton ());
112
112
        screen->addAction (&optionGetExitButton ());
116
116
        cScreen->damageScreen ();
117
117
    }
118
118
    else
119
 
    {
120
119
        termExpo (action, state, options);
121
 
    }
122
120
 
123
121
    return true;
124
122
}
125
123
 
126
124
bool
127
 
ExpoScreen::termExpo (CompAction          *action,
128
 
                      CompAction::State   state,
129
 
                      CompOption::Vector& options)
 
125
ExpoScreen::termExpo (CompAction         *action,
 
126
                      CompAction::State  state,
 
127
                      CompOption::Vector &options)
130
128
{
131
129
    if (!expoMode)
132
130
        return true;
156
154
}
157
155
 
158
156
bool
159
 
ExpoScreen::exitExpo (CompAction          *action,
160
 
                      CompAction::State   state,
161
 
                      CompOption::Vector& options)
 
157
ExpoScreen::exitExpo (CompAction         *action,
 
158
                      CompAction::State  state,
 
159
                      CompOption::Vector &options)
162
160
{
163
161
    if (!expoMode)
164
162
        return false;
171
169
}
172
170
 
173
171
bool
174
 
ExpoScreen::nextVp (CompAction          *action,
175
 
                    CompAction::State   state,
176
 
                    CompOption::Vector& options)
 
172
ExpoScreen::nextVp (CompAction         *action,
 
173
                    CompAction::State  state,
 
174
                    CompOption::Vector &options)
177
175
{
178
 
    unsigned int newX, newY;
179
 
 
180
176
    if (!expoMode)
181
177
        return false;
182
178
 
183
 
    newX = selectedVp.x () + 1;
184
 
    newY = selectedVp.y ();
 
179
    unsigned int newX = selectedVp.x () + 1;
 
180
    unsigned int newY = selectedVp.y ();
185
181
 
186
182
    if (newX >= (unsigned int) screen->vpSize ().width ())
187
183
    {
188
184
        newX = 0;
189
185
        newY = newY + 1;
 
186
 
190
187
        if (newY >= (unsigned int) screen->vpSize ().height ())
191
188
            newY = 0;
192
189
    }
199
196
}
200
197
 
201
198
bool
202
 
ExpoScreen::prevVp (CompAction          *action,
203
 
                    CompAction::State   state,
204
 
                    CompOption::Vector& options)
 
199
ExpoScreen::prevVp (CompAction         *action,
 
200
                    CompAction::State  state,
 
201
                    CompOption::Vector &options)
205
202
{
206
 
    int newX, newY;
207
 
 
208
203
    if (!expoMode)
209
204
        return false;
210
205
 
211
 
    newX = selectedVp.x () - 1;
212
 
    newY = selectedVp.y ();
 
206
    int newX = selectedVp.x () - 1;
 
207
    int newY = selectedVp.y ();
213
208
 
214
209
    if (newX < 0)
215
210
    {
216
211
        newX = screen->vpSize ().width () - 1;
217
212
        newY = newY - 1;
 
213
 
218
214
        if (newY < 0)
219
215
            newY = screen->vpSize ().height () - 1;
220
216
    }
230
226
ExpoScreen::moveFocusViewport (int dx,
231
227
                               int dy)
232
228
{
233
 
    int newX, newY;
234
 
 
235
229
    lastSelectedVp = selectedVp;
236
230
 
237
 
    newX = selectedVp.x () + dx;
238
 
    newY = selectedVp.y () + dy;
 
231
    int newX = selectedVp.x () + dx;
 
232
    int newY = selectedVp.y () + dy;
239
233
 
240
 
    newX = MAX (0, MIN ((int) screen->vpSize ().width () - 1, newX));
241
 
    newY = MAX (0, MIN ((int) screen->vpSize ().height () - 1, newY));
 
234
    newX = MAX (0, MIN (static_cast <int> (screen->vpSize ().width ())  - 1, newX));
 
235
    newY = MAX (0, MIN (static_cast <int> (screen->vpSize ().height ()) - 1, newY));
242
236
 
243
237
    selectedVp.set (newX, newY);
244
238
    cScreen->damageScreen ();
260
254
    if (dndWindow->saveMask () & CWX)
261
255
    {
262
256
        dndWindow->saveWc ().x = dndWindow->saveWc ().x % screen->width ();
 
257
 
263
258
        if (dndWindow->saveWc ().x < 0)
264
259
            dndWindow->saveWc ().x += screen->width ();
265
260
    }
 
261
 
266
262
    if (dndWindow->saveMask () & CWY)
267
263
    {
268
264
        dndWindow->saveWc ().y = dndWindow->saveWc ().y % screen->height ();
 
265
 
269
266
        if (dndWindow->saveWc ().y < 0)
270
267
            dndWindow->saveWc ().y += screen->height ();
271
268
    }
277
274
 
278
275
#if 0 /* FIXME: obsolete in the meantime? */
279
276
    {
280
 
        int lastOutput;
281
 
        int centerX, centerY;
282
 
 
283
277
        /* make sure we snap to the correct output */
284
 
        lastOutput = s->currentOutputDev;
285
 
        centerX = (WIN_X (w) + WIN_W (w) / 2) % s->width;
 
278
        int lastOutput = s->currentOutputDev;
 
279
        int centerX    = (WIN_X (w) + WIN_W (w) / 2) % s->width;
 
280
 
286
281
        if (centerX < 0)
287
282
            centerX += s->width;
288
 
        centerY = (WIN_Y (w) + WIN_H (w) / 2) % s->height;
 
283
 
 
284
        int centerY = (WIN_Y (w) + WIN_H (w) / 2) % s->height;
 
285
 
289
286
        if (centerY < 0)
290
287
            centerY += s->height;
291
288
 
301
298
void
302
299
ExpoScreen::handleEvent (XEvent *event)
303
300
{
304
 
    switch (event->type) {
305
 
    case KeyPress:
306
 
        if (expoMode && event->xkey.root == screen->root ())
307
 
        {
308
 
            if (event->xkey.keycode == leftKey)
309
 
                moveFocusViewport (-1, 0);
310
 
            else if (event->xkey.keycode == rightKey)
311
 
                moveFocusViewport (1, 0);
312
 
            else if (event->xkey.keycode == upKey)
313
 
                moveFocusViewport (0, -1);
314
 
            else if (event->xkey.keycode == downKey)
315
 
                moveFocusViewport (0, 1);
316
 
        }
317
 
        break;
318
 
 
319
 
    case ButtonPress:
320
 
        if (expoMode && event->xbutton.button == Button1 &&
321
 
            event->xbutton.root == screen->root ())
322
 
        {
323
 
            CompPoint pointer (event->xbutton.x_root, event->xbutton.y_root);
324
 
            if (!screen->workArea().contains (pointer))
325
 
                break;
326
 
 
327
 
            anyClick = true;
328
 
            if (clickTime == 0)
329
 
            {
330
 
                clickTime = event->xbutton.time;
331
 
            }
332
 
            else if (event->xbutton.time - clickTime <=
333
 
                     (unsigned int) optionGetDoubleClickTime () && lastSelectedVp == selectedVp)
334
 
            {
335
 
                doubleClick = true;
336
 
            }
337
 
            else
338
 
            {
339
 
                clickTime   = event->xbutton.time;
340
 
                doubleClick = false;
341
 
            }
342
 
            cScreen->damageScreen ();
343
 
            prevClickPoint = CompPoint(event->xbutton.x, event->xbutton.y);
344
 
        }
345
 
        break;
346
 
 
347
 
    case ButtonRelease:
348
 
        if (expoMode && event->xbutton.button == Button1 &&
349
 
            event->xbutton.root == screen->root ())
350
 
        {
351
 
            CompPoint pointer (event->xbutton.x_root, event->xbutton.y_root);
352
 
            if (!screen->workArea().contains (pointer))
353
 
                break;
354
 
 
355
 
            if (event->xbutton.time - clickTime >
356
 
                (unsigned int) optionGetDoubleClickTime ())
357
 
            {
358
 
                clickTime   = 0;
359
 
                doubleClick = false;
360
 
            }
361
 
            else if (doubleClick ||
362
 
                     compiz::expo::clickMovementInThreshold(prevClickPoint.x (),
363
 
                                                            prevClickPoint.y (),
364
 
                                                            event->xbutton.x,
365
 
                                                            event->xbutton.y))
366
 
            {
367
 
                CompAction& action = optionGetExpoKey ();
368
 
 
369
 
                clickTime   = 0;
370
 
                doubleClick = false;
371
 
 
372
 
                termExpo (&action, 0, noOptions ());
 
301
    switch (event->type)
 
302
    {
 
303
        case KeyPress:
 
304
            if (expoMode && event->xkey.root == screen->root ())
 
305
            {
 
306
                if (event->xkey.keycode == leftKey)
 
307
                    moveFocusViewport (-1, 0);
 
308
                else if (event->xkey.keycode == rightKey)
 
309
                    moveFocusViewport (1, 0);
 
310
                else if (event->xkey.keycode == upKey)
 
311
                    moveFocusViewport (0, -1);
 
312
                else if (event->xkey.keycode == downKey)
 
313
                    moveFocusViewport (0, 1);
 
314
            }
 
315
 
 
316
            break;
 
317
 
 
318
        case ButtonPress:
 
319
            if (expoMode                            &&
 
320
                event->xbutton.button == Button1    &&
 
321
                event->xbutton.root   == screen->root ())
 
322
            {
 
323
                CompPoint pointer (event->xbutton.x_root, event->xbutton.y_root);
 
324
 
 
325
                if (!screen->workArea ().contains (pointer))
 
326
                    break;
 
327
 
373
328
                anyClick = true;
374
 
            }
375
 
        }
376
 
        break;
 
329
 
 
330
                if (clickTime == 0)
 
331
                    clickTime = event->xbutton.time;
 
332
                else if (event->xbutton.time - clickTime <=
 
333
                         static_cast <unsigned int> (optionGetDoubleClickTime ()) &&
 
334
                         lastSelectedVp == selectedVp)
 
335
                    doubleClick = true;
 
336
                else
 
337
                {
 
338
                    clickTime   = event->xbutton.time;
 
339
                    doubleClick = false;
 
340
                }
 
341
 
 
342
                cScreen->damageScreen ();
 
343
                prevClickPoint = CompPoint (event->xbutton.x, event->xbutton.y);
 
344
            }
 
345
 
 
346
            break;
 
347
 
 
348
        case ButtonRelease:
 
349
            if (expoMode                            &&
 
350
                event->xbutton.button == Button1    &&
 
351
                event->xbutton.root   == screen->root ())
 
352
            {
 
353
                CompPoint pointer (event->xbutton.x_root, event->xbutton.y_root);
 
354
 
 
355
                if (!screen->workArea ().contains (pointer))
 
356
                    break;
 
357
 
 
358
                if (event->xbutton.time - clickTime >
 
359
                    (unsigned int)optionGetDoubleClickTime ())
 
360
                {
 
361
                    clickTime   = 0;
 
362
                    doubleClick = false;
 
363
                }
 
364
                else if (doubleClick ||
 
365
                         compiz::expo::clickMovementInThreshold(prevClickPoint.x (),
 
366
                                                                prevClickPoint.y (),
 
367
                                                                event->xbutton.x,
 
368
                                                                event->xbutton.y))
 
369
                {
 
370
                    /* TODO: What action to take if expo_key is not defined ? */
 
371
                    CompAction &action = optionGetExpoKey ();
 
372
 
 
373
                    clickTime   = 0;
 
374
                    doubleClick = false;
 
375
 
 
376
                    termExpo (&action, 0, noOptions ());
 
377
                    anyClick = true;
 
378
                }
 
379
            }
 
380
 
 
381
            break;
 
382
 
 
383
        default:
 
384
            break;
377
385
    }
378
386
 
379
387
    screen->handleEvent (event);
382
390
void
383
391
ExpoScreen::preparePaint (int msSinceLastPaint)
384
392
{
385
 
    float val = ((float) msSinceLastPaint / 1000.0) / optionGetZoomTime ();
 
393
    float val = (static_cast <float> (msSinceLastPaint) / 1000.0f) /
 
394
                optionGetZoomTime ();
386
395
 
387
396
    if (expoMode)
388
397
        expoCam = MIN (1.0, expoCam + val);
392
401
    if (expoCam)
393
402
    {
394
403
        unsigned int i, j, vp;
395
 
        unsigned int vpCount = screen->vpSize ().width () *
396
 
                               screen->vpSize ().height ();
 
404
        unsigned int vpCountHorz = screen->vpSize ().width ();
 
405
        unsigned int vpCountVert = screen->vpSize ().height ();
 
406
        unsigned int vpCount     = vpCountHorz * vpCountVert;
397
407
 
398
408
        if (vpActivity.size () < vpCount)
399
409
        {
400
410
            vpActivity.resize (vpCount);
401
 
            foreach (float& activity, vpActivity)
 
411
 
 
412
            foreach (float &activity, vpActivity)
402
413
                activity = 1.0f;
403
414
        }
404
415
 
405
 
        for (i = 0; i < (unsigned int) screen->vpSize ().width (); i++)
 
416
        for (i = 0; i < vpCountHorz; ++i)
406
417
        {
407
 
            for (j = 0; j < (unsigned int) screen->vpSize ().height (); j++)
 
418
            for (j = 0; j < vpCountVert; ++j)
408
419
            {
409
 
                vp = (j * screen->vpSize ().width ()) + i;
 
420
                vp = j * vpCountHorz + i;
410
421
 
411
422
                if (CompPoint (i, j) == selectedVp)
412
423
                    vpActivity[vp] = MIN (1.0, vpActivity[vp] + val);
415
426
            }
416
427
        }
417
428
 
418
 
        for (i = 0; i < 360; i++)
 
429
        const float degToRad    = M_PI / 180.0f;
 
430
        const int   screenWidth = screen->width ();
 
431
 
 
432
        for (i = 0; i < 360; ++i)
419
433
        {
420
 
            float fi = (float) i;
421
 
 
422
 
            vpNormals[i * 3] = (-sin (fi * (M_PI / 180.0f)) / screen->width ()) *
423
 
                               expoCam;
424
 
            vpNormals[(i * 3) + 1] = 0.0;
425
 
            vpNormals[(i * 3) + 2] = (-cos (fi * (M_PI / 180.0f)) * expoCam) -
426
 
                                     (1 - expoCam);
 
434
            vpNormals[i * 3]     = (-sin (i * degToRad) / screenWidth) * expoCam;
 
435
            vpNormals[i * 3 + 1] = 0.0;
 
436
            vpNormals[i * 3 + 2] = (-cos (i * degToRad) * expoCam) - (1 - expoCam);
427
437
        }
428
438
    }
429
439
 
440
450
    gScreen->glPaintOutputSetEnabled (this, enable);
441
451
    gScreen->glPaintTransformedOutputSetEnabled (this, enable);
442
452
 
 
453
    ExpoWindow *ew;
 
454
 
443
455
    foreach (CompWindow *w, screen->windows ())
444
456
    {
445
 
        ExpoWindow *ew = ExpoWindow::get (w);
 
457
        ew = ExpoWindow::get (w);
446
458
 
447
 
        ew->cWindow->damageRectSetEnabled (ew, enable);
448
 
        ew->gWindow->glPaintSetEnabled (ew, enable);
449
 
        ew->gWindow->glDrawSetEnabled (ew, enable);
 
459
        ew->cWindow->damageRectSetEnabled    (ew, enable);
 
460
        ew->gWindow->glPaintSetEnabled       (ew, enable);
 
461
        ew->gWindow->glDrawSetEnabled        (ew, enable);
450
462
        ew->gWindow->glAddGeometrySetEnabled (ew, enable);
451
463
        ew->gWindow->glDrawTextureSetEnabled (ew, enable);
452
464
    }
453
465
}
454
466
 
455
467
void
456
 
ExpoScreen::paint (CompOutput::ptrList& outputs,
457
 
                   unsigned int         mask)
 
468
ExpoScreen::paint (CompOutput::ptrList &outputs,
 
469
                   unsigned int        mask)
458
470
{
459
 
    int width = outputs.front ()->width ();
460
 
    int height = outputs.front ()->height ();
461
 
    bool sizeDiff = false;
462
 
 
463
 
    /* "One big wall" does not make sense where outputs are different
464
 
     * sizes, so force multiple walls in this case
465
 
     *
466
 
     * TODO: Is it possible to re-create "one big wall" using
467
 
     * independent output painting in this case? */
468
 
 
469
 
    foreach (CompOutput *o, outputs)
470
 
    {
471
 
        if (o->width () != width || o->height () != height)
472
 
        {
473
 
            sizeDiff = true;
474
 
            break;
475
 
        }
476
 
    }
477
 
 
478
 
    if (expoCam > 0.0 && outputs.size () > 1 &&
479
 
        optionGetMultioutputMode () == MultioutputModeOneBigWall &&
480
 
        !sizeDiff)
 
471
    if (expoCam         > 0.0   &&
 
472
        outputs.size () > 1     &&
 
473
        optionGetMultioutputMode () == MultioutputModeOneBigWall)
481
474
    {
482
475
        outputs.clear ();
483
476
        outputs.push_back (&screen->fullscreenOutput ());
491
484
{
492
485
    CompOption::Vector o(0);
493
486
    screen->handleCompizEvent ("expo", "start_viewport_switch", o);
494
 
    switch (vpUpdateMode) {
495
 
    case VPUpdateMouseOver:
496
 
        screen->moveViewport (screen->vp ().x () - selectedVp.x (),
497
 
                              screen->vp ().y () - selectedVp.y (), true);
498
 
        screen->focusDefaultWindow ();
499
 
        vpUpdateMode = VPUpdateNone;
500
 
        break;
501
 
    case VPUpdatePrevious:
502
 
        screen->moveViewport (screen->vp ().x () - origVp.x (),
503
 
                              screen->vp ().y () - origVp.y (), true);
504
 
        lastSelectedVp = selectedVp;
505
 
        selectedVp = origVp;
506
 
        screen->focusDefaultWindow ();
507
 
        vpUpdateMode = VPUpdateNone;
508
 
        break;
509
 
    default:
510
 
        break;
 
487
 
 
488
    switch (vpUpdateMode)
 
489
    {
 
490
        case VPUpdateMouseOver:
 
491
            screen->moveViewport (screen->vp ().x () - selectedVp.x (),
 
492
                                  screen->vp ().y () - selectedVp.y (), true);
 
493
            screen->focusDefaultWindow ();
 
494
            vpUpdateMode = VPUpdateNone;
 
495
            break;
 
496
 
 
497
        case VPUpdatePrevious:
 
498
            screen->moveViewport (screen->vp ().x () - origVp.x (),
 
499
                                  screen->vp ().y () - origVp.y (), true);
 
500
            lastSelectedVp = selectedVp;
 
501
            selectedVp     = origVp;
 
502
            screen->focusDefaultWindow ();
 
503
            vpUpdateMode = VPUpdateNone;
 
504
            break;
 
505
 
 
506
        default:
 
507
            break;
511
508
    }
 
509
 
512
510
    screen->handleCompizEvent ("expo", "end_viewport_switch", o);
513
511
 
514
512
    if ((expoCam > 0.0f && expoCam < 1.0f) || dndState != DnDNone)
516
514
 
517
515
    if (expoCam == 1.0f)
518
516
    {
519
 
        foreach (float& vp, vpActivity)
 
517
        foreach (float &vp, vpActivity)
520
518
            if (vp != 0.0 && vp != 1.0)
521
519
                cScreen->damageScreen ();
522
520
    }
530
528
 
531
529
    cScreen->donePaint ();
532
530
 
533
 
    switch (dndState) {
534
 
    case DnDDuring:
 
531
    switch (dndState)
 
532
    {
 
533
        case DnDDuring:
535
534
        {
536
535
            if (dndWindow)
537
536
                dndWindow->move (newCursor.x () - prevCursor.x (),
541
540
            prevCursor = newCursor;
542
541
            cScreen->damageScreen ();
543
542
        }
544
 
        break;
 
543
            break;
545
544
 
546
 
    case DnDStart:
 
545
        case DnDStart:
547
546
        {
548
 
            int                              xOffset, yOffset;
549
 
            CompWindowList::reverse_iterator iter;
550
 
 
551
 
            xOffset = screen->vpSize ().width () * screen->width ();
552
 
            yOffset = screen->vpSize ().height () * screen->height ();
 
547
            int xOffset = screen->vpSize ().width ()  * screen->width ();
 
548
            int yOffset = screen->vpSize ().height () * screen->height ();
553
549
 
554
550
            dndState = DnDNone;
555
551
 
556
 
            for (iter = screen->windows ().rbegin ();
 
552
            bool       inWindow;
 
553
            int        nx, ny;
 
554
            CompWindow *w;
 
555
 
 
556
            for (CompWindowList::reverse_iterator iter = screen->windows ().rbegin ();
557
557
                 iter != screen->windows ().rend (); ++iter)
558
558
            {
559
 
                CompWindow *w = *iter;
560
 
                CompRect   input (w->inputRect ());
561
 
                bool       inWindow;
562
 
                int        nx, ny;
563
 
 
564
 
                if (w->destroyed ())
565
 
                    continue;
566
 
 
567
 
                if (!w->shaded () && !w->isViewable ())
 
559
                w = *iter;
 
560
                CompRect input (w->inputRect ());
 
561
 
 
562
                if (w->destroyed () ||
 
563
                    (!w->shaded () && !w->isViewable ()))
568
564
                    continue;
569
565
 
570
566
                if (w->onAllViewports ())
574
570
                }
575
571
                else
576
572
                {
577
 
                    nx = newCursor.x () -
578
 
                         (screen->vp ().x () * screen->width ());
579
 
                    ny = newCursor.y () -
580
 
                         (screen->vp ().y () * screen->height ());
 
573
                    nx = newCursor.x () - (screen->vp ().x () * screen->width ());
 
574
                    ny = newCursor.y () - (screen->vp ().y () * screen->height ());
581
575
                }
582
576
 
583
577
                inWindow = (nx >= input.left () && nx <= input.right ()) ||
584
 
                           (nx >= (input.left () + xOffset) &&
 
578
                           (nx >= (input.left ()  + xOffset) &&
585
579
                            nx <= (input.right () + xOffset));
586
580
 
587
581
                inWindow &= (ny >= input.top () && ny <= input.bottom ()) ||
588
 
                            (ny >= (input.top () + yOffset) &&
 
582
                            (ny >= (input.top ()    + yOffset) &&
589
583
                             ny <= (input.bottom () + yOffset));
590
584
 
591
585
                if (!inWindow)
616
610
 
617
611
            prevCursor = newCursor;
618
612
        }
619
 
        break;
620
 
    case DnDNone:
621
 
        screen->updateGrab (grabIndex, screen->normalCursor ());
622
 
        break;
623
 
    default:
624
 
        break;
 
613
 
 
614
            break;
 
615
 
 
616
        case DnDNone:
 
617
            screen->updateGrab (grabIndex, screen->normalCursor ());
 
618
            break;
 
619
 
 
620
        default:
 
621
            break;
625
622
    }
626
623
}
627
624
 
628
625
static bool
629
 
unproject (float winx, float winy, float winz,
630
 
           const GLMatrix &modelview,
631
 
           const GLMatrix &projection,
632
 
           const GLint viewport[4],
633
 
           float *objx, float *objy, float *objz)
 
626
unproject (float          winx,
 
627
           float          winy,
 
628
           float          winz,
 
629
           const GLMatrix &modelview,
 
630
           const GLMatrix &projection,
 
631
           const GLint    viewport[4],
 
632
           float          *objx,
 
633
           float          *objy,
 
634
           float          *objz)
634
635
{
635
636
    GLMatrix finalMatrix = projection * modelview;
636
637
    float in[4], out[4];
652
653
    in[1] = in[1] * 2 - 1;
653
654
    in[2] = in[2] * 2 - 1;
654
655
 
655
 
    for (int i = 0; i < 4; i++)
 
656
    for (int i = 0; i < 4; ++i)
656
657
    {
657
658
        out[i] = in[0] * finalMatrix[i] +
658
659
                 in[1] * finalMatrix[4  + i] +
675
676
}
676
677
 
677
678
void
678
 
ExpoScreen::invertTransformedVertex (const GLScreenPaintAttrib& attrib,
679
 
                                     const GLMatrix&            transform,
680
 
                                     CompOutput                 *output,
681
 
                                     int                        vertex[2])
 
679
ExpoScreen::invertTransformedVertex (const GLScreenPaintAttrib &attrib,
 
680
                                     const GLMatrix            &transform,
 
681
                                     CompOutput                *output,
 
682
                                     int                       vertex[2])
682
683
{
683
684
    GLMatrix sTransform (transform);
684
 
    float    p1[3], p2[3], v[3], alpha;
 
685
    float    p1[3], p2[3], v[3];
685
686
    GLint    viewport[4];
686
687
 
687
688
    gScreen->glApplyTransform (attrib, output, &sTransform);
690
691
    glGetIntegerv (GL_VIEWPORT, viewport);
691
692
 
692
693
    unproject (vertex[0], screen->height () - vertex[1], 0,
693
 
               sTransform, *gScreen->projectionMatrix (), viewport,
694
 
               &p1[0], &p1[1], &p1[2]);
 
694
            sTransform, *gScreen->projectionMatrix (), viewport,
 
695
            &p1[0], &p1[1], &p1[2]);
695
696
    unproject (vertex[0], screen->height () - vertex[1], -1.0,
696
 
               sTransform, *gScreen->projectionMatrix (), viewport,
697
 
               &p2[0], &p2[1], &p2[2]);
 
697
            sTransform, *gScreen->projectionMatrix (), viewport,
 
698
            &p2[0], &p2[1], &p2[2]);
698
699
 
699
 
    for (int i = 0; i < 3; i++)
 
700
    for (int i = 0; i < 3; ++i)
700
701
        v[i] = p1[i] - p2[i];
701
702
 
702
 
    alpha = -p1[2] / v[2];
 
703
    float alpha = -p1[2] / v[2];
703
704
 
704
705
    if (optionGetDeform () == DeformCurve && screen->desktopWindowCount ())
705
706
    {
706
 
        const float sws = screen->width () * screen->width ();
707
 
        const float rs = (curveDistance * curveDistance) + 0.25;
708
 
        const float p = ((2.0 * sws * (p1[2] - curveDistance) * v[2]) +
709
 
                         (2.0 * p1[0] * v[0]) -
710
 
                         (v[0] * (float) screen->width ())) /
711
 
                        ((v[2] * v[2] * sws) + (v[0] * v[0]));
712
 
        const float q = (-(sws * rs) + (sws * (p1[2] - curveDistance) *
713
 
                                        (p1[2] - curveDistance)) +
714
 
                         (0.25 * sws) + (p1[0] * p1[0]) -
715
 
                         (p1[0] * (float) screen->width ())) /
716
 
                        ((v[2] * v[2] * sws) + (v[0] * v[0]));
717
 
 
718
 
        const float rq = (0.25 * p * p) - q;
719
 
        const float ph = -p * 0.5;
 
707
        const float screenWidth                  = static_cast <float> (screen->width ());
 
708
        const float screenWidthSquared           = screenWidth * screenWidth;
 
709
        const float curveDistSquaredPlusQuarter  = curveDistance * curveDistance + 0.25;
 
710
        const float pOne2MinusCurveDist          = p1[2] - curveDistance;
 
711
        const float v0Squared                    = v[0] * v[0];
 
712
        const float v2Squared                    = v[2] * v[2];
 
713
        const float vsv                          = v2Squared * screenWidthSquared +
 
714
                                                   v0Squared;
 
715
 
 
716
        const float p   = (2.0 * screenWidthSquared * pOne2MinusCurveDist * v[2] +
 
717
                           2.0 * p1[0] * v[0] - v[0] * screenWidth) / vsv;
 
718
        const float q   = (-screenWidthSquared * curveDistSquaredPlusQuarter +
 
719
                           screenWidthSquared * pOne2MinusCurveDist * pOne2MinusCurveDist +
 
720
                           0.25 * screenWidthSquared +
 
721
                           p1[0] * p1[0] - p1[0] * screenWidth) / vsv;
 
722
 
 
723
        const float rq  = 0.25 * p * p - q;
 
724
        const float ph  = -p * 0.5;
720
725
 
721
726
        if (rq < 0.0)
722
727
        {
727
732
        else
728
733
        {
729
734
            alpha = ph + sqrt(rq);
 
735
 
730
736
            if (p1[2] + (alpha * v[2]) > 0.0)
731
737
            {
732
738
                vertex[0] = -1000;
741
747
}
742
748
 
743
749
void
744
 
ExpoScreen::paintWall (const GLScreenPaintAttrib& attrib,
745
 
                       const GLMatrix&            transform,
746
 
                       const CompRegion&          region,
747
 
                       CompOutput                 *output,
748
 
                       unsigned int               mask,
749
 
                       bool                       reflection)
 
750
ExpoScreen::paintWall (const GLScreenPaintAttrib &attrib,
 
751
                       const GLMatrix&           transform,
 
752
                       const CompRegion&         region,
 
753
                       CompOutput                *output,
 
754
                       unsigned int              mask,
 
755
                       bool                      reflection)
750
756
{
751
 
    GLfloat vertexData[12];
 
757
    GLfloat  vertexData[12];
752
758
    GLushort colorData[16];
753
759
    GLMatrix sTransformW, sTransform (transform);
754
 
    int      i, j, vp;
755
 
    GLenum   oldFilter = gScreen->textureFilter ();
756
760
 
757
 
    float     sx = (float) screen->width () / output->width ();
758
 
    float     sy = (float) screen->height () / output->height ();
759
 
    float     biasZ;
760
 
    float     oScale, rotation = 0.0f, progress, vpp;
761
 
    float     aspectX = 1.0f, aspectY = 1.0f;
762
 
    GLVector  cam;
763
761
    CompPoint vpSize (screen->vpSize ().width (), screen->vpSize ().height ());
764
762
 
765
763
    /* amount of gap between viewports */
767
765
    const float gapX = optionGetVpDistance () * 0.1f * screen->height () /
768
766
                       screen->width () * expoCam;
769
767
 
770
 
    int      glPaintTransformedOutputIndex =
771
 
        gScreen->glPaintTransformedOutputGetCurrentIndex ();
 
768
    int glPaintTransformedOutputIndex = gScreen->glPaintTransformedOutputGetCurrentIndex ();
772
769
 
773
770
    GLVertexBuffer *streamingBuffer = GLVertexBuffer::streamingBuffer ();
774
771
 
782
779
    /* camera position during expo mode */
783
780
    GLVector expoCamPos (0, 0, 0, 0);
784
781
 
 
782
    float sx = screen->width ()  / static_cast <float> (output->width ());
 
783
    float sy = screen->height () / static_cast <float> (output->height ());
 
784
 
785
785
    if (optionGetDeform () == DeformCurve)
786
 
    {
787
 
        vpCamPos[GLVector::x] = -sx * (0.5 - (((float) output->x () +
788
 
                                               (output->width () / 2.0)) /
789
 
                                              (float) screen->width ()));
790
 
    }
 
786
        vpCamPos[GLVector::x] = -sx * (0.5 - ((static_cast <float> (output->x ()) +
 
787
                                               output->width () / 2.0) /
 
788
                                              static_cast <float> (screen->width ())));
791
789
    else
792
 
    {
793
 
        vpCamPos[GLVector::x] = (screen->vp ().x () * sx) + 0.5 +
794
 
                                (output->x () / output->width ()) -
795
 
                                (vpSize.x () * 0.5 * sx) +
 
790
        vpCamPos[GLVector::x] = screen->vp ().x () * sx + 0.5 +
 
791
                                output->x () / output->width () -
 
792
                                vpSize.x () * 0.5 * sx +
796
793
                                gapX * screen->vp ().x ();
797
 
    }
798
 
    vpCamPos[GLVector::y] = -((screen->vp ().y () * sy) + 0.5 +
799
 
                              (output->y () / output->height ())) +
800
 
                             (vpSize.y () * 0.5 * sy) -
801
 
                             gapY * screen->vp ().y ();
802
 
 
803
 
    biasZ = MAX (vpSize.x () * sx, vpSize.y () * sy);
 
794
 
 
795
    vpCamPos[GLVector::y] = -(screen->vp ().y () * sy + 0.5 +
 
796
                              output->y () / output->height ()) +
 
797
                            vpSize.y () * 0.5 * sy -
 
798
                            gapY * screen->vp ().y ();
 
799
 
 
800
    float biasZ = MAX (vpSize.x () * sx, vpSize.y () * sy);
 
801
 
804
802
    if (optionGetDeform () == DeformTilt || optionGetReflection ())
805
803
        biasZ *= (0.15 + optionGetDistance ());
806
804
    else
807
805
        biasZ *= optionGetDistance ();
808
806
 
809
 
    progress = sigmoidProgress (expoCam);
 
807
    float progress = sigmoidProgress (expoCam);
810
808
 
811
809
    if (optionGetDeform () != DeformCurve)
812
810
        expoCamPos[GLVector::x] = gapX * (vpSize.x () - 1) * 0.5;
813
811
 
814
812
    expoCamPos[GLVector::y] = -gapY * (vpSize.y () - 1) * 0.5;
815
813
    expoCamPos[GLVector::z] = -DEFAULT_Z_CAMERA + DEFAULT_Z_CAMERA *
816
 
                              (MAX (vpSize.x () + (vpSize.x () - 1) * gapX,
 
814
                              (MAX (vpSize.x () + (vpSize.x () - 1) * gapX,
817
815
                                    vpSize.y () + (vpSize.y () - 1) * gapY) +
818
816
                               biasZ);
819
817
 
820
818
    /* interpolate between vpCamPos and expoCamPos */
 
819
    GLVector cam;
 
820
 
821
821
    cam[GLVector::x] = vpCamPos[GLVector::x] * (1 - progress) +
822
 
                       expoCamPos[GLVector::x] * progress;
 
822
                       expoCamPos[GLVector::x] * progress;
823
823
    cam[GLVector::y] = vpCamPos[GLVector::y] * (1 - progress) +
824
 
                       expoCamPos[GLVector::y] * progress;
 
824
                       expoCamPos[GLVector::y] * progress;
825
825
    cam[GLVector::z] = vpCamPos[GLVector::z] * (1 - progress) +
826
 
                       expoCamPos[GLVector::z] * progress;
 
826
                       expoCamPos[GLVector::z] * progress;
 
827
 
 
828
    float aspectX = 1.0f, aspectY = 1.0f;
827
829
 
828
830
    if (vpSize.x () > vpSize.y ())
829
831
    {
830
 
        aspectY = (float) vpSize.x () / (float) vpSize.y ();
 
832
        aspectY  = vpSize.x () / static_cast <float> (vpSize.y ());
831
833
        aspectY -= 1.0;
832
834
        aspectY *= -optionGetAspectRatio () + 1.0;
833
835
        aspectY *= progress;
835
837
    }
836
838
    else
837
839
    {
838
 
        aspectX = (float) vpSize.y () / (float) vpSize.x ();
 
840
        aspectX  = vpSize.y () / static_cast <float> (vpSize.x ());
839
841
        aspectX -= 1.0;
840
842
        aspectX *= -optionGetAspectRatio () + 1.0;
841
843
        aspectX *= progress;
844
846
 
845
847
    /* End of Zoom animation stuff */
846
848
 
 
849
    float rotation = 0.0f;
 
850
 
847
851
    if (optionGetDeform () == DeformTilt)
848
852
    {
849
853
        if (optionGetExpoAnimation () == ExpoAnimationZoom)
852
856
            rotation = 10.0 * expoCam;
853
857
    }
854
858
 
 
859
    GLenum oldFilter = gScreen->textureFilter ();
 
860
 
855
861
    if (optionGetMipmaps ())
856
862
        gScreen->setTextureFilter (GL_LINEAR_MIPMAP_LINEAR);
857
863
 
858
864
    /* ALL TRANSFORMATION ARE EXECUTED FROM BOTTOM TO TOP */
859
865
 
860
 
    oScale = 1 / (1 + ((MAX (sx, sy) - 1) * progress));
 
866
    float oScale = 1 / (1 + ((MAX (sx, sy) - 1) * progress));
861
867
 
862
868
    sTransform.scale (oScale, oScale, 1.0);
863
869
 
891
897
 
892
898
    CompPoint offsetInScreenCoords (optionGetXOffset (),
893
899
                                    optionGetYOffset ());
894
 
    float     offsetInWorldCoordX, offsetInWorldCoordY, worldScaleFactorX, worldScaleFactorY;
 
900
    float offsetInWorldCoordX, offsetInWorldCoordY, worldScaleFactorX, worldScaleFactorY;
895
901
 
896
902
    compiz::expo::calculateWallOffset (*output,
897
903
                                       offsetInScreenCoords,
905
911
 
906
912
    /* translate expo to center */
907
913
    sTransform.translate (vpSize.x () * sx * -0.5 + offsetInWorldCoordX,
908
 
                          vpSize.y () * sy * 0.5 - offsetInWorldCoordY, 0.0f);
 
914
                          vpSize.y () * sy *  0.5 - offsetInWorldCoordY, 0.0f);
909
915
    sTransform.scale (worldScaleFactorX, worldScaleFactorY, 1.0f);
910
916
 
911
917
 
924
930
    else
925
931
        curveAngle = interpolate (180 / vpSize.x (), 1, optionGetCurve ());
926
932
 
927
 
    curveDistance = ((0.5f * sx) + (gapX / 2.0)) /
928
 
                    tanf ((M_PI / 180.0f) * curveAngle / 2.0);
929
 
    curveRadius   = ((0.5f * sx) + (gapX / 2.0)) /
930
 
                    sinf ((M_PI / 180.0f) * curveAngle / 2.0);
 
933
    const float halfGapX = gapX / 2.0;
 
934
 
 
935
    curveDistance = ((0.5f * sx) + halfGapX) /
 
936
                    tanf ((M_PI / 360.0f) * curveAngle);
 
937
    curveRadius   = ((0.5f * sx) + halfGapX) /
 
938
                    sinf ((M_PI / 360.0f) * curveAngle);
931
939
 
932
940
    expoActive = true;
933
941
 
934
 
    for (j = 0; j < vpSize.y (); j++)
 
942
    float rotateX, vpp;
 
943
    int   vp;
 
944
 
 
945
    for (int j = 0; j < vpSize.y (); ++j)
935
946
    {
936
947
        GLMatrix sTransform2 (sTransform), sTransform3;
937
948
 
938
 
        for (i = 0; i < vpSize.x (); i++)
 
949
        for (int i = 0; i < vpSize.x (); ++i)
939
950
        {
940
951
            if (optionGetExpoAnimation () == ExpoAnimationVortex)
941
952
                sTransform2.rotate (360 * expoCam,
943
954
 
944
955
            sTransform3 = sTransform2;
945
956
 
946
 
            sTransform3.translate (output->x () / output->width (),
 
957
            sTransform3.translate ( output->x () / output->width (),
947
958
                                   -output->y () / output->height (), 0.0);
948
959
 
949
960
            cScreen->setWindowPaintOffset ((screen->vp ().x () - i) *
965
976
 
966
977
            if (optionGetDeform () == DeformCurve)
967
978
            {
968
 
                float rotateX;
969
 
 
970
979
                sTransform3.translate (-vpCamPos[GLVector::x], 0.0f,
971
980
                                       curveDistance - DEFAULT_Z_CAMERA);
972
981
 
973
 
                rotateX = -i + interpolate (((float) vpSize.x () / 2.0) - 0.5,
 
982
                rotateX = -i + interpolate ((static_cast <float> (vpSize.x ()) / 2.0) -
 
983
                                            0.5,
974
984
                                            screen->vp ().x (), progress);
975
985
 
976
986
                sTransform3.rotate (curveAngle * rotateX, 0.0, 1.0, 0.0);
990
1000
                invertTransformedVertex (attrib, sTransform3,
991
1001
                                         output, cursor);
992
1002
 
993
 
                if ((cursor[0] > 0) && (cursor[0] < (int) screen->width ()) &&
994
 
                    (cursor[1] > 0) && (cursor[1] < (int) screen->height ()))
 
1003
                if (cursor[0] > 0                                       &&
 
1004
                    cursor[0] < static_cast <int> (screen->width ())    &&
 
1005
                    cursor[1] > 0                                       &&
 
1006
                    cursor[1] < static_cast <int> (screen->height ()))
995
1007
                {
996
 
                    newCursor.setX (i * screen->width () + cursor[0]);
 
1008
                    newCursor.setX (i * screen->width ()  + cursor[0]);
997
1009
                    newCursor.setY (j * screen->height () + cursor[1]);
998
1010
 
999
1011
                    if (anyClick || dndState != DnDNone)
1001
1013
                        /* Used to save last viewport interaction was in */
1002
1014
                        lastSelectedVp = selectedVp;
1003
1015
                        selectedVp.set (i, j);
1004
 
                        anyClick = false;
 
1016
                        anyClick       = false;
1005
1017
                    }
1006
1018
                }
1007
1019
            }
1019
1031
 
1020
1032
    if (reflection)
1021
1033
    {
1022
 
        glEnable (GL_BLEND);
 
1034
        GLboolean glBlendEnabled = glIsEnabled (GL_BLEND);
 
1035
 
 
1036
        /* just enable blending if it is disabled */
 
1037
        if (!glBlendEnabled)
 
1038
            glEnable (GL_BLEND);
 
1039
 
1023
1040
        glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
1024
1041
 
1025
1042
        if (optionGetDeform () != DeformCurve)
1145
1162
            streamingBuffer->end ();
1146
1163
            streamingBuffer->render (cTransform);
1147
1164
        }
 
1165
 
1148
1166
        glCullFace (GL_BACK);
1149
1167
 
1150
1168
        if (optionGetGroundSize () > 0.0)
1151
1169
        {
 
1170
            float    groundSize = optionGetGroundSize ();
1152
1171
            GLMatrix gTransform;
1153
1172
            gTransform.translate (0.0, 0.0, -DEFAULT_Z_CAMERA);
1154
1173
 
1161
1180
            vertexData[4]  = -0.5;
1162
1181
            vertexData[5]  = 0;
1163
1182
            vertexData[6]  = -0.5;
1164
 
            vertexData[7]  = -0.5 + optionGetGroundSize ();
 
1183
            vertexData[7]  = -0.5 + groundSize;
1165
1184
            vertexData[8]  = 0;
1166
1185
            vertexData[9]  = 0.5;
1167
 
            vertexData[10] = -0.5 + optionGetGroundSize ();
 
1186
            vertexData[10] = -0.5 + groundSize;
1168
1187
            vertexData[11] = 0;
1169
1188
 
1170
1189
            streamingBuffer->addColors (1, optionGetGroundColor1 ());
1176
1195
            streamingBuffer->end ();
1177
1196
            streamingBuffer->render (gTransform);
1178
1197
        }
 
1198
 
1179
1199
        glBlendFunc (GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
1180
 
        glDisable (GL_BLEND);
 
1200
 
 
1201
        /* just disable blending if it was disabled before */
 
1202
        if (!glBlendEnabled)
 
1203
            glDisable (GL_BLEND);
1181
1204
    }
1182
1205
 
1183
1206
    expoActive = false;
1185
1208
    cScreen->setWindowPaintOffset (0, 0);
1186
1209
 
1187
1210
    gScreen->glPaintTransformedOutputSetCurrentIndex (glPaintTransformedOutputIndex);
 
1211
 
1188
1212
    gScreen->setTextureFilter (oldFilter);
1189
1213
}
1190
1214
 
1191
1215
bool
1192
 
ExpoScreen::glPaintOutput (const GLScreenPaintAttrib& attrib,
1193
 
                           const GLMatrix&            transform,
1194
 
                           const CompRegion&          region,
1195
 
                           CompOutput                 *output,
1196
 
                           unsigned int               mask)
 
1216
ExpoScreen::glPaintOutput (const GLScreenPaintAttrib &attrib,
 
1217
                           const GLMatrix            &transform,
 
1218
                           const CompRegion          &region,
 
1219
                           CompOutput                *output,
 
1220
                           unsigned int              mask)
1197
1221
{
1198
1222
    if (expoCam > 0.0)
1199
1223
        mask |= PAINT_SCREEN_TRANSFORMED_MASK | PAINT_SCREEN_CLEAR_MASK;
1202
1226
}
1203
1227
 
1204
1228
void
1205
 
ExpoScreen::glPaintTransformedOutput (const GLScreenPaintAttrib& attrib,
1206
 
                                      const GLMatrix&            transform,
1207
 
                                      const CompRegion&          region,
1208
 
                                      CompOutput                 *output,
1209
 
                                      unsigned int               mask)
 
1229
ExpoScreen::glPaintTransformedOutput (const GLScreenPaintAttrib &attrib,
 
1230
                                      const GLMatrix            &transform,
 
1231
                                      const CompRegion          &region,
 
1232
                                      CompOutput                *output,
 
1233
                                      unsigned int              mask)
1210
1234
{
1211
1235
    expoActive = false;
1212
1236
 
1226
1250
 
1227
1251
    if (expoCam <= 0 || (expoCam > 0.0 && expoCam < 1.0 &&
1228
1252
                         optionGetExpoAnimation () != ExpoAnimationZoom))
1229
 
    {
1230
1253
        gScreen->glPaintTransformedOutput (attrib, transform, region,
1231
1254
                                           output, mask);
1232
 
    }
1233
1255
    else
1234
 
    {
1235
1256
        gScreen->clearOutput (output, GL_COLOR_BUFFER_BIT);
1236
 
    }
1237
1257
 
1238
1258
    mask &= ~PAINT_SCREEN_CLEAR_MASK;
1239
1259
 
1248
1268
}
1249
1269
 
1250
1270
bool
1251
 
ExpoWindow::glDraw (const GLMatrix&     transform,
1252
 
                    const GLWindowPaintAttrib &attrib,
1253
 
                    const CompRegion&   region,
1254
 
                    unsigned int        mask)
 
1271
ExpoWindow::glDraw (const GLMatrix            &transform,
 
1272
                    const GLWindowPaintAttrib &attrib,
 
1273
                    const CompRegion          &region,
 
1274
                    unsigned int              mask)
1255
1275
{
1256
1276
    if (eScreen->expoCam == 0.0f)
1257
1277
        return gWindow->glDraw (transform, attrib, region, mask);
1258
1278
 
1259
 
    int                expoAnimation;
1260
 
 
1261
1279
    // Scaling factors to be applied to attrib later in glDrawTexture
1262
1280
    expoOpacity = 1.0f;
1263
1281
 
1264
 
    expoAnimation = eScreen->optionGetExpoAnimation ();
 
1282
    int expoAnimation = eScreen->optionGetExpoAnimation ();
1265
1283
 
1266
1284
    if (eScreen->expoActive)
1267
1285
    {
1273
1291
        {
1274
1292
            if (expoAnimation == ExpoScreen::ExpoAnimationZoom &&
1275
1293
                eScreen->paintingVp == eScreen->selectedVp)
1276
 
            {
1277
1294
                expoOpacity = (1.0f - sigmoidProgress (eScreen->expoCam));
1278
 
            }
1279
1295
            else
1280
 
            {
1281
1296
                expoOpacity = 0.0f;
1282
 
            }
1283
1297
        }
1284
1298
    }
1285
1299
 
1286
1300
    bool status = gWindow->glDraw (transform, attrib, region, mask);
1287
1301
 
1288
1302
    if (window->type () & CompWindowTypeDesktopMask &&
1289
 
        eScreen->optionGetSelectedColor ()[3] &&  // colour is visible
1290
 
        mGlowQuads &&
1291
 
        eScreen->paintingVp == eScreen->selectedVp &&
1292
 
        region.numRects ())
 
1303
        eScreen->optionGetSelectedColor ()[3]       &&  // colour is visible
 
1304
        mGlowQuads                                  &&
 
1305
        eScreen->paintingVp == eScreen->selectedVp  &&
 
1306
        region.numRects ())
1293
1307
    {
1294
1308
        /* reset geometry and paint */
1295
1309
        gWindow->vertexBuffer ()->begin ();
1303
1317
static const unsigned short EXPO_GRID_SIZE = 100;
1304
1318
 
1305
1319
void
1306
 
ExpoWindow::glAddGeometry (const GLTexture::MatrixList& matrices,
1307
 
                           const CompRegion&            region,
1308
 
                           const CompRegion&            clip,
1309
 
                           unsigned int                 maxGridWidth,
1310
 
                           unsigned int                 maxGridHeight)
 
1320
ExpoWindow::glAddGeometry (const GLTexture::MatrixList &matrices,
 
1321
                           const CompRegion            &region,
 
1322
                           const CompRegion            &clip,
 
1323
                           unsigned int                maxGridWidth,
 
1324
                           unsigned int                maxGridHeight)
1311
1325
{
1312
 
    if (eScreen->expoCam > 0.0        &&
1313
 
        screen->desktopWindowCount () &&
 
1326
    if (eScreen->expoCam > 0.0          &&
 
1327
        screen->desktopWindowCount ()   &&
1314
1328
        eScreen->optionGetDeform () == ExpoScreen::DeformCurve)
1315
1329
    {
1316
 
        int         i, oldVCount = gWindow->vertexBuffer ()->countVertices ();
1317
 
        GLfloat     *v;
1318
 
        CompPoint   offset;
1319
 
        float       lastX, lastZ = 0.0;
1320
 
        const float radSquare = pow (eScreen->curveDistance, 2) + 0.25;
1321
 
        float       ang;
1322
 
 
1323
1330
        gWindow->glAddGeometry (matrices, region, clip,
1324
 
                                MIN(maxGridWidth , EXPO_GRID_SIZE),
 
1331
                                MIN (maxGridWidth, EXPO_GRID_SIZE),
1325
1332
                                maxGridHeight);
1326
1333
 
1327
 
        int stride = gWindow->vertexBuffer ()->getVertexStride ();
1328
 
        v  = gWindow->vertexBuffer ()->getVertices ();
 
1334
        int     stride    = gWindow->vertexBuffer ()->getVertexStride ();
 
1335
        int     oldVCount = gWindow->vertexBuffer ()->countVertices ();
 
1336
        GLfloat *v        = gWindow->vertexBuffer ()->getVertices ();
 
1337
 
1329
1338
        v += stride - 3;
1330
1339
        v += stride * oldVCount;
1331
1340
 
 
1341
        CompPoint offset;
 
1342
 
1332
1343
        if (!window->onAllViewports ())
1333
1344
        {
1334
1345
            offset = eScreen->cScreen->windowPaintOffset ();
1335
1346
            offset = window->getMovementForOffset (offset);
1336
1347
        }
1337
1348
 
1338
 
        lastX = -1000000000.0;
 
1349
        float       ang;
 
1350
        float       lastX     = -1000000000.0f;
 
1351
        float       lastZ     = 0.0f;
 
1352
        const float radSquare = pow (eScreen->curveDistance, 2) + 0.25;
1339
1353
 
1340
 
        for (i = oldVCount; i < gWindow->vertexBuffer ()->countVertices (); i++)
 
1354
        for (int i = oldVCount; i < gWindow->vertexBuffer ()->countVertices (); ++i)
1341
1355
        {
1342
1356
            if (v[0] == lastX)
1343
 
            {
1344
1357
                v[2] = lastZ;
1345
 
            }
1346
1358
            else if (v[0] + offset.x () >= -EXPO_GRID_SIZE &&
1347
1359
                     v[0] + offset.x () < screen->width () + EXPO_GRID_SIZE)
1348
1360
            {
1349
 
                ang = (((v[0] + offset.x ()) / (float) screen->width ()) - 0.5);
 
1361
                ang  = ((v[0] + offset.x ()) /
 
1362
                       static_cast <float> (screen->width ())) - 0.5;
1350
1363
                ang *= ang;
 
1364
 
1351
1365
                if (ang < radSquare)
1352
1366
                {
1353
 
                    v[2] = eScreen->curveDistance - sqrt (radSquare - ang);
 
1367
                    v[2]  = eScreen->curveDistance - sqrt (radSquare - ang);
1354
1368
                    v[2] *= sigmoidProgress (eScreen->expoCam);
1355
1369
                }
1356
1370
            }
1362
1376
        }
1363
1377
    }
1364
1378
    else
1365
 
    {
1366
1379
        gWindow->glAddGeometry (matrices, region, clip, maxGridWidth, maxGridHeight);
1367
 
    }
1368
1380
}
1369
1381
 
1370
1382
void
1371
 
ExpoWindow::glDrawTexture (GLTexture           *texture,
1372
 
                           const GLMatrix            &transform,
1373
 
                           const GLWindowPaintAttrib &attrib,
1374
 
                           unsigned int        mask)
 
1383
ExpoWindow::glDrawTexture (GLTexture                 *texture,
 
1384
                           const GLMatrix            &transform,
 
1385
                           const GLWindowPaintAttrib &attrib,
 
1386
                           unsigned int              mask)
1375
1387
{
1376
1388
    GLWindowPaintAttrib wAttrib (attrib);
1377
1389
 
1378
1390
    if (eScreen->expoCam > 0.0)
1379
1391
    {
1380
 
        wAttrib.opacity *= expoOpacity;
 
1392
        wAttrib.opacity    *= expoOpacity;
1381
1393
        wAttrib.brightness *= eScreen->vpBrightness;
1382
1394
        wAttrib.saturation *= eScreen->vpSaturation;
1383
1395
    }
1384
1396
 
1385
 
    if (eScreen->expoCam > 0.0                                 &&
1386
 
        eScreen->optionGetDeform () == ExpoScreen::DeformCurve &&
1387
 
        eScreen->gScreen->lighting ()                          &&
 
1397
    if (eScreen->expoCam > 0.0                                  &&
 
1398
        eScreen->optionGetDeform () == ExpoScreen::DeformCurve  &&
 
1399
        eScreen->gScreen->lighting ()                           &&
1388
1400
        screen->desktopWindowCount ())
1389
1401
    {
1390
 
        CompPoint    offset;
1391
 
        GLfloat      *v;
1392
 
        GLVertexBuffer *vb = gWindow->vertexBuffer ();
 
1402
        CompPoint offset;
1393
1403
 
1394
1404
        if (!window->onAllViewports ())
1395
1405
        {
1397
1407
            offset = window->getMovementForOffset (offset);
1398
1408
        }
1399
1409
 
1400
 
        int stride = vb->getVertexStride ();
1401
 
        v = vb->getVertices () + stride - 3;
 
1410
        GLVertexBuffer *vb    = gWindow->vertexBuffer ();
 
1411
        int            stride = vb->getVertexStride ();
 
1412
        GLfloat        *v     = vb->getVertices () + stride - 3;
 
1413
        GLfloat        normal[3];
 
1414
        int            idx;
 
1415
        float          x;
1402
1416
 
1403
 
        for (int i = 0; i < vb->countVertices (); i++)
 
1417
        for (int i = 0; i < vb->countVertices (); ++i)
1404
1418
        {
1405
 
            float x = (v[0] + offset.x () - screen->width () / 2) *
1406
 
                      eScreen->curveAngle / screen->width ();
 
1419
            x = (v[0] + offset.x () - screen->width () / 2) *
 
1420
                    eScreen->curveAngle / screen->width ();
1407
1421
 
1408
1422
            while (x < 0)
1409
1423
                x += 360.0;
1410
1424
 
1411
 
            int idx = floor (x);
 
1425
            idx = floor (x);
1412
1426
 
1413
 
            GLfloat normal[3];
1414
1427
            normal[0] = -eScreen->vpNormals[idx * 3];
1415
1428
            normal[1] = eScreen->vpNormals[(idx * 3) + 1];
1416
1429
            normal[2] = eScreen->vpNormals[(idx * 3) + 2];
1439
1452
}
1440
1453
 
1441
1454
bool
1442
 
ExpoWindow::glPaint (const GLWindowPaintAttrib& attrib,
1443
 
                     const GLMatrix&            transform,
1444
 
                     const CompRegion&          region,
1445
 
                     unsigned int               mask)
 
1455
ExpoWindow::glPaint (const GLWindowPaintAttrib &attrib,
 
1456
                     const GLMatrix            &transform,
 
1457
                     const CompRegion          &region,
 
1458
                     unsigned int              mask)
1446
1459
{
1447
1460
    if (eScreen->expoActive)
1448
1461
    {
1449
 
        float opacity = 1.0;
1450
 
        bool  hide;
1451
 
        bool  zoomAnim;
1452
 
 
1453
 
        zoomAnim = eScreen->optionGetExpoAnimation () ==
1454
 
                   ExpoScreen::ExpoAnimationZoom;
1455
 
        hide     = eScreen->optionGetHideDocks () &&
1456
 
                   (window->wmType () & CompWindowTypeDockMask);
1457
 
 
1458
1462
        if (eScreen->expoCam > 0.0)
1459
1463
            mask |= PAINT_WINDOW_TRANSLUCENT_MASK;
1460
1464
 
 
1465
        float opacity  = 1.0;
 
1466
        bool  zoomAnim = eScreen->optionGetExpoAnimation () ==
 
1467
                         ExpoScreen::ExpoAnimationZoom;
 
1468
        bool  hide     = eScreen->optionGetHideDocks () &&
 
1469
                         (window->wmType () & CompWindowTypeDockMask);
 
1470
 
1461
1471
        if (!zoomAnim)
1462
1472
            opacity = attrib.opacity * eScreen->expoCam;
1463
1473
 
1479
1489
 
1480
1490
bool
1481
1491
ExpoWindow::damageRect (bool            initial,
1482
 
                        const CompRect& rect)
 
1492
                        const CompRect  &rect)
1483
1493
{
1484
1494
    if (eScreen->expoCam > 0.0f)
1485
1495
        eScreen->cScreen->damageScreen ();
1497
1507
ExpoScreen::ExpoScreen (CompScreen *s) :
1498
1508
    PluginClassHandler<ExpoScreen, CompScreen> (s),
1499
1509
    ExpoOptions (),
1500
 
    cScreen (CompositeScreen::get (s)),
1501
 
    gScreen (GLScreen::get (s)),
1502
 
    expoCam (0.0f),
1503
 
    expoActive (false),
1504
 
    expoMode (false),
1505
 
    dndState (DnDNone),
1506
 
    dndWindow (NULL),
1507
 
    origVp (s->vp ()),
1508
 
    selectedVp (s->vp ()),
1509
 
    lastSelectedVp (s->vp ()),
1510
 
    vpUpdateMode (VPUpdateNone),
1511
 
    clickTime (0),
1512
 
    doubleClick (false),
1513
 
    vpNormals (360 * 3),
1514
 
    grabIndex (0),
 
1510
    cScreen                (CompositeScreen::get (s)),
 
1511
    gScreen                (GLScreen::get (s)),
 
1512
    expoCam                (0.0f),
 
1513
    expoActive             (false),
 
1514
    expoMode               (false),
 
1515
    dndState               (DnDNone),
 
1516
    dndWindow              (NULL),
 
1517
    origVp                 (s->vp ()),
 
1518
    selectedVp             (s->vp ()),
 
1519
    lastSelectedVp         (s->vp ()),
 
1520
    vpUpdateMode           (VPUpdateNone),
 
1521
    clickTime              (0),
 
1522
    doubleClick            (false),
 
1523
    vpNormals              (360 * 3),
 
1524
    grabIndex              (0),
1515
1525
    mGlowTextureProperties (&glowTextureProperties)
1516
1526
{
1517
1527
    leftKey  = XKeysymToKeycode (s->dpy (), XStringToKeysym ("Left"));
1552
1562
 
1553
1563
ExpoWindow::ExpoWindow (CompWindow *w) :
1554
1564
    PluginClassHandler<ExpoWindow, CompWindow> (w),
1555
 
    window (w),
1556
 
    cWindow (CompositeWindow::get (w)),
1557
 
    gWindow (GLWindow::get (w)),
1558
 
    eScreen (ExpoScreen::get (screen)),
1559
 
    mGlowQuads (NULL),
 
1565
    window      (w),
 
1566
    cWindow     (CompositeWindow::get (w)),
 
1567
    gWindow     (GLWindow::get (w)),
 
1568
    eScreen     (ExpoScreen::get (screen)),
 
1569
    mGlowQuads  (NULL),
1560
1570
    expoOpacity (1.0f)
1561
1571
{
1562
1572
    CompositeWindowInterface::setHandler (cWindow, false);