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

« back to all changes in this revision

Viewing changes to plugins/widget/src/widget.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:
36
36
    public CompMatch::Expression
37
37
{
38
38
    public:
 
39
 
39
40
        WidgetExp (const CompString &str);
40
41
 
41
42
        bool evaluate (const CompWindow *w) const;
66
67
    foreach (CompWindow *win, screen->windows ())
67
68
    {
68
69
        WIDGET_WINDOW (win);
 
70
 
69
71
        if (ww->mParentWidget == win)
70
72
            ww->mParentWidget = NULL;
71
73
    }
72
74
 
73
 
    if (window->destroyed ())
74
 
        return;
75
 
 
76
 
    if (!mIsWidget)
 
75
    if (window->destroyed () ||
 
76
        !mIsWidget)
77
77
        return;
78
78
 
79
79
    foreach (CompWindow *win, screen->windows ())
92
92
bool
93
93
WidgetWindow::updateWidgetStatus ()
94
94
{
95
 
    bool isWidget, retval;
 
95
    bool isWidget;
96
96
 
97
97
    WIDGET_SCREEN (screen);
98
98
 
99
 
    switch (mPropertyState) {
 
99
    switch (mPropertyState)
 
100
    {
100
101
    case PropertyWidget:
101
102
        isWidget = true;
102
103
        break;
 
104
 
103
105
    case PropertyNoWidget:
104
106
        isWidget = false;
105
107
        break;
 
108
 
106
109
    default:
107
110
        if (!window->managed () ||
108
111
            (window->wmType () & CompWindowTypeDesktopMask))
109
 
        {
110
112
            isWidget = false;
111
 
        }
112
113
        else
113
 
        {
114
114
            isWidget = ws->optionGetMatch ().evaluate (window);
115
 
        }
 
115
 
116
116
        break;
117
117
    }
118
118
 
119
 
    retval = (!isWidget && mIsWidget) || (isWidget && !mIsWidget);
 
119
    bool retval = (!isWidget && mIsWidget) || (isWidget && !mIsWidget);
120
120
    mIsWidget = isWidget;
121
121
 
122
122
    return retval;
126
126
WidgetWindow::updateWidgetPropertyState ()
127
127
{
128
128
    Atom          retType;
129
 
    int           format, result;
 
129
    int           format;
130
130
    unsigned long nitems, remain;
131
131
    unsigned char *data = NULL;
132
132
 
133
133
    WIDGET_SCREEN (screen);
134
134
 
135
 
    result = XGetWindowProperty (screen->dpy (), window->id (),
136
 
                                 ws->mCompizWidgetAtom, 0, 1L, false,
137
 
                                 AnyPropertyType, &retType,
138
 
                                 &format, &nitems, &remain, &data);
 
135
    int result = XGetWindowProperty (screen->dpy (), window->id (),
 
136
                                     ws->mCompizWidgetAtom, 0, 1L, false,
 
137
                                     AnyPropertyType, &retType,
 
138
                                     &format, &nitems, &remain, &data);
139
139
 
140
140
    if (result == Success && data)
141
141
    {
142
142
        if (nitems && format == 32)
143
143
        {
144
144
            unsigned long int *retData = (unsigned long int *) data;
 
145
 
145
146
            if (*retData)
146
147
                mPropertyState = PropertyWidget;
147
148
            else
189
190
void
190
191
WidgetScreen::setWidgetLayerMapState (bool map)
191
192
{
192
 
    CompWindow   *highest = NULL;
193
 
    unsigned int highestActiveNum = 0;
194
 
    CompWindowList copyWindows = screen->windows ();
 
193
    CompWindow     *highest         = NULL;
 
194
    unsigned int   highestActiveNum = 0;
 
195
    CompWindowList copyWindows      = screen->windows ();
195
196
 
196
197
    /* We have to operate on a copy of the list, since it's possible
197
198
     * for the screen->windows () to be re-ordered by
207
208
 
208
209
        if (window->activeNum () > highestActiveNum)
209
210
        {
210
 
            highest = window;
 
211
            highest          = window;
211
212
            highestActiveNum = window->activeNum ();
212
213
        }
213
214
 
218
219
    {
219
220
        if (!mLastActiveWindow)
220
221
            mLastActiveWindow = screen->activeWindow ();
 
222
 
221
223
        highest->moveInputFocusTo ();
222
224
    }
223
225
    else if (!map)
224
226
    {
225
227
        CompWindow *w = screen->findWindow (mLastActiveWindow);
226
228
        mLastActiveWindow = None;
 
229
 
227
230
        if (w)
228
231
            w->moveInputFocusTo ();
229
232
    }
254
257
WidgetScreen::matchInitExp (const CompString &str)
255
258
{
256
259
    /* Create a new match object */
257
 
 
258
260
    if (str.find ("widget=") == 0)
259
261
        return new WidgetExp (str.substr (7));
260
262
 
271
273
    foreach (CompWindow *w, screen->windows ())
272
274
    {
273
275
        WIDGET_WINDOW (w);
 
276
 
274
277
        if (ww->updateWidgetStatus ())
275
278
        {
276
 
            bool map;
277
 
 
278
 
            map = !ww->mIsWidget || (mState != StateOff);
 
279
            bool map = !ww->mIsWidget || (mState != StateOff);
279
280
            ww->updateWidgetMapState (map);
280
281
 
281
282
            ww->updateTreeStatus ();
290
291
                      CompAction::State  state,
291
292
                      CompOption::Vector &options)
292
293
{
293
 
    switch (mState) {
 
294
    switch (mState)
 
295
    {
294
296
        case StateOn:
295
297
        case StateFadeIn:
296
298
            setWidgetLayerMapState (false);
297
299
            mFadeTime = 1000.0f * optionGetFadeTime ();
298
 
            mState = StateFadeOut;
 
300
            mState    = StateFadeOut;
299
301
            break;
 
302
 
300
303
        case StateOff:
301
304
        case StateFadeOut:
302
305
            setWidgetLayerMapState (true);
303
306
            mFadeTime = 1000.0f * optionGetFadeTime ();
304
 
            mState = StateFadeIn;
 
307
            mState    = StateFadeIn;
305
308
            break;
 
309
 
306
310
        default:
307
311
            break;
308
312
    }
328
332
    if (closedWidget)
329
333
    {
330
334
        /* end widget mode if the closed widget was the last one */
331
 
 
332
335
        WIDGET_WINDOW (closedWidget);
 
336
 
333
337
        if (ww->mIsWidget)
334
338
        {
335
339
            foreach (CompWindow *w, screen->windows ())
336
340
            {
337
341
                WIDGET_WINDOW (w);
 
342
 
338
343
                if (w == closedWidget)
339
344
                    continue;
340
345
 
361
366
 
362
367
    switch (event->type)
363
368
    {
364
 
    case PropertyNotify:
365
 
        if (event->xproperty.atom == mCompizWidgetAtom)
366
 
        {
367
 
            w = screen->findWindow (event->xproperty.window);
368
 
            if (w)
369
 
            {
370
 
                WIDGET_WINDOW (w);
371
 
                if (ww->updateWidgetPropertyState ())
372
 
                {
373
 
                    bool map;
374
 
 
375
 
                    map = !ww->mIsWidget || mState != StateOff;
376
 
                    ww->updateWidgetMapState (map);
377
 
                    ww->updateTreeStatus ();
378
 
                    screen->matchPropertyChanged (w);
379
 
                }
380
 
            }
381
 
        }
382
 
        else if (event->xproperty.atom == Atoms::wmClientLeader)
383
 
        {
384
 
            w = screen->findWindow (event->xproperty.window);
385
 
            if (w)
386
 
            {
387
 
                WIDGET_WINDOW (w);
 
369
        case PropertyNotify:
 
370
            if (event->xproperty.atom == mCompizWidgetAtom)
 
371
            {
 
372
                w = screen->findWindow (event->xproperty.window);
 
373
 
 
374
                if (w)
 
375
                {
 
376
                    WIDGET_WINDOW (w);
 
377
 
 
378
                    if (ww->updateWidgetPropertyState ())
 
379
                    {
 
380
                        bool map = !ww->mIsWidget || mState != StateOff;
 
381
                        ww->updateWidgetMapState (map);
 
382
                        ww->updateTreeStatus ();
 
383
                        screen->matchPropertyChanged (w);
 
384
                    }
 
385
                }
 
386
            }
 
387
            else if (event->xproperty.atom == Atoms::wmClientLeader)
 
388
            {
 
389
                w = screen->findWindow (event->xproperty.window);
 
390
 
 
391
                if (w)
 
392
                {
 
393
                    WIDGET_WINDOW (w);
 
394
 
 
395
                    if (ww->mIsWidget)
 
396
                        ww->updateTreeStatus ();
 
397
                    else if (ww->mParentWidget)
 
398
                    {
 
399
                        WidgetWindow *pww = WidgetWindow::get (ww->mParentWidget);
 
400
                        pww->updateTreeStatus ();
 
401
                    }
 
402
                }
 
403
            }
 
404
 
 
405
            break;
 
406
 
 
407
        case ButtonPress:
 
408
            /* terminate widget mode if a non-widget window was clicked */
 
409
            if (optionGetEndOnClick () &&
 
410
                event->xbutton.button == Button1)
 
411
            {
 
412
                if (mState == StateOn)
 
413
                {
 
414
                    w = screen->findWindow (event->xbutton.window);
 
415
 
 
416
                    if (w && w->managed ())
 
417
                    {
 
418
                        WIDGET_WINDOW (w);
 
419
 
 
420
                        if (!ww->mIsWidget && !ww->mParentWidget)
 
421
                            endWidgetMode (NULL);
 
422
                    }
 
423
                }
 
424
            }
 
425
 
 
426
            break;
 
427
 
 
428
        case MapNotify:
 
429
            w = screen->findWindow (event->xmap.window);
 
430
 
 
431
            if (w)
 
432
            {
 
433
                WIDGET_WINDOW (w);
 
434
 
 
435
                ww->updateWidgetStatus ();
388
436
 
389
437
                if (ww->mIsWidget)
390
 
                    ww->updateTreeStatus ();
391
 
                else if (ww->mParentWidget)
392
 
                {
393
 
                    WidgetWindow *pww = WidgetWindow::get (ww->mParentWidget);
394
 
                    pww->updateTreeStatus ();
395
 
                }
396
 
            }
397
 
        }
398
 
        break;
399
 
    case ButtonPress:
400
 
        /* terminate widget mode if a non-widget window was clicked */
401
 
        if (optionGetEndOnClick () &&
402
 
            event->xbutton.button == Button1)
403
 
        {
404
 
            if (mState == StateOn)
405
 
            {
406
 
                w = screen->findWindow (event->xbutton.window);
407
 
                if (w && w->managed ())
408
 
                {
409
 
                    WIDGET_WINDOW (w);
410
 
 
411
 
                    if (!ww->mIsWidget && !ww->mParentWidget)
412
 
                        endWidgetMode (NULL);
413
 
                }
414
 
            }
415
 
        }
416
 
        break;
417
 
    case MapNotify:
418
 
        w = screen->findWindow (event->xmap.window);
419
 
        if (w)
420
 
        {
421
 
            WIDGET_WINDOW (w);
422
 
 
423
 
            ww->updateWidgetStatus ();
424
 
            if (ww->mIsWidget)
425
 
                ww->updateWidgetMapState (mState != StateOff);
426
 
        }
427
 
        break;
428
 
    case UnmapNotify:
429
 
        w = screen->findWindow (event->xunmap.window);
430
 
        if (w)
431
 
        {
432
 
            WIDGET_WINDOW (w);
433
 
            ww->updateTreeStatus ();
434
 
            endWidgetMode (w);
435
 
        }
436
 
        break;
437
 
    case DestroyNotify:
438
 
        w = screen->findWindow (event->xdestroywindow.window);
439
 
        if (w)
440
 
        {
441
 
            WIDGET_WINDOW (w);
442
 
            ww->updateTreeStatus ();
443
 
            endWidgetMode (w);
444
 
        }
445
 
        break;
 
438
                    ww->updateWidgetMapState (mState != StateOff);
 
439
            }
 
440
 
 
441
            break;
 
442
 
 
443
        case UnmapNotify:
 
444
            w = screen->findWindow (event->xunmap.window);
 
445
 
 
446
            if (w)
 
447
            {
 
448
                WIDGET_WINDOW (w);
 
449
                ww->updateTreeStatus ();
 
450
                endWidgetMode (w);
 
451
            }
 
452
 
 
453
            break;
 
454
 
 
455
        case DestroyNotify:
 
456
            w = screen->findWindow (event->xdestroywindow.window);
 
457
 
 
458
            if (w)
 
459
            {
 
460
                WIDGET_WINDOW (w);
 
461
                ww->updateTreeStatus ();
 
462
                endWidgetMode (w);
 
463
            }
 
464
 
 
465
            break;
 
466
 
 
467
        default:
 
468
            break;
446
469
    }
447
470
}
448
471
 
464
487
bool
465
488
WidgetScreen::updateStatus (CompWindow *w)
466
489
{
467
 
    Window clientLeader;
468
 
 
469
490
    WIDGET_WINDOW (w);
470
491
 
471
492
    if (ww->updateWidgetPropertyState ())
472
493
        ww->updateWidgetMapState (mState != StateOff);
473
494
 
474
 
    clientLeader = w->clientLeader (true);
 
495
    Window clientLeader = w->clientLeader (true);
475
496
 
476
497
    if (ww->mIsWidget)
477
 
    {
478
498
        ww->updateTreeStatus ();
479
 
    }
480
499
    else if (clientLeader)
481
500
    {
482
 
        CompWindow *lw;
 
501
        CompWindow *lw = screen->findWindow (clientLeader);
483
502
 
484
 
        lw = screen->findWindow (clientLeader);
485
503
        if (lw)
486
504
        {
487
 
            WidgetWindow *lww;
488
 
            lww = WidgetWindow::get (lw);
 
505
            WidgetWindow *lww = WidgetWindow::get (lw);
489
506
 
490
507
            if (lww->mIsWidget)
491
508
                ww->mParentWidget = lw;
498
515
}
499
516
 
500
517
void
501
 
WidgetScreen::matchPropertyChanged (CompWindow  *w)
 
518
WidgetScreen::matchPropertyChanged (CompWindow *w)
502
519
{
503
520
    WIDGET_WINDOW (w);
504
521
 
518
535
                       const CompRegion          &region,
519
536
                       unsigned int              mask)
520
537
{
521
 
    bool       status;
 
538
    bool status;
522
539
 
523
540
    WIDGET_SCREEN (screen);
524
541
 
532
549
        else
533
550
        {
534
551
            fadeProgress = ws->optionGetFadeTime ();
 
552
 
535
553
            if (fadeProgress)
536
554
                fadeProgress = (float) ws->mFadeTime / (1000.0f * fadeProgress);
 
555
 
537
556
            fadeProgress = 1.0f - fadeProgress;
538
557
        }
539
558
 
540
559
        if (!mIsWidget && !mParentWidget)
541
560
        {
542
 
            float progress;
543
 
 
544
561
            if (ws->mState == WidgetScreen::StateFadeIn ||
545
562
                ws->mState == WidgetScreen::StateOn)
546
 
            {
547
563
                fadeProgress = 1.0f - fadeProgress;
548
 
            }
549
564
 
550
 
            progress = ws->optionGetBgSaturation () / 100.0f;
551
 
            progress += (1.0f - progress) * fadeProgress;
 
565
            float progress     = ws->optionGetBgSaturation () / 100.0f;
 
566
            progress          += (1.0f - progress) * fadeProgress;
552
567
            wAttrib.saturation = (float) wAttrib.saturation * progress;
553
568
 
554
 
            progress = ws->optionGetBgBrightness () / 100.0f;
555
 
            progress += (1.0f - progress) * fadeProgress;
 
569
            progress           = ws->optionGetBgBrightness () / 100.0f;
 
570
            progress          += (1.0f - progress) * fadeProgress;
556
571
 
557
572
            wAttrib.brightness = (float) wAttrib.brightness * progress;
558
573
        }
560
575
        status = gWindow->glPaint (wAttrib, transform, region, mask);
561
576
    }
562
577
    else
563
 
    {
564
578
        status = gWindow->glPaint (attrib, transform, region, mask);
565
 
    }
566
579
 
567
580
    return status;
568
581
}
623
636
}
624
637
 
625
638
void
626
 
WidgetScreen::optionChanged (CompOption              *option,
627
 
                             WidgetOptions::Options  num)
 
639
WidgetScreen::optionChanged (CompOption             *option,
 
640
                             WidgetOptions::Options num)
628
641
{
629
642
    switch (num)
630
643
    {
636
649
 
637
650
                if (ww->updateWidgetStatus ())
638
651
                {
639
 
                    bool map;
640
 
 
641
 
                    map = !ww->mIsWidget || mState != StateOff;
 
652
                    bool map = !ww->mIsWidget || mState != StateOff;
642
653
                    ww->updateWidgetMapState (map);
643
654
 
644
655
                    ww->updateTreeStatus ();
647
658
            }
648
659
        }
649
660
        break;
 
661
 
650
662
    default:
651
663
        break;
652
664
    }
656
668
 
657
669
WidgetScreen::WidgetScreen (CompScreen *screen) :
658
670
    PluginClassHandler <WidgetScreen, CompScreen> (screen),
659
 
    cScreen (CompositeScreen::get (screen)),
 
671
    cScreen           (CompositeScreen::get (screen)),
660
672
    mLastActiveWindow (None),
661
673
    mCompizWidgetAtom (XInternAtom (screen->dpy (), "_COMPIZ_WIDGET", false)),
662
 
    mFadeTime (0),
663
 
    mGrabIndex (0),
664
 
    mCursor (XCreateFontCursor (screen->dpy (), XC_watch))
 
674
    mFadeTime         (0),
 
675
    mGrabIndex        (0),
 
676
    mCursor           (XCreateFontCursor (screen->dpy (), XC_watch))
665
677
{
666
678
    CompAction::CallBack cb;
667
679
    ChangeNotify         notify;
701
713
 
702
714
WidgetWindow::WidgetWindow (CompWindow *window) :
703
715
    PluginClassHandler <WidgetWindow, CompWindow> (window),
704
 
    window (window),
705
 
    gWindow (GLWindow::get (window)),
706
 
    mIsWidget (false),
707
 
    mWasHidden (false),
708
 
    mParentWidget (NULL),
 
716
    window         (window),
 
717
    gWindow        (GLWindow::get (window)),
 
718
    mIsWidget      (false),
 
719
    mWasHidden     (false),
 
720
    mParentWidget  (NULL),
709
721
    mPropertyState (PropertyNotSet)
710
722
{
711
723
    WindowInterface::setHandler (window);
730
742
bool
731
743
WidgetPluginVTable::init ()
732
744
{
733
 
    if (!CompPlugin::checkPluginABI ("core", CORE_ABIVERSION))
734
 
        return false;
735
 
    if (!CompPlugin::checkPluginABI ("composite", COMPIZ_COMPOSITE_ABI))
736
 
        return false;
737
 
    if (!CompPlugin::checkPluginABI ("opengl", COMPIZ_OPENGL_ABI))
738
 
        return false;
 
745
    if (CompPlugin::checkPluginABI ("core", CORE_ABIVERSION)            &&
 
746
        CompPlugin::checkPluginABI ("composite", COMPIZ_COMPOSITE_ABI)  &&
 
747
        CompPlugin::checkPluginABI ("opengl", COMPIZ_OPENGL_ABI))
 
748
        return true;
739
749
 
740
 
    return true;
 
750
    return false;
741
751
}