Merge lp:~compiz-team/compiz/compiz.fix_1159324.1 into lp:compiz/0.9.10

Proposed by Sam Spilsbury
Status: Merged
Approved by: Sam Spilsbury
Approved revision: 3638
Merged at revision: 3652
Proposed branch: lp:~compiz-team/compiz/compiz.fix_1159324.1
Merge into: lp:compiz/0.9.10
Diff against target: 763 lines (+570/-102)
6 files modified
plugins/place/src/constrain-to-workarea/include/constrain-to-workarea.h (+28/-0)
plugins/place/src/constrain-to-workarea/src/constrain-to-workarea.cpp (+151/-0)
plugins/place/src/constrain-to-workarea/tests/constrain-to-workarea/src/test-place-constrain-to-workarea.cpp (+333/-0)
plugins/place/src/place.cpp (+38/-102)
src/window/extents/include/core/windowextents.h (+4/-0)
src/window/extents/src/windowextents.cpp (+16/-0)
To merge this branch: bzr merge lp:~compiz-team/compiz/compiz.fix_1159324.1
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Sam Spilsbury Approve
MC Return Pending
Daniel van Vugt Pending
Review via email: mp+157987@code.launchpad.net

This proposal supersedes a proposal from 2013-04-02.

Commit message

Also take into account the gravity requirements when validating reposition
requests. Get most of that code under test too.

(LP: #1159324)

Description of the change

Also take into account the gravity requirements when validating reposition
requests. Get most of that code under test too.

(LP: #1159324)

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

A typo in the comment here:

52 + /* left, right, top, bottom target coordinates, clamed to viewport

Revision history for this message
MC Return (mc-return) wrote : Posted in a previous version of this proposal

In 'plugins/place/src/constrain-to-workarea/include/constrain-to-workarea.h' one newline here is redundant:

8 +
9 +

Other than those 2 minor issues this seems perfect and very useful !

Are you sure it fixes bug #1159324 ? It seems that this is already fixed.

But +1 for the restructuring anyway.

review: Approve
Revision history for this message
Sam Spilsbury (smspillaz) wrote : Posted in a previous version of this proposal

On Sun, Mar 31, 2013 at 8:00 PM, MC Return <email address hidden> wrote:
> Review: Approve
>
> In 'plugins/place/src/constrain-to-workarea/include/constrain-to-workarea.h' one newline here is redundant:
>
> 8 +
> 9 +
>
> Other than those 2 minor issues this seems perfect and very useful !
>
> Are you sure it fixes bug #1159324 ? It seems that this is already fixed.

There was a corner case where it could still happen. Seemed to be
mostly on multimonitor cases. The window would be placed normally
(ok), and then request a new position, and then be constrained as if
it had a border, but that was wrong, because we were never meant to do
that.

>
> But +1 for the restructuring anyway.
> --
> https://code.launchpad.net/~compiz-team/compiz/compiz.fix_1159324.1/+merge/156245
> Your team Compiz Maintainers is requested to review the proposed merge of lp:~compiz-team/compiz/compiz.fix_1159324.1 into lp:compiz.

--
Sam Spilsbury

Revision history for this message
MC Return (mc-return) wrote : Posted in a previous version of this proposal

>
> There was a corner case where it could still happen. Seemed to be
> mostly on multimonitor cases. The window would be placed normally
> (ok), and then request a new position, and then be constrained as if
> it had a border, but that was wrong, because we were never meant to do
> that.
>
Hmm, that reminds me of a bug I still experience (just with Emerald):

Open any media player-> maximize it -> make it go fullscreen -> restore it
Result:
The window still has no decoration (because it is Unity-maximized),
which is correct, but the window is placed, like it would be decorated,
shifted to the right and down, but with correct window size (making lower
and right part of the window go offscreen...

Revision history for this message
MC Return (mc-return) wrote : Posted in a previous version of this proposal

Another minor typo in a comment:

+/* Just here to keep ABI compatability */

should be

+/* Just here to keep ABI compatibility */

2x

Revision history for this message
Daniel van Vugt (vanvugt) wrote : Posted in a previous version of this proposal

Please re-target this for lp:compiz/0.9.10

review: Needs Resubmitting
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
MC Return (mc-return) wrote : Posted in a previous version of this proposal

This is btw still broken in Raring.
It is not about me, as I got this fix running here locally, but if this won't land into 0.9.10, it probably will never land in Raring either...

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
MC Return (mc-return) wrote : Posted in a previous version of this proposal

/tmp/buildd/compiz-0.9.9~daily13.02.28bzr3640pkg0raring60/compizconfig/gsettings/tests/test_gsettings_tests.cpp:2270:1: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <file:///usr/share/doc/gcc-4.7/README.Bugs> for instructions.
The bug is not reproducible, so it is likely a hardware or OS problem.
make[3]: *** [compizconfig/gsettings/tests/CMakeFiles/compizconfig_test_gsettings.dir/test_gsettings_tests.cpp.o] Error 1
make[3]: Leaving directory `/tmp/buildd/compiz-0.9.9~daily13.02.28bzr3640pkg0raring60/obj-arm-linux-gnueabihf'
make[2]: *** [compizconfig/gsettings/tests/CMakeFiles/compizconfig_test_gsettings.dir/all] Error 2
make[2]: *** Waiting for unfinished jobs....

Seems like a Jenkins problem...

Reapproving (probably without effect)

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Sam Spilsbury (smspillaz) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Sam Spilsbury (smspillaz) wrote :

So I think the arm builder is running out of memory? This is a problem ...

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 2013-03-24 05:51:41 +0000
+++ plugins/place/src/constrain-to-workarea/include/constrain-to-workarea.h 2013-04-10 04:16:22 +0000
@@ -47,6 +47,34 @@
47 const CompWindowExtents &border,47 const CompWindowExtents &border,
48 const CompRect &workArea,48 const CompRect &workArea,
49 bool staticGravity);49 bool staticGravity);
50
51
52CompPoint getViewportRelativeCoordinates (const compiz::window::Geometry &geom,
53 const CompSize &screen);
54
55CompWindowExtents getWindowEdgePositions (const CompPoint &position,
56 const compiz::window::Geometry &geom,
57 const CompWindowExtents &border,
58 unsigned int gravity);
59
60void clampHorizontalEdgePositionsToWorkArea (CompWindowExtents &edgePositions,
61 const CompRect &workArea);
62void clampVerticalEdgePositionsToWorkArea (CompWindowExtents &edgePositions,
63 const CompRect &workArea);
64
65void subtractBordersFromEdgePositions (CompWindowExtents &edgePositions,
66 const CompWindowExtents &border,
67 unsigned int legacyBorder,
68 unsigned int gravity);
69
70bool onlySizeChanged (unsigned int mask);
71bool applyWidthChange (const CompWindowExtents &edgePositions,
72 XWindowChanges &xwc,
73 unsigned int &mask);
74
75bool applyHeightChange (const CompWindowExtents &edgePositions,
76 XWindowChanges &xwc,
77 unsigned int &mask);
50}78}
51}79}
5280
5381
=== modified file 'plugins/place/src/constrain-to-workarea/src/constrain-to-workarea.cpp'
--- plugins/place/src/constrain-to-workarea/src/constrain-to-workarea.cpp 2013-03-24 05:51:41 +0000
+++ plugins/place/src/constrain-to-workarea/src/constrain-to-workarea.cpp 2013-04-10 04:16:22 +0000
@@ -191,3 +191,154 @@
191191
192 return pos;192 return pos;
193}193}
194
195CompPoint cp::getViewportRelativeCoordinates (const cw::Geometry &geom,
196 const CompSize &screen)
197{
198
199 /* left, right, top, bottom target coordinates, clamed to viewport
200 * sizes as we don't need to validate movements to other viewports;
201 * we are only interested in inner-viewport movements */
202
203 int x = geom.x () % screen.width ();
204 if ((geom.x2 ()) < 0)
205 x += screen.width ();
206
207 int y = geom.y () % screen.height ();
208 if ((geom.y2 ()) < 0)
209 y += screen.height ();
210
211 return CompPoint (x, y);
212}
213
214CompWindowExtents cp::getWindowEdgePositions (const CompPoint &position,
215 const cw::Geometry &geom,
216 const CompWindowExtents &border,
217 unsigned int gravity)
218{
219 CompWindowExtents edgePositions;
220 CompWindowExtents effectiveBorder (border);
221
222 if (gravity & StaticGravity)
223 effectiveBorder = CompWindowExtents (0, 0, 0, 0);
224
225 edgePositions.left = position.x () - effectiveBorder.left;
226 edgePositions.right = edgePositions.left +
227 geom.widthIncBorders () + (effectiveBorder.left +
228 effectiveBorder.right);
229 edgePositions.top = position.y () - effectiveBorder.top;
230 edgePositions.bottom = edgePositions.top +
231 geom.heightIncBorders () + (effectiveBorder.top +
232 effectiveBorder.bottom);
233
234 return edgePositions;
235}
236
237void cp::clampHorizontalEdgePositionsToWorkArea (CompWindowExtents &edgePositions,
238 const CompRect &workArea)
239{
240 if ((edgePositions.right - edgePositions.left) > workArea.width ())
241 {
242 edgePositions.left = workArea.left ();
243 edgePositions.right = workArea.right ();
244 }
245 else
246 {
247 if (edgePositions.left < workArea.left ())
248 {
249 edgePositions.right += workArea.left () - edgePositions.left;
250 edgePositions.left = workArea.left ();
251 }
252
253 if (edgePositions.right > workArea.right ())
254 {
255 edgePositions.left -= edgePositions.right - workArea.right ();
256 edgePositions.right = workArea.right ();
257 }
258 }
259
260}
261
262void cp::clampVerticalEdgePositionsToWorkArea (CompWindowExtents &edgePositions,
263 const CompRect &workArea)
264{
265 if ((edgePositions.bottom - edgePositions.top) > workArea.height ())
266 {
267 edgePositions.top = workArea.top ();
268 edgePositions.bottom = workArea.bottom ();
269 }
270 else
271 {
272 if (edgePositions.top < workArea.top ())
273 {
274 edgePositions.bottom += workArea.top () - edgePositions.top;
275 edgePositions.top = workArea.top ();
276 }
277
278 if (edgePositions.bottom > workArea.bottom ())
279 {
280 edgePositions.top -= edgePositions.bottom - workArea.bottom ();
281 edgePositions.bottom = workArea.bottom ();
282 }
283 }
284}
285
286void cp::subtractBordersFromEdgePositions (CompWindowExtents &edgePositions,
287 const CompWindowExtents &border,
288 unsigned int legacyBorder,
289 unsigned int gravity)
290{
291 const unsigned int doubleBorder = 2 * legacyBorder;
292 CompWindowExtents effectiveBorder = border;
293
294 if (gravity & StaticGravity)
295 effectiveBorder = CompWindowExtents (0, 0, 0, 0);
296
297 edgePositions.left += effectiveBorder.left;
298 edgePositions.right -= effectiveBorder.right + doubleBorder;
299 edgePositions.top += effectiveBorder.top;
300 edgePositions.bottom -= effectiveBorder.bottom + doubleBorder;
301}
302
303bool cp::onlySizeChanged (unsigned int mask)
304{
305 return (!(mask & (CWX | CWY)) && (mask & (CWWidth | CWHeight)));
306}
307
308bool cp::applyWidthChange (const CompWindowExtents &edgePositions,
309 XWindowChanges &xwc,
310 unsigned int &mask)
311{
312 bool alreadySet = mask & CWWidth;
313
314 if (alreadySet)
315 alreadySet = edgePositions.right - edgePositions.left == xwc.width;
316
317 if (!alreadySet)
318 {
319 xwc.width = edgePositions.right - edgePositions.left;
320 mask |= CWWidth;
321 return true;
322 }
323
324 return false;
325}
326
327bool cp::applyHeightChange (const CompWindowExtents &edgePositions,
328 XWindowChanges &xwc,
329 unsigned int &mask)
330{
331 bool alreadySet = mask & CWHeight;
332
333 if (alreadySet)
334 alreadySet = edgePositions.bottom - edgePositions.top == xwc.height;
335
336 if (!alreadySet)
337 {
338 xwc.height = edgePositions.bottom - edgePositions.top;
339 mask |= CWHeight;
340 return true;
341 }
342
343 return false;
344}
194345
=== 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 2013-03-24 05:51:41 +0000
+++ plugins/place/src/constrain-to-workarea/tests/constrain-to-workarea/src/test-place-constrain-to-workarea.cpp 2013-04-10 04:16:22 +0000
@@ -278,3 +278,336 @@
278 PlaceConstrainPositionToWorkArea,278 PlaceConstrainPositionToWorkArea,
279 Combine (ValuesIn (PossibleGeometries),279 Combine (ValuesIn (PossibleGeometries),
280 ValuesIn (PossibleExtents)));280 ValuesIn (PossibleExtents)));
281class PlaceGetEdgePositions :
282 public CompPlaceTest
283{
284 public:
285
286 PlaceGetEdgePositions () :
287 geom (100, 200, 300, 400, 1),
288 border (1, 2, 3, 4),
289 pos (geom.pos ())
290 {
291 }
292
293 protected:
294
295 cw::Geometry geom;
296 cwe::Extents border;
297 CompPoint pos;
298};
299
300TEST_F (PlaceGetEdgePositions, GetEdgePositionsNWGravity)
301{
302 int left = geom.x () - border.left;
303 int right = left + (geom.widthIncBorders ()) +
304 (border.left + border.right);
305 int top = geom.y () - border.top;
306 int bottom = top + (geom.heightIncBorders ()) +
307 (border.top + border.bottom);
308
309 const cwe::Extents ExpectedExtents (left, right, top, bottom);
310 cwe::Extents actualExtents (cp::getWindowEdgePositions (pos,
311 geom,
312 border,
313 NorthWestGravity));
314
315 EXPECT_EQ (ExpectedExtents, actualExtents);
316}
317
318TEST_F (PlaceGetEdgePositions, GetEdgePositionsStaticGravity)
319{
320 /* Don't count borders in validation */
321 int left = geom.x ();
322 int right = left + (geom.widthIncBorders ());
323 int top = geom.y ();
324 int bottom = top + (geom.heightIncBorders ());
325
326 const cwe::Extents ExpectedExtents (left, right, top, bottom);
327 cwe::Extents actualExtents (cp::getWindowEdgePositions (pos,
328 geom,
329 border,
330 StaticGravity));
331
332 EXPECT_EQ (ExpectedExtents, actualExtents);
333}
334
335namespace
336{
337const CompSize SCREEN_SIZE (1000, 1000);
338const unsigned int WINDOW_SIZE = 250;
339}
340
341TEST (PlaceGetViewportRelativeCoordinates, WithinScreenWidth)
342{
343 cw::Geometry geom (SCREEN_SIZE.width () / 2,
344 SCREEN_SIZE.height () / 2,
345 WINDOW_SIZE, WINDOW_SIZE,
346 0);
347
348 CompPoint position (cp::getViewportRelativeCoordinates (geom,
349 SCREEN_SIZE));
350 EXPECT_EQ (geom.pos ().x (), position.x ());
351}
352
353TEST (PlaceGetViewportRelativeCoordinates, WithinScreenHeight)
354{
355 cw::Geometry geom (SCREEN_SIZE.width () / 2,
356 SCREEN_SIZE.height () / 2,
357 WINDOW_SIZE, WINDOW_SIZE,
358 0);
359
360 CompPoint position (cp::getViewportRelativeCoordinates (geom,
361 SCREEN_SIZE));
362 EXPECT_EQ (geom.pos ().y (), position.y ());
363}
364
365TEST (PlaceGetViewportRelativeCoordinates, OutsideOuterScreenWidth)
366{
367 cw::Geometry geom (SCREEN_SIZE.width () + 1,
368 SCREEN_SIZE.height () / 2,
369 WINDOW_SIZE, WINDOW_SIZE,
370 0);
371
372 CompPoint position (cp::getViewportRelativeCoordinates (geom,
373 SCREEN_SIZE));
374 EXPECT_EQ (1, position.x ());
375}
376
377TEST (PlaceGetViewportRelativeCoordinates, OutsideInnerScreenWidth)
378{
379 cw::Geometry geom (-(WINDOW_SIZE + 1),
380 SCREEN_SIZE.height () / 2,
381 WINDOW_SIZE, WINDOW_SIZE,
382 0);
383
384 CompPoint position (cp::getViewportRelativeCoordinates (geom,
385 SCREEN_SIZE));
386 EXPECT_EQ (SCREEN_SIZE.width () - (WINDOW_SIZE + 1),
387 position.x ());
388}
389
390TEST (PlaceGetViewportRelativeCoordinates, OutsideOuterScreenHeight)
391{
392 cw::Geometry geom (SCREEN_SIZE.width () / 2,
393 SCREEN_SIZE.height () + 1,
394 WINDOW_SIZE, WINDOW_SIZE,
395 0);
396
397 CompPoint position (cp::getViewportRelativeCoordinates (geom,
398 SCREEN_SIZE));
399 EXPECT_EQ (1, position.y ());
400}
401
402TEST (PlaceGetViewportRelativeCoordinates, OutsideInnerScreenHeight)
403{
404 cw::Geometry geom (SCREEN_SIZE.width () / 2,
405 -(WINDOW_SIZE + 1),
406 WINDOW_SIZE, WINDOW_SIZE,
407 0);
408
409 CompPoint position (cp::getViewportRelativeCoordinates (geom,
410 SCREEN_SIZE));
411 EXPECT_EQ (SCREEN_SIZE.height () - (WINDOW_SIZE + 1),
412 position.y ());
413}
414
415namespace
416{
417const CompRect WORK_AREA (25, 25, 1000, 1000);
418
419const cwe::Extents EdgePositions[] =
420{
421 /* Exact match */
422 cwe::Extents (WORK_AREA.left (), WORK_AREA.right (),
423 WORK_AREA.top (), WORK_AREA.bottom ()),
424 /* Just within */
425 cwe::Extents (WORK_AREA.left () + 1, WORK_AREA.right () - 1,
426 WORK_AREA.top () + 1, WORK_AREA.bottom () - 1),
427 /* Just outside right */
428 cwe::Extents (WORK_AREA.left () + 1, WORK_AREA.right () + 1,
429 WORK_AREA.top (), WORK_AREA.bottom ()),
430 /* Just outside left */
431 cwe::Extents (WORK_AREA.left () - 1, WORK_AREA.right () - 1,
432 WORK_AREA.top (), WORK_AREA.bottom ()),
433 /* Just outside top */
434 cwe::Extents (WORK_AREA.left (), WORK_AREA.right (),
435 WORK_AREA.top () - 1, WORK_AREA.bottom () - 1),
436 /* Just outside bottom */
437 cwe::Extents (WORK_AREA.left (), WORK_AREA.right (),
438 WORK_AREA.top () + 1, WORK_AREA.bottom () + 1),
439};
440}
441
442class PlaceClampEdgePositions :
443 public CompPlaceTest,
444 public WithParamInterface <CompWindowExtents>
445{
446};
447
448TEST_P (PlaceClampEdgePositions, WithinWorkAreaWidth)
449{
450 CompWindowExtents edgePositions (GetParam ());
451 cp::clampHorizontalEdgePositionsToWorkArea (edgePositions,
452 WORK_AREA);
453
454 const int edgePositionsWidth = edgePositions.right - edgePositions.left;
455
456 ASSERT_GT (edgePositionsWidth, 0);
457 EXPECT_LE (edgePositionsWidth, WORK_AREA.width ());
458}
459
460TEST_P (PlaceClampEdgePositions, OutsideLeft)
461{
462 CompWindowExtents edgePositions (GetParam ());
463 cp::clampHorizontalEdgePositionsToWorkArea (edgePositions,
464 WORK_AREA);
465
466 ASSERT_GE (edgePositions.left, WORK_AREA.left ());
467 ASSERT_GE (edgePositions.right, WORK_AREA.left ());
468}
469
470TEST_P (PlaceClampEdgePositions, OutsideRight)
471{
472 CompWindowExtents edgePositions (GetParam ());
473 cp::clampHorizontalEdgePositionsToWorkArea (edgePositions,
474 WORK_AREA);
475
476 ASSERT_LE (edgePositions.left, WORK_AREA.right ());
477 ASSERT_LE (edgePositions.right, WORK_AREA.right ());
478}
479
480TEST_P (PlaceClampEdgePositions, WithinWorkAreaHeight)
481{
482 CompWindowExtents edgePositions (GetParam ());
483 cp::clampVerticalEdgePositionsToWorkArea (edgePositions,
484 WORK_AREA);
485
486 const int edgePositionsHeight = edgePositions.bottom - edgePositions.top;
487
488 ASSERT_GT (edgePositionsHeight, 0);
489 EXPECT_LE (edgePositionsHeight, WORK_AREA.height ());
490}
491
492TEST_P (PlaceClampEdgePositions, OutsideTop)
493{
494 CompWindowExtents edgePositions (GetParam ());
495 cp::clampVerticalEdgePositionsToWorkArea (edgePositions,
496 WORK_AREA);
497
498 ASSERT_GE (edgePositions.top, WORK_AREA.top ());
499 ASSERT_GE (edgePositions.bottom, WORK_AREA.top ());
500}
501
502TEST_P (PlaceClampEdgePositions, OutsideBottom)
503{
504 CompWindowExtents edgePositions (GetParam ());
505 cp::clampVerticalEdgePositionsToWorkArea (edgePositions,
506 WORK_AREA);
507
508 ASSERT_LE (edgePositions.top, WORK_AREA.bottom ());
509 ASSERT_LE (edgePositions.bottom, WORK_AREA.bottom ());
510}
511
512INSTANTIATE_TEST_CASE_P (WAEdgePositions, PlaceClampEdgePositions,
513 ValuesIn (EdgePositions));
514
515TEST (PlaceSubtractBordersFromEdgePositions, NormalGravity)
516{
517 const CompWindowExtents borders (1, 2, 3, 4);
518 const CompWindowExtents edgePositions (100, 200, 100, 200);
519 const unsigned int legacyBorder = 1;
520
521 CompWindowExtents expectedEdgePositions (edgePositions.left + (borders.left),
522 edgePositions.right - (borders.right + 2 * legacyBorder),
523 edgePositions.top + (borders.top),
524 edgePositions.bottom - (borders.bottom + 2 * legacyBorder));
525
526 CompWindowExtents modifiedEdgePositions (edgePositions);
527
528 cp::subtractBordersFromEdgePositions (modifiedEdgePositions,
529 borders,
530 legacyBorder,
531 NorthWestGravity);
532
533 EXPECT_EQ (expectedEdgePositions, modifiedEdgePositions);
534}
535
536TEST (PlaceSubtractBordersFromEdgePositions, StaticGravityDefinition)
537{
538 const CompWindowExtents borders (1, 2, 3, 4);
539 const CompWindowExtents edgePositions (100, 200, 100, 200);
540 const unsigned int legacyBorder = 1;
541
542 CompWindowExtents expectedEdgePositions (edgePositions.left,
543 edgePositions.right - (2 * legacyBorder),
544 edgePositions.top,
545 edgePositions.bottom - (2 * legacyBorder));
546
547 CompWindowExtents modifiedEdgePositions (edgePositions);
548
549 cp::subtractBordersFromEdgePositions (modifiedEdgePositions,
550 borders,
551 legacyBorder,
552 StaticGravity);
553
554 EXPECT_EQ (expectedEdgePositions, modifiedEdgePositions);
555}
556
557TEST (PlaceSizeAndPositionChanged, PositionChangedReturnsFalse)
558{
559 EXPECT_FALSE (cp::onlySizeChanged (CWX | CWY));
560}
561
562TEST (PlaceSizeAndPositionChanged, SizeChangedReturnsTrue)
563{
564 EXPECT_TRUE (cp::onlySizeChanged (CWWidth | CWHeight));
565}
566
567TEST (PlaceSizeAndPositionChanged, XAndWidthChangedReturnsFalse)
568{
569 EXPECT_FALSE (cp::onlySizeChanged (CWX | CWWidth));
570}
571
572TEST (PlaceSizeAndPositionChanged, YAndHeightChangedReturnsFalse)
573{
574 EXPECT_FALSE (cp::onlySizeChanged (CWY | CWHeight));
575}
576
577TEST (PlaceApplyWidthChange, ReturnFalseIfNoChange)
578{
579 CompWindowExtents edgePositions (100, 200, 100, 200);
580 XWindowChanges xwc;
581 xwc.width = 100;
582 unsigned int mask = CWWidth;
583 EXPECT_FALSE (cp::applyWidthChange(edgePositions, xwc, mask));
584}
585
586TEST (PlaceApplyWidthChange, ApplyWidthAndSetFlag)
587{
588 CompWindowExtents edgePositions (100, 200, 100, 200);
589 XWindowChanges xwc;
590 unsigned int mask = 0;
591 ASSERT_TRUE (cp::applyWidthChange(edgePositions, xwc, mask));
592 EXPECT_EQ (edgePositions.right - edgePositions.left, xwc.width);
593 EXPECT_EQ (CWWidth, mask);
594}
595
596TEST (PlaceApplyHeightChange, ReturnFalseIfNoChange)
597{
598 CompWindowExtents edgePositions (100, 200, 100, 200);
599 XWindowChanges xwc;
600 xwc.height = 100;
601 unsigned int mask = CWHeight;
602 EXPECT_FALSE (cp::applyHeightChange(edgePositions, xwc, mask));
603}
604
605TEST (PlaceApplyWidthChange, ApplyHeightAndSetFlag)
606{
607 CompWindowExtents edgePositions (100, 200, 100, 200);
608 XWindowChanges xwc;
609 unsigned int mask = 0;
610 ASSERT_TRUE (cp::applyHeightChange(edgePositions, xwc, mask));
611 EXPECT_EQ (edgePositions.bottom - edgePositions.top, xwc.height);
612 EXPECT_EQ (CWHeight, mask);
613}
281614
=== modified file 'plugins/place/src/place.cpp'
--- plugins/place/src/place.cpp 2013-04-07 08:46:23 +0000
+++ plugins/place/src/place.cpp 2013-04-10 04:16:22 +0000
@@ -350,46 +350,23 @@
350CompRect350CompRect
351PlaceWindow::doValidateResizeRequest (unsigned int &mask,351PlaceWindow::doValidateResizeRequest (unsigned int &mask,
352 XWindowChanges *xwc,352 XWindowChanges *xwc,
353 bool sizeOnly,353 bool onlyValidateSize,
354 bool clampToViewport)354 bool clampToViewport)
355{355{
356 CompRect workArea;356 CompWindow::Geometry geom (xwc->x, xwc->y, xwc->width, xwc->height,
357 int x, y, left, right, bottom, top;357 window->serverGeometry ().border ());
358 CompWindow::Geometry geom;358 CompPoint pos (geom.pos ());
359 int output;
360
361 geom.set (xwc->x, xwc->y, xwc->width, xwc->height,
362 window->serverGeometry ().border ());
363359
364 if (clampToViewport)360 if (clampToViewport)
365 {361 pos = cp::getViewportRelativeCoordinates(geom, *screen);
366 /* left, right, top, bottom target coordinates, clamed to viewport362
367 * sizes as we don't need to validate movements to other viewports;363 CompWindowExtents edgePositions = cp::getWindowEdgePositions (pos,
368 * we are only interested in inner-viewport movements */364 geom,
369365 window->border (),
370 x = geom.x () % screen->width ();366 window->sizeHints ().win_gravity);
371 if ((geom.x2 ()) < 0)367
372 x += screen->width ();368 int output = screen->outputDeviceForGeometry (geom);
373369 CompRect workArea = screen->getWorkareaForOutput (output);
374 y = geom.y () % screen->height ();
375 if ((geom.y2 ()) < 0)
376 y += screen->height ();
377 }
378 else
379 {
380 x = geom.x ();
381 y = geom.y ();
382 }
383
384 left = x - window->border ().left;
385 right = left + geom.widthIncBorders () + (window->border ().left +
386 window->border ().right);
387 top = y - window->border ().top;
388 bottom = top + geom.heightIncBorders () + (window->border ().top +
389 window->border ().bottom);
390
391 output = screen->outputDeviceForGeometry (geom);
392 workArea = screen->getWorkareaForOutput (output);
393370
394 if (clampToViewport &&371 if (clampToViewport &&
395 xwc->width >= workArea.width () &&372 xwc->width >= workArea.width () &&
@@ -403,82 +380,41 @@
403 }380 }
404 }381 }
405382
406 if ((right - left) > workArea.width ())383 cp::clampHorizontalEdgePositionsToWorkArea (edgePositions, workArea);
407 {384 cp::clampVerticalEdgePositionsToWorkArea (edgePositions, workArea);
408 left = workArea.left ();
409 right = workArea.right ();
410 }
411 else
412 {
413 if (left < workArea.left ())
414 {
415 right += workArea.left () - left;
416 left = workArea.left ();
417 }
418
419 if (right > workArea.right ())
420 {
421 left -= right - workArea.right ();
422 right = workArea.right ();
423 }
424 }
425
426 if ((bottom - top) > workArea.height ())
427 {
428 top = workArea.top ();
429 bottom = workArea.bottom ();
430 }
431 else
432 {
433 if (top < workArea.top ())
434 {
435 bottom += workArea.top () - top;
436 top = workArea.top ();
437 }
438
439 if (bottom > workArea.bottom ())
440 {
441 top -= bottom - workArea.bottom ();
442 bottom = workArea.bottom ();
443 }
444 }
445385
446 /* bring left/right/top/bottom to actual window coordinates */386 /* bring left/right/top/bottom to actual window coordinates */
447 left += window->border ().left;387 cp::subtractBordersFromEdgePositions (edgePositions,
448 right -= window->border ().right + 2 * window->serverGeometry ().border ();388 window->border (),
449 top += window->border ().top;389 geom.border (),
450 bottom -= window->border ().bottom + 2 * window->serverGeometry ().border ();390 window->sizeHints ().win_gravity);
451391
452 /* always validate position if the application changed only its size,392 /* always validate position if the application changed only its size,
453 * as it might become partially offscreen because of that */393 * as it might become partially offscreen because of that */
454 if (!(mask) & (CWX | CWY) && (mask & (CWWidth | CWHeight)))394 if (cp::onlySizeChanged (mask))
455 sizeOnly = false;395 onlyValidateSize = false;
456396
457 if ((right - left) != xwc->width)397 if (cp::applyWidthChange(edgePositions,
458 {398 *xwc,
459 xwc->width = right - left;399 mask))
460 mask |= CWWidth;400 onlyValidateSize = false;
461 sizeOnly = false;401
462 }402 if (cp::applyHeightChange(edgePositions,
463403 *xwc,
464 if ((bottom - top) != xwc->height)404 mask))
465 {405 onlyValidateSize = false;
466 xwc->height = bottom - top;406
467 mask |= CWHeight;407 if (!onlyValidateSize)
468 sizeOnly = false;408 {
469 }409 if (edgePositions.left != pos.x ())
470
471 if (!sizeOnly)
472 {
473 if (left != x)
474 {410 {
475 xwc->x += left - x;411 xwc->x += edgePositions.left - pos.x ();
476 mask |= CWX;412 mask |= CWX;
477 }413 }
478414
479 if (top != y)415 if (edgePositions.top != pos.y ())
480 {416 {
481 xwc->y += top - y;417 xwc->y += edgePositions.top - pos.y ();
482 mask |= CWY;418 mask |= CWY;
483 }419 }
484 }420 }
485421
=== modified file 'src/window/extents/include/core/windowextents.h'
--- src/window/extents/include/core/windowextents.h 2012-02-25 05:14:18 +0000
+++ src/window/extents/include/core/windowextents.h 2013-04-10 04:16:22 +0000
@@ -53,6 +53,10 @@
53 int top;53 int top;
54 int bottom;54 int bottom;
5555
56 bool operator== (const Extents &other) const;
57 bool operator!= (const Extents &other) const;
58
59 /* Only here for ABI compatability */
56 bool operator== (const Extents &other);60 bool operator== (const Extents &other);
57 bool operator!= (const Extents &other);61 bool operator!= (const Extents &other);
58};62};
5963
=== modified file 'src/window/extents/src/windowextents.cpp'
--- src/window/extents/src/windowextents.cpp 2012-08-09 09:06:54 +0000
+++ src/window/extents/src/windowextents.cpp 2013-04-10 04:16:22 +0000
@@ -75,17 +75,33 @@
75{75{
76}76}
7777
78/* Just here to keep ABI compatability */
78bool79bool
79compiz::window::extents::Extents::operator== (const Extents &other)80compiz::window::extents::Extents::operator== (const Extents &other)
80{81{
82 const Extents &self = const_cast <const Extents &> (*this);
83 return self == other;
84}
85
86bool
87compiz::window::extents::Extents::operator== (const Extents &other) const
88{
81 return this->left == other.left &&89 return this->left == other.left &&
82 this->right == other.right &&90 this->right == other.right &&
83 this->top == other.top &&91 this->top == other.top &&
84 this->bottom == other.bottom;92 this->bottom == other.bottom;
85}93}
8694
95/* Just here to keep ABI compatability */
87bool96bool
88compiz::window::extents::Extents::operator!= (const Extents &other)97compiz::window::extents::Extents::operator!= (const Extents &other)
89{98{
99 const Extents &self = const_cast <const Extents &> (*this);
100 return self != other;
101}
102
103bool
104compiz::window::extents::Extents::operator!= (const Extents &other) const
105{
90 return !(*this == other);106 return !(*this == other);
91}107}

Subscribers

People subscribed via source and target branches

to all changes: