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
1=== modified file 'plugins/place/src/constrain-to-workarea/include/constrain-to-workarea.h'
2--- plugins/place/src/constrain-to-workarea/include/constrain-to-workarea.h 2012-01-20 06:13:07 +0000
3+++ plugins/place/src/constrain-to-workarea/include/constrain-to-workarea.h 2013-03-24 05:56:21 +0000
4@@ -41,6 +41,12 @@
5 const CompWindowExtents &border,
6 unsigned int flags,
7 const CompSize &screenSize);
8+
9+CompPoint & constrainPositionToWorkArea (CompPoint &pos,
10+ const compiz::window::Geometry &serverGeometry,
11+ const CompWindowExtents &border,
12+ const CompRect &workArea,
13+ bool staticGravity);
14 }
15 }
16
17
18=== modified file 'plugins/place/src/constrain-to-workarea/src/constrain-to-workarea.cpp'
19--- plugins/place/src/constrain-to-workarea/src/constrain-to-workarea.cpp 2012-04-04 04:47:00 +0000
20+++ plugins/place/src/constrain-to-workarea/src/constrain-to-workarea.cpp 2013-03-24 05:56:21 +0000
21@@ -31,12 +31,15 @@
22 }
23 }
24
25+namespace cp = compiz::place;
26+namespace cw = compiz::window;
27+
28 void
29-compiz::place::clampGeometryToWorkArea (compiz::window::Geometry &g,
30- const CompRect &workArea,
31- const CompWindowExtents &border,
32- unsigned int flags,
33- const CompSize &screenSize)
34+cp::clampGeometryToWorkArea (cw::Geometry &g,
35+ const CompRect &workArea,
36+ const CompWindowExtents &border,
37+ unsigned int flags,
38+ const CompSize &screenSize)
39 {
40 int x, y, left, right, bottom, top;
41
42@@ -134,3 +137,57 @@
43 g.setY (g.y () + top - y);
44 }
45 }
46+
47+CompPoint &
48+cp::constrainPositionToWorkArea (CompPoint &pos,
49+ const cw::Geometry &serverGeometry,
50+ const CompWindowExtents &border,
51+ const CompRect &workArea,
52+ bool staticGravity)
53+{
54+ CompWindowExtents extents;
55+ int delta;
56+
57+ CompWindowExtents effectiveBorders = border;
58+
59+ /* Ignore borders in the StaticGravity case for placement
60+ * because the window intended to be placed as if it didn't
61+ * have them */
62+ if (staticGravity)
63+ {
64+ effectiveBorders.left = 0;
65+ effectiveBorders.right = 0;
66+ effectiveBorders.top = 0;
67+ effectiveBorders.bottom = 0;
68+ }
69+
70+ extents.left = pos.x () - effectiveBorders.left;
71+ extents.top = pos.y () - effectiveBorders.top;
72+ extents.right = extents.left + serverGeometry.widthIncBorders () +
73+ (effectiveBorders.left +
74+ effectiveBorders.right);
75+ extents.bottom = extents.top + serverGeometry.heightIncBorders () +
76+ (effectiveBorders.top +
77+ effectiveBorders.bottom);
78+
79+ delta = workArea.right () - extents.right;
80+ if (delta < 0)
81+ extents.left += delta;
82+
83+ delta = workArea.left () - extents.left;
84+ if (delta > 0)
85+ extents.left += delta;
86+
87+ delta = workArea.bottom () - extents.bottom;
88+ if (delta < 0)
89+ extents.top += delta;
90+
91+ delta = workArea.top () - extents.top;
92+ if (delta > 0)
93+ extents.top += delta;
94+
95+ pos.setX (extents.left + effectiveBorders.left);
96+ pos.setY (extents.top + effectiveBorders.top);
97+
98+ return pos;
99+}
100
101=== modified file 'plugins/place/src/constrain-to-workarea/tests/constrain-to-workarea/src/test-place-constrain-to-workarea.cpp'
102--- plugins/place/src/constrain-to-workarea/tests/constrain-to-workarea/src/test-place-constrain-to-workarea.cpp 2012-03-30 16:30:13 +0000
103+++ plugins/place/src/constrain-to-workarea/tests/constrain-to-workarea/src/test-place-constrain-to-workarea.cpp 2013-03-24 05:56:21 +0000
104@@ -23,81 +23,258 @@
105 * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
106 */
107
108+#include <tr1/tuple>
109 #include <test-constrain-to-workarea.h>
110 #include <constrain-to-workarea.h>
111 #include <iostream>
112 #include <stdlib.h>
113 #include <cstring>
114
115-class CompPlaceTestConstrainToWorkarea :
116+namespace cw = compiz::window;
117+namespace cwe = cw::extents;
118+namespace cp = compiz::place;
119+
120+using ::testing::WithParamInterface;
121+using ::testing::ValuesIn;
122+using ::testing::Combine;
123+
124+class PlaceClampGeometryToWorkArea :
125 public CompPlaceTest
126 {
127+ public:
128+
129+ PlaceClampGeometryToWorkArea () :
130+ screensize (1000, 2000),
131+ workArea (50, 50, 900, 1900),
132+ flags (0)
133+ {
134+ memset (&extents, 0, sizeof (cwe::Extents));
135+ }
136+
137+ protected:
138+
139+ CompSize screensize;
140+ CompRect workArea;
141+ cw::Geometry g;
142+ cwe::Extents extents;
143+ unsigned int flags;
144 };
145
146-TEST_F(CompPlaceTestConstrainToWorkarea, TestConstrainToWorkarea)
147-{
148- CompSize screensize (1000, 2000);
149- CompRect workArea (50, 50, 900, 1900);
150- compiz::window::Geometry g (100, 100, 200, 200, 0);
151- compiz::window::extents::Extents extents;
152- unsigned int flags = 0;
153-
154- memset (&extents, 0, sizeof (compiz::window::extents::Extents));
155+namespace
156+{
157+ const cw::Geometry LimitOfAllowedGeometry (50, 50, 900, 1900, 0);
158+}
159+
160+namespace compiz
161+{
162+namespace window
163+{
164+std::ostream & operator<<(std::ostream &os, const Geometry &g)
165+{
166+ return os << "Window Geometry: (" << g.x () <<
167+ ", " << g.y () <<
168+ ", " << g.width () <<
169+ ", " << g.height () <<
170+ ", " << g.border () << ")";
171+}
172+namespace extents
173+{
174+std::ostream & operator<<(std::ostream &os, const Extents &e)
175+{
176+ return os << "Window Extents: (left: " << e.left <<
177+ ", right: " << e.right <<
178+ ", top: " << e.top <<
179+ ", bottom: " << e.bottom << ")";
180+}
181+}
182+}
183+}
184+
185+std::ostream & operator<<(std::ostream &os, const CompPoint &p)
186+{
187+ return os << "Point: (" << p.x () << ", " << p.y () << ")";
188+}
189+
190+TEST_F (PlaceClampGeometryToWorkArea, NoConstrainmentRequired)
191+{
192+ g = cw::Geometry (100, 100, 200, 200, 0);
193
194 /* Do nothing */
195- compiz::place::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);
196-
197- EXPECT_EQ (g, compiz::window::Geometry (100, 100, 200, 200, 0));
198-
199+ cp::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);
200+
201+ EXPECT_EQ (g, cw::Geometry (100, 100, 200, 200, 0));
202+}
203+
204+TEST_F (PlaceClampGeometryToWorkArea, LargerThanWorkAreaConstrainsToWorkAreaSize)
205+{
206 /* Larger than workArea */
207- g = compiz::window::Geometry (50, 50, 950, 1950, 0);
208-
209- compiz::place::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);
210-
211- EXPECT_EQ (g, compiz::window::Geometry (50, 50, 900, 1900, 0));
212-
213+ g = cw::Geometry (50, 50, 950, 1950, 0);
214+
215+ cp::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);
216+
217+ EXPECT_EQ (g, LimitOfAllowedGeometry);
218+}
219+
220+TEST_F (PlaceClampGeometryToWorkArea, OutsideTopLeftConstrainment)
221+{
222 /* Outside top left */
223- g = compiz::window::Geometry (0, 0, 900, 1900, 0);
224-
225- compiz::place::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);
226-
227- EXPECT_EQ (g, compiz::window::Geometry (50, 50, 900, 1900, 0));
228-
229+ g = cw::Geometry (0, 0, 900, 1900, 0);
230+
231+ cp::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);
232+
233+ EXPECT_EQ (g, LimitOfAllowedGeometry);
234+}
235+
236+TEST_F (PlaceClampGeometryToWorkArea, OutsideTopRightConstrainment)
237+{
238 /* Outside top right */
239- g = compiz::window::Geometry (100, 0, 900, 1900, 0);
240-
241- compiz::place::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);
242-
243- EXPECT_EQ (g, compiz::window::Geometry (50, 50, 900, 1900, 0));
244-
245+ g = cw::Geometry (100, 0, 900, 1900, 0);
246+
247+ cp::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);
248+
249+ EXPECT_EQ (g, LimitOfAllowedGeometry);
250+}
251+
252+TEST_F (PlaceClampGeometryToWorkArea, OutsideBottomLeftConstrainment)
253+{
254 /* Outside bottom left */
255- g = compiz::window::Geometry (0, 100, 900, 1900, 0);
256-
257- compiz::place::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);
258-
259- EXPECT_EQ (g, compiz::window::Geometry (50, 50, 900, 1900, 0));
260-
261+ g = cw::Geometry (0, 100, 900, 1900, 0);
262+
263+ cp::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);
264+
265+ EXPECT_EQ (g, LimitOfAllowedGeometry);
266+}
267+
268+TEST_F (PlaceClampGeometryToWorkArea, OutsideBottomRightConstrainment)
269+{
270 /* Outside bottom right */
271- g = compiz::window::Geometry (100, 100, 900, 1900, 0);
272-
273- compiz::place::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);
274-
275- EXPECT_EQ (g, compiz::window::Geometry (50, 50, 900, 1900, 0));
276-
277+ g = cw::Geometry (100, 100, 900, 1900, 0);
278+
279+ cp::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);
280+
281+ EXPECT_EQ (g, LimitOfAllowedGeometry);
282+}
283+
284+TEST_F (PlaceClampGeometryToWorkArea, NoChangePositionIfSizeUnchanged)
285+{
286 /* For the size only case, we should not
287 * change the position of the window if
288 * the size does not change */
289- g = compiz::window::Geometry (0, 0, 900, 1900, 0);
290- flags = compiz::place::clampGeometrySizeOnly;
291-
292- compiz::place::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);
293-
294- EXPECT_EQ (g, compiz::window::Geometry (0, 0, 900, 1900, 0));
295-
296- g = compiz::window::Geometry (0, 0, 1000, 2000, 0);
297- flags = compiz::place::clampGeometrySizeOnly;
298-
299- compiz::place::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);
300-
301- EXPECT_EQ (g, compiz::window::Geometry (50, 50, 900, 1900, 0));
302-}
303+ g = cw::Geometry (0, 0, 900, 1900, 0);
304+ flags = cp::clampGeometrySizeOnly;
305+
306+ cp::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);
307+
308+ EXPECT_EQ (g, cw::Geometry (0, 0, 900, 1900, 0));
309+}
310+
311+TEST_F (PlaceClampGeometryToWorkArea, ChangePositionIfSizeChanged)
312+{
313+ g = cw::Geometry (0, 0, 1000, 2000, 0);
314+ flags = cp::clampGeometrySizeOnly;
315+
316+ cp::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);
317+
318+ EXPECT_EQ (g, LimitOfAllowedGeometry);
319+}
320+
321+namespace
322+{
323+typedef std::tr1::tuple <cw::Geometry, cwe::Extents> ConstrainPositionToWorkAreaParam;
324+
325+const cw::Geometry & WindowGeometry (const ConstrainPositionToWorkAreaParam &p)
326+{
327+ return std::tr1::get <0> (p);
328+}
329+
330+const cwe::Extents & WindowExtents (const ConstrainPositionToWorkAreaParam &p)
331+{
332+ return std::tr1::get <1> (p);
333+}
334+
335+CompPoint InitialPosition (const ConstrainPositionToWorkAreaParam &p)
336+{
337+ /* Initial position is where the window is right now */
338+ return (std::tr1::get <0> (p)).pos ();
339+}
340+
341+const CompRect WArea (50, 50, 900, 1900);
342+const CompPoint ExpectedPosition (WArea.pos ());
343+}
344+
345+class PlaceConstrainPositionToWorkArea :
346+ public CompPlaceTest,
347+ public WithParamInterface <ConstrainPositionToWorkAreaParam>
348+{
349+ public:
350+
351+ PlaceConstrainPositionToWorkArea ()
352+ {
353+ memset (&extents, 0, sizeof (cwe::Extents));
354+ }
355+
356+ protected:
357+
358+ CompRect workArea;
359+ cw::Geometry g;
360+ cwe::Extents extents;
361+};
362+
363+TEST_P (PlaceConstrainPositionToWorkArea, PositionConstrainedWithExtents)
364+{
365+ g = WindowGeometry (GetParam ());
366+ extents = WindowExtents (GetParam ());
367+
368+ CompPoint pos = InitialPosition (GetParam ());
369+ pos = cp::constrainPositionToWorkArea (pos, g, extents, WArea, false);
370+
371+ const CompPoint expectedAfterExtentsAdjustment = ExpectedPosition +
372+ CompPoint (extents.left,
373+ extents.top);
374+
375+ EXPECT_EQ (expectedAfterExtentsAdjustment, pos);
376+}
377+
378+TEST_P (PlaceConstrainPositionToWorkArea, PositionConstrainedStaticGravity)
379+{
380+ g = WindowGeometry (GetParam ());
381+ extents = WindowExtents (GetParam ());
382+
383+ CompPoint pos = InitialPosition (GetParam ());
384+ pos = cp::constrainPositionToWorkArea (pos, g, extents, WArea, true);
385+
386+ /* Do not adjust residual position for extents with windows
387+ * that have a static gravity */
388+ EXPECT_EQ (ExpectedPosition, pos);
389+}
390+
391+namespace
392+{
393+cwe::Extents PossibleExtents[] =
394+{
395+ cwe::Extents (0, 0, 0, 0),
396+ cwe::Extents (1, 0, 0, 0),
397+ cwe::Extents (0, 1, 0, 0),
398+ cwe::Extents (0, 0, 1, 0),
399+ cwe::Extents (0, 0, 0, 1)
400+};
401+
402+cw::Geometry PossibleGeometries[] =
403+{
404+ cw::Geometry (WArea.x (), WArea.y (),
405+ WArea.width (), WArea.height (), 0),
406+ cw::Geometry (WArea.x () - 1, WArea.y (),
407+ WArea.width (), WArea.height (), 0),
408+ cw::Geometry (WArea.x (), WArea.y () - 1,
409+ WArea.width (), WArea.height (), 0),
410+ cw::Geometry (WArea.x () + 1, WArea.y (),
411+ WArea.width (), WArea.height (), 0),
412+ cw::Geometry (WArea.x (), WArea.y () + 1,
413+ WArea.width (), WArea.height (), 0)
414+};
415+}
416+
417+INSTANTIATE_TEST_CASE_P (PlacementData,
418+ PlaceConstrainPositionToWorkArea,
419+ Combine (ValuesIn (PossibleGeometries),
420+ ValuesIn (PossibleExtents)));
421
422=== modified file 'plugins/place/src/place.cpp'
423--- plugins/place/src/place.cpp 2012-12-19 18:05:01 +0000
424+++ plugins/place/src/place.cpp 2013-03-24 05:56:21 +0000
425@@ -24,6 +24,8 @@
426
427 COMPIZ_PLUGIN_20090315 (place, PlacePluginVTable)
428
429+namespace cp = compiz::place;
430+
431 #define XWINDOWCHANGES_INIT {0, 0, 0, 0, 0, None, 0}
432
433 PlaceScreen::PlaceScreen (CompScreen *screen) :
434@@ -1203,36 +1205,13 @@
435 PlaceWindow::constrainToWorkarea (const CompRect &workArea,
436 CompPoint &pos)
437 {
438- CompWindowExtents extents;
439- int delta;
440-
441- extents.left = pos.x () - window->border ().left;
442- extents.top = pos.y () - window->border ().top;
443- extents.right = extents.left + window->serverGeometry ().widthIncBorders () +
444- (window->border ().left +
445- window->border ().right);
446- extents.bottom = extents.top + window->serverGeometry ().heightIncBorders () +
447- (window->border ().top +
448- window->border ().bottom);
449-
450- delta = workArea.right () - extents.right;
451- if (delta < 0)
452- extents.left += delta;
453-
454- delta = workArea.left () - extents.left;
455- if (delta > 0)
456- extents.left += delta;
457-
458- delta = workArea.bottom () - extents.bottom;
459- if (delta < 0)
460- extents.top += delta;
461-
462- delta = workArea.top () - extents.top;
463- if (delta > 0)
464- extents.top += delta;
465-
466- pos.setX (extents.left + window->border ().left);
467- pos.setY (extents.top + window->border ().top);
468+ bool staticGravity = window->sizeHints ().win_gravity & StaticGravity;
469+
470+ pos = cp::constrainPositionToWorkArea (pos,
471+ window->serverGeometry (),
472+ window->border (),
473+ workArea,
474+ staticGravity);
475
476 }
477

Subscribers

People subscribed via source and target branches