summaryrefslogtreecommitdiff
path: root/src/mcompositewindow.cpp
blob: 78bbab384ab5cf91b0e1197fa7ec68cdc4b65b19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
/***************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (directui@nokia.com)
**
** This file is part of mcompositor.
**
** If you have questions regarding the use of this file, please contact
** Nokia at directui@nokia.com.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation
** and appearing in the file LICENSE.LGPL included in the packaging
** of this file.
**
****************************************************************************/

#include "mcompositewindow.h"
#include "mcompwindowanimator.h"
#include "mcompositemanager.h"
#include "mcompositemanager_p.h"
#include "mtexturepixmapitem.h"
#include "mdecoratorframe.h"
#include "mcompositemanagerextension.h"

#include <QX11Info>
#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
#include <X11/Xatom.h>

int MCompositeWindow::window_transitioning = 0;

static QRectF fadeRect = QRectF();

MCompositeWindow::MCompositeWindow(Qt::HANDLE window, 
                                   MWindowPropertyCache *mpc, 
                                   QGraphicsItem *p)
    : QGraphicsItem(p),
      pc(mpc),
      scalefrom(1),
      scaleto(1),
      scaled(false),
      zval(1),
      blur(false),
      iconified(false),
      iconified_final(false),
      iconify_state(NoIconifyState),
      destroyed(false),
      window_status(Normal),
      need_decor(false),
      window_obscured(-1),
      is_transitioning(false),
      pinging_enabled(false),
      dimmed_effect(false),
      waiting_for_damage(0),
      win_id(window)
{
    thumb_mode = false;
    if (!mpc || (mpc && !mpc->is_valid)) {
        is_valid = false;
        anim = 0;
        newly_mapped = false;
        sent_ping_timestamp = 0;
        received_ping_timestamp = 0;
        t_ping = 0;
        window_visible = false;
        return;
    } else
        is_valid = true;
    anim = new MCompWindowAnimator(this);
    connect(anim, SIGNAL(transitionDone()),  SLOT(finalizeState()));
    connect(anim, SIGNAL(transitionStart()), SLOT(beginAnimation()));
    connect(mpc, SIGNAL(iconGeometryUpdated()), SLOT(updateIconGeometry()));
    setAcceptHoverEvents(true);

    t_ping = new QTimer(this);
    connect(t_ping, SIGNAL(timeout()), SLOT(pingTimeout()));

    damage_timer = new QTimer(this);
    damage_timer->setSingleShot(true);
    connect(damage_timer, SIGNAL(timeout()), SLOT(damageTimeout()));
    
    MCompAtoms* atoms = MCompAtoms::instance(); 
    if (pc->windowType() == MCompAtoms::NORMAL)
        pc->setWindowTypeAtom(ATOM(_NET_WM_WINDOW_TYPE_NORMAL));
    else
        pc->setWindowTypeAtom(atoms->getType(window));

    // needed before calling isAppWindow()
    QVector<Atom> states = atoms->getAtomArray(window, ATOM(_NET_WM_STATE));
    pc->setNetWmState(states.toList());

    // Newly-mapped non-decorated application windows are not initially 
    // visible to prevent flickering when animation is started.
    // We initially prevent item visibility from compositor itself
    // or it's corresponding thumbnail rendered by the switcher
    bool is_app = isAppWindow();
    newly_mapped = is_app;
    if (!pc->isInputOnly()) {
        // never paint InputOnly windows
        window_visible = !is_app;
        setVisible(window_visible); // newly_mapped used here
    }
    origPosition = QPointF(pc->realGeometry().x(), pc->realGeometry().y());

    if (fadeRect.isEmpty()) {
        QRectF d = QApplication::desktop()->availableGeometry();
        fadeRect.setWidth(d.width()/2);
        fadeRect.setHeight(d.height()/2);
        fadeRect.moveTo(fadeRect.width()/2, fadeRect.height()/2);
    }
}

MCompositeWindow::~MCompositeWindow()
{
    MCompositeManager *p = (MCompositeManager *) qApp;
    p->d->removeWindow(window());

    if (t_ping) {
        stopPing();
        t_ping = 0;
    }
    endAnimation();
    
    anim = 0;
    
    if (pc) {
        p->d->prop_caches.remove(window());
        pc->deleteLater();
    }    
}

void MCompositeWindow::setBlurred(bool b)
{
    blur = b;
    update();
}

bool MCompositeWindow::blurred()
{
    return blur;
}

void MCompositeWindow::saveState()
{
    anim->saveState();
}

void MCompositeWindow::localSaveState()
{
    anim->localSaveState();
}

// set the scale point to actual values
void MCompositeWindow::setScalePoint(qreal from, qreal to)
{
    scalefrom = from;
    scaleto = to;
}

void MCompositeWindow::setThumbMode(bool mode)
{
    thumb_mode = mode;
}

/* This is a delayed animation. Actual animation is triggered
 * when startTransition() is called
 */
void MCompositeWindow::iconify(const QRectF &icongeometry, bool defer)
{
    if (iconify_state == ManualIconifyState) {
        setIconified(true);
        return;
    }

    if (window_status != MCompositeWindow::Closing)
        window_status = MCompositeWindow::Minimizing;
    
    // Custom iconify handler
    MCompositeManager *p = (MCompositeManager *) qApp;
    QList<MCompositeManagerExtension*> evlist = p->d->m_extensions.values(MapNotify);
    for (int i = 0; i < evlist.size(); ++i) { 
        if (evlist[i]->windowIconified(this, defer)) {
            iconified = true;
            return;
        }
    }
    
    this->iconGeometry = icongeometry;
    if (!iconified)
        origPosition = pos();

    // horizontal and vert. scaling factors
    qreal sx = iconGeometry.width() / boundingRect().width();
    qreal sy = iconGeometry.height() / boundingRect().height();
    
    anim->deferAnimation(defer);
    anim->translateScale(qreal(1.0), qreal(1.0), sx, sy,
                         iconGeometry.topLeft());
    iconified = true;
    // do this to avoid stacking code disturbing Z values
    beginAnimation();
}

void MCompositeWindow::setUntransformed()
{
    endAnimation();
    
    if (anim)
        anim->stopAnimation(); // stop and restore the matrix
    newly_mapped = false;
    setVisible(true);
    setOpacity(1.0);
    setScale(1.0);
    setScaled(false);
    iconified = false;
}

void MCompositeWindow::setIconified(bool iconified)
{
    iconified_final = iconified;
    iconify_state = ManualIconifyState;
    if (iconified && !anim->pendingAnimation())
        emit itemIconified(this);
    else if (!iconified && !anim->pendingAnimation())
        iconify_state = NoIconifyState;
}

MCompositeWindow::IconifyState MCompositeWindow::iconifyState() const
{
    return iconify_state;
}

void MCompositeWindow::setIconifyState(MCompositeWindow::IconifyState state)
{
    iconify_state = state;
}

void MCompositeWindow::setWindowObscured(bool obscured, bool no_notify)
{
    MCompositeManager *p = (MCompositeManager *) qApp;
    short new_value = obscured ? 1 : 0;
    if ((new_value == window_obscured && !newly_mapped)
        || (!obscured && p->displayOff()))
        return;
    window_obscured = new_value;

    if (!no_notify) {
        XVisibilityEvent c;
        c.type       = VisibilityNotify;
        c.send_event = True;
        c.window     = window();
        c.state      = obscured ? VisibilityFullyObscured :
                                  VisibilityUnobscured;
        XSendEvent(QX11Info::display(), window(), true,
                   VisibilityChangeMask, (XEvent *)&c);
    }
}

/*
 * We ensure that ensure there are ALWAYS updated thumbnails in the 
 * switcher by letting switcher know in advance of the presence of this window.
 * Delay the minimize animation until we receive an iconGeometry update from
 * the switcher
 */
void MCompositeWindow::startTransition()
{
    if (iconified) {
        if (iconGeometry.isNull())
            return;
        setWindowObscured(true);
    }
    if (anim->pendingAnimation()) {
        MCompositeWindow::setVisible(true);
        anim->startAnimation();
        anim->deferAnimation(false);
    }
}

void MCompositeWindow::updateIconGeometry()
{
    if (!pc)
        return;
    
    iconGeometry = pc->iconGeometry();
    if (iconGeometry.isNull())
        return;
    
    // trigger transition the second time around and update animation values
    if (iconified) {
        qreal sx = iconGeometry.width() / boundingRect().width();
        qreal sy = iconGeometry.height() / boundingRect().height();
        anim->translateScale(qreal(1.0), qreal(1.0), sx, sy,
                             iconGeometry.topLeft());
        startTransition();
    }
}

// TODO: have an option of disabling the animation
void MCompositeWindow::restore(const QRectF &icongeometry, bool defer)
{
     // Custom restore handler
    MCompositeManager *p = (MCompositeManager *) qApp;
    QList<MCompositeManagerExtension*> evlist = p->d->m_extensions.values(MapNotify);
    for (int i = 0; i < evlist.size(); ++i) { 
        if (evlist[i]->windowRestored(this, defer)) {
            iconified = false;
            return;
        }
    }

    if (icongeometry.isEmpty())
        this->iconGeometry = fadeRect;
    else
        this->iconGeometry = icongeometry;
    setPos(iconGeometry.topLeft());
    // horizontal and vert. scaling factors
    qreal sx = iconGeometry.width() / boundingRect().width();
    qreal sy = iconGeometry.height() / boundingRect().height();

    setVisible(true);

    anim->deferAnimation(defer);
    anim->translateScale(qreal(1.0), qreal(1.0), sx, sy, origPosition, true);
    iconified = false;
    // do this to avoid stacking code disturbing Z values
    beginAnimation();
}

bool MCompositeWindow::showWindow()
{
    // defer putting this window in the _NET_CLIENT_LIST
    // only after animation is done to prevent the switcher from rendering it
    if (!isAppWindow())
        return false;
    
    findBehindWindow();
    beginAnimation();
    if (newly_mapped) {
        // NB#180628 - some stupid apps are listening for visibilitynotifies.
        // Well, all of the toolkit anyways
        setWindowObscured(false);
        // waiting for two damage events seems to work for Meegotouch apps
        // at least, for the rest, there is a timeout
        waiting_for_damage = 2;
        damage_timer->start(500);
    } else
        q_fadeIn();
    return true;
}

void MCompositeWindow::damageTimeout()
{
    damageReceived(true);
}

void MCompositeWindow::damageReceived(bool timeout)
{
    if (timeout || (waiting_for_damage > 0 && !--waiting_for_damage)) {
        damage_timer->stop();
        waiting_for_damage = 0;
        q_fadeIn();
    }
}

void MCompositeWindow::q_fadeIn()
{   
    endAnimation();
    
    newly_mapped = false;
    setVisible(true);
    setOpacity(0.0);
    updateWindowPixmap();
    origPosition = pos();
    newly_mapped = true;
    
    // Custom fade-in handler
    MCompositeManager *p = (MCompositeManager *) qApp;
    QList<MCompositeManagerExtension*> evlist = p->d->m_extensions.values(MapNotify);
    for (int i = 0; i < evlist.size(); ++i) { 
        if (evlist[i]->windowShown(this)) 
            return;
    }
    
    setPos(fadeRect.topLeft());
    restore(fadeRect, false);
}

void MCompositeWindow::closeWindow()
{
    if (!isAppWindow() || propertyCache()->windowState() == IconicState) {
        setVisible(false);
        emit windowClosed(this);
        return;
    }
    if (window_status == MCompositeWindow::Hung) {
        hide();
        emit windowClosed(this);
        return;
    }
    window_status = MCompositeWindow::Closing;
    
    MCompositeManager *p = (MCompositeManager *) qApp;
    bool defer = false;
    setVisible(true);
    if (!p->isCompositing()) {
        p->d->enableCompositing(true);
        defer = true;
    }
    
    updateWindowPixmap();
    origPosition = pos();
    
    // Custom close window animation handler    
    QList<MCompositeManagerExtension*> evlist = p->d->m_extensions.values(MapNotify);
    for (int i = 0; i < evlist.size(); ++i) { 
        if (evlist[i]->windowClosed(this)) {
            return;
        }
    }
    iconify(fadeRect, defer);
}

bool MCompositeWindow::event(QEvent *e)
{
    if (e->type() == QEvent::DeferredDelete && is_transitioning) {
        // Can't delete the object yet, try again in the next iteration.
        deleteLater();
        return true;
    } else
        return QObject::event(e);
}

void MCompositeWindow::prettyDestroy()
{
    setVisible(true);
    destroyed = true;
    iconify();
}

void MCompositeWindow::finalizeState()
{
    endAnimation();

    if (pc && pc->windowTypeAtom() == ATOM(_NET_WM_WINDOW_TYPE_DESKTOP))
        emit desktopActivated(this);

    // iconification status
    if (iconified) {
        iconified = false;
        iconified_final = true;
        hide();
        iconify_state = TransitionIconifyState;
        emit itemIconified(this);
        if (isClosing()) {
            emit windowClosed(this);
            return;
        }
    } else {
        iconify_state = NoIconifyState;
        iconified_final = false;
        show();
        // no delay: window does not need to be repainted when restoring
        // from the switcher (even then the animation should take long enough
        // to allow it)
        q_itemRestored();
    }
    window_status = Normal;
    
    // item lifetime
    if (destroyed)
        deleteLater();
}

void MCompositeWindow::q_itemRestored()
{
    emit itemRestored(this);
}

void MCompositeWindow::requestZValue(int zvalue)
{
    // when animating, Z-value is set again after finishing the animation
    // (setting it later in finalizeState() caused flickering)
    if (anim && !anim->isActive() && !anim->pendingAnimation())
        setZValue(zvalue);
}

bool MCompositeWindow::isIconified() const
{
    if (anim->isActive())
        return false;

    return iconified_final;
}
bool MCompositeWindow::isScaled() const
{
    return scaled;
}
void MCompositeWindow::setScaled(bool s)
{
    scaled = s;
}

void MCompositeWindow::hoverEnterEvent(QGraphicsSceneHoverEvent *e)
{
    if (thumb_mode) {
        zval = zValue();
        setZValue(scene()->items().count() + 1);
        setZValue(100);
        anim->translateScale(scalefrom, scalefrom, scaleto, scaleto, pos());

    }
    return QGraphicsItem::hoverEnterEvent(e);
}

void MCompositeWindow::hoverLeaveEvent(QGraphicsSceneHoverEvent   *e)
{
    if (thumb_mode) {
        setZValue(zval);
        anim->translateScale(scalefrom, scalefrom, scaleto, scaleto, pos(), true);
    }
    return QGraphicsItem::hoverLeaveEvent(e);
}

void MCompositeWindow::mouseReleaseEvent(QGraphicsSceneMouseEvent *m)
{
    anim->restore();
    setThumbMode(false);
    setScaled(false);
    setZValue(100);

    emit acceptingInput();
    windowRaised();
    QGraphicsItem::mouseReleaseEvent(m);
}

void MCompositeWindow::manipulationEnabled(bool isEnabled)
{
    setFlag(QGraphicsItem::ItemIsMovable, isEnabled);
    setFlag(QGraphicsItem::ItemIsSelectable, isEnabled);
}

void MCompositeWindow::setVisible(bool visible)
{
    if ((pc && pc->isInputOnly())
        || (visible && newly_mapped && isAppWindow()) 
        || (!visible && is_transitioning)) 
        return;

    // Set the iconification status as well
    iconified_final = !visible;
    if (visible != window_visible)
        emit visualized(visible);
    window_visible = visible;

    QGraphicsItem::setVisible(visible);
    MCompositeManager *p = (MCompositeManager *) qApp;
    p->d->setWindowDebugProperties(window());

    QGraphicsScene* sc = scene();    
    if (sc && !visible && sc->items().count() == 1)
        clearTexture();
}

void MCompositeWindow::startPing()
{
    if (pinging_enabled || !t_ping)
        // this function can be called repeatedly without extending the timeout
        return;
    // startup: send ping now, otherwise it is sent after timeout
    pinging_enabled = true;
    pingWindow();
    if (t_ping->isActive())
        t_ping->stop();
    // this could be configurable. But will do for now. Most WMs use 5s delay
    t_ping->setSingleShot(false);
    t_ping->setInterval(5000);
    t_ping->start();
}

void MCompositeWindow::stopPing()
{
    pinging_enabled = false;
    if (t_ping)
        t_ping->stop();
}

void MCompositeWindow::receivedPing(ulong serverTimeStamp)
{
    received_ping_timestamp = serverTimeStamp;
    
    if (window_status != Minimizing && window_status != Closing)
        window_status = Normal;
    if (blurred())
        setBlurred(false);
}

void MCompositeWindow::pingTimeout()
{
    if (pinging_enabled && received_ping_timestamp < sent_ping_timestamp
        && window_status != Hung
        && window_status != Minimizing && window_status != Closing) {
        setBlurred(true);
        window_status = Hung;
        emit windowHung(this);
    }
    if (pinging_enabled)
        // interval timer is still active
        pingWindow();
}

void MCompositeWindow::pingWindow()
{
    ulong t = QDateTime::currentDateTime().toTime_t();
    sent_ping_timestamp = t;
    Window w = window();

    XEvent ev;
    memset(&ev, 0, sizeof(ev));
    ev.xclient.type = ClientMessage;
    ev.xclient.window = w;
    ev.xclient.message_type = ATOM(WM_PROTOCOLS);
    ev.xclient.format = 32;
    ev.xclient.data.l[0] = ATOM(_NET_WM_PING);
    ev.xclient.data.l[1] = t;
    ev.xclient.data.l[2] = w;

    XSendEvent(QX11Info::display(), w, False, NoEventMask, &ev);
}

MCompositeWindow::WindowStatus MCompositeWindow::status() const
{
    return window_status;
}

bool MCompositeWindow::needDecoration() const
{
    return need_decor;
}

void MCompositeWindow::setDecorated(bool decorated)
{
    need_decor = decorated;
}

MCompositeWindow *MCompositeWindow::compositeWindow(Qt::HANDLE window)
{
    MCompositeManager *p = (MCompositeManager *) qApp;
    return p->d->windows.value(window, 0);
}

void MCompositeWindow::beginAnimation()
{
    if (!isMapped())
        return;

    if (!is_transitioning) {
        ++window_transitioning;        
        is_transitioning = true;
    }
}

void MCompositeWindow::endAnimation()
{    
    if (is_transitioning) {
        --window_transitioning;
        is_transitioning = false;
    }
}

bool MCompositeWindow::hasTransitioningWindow()
{
    return window_transitioning > 0;
}

QVariant MCompositeWindow::itemChange(GraphicsItemChange change, const QVariant &value)
{
    MCompositeManager *p = (MCompositeManager *) qApp;
    bool zvalChanged = (change == ItemZValueHasChanged);
    if (zvalChanged) {
        findBehindWindow();
        p->d->setWindowDebugProperties(window());
    }
    
    /* disabled to avoid glSwapBuffers call without painting any item (Qt bug)
     * see NB#189519
    if (zvalChanged || change == ItemVisibleHasChanged || change == ItemParentHasChanged)
    {
        p->d->glwidget->update();
    }
    */

    return QGraphicsItem::itemChange(change, value);
}

void MCompositeWindow::findBehindWindow()
{
    MCompositeManager *p = (MCompositeManager *) qApp;
    int behind_i = indexInStack() - 1;
    if (behind_i >= 0 && behind_i < p->d->stacking_list.size()) {
        MCompositeWindow* w = MCompositeWindow::compositeWindow(p->d->stacking_list.at(behind_i));
        if (w->propertyCache()->windowState() == NormalState 
            && w->propertyCache()->isMapped()
            && !w->propertyCache()->isDecorator()) 
            behind_window = w;
        else if (w->propertyCache()->isDecorator() && MDecoratorFrame::instance()->managedClient())
            behind_window = MDecoratorFrame::instance()->managedClient();
        else
            behind_window = MCompositeWindow::compositeWindow(p->d->stack[DESKTOP_LAYER]);
    }
}

void MCompositeWindow::update()
{
    MCompositeManager *p = (MCompositeManager *) qApp;
    p->d->glwidget->update();
}

bool MCompositeWindow::windowVisible() const
{
    return window_visible;
}

bool MCompositeWindow::isAppWindow(bool include_transients)
{
    MCompositeManager *p = (MCompositeManager *) qApp;
    
    if (!include_transients && p->d->getLastVisibleParent(pc))
        return false;
    
    if (pc && !pc->isOverrideRedirect() &&
            (pc->windowTypeAtom() == ATOM(_NET_WM_WINDOW_TYPE_NORMAL) ||
             pc->windowTypeAtom() == ATOM(_KDE_NET_WM_WINDOW_TYPE_OVERRIDE) ||
             /* non-modal, non-transient dialogs behave like applications */
             (pc->windowTypeAtom() == ATOM(_NET_WM_WINDOW_TYPE_DIALOG) &&
              (pc->netWmState().indexOf(ATOM(_NET_WM_STATE_MODAL)) == -1)))
        && !pc->isDecorator())
        return true;
    return false;
}

QPainterPath MCompositeWindow::shape() const
{    
    QPainterPath path;
    const QRegion &shape = propertyCache()->shapeRegion();
    if (QRegion(boundingRect().toRect()).subtracted(shape).isEmpty())
        path.addRect(boundingRect());
    else
        path.addRegion(shape);
    return path;
}

Window MCompositeWindow::lastVisibleParent() const
{
    MCompositeManager *p = (MCompositeManager *) qApp;
    if (pc && pc->is_valid)
        return p->d->getLastVisibleParent(pc);
    else
        return None;
}

int MCompositeWindow::indexInStack() const
{
    MCompositeManager *p = (MCompositeManager *) qApp;
    return p->d->stacking_list.indexOf(window());
}

void MCompositeWindow::setIsMapped(bool mapped) 
{ 
    if (pc) pc->setIsMapped(mapped); 
}

bool MCompositeWindow::isMapped() const 
{
    return pc ? pc->isMapped() : false;
}