Merge lp:~compiz-team/compiz/compiz.fix_1159324 into lp:compiz/0.9.9

Proposed by Sam Spilsbury
Status: Merged
Approved by: Michael Terry
Approved revision: 3636
Merged at revision: 3636
Proposed branch: lp:~compiz-team/compiz/compiz.fix_1159324
Merge into: lp:compiz/0.9.9
Diff against target: 476 lines (+312/-93)
4 files modified
plugins/place/src/constrain-to-workarea/include/constrain-to-workarea.h (+6/-0)
plugins/place/src/constrain-to-workarea/src/constrain-to-workarea.cpp (+62/-5)
plugins/place/src/constrain-to-workarea/tests/constrain-to-workarea/src/test-place-constrain-to-workarea.cpp (+235/-58)
plugins/place/src/place.cpp (+9/-30)
To merge this branch: bzr merge lp:~compiz-team/compiz/compiz.fix_1159324
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
MC Return Approve
Compiz Maintainers Pending
Review via email: mp+155130@code.launchpad.net

Commit message

Don't offset placement by window extents for windows that have a static
gravity.

Those windows want to be placed as though they didn't have decorations.

Get cp::constrainPositionToWorkArea under test and clean up the other
place tests too, so that they only test one thing at a time.

(LP: #1159324)

Description of the change

Don't offset placement by window extents for windows that have a static
gravity.

Those windows want to be placed as though they didn't have decorations.

Get cp::constrainPositionToWorkArea under test and clean up the other
place tests too, so that they only test one thing at a time.

(LP: #1159324)

To post a comment you must log in.
Revision history for this message
MC Return (mc-return) wrote :

Confirming this fixes bug #1159324. \o/
All regressions recently introduced are gone.
Tested Guake, Terra and Yakuake drop-down terminals.
All open with right sizes and in correct positions.

Thanks a lot, Sam. +1

P.S.:
Raring would need this fix also, because of:
http://bazaar.launchpad.net/~compiz-team/compiz/raring/revision/3639

It is a bit painful to suddenly have to deal with a trunk != raring situation...

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'plugins/place/src/constrain-to-workarea/include/constrain-to-workarea.h'
--- plugins/place/src/constrain-to-workarea/include/constrain-to-workarea.h 2012-01-20 06:13:07 +0000
+++ plugins/place/src/constrain-to-workarea/include/constrain-to-workarea.h 2013-03-24 05:56:21 +0000
@@ -41,6 +41,12 @@
41 const CompWindowExtents &border,41 const CompWindowExtents &border,
42 unsigned int flags,42 unsigned int flags,
43 const CompSize &screenSize);43 const CompSize &screenSize);
44
45CompPoint & constrainPositionToWorkArea (CompPoint &pos,
46 const compiz::window::Geometry &serverGeometry,
47 const CompWindowExtents &border,
48 const CompRect &workArea,
49 bool staticGravity);
44}50}
45}51}
4652
4753
=== modified file 'plugins/place/src/constrain-to-workarea/src/constrain-to-workarea.cpp'
--- plugins/place/src/constrain-to-workarea/src/constrain-to-workarea.cpp 2012-04-04 04:47:00 +0000
+++ plugins/place/src/constrain-to-workarea/src/constrain-to-workarea.cpp 2013-03-24 05:56:21 +0000
@@ -31,12 +31,15 @@
31}31}
32}32}
3333
34namespace cp = compiz::place;
35namespace cw = compiz::window;
36
34void37void
35compiz::place::clampGeometryToWorkArea (compiz::window::Geometry &g,38cp::clampGeometryToWorkArea (cw::Geometry &g,
36 const CompRect &workArea,39 const CompRect &workArea,
37 const CompWindowExtents &border,40 const CompWindowExtents &border,
38 unsigned int flags,41 unsigned int flags,
39 const CompSize &screenSize)42 const CompSize &screenSize)
40{43{
41 int x, y, left, right, bottom, top;44 int x, y, left, right, bottom, top;
4245
@@ -134,3 +137,57 @@
134 g.setY (g.y () + top - y);137 g.setY (g.y () + top - y);
135 }138 }
136}139}
140
141CompPoint &
142cp::constrainPositionToWorkArea (CompPoint &pos,
143 const cw::Geometry &serverGeometry,
144 const CompWindowExtents &border,
145 const CompRect &workArea,
146 bool staticGravity)
147{
148 CompWindowExtents extents;
149 int delta;
150
151 CompWindowExtents effectiveBorders = border;
152
153 /* Ignore borders in the StaticGravity case for placement
154 * because the window intended to be placed as if it didn't
155 * have them */
156 if (staticGravity)
157 {
158 effectiveBorders.left = 0;
159 effectiveBorders.right = 0;
160 effectiveBorders.top = 0;
161 effectiveBorders.bottom = 0;
162 }
163
164 extents.left = pos.x () - effectiveBorders.left;
165 extents.top = pos.y () - effectiveBorders.top;
166 extents.right = extents.left + serverGeometry.widthIncBorders () +
167 (effectiveBorders.left +
168 effectiveBorders.right);
169 extents.bottom = extents.top + serverGeometry.heightIncBorders () +
170 (effectiveBorders.top +
171 effectiveBorders.bottom);
172
173 delta = workArea.right () - extents.right;
174 if (delta < 0)
175 extents.left += delta;
176
177 delta = workArea.left () - extents.left;
178 if (delta > 0)
179 extents.left += delta;
180
181 delta = workArea.bottom () - extents.bottom;
182 if (delta < 0)
183 extents.top += delta;
184
185 delta = workArea.top () - extents.top;
186 if (delta > 0)
187 extents.top += delta;
188
189 pos.setX (extents.left + effectiveBorders.left);
190 pos.setY (extents.top + effectiveBorders.top);
191
192 return pos;
193}
137194
=== modified file 'plugins/place/src/constrain-to-workarea/tests/constrain-to-workarea/src/test-place-constrain-to-workarea.cpp'
--- plugins/place/src/constrain-to-workarea/tests/constrain-to-workarea/src/test-place-constrain-to-workarea.cpp 2012-03-30 16:30:13 +0000
+++ plugins/place/src/constrain-to-workarea/tests/constrain-to-workarea/src/test-place-constrain-to-workarea.cpp 2013-03-24 05:56:21 +0000
@@ -23,81 +23,258 @@
23 * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>23 * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
24 */24 */
2525
26#include <tr1/tuple>
26#include <test-constrain-to-workarea.h>27#include <test-constrain-to-workarea.h>
27#include <constrain-to-workarea.h>28#include <constrain-to-workarea.h>
28#include <iostream>29#include <iostream>
29#include <stdlib.h>30#include <stdlib.h>
30#include <cstring>31#include <cstring>
3132
32class CompPlaceTestConstrainToWorkarea :33namespace cw = compiz::window;
34namespace cwe = cw::extents;
35namespace cp = compiz::place;
36
37using ::testing::WithParamInterface;
38using ::testing::ValuesIn;
39using ::testing::Combine;
40
41class PlaceClampGeometryToWorkArea :
33 public CompPlaceTest42 public CompPlaceTest
34{43{
44 public:
45
46 PlaceClampGeometryToWorkArea () :
47 screensize (1000, 2000),
48 workArea (50, 50, 900, 1900),
49 flags (0)
50 {
51 memset (&extents, 0, sizeof (cwe::Extents));
52 }
53
54 protected:
55
56 CompSize screensize;
57 CompRect workArea;
58 cw::Geometry g;
59 cwe::Extents extents;
60 unsigned int flags;
35};61};
3662
37TEST_F(CompPlaceTestConstrainToWorkarea, TestConstrainToWorkarea)63namespace
38{64{
39 CompSize screensize (1000, 2000);65 const cw::Geometry LimitOfAllowedGeometry (50, 50, 900, 1900, 0);
40 CompRect workArea (50, 50, 900, 1900);66}
41 compiz::window::Geometry g (100, 100, 200, 200, 0);67
42 compiz::window::extents::Extents extents;68namespace compiz
43 unsigned int flags = 0;69{
4470namespace window
45 memset (&extents, 0, sizeof (compiz::window::extents::Extents));71{
72std::ostream & operator<<(std::ostream &os, const Geometry &g)
73{
74 return os << "Window Geometry: (" << g.x () <<
75 ", " << g.y () <<
76 ", " << g.width () <<
77 ", " << g.height () <<
78 ", " << g.border () << ")";
79}
80namespace extents
81{
82std::ostream & operator<<(std::ostream &os, const Extents &e)
83{
84 return os << "Window Extents: (left: " << e.left <<
85 ", right: " << e.right <<
86 ", top: " << e.top <<
87 ", bottom: " << e.bottom << ")";
88}
89}
90}
91}
92
93std::ostream & operator<<(std::ostream &os, const CompPoint &p)
94{
95 return os << "Point: (" << p.x () << ", " << p.y () << ")";
96}
97
98TEST_F (PlaceClampGeometryToWorkArea, NoConstrainmentRequired)
99{
100 g = cw::Geometry (100, 100, 200, 200, 0);
46101
47 /* Do nothing */102 /* Do nothing */
48 compiz::place::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);103 cp::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);
49104
50 EXPECT_EQ (g, compiz::window::Geometry (100, 100, 200, 200, 0));105 EXPECT_EQ (g, cw::Geometry (100, 100, 200, 200, 0));
51106}
107
108TEST_F (PlaceClampGeometryToWorkArea, LargerThanWorkAreaConstrainsToWorkAreaSize)
109{
52 /* Larger than workArea */110 /* Larger than workArea */
53 g = compiz::window::Geometry (50, 50, 950, 1950, 0);111 g = cw::Geometry (50, 50, 950, 1950, 0);
54112
55 compiz::place::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);113 cp::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);
56114
57 EXPECT_EQ (g, compiz::window::Geometry (50, 50, 900, 1900, 0));115 EXPECT_EQ (g, LimitOfAllowedGeometry);
58116}
117
118TEST_F (PlaceClampGeometryToWorkArea, OutsideTopLeftConstrainment)
119{
59 /* Outside top left */120 /* Outside top left */
60 g = compiz::window::Geometry (0, 0, 900, 1900, 0);121 g = cw::Geometry (0, 0, 900, 1900, 0);
61122
62 compiz::place::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);123 cp::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);
63124
64 EXPECT_EQ (g, compiz::window::Geometry (50, 50, 900, 1900, 0));125 EXPECT_EQ (g, LimitOfAllowedGeometry);
65126}
127
128TEST_F (PlaceClampGeometryToWorkArea, OutsideTopRightConstrainment)
129{
66 /* Outside top right */130 /* Outside top right */
67 g = compiz::window::Geometry (100, 0, 900, 1900, 0);131 g = cw::Geometry (100, 0, 900, 1900, 0);
68132
69 compiz::place::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);133 cp::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);
70134
71 EXPECT_EQ (g, compiz::window::Geometry (50, 50, 900, 1900, 0));135 EXPECT_EQ (g, LimitOfAllowedGeometry);
72136}
137
138TEST_F (PlaceClampGeometryToWorkArea, OutsideBottomLeftConstrainment)
139{
73 /* Outside bottom left */140 /* Outside bottom left */
74 g = compiz::window::Geometry (0, 100, 900, 1900, 0);141 g = cw::Geometry (0, 100, 900, 1900, 0);
75142
76 compiz::place::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);143 cp::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);
77144
78 EXPECT_EQ (g, compiz::window::Geometry (50, 50, 900, 1900, 0));145 EXPECT_EQ (g, LimitOfAllowedGeometry);
79146}
147
148TEST_F (PlaceClampGeometryToWorkArea, OutsideBottomRightConstrainment)
149{
80 /* Outside bottom right */150 /* Outside bottom right */
81 g = compiz::window::Geometry (100, 100, 900, 1900, 0);151 g = cw::Geometry (100, 100, 900, 1900, 0);
82152
83 compiz::place::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);153 cp::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);
84154
85 EXPECT_EQ (g, compiz::window::Geometry (50, 50, 900, 1900, 0));155 EXPECT_EQ (g, LimitOfAllowedGeometry);
86156}
157
158TEST_F (PlaceClampGeometryToWorkArea, NoChangePositionIfSizeUnchanged)
159{
87 /* For the size only case, we should not160 /* For the size only case, we should not
88 * change the position of the window if161 * change the position of the window if
89 * the size does not change */162 * the size does not change */
90 g = compiz::window::Geometry (0, 0, 900, 1900, 0);163 g = cw::Geometry (0, 0, 900, 1900, 0);
91 flags = compiz::place::clampGeometrySizeOnly;164 flags = cp::clampGeometrySizeOnly;
92165
93 compiz::place::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);166 cp::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);
94167
95 EXPECT_EQ (g, compiz::window::Geometry (0, 0, 900, 1900, 0));168 EXPECT_EQ (g, cw::Geometry (0, 0, 900, 1900, 0));
96169}
97 g = compiz::window::Geometry (0, 0, 1000, 2000, 0);170
98 flags = compiz::place::clampGeometrySizeOnly;171TEST_F (PlaceClampGeometryToWorkArea, ChangePositionIfSizeChanged)
99172{
100 compiz::place::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);173 g = cw::Geometry (0, 0, 1000, 2000, 0);
101174 flags = cp::clampGeometrySizeOnly;
102 EXPECT_EQ (g, compiz::window::Geometry (50, 50, 900, 1900, 0));175
103}176 cp::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);
177
178 EXPECT_EQ (g, LimitOfAllowedGeometry);
179}
180
181namespace
182{
183typedef std::tr1::tuple <cw::Geometry, cwe::Extents> ConstrainPositionToWorkAreaParam;
184
185const cw::Geometry & WindowGeometry (const ConstrainPositionToWorkAreaParam &p)
186{
187 return std::tr1::get <0> (p);
188}
189
190const cwe::Extents & WindowExtents (const ConstrainPositionToWorkAreaParam &p)
191{
192 return std::tr1::get <1> (p);
193}
194
195CompPoint InitialPosition (const ConstrainPositionToWorkAreaParam &p)
196{
197 /* Initial position is where the window is right now */
198 return (std::tr1::get <0> (p)).pos ();
199}
200
201const CompRect WArea (50, 50, 900, 1900);
202const CompPoint ExpectedPosition (WArea.pos ());
203}
204
205class PlaceConstrainPositionToWorkArea :
206 public CompPlaceTest,
207 public WithParamInterface <ConstrainPositionToWorkAreaParam>
208{
209 public:
210
211 PlaceConstrainPositionToWorkArea ()
212 {
213 memset (&extents, 0, sizeof (cwe::Extents));
214 }
215
216 protected:
217
218 CompRect workArea;
219 cw::Geometry g;
220 cwe::Extents extents;
221};
222
223TEST_P (PlaceConstrainPositionToWorkArea, PositionConstrainedWithExtents)
224{
225 g = WindowGeometry (GetParam ());
226 extents = WindowExtents (GetParam ());
227
228 CompPoint pos = InitialPosition (GetParam ());
229 pos = cp::constrainPositionToWorkArea (pos, g, extents, WArea, false);
230
231 const CompPoint expectedAfterExtentsAdjustment = ExpectedPosition +
232 CompPoint (extents.left,
233 extents.top);
234
235 EXPECT_EQ (expectedAfterExtentsAdjustment, pos);
236}
237
238TEST_P (PlaceConstrainPositionToWorkArea, PositionConstrainedStaticGravity)
239{
240 g = WindowGeometry (GetParam ());
241 extents = WindowExtents (GetParam ());
242
243 CompPoint pos = InitialPosition (GetParam ());
244 pos = cp::constrainPositionToWorkArea (pos, g, extents, WArea, true);
245
246 /* Do not adjust residual position for extents with windows
247 * that have a static gravity */
248 EXPECT_EQ (ExpectedPosition, pos);
249}
250
251namespace
252{
253cwe::Extents PossibleExtents[] =
254{
255 cwe::Extents (0, 0, 0, 0),
256 cwe::Extents (1, 0, 0, 0),
257 cwe::Extents (0, 1, 0, 0),
258 cwe::Extents (0, 0, 1, 0),
259 cwe::Extents (0, 0, 0, 1)
260};
261
262cw::Geometry PossibleGeometries[] =
263{
264 cw::Geometry (WArea.x (), WArea.y (),
265 WArea.width (), WArea.height (), 0),
266 cw::Geometry (WArea.x () - 1, WArea.y (),
267 WArea.width (), WArea.height (), 0),
268 cw::Geometry (WArea.x (), WArea.y () - 1,
269 WArea.width (), WArea.height (), 0),
270 cw::Geometry (WArea.x () + 1, WArea.y (),
271 WArea.width (), WArea.height (), 0),
272 cw::Geometry (WArea.x (), WArea.y () + 1,
273 WArea.width (), WArea.height (), 0)
274};
275}
276
277INSTANTIATE_TEST_CASE_P (PlacementData,
278 PlaceConstrainPositionToWorkArea,
279 Combine (ValuesIn (PossibleGeometries),
280 ValuesIn (PossibleExtents)));
104281
=== modified file 'plugins/place/src/place.cpp'
--- plugins/place/src/place.cpp 2012-12-19 18:05:01 +0000
+++ plugins/place/src/place.cpp 2013-03-24 05:56:21 +0000
@@ -24,6 +24,8 @@
2424
25COMPIZ_PLUGIN_20090315 (place, PlacePluginVTable)25COMPIZ_PLUGIN_20090315 (place, PlacePluginVTable)
2626
27namespace cp = compiz::place;
28
27#define XWINDOWCHANGES_INIT {0, 0, 0, 0, 0, None, 0}29#define XWINDOWCHANGES_INIT {0, 0, 0, 0, 0, None, 0}
2830
29PlaceScreen::PlaceScreen (CompScreen *screen) :31PlaceScreen::PlaceScreen (CompScreen *screen) :
@@ -1203,36 +1205,13 @@
1203PlaceWindow::constrainToWorkarea (const CompRect &workArea,1205PlaceWindow::constrainToWorkarea (const CompRect &workArea,
1204 CompPoint &pos)1206 CompPoint &pos)
1205{1207{
1206 CompWindowExtents extents;1208 bool staticGravity = window->sizeHints ().win_gravity & StaticGravity;
1207 int delta;1209
12081210 pos = cp::constrainPositionToWorkArea (pos,
1209 extents.left = pos.x () - window->border ().left;1211 window->serverGeometry (),
1210 extents.top = pos.y () - window->border ().top;1212 window->border (),
1211 extents.right = extents.left + window->serverGeometry ().widthIncBorders () +1213 workArea,
1212 (window->border ().left +1214 staticGravity);
1213 window->border ().right);
1214 extents.bottom = extents.top + window->serverGeometry ().heightIncBorders () +
1215 (window->border ().top +
1216 window->border ().bottom);
1217
1218 delta = workArea.right () - extents.right;
1219 if (delta < 0)
1220 extents.left += delta;
1221
1222 delta = workArea.left () - extents.left;
1223 if (delta > 0)
1224 extents.left += delta;
1225
1226 delta = workArea.bottom () - extents.bottom;
1227 if (delta < 0)
1228 extents.top += delta;
1229
1230 delta = workArea.top () - extents.top;
1231 if (delta > 0)
1232 extents.top += delta;
1233
1234 pos.setX (extents.left + window->border ().left);
1235 pos.setY (extents.top + window->border ().top);
12361215
1237}1216}
12381217

Subscribers

People subscribed via source and target branches