~smspillaz/compiz-grid-plugin/oneiric.fix_827560

« back to all changes in this revision

Viewing changes to src/grid.cpp

  • Committer: Sam Spilsbury
  • Date: 2011-09-27 15:59:09 UTC
  • mfrom: (84.5.14 compiz-grid-plugin)
  • Revision ID: sam.spilsbury@canonical.com-20110927155909-9amod8kcevzt3g1b
MergeĀ upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
    {0,0, 1,1},
44
44
};
45
45
 
 
46
void
 
47
GridScreen::handleCompizEvent(const char*    plugin,
 
48
                              const char*    event,
 
49
                              CompOption::Vector&  o)
 
50
{
 
51
    if (strcmp(event, "start_viewport_switch") == 0)
 
52
    {
 
53
        mSwitchingVp = true;
 
54
    }
 
55
    else if (strcmp(event, "end_viewport_switch") == 0)
 
56
    {
 
57
        mSwitchingVp = false;
 
58
    }
 
59
 
 
60
  screen->handleCompizEvent(plugin, event, o);
 
61
}
 
62
 
46
63
CompRect
47
64
GridScreen::slotToRect (CompWindow      *w,
48
65
                        const CompRect& slot)
119
136
                            CompAction::State  state,
120
137
                            CompOption::Vector &option,
121
138
                            GridType           where,
122
 
                            bool               resize)
 
139
                            bool               resize,
 
140
                            bool               key)
123
141
{
124
142
    Window     xid;
125
143
    CompWindow *cw = 0;
138
156
 
139
157
        if (gw->lastTarget != where)
140
158
            gw->resizeCount = 0;
 
159
        else if (!key)
 
160
            return false;
141
161
 
142
162
        props = gridProps[where];
143
163
 
324
344
            gw->isGridMaximized = false;
325
345
                for (unsigned int i = 0; i < animations.size (); i++)
326
346
                        animations.at (i).fadingOut = true;
 
347
            gw->lastTarget = where;
 
348
            gw->currentSize = CompRect (wc.x, wc.y, wc.width, wc.height);
327
349
        }
328
350
 
329
351
        /* This centers a window if it could not be resized to the desired
345
367
 
346
368
            centerCheck = false;
347
369
        }
348
 
 
349
 
        gw->lastTarget = where;
350
370
    }
351
371
 
352
372
    return true;
514
534
GridScreen::handleEvent (XEvent *event)
515
535
{
516
536
    CompOutput out;
 
537
    CompWindow *w;
 
538
    bool       check = false;
517
539
 
518
540
    screen->handleEvent (event);
519
541
 
567
589
        if (cScreen)
568
590
            cScreen->damageRegion (desiredSlot);
569
591
 
570
 
        initiateCommon (0, 0, o, edgeToGridType (), false);
 
592
        initiateCommon (0, 0, o, edgeToGridType (), false, false);
571
593
 
572
594
        if (cScreen)
573
595
            cScreen->damageRegion (desiredSlot);
585
607
                if (cScreen)
586
608
                        cScreen->damageRegion (desiredSlot);
587
609
 
588
 
                initiateCommon (0, 0, o, edgeToGridType (), false);
 
610
                check = initiateCommon (0, 0, o, edgeToGridType (), false, false);
589
611
 
590
612
                if (cScreen)
591
613
                        cScreen->damageRegion (desiredSlot);
596
618
                                /* Begin fading previous animation instance */
597
619
                                animations.at (animations.size () - 1).fadingOut = true;
598
620
 
599
 
                        if (edge != NoEdge)
 
621
                        if (edge != NoEdge && check)
600
622
                        {
601
623
                                CompWindow *cw = screen->findWindow (screen->activeWindow ());
602
624
                                animations.push_back (Animation ());
620
642
                lastEdge = edge;
621
643
    }
622
644
 
623
 
    GRID_WINDOW (screen->findWindow
624
 
                                (CompOption::getIntOptionNamed (o, "window")));
625
 
 
626
 
    if ((gw->pointerBufDx > SNAPOFF_THRESHOLD ||
627
 
         gw->pointerBufDy > SNAPOFF_THRESHOLD ||
628
 
         gw->pointerBufDx < -SNAPOFF_THRESHOLD ||
629
 
         gw->pointerBufDy < -SNAPOFF_THRESHOLD) &&
630
 
         gw->isGridResized &&
631
 
         optionGetSnapbackWindows ())
632
 
            restoreWindow (0, 0, o);
 
645
    w = screen->findWindow (CompOption::getIntOptionNamed (o, "window"));
 
646
 
 
647
    if (w)
 
648
    {
 
649
        GRID_WINDOW (w);
 
650
 
 
651
        if ((gw->pointerBufDx > SNAPOFF_THRESHOLD ||
 
652
             gw->pointerBufDy > SNAPOFF_THRESHOLD ||
 
653
             gw->pointerBufDx < -SNAPOFF_THRESHOLD ||
 
654
             gw->pointerBufDy < -SNAPOFF_THRESHOLD) &&
 
655
             gw->isGridResized &&
 
656
             optionGetSnapbackWindows ())
 
657
                restoreWindow (0, 0, o);
 
658
    }
633
659
}
634
660
 
635
661
void
640
666
{
641
667
    if (screen->grabExist ("move"))
642
668
    {
643
 
        gScreen->o.push_back (CompOption ("window", CompOption::TypeInt));
644
669
        gScreen->o[0].value ().set ((int) window->id ());
645
670
 
646
671
        screen->handleEventSetEnabled (gScreen, true);
668
693
    if (window == gScreen->mGrabWindow)
669
694
    {
670
695
        gScreen->initiateCommon
671
 
                        (0, 0, gScreen->o, gScreen->edgeToGridType (), true);
 
696
                        (0, 0, gScreen->o, gScreen->edgeToGridType (), true,
 
697
                         gScreen->edge != gScreen->lastResizeEdge);
672
698
 
673
699
        screen->handleEventSetEnabled (gScreen, false);
674
700
        gScreen->mGrabWindow = NULL;
 
701
        gScreen->o[0].value ().set (0);
675
702
        gScreen->cScreen->damageRegion (gScreen->desiredSlot);
676
703
    }
677
704
 
 
705
    gScreen->lastResizeEdge = gScreen->edge;
678
706
    gScreen->edge = NoEdge;
679
707
 
680
708
    window->ungrabNotify ();
685
713
{
686
714
    window->moveNotify (dx, dy, immediate);
687
715
 
688
 
    pointerBufDx += dx;
689
 
    pointerBufDy += dy;
 
716
    if (isGridResized && !isGridMaximized && !GridScreen::get (screen)->mSwitchingVp)
 
717
    {
 
718
        if (window->grabbed ())
 
719
        {
 
720
            pointerBufDx += dx;
 
721
            pointerBufDy += dy;
 
722
        }
 
723
 
 
724
        /* Do not allow the window to be moved while it
 
725
         * is resized */
 
726
        dx = currentSize.x () - window->geometry ().x ();
 
727
        dy = currentSize.y () - window->geometry ().y ();
 
728
 
 
729
        window->move (dx, dy);
 
730
    }
690
731
}
691
732
 
 
733
void
 
734
GridWindow::stateChangeNotify (unsigned int lastState)
 
735
{
 
736
    if (lastState & MAXIMIZE_STATE &&
 
737
        !(window->state () & MAXIMIZE_STATE))
 
738
        lastTarget = GridUnknown;
 
739
    else if (!(lastState & MAXIMIZE_STATE) &&
 
740
             window->state () & MAXIMIZE_STATE)
 
741
        lastTarget = GridMaximize;
 
742
 
 
743
    window->stateChangeNotify (lastState);
 
744
 
745
 
692
746
bool
693
747
GridScreen::restoreWindow (CompAction         *action,
694
748
                           CompAction::State  state,
722
776
        xwc.width  = gw->originalSize.width ();
723
777
        xwc.height = gw->originalSize.height ();
724
778
        cw->maximize (0);
 
779
        gw->currentSize = CompRect ();
725
780
        cw->configureXWindow (CWX | CWY | CWWidth | CWHeight, &xwc);
726
781
        gw->pointerBufDx = 0;
727
782
        gw->pointerBufDy = 0;
728
783
    }
729
784
    gw->isGridResized = false;
730
785
    gw->resizeCount = 0;
 
786
    gw->lastTarget = GridUnknown;
731
787
 
732
788
    return true;
733
789
}
826
882
    glScreen (GLScreen::get (screen)),
827
883
    centerCheck (false),
828
884
    mGrabWindow (NULL),
829
 
    animating (false)
 
885
    animating (false),
 
886
    mSwitchingVp (false)
830
887
{
 
888
    o.push_back (CompOption ("window", CompOption::TypeInt));
831
889
 
832
890
    ScreenInterface::setHandler (screen, false);
 
891
    screen->handleCompizEventSetEnabled (this, true);
833
892
    CompositeScreenInterface::setHandler (cScreen, false);
834
893
    GLScreenInterface::setHandler (glScreen, false);
835
894
 
836
 
    edge = lastEdge = NoEdge;
 
895
    edge = lastEdge = lastResizeEdge = NoEdge;
837
896
    currentWorkarea = lastWorkarea = screen->getWorkareaForOutput
838
897
                            (screen->outputDeviceForPoint (pointerX, pointerY));
839
898
 
840
899
        animations.clear ();
841
900
 
842
 
#define GRIDSET(opt,where,resize)                                              \
 
901
#define GRIDSET(opt,where,resize,key)                                          \
843
902
    optionSet##opt##Initiate (boost::bind (&GridScreen::initiateCommon, this,  \
844
 
                                           _1, _2, _3, where, resize))
 
903
                                           _1, _2, _3, where, resize, key))
845
904
 
846
 
    GRIDSET (PutCenterKey, GridCenter, true);
847
 
    GRIDSET (PutLeftKey, GridLeft, true);
848
 
    GRIDSET (PutRightKey, GridRight, true);
849
 
    GRIDSET (PutTopKey, GridTop, true);
850
 
    GRIDSET (PutBottomKey, GridBottom, true);
851
 
    GRIDSET (PutTopleftKey, GridTopLeft, true);
852
 
    GRIDSET (PutToprightKey, GridTopRight, true);
853
 
    GRIDSET (PutBottomleftKey, GridBottomLeft, true);
854
 
    GRIDSET (PutBottomrightKey, GridBottomRight, true);
855
 
    GRIDSET (PutMaximizeKey, GridMaximize, true);
 
905
    GRIDSET (PutCenterKey, GridCenter, true, true);
 
906
    GRIDSET (PutLeftKey, GridLeft, true, true);
 
907
    GRIDSET (PutRightKey, GridRight, true, true);
 
908
    GRIDSET (PutTopKey, GridTop, true, true);
 
909
    GRIDSET (PutBottomKey, GridBottom, true, true);
 
910
    GRIDSET (PutTopleftKey, GridTopLeft, true, true);
 
911
    GRIDSET (PutToprightKey, GridTopRight, true, true);
 
912
    GRIDSET (PutBottomleftKey, GridBottomLeft, true, true);
 
913
    GRIDSET (PutBottomrightKey, GridBottomRight, true, true);
 
914
    GRIDSET (PutMaximizeKey, GridMaximize, true, true);
856
915
 
857
916
#undef GRIDSET
858
917
 
878
937
    WindowInterface::setHandler (window);
879
938
}
880
939
 
 
940
GridWindow::~GridWindow ()
 
941
{
 
942
    if (gScreen->mGrabWindow == window)
 
943
        gScreen->mGrabWindow = NULL;
 
944
 
 
945
    gScreen->o[0].value ().set (0);
 
946
}
 
947
 
881
948
/* Initial plugin init function called. Checks to see if we are ABI
882
949
 * compatible with core, otherwise unload */
883
950