Merge lp:~compiz-team/compiz-core/compiz-core.fix_874004 into lp:compiz-core/0.9.5

Proposed by Sam Spilsbury
Status: Merged
Approved by: Mirco Müller
Approved revision: 2882
Merged at revision: 2884
Proposed branch: lp:~compiz-team/compiz-core/compiz-core.fix_874004
Merge into: lp:compiz-core/0.9.5
Diff against target: 118 lines (+57/-5)
2 files modified
plugins/scale/src/privates.h (+1/-1)
plugins/scale/src/scale.cpp (+56/-4)
To merge this branch: bzr merge lp:~compiz-team/compiz-core/compiz-core.fix_874004
Reviewer Review Type Date Requested Status
Mirco Müller (community) Approve
Review via email: mp+79400@code.launchpad.net

Description of the change

To post a comment you must log in.
Revision history for this message
Mirco Müller (macslow) wrote :

As mentioned on IRC this overlaps with a different commit, so just looking at scale.cpp/privates.h (rev 2881).

I would give it the seal of approval, if you'd check and protect against these edge-cases:

   priv->slot->scale == 1.0
   window->x() == -1.0 * priv->tx
   window->y() == -1.0 * priv->ty

At the moment those would still lead to a division by zero.

review: Needs Fixing
Revision history for this message
Mirco Müller (macslow) wrote :

Doh... fourth edge-case:

    priv->lastTargetScale == 1.0

Revision history for this message
Sam Spilsbury (smspillaz) wrote :

Fixing

2882. By Sam Spilsbury

Avoid FDIV0 in other cases too

Revision history for this message
Mirco Müller (macslow) wrote :

Ok now.

review: Approve
Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Note: unless C++ contains some magic that I am unaware of then x == f0.0 is a bad idea. It may spuriously be false when x == 0.0000000001. And I *have* seen this in the real world.

Revision history for this message
Mikkel Kamstrup Erlandsen (kamstrup) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/scale/src/privates.h'
2--- plugins/scale/src/privates.h 2011-10-05 17:34:43 +0000
3+++ plugins/scale/src/privates.h 2011-10-17 10:13:25 +0000
4@@ -176,7 +176,7 @@
5
6 GLfloat xVelocity, yVelocity, scaleVelocity;
7 GLfloat scale;
8- GLfloat lastTargetScale;
9+ GLfloat lastTargetScale, lastTargetX, lastTargetY;
10 GLfloat tx, ty;
11 float delta;
12 bool adjust;
13
14=== modified file 'plugins/scale/src/scale.cpp'
15--- plugins/scale/src/scale.cpp 2011-10-05 17:34:43 +0000
16+++ plugins/scale/src/scale.cpp 2011-10-17 10:13:25 +0000
17@@ -266,10 +266,54 @@
18 * should be faded in and out */
19 if (window->state () & CompWindowStateHiddenMask)
20 {
21+ GLfloat factor = 0;
22+
23 if (priv->slot)
24- attrib.opacity *= (1.0f - priv->scale) / (1.0f - priv->slot->scale);
25+ {
26+ GLfloat scaleFactor, xFactor, yFactor;
27+
28+ /* Don't FDIV0 */
29+ if (priv->scale - priv->slot->scale == 0.0f)
30+ scaleFactor = 1.0f;
31+ else
32+ scaleFactor = (1.0f - priv->scale) / (1.0f - priv->slot->scale);
33+
34+ if (priv->slot->x () - ((float) window->x () + priv->tx) == 0.0f)
35+ xFactor = 1.0f;
36+ else
37+ xFactor = priv->slot->x () / ((float) window->x () + priv->tx);
38+
39+ if (priv->slot->y () - ((float) window->y () + priv->ty) == 0.0f)
40+ yFactor = 1.0f;
41+ else
42+ yFactor = priv->slot->y () / ((float) window->y () + priv->ty);
43+
44+ factor = (scaleFactor + xFactor + yFactor) / 3.0f;
45+ attrib.opacity *= factor;
46+ }
47 else
48- attrib.opacity *= (1.0f - priv->scale) / (1.0f - priv->lastTargetScale);
49+ {
50+ GLfloat scaleFactor, xFactor, yFactor;
51+
52+ /* Don't FDIV0 */
53+ if (priv->scale - priv->slot->scale == 0.0f)
54+ scaleFactor = 1.0f;
55+ else
56+ scaleFactor = (1.0f - priv->scale) / (1.0f - priv->slot->scale);
57+
58+ if (priv->lastTargetX - ((float) window->x () + priv->tx) == 0.0f)
59+ xFactor = 1.0f;
60+ else
61+ xFactor = priv->lastTargetX / ((float) window->x () + priv->tx);
62+
63+ if (priv->lastTargetY - ((float) window->y () + priv->ty) == 0.0f)
64+ yFactor = 1.0f;
65+ else
66+ yFactor = priv->lastTargetY / ((float) window->y () + priv->ty);
67+
68+ factor = (scaleFactor + xFactor + yFactor) / 3.0f;
69+ attrib.opacity *= factor;
70+ }
71 }
72
73 if (priv->adjust || priv->slot)
74@@ -952,11 +996,17 @@
75 if (sw->priv->slot)
76 {
77 sw->priv->lastTargetScale = sw->priv->slot->scale;
78+ sw->priv->lastTargetX = sw->priv->slot->x ();
79+ sw->priv->lastTargetY = sw->priv->slot->y ();
80 sw->priv->slot = NULL;
81 sw->priv->adjust = true;
82 }
83 else
84+ {
85 sw->priv->lastTargetScale = 1.0f;
86+ sw->priv->lastTargetX = w->x ();
87+ sw->priv->lastTargetY = w->y ();
88+ }
89 }
90
91 if (state & CompAction::StateCancel)
92@@ -1497,7 +1547,7 @@
93 bool focus = false;
94 CompOption *o = screen->getOption ("click_to_focus");
95
96- if (o && o->value ().b ())
97+ if (o && !o->value ().b ())
98 focus = true;
99
100 selectWindowAt (event->xmotion.x_root,
101@@ -1528,7 +1578,7 @@
102 bool focus = false;
103 CompOption *o = screen->getOption ("click_to_focus");
104
105- if (o && o->value ().b ())
106+ if (o && !o->value ().b ())
107 focus = true;
108
109 if (w->id () == dndTarget)
110@@ -1774,6 +1824,8 @@
111 scaleVelocity (0.0),
112 scale (1.0),
113 lastTargetScale (1.0f),
114+ lastTargetX (w->x ()),
115+ lastTargetY (w->y ()),
116 tx (0.0),
117 ty (0.0),
118 delta (1.0),

Subscribers

People subscribed via source and target branches