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

« back to all changes in this revision

Viewing changes to src/window.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:
52
52
#include <boost/scoped_array.hpp>
53
53
 
54
54
namespace crb = compiz::window::configure_buffers;
55
 
namespace cw = compiz::window;
 
55
namespace cw  = compiz::window;
56
56
 
57
57
template class WrapableInterface<CompWindow, WindowInterface>;
58
58
 
83
83
inline bool
84
84
PrivateWindow::isInvisible() const
85
85
{
86
 
    return attrib.map_state != IsViewable ||
87
 
     attrib.x + geometry.width ()  + output.right  <= 0 ||
88
 
     attrib.y + geometry.height () + output.bottom <= 0 ||
89
 
     attrib.x - output.left >= (int) screen->width () ||
90
 
     attrib.y - output.top >= (int) screen->height ();
 
86
    return attrib.map_state != IsViewable                                           ||
 
87
                               attrib.x + geometry.width ()  + output.right  <= 0   ||
 
88
                               attrib.y + geometry.height () + output.bottom <= 0   ||
 
89
                               attrib.x - output.left >= (int) screen->width ()     ||
 
90
                               attrib.y - output.top  >= (int) screen->height ();
91
91
}
92
92
 
93
93
bool
100
100
            return true;
101
101
 
102
102
        transient = screen->findWindow (transient->priv->transientFor);
 
103
 
103
104
        if (transient)
104
105
            return isAncestorTo (transient, ancestor);
105
106
    }
110
111
void
111
112
PrivateWindow::recalcNormalHints ()
112
113
{
113
 
    int maxSize;
114
 
 
115
114
/* FIXME to max Texture size */
116
 
    maxSize  = MAXSHORT;
117
 
    maxSize -= serverGeometry.border () * 2;
 
115
    int maxSize  = MAXSHORT;
 
116
    maxSize     -= serverGeometry.border () * 2;
118
117
 
119
118
    sizeHints.x      = serverGeometry.x ();
120
119
    sizeHints.y      = serverGeometry.y ();
230
229
void
231
230
PrivateWindow::updateNormalHints ()
232
231
{
233
 
    Status status;
234
232
    long   supplied;
235
 
 
236
 
    status = XGetWMNormalHints (screen->dpy (), priv->id,
237
 
                                &priv->sizeHints, &supplied);
 
233
    Status status = XGetWMNormalHints (screen->dpy (), priv->id,
 
234
                                       &priv->sizeHints, &supplied);
238
235
 
239
236
    if (!status)
240
237
        priv->sizeHints.flags = 0;
245
242
void
246
243
PrivateWindow::updateWmHints ()
247
244
{
248
 
    XWMHints *newHints;
249
 
    long     dFlags = 0;
250
 
    bool     iconChanged = false;
 
245
    long dFlags = 0;
 
246
    bool iconChanged;
251
247
 
252
248
    if (hints)
253
249
        dFlags = hints->flags;
254
250
 
255
251
    inputHint = true;
256
252
 
257
 
    newHints = XGetWMHints (screen->dpy (), id);
 
253
    XWMHints *newHints = XGetWMHints (screen->dpy (), id);
 
254
 
258
255
    if (newHints)
259
256
    {
260
257
        dFlags ^= newHints->flags;
266
263
        {
267
264
            if ((newHints->flags & IconPixmapHint) &&
268
265
                (hints->icon_pixmap != newHints->icon_pixmap))
269
 
            {
270
266
                iconChanged = true;
271
 
            }
272
267
            else if ((newHints->flags & IconMaskHint) &&
273
268
                     (hints->icon_mask != newHints->icon_mask))
274
 
            {
275
269
                iconChanged = true;
276
 
            }
277
270
        }
278
271
    }
279
272
 
291
284
void
292
285
PrivateWindow::updateClassHints ()
293
286
{
294
 
    XClassHint classHint;
295
 
    int        status;
296
 
 
297
287
    if (priv->resName)
298
288
    {
299
289
        free (priv->resName);
306
296
        priv->resClass = NULL;
307
297
    }
308
298
 
309
 
    status = XGetClassHint (screen->dpy (),
310
 
                            priv->id, &classHint);
 
299
    XClassHint classHint;
 
300
    int        status = XGetClassHint (screen->dpy (),
 
301
                                       priv->id, &classHint);
 
302
 
311
303
    if (status)
312
304
    {
313
305
        if (classHint.res_name)
328
320
PrivateWindow::updateTransientHint ()
329
321
{
330
322
    Window transientFor;
331
 
    Status status;
332
323
 
333
324
    priv->transientFor = None;
334
325
 
335
 
    status = XGetTransientForHint (screen->dpy (),
336
 
                                   priv->id, &transientFor);
 
326
    Status status = XGetTransientForHint (screen->dpy (),
 
327
                                          priv->id, &transientFor);
337
328
 
338
329
    if (status)
339
330
    {
340
 
        CompWindow *ancestor;
 
331
        CompWindow *ancestor = screen->findWindow (transientFor);
341
332
 
342
 
        ancestor = screen->findWindow (transientFor);
343
333
        if (!ancestor)
344
334
            return;
345
335
 
355
345
void
356
346
PrivateWindow::updateIconGeometry ()
357
347
{
358
 
    Atom          actual;
359
 
    int           result, format;
 
348
    Atom          actual;
 
349
    int           format;
360
350
    unsigned long n, left;
361
351
    unsigned char *data;
362
352
 
363
353
    priv->iconGeometry.setGeometry (0, 0, 0, 0);
364
354
 
365
 
    result = XGetWindowProperty (screen->dpy (), priv->id,
366
 
                                 Atoms::wmIconGeometry,
367
 
                                 0L, 1024L, False, XA_CARDINAL,
368
 
                                 &actual, &format, &n, &left, &data);
 
355
    int result = XGetWindowProperty (screen->dpy (), priv->id,
 
356
                                     Atoms::wmIconGeometry,
 
357
                                     0L, 1024L, False, XA_CARDINAL,
 
358
                                     &actual, &format, &n, &left, &data);
369
359
 
370
360
    if (result == Success && data)
371
361
    {
389
379
    if (transientFor)
390
380
    {
391
381
        CompWindow *w = screen->findWindow (transientFor);
 
382
 
392
383
        if (w)
393
384
        {
394
385
            if (w->priv->clientLeader)
404
395
Window
405
396
PrivateWindow::getClientLeader ()
406
397
{
407
 
    Atom          actual;
408
 
    int           result, format;
 
398
    Atom          actual;
 
399
    int           format;
409
400
    unsigned long n, left;
410
401
    unsigned char *data;
411
402
 
412
 
    result = XGetWindowProperty (screen->dpy (), priv->id,
413
 
                                 Atoms::wmClientLeader,
414
 
                                 0L, 1L, False, XA_WINDOW, &actual, &format,
415
 
                                 &n, &left, &data);
 
403
    int result = XGetWindowProperty (screen->dpy (), priv->id,
 
404
                                     Atoms::wmClientLeader,
 
405
                                     0L, 1L, False, XA_WINDOW, &actual, &format,
 
406
                                     &n, &left, &data);
416
407
 
417
408
    if (result == Success && data)
418
409
    {
433
424
char *
434
425
PrivateWindow::getStartupId ()
435
426
{
436
 
    Atom          actual;
437
 
    int           result, format;
 
427
    Atom          actual;
 
428
    int           format;
438
429
    unsigned long n, left;
439
430
    unsigned char *data;
440
431
 
441
 
    result = XGetWindowProperty (screen->dpy (), priv->id,
442
 
                                 Atoms::startupId,
443
 
                                 0L, 1024L, False,
444
 
                                 Atoms::utf8String,
445
 
                                 &actual, &format,
446
 
                                 &n, &left, &data);
 
432
    int result = XGetWindowProperty (screen->dpy (), priv->id,
 
433
                                     Atoms::startupId,
 
434
                                     0L, 1024L, False,
 
435
                                     Atoms::utf8String,
 
436
                                     &actual, &format,
 
437
                                     &n, &left, &data);
447
438
 
448
439
    if (result == Success && data)
449
440
    {
451
442
 
452
443
        if (n)
453
444
            id = strdup ((char *) data);
 
445
 
454
446
        XFree ((void *) data);
455
447
 
456
448
        return id;
463
455
PrivateWindow::setFullscreenMonitors (CompFullscreenMonitorSet *monitors)
464
456
{
465
457
    bool         hadFsMonitors = fullscreenMonitorsSet;
466
 
    unsigned int outputs = screen->outputDevs ().size ();
 
458
    unsigned int outputs       = screen->outputDevs ().size ();
467
459
 
468
460
    fullscreenMonitorsSet = false;
469
461
 
470
 
    if (monitors                   &&
471
 
        (unsigned int) monitors->left   < outputs &&
472
 
        (unsigned int) monitors->right  < outputs &&
473
 
        (unsigned int) monitors->top    < outputs &&
 
462
    if (monitors                                    &&
 
463
        (unsigned int) monitors->left   < outputs   &&
 
464
        (unsigned int) monitors->right  < outputs   &&
 
465
        (unsigned int) monitors->top    < outputs   &&
474
466
        (unsigned int) monitors->bottom < outputs)
475
467
    {
476
468
        CompRect fsRect (screen->outputDevs ()[monitors->left].x1 (),
499
491
                         (unsigned char *) data, 4);
500
492
    }
501
493
    else if (hadFsMonitors)
502
 
    {
503
494
        XDeleteProperty (screen->dpy (), id, Atoms::wmFullscreenMonitors);
504
 
    }
505
495
 
506
 
    if (state & CompWindowStateFullscreenMask)
507
 
        if (fullscreenMonitorsSet || hadFsMonitors)
508
 
            window->updateAttributes (CompStackingUpdateModeNone);
 
496
    if (state & CompWindowStateFullscreenMask &&
 
497
        (fullscreenMonitorsSet || hadFsMonitors))
 
498
        window->updateAttributes (CompStackingUpdateModeNone);
509
499
}
510
500
 
511
501
void
515
505
        return;
516
506
 
517
507
    unsigned int oldState = priv->state;
518
 
    priv->state = newState;
 
508
    priv->state           = newState;
519
509
 
520
510
    recalcType ();
521
511
    recalcActions ();
537
527
 
538
528
    if (actions & CompWindowActionMoveMask)
539
529
        data[i++] = Atoms::winActionMove;
 
530
 
540
531
    if (actions & CompWindowActionResizeMask)
541
532
        data[i++] = Atoms::winActionResize;
 
533
 
542
534
    if (actions & CompWindowActionStickMask)
543
535
        data[i++] = Atoms::winActionStick;
 
536
 
544
537
    if (actions & CompWindowActionMinimizeMask)
545
538
        data[i++] = Atoms::winActionMinimize;
 
539
 
546
540
    if (actions & CompWindowActionMaximizeHorzMask)
547
541
        data[i++] = Atoms::winActionMaximizeHorz;
 
542
 
548
543
    if (actions & CompWindowActionMaximizeVertMask)
549
544
        data[i++] = Atoms::winActionMaximizeVert;
 
545
 
550
546
    if (actions & CompWindowActionFullscreenMask)
551
547
        data[i++] = Atoms::winActionFullscreen;
 
548
 
552
549
    if (actions & CompWindowActionCloseMask)
553
550
        data[i++] = Atoms::winActionClose;
 
551
 
554
552
    if (actions & CompWindowActionShadeMask)
555
553
        data[i++] = Atoms::winActionShade;
 
554
 
556
555
    if (actions & CompWindowActionChangeDesktopMask)
557
556
        data[i++] = Atoms::winActionChangeDesktop;
 
557
 
558
558
    if (actions & CompWindowActionAboveMask)
559
559
        data[i++] = Atoms::winActionAbove;
 
560
 
560
561
    if (actions & CompWindowActionBelowMask)
561
562
        data[i++] = Atoms::winActionBelow;
562
563
 
571
572
    unsigned int actions = 0;
572
573
    unsigned int setActions, clearActions;
573
574
 
574
 
    switch (priv->type) {
575
 
    case CompWindowTypeFullscreenMask:
576
 
    case CompWindowTypeNormalMask:
577
 
        actions =
578
 
            CompWindowActionMaximizeHorzMask |
579
 
            CompWindowActionMaximizeVertMask |
580
 
            CompWindowActionFullscreenMask   |
581
 
            CompWindowActionMoveMask         |
582
 
            CompWindowActionResizeMask       |
583
 
            CompWindowActionStickMask        |
584
 
            CompWindowActionMinimizeMask     |
585
 
            CompWindowActionCloseMask        |
586
 
            CompWindowActionChangeDesktopMask;
587
 
        break;
588
 
    case CompWindowTypeUtilMask:
589
 
    case CompWindowTypeMenuMask:
590
 
    case CompWindowTypeToolbarMask:
591
 
        actions =
592
 
            CompWindowActionMoveMask   |
593
 
            CompWindowActionResizeMask |
594
 
            CompWindowActionStickMask  |
595
 
            CompWindowActionCloseMask  |
596
 
            CompWindowActionChangeDesktopMask;
597
 
        break;
598
 
    case CompWindowTypeDialogMask:
599
 
    case CompWindowTypeModalDialogMask:
600
 
        actions =
601
 
            CompWindowActionMaximizeHorzMask |
602
 
            CompWindowActionMaximizeVertMask |
603
 
            CompWindowActionMoveMask         |
604
 
            CompWindowActionResizeMask       |
605
 
            CompWindowActionStickMask        |
606
 
            CompWindowActionCloseMask        |
607
 
            CompWindowActionChangeDesktopMask;
608
 
 
609
 
        /* allow minimization for dialog windows if they
610
 
           a) are not a transient (transients can be minimized
611
 
              with their parent)
612
 
           b) don't have the skip taskbar hint set (as those
613
 
              have no target to be minimized to)
614
 
        */
615
 
        if (!priv->transientFor &&
616
 
            !(priv->state & CompWindowStateSkipTaskbarMask))
617
 
        {
618
 
            actions |= CompWindowActionMinimizeMask;
619
 
        }
620
 
    default:
621
 
        break;
 
575
    switch (priv->type)
 
576
    {
 
577
        case CompWindowTypeFullscreenMask:
 
578
        case CompWindowTypeNormalMask:
 
579
            actions =
 
580
                    CompWindowActionMaximizeHorzMask |
 
581
                    CompWindowActionMaximizeVertMask |
 
582
                    CompWindowActionFullscreenMask   |
 
583
                    CompWindowActionMoveMask         |
 
584
                    CompWindowActionResizeMask       |
 
585
                    CompWindowActionStickMask        |
 
586
                    CompWindowActionMinimizeMask     |
 
587
                    CompWindowActionCloseMask        |
 
588
                    CompWindowActionChangeDesktopMask;
 
589
            break;
 
590
 
 
591
        case CompWindowTypeUtilMask:
 
592
        case CompWindowTypeMenuMask:
 
593
        case CompWindowTypeToolbarMask:
 
594
            actions =
 
595
                    CompWindowActionMoveMask   |
 
596
                    CompWindowActionResizeMask |
 
597
                    CompWindowActionStickMask  |
 
598
                    CompWindowActionCloseMask  |
 
599
                    CompWindowActionChangeDesktopMask;
 
600
            break;
 
601
 
 
602
        case CompWindowTypeDialogMask:
 
603
        case CompWindowTypeModalDialogMask:
 
604
            actions =
 
605
                    CompWindowActionMaximizeHorzMask |
 
606
                    CompWindowActionMaximizeVertMask |
 
607
                    CompWindowActionMoveMask         |
 
608
                    CompWindowActionResizeMask       |
 
609
                    CompWindowActionStickMask        |
 
610
                    CompWindowActionCloseMask        |
 
611
                    CompWindowActionChangeDesktopMask;
 
612
 
 
613
        /* allow minimization for dialog windows if they:
 
614
         * a) are not a transient (transients can be minimized
 
615
         *    with their parent)
 
616
         * b) don't have the skip taskbar hint set (as those
 
617
         *    have no target to be minimized to)
 
618
         */
 
619
            if (!priv->transientFor &&
 
620
                !(priv->state & CompWindowStateSkipTaskbarMask))
 
621
                actions |= CompWindowActionMinimizeMask;
 
622
 
 
623
            break;
 
624
 
 
625
        default:
 
626
            break;
622
627
    }
623
628
 
624
629
    if (priv->serverInput.top)
626
631
 
627
632
    actions |= (CompWindowActionAboveMask | CompWindowActionBelowMask);
628
633
 
629
 
    switch (priv->wmType) {
 
634
    switch (priv->wmType)
 
635
    {
630
636
    case CompWindowTypeNormalMask:
631
637
        actions |= CompWindowActionFullscreenMask |
632
638
                   CompWindowActionMinimizeMask;
 
639
        break;
 
640
 
633
641
    default:
634
642
        break;
635
643
    }
650
658
 
651
659
    foreach (CompOutput &o, screen->outputDevs ())
652
660
    {
653
 
        if (o.width () >= (priv->sizeHints.min_width + priv->border.left + priv->border.right))
 
661
        if (o.width ()  >= (priv->sizeHints.min_width + priv->border.left + priv->border.right))
654
662
            foundHorz = true;
655
663
        if (o.height () >= (priv->sizeHints.min_height + priv->border.top + priv->border.bottom))
656
664
            foundVert = true;
657
665
 
658
666
        /* Fullscreen windows don't need to fit borders... */
659
 
        if (o.width () >= priv->sizeHints.min_width &&
 
667
        if (o.width ()  >= priv->sizeHints.min_width &&
660
668
            o.height () >= priv->sizeHints.min_height)
661
669
            foundFull = true;
662
670
    }
777
785
void
778
786
CompWindow::recalcType ()
779
787
{
780
 
    unsigned int type;
781
 
 
782
 
    type = priv->wmType;
 
788
    unsigned int type = priv->wmType;
783
789
 
784
790
    if (!overrideRedirect () && priv->wmType == CompWindowTypeUnknownMask)
785
791
        type = CompWindowTypeNormalMask;
787
793
    if (priv->state & CompWindowStateFullscreenMask)
788
794
        type = CompWindowTypeFullscreenMask;
789
795
 
790
 
    if (type == CompWindowTypeNormalMask)
791
 
    {
792
 
        if (priv->transientFor)
793
 
            type = CompWindowTypeDialogMask;
794
 
    }
 
796
    if (type == CompWindowTypeNormalMask &&
 
797
        priv->transientFor)
 
798
        type = CompWindowTypeDialogMask;
795
799
 
796
800
    if (type == CompWindowTypeDockMask &&
797
801
        (priv->state & CompWindowStateBelowMask))
798
 
    {
799
802
        type = CompWindowTypeNormalMask;
800
 
    }
801
803
 
802
804
    if ((type & (CompWindowTypeNormalMask | CompWindowTypeDialogMask)) &&
803
805
        (priv->state & CompWindowStateModalMask))
804
 
    {
805
806
        type = CompWindowTypeModalDialogMask;
806
 
    }
807
807
 
808
808
    priv->type = type;
809
809
}
814
814
    if (!serverFrame)
815
815
        return false;
816
816
 
817
 
    XWindowChanges xwc = XWINDOWCHANGES_INIT;
 
817
    XWindowChanges xwc       = XWINDOWCHANGES_INIT;
818
818
    unsigned int   valueMask = CWX | CWY | CWWidth | CWHeight;
819
819
 
820
 
    xwc.x = serverGeometry.x ();
821
 
    xwc.y = serverGeometry.y ();
822
 
    xwc.width = serverGeometry.width ();
823
 
    xwc.height = serverGeometry.height ();
 
820
    xwc.x            = serverGeometry.x ();
 
821
    xwc.y            = serverGeometry.y ();
 
822
    xwc.width        = serverGeometry.width ();
 
823
    xwc.height       = serverGeometry.height ();
824
824
    xwc.border_width = serverGeometry.border ();
825
825
 
826
826
    window->configureXWindow (valueMask, &xwc);
830
830
    return true;
831
831
}
832
832
 
833
 
 
834
 
 
835
833
void
836
834
CompWindow::updateWindowOutputExtents ()
837
835
{
862
860
}
863
861
 
864
862
CompRegion
865
 
PrivateWindow::rectsToRegion (unsigned int n, XRectangle *rects)
 
863
PrivateWindow::rectsToRegion (unsigned int n,
 
864
                              XRectangle   *rects)
866
865
{
867
 
    CompRegion ret;
868
 
    int        x1, x2, y1, y2;
869
 
    const CompWindow::Geometry &geom = attrib.override_redirect ? priv->geometry : priv->serverGeometry;
 
866
    CompRegion                 ret;
 
867
    int                        x1, x2, y1, y2;
 
868
    const CompWindow::Geometry &geom = attrib.override_redirect ?
 
869
                                           priv->geometry : priv->serverGeometry;
870
870
 
871
 
    for (unsigned int i = 0; i < n; i++)
 
871
    for (unsigned int i = 0; i < n; ++i)
872
872
    {
873
873
        x1 = rects[i].x + geom.border ();
874
874
        y1 = rects[i].y + geom.border ();
877
877
 
878
878
        if (x1 < 0)
879
879
            x1 = 0;
 
880
 
880
881
        if (y1 < 0)
881
882
            y1 = 0;
 
883
 
882
884
        if (x2 > geom.width ())
883
885
            x2 = geom.width ();
 
886
 
884
887
        if (y2 > geom.height ())
885
888
            y2 = geom.height ();
886
889
 
906
909
void
907
910
PrivateWindow::updateRegion ()
908
911
{
909
 
    XRectangle r, *boundingShapeRects = NULL;
910
 
    XRectangle *inputShapeRects = NULL;
911
 
    int        nBounding = 0, nInput = 0;
912
 
    const CompWindow::Geometry &geom = attrib.override_redirect ? priv->geometry : priv->serverGeometry;
 
912
    XRectangle                 r, *boundingShapeRects = NULL;
 
913
    XRectangle                 *inputShapeRects       = NULL;
 
914
    int                        nBounding = 0, nInput  = 0;
 
915
    const CompWindow::Geometry &geom = attrib.override_redirect ?
 
916
                                           priv->geometry : priv->serverGeometry;
913
917
 
914
918
    priv->region = priv->inputRegion = emptyRegion;
915
919
 
939
943
    else
940
944
    {
941
945
        boundingShapeRects = &r;
942
 
        nBounding = 1;
 
946
        nBounding          = 1;
943
947
 
944
 
        inputShapeRects = &r;
945
 
        nInput = 1;
 
948
        inputShapeRects    = &r;
 
949
        nInput             = 1;
946
950
    }
947
951
 
948
 
    priv->region += rectsToRegion (nBounding, boundingShapeRects);
 
952
    priv->region      += rectsToRegion (nBounding, boundingShapeRects);
949
953
    priv->inputRegion += rectsToRegion (nInput, inputShapeRects);
950
954
 
951
955
    if (boundingShapeRects && boundingShapeRects != &r)
952
956
        XFree (boundingShapeRects);
 
957
 
953
958
    if (inputShapeRects && inputShapeRects != &r)
954
959
        XFree (inputShapeRects);
955
960
 
959
964
bool
960
965
CompWindow::updateStruts ()
961
966
{
962
 
    Atom          actual;
963
 
    int           result, format;
 
967
    Atom          actual;
 
968
    int           format;
964
969
    unsigned long n, left;
965
970
    unsigned char *data;
966
 
    bool          hasOld, hasNew;
 
971
    bool          hasOld;
967
972
    CompStruts    oldStrut, newStrut;
968
973
 
969
974
    if (priv->struts)
976
981
        oldStrut.bottom = priv->struts->bottom;
977
982
    }
978
983
    else
979
 
    {
980
984
        hasOld = false;
981
 
    }
982
 
 
983
 
    hasNew = false;
984
 
 
985
 
    newStrut.left.x         = 0;
986
 
    newStrut.left.y         = 0;
987
 
    newStrut.left.width  = 0;
988
 
    newStrut.left.height = screen->height ();
989
 
 
990
 
    newStrut.right.x      = screen->width ();
991
 
    newStrut.right.y      = 0;
992
 
    newStrut.right.width  = 0;
993
 
    newStrut.right.height = screen->height ();
994
 
 
995
 
    newStrut.top.x         = 0;
996
 
    newStrut.top.y         = 0;
997
 
    newStrut.top.width  = screen->width ();
998
 
    newStrut.top.height = 0;
 
985
 
 
986
    bool hasNew = false;
 
987
 
 
988
    newStrut.left.x        = 0;
 
989
    newStrut.left.y        = 0;
 
990
    newStrut.left.width    = 0;
 
991
    newStrut.left.height   = screen->height ();
 
992
 
 
993
    newStrut.right.x       = screen->width ();
 
994
    newStrut.right.y       = 0;
 
995
    newStrut.right.width   = 0;
 
996
    newStrut.right.height  = screen->height ();
 
997
 
 
998
    newStrut.top.x         = 0;
 
999
    newStrut.top.y         = 0;
 
1000
    newStrut.top.width     = screen->width ();
 
1001
    newStrut.top.height    = 0;
999
1002
 
1000
1003
    newStrut.bottom.x      = 0;
1001
1004
    newStrut.bottom.y      = screen->height ();
1002
1005
    newStrut.bottom.width  = screen->width ();
1003
1006
    newStrut.bottom.height = 0;
1004
1007
 
1005
 
    result = XGetWindowProperty (screen->dpy (), priv->id,
1006
 
                                 Atoms::wmStrutPartial,
1007
 
                                 0L, 12L, false, XA_CARDINAL, &actual, &format,
1008
 
                                 &n, &left, &data);
 
1008
    int result = XGetWindowProperty (screen->dpy (), priv->id,
 
1009
                                     Atoms::wmStrutPartial,
 
1010
                                     0L, 12L, false, XA_CARDINAL, &actual, &format,
 
1011
                                     &n, &left, &data);
1009
1012
 
1010
1013
    if (result == Success && data)
1011
1014
    {
1075
1078
        int x1, y1, x2, y2;
1076
1079
 
1077
1080
        /* applications expect us to clip struts to xinerama edges */
1078
 
        for (unsigned int i = 0;
1079
 
             i < screen->screenInfo ().size (); i++)
 
1081
        for (unsigned int i = 0; i < screen->screenInfo ().size (); ++i)
1080
1082
        {
1081
1083
            x1 = screen->screenInfo ()[i].x_org;
1082
1084
            y1 = screen->screenInfo ()[i].y_org;
1134
1136
    }
1135
1137
 
1136
1138
    if (hasOld != hasNew ||
1137
 
        (hasNew && hasOld &&
1138
 
         memcmp (&newStrut, &oldStrut, sizeof (CompStruts))))
 
1139
        (hasNew && hasOld && memcmp (&newStrut, &oldStrut, sizeof (CompStruts))))
1139
1140
    {
1140
1141
        if (hasNew)
1141
1142
        {
1142
1143
            if (!priv->struts)
1143
1144
            {
1144
1145
                priv->struts = (CompStruts *) malloc (sizeof (CompStruts));
 
1146
 
1145
1147
                if (!priv->struts)
1146
1148
                    return false;
1147
1149
            }
1163
1165
void
1164
1166
CompWindow::incrementDestroyReference ()
1165
1167
{
1166
 
    priv->destroyRefCnt++;
 
1168
    ++priv->destroyRefCnt;
1167
1169
}
1168
1170
 
1169
1171
void
1171
1173
{
1172
1174
    if (priv->id)
1173
1175
    {
1174
 
        CompWindow *oldServerNext, *oldServerPrev, *oldNext, *oldPrev;
1175
1176
        StackDebugger *dbg = StackDebugger::Default ();
1176
1177
 
1177
1178
        windowNotify (CompWindowNotifyBeforeDestroy);
1183
1184
        if (priv->wrapper)
1184
1185
            XUnmapWindow (screen->dpy (), priv->wrapper);
1185
1186
 
1186
 
        oldServerNext = serverNext;
1187
 
        oldServerPrev = serverPrev;
1188
 
        oldNext = next;
1189
 
        oldPrev = prev;
 
1187
        CompWindow *oldServerNext = serverNext;
 
1188
        CompWindow *oldServerPrev = serverPrev;
 
1189
        CompWindow *oldNext       = next;
 
1190
        CompWindow *oldPrev       = prev;
1190
1191
 
1191
1192
        /* This is where things get tricky ... it is possible
1192
1193
         * to receive a ConfigureNotify relative to a frame window
1237
1238
         * linked list links but we don't want that so don't
1238
1239
         * do that */
1239
1240
 
1240
 
        next = oldNext;
1241
 
        prev = oldPrev;
 
1241
        next       = oldNext;
 
1242
        prev       = oldPrev;
1242
1243
        serverNext = oldServerNext;
1243
1244
        serverPrev = oldServerPrev;
1244
1245
 
1247
1248
        /* We must set the xid of this window
1248
1249
         * to zero as it no longer references
1249
1250
         * a valid window */
1250
 
        priv->mapNum = 0;
1251
 
        priv->id = 0;
1252
 
        priv->frame = 0;
 
1251
        priv->mapNum      = 0;
 
1252
        priv->id          = 0;
 
1253
        priv->frame       = 0;
1253
1254
        priv->serverFrame = 0;
1254
 
        priv->managed    = false;
 
1255
        priv->managed     = false;
1255
1256
    }
1256
1257
 
1257
 
    priv->destroyRefCnt--;
 
1258
    --priv->destroyRefCnt;
 
1259
 
1258
1260
    if (priv->destroyRefCnt)
1259
1261
        return;
1260
1262
 
1283
1285
    xev.event  = priv->id;
1284
1286
    xev.window = priv->id;
1285
1287
 
1286
 
    xev.x            = priv->serverGeometry.x ();
1287
 
    xev.y            = priv->serverGeometry.y ();
1288
 
    xev.width        = priv->serverGeometry.width ();
1289
 
    xev.height       = priv->serverGeometry.height ();
1290
 
    xev.border_width = priv->serverGeometry.border ();
 
1288
    xev.x                 = priv->serverGeometry.x ();
 
1289
    xev.y                 = priv->serverGeometry.y ();
 
1290
    xev.width             = priv->serverGeometry.width ();
 
1291
    xev.height            = priv->serverGeometry.height ();
 
1292
    xev.border_width      = priv->serverGeometry.border ();
1291
1293
    xev.override_redirect = priv->attrib.override_redirect;
1292
1294
 
1293
1295
    /* These used to be based on the actual sibling of the window
1353
1355
        priv->invisible  = priv->isInvisible ();
1354
1356
        priv->alive      = true;
1355
1357
 
1356
 
        priv->lastPong = screen->lastPing ();
 
1358
        priv->lastPong   = screen->lastPing ();
1357
1359
 
1358
1360
        priv->updateRegion ();
1359
1361
        priv->updateSize ();
1369
1371
            sendConfigureNotify ();
1370
1372
        }
1371
1373
 
1372
 
        if (!overrideRedirect ())
 
1374
        if (!overrideRedirect () &&
 
1375
            priv->shaded) // been shaded
1373
1376
        {
1374
 
            /* been shaded */
1375
 
            if (priv->shaded)
1376
 
            {
1377
 
                priv->shaded = false;
1378
 
                priv->updateFrameWindow ();
1379
 
            }
 
1377
            priv->shaded = false;
 
1378
            priv->updateFrameWindow ();
1380
1379
        }
1381
1380
    }
1382
1381
 
1389
1388
void
1390
1389
CompWindow::incrementUnmapReference ()
1391
1390
{
1392
 
    priv->unmapRefCnt++;
 
1391
    ++priv->unmapRefCnt;
1393
1392
}
1394
1393
 
1395
1394
void
1411
1410
    if (!priv->shaded)
1412
1411
        XUnmapWindow (screen->dpy (), priv->serverFrame);
1413
1412
 
1414
 
    priv->unmapRefCnt--;
 
1413
    --priv->unmapRefCnt;
 
1414
 
1415
1415
    if (priv->unmapRefCnt > 0)
1416
1416
        return;
1417
1417
 
1418
1418
    if (priv->unmanaging)
1419
1419
    {
1420
 
        XWindowChanges xwc = XWINDOWCHANGES_INIT;
 
1420
        XWindowChanges xwc     = XWINDOWCHANGES_INIT;
1421
1421
        unsigned int   xwcm;
1422
 
        int                gravity = priv->sizeHints.win_gravity;
 
1422
        int            gravity = priv->sizeHints.win_gravity;
1423
1423
 
1424
1424
        /* revert gravity adjustment made at MapNotify time */
1425
 
        xwc.x   = priv->serverGeometry.x ();
1426
 
        xwc.y   = priv->serverGeometry.y ();
1427
 
        xwc.width   = 0;
1428
 
        xwc.height  = 0;
 
1425
        xwc.x      = priv->serverGeometry.x ();
 
1426
        xwc.y      = priv->serverGeometry.y ();
 
1427
        xwc.width  = 0;
 
1428
        xwc.height = 0;
1429
1429
 
1430
1430
        xwcm = priv->adjustConfigureRequestForGravity (&xwc,
1431
1431
                                                       CWX | CWY,
1450
1450
        screen->decrementDesktopWindowCount();
1451
1451
 
1452
1452
    priv->attrib.map_state = IsUnmapped;
1453
 
    priv->invisible = true;
 
1453
    priv->invisible        = true;
1454
1454
 
1455
1455
    if (priv->shaded)
1456
1456
        priv->updateFrameWindow ();
1487
1487
        return false;
1488
1488
 
1489
1489
    if (aboveId && !screen->findTopLevelWindow (aboveId, true))
1490
 
    {
1491
 
        return false;
1492
 
    }
 
1490
        return false;
1493
1491
 
1494
1492
    screen->unhookWindow (window);
1495
1493
    screen->insertWindow (window, aboveId);
1525
1523
}
1526
1524
 
1527
1525
bool
1528
 
CompWindow::resize (int          x,
1529
 
                    int          y,
1530
 
                    int          width,
1531
 
                    int          height,
1532
 
                    int          border)
 
1526
CompWindow::resize (int x,
 
1527
                    int y,
 
1528
                    int width,
 
1529
                    int height,
 
1530
                    int border)
1533
1531
{
1534
1532
    return resize (Geometry (x, y, width, height, border));
1535
1533
}
1552
1550
        priv->geometry.height ()  != gm.height () ||
1553
1551
        priv->geometry.border ()  != gm.border ())
1554
1552
    {
1555
 
        int dx, dy, dwidth, dheight;
1556
 
 
1557
 
        dx      = gm.x () - priv->geometry.x ();
1558
 
        dy      = gm.y () - priv->geometry.y ();
1559
 
        dwidth  = gm.width () - priv->geometry.width ();
1560
 
        dheight = gm.height () - priv->geometry.height ();
 
1553
        int dx      = gm.x () - priv->geometry.x ();
 
1554
        int dy      = gm.y () - priv->geometry.y ();
 
1555
        int dwidth  = gm.width ()  - priv->geometry.width ();
 
1556
        int dheight = gm.height () - priv->geometry.height ();
1561
1557
 
1562
1558
        priv->geometry.set (gm.x (), gm.y (),
1563
1559
                            gm.width (), gm.height (),
1567
1563
 
1568
1564
        if (priv->attrib.override_redirect)
1569
1565
        {
1570
 
            priv->serverGeometry = priv->geometry;
 
1566
            priv->serverGeometry      = priv->geometry;
1571
1567
            priv->serverFrameGeometry = priv->frameGeometry;
1572
1568
 
1573
1569
            if (priv->mapNum)
1576
1572
            window->resizeNotify (dx, dy, dwidth, dheight);
1577
1573
        }
1578
1574
    }
1579
 
    else if (priv->geometry.x () != gm.x () || priv->geometry.y () != gm.y ())
1580
 
    {
 
1575
    else if (priv->geometry.x () != gm.x () ||
 
1576
             priv->geometry.y () != gm.y ())
1581
1577
        move (gm.x () - priv->geometry.x (),
1582
1578
              gm.y () - priv->geometry.y (), true);
1583
 
    }
1584
1579
 
1585
1580
    return true;
1586
1581
}
1593
1588
}
1594
1589
 
1595
1590
bool
1596
 
PrivateWindow::resize (int          x,
1597
 
                       int          y,
1598
 
                       int          width,
1599
 
                       int          height,
1600
 
                       int          border)
 
1591
PrivateWindow::resize (int x,
 
1592
                       int y,
 
1593
                       int width,
 
1594
                       int height,
 
1595
                       int border)
1601
1596
{
1602
1597
    return resize (CompWindow::Geometry (x, y, width, height, border));
1603
1598
}
1605
1600
bool
1606
1601
CompWindow::resize (CompWindow::Geometry gm)
1607
1602
{
1608
 
    XWindowChanges xwc = XWINDOWCHANGES_INIT;
 
1603
    XWindowChanges xwc       = XWINDOWCHANGES_INIT;
1609
1604
    unsigned int   valueMask = CWX | CWY | CWWidth | CWHeight | CWBorderWidth;
1610
1605
 
1611
 
    xwc.x = gm.x ();
1612
 
    xwc.y = gm.y ();
1613
 
    xwc.width = gm.width ();
1614
 
    xwc.height = gm.height ();
 
1606
    xwc.x            = gm.x ();
 
1607
    xwc.y            = gm.y ();
 
1608
    xwc.width        = gm.width ();
 
1609
    xwc.height       = gm.height ();
1615
1610
    xwc.border_width = gm.border ();
1616
1611
 
1617
1612
    configureXWindow (valueMask, &xwc);
1623
1618
syncValueIncrement (XSyncValue *value)
1624
1619
{
1625
1620
    XSyncValue one;
1626
 
    int        overflow;
 
1621
    int        overflow;
1627
1622
 
1628
1623
    XSyncIntToValue (&one, 1);
1629
1624
    XSyncValueAdd (value, *value, one, &overflow);
1632
1627
bool
1633
1628
PrivateWindow::initializeSyncCounter ()
1634
1629
{
1635
 
    XSyncAlarmAttributes values;
1636
 
    Atom                 actual;
1637
 
    int                  result, format;
1638
 
    unsigned long        n, left;
1639
 
    unsigned char        *data;
1640
 
 
1641
1630
    if (syncCounter)
1642
1631
        return syncAlarm != None;
1643
1632
 
1644
1633
    if (!(protocols & CompWindowProtocolSyncRequestMask))
1645
1634
        return false;
1646
1635
 
1647
 
    result = XGetWindowProperty (screen->dpy (), id,
1648
 
                                 Atoms::wmSyncRequestCounter,
1649
 
                                 0L, 1L, false, XA_CARDINAL, &actual, &format,
1650
 
                                 &n, &left, &data);
 
1636
    Atom          actual;
 
1637
    int           format;
 
1638
    unsigned long n, left;
 
1639
    unsigned char *data;
 
1640
 
 
1641
    int result = XGetWindowProperty (screen->dpy (), id,
 
1642
                                     Atoms::wmSyncRequestCounter,
 
1643
                                     0L, 1L, false, XA_CARDINAL, &actual, &format,
 
1644
                                     &n, &left, &data);
1651
1645
 
1652
1646
    if (result == Success && n && data)
1653
1647
    {
1664
1658
 
1665
1659
        syncValueIncrement (&syncValue);
1666
1660
 
1667
 
        values.events = true;
 
1661
        XSyncAlarmAttributes values;
 
1662
 
 
1663
        values.events             = true;
1668
1664
 
1669
1665
        values.trigger.counter    = syncCounter;
1670
1666
        values.trigger.wait_value = syncValue;
1698
1694
        syncAlarm = None;
1699
1695
    }
1700
1696
    else if (result == Success && data)
1701
 
    {
1702
1697
        XFree (data);
1703
 
    }
1704
1698
 
1705
1699
    return false;
1706
1700
}
1708
1702
void
1709
1703
CompWindow::sendSyncRequest ()
1710
1704
{
1711
 
    if (priv->syncWait)
1712
 
        return;
1713
 
 
1714
 
    if (!priv->initializeSyncCounter ())
 
1705
    if (priv->syncWait ||
 
1706
        !priv->initializeSyncCounter ())
1715
1707
        return;
1716
1708
 
1717
1709
    XClientMessageEvent xev;
1718
1710
 
1719
 
    xev.type         = ClientMessage;
1720
 
    xev.window       = priv->id;
 
1711
    xev.type         = ClientMessage;
 
1712
    xev.window       = priv->id;
1721
1713
    xev.message_type = Atoms::wmProtocols;
1722
 
    xev.format       = 32;
 
1714
    xev.format       = 32;
1723
1715
    xev.data.l[0]    = Atoms::wmSyncRequest;
1724
1716
    xev.data.l[1]    = CurrentTime;
1725
1717
    xev.data.l[2]    = XSyncValueLow32 (priv->syncValue);
1766
1758
        if (ROOTPARENT (window->prev) != ce->above)
1767
1759
            valueMask |= CWSibling | CWStackMode;
1768
1760
    }
1769
 
    else
1770
 
    {
1771
 
        if (ce->above != 0)
1772
 
            valueMask |= CWSibling | CWStackMode;
1773
 
    }
 
1761
    else if (ce->above != 0)
 
1762
        valueMask |= CWSibling | CWStackMode;
1774
1763
 
1775
1764
    priv->attrib.override_redirect = ce->override_redirect;
1776
1765
 
1781
1770
        priv->syncGeometry.set (ce->x, ce->y, ce->width, ce->height,
1782
1771
                                ce->border_width);
1783
1772
    else
1784
 
    {
1785
1773
        resize (ce->x, ce->y, ce->width, ce->height, ce->border_width);
1786
 
    }
1787
1774
 
1788
1775
    if (ce->event == screen->root ())
1789
1776
        priv->restack (ce->above);
1795
1782
    if (!priv->frame)
1796
1783
        return;
1797
1784
 
1798
 
    int x, y, width, height;
1799
 
    CompWindow       *above;
 
1785
    int              height;
 
1786
    CompWindow       *above;
1800
1787
    unsigned int     valueMask = 0;
1801
1788
 
1802
1789
    /* remove configure event from pending configures */
1820
1807
        if (ROOTPARENT (window->prev) != ce->above)
1821
1808
            valueMask |= CWSibling | CWStackMode;
1822
1809
    }
1823
 
    else
1824
 
    {
1825
 
        if (ce->above != 0)
1826
 
            valueMask |= CWSibling | CWStackMode;
1827
 
    }
 
1810
    else if (ce->above != 0)
 
1811
        valueMask |= CWSibling | CWStackMode;
1828
1812
 
1829
1813
    if (!pendingConfigures.match ((XEvent *) ce))
1830
1814
    {
1843
1827
     * re-sync the input extents and extents last
1844
1828
     * sent to server on resize () */
1845
1829
 
1846
 
    x      = ce->x + priv->serverInput.left;
1847
 
    y      = ce->y + priv->serverInput.top;
1848
 
    width  = ce->width - priv->serverGeometry.border () * 2 - priv->serverInput.left - priv->serverInput.right;
 
1830
    int x      = ce->x + priv->serverInput.left;
 
1831
    int y      = ce->y + priv->serverInput.top;
 
1832
    int width  = ce->width - priv->serverGeometry.border () * 2 -
 
1833
                 priv->serverInput.left - priv->serverInput.right;
1849
1834
 
1850
1835
    /* Don't use the server side frame geometry
1851
1836
     * to determine the geometry of shaded
1852
1837
     * windows since we didn't resize them
1853
1838
     * on configureXWindow */
1854
1839
    if (priv->shaded)
1855
 
        height = priv->serverGeometry.heightIncBorders () - priv->serverInput.top - priv->serverInput.bottom;
 
1840
        height = priv->serverGeometry.heightIncBorders () -
 
1841
                 priv->serverInput.top - priv->serverInput.bottom;
1856
1842
    else
1857
 
        height = ce->height + priv->serverGeometry.border () * 2 - priv->serverInput.top - priv->serverInput.bottom;
 
1843
        height = ce->height + priv->serverGeometry.border () * 2 -
 
1844
                 priv->serverInput.top - priv->serverInput.bottom;
1858
1845
 
1859
1846
    /* set the frame geometry */
1860
1847
    priv->frameGeometry.set (ce->x, ce->y, ce->width, ce->height, ce->border_width);
1861
1848
 
1862
 
 
1863
1849
    if (priv->syncWait)
1864
1850
        priv->syncGeometry.set (x, y, width, height, ce->border_width);
1865
1851
    else
1897
1883
{
1898
1884
    if (dx || dy)
1899
1885
    {
1900
 
        XWindowChanges xwc = XWINDOWCHANGES_INIT;
 
1886
        XWindowChanges xwc       = XWINDOWCHANGES_INIT;
1901
1887
        unsigned int   valueMask = CWX | CWY;
1902
1888
 
1903
1889
        xwc.x = priv->serverGeometry.x () + dx;
1927
1913
            priv->serverFrameGeometry = priv->frameGeometry;
1928
1914
            priv->region.translate (dx, dy);
1929
1915
            priv->inputRegion.translate (dx, dy);
 
1916
 
1930
1917
            if (!priv->frameRegion.isEmpty ())
1931
1918
                priv->frameRegion.translate (dx, dy);
1932
1919
 
1997
1984
compiz::X11::PendingEventQueue::forEachIf (boost::function<bool (compiz::X11::PendingEvent::Ptr)> f)
1998
1985
{
1999
1986
    foreach (compiz::X11::PendingEvent::Ptr p, mEvents)
2000
 
    {
2001
1987
        if (f (p))
2002
1988
            return true;
2003
 
    }
2004
1989
 
2005
1990
    return false;
2006
1991
}
2035
2020
bool
2036
2021
compiz::X11::PendingEvent::match (XEvent *event)
2037
2022
{
2038
 
    if (event->xany.serial != mSerial)
2039
 
        return false;
2040
 
    if (getEventWindow (event)!= mWindow)
 
2023
    if (event->xany.serial != mSerial ||
 
2024
        getEventWindow (event)!= mWindow)
2041
2025
        return false;
2042
2026
 
2043
2027
    return true;
2068
2052
}
2069
2053
 
2070
2054
bool
2071
 
compiz::X11::PendingConfigureEvent::matchRequest (XWindowChanges &xwc, unsigned int valueMask)
 
2055
compiz::X11::PendingConfigureEvent::matchRequest (XWindowChanges &xwc,
 
2056
                                                  unsigned int   valueMask)
2072
2057
{
2073
2058
    if (matchVM (valueMask))
2074
2059
    {
2075
 
        if (valueMask & CWX)
2076
 
            if (xwc.x != mXwc.x)
2077
 
                return false;
2078
 
 
2079
 
        if (valueMask & CWY)
2080
 
            if (xwc.y != mXwc.y)
2081
 
                return false;
2082
 
 
2083
 
        if (valueMask & CWWidth)
2084
 
            if (xwc.width != mXwc.width)
2085
 
                return false;
2086
 
 
2087
 
        if (valueMask & CWHeight)
2088
 
            if (xwc.height != mXwc.height)
2089
 
                return false;
2090
 
 
2091
 
        if (valueMask & CWBorderWidth)
2092
 
            if (xwc.border_width != mXwc.border_width)
2093
 
                return false;
2094
 
 
2095
 
        if (valueMask & (CWStackMode | CWSibling))
2096
 
            if (xwc.sibling != mXwc.sibling)
2097
 
                return false;
 
2060
        if ((valueMask & CWX                       && xwc.x            != mXwc.x)               ||
 
2061
            (valueMask & CWY                       && xwc.y            != mXwc.y)               ||
 
2062
            (valueMask & CWWidth                   && xwc.width        != mXwc.width)           ||
 
2063
            (valueMask & CWHeight                  && xwc.height       != mXwc.height)          ||
 
2064
            (valueMask & CWBorderWidth             && xwc.border_width != mXwc.border_width)    ||
 
2065
            (valueMask & (CWStackMode | CWSibling) && xwc.sibling      != mXwc.sibling))
 
2066
            return false;
2098
2067
 
2099
2068
        return true;
2100
2069
    }
2105
2074
bool
2106
2075
compiz::X11::PendingConfigureEvent::match (XEvent *event)
2107
2076
{
2108
 
    XConfigureEvent *ce = (XConfigureEvent *) event;
2109
 
    bool matched = true;
 
2077
    XConfigureEvent *ce     = (XConfigureEvent *) event;
 
2078
    bool            matched = true;
2110
2079
 
2111
2080
    if (!compiz::X11::PendingEvent::match (event))
2112
2081
        return false;
2113
2082
 
2114
2083
    XWindowChanges xwc = XWINDOWCHANGES_INIT;
2115
2084
 
2116
 
    xwc.x = ce->x;
2117
 
    xwc.y = ce->y;
2118
 
    xwc.width = ce->width;
2119
 
    xwc.height = ce->height;
 
2085
    xwc.x            = ce->x;
 
2086
    xwc.y            = ce->y;
 
2087
    xwc.width        = ce->width;
 
2088
    xwc.height       = ce->height;
2120
2089
    xwc.border_width = ce->border_width;
2121
 
    xwc.sibling = ce->above;
 
2090
    xwc.sibling      = ce->above;
2122
2091
 
2123
2092
    matched = matchRequest (xwc, mValueMask);
2124
2093
 
2130
2099
    {
2131
2100
        compLogMessage ("core", CompLogLevelWarn, "no exact match for ConfigureNotify on 0x%x!", mWindow);
2132
2101
        compLogMessage ("core", CompLogLevelWarn, "expected the following changes:");
 
2102
 
2133
2103
        if (mValueMask & CWX)
2134
2104
            compLogMessage ("core", CompLogLevelWarn, "x: %i", mXwc.x);
 
2105
 
2135
2106
        if (mValueMask & CWY)
2136
2107
            compLogMessage ("core", CompLogLevelWarn, "y: %i", mXwc.y);
 
2108
 
2137
2109
        if (mValueMask & CWWidth)
2138
2110
            compLogMessage ("core", CompLogLevelWarn, "width: %i", mXwc.width);
 
2111
 
2139
2112
        if (mValueMask & CWHeight)
2140
2113
            compLogMessage ("core", CompLogLevelWarn, "height: %i", mXwc.height);
 
2114
 
2141
2115
        if (mValueMask & CWBorderWidth)
2142
2116
            compLogMessage ("core", CompLogLevelWarn, "border: %i", mXwc.border_width);
 
2117
 
2143
2118
        if (mValueMask & (CWStackMode | CWSibling))
2144
2119
            compLogMessage ("core", CompLogLevelWarn, "sibling: 0x%x", mXwc.sibling);
2145
2120
 
2156
2131
    return true;
2157
2132
}
2158
2133
 
2159
 
compiz::X11::PendingConfigureEvent::PendingConfigureEvent (Display *d,
2160
 
                                                           Window   w,
2161
 
                                                           unsigned int valueMask,
 
2134
compiz::X11::PendingConfigureEvent::PendingConfigureEvent (Display        *d,
 
2135
                                                           Window         w,
 
2136
                                                           unsigned int   valueMask,
2162
2137
                                                           XWindowChanges *xwc) :
2163
2138
    compiz::X11::PendingEvent::PendingEvent (d, w),
2164
2139
    mValueMask (valueMask),
2175
2150
{
2176
2151
    WRAPABLE_HND_FUNCTN_RETURN (bool, focus)
2177
2152
 
2178
 
    if (overrideRedirect ())
2179
 
        return false;
2180
 
 
2181
 
    if (!priv->managed || priv->unmanaging)
2182
 
        return false;
2183
 
 
2184
 
    if (!onCurrentDesktop ())
2185
 
        return false;
2186
 
 
2187
 
    if (priv->destroyed)
2188
 
        return false;
2189
 
 
2190
 
    if (!priv->shaded && (priv->state & CompWindowStateHiddenMask))
2191
 
        return false;
2192
 
 
2193
 
    if (priv->serverGeometry.x () + priv->serverGeometry.width ()  <= 0 ||
 
2153
    if (overrideRedirect ()                                             ||
 
2154
        !priv->managed                                                  ||
 
2155
        priv->unmanaging                                                ||
 
2156
        !onCurrentDesktop ()                                            ||
 
2157
        priv->destroyed                                                 ||
 
2158
        (!priv->shaded && (priv->state & CompWindowStateHiddenMask))    ||
 
2159
        priv->serverGeometry.x () + priv->serverGeometry.width ()  <= 0 ||
2194
2160
        priv->serverGeometry.y () + priv->serverGeometry.height () <= 0 ||
2195
 
        priv->serverGeometry.x () >= (int) screen->width ()||
 
2161
        priv->serverGeometry.x () >= (int) screen->width ()             ||
2196
2162
        priv->serverGeometry.y () >= (int) screen->height ())
2197
2163
        return false;
2198
2164
 
2213
2179
{
2214
2180
    WRAPABLE_HND_FUNCTN (validateResizeRequest, mask, xwc, source)
2215
2181
 
2216
 
    if (!(priv->type & (CompWindowTypeDockMask    |
2217
 
                     CompWindowTypeFullscreenMask |
2218
 
                     CompWindowTypeUnknownMask)))
 
2182
    if (!(priv->type & (CompWindowTypeDockMask       |
 
2183
                        CompWindowTypeFullscreenMask |
 
2184
                        CompWindowTypeUnknownMask)))
2219
2185
    {
2220
2186
        if (mask & CWY)
2221
2187
        {
2222
 
            int min, max;
2223
 
 
2224
 
            min = screen->workArea ().y () + priv->input.top;
2225
 
            max = screen->workArea ().bottom ();
 
2188
            int min = screen->workArea ().y () + priv->input.top;
 
2189
            int max = screen->workArea ().bottom ();
2226
2190
 
2227
2191
            if (priv->state & CompWindowStateStickyMask &&
2228
 
                 (xwc->y < min || xwc->y > max))
2229
 
            {
 
2192
                (xwc->y < min || xwc->y > max))
2230
2193
                xwc->y = priv->serverGeometry.y ();
2231
 
            }
2232
2194
            else
2233
2195
            {
2234
2196
                min -= screen->vp ().y () * screen->height ();
2244
2206
 
2245
2207
        if (mask & CWX)
2246
2208
        {
2247
 
            int min, max;
2248
 
 
2249
 
            min = screen->workArea ().x () + priv->input.left;
2250
 
            max = screen->workArea ().right ();
 
2209
            int min = screen->workArea ().x () + priv->input.left;
 
2210
            int max = screen->workArea ().right ();
2251
2211
 
2252
2212
            if (priv->state & CompWindowStateStickyMask &&
2253
2213
                (xwc->x < min || xwc->x > max))
2254
 
            {
2255
2214
                xwc->x = priv->serverGeometry.x ();
2256
 
            }
2257
2215
            else
2258
2216
            {
2259
2217
                min -= screen->vp ().x () * screen->width ();
2287
2245
    WRAPABLE_HND_FUNCTN (windowNotify, n)
2288
2246
 
2289
2247
void
2290
 
CompWindow::grabNotify (int          x,
2291
 
                        int          y,
 
2248
CompWindow::grabNotify (int          x,
 
2249
                        int          y,
2292
2250
                        unsigned int state,
2293
2251
                        unsigned int mask)
2294
2252
{
2312
2270
    if (!(lastState & CompWindowStateStickyMask) &&
2313
2271
        (priv->state & CompWindowStateStickyMask))
2314
2272
    {
2315
 
        CompPoint vp;   /* index of the window's vp */
2316
 
 
2317
2273
        /* Find which viewport the window falls in,
2318
2274
           and check if it's the current viewport */
2319
 
        vp = defaultViewport ();
 
2275
        CompPoint vp = defaultViewport (); /* index of the window's vp */
 
2276
 
2320
2277
        if (screen->vp () != vp)
2321
2278
        {
2322
2279
            unsigned int valueMask = CWX | CWY;
2323
 
            XWindowChanges xwc = XWINDOWCHANGES_INIT;
 
2280
            XWindowChanges xwc     = XWINDOWCHANGES_INIT;
2324
2281
 
2325
2282
            xwc.x = serverGeometry ().x () +  (screen->vp ().x () - vp.x ()) * screen->width ();
2326
2283
            xwc.y = serverGeometry ().y () +  (screen->vp ().y () - vp.y ()) * screen->height ();
2330
2287
    }
2331
2288
}
2332
2289
 
2333
 
 
2334
2290
bool
2335
2291
PrivateWindow::isGroupTransient (Window clientLeader)
2336
2292
{
2337
2293
    if (!clientLeader)
2338
2294
        return false;
2339
2295
 
2340
 
    if (transientFor == None || transientFor == screen->root ())
2341
 
    {
2342
 
        if (type & (CompWindowTypeUtilMask    |
2343
 
                    CompWindowTypeToolbarMask |
2344
 
                    CompWindowTypeMenuMask    |
2345
 
                    CompWindowTypeDialogMask  |
2346
 
                    CompWindowTypeModalDialogMask))
2347
 
        {
2348
 
            if (this->clientLeader == clientLeader)
2349
 
                return true;
2350
 
        }
2351
 
    }
 
2296
    if ((transientFor == None || transientFor == screen->root ())   &&
 
2297
        (type & (CompWindowTypeUtilMask    |
 
2298
                 CompWindowTypeToolbarMask |
 
2299
                 CompWindowTypeMenuMask    |
 
2300
                 CompWindowTypeDialogMask  |
 
2301
                 CompWindowTypeModalDialogMask)                     &&
 
2302
        this->clientLeader == clientLeader))
 
2303
        return true;
2352
2304
 
2353
2305
    return false;
2354
2306
}
2365
2317
        if (w == modalTransient || w->priv->mapNum == 0)
2366
2318
            continue;
2367
2319
 
2368
 
        if (w->priv->transientFor == modalTransient->priv->id)
 
2320
        if (w->priv->transientFor == modalTransient->priv->id &&
 
2321
            w->priv->state & CompWindowStateModalMask)
2369
2322
        {
2370
 
            if (w->priv->state & CompWindowStateModalMask)
2371
 
            {
2372
 
                modalTransient = w;
2373
 
                w = screen->windows ().back ();
2374
 
            }
 
2323
            modalTransient = w;
 
2324
            w              = screen->windows ().back ();
2375
2325
        }
2376
2326
    }
2377
2327
 
2384
2334
 
2385
2335
        for (w = screen->windows ().back (); w; w = w->prev)
2386
2336
        {
2387
 
            if (w == modalTransient || w->priv->mapNum == 0)
2388
 
                continue;
2389
 
 
2390
 
            if (isAncestorTo (modalTransient, w))
2391
 
                continue;
2392
 
 
2393
 
            if (w->priv->isGroupTransient (modalTransient->priv->clientLeader))
 
2337
            if (w == modalTransient     ||
 
2338
                w->priv->mapNum == 0    ||
 
2339
                isAncestorTo (modalTransient, w))
 
2340
                continue;
 
2341
 
 
2342
            if (w->priv->isGroupTransient (modalTransient->priv->clientLeader) &&
 
2343
                w->priv->state & CompWindowStateModalMask)
2394
2344
            {
2395
 
                if (w->priv->state & CompWindowStateModalMask)
2396
 
                {
 
2345
                modalTransient = w;
 
2346
                w              = w->priv->getModalTransient ();
 
2347
 
 
2348
                if (w)
2397
2349
                    modalTransient = w;
2398
 
                    w = w->priv->getModalTransient ();
2399
 
                    if (w)
2400
 
                        modalTransient = w;
2401
2350
 
2402
 
                    break;
2403
 
                }
 
2351
                break;
2404
2352
            }
2405
2353
        }
2406
2354
    }
2414
2362
void
2415
2363
CompWindow::moveInputFocusTo ()
2416
2364
{
2417
 
    CompScreen  *s = screen;
2418
 
    CompWindow  *modalTransient;
 
2365
    CompScreen  *s              = screen;
 
2366
    CompWindow  *modalTransient = priv->getModalTransient ();
2419
2367
 
2420
 
    modalTransient = priv->getModalTransient ();
2421
2368
    if (modalTransient)
2422
2369
        return modalTransient->moveInputFocusTo ();
2423
2370
 
2451
2398
        {
2452
2399
            XEvent ev;
2453
2400
 
2454
 
            ev.type                 = ClientMessage;
2455
 
            ev.xclient.window       = priv->id;
 
2401
            ev.type                 = ClientMessage;
 
2402
            ev.xclient.window       = priv->id;
2456
2403
            ev.xclient.message_type = Atoms::wmProtocols;
2457
 
            ev.xclient.format       = 32;
 
2404
            ev.xclient.format       = 32;
2458
2405
            ev.xclient.data.l[0]    = Atoms::wmTakeFocus;
2459
2406
            ev.xclient.data.l[1]    = s->getCurrentTime ();
2460
2407
            ev.xclient.data.l[2]    = 0;
2493
2440
    if (priv->id == screen->activeWindow () ||
2494
2441
        priv->id == screen->getNextActiveWindow())
2495
2442
    {
2496
 
        CompWindow *nextActive = screen->findWindow (screen->getNextActiveWindow());
 
2443
        CompWindow *nextActive = screen->findWindow (screen->getNextActiveWindow ());
2497
2444
 
2498
 
        /* Window pending focus */
2499
 
        if (priv->id != screen->getNextActiveWindow() &&
2500
 
            nextActive &&
 
2445
        /* Window pending focus */
 
2446
        if (priv->id != screen->getNextActiveWindow ()  &&
 
2447
            nextActive                                  &&
2501
2448
            nextActive->focus ())
2502
 
        {
2503
2449
            nextActive->moveInputFocusTo ();
2504
 
        }
2505
 
        else if (priv->transientFor && priv->transientFor != screen->root ())
 
2450
        else if (priv->transientFor &&
 
2451
                 priv->transientFor != screen->root ())
2506
2452
        {
2507
 
            CompWindow *ancestor;
2508
 
            ancestor = screen->findWindow (priv->transientFor);
2509
 
            if (ancestor &&
2510
 
                ancestor->focus () &&
 
2453
            CompWindow *ancestor = screen->findWindow (priv->transientFor);
 
2454
 
 
2455
            if (ancestor            &&
 
2456
                ancestor->focus ()  &&
2511
2457
                !(ancestor->priv->type & (CompWindowTypeDesktopMask |
2512
2458
                                          CompWindowTypeDockMask)))
2513
 
            {
2514
2459
                ancestor->moveInputFocusTo ();
2515
 
            }
2516
2460
            else
2517
2461
                screen->focusDefaultWindow ();
2518
2462
        }
2545
2489
 
2546
2490
            if (focus && !(focus->priv->type & (CompWindowTypeDesktopMask |
2547
2491
                                                CompWindowTypeDockMask)))
2548
 
            {
2549
2492
                focus->moveInputFocusTo ();
2550
 
            }
2551
2493
            else
2552
2494
                screen->focusDefaultWindow ();
2553
2495
        }
2596
2538
    else
2597
2539
    {
2598
2540
        XWindowAttributes attrib;
 
2541
 
2599
2542
        if (!XGetWindowAttributes (screen->dpy (),
2600
2543
                                   ROOTPARENT (window),
2601
2544
                                   &attrib))
2606
2549
}
2607
2550
}
2608
2551
 
2609
 
 
2610
2552
bool
2611
2553
PrivateWindow::stackLayerCheck (CompWindow       *w,
2612
 
                                Window           clientLeader,
 
2554
                                Window           clientLeader,
2613
2555
                                CompWindow       *below,
2614
2556
                                const ServerLock &lock)
2615
2557
{
2619
2561
    if (isAncestorTo (below, w))
2620
2562
        return false;
2621
2563
 
2622
 
    if (clientLeader && below->priv->clientLeader == clientLeader)
2623
 
        if (below->priv->isGroupTransient (clientLeader))
2624
 
            return false;
 
2564
    if (clientLeader && below->priv->clientLeader == clientLeader &&
 
2565
        below->priv->isGroupTransient (clientLeader))
 
2566
        return false;
2625
2567
 
2626
2568
    if (w->priv->state & CompWindowStateAboveMask)
2627
 
    {
2628
2569
        return true;
2629
 
    }
2630
2570
    else if (w->priv->state & CompWindowStateBelowMask)
2631
2571
    {
2632
2572
        if (below->priv->state & CompWindowStateBelowMask)
2633
2573
            return true;
2634
2574
    }
2635
2575
    else if (!(below->priv->state & CompWindowStateAboveMask))
2636
 
    {
2637
2576
        return true;
2638
 
    }
2639
2577
 
2640
2578
    return false;
2641
2579
}
2644
2582
PrivateWindow::avoidStackingRelativeTo (CompWindow       *w,
2645
2583
                                        const ServerLock &lock)
2646
2584
{
2647
 
    if (w->overrideRedirect ())
2648
 
        return true;
2649
 
 
2650
 
    if (w->destroyed ())
2651
 
        return true;
2652
 
 
2653
 
    bool allowRelativeToUnmmaped = w->priv->receivedMapRequestAndAwaitingMap ||
2654
 
                                   w->priv->shaded ||
 
2585
    bool allowRelativeToUnmapped = w->priv->receivedMapRequestAndAwaitingMap    ||
 
2586
                                   w->priv->shaded                              ||
2655
2587
                                   w->priv->pendingMaps;
2656
2588
 
2657
 
    if (!allowRelativeToUnmmaped)
2658
 
    {
2659
 
        if (!w->isViewable () || !w->isMapped ())
2660
 
            return true;
2661
 
    }
 
2589
    if ((w->overrideRedirect () || w->destroyed ()) ||
 
2590
        (!allowRelativeToUnmapped && (!w->isViewable () || !w->isMapped ())))
 
2591
        return true;
2662
2592
 
2663
2593
    return false;
2664
2594
}
2672
2602
                                 const ServerLock &lock)
2673
2603
{
2674
2604
    CompWindow   *below;
2675
 
    CompWindow   *t = screen->findWindow (w->transientFor ());
2676
 
    Window       clientLeader = w->priv->clientLeader;
2677
 
    unsigned int type = w->priv->type;
 
2605
    CompWindow   *t           = screen->findWindow (w->transientFor ());
 
2606
    Window       clientLeader = w->priv->clientLeader;
 
2607
    unsigned int type         = w->priv->type;
2678
2608
    unsigned int belowMask;
2679
2609
 
2680
2610
    if (aboveFs)
2709
2639
        if (below->priv->type & CompWindowTypeDesktopMask)
2710
2640
            return below;
2711
2641
 
2712
 
        switch (type) {
2713
 
        case CompWindowTypeDesktopMask:
2714
 
            /* desktop window layer */
2715
 
            break;
2716
 
        case CompWindowTypeFullscreenMask:
2717
 
            if (aboveFs)
2718
 
                return below;
2719
 
            /* otherwise fall-through */
2720
 
        case CompWindowTypeDockMask:
2721
 
            /* fullscreen and dock layer */
2722
 
            if (below->priv->type & (CompWindowTypeFullscreenMask |
2723
 
                               CompWindowTypeDockMask))
2724
 
            {
2725
 
                if (stackLayerCheck (w, clientLeader, below, lock) &&
2726
 
                    existsOnServer (below, lock))
2727
 
                    return below;
2728
 
            }
2729
 
            else
2730
 
            {
2731
 
                return below;
2732
 
            }
2733
 
            break;
2734
 
        default:
 
2642
        switch (type)
2735
2643
        {
2736
 
            bool allowedRelativeToLayer = !(below->priv->type & belowMask);
2737
 
 
2738
 
            if (aboveFs && below->priv->type & CompWindowTypeFullscreenMask)
2739
 
                if (!below->focus ())
 
2644
            case CompWindowTypeDesktopMask:
 
2645
                /* desktop window layer */
 
2646
                break;
 
2647
 
 
2648
            case CompWindowTypeFullscreenMask:
 
2649
                if (aboveFs)
 
2650
                    return below;
 
2651
                /* otherwise fall-through */
 
2652
            case CompWindowTypeDockMask:
 
2653
                /* fullscreen and dock layer */
 
2654
                if (below->priv->type & (CompWindowTypeFullscreenMask |
 
2655
                                         CompWindowTypeDockMask))
 
2656
                {
 
2657
                    if (stackLayerCheck (w, clientLeader, below, lock) &&
 
2658
                        existsOnServer (below, lock))
 
2659
                        return below;
 
2660
                }
 
2661
                else
 
2662
                    return below;
 
2663
 
 
2664
                break;
 
2665
 
 
2666
            default:
 
2667
            {
 
2668
                bool allowedRelativeToLayer = !(below->priv->type & belowMask);
 
2669
 
 
2670
                if (aboveFs && below->priv->type & CompWindowTypeFullscreenMask &&
 
2671
                    !below->focus ())
2740
2672
                    break;
2741
2673
 
2742
 
            t = screen->findWindow (below->transientFor ());
2743
 
 
2744
 
            while (t && allowedRelativeToLayer)
2745
 
            {
2746
 
                /* dock stacking of transients for docks */
2747
 
                allowedRelativeToLayer = !(t->priv->type & belowMask);
2748
 
 
2749
 
                t = screen->findWindow (t->transientFor ());
2750
 
            }
2751
 
 
2752
 
            /* fullscreen and normal layer */
2753
 
            if (allowedRelativeToLayer)
2754
 
            {
2755
 
                if (stackLayerCheck (w, clientLeader, below, lock) &&
 
2674
                t = screen->findWindow (below->transientFor ());
 
2675
 
 
2676
                while (t && allowedRelativeToLayer)
 
2677
                {
 
2678
                    /* dock stacking of transients for docks */
 
2679
                    allowedRelativeToLayer = !(t->priv->type & belowMask);
 
2680
 
 
2681
                    t = screen->findWindow (t->transientFor ());
 
2682
                }
 
2683
 
 
2684
                /* fullscreen and normal layer */
 
2685
                if (allowedRelativeToLayer                          &&
 
2686
                    stackLayerCheck (w, clientLeader, below, lock)  &&
2756
2687
                    existsOnServer (below, lock))
2757
2688
                    return below;
 
2689
 
 
2690
                break;
2758
2691
            }
2759
 
            break;
2760
 
        }
2761
2692
        }
2762
2693
    }
2763
2694
 
2771
2702
                                       const ServerLock &lock)
2772
2703
{
2773
2704
    CompWindow   *below, *lowest = screen->serverWindows ().back ();
2774
 
    CompWindow   *t = screen->findWindow (w->transientFor ());
2775
 
    Window       clientLeader = w->priv->clientLeader;
2776
 
    unsigned int type = w->priv->type;
 
2705
    CompWindow   *t              = screen->findWindow (w->transientFor ());
 
2706
    Window       clientLeader    = w->priv->clientLeader;
 
2707
    unsigned int type            = w->priv->type;
2777
2708
 
2778
2709
    /* normal stacking fullscreen windows with below state */
2779
 
    if ((type & CompWindowTypeFullscreenMask) &&
2780
 
        (w->priv->state & CompWindowStateBelowMask))
 
2710
    if (type & CompWindowTypeFullscreenMask &&
 
2711
        w->priv->state & CompWindowStateBelowMask)
2781
2712
        type = CompWindowTypeNormalMask;
2782
2713
 
2783
2714
    while (t && type != CompWindowTypeDockMask)
2789
2720
        t = screen->findWindow (t->transientFor ());
2790
2721
    }
2791
2722
 
2792
 
 
2793
2723
    if (w->priv->transientFor || w->priv->isGroupTransient (clientLeader))
2794
2724
        clientLeader = None;
2795
2725
 
2800
2730
            continue;
2801
2731
 
2802
2732
        /* always above desktop windows */
2803
 
        if ((below->priv->type & CompWindowTypeDesktopMask) &&
 
2733
        if (below->priv->type & CompWindowTypeDesktopMask &&
2804
2734
            existsOnServer (below, lock))
2805
2735
            return below;
2806
2736
 
2807
 
        switch (type) {
2808
 
        case CompWindowTypeDesktopMask:
2809
 
            /* desktop window layer - desktop windows always should be
 
2737
        switch (type)
 
2738
        {
 
2739
            case CompWindowTypeDesktopMask:
 
2740
                /* desktop window layer - desktop windows always should be
2810
2741
               stacked at the bottom; no other window should be below them */
2811
 
            return NULL;
2812
 
            break;
2813
 
        case CompWindowTypeFullscreenMask:
2814
 
        case CompWindowTypeDockMask:
2815
 
            /* fullscreen and dock layer */
2816
 
            if (below->priv->type & (CompWindowTypeFullscreenMask |
2817
 
                               CompWindowTypeDockMask))
2818
 
            {
2819
 
                if (!stackLayerCheck (below, clientLeader, w, lock) &&
2820
 
                    existsOnServer (lowest, lock))
2821
 
                    return lowest;
2822
 
            }
2823
 
            else if (existsOnServer (lowest, lock))
2824
 
                return lowest;
2825
 
            break;
2826
 
        default:
2827
 
        {
2828
 
            bool allowedRelativeToLayer = !(below->priv->type & CompWindowTypeDockMask);
2829
 
 
2830
 
            t = screen->findWindow (below->transientFor ());
2831
 
 
2832
 
            while (t && allowedRelativeToLayer)
2833
 
            {
2834
 
                /* dock stacking of transients for docks */
2835
 
                allowedRelativeToLayer = !(t->priv->type & CompWindowTypeDockMask);
2836
 
 
2837
 
                t = screen->findWindow (t->transientFor ());
2838
 
            }
2839
 
 
2840
 
            /* fullscreen and normal layer */
2841
 
            if (allowedRelativeToLayer)
2842
 
            {
2843
 
                if (!stackLayerCheck (below, clientLeader, w, lock) &&
2844
 
                    existsOnServer (lowest, lock))
2845
 
                    return lowest;
2846
 
            }
2847
 
            break;
2848
 
        }
 
2742
                return NULL;
 
2743
                break;
 
2744
 
 
2745
            case CompWindowTypeFullscreenMask:
 
2746
            case CompWindowTypeDockMask:
 
2747
                /* fullscreen and dock layer */
 
2748
                if (below->priv->type & (CompWindowTypeFullscreenMask |
 
2749
                                         CompWindowTypeDockMask))
 
2750
                {
 
2751
                    if (!stackLayerCheck (below, clientLeader, w, lock) &&
 
2752
                        existsOnServer (lowest, lock))
 
2753
                        return lowest;
 
2754
                }
 
2755
                else if (existsOnServer (lowest, lock))
 
2756
                    return lowest;
 
2757
 
 
2758
                break;
 
2759
 
 
2760
            default:
 
2761
            {
 
2762
                bool allowedRelativeToLayer = !(below->priv->type & CompWindowTypeDockMask);
 
2763
 
 
2764
                t = screen->findWindow (below->transientFor ());
 
2765
 
 
2766
                while (t && allowedRelativeToLayer)
 
2767
                {
 
2768
                    /* dock stacking of transients for docks */
 
2769
                    allowedRelativeToLayer = !(t->priv->type & CompWindowTypeDockMask);
 
2770
 
 
2771
                    t = screen->findWindow (t->transientFor ());
 
2772
                }
 
2773
 
 
2774
                /* fullscreen and normal layer */
 
2775
                if (allowedRelativeToLayer                          &&
 
2776
                    !stackLayerCheck (below, clientLeader, w, lock) &&
 
2777
                    existsOnServer (lowest, lock))
 
2778
                    return lowest;
 
2779
 
 
2780
                break;
 
2781
            }
2849
2782
        }
2850
2783
 
2851
2784
        lowest = below;
2866
2799
                                  CompWindow       *sibling,
2867
2800
                                  const ServerLock &lock)
2868
2801
{
2869
 
    CompWindow   *t = screen->findWindow (w->transientFor ());
2870
 
    Window       clientLeader = w->priv->clientLeader;
2871
 
    unsigned int type = w->priv->type;
 
2802
    CompWindow   *t           = screen->findWindow (w->transientFor ());
 
2803
    Window       clientLeader = w->priv->clientLeader;
 
2804
    unsigned int type         = w->priv->type;
2872
2805
 
2873
2806
    /* normal stacking fullscreen windows with below state */
2874
2807
    if ((type & CompWindowTypeFullscreenMask) &&
2884
2817
        t = screen->findWindow (t->transientFor ());
2885
2818
    }
2886
2819
 
2887
 
 
2888
2820
    if (w->priv->transientFor || w->priv->isGroupTransient (clientLeader))
2889
2821
        clientLeader = None;
2890
2822
 
2895
2827
    if (sibling->priv->type & CompWindowTypeDesktopMask)
2896
2828
        return true;
2897
2829
 
2898
 
    switch (type) {
2899
 
    case CompWindowTypeDesktopMask:
2900
 
        /* desktop window layer */
2901
 
        break;
2902
 
    case CompWindowTypeFullscreenMask:
2903
 
    case CompWindowTypeDockMask:
2904
 
        /* fullscreen and dock layer */
2905
 
        if (sibling->priv->type & (CompWindowTypeFullscreenMask |
2906
 
                             CompWindowTypeDockMask))
2907
 
        {
2908
 
            if (stackLayerCheck (w, clientLeader, sibling, lock) &&
2909
 
                existsOnServer (sibling, lock))
2910
 
                return true;
2911
 
        }
2912
 
        else if (existsOnServer (sibling, lock))
2913
 
            return true;
2914
 
        break;
2915
 
    default:
 
2830
    switch (type)
2916
2831
    {
2917
 
        bool allowedRelativeToLayer = !(sibling->priv->type & CompWindowTypeDockMask);
2918
 
 
2919
 
        t = screen->findWindow (sibling->transientFor ());
2920
 
 
2921
 
        while (t && allowedRelativeToLayer)
2922
 
        {
2923
 
            /* dock stacking of transients for docks */
2924
 
            allowedRelativeToLayer = !(t->priv->type & CompWindowTypeDockMask);
2925
 
 
2926
 
            t = screen->findWindow (t->transientFor ());
2927
 
        }
2928
 
 
2929
 
        /* fullscreen and normal layer */
2930
 
        if (allowedRelativeToLayer)
2931
 
        {
2932
 
            if (stackLayerCheck (w, clientLeader, sibling, lock) &&
 
2832
        case CompWindowTypeDesktopMask:
 
2833
            /* desktop window layer */
 
2834
            break;
 
2835
 
 
2836
        case CompWindowTypeFullscreenMask:
 
2837
        case CompWindowTypeDockMask:
 
2838
            /* fullscreen and dock layer */
 
2839
            if (sibling->priv->type & (CompWindowTypeFullscreenMask |
 
2840
                                       CompWindowTypeDockMask))
 
2841
            {
 
2842
                if (stackLayerCheck (w, clientLeader, sibling, lock) &&
 
2843
                    existsOnServer (sibling, lock))
 
2844
                    return true;
 
2845
            }
 
2846
            else if (existsOnServer (sibling, lock))
 
2847
                return true;
 
2848
 
 
2849
            break;
 
2850
 
 
2851
        default:
 
2852
        {
 
2853
            bool allowedRelativeToLayer = !(sibling->priv->type & CompWindowTypeDockMask);
 
2854
 
 
2855
            t = screen->findWindow (sibling->transientFor ());
 
2856
 
 
2857
            while (t && allowedRelativeToLayer)
 
2858
            {
 
2859
                /* dock stacking of transients for docks */
 
2860
                allowedRelativeToLayer = !(t->priv->type & CompWindowTypeDockMask);
 
2861
 
 
2862
                t = screen->findWindow (t->transientFor ());
 
2863
            }
 
2864
 
 
2865
            /* fullscreen and normal layer */
 
2866
            if (allowedRelativeToLayer                              &&
 
2867
                stackLayerCheck (w, clientLeader, sibling, lock)    &&
2933
2868
                existsOnServer (sibling, lock))
2934
2869
                return true;
 
2870
 
 
2871
            break;
2935
2872
        }
2936
 
        break;
2937
 
    }
2938
2873
    }
2939
2874
 
2940
2875
    return false;
2986
2921
        /* This is not perfect but it works OK for now. If the saved width is
2987
2922
           the same as the current width then make it a little be smaller so
2988
2923
           the user can see that it changed and it also makes sure that
2989
 
           windowResizeNotify is called and plugins are notified. */
 
2924
           windowResizeNotify is called and plugins are notified.
 
2925
           TODO: Eliminate these arbitrary magic numbers here */
2990
2926
        if (xwc->width == (int) serverGeometry.width ())
2991
2927
        {
2992
2928
            xwc->width -= 10;
 
2929
 
2993
2930
            if (m & CWX)
2994
2931
                xwc->x += 5;
2995
2932
        }
3000
2937
        xwc->height = saveWc.height;
3001
2938
 
3002
2939
        /* As above, if the saved height is the same as the current height
3003
 
           then make it a little be smaller. */
 
2940
           then make it a little be smaller.
 
2941
           TODO: As above, find a better solution without magic numbers here */
3004
2942
        if (xwc->height == (int) serverGeometry.height ())
3005
2943
        {
3006
2944
            xwc->height -= 10;
 
2945
 
3007
2946
            if (m & CWY)
3008
2947
                xwc->y += 5;
3009
2948
        }
3026
2965
}
3027
2966
 
3028
2967
static bool isExistingRequest (const compiz::X11::PendingEvent::Ptr &p,
3029
 
                               XWindowChanges &xwc,
3030
 
                               unsigned int valueMask)
 
2968
                               XWindowChanges                       &xwc,
 
2969
                               unsigned int                         valueMask)
3031
2970
{
3032
2971
    compiz::X11::PendingConfigureEvent::Ptr pc =
3033
2972
            boost::static_pointer_cast <compiz::X11::PendingConfigureEvent> (p);
3048
2987
}
3049
2988
 
3050
2989
XRectangle *
3051
 
PrivateWindow::queryShapeRectangles (int kind, int *count, int *ordering)
 
2990
PrivateWindow::queryShapeRectangles (int kind,
 
2991
                                     int *count,
 
2992
                                     int *ordering)
3052
2993
{
3053
2994
    return configureBuffer->queryShapeRectangles (kind, count, ordering);
3054
2995
}
3055
2996
 
3056
2997
int
3057
2998
PrivateWindow::requestConfigureOnClient (const XWindowChanges &xwc,
3058
 
                                         unsigned int valueMask)
 
2999
                                         unsigned int         valueMask)
3059
3000
{
3060
3001
    return XConfigureWindow (screen->dpy (),
3061
3002
                             id,
3065
3006
 
3066
3007
int
3067
3008
PrivateWindow::requestConfigureOnWrapper (const XWindowChanges &xwc,
3068
 
                                          unsigned int valueMask)
 
3009
                                          unsigned int         valueMask)
3069
3010
{
3070
3011
    return XConfigureWindow (screen->dpy (),
3071
3012
                             wrapper,
3075
3016
 
3076
3017
int
3077
3018
PrivateWindow::requestConfigureOnFrame (const XWindowChanges &xwc,
3078
 
                                        unsigned int frameValueMask)
 
3019
                                        unsigned int         frameValueMask)
3079
3020
{
3080
3021
    XWindowChanges wc = xwc;
3081
3022
 
3121
3062
 
3122
3063
    /* Remove redundant bits */
3123
3064
 
3124
 
    xwc->x = valueMask & CWX ? xwc->x : serverGeometry.x ();
3125
 
    xwc->y = valueMask & CWY ? xwc->y : serverGeometry.y ();
3126
 
    xwc->width = valueMask & CWWidth ? xwc->width : serverGeometry.width ();
3127
 
    xwc->height = valueMask & CWHeight ? xwc->height : serverGeometry.height ();
 
3065
    xwc->x            = valueMask & CWX           ? xwc->x            : serverGeometry.x ();
 
3066
    xwc->y            = valueMask & CWY           ? xwc->y            : serverGeometry.y ();
 
3067
    xwc->width        = valueMask & CWWidth       ? xwc->width        : serverGeometry.width ();
 
3068
    xwc->height       = valueMask & CWHeight      ? xwc->height       : serverGeometry.height ();
3128
3069
    xwc->border_width = valueMask & CWBorderWidth ? xwc->border_width : serverGeometry.border ();
3129
3070
 
3130
3071
    /* Don't allow anything that might generate a BadValue */
3140
3081
        xwc->height = 1;
3141
3082
    }
3142
3083
 
3143
 
    int dx = valueMask & CWX ? xwc->x - serverGeometry.x () : 0;
3144
 
    int dy = valueMask & CWY ? xwc->y - serverGeometry.y () : 0;
3145
 
    int dwidth = valueMask & CWWidth ? xwc->width - serverGeometry.width () : 0;
 
3084
    int dx      = valueMask & CWX      ? xwc->x - serverGeometry.x ()           : 0;
 
3085
    int dy      = valueMask & CWY      ? xwc->y - serverGeometry.y ()           : 0;
 
3086
    int dwidth  = valueMask & CWWidth  ? xwc->width  - serverGeometry.width ()  : 0;
3146
3087
    int dheight = valueMask & CWHeight ? xwc->height - serverGeometry.height () : 0;
3147
3088
 
3148
3089
    /* FIXME: This is a total fallacy for the reparenting case
3163
3104
    if (valueMask & CWBorderWidth && serverGeometry.border () == xwc->border_width)
3164
3105
        valueMask &= ~(CWBorderWidth);
3165
3106
 
3166
 
    if (valueMask & CWSibling && window->serverPrev)
 
3107
    /* check if the sibling is also pending a restack,
 
3108
     * if not, then setting this bit is useless */
 
3109
    if (valueMask & CWSibling && window->serverPrev &&
 
3110
        ROOTPARENT (window->serverPrev) == xwc->sibling)
3167
3111
    {
3168
 
        /* check if the sibling is also pending a restack,
3169
 
         * if not, then setting this bit is useless */
3170
 
        if (ROOTPARENT (window->serverPrev) == xwc->sibling)
3171
 
        {
3172
 
            bool matchingRequest = priv->pendingConfigures.forEachIf (boost::bind (isExistingRequest, _1, *xwc, valueMask));
3173
 
            bool restackPending = window->serverPrev->priv->pendingConfigures.forEachIf (boost::bind (isPendingRestack, _1));
3174
 
            bool remove = matchingRequest;
3175
 
 
3176
 
            if (!remove)
3177
 
                remove = !restackPending;
3178
 
 
3179
 
            if (remove)
3180
 
                valueMask &= ~(CWSibling | CWStackMode);
3181
 
        }
 
3112
        bool matchingRequest = priv->pendingConfigures.forEachIf (boost::bind (isExistingRequest, _1, *xwc, valueMask));
 
3113
        bool restackPending  = window->serverPrev->priv->pendingConfigures.forEachIf (boost::bind (isPendingRestack, _1));
 
3114
        bool remove          = matchingRequest;
 
3115
 
 
3116
        if (!remove)
 
3117
            remove = !restackPending;
 
3118
 
 
3119
        if (remove)
 
3120
            valueMask &= ~(CWSibling | CWStackMode);
3182
3121
    }
3183
3122
 
3184
3123
    if (valueMask & CWBorderWidth)
3222
3161
    if (serverFrameGeometry.y () == xwc->y - serverGeometry.border () - serverInput.top)
3223
3162
        frameValueMask &= ~(CWY);
3224
3163
 
3225
 
   if (serverFrameGeometry.width () == xwc->width + serverGeometry.border () * 2
3226
 
                                      + serverInput.left + serverInput.right)
 
3164
   if (serverFrameGeometry.width () == xwc->width + serverGeometry.border () * 2 +
 
3165
                                       serverInput.left + serverInput.right)
3227
3166
        frameValueMask &= ~(CWWidth);
3228
3167
 
3229
3168
    /* shaded windows are not allowed to have their frame window
3232
3171
 
3233
3172
    if (shaded)
3234
3173
    {
3235
 
        if (serverFrameGeometry.height () == serverGeometry.border () * 2
3236
 
            + serverInput.top + serverInput.bottom)
 
3174
        if (serverFrameGeometry.height () == serverGeometry.border () * 2 +
 
3175
            serverInput.top + serverInput.bottom)
3237
3176
            frameValueMask &= ~(CWHeight);
3238
3177
    }
3239
3178
    else
3240
3179
    {
3241
 
        if (serverFrameGeometry.height () == xwc->height + serverGeometry.border () * 2
3242
 
            + serverInput.top + serverInput.bottom)
 
3180
        if (serverFrameGeometry.height () == xwc->height + serverGeometry.border () * 2 +
 
3181
            serverInput.top + serverInput.bottom)
3243
3182
            frameValueMask &= ~(CWHeight);
3244
3183
    }
3245
3184
 
3246
3185
 
3247
 
    if (valueMask & CWStackMode &&
3248
 
        ((xwc->stack_mode != TopIf) && (xwc->stack_mode != BottomIf) && (xwc->stack_mode != Opposite) &&
3249
 
         (xwc->stack_mode != Above) && (xwc->stack_mode != Below)))
 
3186
    if (valueMask & CWStackMode     &&
 
3187
        xwc->stack_mode != TopIf    &&
 
3188
        xwc->stack_mode != BottomIf &&
 
3189
        xwc->stack_mode != Opposite &&
 
3190
        xwc->stack_mode != Above    &&
 
3191
        xwc->stack_mode != Below)
3250
3192
    {
3251
3193
        compLogMessage ("core", CompLogLevelWarn, "Invalid stack mode %i", xwc->stack_mode);
3252
3194
        valueMask &= ~(CWStackMode | CWSibling);
3300
3242
        serverFrameGeometry.setY (xwc->y -serverGeometry.border () - serverInput.top);
3301
3243
 
3302
3244
    if (frameValueMask & CWWidth)
3303
 
        serverFrameGeometry.setWidth (xwc->width + serverGeometry.border () * 2
3304
 
                                      + serverInput.left + serverInput.right);
 
3245
        serverFrameGeometry.setWidth (xwc->width + serverGeometry.border () * 2 +
 
3246
                                      serverInput.left + serverInput.right);
3305
3247
 
3306
3248
    if (shaded)
3307
3249
    {
3308
3250
        if (frameValueMask & CWHeight)
3309
 
            serverFrameGeometry.setHeight (serverGeometry.border () * 2
3310
 
                                           + serverInput.top + serverInput.bottom);
3311
 
    }
3312
 
    else
3313
 
    {
3314
 
        if (frameValueMask & CWHeight)
3315
 
            serverFrameGeometry.setHeight (xwc->height + serverGeometry.border () * 2
3316
 
                                           + serverInput.top + serverInput.bottom);
3317
 
    }
 
3251
            serverFrameGeometry.setHeight (serverGeometry.border () * 2 +
 
3252
                                           serverInput.top + serverInput.bottom);
 
3253
    }
 
3254
    else if (frameValueMask & CWHeight)
 
3255
        serverFrameGeometry.setHeight (xwc->height + serverGeometry.border () * 2 +
 
3256
                                       serverInput.top + serverInput.bottom);
3318
3257
 
3319
3258
    if (serverFrame)
3320
3259
    {
3328
3267
         * update the client and wrapper position */
3329
3268
        if (lastServerInput.left != serverInput.left)
3330
3269
            valueMask |= CWX;
 
3270
 
3331
3271
        if (lastServerInput.top != serverInput.top)
3332
3272
            valueMask |= CWY;
3333
3273
 
3334
3274
        /* Calculate frame extents and protect against underflow */
3335
 
        const unsigned int lastWrapperWidth = std::max (0, serverFrameGeometry.width () -
3336
 
                                                           (lastServerInput.right + lastServerInput.left));
 
3275
        const unsigned int lastWrapperWidth  = std::max (0, serverFrameGeometry.width () -
 
3276
                                                         (lastServerInput.right + lastServerInput.left));
3337
3277
        const unsigned int lastWrapperHeight = std::max (0, serverFrameGeometry.height () -
3338
 
                                                            (lastServerInput.bottom + lastServerInput.top));
3339
 
        const unsigned int wrapperWidth = std::max (0, serverFrameGeometry.width () -
3340
 
                                                       (serverInput.right + serverInput.left));
3341
 
        const unsigned int wrapperHeight = std::max (0, serverFrameGeometry.height () -
3342
 
                                                        (serverInput.bottom + serverInput.top));
 
3278
                                                         (lastServerInput.bottom + lastServerInput.top));
 
3279
        const unsigned int wrapperWidth      = std::max (0, serverFrameGeometry.width () -
 
3280
                                                         (serverInput.right + serverInput.left));
 
3281
        const unsigned int wrapperHeight     = std::max (0, serverFrameGeometry.height () -
 
3282
                                                         (serverInput.bottom + serverInput.top));
3343
3283
 
3344
3284
        if (lastWrapperWidth != wrapperWidth)
3345
3285
            valueMask |= CWWidth;
 
3286
 
3346
3287
        if (lastWrapperHeight != wrapperHeight)
3347
3288
            valueMask |= CWHeight;
3348
3289
 
3373
3314
     * the absolute position */
3374
3315
    if (dx)
3375
3316
        valueMask |= CWX;
 
3317
 
3376
3318
    if (dy)
3377
3319
        valueMask |= CWY;
 
3320
 
3378
3321
    if (dwidth)
3379
3322
        valueMask |= CWWidth;
 
3323
 
3380
3324
    if (dheight)
3381
3325
        valueMask |= CWHeight;
3382
3326
 
3391
3335
        {
3392
3336
            region.translate (dx, dy);
3393
3337
            inputRegion.translate (dx, dy);
 
3338
 
3394
3339
            if (!frameRegion.isEmpty ())
3395
3340
                frameRegion.translate (dx, dy);
3396
3341
 
3411
3356
                           const ServerLock &lock)
3412
3357
{
3413
3358
    CompWindow *firstFullscreenWindow = NULL;
3414
 
    CompWindow *belowDocks = NULL;
 
3359
    CompWindow *belowDocks            = NULL;
 
3360
    bool       currentlyManaged, visible, ancestorToClient, acceptableType;
3415
3361
 
3416
3362
    foreach (CompWindow *dw, screen->serverWindows ())
3417
3363
    {
3418
 
        /* fullscreen window found */
3419
 
        if (firstFullscreenWindow)
3420
 
        {
 
3364
        /* fullscreen window found */
 
3365
        if (firstFullscreenWindow)
 
3366
        {
 
3367
            currentlyManaged = dw->priv->managed && !dw->priv->unmanaging;
 
3368
            visible          = !(dw->state () & CompWindowStateHiddenMask);
 
3369
            ancestorToClient = PrivateWindow::isAncestorTo (w, dw);
 
3370
            acceptableType   = !(dw->type () & (CompWindowTypeFullscreenMask |
 
3371
                                                CompWindowTypeDockMask));
 
3372
 
3421
3373
            /* If there is another toplevel window above the fullscreen one
3422
3374
             * then we need to stack above that */
3423
 
            bool currentlyManaged = dw->priv->managed && !dw->priv->unmanaging;
3424
 
            bool visible = !(dw->state () & CompWindowStateHiddenMask);
3425
 
            bool ancestorToClient = PrivateWindow::isAncestorTo (w, dw);
3426
 
            bool acceptableType = !(dw->type () & (CompWindowTypeFullscreenMask |
3427
 
                                                   CompWindowTypeDockMask));
3428
 
            if (currentlyManaged &&
3429
 
                visible &&
3430
 
                acceptableType &&
3431
 
                !ancestorToClient &&
3432
 
                !dw->overrideRedirect () &&
3433
 
                dw->isViewable ())
3434
 
            {
3435
 
                if (existsOnServer (dw, lock))
3436
 
                    belowDocks = dw;
3437
 
            }
3438
 
        }
3439
 
        else if (dw->type () & CompWindowTypeFullscreenMask)
3440
 
        {
 
3375
            if (currentlyManaged            &&
 
3376
                visible                     &&
 
3377
                acceptableType              &&
 
3378
                !ancestorToClient           &&
 
3379
                !dw->overrideRedirect ()    &&
 
3380
                dw->isViewable ()           &&
 
3381
                existsOnServer (dw, lock))
 
3382
                belowDocks = dw;
 
3383
        }
 
3384
        else if (dw->type () & CompWindowTypeFullscreenMask)
 
3385
        {
3441
3386
            /* First fullscreen window found when checking up the stack
3442
3387
             * now go back down to find a suitable candidate client
3443
3388
             * window to put the docks above */
3444
 
            firstFullscreenWindow = dw;
 
3389
            firstFullscreenWindow = dw;
 
3390
 
3445
3391
            for (CompWindow *dww = dw->serverPrev; dww; dww = dww->serverPrev)
3446
 
            {
3447
 
                bool currentlyManaged = dw->priv->managed && !dw->priv->unmanaging;
3448
 
                bool visible = !(dw->priv->state & CompWindowStateHiddenMask);
3449
 
                bool acceptableType = !(dww->type () & (CompWindowTypeFullscreenMask |
3450
 
                                                        CompWindowTypeDockMask));
3451
 
                if (currentlyManaged &&
3452
 
                    visible &&
3453
 
                    acceptableType &&
3454
 
                    !dww->overrideRedirect () &&
3455
 
                    dww->isViewable ())
3456
 
                {
3457
 
                    if (existsOnServer (dww, lock))
3458
 
                    {
3459
 
                        belowDocks = dww;
3460
 
                        break;
3461
 
                    }
3462
 
                }
3463
 
            }
3464
 
        }
 
3392
            {
 
3393
                currentlyManaged = dw->priv->managed && !dw->priv->unmanaging;
 
3394
                visible          = !(dw->state () & CompWindowStateHiddenMask);
 
3395
                acceptableType   = !(dw->type () & (CompWindowTypeFullscreenMask |
 
3396
                                                    CompWindowTypeDockMask));
 
3397
 
 
3398
                if (currentlyManaged            &&
 
3399
                    visible                     &&
 
3400
                    acceptableType              &&
 
3401
                    !dww->overrideRedirect ()   &&
 
3402
                    dww->isViewable ()          &&
 
3403
                    existsOnServer (dww, lock))
 
3404
                {
 
3405
                    belowDocks = dww;
 
3406
                    break;
 
3407
                }
 
3408
            }
 
3409
        }
3465
3410
    }
3466
3411
 
3467
3412
    if (belowDocks)
3468
3413
    {
3469
 
        *mask = CWSibling | CWStackMode;
3470
 
        xwc->sibling = ROOTPARENT (belowDocks);
 
3414
        *mask = CWSibling | CWStackMode;
 
3415
        xwc->sibling = ROOTPARENT (belowDocks);
3471
3416
 
3472
 
        /* Collect all dock windows first */
 
3417
        /* Collect all dock windows first */
3473
3418
        foreach (CompWindow *dw, screen->serverWindows ())
3474
 
            if (dw->priv->type & CompWindowTypeDockMask)
3475
 
                updateList.push_front (dw);
 
3419
            if (dw->priv->type & CompWindowTypeDockMask)
 
3420
                updateList.push_front (dw);
3476
3421
 
3477
 
        return true;
 
3422
        return true;
3478
3423
    }
3479
3424
 
3480
3425
    return false;
3481
3426
}
3482
3427
 
3483
3428
bool
3484
 
PrivateWindow::stackTransients (CompWindow       *w,
3485
 
                                CompWindow       *avoid,
 
3429
PrivateWindow::stackTransients (CompWindow       *w,
 
3430
                                CompWindow       *avoid,
3486
3431
                                XWindowChanges   *xwc,
3487
3432
                                CompWindowList   &updateList,
3488
3433
                                const ServerLock &lock)
3489
3434
{
3490
 
    CompWindow *t;
3491
 
    Window     clientLeader = w->priv->clientLeader;
 
3435
    Window clientLeader = w->priv->clientLeader;
3492
3436
 
3493
3437
    if (w->priv->transientFor || w->priv->isGroupTransient (clientLeader))
3494
3438
        clientLeader = None;
3495
3439
 
3496
 
    for (t = screen->serverWindows ().back (); t; t = t->serverPrev)
 
3440
    for (CompWindow *t = screen->serverWindows ().back (); t; t = t->serverPrev)
3497
3441
    {
3498
3442
        if (t == w || t == avoid)
3499
3443
            continue;
3501
3445
        if (t->priv->transientFor == w->priv->id ||
3502
3446
            t->priv->isGroupTransient (clientLeader))
3503
3447
        {
3504
 
            if (!stackTransients (t, avoid, xwc, updateList, lock))
3505
 
                return false;
3506
 
 
3507
 
            if (xwc->sibling == t->priv->id ||
 
3448
            if (!stackTransients (t, avoid, xwc, updateList, lock)  ||
 
3449
                xwc->sibling == t->priv->id                         ||
3508
3450
                (t->priv->serverFrame && xwc->sibling == t->priv->serverFrame))
3509
3451
                return false;
3510
3452
 
3511
 
            if (t->priv->mapNum || t->priv->pendingMaps)
3512
 
            {
3513
 
                if (existsOnServer (t, lock))
3514
 
                    updateList.push_back (t);
3515
 
            }
 
3453
            if ((t->priv->mapNum || t->priv->pendingMaps) &&
 
3454
                existsOnServer (t, lock))
 
3455
                updateList.push_back (t);
3516
3456
        }
3517
3457
    }
3518
3458
 
3534
3474
        xwc->sibling != transient->priv->id &&
3535
3475
        (!transient->priv->serverFrame || xwc->sibling != transient->priv->serverFrame))
3536
3476
    {
3537
 
        CompWindow *ancestor;
 
3477
        CompWindow *ancestor = screen->findWindow (w->priv->transientFor);
3538
3478
 
3539
 
        ancestor = screen->findWindow (w->priv->transientFor);
3540
3479
        if (ancestor)
3541
3480
        {
3542
 
            if (!stackTransients (ancestor, w, xwc, updateList, lock))
3543
 
                return;
3544
 
 
3545
 
            if (ancestor->priv->type & CompWindowTypeDesktopMask)
3546
 
                return;
3547
 
 
3548
 
            if (ancestor->priv->type & CompWindowTypeDockMask)
3549
 
                if (!(w->priv->type & CompWindowTypeDockMask))
3550
 
                    return;
3551
 
 
3552
 
            if (ancestor->priv->mapNum || ancestor->priv->pendingMaps)
3553
 
                if (existsOnServer (ancestor, lock))
3554
 
                    updateList.push_back (ancestor);
 
3481
            if (!stackTransients (ancestor, w, xwc, updateList, lock)   ||
 
3482
                ancestor->priv->type & CompWindowTypeDesktopMask        ||
 
3483
                (ancestor->priv->type & CompWindowTypeDockMask && !(w->priv->type & CompWindowTypeDockMask)))
 
3484
                return;
 
3485
 
 
3486
            if ((ancestor->priv->mapNum || ancestor->priv->pendingMaps) &&
 
3487
                existsOnServer (ancestor, lock))
 
3488
                updateList.push_back (ancestor);
3555
3489
 
3556
3490
            stackAncestors (ancestor, xwc, updateList, lock);
3557
3491
        }
3558
3492
    }
3559
3493
    else if (w->priv->isGroupTransient (w->priv->clientLeader))
3560
3494
    {
3561
 
        CompWindow *a;
3562
 
 
3563
 
        for (a = screen->serverWindows ().back (); a; a = a->serverPrev)
 
3495
        for (CompWindow *a = screen->serverWindows ().back (); a; a = a->serverPrev)
3564
3496
        {
3565
3497
            if (a->priv->clientLeader == w->priv->clientLeader &&
3566
3498
                a->priv->transientFor == None                  &&
3567
3499
                !a->priv->isGroupTransient (w->priv->clientLeader))
3568
3500
            {
3569
3501
                if (xwc->sibling == a->priv->id ||
3570
 
                    (a->priv->serverFrame && xwc->sibling == a->priv->serverFrame))
3571
 
                    break;
3572
 
 
3573
 
                if (!stackTransients (a, w, xwc, updateList, lock))
 
3502
                    (a->priv->serverFrame && xwc->sibling == a->priv->serverFrame) ||
 
3503
                    !stackTransients (a, w, xwc, updateList, lock))
3574
3504
                    break;
3575
3505
 
3576
3506
                if (a->priv->type & CompWindowTypeDesktopMask)
3577
3507
                    continue;
3578
3508
 
3579
 
                if (a->priv->type & CompWindowTypeDockMask)
3580
 
                    if (!(w->priv->type & CompWindowTypeDockMask))
3581
 
                        break;
 
3509
                if (a->priv->type & CompWindowTypeDockMask &&
 
3510
                    !(w->priv->type & CompWindowTypeDockMask))
 
3511
                    break;
3582
3512
 
3583
 
                if (a->priv->mapNum || a->priv->pendingMaps)
3584
 
                    if (existsOnServer (a, lock))
3585
 
                        updateList.push_back (a);
 
3513
                if ((a->priv->mapNum || a->priv->pendingMaps) &&
 
3514
                    existsOnServer (a, lock))
 
3515
                    updateList.push_back (a);
3586
3516
            }
3587
3517
        }
3588
3518
    }
3651
3581
                Window sibling = xwc->sibling;
3652
3582
                xwc->stack_mode = Above;
3653
3583
 
3654
 
                /* Then update the dock windows */
3655
 
                foreach (CompWindow *dw, docks)
3656
 
                {
3657
 
                    xwc->sibling = sibling;
3658
 
                    dw->priv->reconfigureXWindow (valueMask, xwc);
3659
 
                }
3660
 
            }
 
3584
                /* Then update the dock windows */
 
3585
                foreach (CompWindow *dw, docks)
 
3586
                {
 
3587
                    xwc->sibling = sibling;
 
3588
                    dw->priv->reconfigureXWindow (valueMask, xwc);
 
3589
                }
 
3590
            }
3661
3591
        }
3662
3592
    }
3663
3593
    else if (priv->id)
3664
 
    {
3665
3594
        priv->reconfigureXWindow (valueMask, xwc);
3666
 
    }
3667
3595
}
3668
3596
 
3669
3597
int
3670
3598
PrivateWindow::addWindowSizeChanges (XWindowChanges       *xwc,
3671
3599
                                     CompWindow::Geometry old)
3672
3600
{
3673
 
    CompRect  workArea;
3674
 
    int       mask = 0;
3675
 
    int       x, y;
3676
 
    CompOutput *output;
 
3601
    int       mask = 0;
3677
3602
    CompPoint viewport;
3678
3603
 
3679
3604
    screen->viewportForGeometry (old, viewport);
3680
3605
 
3681
 
    x = (viewport.x () - screen->vp ().x ()) * screen->width ();
3682
 
    y = (viewport.y () - screen->vp ().y ()) * screen->height ();
 
3606
    int x = (viewport.x () - screen->vp ().x ()) * screen->width ();
 
3607
    int y = (viewport.y () - screen->vp ().y ()) * screen->height ();
3683
3608
 
3684
 
    /* Try to select and output device that the window is on first
3685
 
     * and make sure if we are fullscreening or maximizing that the
3686
 
     * window is actually able to fit on this output ... otherwise
3687
 
     * we're going to have to use another output device which sucks
3688
 
     * but at least the user will be able to see all of the window */
3689
 
    output   = &screen->outputDevs ().at (screen->outputDeviceForGeometry (old));
 
3609
    CompOutput *output = &screen->outputDevs ().at (screen->outputDeviceForGeometry (old));
3690
3610
 
3691
3611
    /*
3692
3612
     * output is now the correct output for the given geometry.
3703
3623
     * the user never asked to.
3704
3624
     */
3705
3625
 
3706
 
    workArea = output->workArea ();
 
3626
    CompRect workArea = output->workArea ();
3707
3627
 
3708
3628
    if (type & CompWindowTypeFullscreenMask)
3709
3629
    {
3731
3651
    else
3732
3652
    {
3733
3653
        mask |= restoreGeometry (xwc, CWBorderWidth);
 
3654
 
3734
3655
        if (state & CompWindowStateMaximizedVertMask)
3735
3656
        {
3736
3657
            saveGeometry (CWY | CWHeight);
3741
3662
            mask |= CWHeight;
3742
3663
        }
3743
3664
        else
3744
 
        {
3745
3665
            mask |= restoreGeometry (xwc, CWY | CWHeight);
3746
 
        }
3747
3666
 
3748
3667
        if (state & CompWindowStateMaximizedHorzMask)
3749
3668
        {
3755
3674
            mask |= CWWidth;
3756
3675
        }
3757
3676
        else
3758
 
        {
3759
3677
            mask |= restoreGeometry (xwc, CWX | CWWidth);
3760
 
        }
3761
3678
 
3762
3679
        /* constrain window width if smaller than minimum width */
3763
3680
        if (!(mask & CWWidth) && (int) old.width () < sizeHints.min_width)
3789
3706
 
3790
3707
        if (mask & (CWWidth | CWHeight))
3791
3708
        {
3792
 
            int width, height, max;
 
3709
            int max;
3793
3710
 
3794
 
            width  = (mask & CWWidth)  ? xwc->width  : old.width ();
3795
 
            height = (mask & CWHeight) ? xwc->height : old.height ();
 
3711
            int width   = (mask & CWWidth)  ? xwc->width  : old.width ();
 
3712
            int height  = (mask & CWHeight) ? xwc->height : old.height ();
3796
3713
 
3797
3714
            xwc->width  = old.width ();
3798
3715
            xwc->height = old.height ();
3839
3756
                            mask |= CWY;
3840
3757
                        }
3841
3758
                        break;
3842
 
                    /* For EastGravity, WestGravity and CenterGravity we default to the top
 
3759
 
 
3760
                    /* TODO: check if this is correct:
 
3761
                     * For EastGravity, WestGravity and CenterGravity we default to the top
3843
3762
                     * of the window since the user should at least be able to close it
3844
3763
                     * (but not for SouthGravity, SouthWestGravity and SouthEastGravity since
3845
 
                     * that indicates that the application has requested positioning in that area
 
3764
                     * that indicates that the application has requested positioning in that area)
3846
3765
                     */
3847
3766
                    case EastGravity:
3848
3767
                    case WestGravity:
3867
3786
                    case SouthEastGravity:
3868
3787
                    case EastGravity:
3869
3788
                        width = xwc->width + old.border () * 2;
3870
 
 
3871
 
                        max = x + workArea.right ();
 
3789
                        max   = x + workArea.right ();
3872
3790
 
3873
3791
                        if (old.x () + (int) old.width () + border.right > max)
3874
3792
                        {
3882
3800
                                      border.right) / 2 + border.left;
3883
3801
                            mask |= CWX;
3884
3802
                        }
3885
 
                    /* For NorthGravity, SouthGravity and CenterGravity we default to the top
 
3803
                    /* TODO: check if this is correct, note that there is no break here:
 
3804
                     * For NorthGravity, SouthGravity and CenterGravity we default to the top
3886
3805
                     * of the window since the user should at least be able to close it
3887
3806
                     * (but not for SouthGravity, SouthWestGravity and SouthEastGravity since
3888
 
                     * that indicates that the application has requested positioning in that area
 
3807
                     * that indicates that the application has requested positioning in that area)
3889
3808
                     */
3890
3809
                    case NorthGravity:
3891
3810
                    case SouthGravity:
3919
3838
PrivateWindow::adjustConfigureRequestForGravity (XWindowChanges *xwc,
3920
3839
                                                 unsigned int   xwcm,
3921
3840
                                                 int            gravity,
3922
 
                                                 int            direction)
 
3841
                                                 int            direction)
3923
3842
{
3924
 
    int          newX, newY;
3925
3843
    unsigned int mask = 0;
3926
 
 
3927
 
    newX = xwc->x;
3928
 
    newY = xwc->y;
 
3844
    int          newX = xwc->x;
 
3845
    int          newY = xwc->y;
3929
3846
 
3930
3847
    if (xwcm & (CWX | CWWidth))
3931
3848
    {
3932
 
        switch (gravity) {
3933
 
        case NorthWestGravity:
3934
 
        case WestGravity:
3935
 
        case SouthWestGravity:
3936
 
            if (xwcm & CWX)
3937
 
                newX += priv->border.left * direction;
3938
 
            break;
3939
 
 
3940
 
        case NorthGravity:
3941
 
        case CenterGravity:
3942
 
        case SouthGravity:
3943
 
            if (xwcm & CWX)
3944
 
                newX -= (xwc->width / 2 - priv->border.left +
3945
 
                        (priv->border.left + priv->border.right) / 2) * direction;
3946
 
            else
3947
 
                newX -= (xwc->width - priv->serverGeometry.width ()) * direction;
3948
 
            break;
3949
 
 
3950
 
        case NorthEastGravity:
3951
 
        case EastGravity:
3952
 
        case SouthEastGravity:
3953
 
            if (xwcm & CWX)
3954
 
                newX -= xwc->width + priv->border.right * direction;
3955
 
            else
3956
 
                newX -= (xwc->width - priv->serverGeometry.width ()) * direction;
3957
 
            break;
3958
 
 
3959
 
        case StaticGravity:
3960
 
        default:
3961
 
            break;
 
3849
        switch (gravity)
 
3850
        {
 
3851
            case NorthWestGravity:
 
3852
            case WestGravity:
 
3853
            case SouthWestGravity:
 
3854
                if (xwcm & CWX)
 
3855
                    newX += priv->border.left * direction;
 
3856
                break;
 
3857
 
 
3858
            case NorthGravity:
 
3859
            case CenterGravity:
 
3860
            case SouthGravity:
 
3861
                if (xwcm & CWX)
 
3862
                    newX -= (xwc->width / 2 - priv->border.left +
 
3863
                             (priv->border.left + priv->border.right) / 2) * direction;
 
3864
                else
 
3865
                    newX -= (xwc->width - priv->serverGeometry.width ()) * direction;
 
3866
 
 
3867
                break;
 
3868
 
 
3869
            case NorthEastGravity:
 
3870
            case EastGravity:
 
3871
            case SouthEastGravity:
 
3872
                if (xwcm & CWX)
 
3873
                    newX -= xwc->width + priv->border.right * direction;
 
3874
                else
 
3875
                    newX -= (xwc->width - priv->serverGeometry.width ()) * direction;
 
3876
 
 
3877
                break;
 
3878
 
 
3879
            case StaticGravity:
 
3880
            default:
 
3881
                break;
3962
3882
        }
3963
3883
    }
3964
3884
 
3965
3885
    if (xwcm & (CWY | CWHeight))
3966
3886
    {
3967
 
        switch (gravity) {
3968
 
        case NorthWestGravity:
3969
 
        case NorthGravity:
3970
 
        case NorthEastGravity:
3971
 
            if (xwcm & CWY)
3972
 
                newY = xwc->y + priv->border.top * direction;
3973
 
            break;
3974
 
 
3975
 
        case WestGravity:
3976
 
        case CenterGravity:
3977
 
        case EastGravity:
3978
 
            if (xwcm & CWY)
3979
 
                newY -= (xwc->height / 2 - priv->border.top +
3980
 
                        (priv->border.top + priv->border.bottom) / 2) * direction;
3981
 
            else
3982
 
                newY -= ((xwc->height - priv->serverGeometry.height ()) / 2) * direction;
3983
 
            break;
3984
 
 
3985
 
        case SouthWestGravity:
3986
 
        case SouthGravity:
3987
 
        case SouthEastGravity:
3988
 
            if (xwcm & CWY)
3989
 
                newY -= xwc->height + priv->border.bottom * direction;
3990
 
            else
3991
 
                newY -= (xwc->height - priv->serverGeometry.height ()) * direction;
3992
 
            break;
3993
 
 
3994
 
        case StaticGravity:
3995
 
        default:
3996
 
            break;
 
3887
        switch (gravity)
 
3888
        {
 
3889
            case NorthWestGravity:
 
3890
            case NorthGravity:
 
3891
            case NorthEastGravity:
 
3892
                if (xwcm & CWY)
 
3893
                    newY = xwc->y + priv->border.top * direction;
 
3894
 
 
3895
                break;
 
3896
 
 
3897
            case WestGravity:
 
3898
            case CenterGravity:
 
3899
            case EastGravity:
 
3900
                if (xwcm & CWY)
 
3901
                    newY -= (xwc->height / 2 - priv->border.top +
 
3902
                             (priv->border.top + priv->border.bottom) / 2) * direction;
 
3903
                else
 
3904
                    newY -= ((xwc->height - priv->serverGeometry.height ()) / 2) * direction;
 
3905
 
 
3906
                break;
 
3907
 
 
3908
            case SouthWestGravity:
 
3909
            case SouthGravity:
 
3910
            case SouthEastGravity:
 
3911
                if (xwcm & CWY)
 
3912
                    newY -= xwc->height + priv->border.bottom * direction;
 
3913
                else
 
3914
                    newY -= (xwc->height - priv->serverGeometry.height ()) * direction;
 
3915
 
 
3916
                break;
 
3917
 
 
3918
            case StaticGravity:
 
3919
            default:
 
3920
                break;
3997
3921
        }
3998
3922
    }
3999
3923
 
4022
3946
 
4023
3947
    xwcm &= (CWX | CWY | CWWidth | CWHeight | CWBorderWidth);
4024
3948
 
4025
 
    if (xwcm & (CWX | CWY))
4026
 
        if (priv->sizeHints.flags & (USPosition | PPosition))
4027
 
            placed = true;
 
3949
    if (xwcm & (CWX | CWY) &&
 
3950
        priv->sizeHints.flags & (USPosition | PPosition))
 
3951
        placed = true;
4028
3952
 
4029
3953
    if (gravity == 0)
4030
3954
        gravity = priv->sizeHints.win_gravity;
4031
3955
 
4032
3956
    if (!(xwcm & CWX))
4033
3957
        xwc->x = priv->serverGeometry.x ();
 
3958
 
4034
3959
    if (!(xwcm & CWY))
4035
3960
        xwc->y = priv->serverGeometry.y ();
 
3961
 
4036
3962
    if (!(xwcm & CWWidth))
4037
 
        xwc->width = priv->serverGeometry.width ();
 
3963
        xwc->width  = priv->serverGeometry.width ();
 
3964
 
4038
3965
    if (!(xwcm & CWHeight))
4039
3966
        xwc->height = priv->serverGeometry.height ();
4040
3967
 
4108
4035
    if (xwcm)
4109
4036
        configureXWindow (xwcm, xwc);
4110
4037
    else
4111
 
    {
4112
4038
        /* we have to send a configure notify on ConfigureRequest events if
4113
4039
           we decide not to do anything according to ICCCM 4.1.5 */
4114
4040
        sendConfigureNotify ();
4115
 
    }
4116
4041
 
4117
4042
    if (placed)
4118
4043
        priv->placed = true;
4124
4049
    if (window->overrideRedirect () || !managed)
4125
4050
        return false;
4126
4051
 
4127
 
    XWindowChanges xwc = XWINDOWCHANGES_INIT;
 
4052
    XWindowChanges xwc  = XWINDOWCHANGES_INIT;
 
4053
    int            mask = priv->addWindowSizeChanges (&xwc, priv->serverGeometry);
4128
4054
 
4129
 
    int mask = priv->addWindowSizeChanges (&xwc, priv->serverGeometry);
4130
4055
    if (mask)
4131
4056
    {
4132
4057
        if (priv->mapNum && (mask & (CWWidth | CWHeight)))
4154
4079
        {
4155
4080
            if (!sibling && id)
4156
4081
            {
4157
 
                XWindowChanges lxwc = XWINDOWCHANGES_INIT;
 
4082
                XWindowChanges lxwc      = XWINDOWCHANGES_INIT;
4158
4083
                unsigned int   valueMask = CWStackMode;
4159
4084
 
4160
4085
                lxwc.stack_mode = Below;
4178
4103
            else if (sibling)
4179
4104
            {
4180
4105
                bool matchingRequest = priv->pendingConfigures.forEachIf (boost::bind (isExistingRequest, _1, *xwc, (CWStackMode | CWSibling)));
4181
 
                bool restackPending = window->serverPrev->priv->pendingConfigures.forEachIf (boost::bind (isPendingRestack, _1));
4182
 
                bool processAnyways = restackPending;
 
4106
                bool restackPending  = window->serverPrev->priv->pendingConfigures.forEachIf (boost::bind (isPendingRestack, _1));
 
4107
                bool processAnyways  = restackPending;
4183
4108
 
4184
4109
                if (matchingRequest)
4185
4110
                    processAnyways = false;
4209
4134
void
4210
4135
CompWindow::raise ()
4211
4136
{
4212
 
    XWindowChanges xwc = XWINDOWCHANGES_INIT;
4213
 
    int            mask;
4214
 
    bool           aboveFs = false;
 
4137
    XWindowChanges xwc     = XWINDOWCHANGES_INIT;
 
4138
    int            mask;
 
4139
    bool           aboveFs = false;
4215
4140
 
4216
4141
    /* an active fullscreen window should be raised over all other
4217
4142
       windows in its layer */
4218
 
    if (priv->type & CompWindowTypeFullscreenMask)
4219
 
        if (priv->id == screen->activeWindow ())
4220
 
            aboveFs = true;
 
4143
    if (priv->type & CompWindowTypeFullscreenMask &&
 
4144
        priv->id == screen->activeWindow ())
 
4145
        aboveFs = true;
4221
4146
 
4222
4147
    for (CompWindow *pw = serverPrev; pw; pw = pw->serverPrev)
4223
 
    {
4224
 
        if (pw->priv->type & CompWindowTypeFullscreenMask)
4225
 
        {
4226
 
            if (priv->id == screen->activeWindow ())
4227
 
                aboveFs = true;
4228
 
 
 
4148
        if (pw->priv->type & CompWindowTypeFullscreenMask &&
 
4149
            priv->id == screen->activeWindow ())
 
4150
            aboveFs = true;
 
4151
        else
4229
4152
            break;
4230
 
        }
4231
 
    }
4232
4153
 
4233
4154
    ServerLock lock (screen->serverGrabInterface ());
4234
4155
 
4244
4165
{
4245
4166
    using ::compiz::private_screen::WindowManager;
4246
4167
 
4247
 
    CompWindow  *focus = NULL;
4248
 
    WindowManager::reverse_iterator it = windowManager.rserverBegin ();
 
4168
    CompWindow                      *focus = NULL;
 
4169
    WindowManager::reverse_iterator it     = windowManager.rserverBegin ();
4249
4170
 
4250
4171
    for (; it != windowManager.rserverEnd (); ++it)
4251
4172
    {
4267
4188
            focus->moveInputFocusTo ();
4268
4189
    }
4269
4190
    else
4270
 
        XSetInputFocus (privateScreen.dpy, privateScreen.rootWindow(), RevertToPointerRoot,
 
4191
        XSetInputFocus (privateScreen.dpy, privateScreen.rootWindow (), RevertToPointerRoot,
4271
4192
                        CurrentTime);
4272
4193
    return focus;
4273
4194
}
4277
4198
CompWindow::lower ()
4278
4199
{
4279
4200
    XWindowChanges xwc = XWINDOWCHANGES_INIT;
4280
 
    int            mask;
4281
4201
 
4282
4202
    ServerLock lock (screen->serverGrabInterface ());
4283
4203
 
4284
 
    mask = priv->addWindowStackChanges (&xwc,
 
4204
    int mask = priv->addWindowStackChanges (&xwc,
4285
4205
        PrivateWindow::findLowestSiblingBelow (this, lock), lock);
 
4206
 
4286
4207
    if (mask)
4287
4208
        restackAndConfigureXWindow (mask, &xwc, lock);
4288
4209
 
4289
4210
    /* when lowering a window, focus the topmost window if
4290
4211
       the click-to-focus option is on */
4291
 
    if ((screen->getCoreOptions().optionGetClickToFocus ()))
 
4212
    if ((screen->getCoreOptions ().optionGetClickToFocus ()))
4292
4213
    {
4293
4214
        CompWindow *focusedWindow = screen->focusTopMostWindow ();
4294
4215
 
4296
4217
           give the focus back to w */
4297
4218
        if (focusedWindow &&
4298
4219
            focusedWindow->type () & CompWindowTypeDesktopMask)
4299
 
        {
4300
4220
            moveInputFocusTo ();
4301
 
        }
4302
4221
    }
4303
4222
}
4304
4223
 
4313
4232
 
4314
4233
    if (sibling)
4315
4234
    {
4316
 
        XWindowChanges xwc = XWINDOWCHANGES_INIT;
4317
 
        int            mask;
 
4235
        XWindowChanges xwc  = XWINDOWCHANGES_INIT;
 
4236
        int            mask = priv->addWindowStackChanges (&xwc, sibling, lock);
4318
4237
 
4319
 
        mask = priv->addWindowStackChanges (&xwc, sibling, lock);
4320
4238
        if (mask)
4321
4239
            restackAndConfigureXWindow (mask, &xwc, lock);
4322
4240
    }
4336
4254
     * underneath it */
4337
4255
 
4338
4256
    for (p = sibling; p; p = p->serverNext)
4339
 
    {
4340
 
        if (!avoidStackingRelativeTo (p, lock))
4341
 
        {
4342
 
            if (!validSiblingBelow (p, w, lock))
4343
 
                return NULL;
 
4257
        if (!avoidStackingRelativeTo (p, lock) &&
 
4258
            !validSiblingBelow (p, w, lock))
 
4259
            return NULL;
 
4260
        else
4344
4261
            break;
4345
 
        }
4346
 
    }
4347
4262
 
4348
4263
    /* get lowest sibling we're allowed to stack above */
4349
4264
    lowest = last = findLowestSiblingBelow (w, lock);
4360
4275
        if (w == p || avoidStackingRelativeTo (p, lock))
4361
4276
            continue;
4362
4277
 
4363
 
        if (validSiblingBelow (w, p, lock))
4364
 
        {
 
4278
        if (validSiblingBelow (w, p, lock) &&
 
4279
            last == lowest)
4365
4280
            /* update lowest as we find windows below sibling that we're
4366
4281
               allowed to stack above. last window must be equal to the
4367
4282
               lowest as we shouldn't update lowest if we passed an
4368
4283
               invalid window */
4369
 
            if (last == lowest)
4370
 
                lowest = p;
4371
 
        }
 
4284
            lowest = p;
4372
4285
 
4373
4286
        /* update last pointer */
4374
4287
        last = p;
4381
4294
CompWindow::restackBelow (CompWindow *sibling)
4382
4295
{
4383
4296
    XWindowChanges xwc = XWINDOWCHANGES_INIT;
4384
 
    unsigned int   mask;
4385
4297
 
4386
4298
    ServerLock lock (screen->serverGrabInterface ());
4387
4299
 
4388
 
    mask = priv->addWindowStackChanges (&xwc,
 
4300
    unsigned int mask = priv->addWindowStackChanges (&xwc,
4389
4301
        PrivateWindow::findValidStackSiblingBelow (this, sibling, lock), lock);
4390
4302
 
4391
4303
    if (mask)
4394
4306
 
4395
4307
namespace
4396
4308
{
4397
 
void addSizeChangesSyncAndReconfigure (PrivateWindow        *priv,
4398
 
                                       XWindowChanges       &xwc,
4399
 
                                       unsigned int         mask,
4400
 
                                       ServerLock           *lock)
 
4309
void addSizeChangesSyncAndReconfigure (PrivateWindow  *priv,
 
4310
                                       XWindowChanges &xwc,
 
4311
                                       unsigned int   mask,
 
4312
                                       ServerLock     *lock)
4401
4313
{
4402
4314
    mask |= priv->addWindowSizeChanges (&xwc, priv->serverGeometry);
4403
4315
 
4420
4332
    if (overrideRedirect () || !priv->managed)
4421
4333
        return;
4422
4334
 
4423
 
    XWindowChanges xwc = XWINDOWCHANGES_INIT;
4424
 
    int            mask = 0;
 
4335
    XWindowChanges xwc  = XWINDOWCHANGES_INIT;
 
4336
    int            mask = 0;
4425
4337
 
4426
4338
    if (priv->state & CompWindowStateShadedMask && !priv->shaded)
4427
4339
    {
4428
4340
        windowNotify (CompWindowNotifyShade);
4429
 
 
4430
4341
        priv->hide ();
4431
4342
    }
4432
4343
    else if (priv->shaded)
4433
4344
    {
4434
4345
        windowNotify (CompWindowNotifyUnshade);
4435
 
 
4436
4346
        priv->show ();
4437
4347
    }
4438
4348
 
4439
4349
    if (stackingMode != CompStackingUpdateModeNone)
4440
4350
    {
4441
 
        bool       aboveFs;
4442
4351
        CompWindow *sibling;
4443
4352
 
4444
 
        aboveFs = (stackingMode == CompStackingUpdateModeAboveFullscreen);
4445
 
        if (priv->type & CompWindowTypeFullscreenMask)
4446
 
        {
 
4353
        bool aboveFs = (stackingMode == CompStackingUpdateModeAboveFullscreen);
 
4354
 
 
4355
        if (priv->type & CompWindowTypeFullscreenMask &&
4447
4356
            /* put active or soon-to-be-active fullscreen windows over
4448
4357
               all others in their layer */
4449
 
            if (priv->id == screen->activeWindow () ||
4450
 
                priv->id == screen->getNextActiveWindow())
4451
 
            {
4452
 
                aboveFs = true;
4453
 
            }
4454
 
        }
 
4358
            (priv->id == screen->activeWindow () ||
 
4359
             priv->id == screen->getNextActiveWindow ()))
 
4360
            aboveFs = true;
4455
4361
 
4456
4362
        /* put windows that are just mapped, over fullscreen windows */
4457
4363
        if (stackingMode == CompStackingUpdateModeInitialMap)
4488
4394
        /* If sibling is NULL, then this window will go on the bottom
4489
4395
         * of the stack */
4490
4396
        mask |= priv->addWindowStackChanges (&xwc, sibling, lock);
4491
 
        addSizeChangesSyncAndReconfigure (priv,
4492
 
                                          xwc,
4493
 
                                          mask,
4494
 
                                          &lock);
 
4397
        addSizeChangesSyncAndReconfigure (priv, xwc, mask, &lock);
4495
4398
    }
4496
4399
    else
4497
 
        addSizeChangesSyncAndReconfigure (priv,
4498
 
                                          xwc,
4499
 
                                          mask,
4500
 
                                          NULL);
 
4400
        addSizeChangesSyncAndReconfigure (priv, xwc, mask, NULL);
4501
4401
}
4502
4402
 
4503
4403
void
4506
4406
    if (struts || attrib.override_redirect)
4507
4407
        return;
4508
4408
 
4509
 
    if (type & (CompWindowTypeDockMask       |
 
4409
    if (type & (CompWindowTypeDockMask       |
4510
4410
                CompWindowTypeFullscreenMask |
4511
4411
                CompWindowTypeUnknownMask))
4512
4412
        return;
4513
4413
 
4514
 
    int x1 = screen->workArea ().x () - screen->width () * screen->vp ().x ();
4515
 
    int y1 = screen->workArea ().y () - screen->height () * screen->vp ().y ();
4516
 
    int x2 = x1 + screen->workArea ().width () + screen->vpSize ().width () *
4517
 
         screen->width ();
4518
 
    int y2 = y1 + screen->workArea ().height () + screen->vpSize ().height () *
4519
 
         screen->height ();
4520
 
 
4521
 
    int dx = 0;
4522
 
    int width = serverGeometry.widthIncBorders ();
4523
 
 
 
4414
    int x1     = screen->workArea ().x () - screen->width ()  * screen->vp ().x ();
 
4415
    int y1     = screen->workArea ().y () - screen->height () * screen->vp ().y ();
 
4416
    int x2     = x1 + screen->workArea ().width ()  + screen->vpSize ().width ()  *
 
4417
                 screen->width ();
 
4418
    int y2     = y1 + screen->workArea ().height () + screen->vpSize ().height () *
 
4419
                 screen->height ();
 
4420
 
 
4421
    int dx     = 0;
 
4422
    int width  = serverGeometry.widthIncBorders ();
 
4423
 
 
4424
    // TODO: Eliminate those magic numbers below
4524
4425
    if (serverGeometry.x () - serverInput.left >= x2)
4525
4426
        dx = (x2 - 25) - serverGeometry.x ();
4526
4427
    else if (serverGeometry.x () + width + serverInput.right <= x1)
4527
4428
        dx = (x1 + 25) - (serverGeometry.x () + width);
4528
4429
 
4529
 
    int dy = 0;
 
4430
    int dy     = 0;
4530
4431
    int height = serverGeometry.heightIncBorders ();
4531
4432
 
4532
4433
    if (serverGeometry.y () - serverInput.top >= y2)
4570
4471
 
4571
4472
    screen->setCurrentDesktop (priv->desktop);
4572
4473
 
4573
 
    screen->forEachWindow (
4574
 
        boost::bind (PrivateWindow::revealAncestors, _1, this));
 
4474
    screen->forEachWindow (boost::bind (PrivateWindow::revealAncestors, _1, this));
4575
4475
    priv->reveal ();
4576
4476
 
4577
4477
    screen->leaveShowDesktopMode (this);
4579
4479
    if (priv->state & CompWindowStateHiddenMask)
4580
4480
    {
4581
4481
        priv->state &= ~CompWindowStateShadedMask;
 
4482
 
4582
4483
        if (priv->shaded)
4583
4484
            priv->show ();
4584
4485
    }
4585
4486
 
4586
 
    if (priv->state & CompWindowStateHiddenMask)
4587
 
        return;
4588
 
 
4589
 
    if (!onCurrentDesktop ())
 
4487
    if (priv->state & CompWindowStateHiddenMask ||
 
4488
        !onCurrentDesktop ())
4590
4489
        return;
4591
4490
 
4592
4491
    priv->ensureWindowVisibility ();
4594
4493
    moveInputFocusTo ();
4595
4494
}
4596
4495
 
4597
 
 
4598
4496
#define PVertResizeInc (1 << 0)
4599
4497
#define PHorzResizeInc (1 << 1)
4600
4498
 
4601
4499
bool
4602
 
CompWindow::constrainNewWindowSize (int        width,
4603
 
                                    int        height,
4604
 
                                    int        *newWidth,
4605
 
                                    int        *newHeight)
 
4500
CompWindow::constrainNewWindowSize (int width,
 
4501
                                    int height,
 
4502
                                    int *newWidth,
 
4503
                                    int *newHeight)
4606
4504
{
4607
 
    CompSize         size (width, height);
4608
 
    long             ignoredHints = 0;
4609
 
    long             ignoredResizeHints = 0;
 
4505
    CompSize size (width, height);
 
4506
    long     ignoredHints       = 0;
 
4507
    long     ignoredResizeHints = 0;
4610
4508
 
4611
 
    if (screen->getCoreOptions().optionGetIgnoreHintsWhenMaximized ())
 
4509
    if (screen->getCoreOptions ().optionGetIgnoreHintsWhenMaximized ())
4612
4510
    {
4613
4511
        ignoredHints |= PAspect;
4614
4512
 
4623
4521
                                                                    size,
4624
4522
                                                                    ignoredHints, ignoredResizeHints);
4625
4523
 
4626
 
    *newWidth = ret.width ();
 
4524
    *newWidth  = ret.width ();
4627
4525
    *newHeight = ret.height ();
4628
4526
 
4629
4527
    return ret != size;
4651
4549
 
4652
4550
    bool onDesktop = window->onCurrentDesktop ();
4653
4551
 
4654
 
    if (!window->minimized () && !inShowDesktopMode &&
4655
 
        !hidden && onDesktop)
 
4552
    if (!window->minimized ()   &&
 
4553
        !inShowDesktopMode      &&
 
4554
        !hidden                 &&
 
4555
        onDesktop)
4656
4556
    {
4657
4557
        if (state & CompWindowStateShadedMask)
4658
 
        {
4659
4558
            shaded = true;
4660
 
        }
4661
4559
        else
4662
 
        {
4663
4560
            return;
4664
 
        }
4665
4561
    }
4666
4562
    else
4667
4563
    {
4676
4572
 
4677
4573
    window->windowNotify (CompWindowNotifyHide);
4678
4574
 
4679
 
    pendingUnmaps++;
 
4575
    ++pendingUnmaps;
4680
4576
 
4681
4577
    if (serverFrame && !shaded)
4682
4578
        XUnmapWindow (screen->dpy (), serverFrame);
4698
4594
 
4699
4595
    bool onDesktop = window->onCurrentDesktop ();
4700
4596
 
4701
 
    if (minimized || inShowDesktopMode ||
4702
 
        hidden    || !onDesktop)
 
4597
    if (minimized || inShowDesktopMode || hidden || !onDesktop)
4703
4598
    {
4704
4599
        /* no longer hidden but not on current desktop */
4705
4600
        if (!minimized && !inShowDesktopMode && !hidden)
4723
4618
 
4724
4619
    window->windowNotify (CompWindowNotifyShow);
4725
4620
 
4726
 
    pendingMaps++;
 
4621
    ++pendingMaps;
4727
4622
 
4728
4623
    if (serverFrame)
4729
4624
    {
4743
4638
{
4744
4639
    if (w->priv->transientFor == ancestor->priv->id ||
4745
4640
        w->priv->isGroupTransient (ancestor->priv->clientLeader))
4746
 
    {
4747
4641
        w->minimize ();
4748
 
    }
4749
4642
}
4750
4643
 
4751
4644
void
4817
4710
bool
4818
4711
PrivateWindow::getUserTime (Time& time)
4819
4712
{
4820
 
    Atom          actual;
4821
 
    int           result, format;
 
4713
    Atom          actual;
 
4714
    int           format;
4822
4715
    unsigned long n, left;
4823
4716
    unsigned char *data;
4824
4717
    bool          retval = false;
4825
4718
 
4826
 
    result = XGetWindowProperty (screen->dpy (), priv->id,
4827
 
                                 Atoms::wmUserTime,
4828
 
                                 0L, 1L, False, XA_CARDINAL, &actual, &format,
4829
 
                                 &n, &left, &data);
 
4719
    int result = XGetWindowProperty (screen->dpy (), priv->id,
 
4720
                                     Atoms::wmUserTime,
 
4721
                                     0L, 1L, False, XA_CARDINAL, &actual, &format,
 
4722
                                     &n, &left, &data);
4830
4723
 
4831
4724
    if (result == Success && data)
4832
4725
    {
4902
4795
bool
4903
4796
PrivateWindow::isWindowFocusAllowed (Time timestamp)
4904
4797
{
4905
 
    CompScreen   *s = screen;
 
4798
    CompScreen   *s           = screen;
4906
4799
    CompWindow   *active;
4907
 
    Time         wUserTime, aUserTime;
 
4800
    Time         wUserTime, aUserTime;
4908
4801
    bool         gotTimestamp = false;
4909
 
    int          level;
4910
4802
    CompPoint    dvp;
4911
4803
 
4912
 
    level = s->getCoreOptions().optionGetFocusPreventionLevel ();
 
4804
    int level = s->getCoreOptions ().optionGetFocusPreventionLevel ();
4913
4805
 
4914
4806
    if (level == CoreOptions::FocusPreventionLevelOff)
4915
4807
        return true;
4918
4810
    {
4919
4811
        /* the caller passed a timestamp, so use that
4920
4812
           instead of the window's user time */
4921
 
        wUserTime = timestamp;
 
4813
        wUserTime    = timestamp;
4922
4814
        gotTimestamp = true;
4923
4815
    }
4924
4816
    else
4925
 
    {
4926
4817
        gotTimestamp = getUsageTimestamp (wUserTime);
4927
 
    }
4928
4818
 
4929
4819
    /* if we got no timestamp for the window, try to get at least a timestamp
4930
4820
       for its transient parent, if any */
4931
4821
    if (!gotTimestamp && transientFor)
4932
4822
    {
4933
 
        CompWindow *parent;
 
4823
        CompWindow *parent = screen->findWindow (transientFor);
4934
4824
 
4935
 
        parent = screen->findWindow (transientFor);
4936
4825
        if (parent)
4937
4826
            gotTimestamp = parent->priv->getUsageTimestamp (wUserTime);
4938
4827
    }
4939
4828
 
4940
4829
    if (gotTimestamp && !wUserTime)
4941
 
    {
4942
4830
        /* window explicitly requested no focus */
4943
4831
        return false;
4944
 
    }
4945
4832
 
4946
4833
    /* allow focus for excluded windows */
4947
 
    CompMatch &match = s->getCoreOptions().optionGetFocusPreventionMatch ();
 
4834
    CompMatch &match = s->getCoreOptions ().optionGetFocusPreventionMatch ();
 
4835
 
4948
4836
    if (!match.evaluate (window))
4949
4837
        return true;
4950
4838
 
4954
4842
    active = s->findWindow (s->activeWindow ());
4955
4843
 
4956
4844
    /* no active window */
4957
 
    if (!active || (active->type () & CompWindowTypeDesktopMask))
 
4845
    if (!active || (active->type () & CompWindowTypeDesktopMask) ||
 
4846
        /* active window belongs to same application */
 
4847
        window->clientLeader () == active->clientLeader ())
4958
4848
        return true;
4959
4849
 
4960
 
    /* active window belongs to same application */
4961
 
    if (window->clientLeader () == active->clientLeader ())
4962
 
       return true;
4963
 
 
4964
4850
    if (level == CoreOptions::FocusPreventionLevelHigh)
4965
 
       return false;
 
4851
        return false;
4966
4852
 
4967
4853
    /* not in current viewport or desktop */
4968
4854
    if (!window->onCurrentDesktop ())
4969
4855
        return false;
4970
4856
 
4971
4857
    dvp = window->defaultViewport ();
 
4858
 
4972
4859
    if (dvp.x () != s->vp ().x () || dvp.y () != s->vp ().y ())
4973
4860
        return false;
4974
4861
 
4996
4883
PrivateWindow::allowWindowFocus (unsigned int noFocusMask,
4997
4884
                                 Time         timestamp)
4998
4885
{
4999
 
    bool retval;
5000
 
 
5001
4886
    if (priv->id == screen->activeWindow ())
5002
4887
        return true;
5003
4888
 
5004
4889
    /* do not focus windows of these types */
5005
 
    if (priv->type & noFocusMask)
5006
 
        return false;
5007
 
 
5008
 
    /* window doesn't take focus */
5009
 
    if (!priv->inputHint &&
5010
 
        !(priv->protocols & CompWindowProtocolTakeFocusMask))
5011
 
    {
5012
 
        return false;
5013
 
    }
5014
 
 
5015
 
    retval = priv->isWindowFocusAllowed (timestamp);
 
4890
    if (priv->type & noFocusMask    ||
 
4891
        /* window doesn't take focus */
 
4892
        !(priv->inputHint           ||
 
4893
        priv->protocols & CompWindowProtocolTakeFocusMask))
 
4894
        return false;
 
4895
 
 
4896
    bool retval = priv->isWindowFocusAllowed (timestamp);
 
4897
 
 
4898
    /* add demands attention state if focus was prevented */
5016
4899
    if (!retval)
5017
 
    {
5018
 
        /* add demands attention state if focus was prevented */
5019
4900
        window->changeState (priv->state | CompWindowStateDemandsAttentionMask);
5020
 
    }
5021
4901
 
5022
4902
    return retval;
5023
4903
}
5027
4907
{
5028
4908
    CompPoint viewport;
5029
4909
 
5030
 
    if (priv->serverGeometry.x () < (int) screen->width ()            &&
5031
 
        priv->serverGeometry.x () + priv->serverGeometry.width () > 0 &&
5032
 
        priv->serverGeometry.y () < (int) screen->height ()           &&
5033
 
        priv->serverGeometry.y ()+ priv->serverGeometry.height () > 0)
5034
 
    {
 
4910
    if (priv->serverGeometry.x () < (int) screen->width ()              &&
 
4911
        priv->serverGeometry.y () < (int) screen->height ()             &&
 
4912
        priv->serverGeometry.x () + priv->serverGeometry.width ()  > 0  &&
 
4913
        priv->serverGeometry.y () + priv->serverGeometry.height () > 0)
5035
4914
        return screen->vp ();
5036
 
    }
5037
4915
 
5038
4916
    screen->viewportForGeometry (priv->serverGeometry, viewport);
5039
4917
 
5049
4927
void
5050
4928
PrivateWindow::readIconHint ()
5051
4929
{
5052
 
    XImage       *image, *maskImage = NULL;
5053
 
    Display      *dpy = screen->dpy ();
 
4930
    XImage       *maskImage = NULL;
 
4931
    Display      *dpy       = screen->dpy ();
5054
4932
    unsigned int width, height, dummy;
5055
 
    unsigned int i, j, k;
5056
 
    int          iDummy;
 
4933
    unsigned int i, j;
 
4934
    int          iDummy;
5057
4935
    Window       wDummy;
5058
 
    CompIcon     *icon;
5059
 
    CARD32       *p;
5060
4936
 
5061
4937
    if (!XGetGeometry (dpy, hints->icon_pixmap, &wDummy, &iDummy,
5062
4938
                       &iDummy, &width, &height, &dummy, &dummy))
5063
4939
        return;
5064
4940
 
5065
 
    image = XGetImage (dpy, hints->icon_pixmap, 0, 0, width, height,
5066
 
                       AllPlanes, ZPixmap);
 
4941
    XImage *image = XGetImage (dpy, hints->icon_pixmap, 0, 0, width, height,
 
4942
                               AllPlanes, ZPixmap);
 
4943
 
5067
4944
    if (!image)
5068
4945
        return;
5069
4946
 
5074
4951
        return;
5075
4952
    }
5076
4953
 
5077
 
    k = 0;
5078
 
    for (j = 0; j < height; j++)
5079
 
        for (i = 0; i < width; i++)
 
4954
    unsigned int k = 0;
 
4955
 
 
4956
    for (j = 0; j < height; ++j)
 
4957
        for (i = 0; i < width; ++i)
5080
4958
            colors[k++].pixel = XGetPixel (image, i, j);
5081
4959
 
5082
4960
    for (i = 0; i < k; i += 256)
5083
 
        XQueryColors (dpy, screen->colormap(),
 
4961
        XQueryColors (dpy, screen->colormap (),
5084
4962
                      &colors[i], MIN (k - i, 256));
5085
4963
 
5086
4964
    XDestroyImage (image);
5087
4965
 
5088
 
    icon = new CompIcon (width, height);
 
4966
    CompIcon *icon = new CompIcon (width, height);
 
4967
 
5089
4968
    if (!icon)
5090
 
    {
5091
4969
        return;
5092
 
    }
5093
4970
 
5094
4971
    if (hints->flags & IconMaskHint)
5095
4972
        maskImage = XGetImage (dpy, hints->icon_mask, 0, 0,
5096
4973
                               width, height, AllPlanes, ZPixmap);
5097
4974
 
5098
 
    k = 0;
5099
 
    p = (CARD32 *) icon->data ();
 
4975
    k         = 0;
 
4976
    CARD32 *p = (CARD32 *) icon->data ();
5100
4977
 
5101
 
    for (j = 0; j < height; j++)
 
4978
    for (j = 0; j < height; ++j)
5102
4979
    {
5103
 
        for (i = 0; i < width; i++)
 
4980
        for (i = 0; i < width; ++i)
5104
4981
        {
5105
4982
            if (maskImage && !XGetPixel (maskImage, i, j))
5106
4983
                *p++ = 0;
5108
4985
                *p++ = colors[k].pixel ? 0xffffffff : 0xff000000;
5109
4986
            else
5110
4987
                *p++ = 0xff000000                             | /* alpha */
5111
 
                       (((colors[k].red >> 8) & 0xff) << 16)  | /* red */
 
4988
                       (((colors[k].red   >> 8) & 0xff) << 16)  | /* red */
5112
4989
                       (((colors[k].green >> 8) & 0xff) << 8) | /* green */
5113
 
                       ((colors[k].blue >> 8) & 0xff);          /* blue */
 
4990
                       ((colors[k].blue   >> 8) & 0xff);          /* blue */
5114
4991
 
5115
 
            k++;
 
4992
            ++k;
5116
4993
        }
5117
4994
    }
5118
4995
 
5135
5012
    /* need to fetch icon property */
5136
5013
    if (priv->icons.size () == 0 && !priv->noIcons)
5137
5014
    {
5138
 
        Atom          actual;
5139
 
        int           result, format;
 
5015
        Atom          actual;
 
5016
        int           format;
5140
5017
        unsigned long n, left;
5141
5018
        unsigned char *data;
5142
5019
 
5143
 
        result = XGetWindowProperty (screen->dpy (), priv->id, Atoms::wmIcon,
5144
 
                                     0L, 65536L, false, XA_CARDINAL,
5145
 
                                     &actual, &format, &n, &left, &data);
 
5020
        int result = XGetWindowProperty (screen->dpy (), priv->id, Atoms::wmIcon,
 
5021
                                         0L, 65536L, false, XA_CARDINAL,
 
5022
                                         &actual, &format, &n, &left, &data);
5146
5023
 
5147
5024
        if (result == Success && data)
5148
5025
        {
5149
5026
            CARD32        *p;
5150
5027
            CARD32        alpha, red, green, blue;
5151
5028
            unsigned long iw, ih;
 
5029
            unsigned long *idata;
5152
5030
 
5153
5031
            for (i = 0; i + 2 < n; i += iw * ih + 2)
5154
5032
            {
5155
 
                unsigned long *idata = (unsigned long *) data;
 
5033
                idata = (unsigned long *) data;
5156
5034
 
5157
5035
                iw = idata[i];
5158
5036
                ih = idata[i + 1];
5166
5044
                if (iw && ih)
5167
5045
                {
5168
5046
                    icon = new CompIcon (iw, ih);
 
5047
 
5169
5048
                    if (!icon)
5170
5049
                        continue;
5171
5050
 
5176
5055
                    /* EWMH doesn't say if icon data is premultiplied or
5177
5056
                       not but most applications seem to assume data should
5178
5057
                       be unpremultiplied. */
5179
 
                    for (unsigned long j = 0; j < iw * ih; j++)
 
5058
                    for (unsigned long j = 0; j < iw * ih; ++j)
5180
5059
                    {
5181
5060
                        alpha = (idata[i + j + 2] >> 24) & 0xff;
5182
5061
                        red   = (idata[i + j + 2] >> 16) & 0xff;
5199
5078
            XFree (data);
5200
5079
        }
5201
5080
        else if (priv->hints && (priv->hints->flags & IconPixmapHint))
5202
 
        {
5203
5081
            priv->readIconHint ();
5204
 
        }
5205
5082
 
5206
5083
        /* don't fetch property again */
5207
5084
        if (priv->icons.size () == 0)
5215
5092
    icon = NULL;
5216
5093
    wh   = width + height;
5217
5094
 
5218
 
    for (i = 0; i < priv->icons.size (); i++)
 
5095
    for (i = 0; i < priv->icons.size (); ++i)
5219
5096
    {
5220
5097
        const CompSize iconSize = *priv->icons[i];
5221
5098
 
5222
 
        if ((int) iconSize.width () > width ||
 
5099
        if ((int) iconSize.width ()  > width ||
5223
5100
            (int) iconSize.height () > height)
5224
5101
            continue;
5225
5102
 
5226
5103
        if (icon)
5227
5104
        {
5228
5105
            diff    = wh - (iconSize.width () + iconSize.height ());
5229
 
            oldDiff = wh - (icon->width () + icon->height ());
 
5106
            oldDiff = wh - (icon->width ()    + icon->height ());
5230
5107
 
5231
5108
            if (diff < oldDiff)
5232
5109
                icon = priv->icons[i];
5247
5124
void
5248
5125
PrivateWindow::freeIcons ()
5249
5126
{
5250
 
    for (unsigned int i = 0; i < priv->icons.size (); i++)
 
5127
    for (unsigned int i = 0; i < priv->icons.size (); ++i)
5251
5128
        delete priv->icons[i];
5252
5129
 
5253
5130
    priv->icons.resize (0);
5265
5142
{
5266
5143
    if (priv->desktop == 0xffffffff ||
5267
5144
        priv->desktop == screen->currentDesktop ())
5268
 
    {
5269
5145
        return true;
5270
 
    }
5271
5146
 
5272
5147
    return false;
5273
5148
}
5275
5150
void
5276
5151
CompWindow::setDesktop (unsigned int desktop)
5277
5152
{
5278
 
    if (desktop != 0xffffffff)
5279
 
    {
5280
 
        if (priv->type & (CompWindowTypeDesktopMask | CompWindowTypeDockMask))
5281
 
            return;
5282
 
 
5283
 
        if (desktop >= screen->nDesktop ())
5284
 
            return;
5285
 
    }
 
5153
    if (desktop != 0xffffffff &&
 
5154
        (priv->type & (CompWindowTypeDesktopMask | CompWindowTypeDockMask) ||
 
5155
         desktop >= screen->nDesktop ()))
 
5156
            return;
5286
5157
 
5287
5158
    if (desktop == priv->desktop)
5288
5159
        return;
5307
5178
                                        CompWindow *w2)
5308
5179
{
5309
5180
    CompActiveWindowHistory *history = screen->currentHistory ();
5310
 
    int                     i;
5311
5181
 
5312
5182
    /* check current window history first */
5313
 
    for (i = 0; i < ACTIVE_WINDOW_HISTORY_SIZE; i++)
 
5183
    for (int i = 0; i < ACTIVE_WINDOW_HISTORY_SIZE; ++i)
5314
5184
    {
5315
5185
        if (history->id[i] == w1->priv->id)
5316
5186
            return 1;
5328
5198
bool
5329
5199
CompWindow::onAllViewports () const
5330
5200
{
5331
 
    if (overrideRedirect ())
5332
 
        return true;
5333
 
 
5334
 
    if (!priv->managed && !isViewable ())
5335
 
        return true;
5336
 
 
5337
 
    if (priv->type & (CompWindowTypeDesktopMask | CompWindowTypeDockMask))
5338
 
        return true;
5339
 
 
5340
 
    if (priv->state & CompWindowStateStickyMask)
 
5201
    if (overrideRedirect ()                                                 ||
 
5202
        (!priv->managed && !isViewable ())                                  ||
 
5203
        priv->type & (CompWindowTypeDesktopMask | CompWindowTypeDockMask)   ||
 
5204
        priv->state & CompWindowStateStickyMask)
5341
5205
        return true;
5342
5206
 
5343
5207
    return false;
5347
5211
CompWindow::getMovementForOffset (const CompPoint &offset) const
5348
5212
{
5349
5213
    CompScreen *s = screen;
5350
 
    int         m, vWidth, vHeight;
 
5214
    int         m;
5351
5215
    int         offX = offset.x (), offY = offset.y ();
5352
5216
    CompPoint   rv;
5353
5217
 
5354
 
    vWidth = s->width () * s->vpSize ().width ();
5355
 
    vHeight = s->height () * s->vpSize ().height ();
 
5218
    int vWidth  = s->width ()  * s->vpSize ().width ();
 
5219
    int vHeight = s->height () * s->vpSize ().height ();
5356
5220
 
5357
5221
    offX %= vWidth;
5358
5222
    offY %= vHeight;
5359
5223
 
5360
5224
    /* x */
5361
5225
    if (s->vpSize ().width () == 1)
5362
 
    {
5363
5226
        rv.setX (offX);
5364
 
    }
5365
5227
    else
5366
5228
    {
5367
5229
        m = priv->serverGeometry.x () + offX;
 
5230
 
5368
5231
        if (m - priv->serverInput.left < (int) s->width () - vWidth)
5369
5232
            rv.setX (offX + vWidth);
5370
5233
        else if (m + priv->serverGeometry.width () + priv->serverInput.right > vWidth)
5374
5237
    }
5375
5238
 
5376
5239
    if (s->vpSize ().height () == 1)
5377
 
    {
5378
5240
        rv.setY (offY);
5379
 
    }
5380
5241
    else
5381
5242
    {
5382
5243
        m = priv->serverGeometry.y () + offY;
 
5244
 
5383
5245
        if (m - priv->serverInput.top < (int) s->height () - vHeight)
5384
5246
            rv.setY (offY + vHeight);
5385
5247
        else if (m + priv->serverGeometry.height () + priv->serverInput.bottom > vHeight)
5537
5399
            XSendEvent (screen->dpy (), priv->id, false, NoEventMask, &ev);
5538
5400
        }
5539
5401
        else
5540
 
        {
5541
5402
            XKillClient (screen->dpy (), priv->id);
5542
 
        }
5543
5403
 
5544
 
        priv->closeRequests++;
 
5404
        ++priv->closeRequests;
5545
5405
    }
5546
5406
    else
5547
 
    {
5548
5407
        screen->toolkitAction (Atoms::toolkitActionForceQuitDialog,
5549
5408
                                     serverTime, priv->id, true, 0, 0);
5550
 
    }
5551
5409
 
5552
5410
    priv->lastCloseRequestTime = serverTime;
5553
5411
}
5555
5413
bool
5556
5414
PrivateWindow::handlePingTimeout (unsigned int lastPing)
5557
5415
{
5558
 
    if (!window->isViewable ())
5559
 
        return false;
5560
 
 
5561
 
    if (!(priv->type & CompWindowTypeNormalMask))
 
5416
    if (!window->isViewable () ||
 
5417
        !(priv->type & CompWindowTypeNormalMask))
5562
5418
        return false;
5563
5419
 
5564
5420
    if (priv->protocols & CompWindowProtocolPingMask)
5566
5422
        if (priv->transientFor)
5567
5423
            return false;
5568
5424
 
5569
 
        if (priv->lastPong < lastPing)
 
5425
        if (priv->lastPong < lastPing &&
 
5426
            priv->alive)
5570
5427
        {
5571
 
            if (priv->alive)
 
5428
            priv->alive = false;
 
5429
            window->windowNotify (CompWindowNotifyAliveChanged);
 
5430
 
 
5431
            if (priv->closeRequests)
5572
5432
            {
5573
 
                priv->alive = false;
5574
 
 
5575
 
                window->windowNotify (CompWindowNotifyAliveChanged);
5576
 
 
5577
 
                if (priv->closeRequests)
5578
 
                {
5579
 
                    screen->toolkitAction (Atoms::toolkitActionForceQuitDialog,
5580
 
                                           priv->lastCloseRequestTime,
5581
 
                                           priv->id, true, 0, 0);
5582
 
 
5583
 
                    priv->closeRequests = 0;
5584
 
                }
 
5433
                screen->toolkitAction (Atoms::toolkitActionForceQuitDialog,
 
5434
                                       priv->lastCloseRequestTime,
 
5435
                                       priv->id, true, 0, 0);
 
5436
 
 
5437
                priv->closeRequests = 0;
5585
5438
            }
5586
5439
        }
5587
5440
 
5588
5441
        return true;
5589
5442
    }
 
5443
 
5590
5444
    return false;
5591
5445
}
5592
5446
 
5614
5468
void
5615
5469
PrivateWindow::processMap ()
5616
5470
{
5617
 
    bool                   allowFocus;
5618
 
    bool                   initiallyMinimized;
5619
 
    CompStackingUpdateMode stackingMode;
5620
 
 
5621
5471
    priv->initialViewport = screen->vp ();
5622
5472
 
5623
5473
    priv->initialTimestampSet = false;
5624
5474
 
5625
5475
    screen->applyStartupProperties (window);
5626
5476
 
5627
 
    initiallyMinimized = (priv->hints &&
5628
 
                          priv->hints->initial_state == IconicState &&
5629
 
                          !window->minimized ());
 
5477
    bool initiallyMinimized = (priv->hints                                  &&
 
5478
                               priv->hints->initial_state == IconicState    &&
 
5479
                               !window->minimized ());
5630
5480
 
5631
5481
    if (!serverFrame && !initiallyMinimized)
5632
5482
        reparent ();
5639
5489
    if (!priv->placed)
5640
5490
    {
5641
5491
        int            gravity = priv->sizeHints.win_gravity;
5642
 
        XWindowChanges xwc = XWINDOWCHANGES_INIT;
 
5492
        XWindowChanges xwc     = XWINDOWCHANGES_INIT;
5643
5493
        unsigned int   xwcm;
5644
5494
 
5645
5495
        /* adjust for gravity, but only for frame size */
5650
5500
 
5651
5501
        xwcm = adjustConfigureRequestForGravity (&xwc, CWX | CWY, gravity, 1);
5652
5502
 
5653
 
        xwc.width = priv->serverGeometry.width ();
 
5503
        xwc.width  = priv->serverGeometry.width ();
5654
5504
        xwc.height = priv->serverGeometry.height ();
5655
5505
 
5656
5506
        window->validateResizeRequest (xwcm, &xwc, ClientTypeApplication);
5669
5519
        priv->placed = true;
5670
5520
    }
5671
5521
 
5672
 
    allowFocus = allowWindowFocus (NO_FOCUS_MASK, 0);
 
5522
    CompStackingUpdateMode stackingMode;
 
5523
 
 
5524
    bool allowFocus = allowWindowFocus (NO_FOCUS_MASK, 0);
5673
5525
 
5674
5526
    if (!allowFocus && (priv->type & ~NO_FOCUS_MASK))
5675
5527
        stackingMode = CompStackingUpdateModeInitialMapDeniedFocus;
5697
5549
        if (allowFocus)
5698
5550
        {
5699
5551
            window->moveInputFocusTo ();
 
5552
 
5700
5553
            if (!window->onCurrentDesktop ())
5701
5554
                screen->setCurrentDesktop (priv->desktop);
5702
5555
        }
5747
5600
    if (!priv->frame)
5748
5601
        return;
5749
5602
 
5750
 
    bool onlyActions = (priv->id == screen->activeWindow() ||
5751
 
                        !screen->getCoreOptions().optionGetClickToFocus ());
 
5603
    bool onlyActions = (priv->id == screen->activeWindow () ||
 
5604
                        !screen->getCoreOptions ().optionGetClickToFocus ());
5752
5605
 
5753
5606
    /* Ungrab everything */
5754
 
    XUngrabButton (screen->dpy(), AnyButton, AnyModifier, frame);
 
5607
    XUngrabButton (screen->dpy (), AnyButton, AnyModifier, frame);
5755
5608
 
5756
5609
    /* We don't need the full grab in the following cases:
5757
5610
     * - This window has the focus and either
5761
5614
 
5762
5615
    if (onlyActions)
5763
5616
    {
5764
 
        if (screen->getCoreOptions().optionGetRaiseOnClick ())
 
5617
        if (screen->getCoreOptions ().optionGetRaiseOnClick ())
5765
5618
        {
5766
5619
            /* We do not actually need a server grab here since
5767
5620
             * there is no risk to our internal state */
5785
5638
    }
5786
5639
 
5787
5640
    if (onlyActions)
5788
 
    {
5789
 
        screen->updatePassiveButtonGrabs(serverFrame);
5790
 
    }
 
5641
        screen->updatePassiveButtonGrabs(serverFrame);
5791
5642
    else
5792
5643
    {
5793
5644
        /* Grab everything */
5794
 
        XGrabButton (screen->dpy(),
 
5645
        XGrabButton (screen->dpy (),
5795
5646
                     AnyButton,
5796
5647
                     AnyModifier,
5797
5648
                     serverFrame, false,
5803
5654
    }
5804
5655
}
5805
5656
 
5806
 
 
5807
5657
const CompRegion &
5808
5658
CompWindow::region () const
5809
5659
{
5928
5778
                                    int  y,
5929
5779
                                    bool sync)
5930
5780
{
5931
 
    int tx, ty;
5932
 
    int vWidth  = screen->width () * screen->vpSize ().width ();
 
5781
    int vWidth  = screen->width ()  * screen->vpSize ().width ();
5933
5782
    int vHeight = screen->height () * screen->vpSize ().height ();
5934
5783
 
5935
5784
    if (screen->vpSize ().width () != 1)
5936
5785
    {
5937
5786
        x += screen->vp ().x () * screen->width ();
5938
 
        x = compiz::core::screen::wraparound_mod (x, vWidth);
 
5787
        x  = compiz::core::screen::wraparound_mod (x, vWidth);
5939
5788
        x -= screen->vp ().x () * screen->width ();
5940
5789
    }
5941
5790
 
5942
5791
    if (screen->vpSize ().height () != 1)
5943
5792
    {
5944
5793
        y += screen->vp ().y () * screen->height ();
5945
 
        y = compiz::core::screen::wraparound_mod (y, vHeight);
 
5794
        y  = compiz::core::screen::wraparound_mod (y, vHeight);
5946
5795
        y -= screen->vp ().y () * screen->height ();
5947
5796
    }
5948
5797
 
5949
 
    tx = x - priv->serverGeometry.x ();
5950
 
    ty = y - priv->serverGeometry.y ();
 
5798
    int tx = x - priv->serverGeometry.x ();
 
5799
    int ty = y - priv->serverGeometry.y ();
5951
5800
 
5952
5801
    if (tx || ty)
5953
5802
    {
5954
5803
        unsigned int   valueMask = CWX | CWY;
5955
5804
        XWindowChanges xwc = XWINDOWCHANGES_INIT;
5956
5805
 
5957
 
        if (!priv->managed)
5958
 
            return;
5959
 
 
5960
 
        if (priv->type & (CompWindowTypeDesktopMask | CompWindowTypeDockMask))
5961
 
            return;
5962
 
 
5963
 
        if (priv->state & CompWindowStateStickyMask)
 
5806
        if (!priv->managed ||
 
5807
            priv->type & (CompWindowTypeDesktopMask | CompWindowTypeDockMask) ||
 
5808
            priv->state & CompWindowStateStickyMask)
5964
5809
            return;
5965
5810
 
5966
5811
        int wx = tx;
6009
5854
void
6010
5855
PrivateWindow::applyStartupProperties (CompStartupSequence *s)
6011
5856
{
6012
 
    int workspace;
6013
 
 
6014
5857
    priv->initialViewport.setX (s->viewportX);
6015
5858
    priv->initialViewport.setY (s->viewportY);
6016
5859
 
6017
 
    workspace = sn_startup_sequence_get_workspace (s->sequence);
 
5860
    int workspace = sn_startup_sequence_get_workspace (s->sequence);
 
5861
 
6018
5862
    if (workspace >= 0)
6019
5863
        window->setDesktop (workspace);
6020
5864
 
6021
 
    priv->initialTimestamp    =
6022
 
        sn_startup_sequence_get_timestamp (s->sequence);
 
5865
    priv->initialTimestamp    = sn_startup_sequence_get_timestamp (s->sequence);
6023
5866
    priv->initialTimestampSet = true;
6024
5867
}
6025
5868
 
6107
5950
PrivateWindow::updateStartupId ()
6108
5951
{
6109
5952
    char *oldId = startupId;
6110
 
    bool newId = true;
 
5953
    bool newId  = true;
6111
5954
 
6112
5955
    startupId = getStartupId ();
6113
5956
 
6114
 
    if (oldId && startupId)
6115
 
    {
6116
 
        if (strcmp (startupId, oldId) == 0)
6117
 
            newId = false;
6118
 
    }
 
5957
    if (oldId && startupId && strcmp (startupId, oldId) == 0)
 
5958
        newId = false;
6119
5959
 
6120
5960
    if (managed && startupId && newId)
6121
5961
    {
6122
5962
        Time       timestamp = 0;
6123
 
        CompPoint  vp, svp;
6124
 
        CompSize   size;
6125
 
        int        x, y;
6126
5963
 
6127
5964
        initialTimestampSet = false;
6128
5965
        screen->applyStartupProperties (window);
6134
5971
           notification, assume the client changing the ID
6135
5972
           wanted to activate the window on the current viewport */
6136
5973
 
6137
 
        vp   = window->defaultViewport ();
6138
 
        svp  = screen->vp ();
6139
 
        size = *screen;
 
5974
        CompPoint vp   = window->defaultViewport ();
 
5975
        CompPoint svp  = screen->vp ();
 
5976
        CompSize size  = *screen;
6140
5977
 
6141
 
        x = window->serverGeometry ().x () + (svp.x () - vp.x ()) * size.width ();
6142
 
        y = window->serverGeometry ().y () + (svp.y () - vp.y ()) * size.height ();
 
5978
        int x = window->serverGeometry ().x () + (svp.x () - vp.x ()) * size.width ();
 
5979
        int y = window->serverGeometry ().y () + (svp.y () - vp.y ()) * size.height ();
6143
5980
        window->moveToViewportPosition (x, y, true);
6144
5981
 
6145
5982
        if (allowWindowFocus (0, timestamp))
6146
5983
            window->activate ();
6147
5984
    }
6148
 
    
 
5985
 
6149
5986
    if (oldId)
6150
5987
        free (oldId);
6151
5988
}
6172
6009
PrivateWindow::createCompWindow (Window aboveId, Window aboveServerId, XWindowAttributes &wa, Window id)
6173
6010
{
6174
6011
    PrivateWindow* priv(new PrivateWindow ());
6175
 
    priv->id = id;
 
6012
    priv->id       = id;
6176
6013
    priv->serverId = id;
6177
6014
 
6178
6015
    CompWindow *fw = new CompWindow (aboveId, aboveServerId, wa, priv);
6180
6017
    return fw;
6181
6018
}
6182
6019
 
6183
 
 
6184
 
CompWindow::CompWindow (Window aboveId,
6185
 
                        Window aboveServerId,
 
6020
CompWindow::CompWindow (Window            aboveId,
 
6021
                        Window            aboveServerId,
6186
6022
                        XWindowAttributes &wa,
6187
 
                        PrivateWindow *priv) :
 
6023
                        PrivateWindow     *priv) :
6188
6024
    PluginClassStorage (windowPluginClassIndices),
6189
6025
    priv (priv)
6190
6026
{
6206
6042
    priv->serverGeometry.set (priv->attrib.x, priv->attrib.y,
6207
6043
                              priv->attrib.width, priv->attrib.height,
6208
6044
                              priv->attrib.border_width);
6209
 
    priv->serverFrameGeometry = priv->frameGeometry = priv->syncGeometry
6210
 
            = priv->geometry = priv->serverGeometry;
 
6045
    priv->serverFrameGeometry = priv->frameGeometry = priv->syncGeometry =
 
6046
                                priv->geometry = priv->serverGeometry;
6211
6047
 
6212
6048
    priv->sizeHints.flags = 0;
6213
6049
 
6230
6066
 
6231
6067
    if (priv->attrib.c_class != InputOnly)
6232
6068
    {
6233
 
        priv->region = CompRegion (priv->serverGeometry);
 
6069
        priv->region      = CompRegion (priv->serverGeometry);
6234
6070
        priv->inputRegion = priv->region;
6235
6071
 
6236
6072
        /* need to check for DisplayModal state on all windows */
6237
 
        priv->state = screen->getWindowState (priv->id);
 
6073
        priv->state       = screen->getWindowState (priv->id);
6238
6074
 
6239
6075
        priv->updateClassHints ();
6240
6076
    }
6241
6077
    else
6242
 
    {
6243
6078
        priv->attrib.map_state = IsUnmapped;
6244
 
    }
6245
6079
 
6246
6080
    priv->wmType    = screen->getWindowType (priv->id);
6247
6081
    priv->protocols = screen->getProtocols (priv->id);
6254
6088
        priv->updateTransientHint ();
6255
6089
 
6256
6090
        priv->clientLeader = priv->getClientLeader ();
6257
 
        priv->startupId = priv->getStartupId ();
 
6091
        priv->startupId    = priv->getStartupId ();
6258
6092
 
6259
6093
        recalcType ();
6260
6094
 
6264
6098
        {
6265
6099
            priv->desktop = screen->getWindowProp (priv->id, Atoms::winDesktop,
6266
6100
                                                   priv->desktop);
6267
 
            if (priv->desktop != 0xffffffff)
6268
 
            {
6269
 
                if (priv->desktop >= screen->nDesktop ())
6270
 
                    priv->desktop = screen->currentDesktop ();
6271
 
            }
 
6101
            if (priv->desktop != 0xffffffff &&
 
6102
                priv->desktop >= screen->nDesktop ())
 
6103
                priv->desktop = screen->currentDesktop ();
6272
6104
        }
6273
6105
    }
6274
6106
    else
6275
 
    {
6276
6107
        recalcType ();
6277
 
    }
6278
6108
 
6279
6109
    if (priv->attrib.map_state == IsViewable)
6280
6110
    {
6285
6115
            // needs to happen right after maprequest
6286
6116
            if (!priv->serverFrame)
6287
6117
                priv->reparent ();
 
6118
 
6288
6119
            priv->managed = true;
6289
6120
 
6290
6121
            if (screen->getWmState (priv->id) == IconicState)
6298
6129
            {
6299
6130
                if (priv->wmType & (CompWindowTypeDockMask |
6300
6131
                                 CompWindowTypeDesktopMask))
6301
 
                {
6302
6132
                    setDesktop (0xffffffff);
6303
 
                }
6304
6133
                else
6305
6134
                {
6306
6135
                    if (priv->desktop != 0xffffffff)
6313
6142
        }
6314
6143
 
6315
6144
        priv->attrib.map_state = IsUnmapped;
6316
 
        priv->pendingMaps++;
 
6145
        ++priv->pendingMaps;
6317
6146
 
6318
6147
        map ();
6319
6148
 
6320
6149
        updateAttributes (CompStackingUpdateModeNormal);
6321
6150
 
6322
6151
        if (priv->minimized || priv->inShowDesktopMode ||
6323
 
            priv->hidden || priv->shaded)
 
6152
            priv->hidden    || priv->shaded)
6324
6153
        {
6325
6154
            priv->state |= CompWindowStateHiddenMask;
6326
6155
 
6327
 
            priv->pendingUnmaps++;
 
6156
            ++priv->pendingUnmaps;
6328
6157
 
6329
6158
            if (priv->serverFrame && !priv->shaded)
6330
6159
                XUnmapWindow (screen->dpy (), priv->serverFrame);
6334
6163
            screen->setWindowState (priv->state, priv->id);
6335
6164
        }
6336
6165
    }
6337
 
    else if (!overrideRedirect ())
 
6166
    else if (!overrideRedirect () &&
 
6167
             screen->getWmState (priv->id) == IconicState)
6338
6168
    {
6339
 
        if (screen->getWmState (priv->id) == IconicState)
 
6169
        // before everything else in maprequest
 
6170
        if (!priv->serverFrame)
 
6171
            priv->reparent ();
 
6172
 
 
6173
        priv->managed = true;
 
6174
        priv->placed  = true;
 
6175
 
 
6176
        if (priv->state & CompWindowStateHiddenMask)
6340
6177
        {
6341
 
            // before everything else in maprequest
6342
 
            if (!priv->serverFrame)
6343
 
                priv->reparent ();
6344
 
            priv->managed = true;
6345
 
            priv->placed  = true;
6346
 
 
6347
 
            if (priv->state & CompWindowStateHiddenMask)
6348
 
            {
6349
 
                if (priv->state & CompWindowStateShadedMask)
6350
 
                    priv->shaded = true;
6351
 
                else
6352
 
                    priv->minimized = true;
6353
 
            }
 
6178
            if (priv->state & CompWindowStateShadedMask)
 
6179
                priv->shaded = true;
 
6180
            else
 
6181
                priv->minimized = true;
6354
6182
        }
6355
6183
    }
6356
6184
 
6357
6185
    /* TODO: bailout properly when objectInitPlugins fails */
6358
6186
    bool init_succeeded = CompPlugin::windowInitPlugins (this);
6359
6187
    assert (init_succeeded);
 
6188
 
6360
6189
    if (!init_succeeded)
6361
 
      return;
 
6190
        return;
6362
6191
 
6363
6192
    recalcActions ();
6364
6193
    priv->updateIconGeometry ();
6367
6196
        priv->updateFrameWindow ();
6368
6197
 
6369
6198
    if (priv->attrib.map_state == IsViewable)
6370
 
    {
6371
6199
        priv->invisible = priv->isInvisible ();
6372
 
    }
6373
6200
}
6374
6201
 
6375
6202
CompWindow::~CompWindow ()
6381
6208
     * pending destroy if this was a sibling
6382
6209
     * of one of those */
6383
6210
 
6384
 
    screen->destroyedWindows().remove (this);
 
6211
    screen->destroyedWindows ().remove (this);
6385
6212
 
6386
 
    foreach (CompWindow *dw, screen->destroyedWindows())
 
6213
    foreach (CompWindow *dw, screen->destroyedWindows ())
6387
6214
    {
6388
6215
        if (dw->next == this)
6389
6216
            dw->next = this->next;
 
6217
 
6390
6218
        if (dw->prev == this)
6391
6219
            dw->prev = this->prev;
6392
6220
 
6393
6221
        if (dw->serverNext == this)
6394
6222
            dw->serverNext = this->serverNext;
 
6223
 
6395
6224
        if (dw->serverPrev == this)
6396
6225
            dw->serverPrev = this->serverPrev;
6397
6226
    }
6415
6244
                XConfigureWindow (screen->dpy (), priv->id,
6416
6245
                                  priv->saveMask, &priv->saveWc);
6417
6246
 
6418
 
            if (!priv->hidden)
6419
 
            {
6420
 
                if (priv->state & CompWindowStateHiddenMask)
6421
 
                    XMapWindow (screen->dpy (), priv->id);
6422
 
            }
 
6247
            if (!priv->hidden &&
 
6248
                priv->state & CompWindowStateHiddenMask)
 
6249
                XMapWindow (screen->dpy (), priv->id);
6423
6250
        }
6424
6251
 
6425
6252
        if (screen->XShape ())
6435
6262
    if (priv->attrib.map_state == IsViewable)
6436
6263
    {
6437
6264
        if (priv->type == CompWindowTypeDesktopMask)
6438
 
            screen->decrementDesktopWindowCount();
 
6265
            screen->decrementDesktopWindowCount ();
6439
6266
 
6440
6267
        if (priv->destroyed && priv->struts)
6441
6268
            screen->updateWorkarea ();
6677
6504
{
6678
6505
    WRAPABLE_HND_FUNCTN_RETURN (bool, isFocussable);
6679
6506
 
6680
 
    if (priv->inputHint)
6681
 
        return true;
6682
 
 
6683
 
    if (priv->protocols & CompWindowProtocolTakeFocusMask)
 
6507
    if (priv->inputHint || priv->protocols & CompWindowProtocolTakeFocusMask)
6684
6508
        return true;
6685
6509
 
6686
6510
    return false;
6726
6550
{
6727
6551
    if (priv->serverFrame)
6728
6552
    {
6729
 
        CompRect   r;
6730
 
        int        x, y;
6731
 
 
6732
6553
        priv->frameRegion = emptyRegion;
6733
6554
 
6734
6555
        updateFrameRegion (priv->frameRegion);
6735
6556
 
6736
6557
        if (!shaded ())
6737
6558
        {
6738
 
            r = priv->region.boundingRect ();
 
6559
            CompRect r = priv->region.boundingRect ();
6739
6560
            priv->frameRegion -= r;
6740
6561
 
6741
6562
            r.setGeometry (r.x1 () - priv->serverInput.left,
6742
 
                        r.y1 () - priv->serverInput.top,
6743
 
                        r.width  () + priv->serverInput.right + priv->serverInput.left,
6744
 
                        r.height () + priv->serverInput.bottom + priv->serverInput.top);
 
6563
                           r.y1 () - priv->serverInput.top,
 
6564
                           r.width  () + priv->serverInput.right  + priv->serverInput.left,
 
6565
                           r.height () + priv->serverInput.bottom + priv->serverInput.top);
6745
6566
 
6746
6567
            priv->frameRegion &= CompRegion (r);
6747
6568
        }
6748
6569
 
6749
 
        x = priv->serverGeometry.x () - priv->serverInput.left;
6750
 
        y = priv->serverGeometry.y () - priv->serverInput.top;
 
6570
        int x = priv->serverGeometry.x () - priv->serverInput.left;
 
6571
        int y = priv->serverGeometry.y () - priv->serverInput.top;
6751
6572
 
6752
6573
        XShapeCombineRegion (screen->dpy (), priv->serverFrame,
6753
6574
                             ShapeBounding, -x, -y,
6772
6593
    /* Input extents are used for frame size,
6773
6594
     * Border extents used for placement.
6774
6595
     */
6775
 
 
6776
6596
    if (!i)
6777
6597
        i = b;
6778
6598
 
6779
 
    if (priv->serverInput.left   != i->left ||
6780
 
        priv->serverInput.right  != i->right ||
6781
 
        priv->serverInput.top    != i->top ||
6782
 
        priv->serverInput.bottom != i->bottom ||
6783
 
        priv->border.left   != b->left ||
6784
 
        priv->border.right  != b->right ||
6785
 
        priv->border.top    != b->top ||
 
6599
    if (priv->serverInput.left   != i->left     ||
 
6600
        priv->serverInput.right  != i->right    ||
 
6601
        priv->serverInput.top    != i->top      ||
 
6602
        priv->serverInput.bottom != i->bottom   ||
 
6603
        priv->border.left   != b->left          ||
 
6604
        priv->border.right  != b->right         ||
 
6605
        priv->border.top    != b->top           ||
6786
6606
        priv->border.bottom != b->bottom)
6787
6607
    {
6788
6608
        priv->serverInput = *i;
6789
 
        priv->border = *b;
 
6609
        priv->border      = *b;
6790
6610
 
6791
6611
        recalcActions ();
6792
6612
 
6847
6667
bool
6848
6668
PrivateWindow::reparent ()
6849
6669
{
 
6670
    if (serverFrame)
 
6671
        return false;
 
6672
 
6850
6673
    XSetWindowAttributes attr;
6851
6674
    XWindowAttributes    wa;
6852
 
    XWindowChanges       xwc = XWINDOWCHANGES_INIT;
6853
 
    int                  mask;
 
6675
    XWindowChanges       xwc     = XWINDOWCHANGES_INIT;
6854
6676
    unsigned int         nchildren;
6855
 
    Window               *children, root_return, parent_return;
6856
 
    Display              *dpy = screen->dpy ();
6857
 
    Visual               *visual = DefaultVisual (screen->dpy (),
 
6677
    Window               *children, root_return, parent_return;
 
6678
    Display              *dpy    = screen->dpy ();
 
6679
    Visual               *visual = DefaultVisual (screen->dpy (),
6858
6680
                                                  screen->screenNum ());
6859
 
    Colormap             cmap = DefaultColormap (screen->dpy (),
6860
 
                                                 screen->screenNum ());
6861
 
 
6862
 
    if (serverFrame)
6863
 
        return false;
 
6681
    Colormap             cmap    = DefaultColormap (screen->dpy (),
 
6682
                                                    screen->screenNum ());
6864
6683
 
6865
6684
    XSync (dpy, false);
6866
6685
    XGrabServer (dpy);
6873
6692
    {
6874
6693
        XUngrabServer (dpy);
6875
6694
        XSync (dpy, false);
 
6695
 
6876
6696
        return false;
6877
6697
    }
6878
6698
 
6890
6710
        XFree (children);
6891
6711
        XUngrabServer (dpy);
6892
6712
        XSync (dpy, false);
 
6713
 
6893
6714
        return false;
6894
6715
    }
6895
6716
 
6905
6726
 
6906
6727
    priv->serverGeometry.setBorder (0);
6907
6728
 
6908
 
    mask = CWBorderPixel | CWColormap | CWBackPixmap | CWOverrideRedirect;
 
6729
    int mask = CWBorderPixel | CWColormap | CWBackPixmap | CWOverrideRedirect;
6909
6730
 
6910
6731
    if (wa.depth == 32)
6911
6732
    {
6926
6747
     * that if need be */
6927
6748
 
6928
6749
    /* Awaiting a new frame to be given to us */
6929
 
    frame = None;
 
6750
    frame       = None;
6930
6751
    serverFrame = XCreateWindow (dpy, screen->root (), 0, 0,
6931
6752
                                 wa.width, wa.height, 0, wa.depth,
6932
6753
                                 InputOutput, visual, mask, &attr);
6944
6765
                            InputOutput, visual, mask, &attr);
6945
6766
 
6946
6767
    lastServerInput = serverInput;
6947
 
 
6948
 
    xwc.stack_mode = Above;
 
6768
    xwc.stack_mode  = Above;
6949
6769
 
6950
6770
    /* Look for the client in the current server side stacking
6951
6771
     * order and put the frame above what the client is above
6959
6779
    }
6960
6780
    else
6961
6781
    {
6962
 
        for (unsigned int i = 0; i < nchildren; i++)
 
6782
        for (unsigned int i = 0; i < nchildren; ++i)
6963
6783
        {
6964
6784
            if (i < nchildren - 1)
6965
6785
            {
6994
6814
    /* We don't care about client events on the frame, and listening for them
6995
6815
     * will probably end up fighting the client anyways, so disable them */
6996
6816
 
6997
 
    attr.do_not_propagate_mask = KeyPressMask | KeyReleaseMask |
6998
 
                                 ButtonPressMask | ButtonReleaseMask |
6999
 
                                 EnterWindowMask | LeaveWindowMask |
7000
 
                                 PointerMotionMask | PointerMotionHintMask |
7001
 
                                 Button1MotionMask | Button2MotionMask |
7002
 
                                 Button3MotionMask | Button4MotionMask |
7003
 
                                 Button5MotionMask | ButtonMotionMask |
7004
 
                                 KeymapStateMask | ExposureMask |
7005
 
                                 VisibilityChangeMask | StructureNotifyMask |
7006
 
                                 ResizeRedirectMask | SubstructureNotifyMask |
7007
 
                                 SubstructureRedirectMask | FocusChangeMask |
7008
 
                                 PropertyChangeMask | ColormapChangeMask |
 
6817
    attr.do_not_propagate_mask = KeyPressMask             | KeyReleaseMask          |
 
6818
                                 ButtonPressMask          | ButtonReleaseMask       |
 
6819
                                 EnterWindowMask          | LeaveWindowMask         |
 
6820
                                 PointerMotionMask        | PointerMotionHintMask   |
 
6821
                                 Button1MotionMask        | Button2MotionMask       |
 
6822
                                 Button3MotionMask        | Button4MotionMask       |
 
6823
                                 Button5MotionMask        | ButtonMotionMask        |
 
6824
                                 KeymapStateMask          | ExposureMask            |
 
6825
                                 VisibilityChangeMask     | StructureNotifyMask     |
 
6826
                                 ResizeRedirectMask       | SubstructureNotifyMask  |
 
6827
                                 SubstructureRedirectMask | FocusChangeMask         |
 
6828
                                 PropertyChangeMask       | ColormapChangeMask      |
7009
6829
                                 OwnerGrabButtonMask;
7010
6830
 
7011
6831
    XChangeWindowAttributes (dpy, id, CWEventMask | CWDontPropagate, &attr);
7013
6833
    if (wa.map_state == IsViewable || shaded)
7014
6834
        XMapWindow (dpy, serverFrame);
7015
6835
 
7016
 
    attr.event_mask = SubstructureRedirectMask |
7017
 
                      SubstructureNotifyMask | EnterWindowMask |
7018
 
                      LeaveWindowMask;
 
6836
    attr.event_mask = SubstructureRedirectMask | SubstructureNotifyMask |
 
6837
                      EnterWindowMask          | LeaveWindowMask;
7019
6838
 
7020
6839
    serverFrameGeometry = serverGeometry;
7021
6840
 
7050
6869
void
7051
6870
PrivateWindow::unreparent ()
7052
6871
{
7053
 
    Display              *dpy = screen->dpy ();
7054
 
    XEvent               e;
7055
 
    bool                 alive = true;
7056
 
    XWindowChanges       xwc = XWINDOWCHANGES_INIT;
7057
 
    unsigned int         nchildren;
7058
 
    Window               *children = NULL, root_return, parent_return;
7059
 
    XWindowAttributes    wa;
7060
 
    StackDebugger        *dbg = StackDebugger::Default ();
7061
 
 
7062
6872
    if (!serverFrame)
7063
6873
        return;
7064
6874
 
 
6875
    Display           *dpy      = screen->dpy ();
 
6876
    XEvent            e;
 
6877
    bool              alive     = true;
 
6878
    XWindowChanges    xwc       = XWINDOWCHANGES_INIT;
 
6879
    unsigned int      nchildren;
 
6880
    Window            *children = NULL, root_return, parent_return;
 
6881
    XWindowAttributes wa;
 
6882
    StackDebugger     *dbg      = StackDebugger::Default ();
 
6883
 
7065
6884
    XSync (dpy, false);
7066
6885
 
7067
6886
    if (XCheckTypedWindowEvent (dpy, id, DestroyNotify, &e))
7069
6888
        XPutBackEvent (dpy, &e);
7070
6889
        alive = false;
7071
6890
    }
7072
 
    else
7073
 
    {
7074
 
        if (!XGetWindowAttributes (dpy, id, &wa))
 
6891
    else if (!XGetWindowAttributes (dpy, id, &wa))
7075
6892
            alive = false;
7076
 
    }
7077
6893
 
7078
6894
    /* Also don't reparent back into root windows that have ended up
7079
6895
     * reparented into other windows (and as such we are unmanaging them) */
7102
6918
 
7103
6919
        xwc.x = serverGeometry.xMinusBorder ();
7104
6920
        xwc.y = serverGeometry.yMinusBorder ();
7105
 
        xwc.width = serverGeometry.widthIncBorders ();
 
6921
        xwc.width  = serverGeometry.widthIncBorders ();
7106
6922
        xwc.height = serverGeometry.heightIncBorders ();
7107
6923
 
7108
6924
        XConfigureWindow (dpy, serverFrame, CWX | CWY | CWWidth | CWHeight, &xwc);
7184
7000
     * handle the ReparentNotify */
7185
7001
    pendingConfigures.clear ();
7186
7002
 
7187
 
    frame = None;
7188
 
    wrapper = None;
 
7003
    frame       = None;
 
7004
    wrapper     = None;
7189
7005
    serverFrame = None;
7190
7006
 
7191
7007
    // Finally, (i.e. after updating state) notify the change