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

« back to all changes in this revision

Viewing changes to plugins/fade/src/fade.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:
37
37
    {
38
38
        foreach (CompWindow *w, screen->windows ())
39
39
        {
40
 
            if (w->destroyed ())
41
 
                continue;
42
 
 
43
 
            if (!w->isViewable ())
 
40
            if (w->destroyed () ||
 
41
                !w->isViewable ())
44
42
                continue;
45
43
 
46
44
            FadeWindow::get (w)->dim (false);
67
65
    if (event->type == PropertyNotify &&
68
66
        event->xproperty.atom == Atoms::winState)
69
67
    {
70
 
        CompWindow *w;
71
 
        w = screen->findWindow (event->xproperty.window);
 
68
        CompWindow *w = screen->findWindow (event->xproperty.window);
 
69
 
72
70
        if (w && w->isViewable ())
73
71
        {
74
72
            if (w->state () & CompWindowStateDisplayModalMask)
106
104
void
107
105
FadeWindow::addDisplayModal ()
108
106
{
109
 
    if (!(window->state () & CompWindowStateDisplayModalMask))
110
 
        return;
111
 
 
112
 
    if (dModal)
 
107
    if (!(window->state () & CompWindowStateDisplayModalMask) ||
 
108
        dModal)
113
109
        return;
114
110
 
115
111
    dModal = true;
116
112
 
117
 
    fScreen->displayModals++;
 
113
    ++fScreen->displayModals;
 
114
 
118
115
    if (fScreen->displayModals == 1)
119
116
        fScreen->cScreen->damageScreen ();
120
117
}
127
124
 
128
125
    dModal = false;
129
126
 
130
 
    fScreen->displayModals--;
 
127
    --fScreen->displayModals;
 
128
 
131
129
    if (fScreen->displayModals == 0)
132
130
        fScreen->cScreen->damageScreen ();
133
131
}
148
146
        {
149
147
            steps     = 1;
150
148
            fadeTime -= msSinceLastPaint;
 
149
 
151
150
            if (fadeTime < 0)
152
151
                fadeTime = 0;
153
152
        }
154
153
        else
155
 
        {
156
154
            steps = 0;
157
 
        }
158
155
    }
159
156
}
160
157
 
168
165
}
169
166
 
170
167
bool
171
 
FadeWindow::glPaint (const GLWindowPaintAttrib& attrib,
172
 
                     const GLMatrix&            transform,
173
 
                     const CompRegion&          region,
174
 
                     unsigned int               mask)
 
168
FadeWindow::glPaint (const GLWindowPaintAttrib &attrib,
 
169
                     const GLMatrix            &transform,
 
170
                     const CompRegion          &region,
 
171
                     unsigned int              mask)
175
172
{
176
173
    if (!GL::canDoSlightlySaturated)
177
174
        saturation = attrib.saturation;
181
178
        brightness == attrib.brightness &&
182
179
        saturation == attrib.saturation &&
183
180
        !fScreen->displayModals)
184
 
    {
185
181
        return gWindow->glPaint (attrib, transform, region, mask);
186
 
    }
187
182
 
188
183
    GLWindowPaintAttrib fAttrib (attrib);
189
 
    int                 mode;
190
184
 
191
 
    mode = fScreen->optionGetFadeMode ();
 
185
    int mode = fScreen->optionGetFadeMode ();
192
186
 
193
187
    if (!window->alive () &&
194
188
        fScreen->optionGetDimUnresponsive ())
195
189
    {
196
 
        GLuint value;
 
190
        GLuint value = fScreen->optionGetUnresponsiveBrightness ();
197
191
 
198
 
        value = fScreen->optionGetUnresponsiveBrightness ();
199
192
        if (value != 100)
200
193
            fAttrib.brightness = fAttrib.brightness * value / 100;
201
194
 
202
 
        value = fScreen->optionGetUnresponsiveSaturation ();
 
195
        value        = fScreen->optionGetUnresponsiveSaturation ();
 
196
 
203
197
        if (value != 100 && GL::canDoSlightlySaturated)
204
198
            fAttrib.saturation = fAttrib.saturation * value / 100;
205
199
    }
209
203
        fAttrib.saturation = 0;
210
204
    }
211
205
 
212
 
    if (mode == FadeOptions::FadeModeConstantTime)
 
206
    if (mode == FadeOptions::FadeModeConstantTime   &&
 
207
        (fAttrib.opacity    != targetOpacity    ||
 
208
         fAttrib.brightness != targetBrightness ||
 
209
         fAttrib.saturation != targetSaturation))
213
210
    {
214
 
        if (fAttrib.opacity    != targetOpacity    ||
215
 
            fAttrib.brightness != targetBrightness ||
216
 
            fAttrib.saturation != targetSaturation)
217
 
        {
218
 
            fadeTime = fScreen->optionGetFadeTime ();
219
 
            steps    = 1;
220
 
 
221
 
            opacityDiff    = fAttrib.opacity - opacity;
222
 
            brightnessDiff = fAttrib.brightness - brightness;
223
 
            saturationDiff = fAttrib.saturation - saturation;
224
 
 
225
 
            targetOpacity    = fAttrib.opacity;
226
 
            targetBrightness = fAttrib.brightness;
227
 
            targetSaturation = fAttrib.saturation;
228
 
        }
 
211
        fadeTime = fScreen->optionGetFadeTime ();
 
212
        steps    = 1;
 
213
 
 
214
        opacityDiff    = fAttrib.opacity    - opacity;
 
215
        brightnessDiff = fAttrib.brightness - brightness;
 
216
        saturationDiff = fAttrib.saturation - saturation;
 
217
 
 
218
        targetOpacity    = fAttrib.opacity;
 
219
        targetBrightness = fAttrib.brightness;
 
220
        targetSaturation = fAttrib.saturation;
229
221
    }
230
222
 
231
223
    if (steps)
232
224
    {
233
 
        GLint newOpacity = OPAQUE;
 
225
        GLint newOpacity    = OPAQUE;
234
226
        GLint newBrightness = BRIGHT;
235
227
        GLint newSaturation = COLOR;
236
228
 
237
229
        if (mode == FadeOptions::FadeModeConstantSpeed)
238
230
        {
239
231
            newOpacity = opacity;
 
232
 
240
233
            if (fAttrib.opacity > opacity)
241
234
                newOpacity = MIN (opacity + steps, fAttrib.opacity);
242
235
            else if (fAttrib.opacity < opacity)
243
236
                newOpacity = MAX (opacity - steps, fAttrib.opacity);
244
237
 
245
238
            newBrightness = brightness;
 
239
 
246
240
            if (fAttrib.brightness > brightness)
247
 
                newBrightness = MIN (brightness + (steps / 12),
248
 
                                     fAttrib.brightness);
 
241
                newBrightness = MIN (brightness + (steps / 12), fAttrib.brightness);
249
242
            else if (fAttrib.brightness < brightness)
250
 
                newBrightness = MAX (brightness - (steps / 12),
251
 
                                     fAttrib.brightness);
 
243
                newBrightness = MAX (brightness - (steps / 12), fAttrib.brightness);
252
244
 
253
245
            newSaturation = saturation;
 
246
 
254
247
            if (fAttrib.saturation > saturation)
255
 
                saturation = MIN (saturation + (steps / 6),
256
 
                                  fAttrib.saturation);
 
248
                newSaturation = MIN (saturation + (steps / 6), fAttrib.saturation);
257
249
            else if (fAttrib.saturation < saturation)
258
 
                saturation = MAX (saturation - (steps / 6),
259
 
                                  fAttrib.saturation);
 
250
                newSaturation = MAX (saturation - (steps / 6), fAttrib.saturation);
260
251
        }
261
252
        else if (mode == FadeOptions::FadeModeConstantTime)
262
253
        {
265
256
            if (totalFadeTime == 0)
266
257
                totalFadeTime = fadeTime;
267
258
 
268
 
            newOpacity = fAttrib.opacity -
269
 
                            (opacityDiff * fadeTime / totalFadeTime);
 
259
            newOpacity    = fAttrib.opacity -
 
260
                            (opacityDiff    * fadeTime / totalFadeTime);
270
261
            newBrightness = fAttrib.brightness -
271
 
                            (brightnessDiff * fadeTime / totalFadeTime);
 
262
                            (brightnessDiff * fadeTime / totalFadeTime);
272
263
            newSaturation = fAttrib.saturation -
273
 
                            (saturationDiff * fadeTime / totalFadeTime);
 
264
                            (saturationDiff * fadeTime / totalFadeTime);
274
265
        }
275
266
 
276
267
        steps = 0;
284
275
            if (newOpacity    != fAttrib.opacity    ||
285
276
                newBrightness != fAttrib.brightness ||
286
277
                newSaturation != fAttrib.saturation)
287
 
            {
288
278
                cWindow->addDamage ();
289
 
            }
290
279
        }
291
280
        else
292
 
        {
293
281
            opacity = 0;
294
 
        }
295
282
    }
296
283
 
297
284
    fAttrib.opacity    = opacity;
325
312
    if (!rv || !CompOption::findOption (getOptions (), name, &index))
326
313
        return false;
327
314
 
328
 
    switch (index) {
 
315
    switch (index)
 
316
    {
329
317
        case FadeOptions::FadeSpeed:
330
 
                fadeTime = 1000.0f / optionGetFadeSpeed ();
 
318
            fadeTime = 1000.0f / optionGetFadeSpeed ();
331
319
            break;
 
320
 
332
321
        case FadeOptions::WindowMatch:
333
322
            cScreen->damageScreen ();
334
323
            break;
 
324
 
335
325
        case FadeOptions::DimUnresponsive:
336
326
            foreach (CompWindow *w, screen->windows ())
337
327
                w->windowNotifySetEnabled (FadeWindow::get (w), optionGetDimUnresponsive ());
 
328
 
338
329
            break;
 
330
 
339
331
        default:
340
332
            break;
341
333
    }
345
337
 
346
338
FadeWindow::FadeWindow (CompWindow *w) :
347
339
    PluginClassHandler<FadeWindow, CompWindow> (w),
348
 
    fScreen (FadeScreen::get (screen)),
349
 
    window (w),
350
 
    cWindow (CompositeWindow::get (w)),
351
 
    gWindow (GLWindow::get (w)),
352
 
    opacity (cWindow->opacity ()),
353
 
    brightness (cWindow->brightness ()),
354
 
    saturation (cWindow->saturation ()),
355
 
    targetOpacity (opacity),
 
340
    fScreen          (FadeScreen::get (screen)),
 
341
    window           (w),
 
342
    cWindow          (CompositeWindow::get (w)),
 
343
    gWindow          (GLWindow::get (w)),
 
344
    opacity          (cWindow->opacity ()),
 
345
    brightness       (cWindow->brightness ()),
 
346
    saturation       (cWindow->saturation ()),
 
347
    targetOpacity    (opacity),
356
348
    targetBrightness (brightness),
357
349
    targetSaturation (saturation),
358
 
    dModal (false),
359
 
    steps (0),
360
 
    fadeTime (0),
361
 
    opacityDiff (0),
362
 
    brightnessDiff (0),
363
 
    saturationDiff (0)
 
350
    dModal           (false),
 
351
    steps            (0),
 
352
    fadeTime         (0),
 
353
    opacityDiff      (0),
 
354
    brightnessDiff   (0),
 
355
    saturationDiff   (0)
364
356
{
365
357
    if (window->isViewable ())
366
358
        addDisplayModal ();
380
372
bool
381
373
FadePluginVTable::init ()
382
374
{
383
 
    if (!CompPlugin::checkPluginABI ("core", CORE_ABIVERSION)           |
384
 
        !CompPlugin::checkPluginABI ("composite", COMPIZ_COMPOSITE_ABI) |
385
 
        !CompPlugin::checkPluginABI ("opengl", COMPIZ_OPENGL_ABI))
386
 
    {
387
 
        return false;
388
 
    }
389
 
    return true;
 
375
    if (CompPlugin::checkPluginABI ("core", CORE_ABIVERSION)            &&
 
376
        CompPlugin::checkPluginABI ("composite", COMPIZ_COMPOSITE_ABI)  &&
 
377
        CompPlugin::checkPluginABI ("opengl", COMPIZ_OPENGL_ABI))
 
378
        return true;
 
379
 
 
380
    return false;
390
381
}