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

« back to all changes in this revision

Viewing changes to plugins/opacify/src/opacify.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:
35
35
{
36
36
    OPACIFY_SCREEN (screen);
37
37
 
38
 
    screen->handleEventSetEnabled (os, enabled);
 
38
    screen->handleEventSetEnabled (os, os->isToggle);
39
39
 
40
40
    foreach (CompWindow *w, screen->windows ())
41
41
    {
57
57
        cWindow->addDamage ();
58
58
 
59
59
    opacified = true;
60
 
    opacity = fOpacity;
 
60
    opacity   = fOpacity;
61
61
}
62
62
 
63
63
/* Resets the Window to the original opacity if it still exists.
64
64
*/
65
65
 
66
66
void
67
 
OpacifyScreen::resetWindowOpacity (Window  id)
 
67
OpacifyScreen::resetWindowOpacity (Window id)
68
68
{
69
 
    CompWindow *w;
 
69
    CompWindow *w = screen->findWindow (id);
70
70
 
71
 
    w = screen->findWindow (id);
72
71
    if (!w)
73
72
        return;
74
73
 
81
80
/* Resets all the windows on the screen to the original opacity
82
81
 * if necessary. Then reset active.
83
82
*/
84
 
 
85
83
void
86
84
OpacifyScreen::resetScreenOpacity ()
87
85
{
98
96
void
99
97
OpacifyScreen::clearPassive ()
100
98
{
 
99
    CompWindow *win;
 
100
    int        activeOpacity = optionGetActiveOpacity ();
 
101
    GLushort   targetOpacity = OPAQUE * activeOpacity / 100;
 
102
 
101
103
    foreach (Window xid, passive)
102
104
    {
103
 
        CompWindow *win = screen->findWindow (xid);
 
105
        win = screen->findWindow (xid);
104
106
 
105
107
        if (!win)
106
108
            continue;
107
109
 
108
110
        OPACIFY_WINDOW (win);
109
111
 
110
 
        ow->setOpacity (MAX (OPAQUE * optionGetActiveOpacity () / 100,
111
 
                        ow->gWindow->paintAttrib ().opacity));
 
112
        ow->setOpacity (std::max (targetOpacity,
 
113
                                  ow->gWindow->paintAttrib ().opacity));
112
114
        resetWindowOpacity (xid);
113
115
    }
 
116
 
114
117
    passive.clear ();
115
118
}
116
119
 
117
120
/* Dim an (inactive) window. Place it on the passive list and
118
121
 * update passiveNum. Then change the opacity.
119
122
 */
120
 
 
121
123
void
122
124
OpacifyWindow::dim ()
123
125
{
138
140
 */
139
141
 
140
142
int
141
 
OpacifyScreen::passiveWindows (CompRegion     fRegion)
 
143
OpacifyScreen::passiveWindows (CompRegion fRegion)
142
144
{
143
 
    bool       flag = false;
144
 
    int        i = 0;
 
145
    bool flag = false;
 
146
    int  i    = 0;
145
147
 
146
148
    /* Clear the list first to prevent memleaks */
147
149
    clearPassive ();
153
155
            flag = true;
154
156
            continue;
155
157
        }
156
 
        if (!flag)
157
 
            continue;
158
 
        if (!optionGetWindowMatch ().evaluate (w))
159
 
            continue;
160
 
        if (!w->isViewable () || w->minimized ())
 
158
 
 
159
        if (!flag                                   ||
 
160
            !optionGetWindowMatch ().evaluate (w)   ||
 
161
            !w->isViewable ()                       ||
 
162
            w->minimized ())
161
163
            continue;
162
164
 
163
165
        intersect = w->region ().intersected (fRegion);
 
166
 
164
167
        if (!intersect.isEmpty ())
165
168
        {
166
169
            OpacifyWindow::get (w)->dim ();
167
 
            i++;
 
170
            ++i;
168
171
        }
169
172
    }
170
173
 
193
196
        }
194
197
 
195
198
        os->resetScreenOpacity ();
 
199
 
196
200
        return;
197
201
    }
198
202
 
200
204
    {
201
205
        os->justMoved = false;
202
206
        os->resetWindowOpacity (os->active);
203
 
        os->active = 0;
 
207
        os->active    = 0;
204
208
    }
205
209
 
206
210
    if (!window)
209
213
    if (window->id () != os->active && !window->shaded () &&
210
214
        os->optionGetWindowMatch ().evaluate (window))
211
215
    {
212
 
        int num;
213
 
 
214
216
        os->active = window->id ();
215
 
        num = os->passiveWindows (window->region ());
 
217
        int num    = os->passiveWindows (window->region ());
216
218
 
217
219
        if (num || os->optionGetOnlyIfBlock ())
218
220
            setOpacity (MAX (OPAQUE * os->optionGetActiveOpacity () / 100,
238
240
bool
239
241
OpacifyScreen::checkDelay ()
240
242
{
241
 
    if (optionGetFocusInstant () && newActive &&
242
 
        (newActive->id () == screen->activeWindow ()))
 
243
    if (optionGetFocusInstant ()    &&
 
244
        newActive                   &&
 
245
        newActive->id () == screen->activeWindow ())
243
246
        return true;
 
247
 
244
248
    if (!optionGetTimeout ())
245
249
        return true;
246
 
    if (!newActive || (newActive->id () == screen->root ()))
247
 
        return false;
248
 
    if (newActive->type () & (CompWindowTypeDesktopMask |
 
250
 
 
251
    if (!newActive                          ||
 
252
        newActive->id () == screen->root () ||
 
253
        newActive->type () & (CompWindowTypeDesktopMask |
249
254
                              CompWindowTypeDockMask))
250
 
    {
251
255
        return false;
252
 
    }
 
256
 
253
257
    if (optionGetNoDelayChange () && !passive.empty ())
254
258
        return true;
255
259
 
258
262
 
259
263
bool
260
264
OpacifyWindow::glPaint (const GLWindowPaintAttrib &attrib,
261
 
                        const GLMatrix            &transform,
262
 
                        const CompRegion          &region,
263
 
                        unsigned int              mask)
 
265
                        const GLMatrix            &transform,
 
266
                        const CompRegion          &region,
 
267
                        unsigned int              mask)
264
268
{
265
269
    if (opacified)
266
270
    {
267
271
        GLWindowPaintAttrib wAttrib = attrib;
268
 
 
269
 
        wAttrib.opacity = opacity;
 
272
        wAttrib.opacity             = opacity;
270
273
 
271
274
        return gWindow->glPaint (wAttrib, transform, region, mask);
272
275
    }
273
276
    else
274
 
    {
275
277
        return gWindow->glPaint (attrib, transform, region, mask);
276
 
    }
277
278
 
278
279
    return false;
279
280
}
285
286
 * micro seconds, or directly if od->timeout is 0 (no delay).
286
287
 *
287
288
 */
288
 
 
289
289
void
290
290
OpacifyScreen::handleEvent (XEvent *event)
291
291
{
292
 
 
293
292
    screen->handleEvent (event);
294
293
 
295
294
    if (!isToggle)
296
295
        return;
297
296
 
298
 
    switch (event->type) {
299
 
    case EnterNotify:
300
 
        Window id;
301
 
 
302
 
        id = event->xcrossing.window;
303
 
        newActive = screen->findTopLevelWindow (id);
304
 
 
305
 
        if (timeoutHandle.active ())
306
 
            timeoutHandle.stop ();
307
 
 
308
 
        if (checkDelay ())
309
 
            handleTimeout ();
310
 
        else
311
 
            timeoutHandle.start ();
312
 
        break;
313
 
    case FocusIn:
314
 
        resetScreenOpacity();
315
 
        break;
316
 
    case ConfigureNotify:
317
 
 
318
 
        if (active != event->xconfigure.window)
319
 
            break;
320
 
 
321
 
        clearPassive ();
322
 
        if (active)
323
 
        {
324
 
            CompWindow *w;
325
 
 
326
 
            w = screen->findWindow (active);
327
 
            if (w)
328
 
                passiveWindows (w->region ());
329
 
        }
330
 
        break;
331
 
    default:
332
 
        break;
 
297
    switch (event->type)
 
298
    {
 
299
        case EnterNotify:
 
300
            Window id;
 
301
 
 
302
            id        = event->xcrossing.window;
 
303
            newActive = screen->findTopLevelWindow (id);
 
304
 
 
305
            if (timeoutHandle.active ())
 
306
                timeoutHandle.stop ();
 
307
 
 
308
            if (checkDelay ())
 
309
                handleTimeout ();
 
310
            else
 
311
                timeoutHandle.start ();
 
312
 
 
313
            break;
 
314
 
 
315
        case FocusIn:
 
316
            resetScreenOpacity();
 
317
            break;
 
318
 
 
319
        case ConfigureNotify:
 
320
 
 
321
            if (active != event->xconfigure.window)
 
322
                break;
 
323
 
 
324
            clearPassive ();
 
325
 
 
326
            if (active)
 
327
            {
 
328
                CompWindow *w = screen->findWindow (active);
 
329
 
 
330
                if (w)
 
331
                    passiveWindows (w->region ());
 
332
            }
 
333
 
 
334
            break;
 
335
 
 
336
        default:
 
337
            break;
333
338
    }
334
339
}
335
340
 
336
341
/* Toggle opacify on/off. We are in Display-context, make sure we handle all
337
342
 * screens.
338
343
 */
339
 
 
340
344
bool
341
345
OpacifyScreen::toggle (CompAction         *action,
342
346
                       CompAction::State  state,
343
347
                       CompOption::Vector options)
344
348
{
345
349
    isToggle = !isToggle;
 
350
 
346
351
    if (!isToggle && optionGetToggleReset ())
347
 
    {
348
352
        resetScreenOpacity();
349
 
    }
350
353
 
351
354
    setFunctions (isToggle);
352
355
 
359
362
 *  here is 'init_toggle' so when that changes, we adjust our internal values
360
363
 *  appropriately
361
364
 */
362
 
 
363
365
void
364
366
OpacifyScreen::optionChanged (CompOption              *option,
365
367
                              OpacifyOptions::Options num)
366
368
{
367
 
    switch (num) {
368
 
    case OpacifyOptions::InitToggle:
369
 
        isToggle = option->value ().b ();
370
 
        setFunctions (isToggle);
371
 
        resetScreenOpacity();
372
 
        break;
 
369
    switch (num)
 
370
    {
 
371
        case OpacifyOptions::InitToggle:
 
372
            isToggle = option->value ().b ();
 
373
            setFunctions (isToggle);
 
374
            resetScreenOpacity();
 
375
            break;
 
376
 
373
377
        case OpacifyOptions::Timeout:
374
 
        timeoutHandle.setTimes (optionGetTimeout (), optionGetTimeout () * 1.2);
375
 
        break;
376
 
    default:
377
 
        break;
 
378
            timeoutHandle.setTimes (optionGetTimeout (), optionGetTimeout () * 1.2);
 
379
            break;
 
380
 
 
381
        default:
 
382
            break;
378
383
    }
379
384
}
380
385
 
382
387
 *  is created and we set our custom variables to it and also register to
383
388
 *  paint this window
384
389
 */
385
 
 
386
390
OpacifyWindow::OpacifyWindow (CompWindow *window) :
387
391
    PluginClassHandler <OpacifyWindow, CompWindow> (window),
388
 
    window (window),
389
 
    cWindow (CompositeWindow::get (window)),
390
 
    gWindow (GLWindow::get (window)),
 
392
    window    (window),
 
393
    cWindow   (CompositeWindow::get (window)),
 
394
    gWindow   (GLWindow::get (window)),
391
395
    opacified (false),
392
 
    opacity (100)
 
396
    opacity   (100)
393
397
{
394
398
    GLWindowInterface::setHandler (gWindow, false);
395
399
}
398
402
 *  is created and we set our custom variables to it and also register to
399
403
 *  handle X.org events when they come through
400
404
 */
401
 
 
402
405
OpacifyScreen::OpacifyScreen (CompScreen *screen) :
403
406
    PluginClassHandler <OpacifyScreen, CompScreen> (screen),
404
 
    isToggle (true),
 
407
    isToggle  (optionGetInitToggle ()),
405
408
    newActive (NULL),
406
 
    active (screen->activeWindow ()),
 
409
    active    (screen->activeWindow ()),
407
410
    intersect (emptyRegion),
408
411
    justMoved (false)
409
412
{
420
423
    optionSetTimeoutNotify (boost::bind (&OpacifyScreen::optionChanged,
421
424
                                                                 this, _1, _2));
422
425
 
423
 
    setFunctions (optionGetInitToggle ());
 
426
    setFunctions (isToggle);
424
427
}
425
428
 
426
429
bool
427
430
OpacifyPluginVTable::init ()
428
431
{
429
 
    if (!CompPlugin::checkPluginABI ("core", CORE_ABIVERSION))
430
 
        return false;
431
 
    if (!CompPlugin::checkPluginABI ("composite", COMPIZ_COMPOSITE_ABI))
432
 
        return false;
433
 
    if (!CompPlugin::checkPluginABI ("opengl", COMPIZ_OPENGL_ABI))
434
 
        return false;
435
 
 
436
 
 
437
 
    return true;
 
432
    if (CompPlugin::checkPluginABI ("core", CORE_ABIVERSION)            &&
 
433
        CompPlugin::checkPluginABI ("composite", COMPIZ_COMPOSITE_ABI)  &&
 
434
        CompPlugin::checkPluginABI ("opengl", COMPIZ_OPENGL_ABI))
 
435
        return true;
 
436
 
 
437
    return false;
438
438
}