~compiz-team/compiz/compiz.fix_1088399

« back to all changes in this revision

Viewing changes to src/window.cpp

Minor Performance Optimizations:

* Return ASAP./Prevent executing any unnecessary operations if we return.
* Used De Morgan's laws to merge and simplify if statements.

Other Changes:

* C++ Style: Declared iterator variables inside the for loops they are used in.
* No logic changes have been made.

Approved by Daniel van Vugt.

Show diffs side-by-side

added added

removed removed

Lines of Context:
504
504
void
505
505
CompWindow::changeState (unsigned int newState)
506
506
{
507
 
    unsigned int oldState;
508
 
 
509
507
    if (priv->state == newState)
510
508
        return;
511
509
 
512
 
    oldState = priv->state;
 
510
    unsigned int oldState = priv->state;
513
511
    priv->state = newState;
514
512
 
515
513
    recalcType ();
807
805
void
808
806
PrivateWindow::updateFrameWindow ()
809
807
{
 
808
    if (!serverFrame)
 
809
        return;
 
810
 
810
811
    XWindowChanges xwc = XWINDOWCHANGES_INIT;
811
812
    unsigned int   valueMask = CWX | CWY | CWWidth | CWHeight;
812
813
 
813
 
    if (!serverFrame)
814
 
        return;
815
 
 
816
814
    xwc.x = serverGeometry.x ();
817
815
    xwc.y = serverGeometry.y ();
818
816
    xwc.width = serverGeometry.width ();
1716
1714
void
1717
1715
CompWindow::sendSyncRequest ()
1718
1716
{
 
1717
    if (priv->syncWait)
 
1718
        return;
 
1719
 
 
1720
    if (!priv->initializeSyncCounter ())
 
1721
        return;
 
1722
 
1719
1723
    XClientMessageEvent xev;
1720
1724
 
1721
 
    if (priv->syncWait)
1722
 
        return;
1723
 
 
1724
 
    if (!priv->initializeSyncCounter ())
1725
 
        return;
1726
 
 
1727
1725
    xev.type         = ClientMessage;
1728
1726
    xev.window       = priv->id;
1729
1727
    xev.message_type = Atoms::wmProtocols;
1748
1746
void
1749
1747
PrivateWindow::configure (XConfigureEvent *ce)
1750
1748
{
 
1749
    if (priv->frame)
 
1750
        return;
 
1751
 
1751
1752
    unsigned int valueMask = 0;
1752
1753
 
1753
 
    if (priv->frame)
1754
 
        return;
1755
 
 
1756
1754
    /* remove configure event from pending configures */
1757
1755
    if (priv->geometry.x () != ce->x)
1758
1756
        valueMask |= CWX;
1800
1798
void
1801
1799
PrivateWindow::configureFrame (XConfigureEvent *ce)
1802
1800
{
 
1801
    if (!priv->frame)
 
1802
        return;
 
1803
 
1803
1804
    int x, y, width, height;
1804
1805
    CompWindow       *above;
1805
1806
    unsigned int     valueMask = 0;
1806
1807
 
1807
 
    if (!priv->frame)
1808
 
        return;
1809
 
 
1810
1808
    /* remove configure event from pending configures */
1811
1809
    if (priv->frameGeometry.x () != ce->x)
1812
1810
        valueMask |= CWX;
2891
2889
void
2892
2890
PrivateWindow::saveGeometry (int mask)
2893
2891
{
2894
 
    int m = mask & ~saveMask;
2895
 
 
2896
2892
    /* only save geometry if window has been placed */
2897
2893
    if (!placed)
2898
2894
        return;
2899
2895
 
 
2896
    int m = mask & ~saveMask;
 
2897
 
2900
2898
    if (m & CWX)
2901
2899
        saveWc.x = serverGeometry.x ();
2902
2900
 
2983
2981
PrivateWindow::reconfigureXWindow (unsigned int   valueMask,
2984
2982
                                   XWindowChanges *xwc)
2985
2983
{
2986
 
    unsigned int frameValueMask = 0;
2987
 
 
2988
2984
    if (id == screen->root ())
2989
2985
    {
2990
2986
        compLogMessage ("core", CompLogLevelWarn, "attempted to reconfigure root window");
2991
2987
        return;
2992
2988
    }
2993
2989
 
 
2990
    unsigned int frameValueMask = 0;
 
2991
 
2994
2992
    /* Remove redundant bits */
2995
2993
 
2996
2994
    xwc->x = valueMask & CWX ? xwc->x : serverGeometry.x ();
3950
3948
void
3951
3949
PrivateWindow::updateSize ()
3952
3950
{
3953
 
    XWindowChanges xwc = XWINDOWCHANGES_INIT;
3954
 
    int            mask;
3955
 
 
3956
3951
    if (window->overrideRedirect () || !managed)
3957
3952
        return;
3958
3953
 
3959
 
    mask = priv->addWindowSizeChanges (&xwc, priv->serverGeometry);
 
3954
    XWindowChanges xwc = XWINDOWCHANGES_INIT;
 
3955
 
 
3956
    int mask = priv->addWindowSizeChanges (&xwc, priv->serverGeometry);
3960
3957
    if (mask)
3961
3958
    {
3962
3959
        if (priv->mapNum && (mask & (CWWidth | CWHeight)))
4214
4211
void
4215
4212
CompWindow::updateAttributes (CompStackingUpdateMode stackingMode)
4216
4213
{
 
4214
    if (overrideRedirect () || !priv->managed)
 
4215
        return;
 
4216
 
4217
4217
    XWindowChanges xwc = XWINDOWCHANGES_INIT;
4218
4218
    int            mask = 0;
4219
4219
 
4220
 
    if (overrideRedirect () || !priv->managed)
4221
 
        return;
4222
 
 
4223
4220
    if (priv->state & CompWindowStateShadedMask && !priv->shaded)
4224
4221
    {
4225
4222
        windowNotify (CompWindowNotifyShade);
4297
4294
void
4298
4295
PrivateWindow::ensureWindowVisibility ()
4299
4296
{
4300
 
    int x1, y1, x2, y2;
4301
 
    int width = serverGeometry.widthIncBorders ();
4302
 
    int height = serverGeometry.heightIncBorders ();
4303
 
    int dx = 0;
4304
 
    int dy = 0;
4305
 
 
4306
4297
    if (struts || attrib.override_redirect)
4307
4298
        return;
4308
4299
 
4311
4302
                CompWindowTypeUnknownMask))
4312
4303
        return;
4313
4304
 
4314
 
    x1 = screen->workArea ().x () - screen->width () * screen->vp ().x ();
4315
 
    y1 = screen->workArea ().y () - screen->height () * screen->vp ().y ();
4316
 
    x2 = x1 + screen->workArea ().width () + screen->vpSize ().width () *
 
4305
    int x1 = screen->workArea ().x () - screen->width () * screen->vp ().x ();
 
4306
    int y1 = screen->workArea ().y () - screen->height () * screen->vp ().y ();
 
4307
    int x2 = x1 + screen->workArea ().width () + screen->vpSize ().width () *
4317
4308
         screen->width ();
4318
 
    y2 = y1 + screen->workArea ().height () + screen->vpSize ().height () *
 
4309
    int y2 = y1 + screen->workArea ().height () + screen->vpSize ().height () *
4319
4310
         screen->height ();
4320
4311
 
 
4312
    int dx = 0;
 
4313
    int width = serverGeometry.widthIncBorders ();
 
4314
 
4321
4315
    if (serverGeometry.x () - serverInput.left >= x2)
4322
4316
        dx = (x2 - 25) - serverGeometry.x ();
4323
4317
    else if (serverGeometry.x () + width + serverInput.right <= x1)
4324
4318
        dx = (x1 + 25) - (serverGeometry.x () + width);
4325
4319
 
 
4320
    int dy = 0;
 
4321
    int height = serverGeometry.heightIncBorders ();
 
4322
 
4326
4323
    if (serverGeometry.y () - serverInput.top >= y2)
4327
4324
        dy = (y2 - 25) - serverGeometry.y ();
4328
4325
    else if (serverGeometry.y () + height + serverInput.bottom <= y1)
4440
4437
void
4441
4438
PrivateWindow::hide ()
4442
4439
{
4443
 
    bool onDesktop = window->onCurrentDesktop ();
4444
 
 
4445
4440
    if (!managed)
4446
4441
        return;
4447
4442
 
 
4443
    bool onDesktop = window->onCurrentDesktop ();
 
4444
 
4448
4445
    if (!window->minimized () && !inShowDesktopMode &&
4449
4446
        !hidden && onDesktop)
4450
4447
    {
4487
4484
void
4488
4485
PrivateWindow::show ()
4489
4486
{
4490
 
    bool onDesktop = window->onCurrentDesktop ();
4491
 
 
4492
4487
    if (!managed)
4493
4488
        return;
4494
4489
 
 
4490
    bool onDesktop = window->onCurrentDesktop ();
 
4491
 
4495
4492
    if (minimized || inShowDesktopMode ||
4496
4493
        hidden    || !onDesktop)
4497
4494
    {
4959
4956
 
4960
4957
                if (iw && ih)
4961
4958
                {
4962
 
                    unsigned long j;
4963
4959
                    icon = new CompIcon (iw, ih);
4964
4960
                    if (!icon)
4965
4961
                        continue;
4971
4967
                    /* EWMH doesn't say if icon data is premultiplied or
4972
4968
                       not but most applications seem to assume data should
4973
4969
                       be unpremultiplied. */
4974
 
                    for (j = 0; j < iw * ih; j++)
 
4970
                    for (unsigned long j = 0; j < iw * ih; j++)
4975
4971
                    {
4976
4972
                        alpha = (idata[i + j + 2] >> 24) & 0xff;
4977
4973
                        red   = (idata[i + j + 2] >> 16) & 0xff;
5527
5523
void
5528
5524
PrivateWindow::updatePassiveButtonGrabs ()
5529
5525
{
 
5526
    if (!priv->frame)
 
5527
        return;
 
5528
 
5530
5529
    bool onlyActions = (priv->id == screen->activeWindow() ||
5531
5530
                        !screen->getCoreOptions().optionGetClickToFocus ());
5532
5531
 
5533
 
    if (!priv->frame)
5534
 
        return;
5535
 
 
5536
5532
    /* Ungrab everything */
5537
5533
    XUngrabButton (screen->dpy(), AnyButton, AnyModifier, frame);
5538
5534
 
5713
5709
    {
5714
5710
        unsigned int   valueMask = CWX | CWY;
5715
5711
        XWindowChanges xwc = XWINDOWCHANGES_INIT;
5716
 
        int m, wx, wy;
5717
5712
 
5718
5713
        if (!priv->managed)
5719
5714
            return;
5724
5719
        if (priv->state & CompWindowStateStickyMask)
5725
5720
            return;
5726
5721
 
5727
 
        wx = tx;
5728
 
        wy = ty;
 
5722
        int wx = tx;
 
5723
        int wy = ty;
 
5724
        int m;
5729
5725
 
5730
5726
        if (screen->vpSize ().width ()!= 1)
5731
5727
        {