Merge lp:~townsend/compiz-core/fix-763148 into lp:compiz-core

Proposed by Christopher Townsend
Status: Merged
Approved by: Brandon Schaefer
Approved revision: 3135
Merged at revision: 3136
Proposed branch: lp:~townsend/compiz-core/fix-763148
Merge into: lp:compiz-core
Diff against target: 490 lines (+217/-131)
3 files modified
plugins/place/src/place.cpp (+11/-1)
plugins/place/src/screen-size-change/src/screen-size-change.cpp (+11/-38)
plugins/place/src/screen-size-change/tests/screen-size-change/src/test-place-screen-size-change.cpp (+195/-92)
To merge this branch: bzr merge lp:~townsend/compiz-core/fix-763148
Reviewer Review Type Date Requested Status
Brandon Schaefer (community) Approve
Review via email: mp+158700@code.launchpad.net

Commit message

Backport of lp:compiz/0.9.9 revno. 3646 to fix bug #763148. Also had to backport the code in the PlaceWindow destructor.

Description of the change

This is backport from lp:compiz/0.9.9 revno. 3646 to fix bug #763148. Also had to backport the code in the PlaceWindow destructor.

All tests from the backport have been included as well.

To post a comment you must log in.
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/place/src/place.cpp'
2--- plugins/place/src/place.cpp 2012-09-14 09:33:36 +0000
3+++ plugins/place/src/place.cpp 2013-04-12 19:16:27 +0000
4@@ -200,7 +200,9 @@
5 PlaceScreen::handleEvent (XEvent *event)
6 {
7 if (event->type == ConfigureNotify &&
8- event->xconfigure.window == screen->root ())
9+ event->xconfigure.window == screen->root () &&
10+ (event->xconfigure.width != screen->width () ||
11+ event->xconfigure.height != screen->height ()))
12 {
13 mPrevSize.setWidth (screen->width ());
14 mPrevSize.setHeight (screen->height ());
15@@ -300,6 +302,14 @@
16
17 PlaceWindow::~PlaceWindow ()
18 {
19+ if (!ps->mStrutWindows.empty() && window->struts())
20+ {
21+ ps->mStrutWindows.remove(window);
22+ if (ps->mStrutWindows.empty())
23+ {
24+ ps->doHandleScreenSizeChange(screen->width(), screen->height());
25+ }
26+ }
27 }
28
29 bool
30
31=== modified file 'plugins/place/src/screen-size-change/src/screen-size-change.cpp'
32--- plugins/place/src/screen-size-change/src/screen-size-change.cpp 2012-01-21 17:16:07 +0000
33+++ plugins/place/src/screen-size-change/src/screen-size-change.cpp 2013-04-12 19:16:27 +0000
34@@ -37,11 +37,9 @@
35 compiz::place::ScreenSizeChangeObject::adjustForSize (const CompSize &oldSize,
36 const CompSize &newSize)
37 {
38- int vpX, vpY, shiftX, shiftY;
39+ int vpX, vpY;
40 compiz::window::Geometry g, vpRelRect;
41 int pivotX, pivotY;
42- int curVpOffsetX = getViewport ().x () * newSize.width ();
43- int curVpOffsetY = getViewport ().y () * newSize.height ();
44
45 g = getGeometry ();
46 compiz::window::Geometry og (g);
47@@ -59,24 +57,14 @@
48 if (pivotY < 0)
49 vpY -= 1;
50
51- /* if window's target vp is to the left of the leftmost viewport on that
52- row, assign its target vp column as 0 (-s->x rel. to current vp) */
53- if (getViewport ().x () + vpX < 0)
54- vpX = -getViewport ().x ();
55-
56- /* if window's target vp is above the topmost viewport on that column,
57- assign its target vp row as 0 (-s->y rel. to current vp) */
58- if (getViewport ().y () + vpY < 0)
59- vpY = -getViewport ().y ();
60-
61 unsigned int mask = mSaver.pop (vpRelRect, CHANGE_X | CHANGE_Y |
62 CHANGE_WIDTH | CHANGE_HEIGHT);
63
64 if (mask)
65 {
66 /* set position/size to saved original rectangle */
67- g.applyChange (compiz::window::Geometry (vpRelRect.x () + vpX * newSize.width (),
68- vpRelRect.y () + vpY * newSize.height (),
69+ g.applyChange (compiz::window::Geometry (vpRelRect.x (),
70+ vpRelRect.y (),
71 vpRelRect.width (),
72 vpRelRect.height (),
73 vpRelRect.border ()), mask);
74@@ -90,42 +78,24 @@
75 vpRelRect.setWidth (g.width ());
76 vpRelRect.setHeight (g.height ());
77
78- g.setPos (g.pos ());
79-
80- shiftX = vpX * (newSize.width () - oldSize.width ());
81- shiftY = vpY * (newSize.width () - oldSize.height ());
82+ g = vpRelRect;
83
84 /* if coords. relative to viewport are outside new viewport area,
85 shift window left/up so that it falls inside */
86- if (vpRelRect.x () >= newSize.width ())
87- shiftX -= vpRelRect.x () - (newSize.width () - 1);
88- if (vpRelRect.y () >= newSize.height ())
89- shiftY -= vpRelRect.y () - (newSize.height () - 1);
90-
91- if (shiftX)
92- g.setX (g.x () + shiftX);
93-
94- if (shiftY)
95- g.setY (g.y () + shiftY);
96+ if (vpRelRect.x () + vpRelRect.width() >= newSize.width ())
97+ g.setX (g.x () - (vpRelRect.x () + vpRelRect.width () - newSize.width ()));
98+ if (vpRelRect.y () + vpRelRect.height() >= newSize.height ())
99+ g.setY (g.y () - (vpRelRect.y () + vpRelRect.width () - newSize.height ()));
100
101 g.setWidth (vpRelRect.width ());
102 g.setHeight (vpRelRect.height ());
103 }
104
105- /* Handle non-(0,0) current viewport by shifting by curVpOffsetX,Y,
106- and bring window to (0,0) by shifting by minus its vp offset */
107-
108- g.setX (g.x () + curVpOffsetX - (getViewport ().x () + vpX) * newSize.width ());
109- g.setY (g.y () + curVpOffsetY - (getViewport ().y () + vpY) * newSize.height ());
110-
111 unsigned int flags = 0;
112 const CompRect &workArea = getWorkarea (g);
113
114 compiz::place::clampGeometryToWorkArea (g, workArea, getExtents (), flags, newSize);
115
116- g.setX (g.x () - curVpOffsetX + (getViewport ().x () + vpX) * newSize.width ());
117- g.setY (g.y () - curVpOffsetY + (getViewport ().y () + vpY) * newSize.height ());
118-
119 if (!mask)
120 {
121 /* save window geometry (relative to viewport) so that it
122@@ -151,6 +121,9 @@
123 mSaver.push (vpRelRect, remaining);
124 }
125
126+ g.setX (g.x () + vpX * newSize.width ());
127+ g.setY (g.y () + vpY * newSize.height ());
128+
129 /* for maximized/fullscreen windows, update saved pos/size XXX,
130 * also pull in the old code to handle maximized windows which
131 * currently can't be implemented yet */
132
133=== modified file 'plugins/place/src/screen-size-change/tests/screen-size-change/src/test-place-screen-size-change.cpp'
134--- plugins/place/src/screen-size-change/tests/screen-size-change/src/test-place-screen-size-change.cpp 2012-03-30 16:30:13 +0000
135+++ plugins/place/src/screen-size-change/tests/screen-size-change/src/test-place-screen-size-change.cpp 2013-04-12 19:16:27 +0000
136@@ -57,6 +57,9 @@
137 unsigned int bottom);
138
139 void setGeometry (const compiz::window::Geometry &g);
140+ compiz::window::Geometry sizeAdjustTest (const CompSize &oldSize,
141+ const CompSize &newSize,
142+ CompRect &workArea);
143
144 private:
145
146@@ -162,21 +165,34 @@
147 workArea.setBottom (workArea.bottom () - 24);
148 }
149
150+compiz::window::Geometry
151+MockScreenSizeChangeObject::sizeAdjustTest (const CompSize &oldSize,
152+ const CompSize &newSize,
153+ CompRect &workArea)
154+{
155+ /* Reserve top, bottom and left parts of the screen for
156+ * fake "24px" panels */
157+ reserveStruts (workArea);
158+
159+ setWorkArea (workArea);
160+
161+ compiz::window::Geometry g = adjustForSize (oldSize, newSize);
162+
163+ return g;
164+}
165+
166+
167 TEST_F(CompPlaceScreenSizeChangeTestScreenSizeChange, TestScreenSizeChange)
168 {
169 CompSize current, old;
170 compiz::window::Geometry g (200, 250, 300, 400, 0);
171+ compiz::window::Geometry expected;
172
173- MockScreenSizeChangeObject *ms = new MockScreenSizeChangeObject (g);
174+ MockScreenSizeChangeObject ms (g);
175
176 current = CompSize (1280, 800);
177
178- /* Reserve top, bottom and left parts of the screen for
179- * fake "24px" panels */
180- CompRect workArea = CompRect (0, 0, current.width (), current.height ());
181- reserveStruts (workArea);
182-
183- ms->setWorkArea (workArea);
184+ CompRect workArea;
185
186 /* First test that changing the screen size
187 * to something smaller here doesn't cause our
188@@ -184,115 +200,101 @@
189
190 old = current;
191 current = CompSize (1024, 768);
192-
193 workArea = CompRect (0, 0, current.width (), current.height ());
194- reserveStruts (workArea);
195-
196- ms->setWorkArea (workArea);
197-
198- g = ms->adjustForSize (old, current);
199-
200- EXPECT_EQ (g, compiz::window::Geometry (200, 250, 300, 400, 0));
201+
202+ expected = compiz::window::Geometry (200, 250, 300, 400, 0);
203+
204+ g = ms.sizeAdjustTest (old, current, workArea);
205+
206+ EXPECT_EQ (expected, g);
207
208 /* Making the screen size bigger with no
209 * saved geometry should cause the window not to move */
210-
211 old = current;
212 current = CompSize (2048, 768);
213-
214 workArea = CompRect (0, 0, current.width (), current.height ());
215- reserveStruts (workArea);
216-
217- ms->setWorkArea (workArea);
218-
219- g = ms->adjustForSize (old, current);
220-
221- EXPECT_EQ (g, compiz::window::Geometry (200, 250, 300, 400, 0));
222+
223+ g = ms.sizeAdjustTest (old, current, workArea);
224+
225+ EXPECT_EQ (expected, g);
226
227 /* Move the window to the other "monitor" */
228-
229- ms->setGeometry (compiz::window::Geometry (1025, 250, 300, 400, 0));
230-
231- old = current;
232+ ms.setGeometry (compiz::window::Geometry (1025, 250, 300, 400, 0));
233
234 /* Unplug a "monitor" */
235+ old = current;
236 current = CompSize (1024, 768);
237-
238 workArea = CompRect (0, 0, current.width (), current.height ());
239- reserveStruts (workArea);
240-
241- ms->setWorkArea (workArea);
242-
243- g = ms->adjustForSize (old, current);
244-
245- EXPECT_EQ (g, compiz::window::Geometry (724, 250, 300, 400, 0));
246-
247- old = current;
248+
249+ expected = compiz::window::Geometry (724, 250, 300, 400, 0);
250+
251+ g = ms.sizeAdjustTest (old, current, workArea);
252+
253+ EXPECT_EQ (expected, g);
254
255 /* Re-plug the monitor - window should go back
256 * to the same position */
257+ old = current;
258 current = CompSize (2048, 768);
259-
260 workArea = CompRect (0, 0, current.width (), current.height ());
261- reserveStruts (workArea);
262-
263- ms->setWorkArea (workArea);
264-
265- g = ms->adjustForSize (old, current);
266-
267- EXPECT_EQ (g, compiz::window::Geometry (1025, 250, 300, 400, 0));
268-
269- old = current;
270+
271+ expected = compiz::window::Geometry (1025, 250, 300, 400, 0);
272+
273+ g = ms.sizeAdjustTest (old, current, workArea);
274+
275+ EXPECT_EQ (expected, g);
276
277 /* Plug 2 monitors downwards, no change */
278+ old = current;
279 current = CompSize (2048, 1536);
280-
281 workArea = CompRect (0, 0, current.width (), current.height ());
282- reserveStruts (workArea);
283-
284- ms->setWorkArea (workArea);
285-
286- g = ms->adjustForSize (old, current);
287-
288- EXPECT_EQ (g, compiz::window::Geometry (1025, 250, 300, 400, 0));
289+
290+ g = ms.sizeAdjustTest (old, current, workArea);
291+
292+ EXPECT_EQ (expected, g);
293
294 /* Move the window to the bottom "monitor" */
295-
296- ms->setGeometry (compiz::window::Geometry (1025, 791, 300, 400, 0));
297-
298- old = current;
299+ ms.setGeometry (compiz::window::Geometry (1025, 791, 300, 400, 0));
300
301 /* Unplug bottom "monitor" */
302+ old = current;
303 current = CompSize (2048, 768);
304-
305 workArea = CompRect (0, 0, current.width (), current.height ());
306- reserveStruts (workArea);
307-
308- ms->setWorkArea (workArea);
309-
310- g = ms->adjustForSize (old, current);
311-
312- EXPECT_EQ (g, compiz::window::Geometry (1025, 344, 300, 400, 0));
313-
314- old = current;
315+
316+ expected = compiz::window::Geometry (1025, 344, 300, 400, 0);
317+
318+ g = ms.sizeAdjustTest (old, current, workArea);
319+
320+ EXPECT_EQ (expected, g);
321
322 /* Re-plug bottom "monitor" */
323+ old = current;
324 current = CompSize (2048, 1356);
325-
326 workArea = CompRect (0, 0, current.width (), current.height ());
327- reserveStruts (workArea);
328-
329- ms->setWorkArea (workArea);
330-
331- g = ms->adjustForSize (old, current);
332-
333- EXPECT_EQ (g, compiz::window::Geometry (1025, 791, 300, 400, 0));
334+
335+ expected = compiz::window::Geometry (1025, 791, 300, 400, 0);
336+
337+ g = ms.sizeAdjustTest (old, current, workArea);
338+
339+ EXPECT_EQ (expected, g);
340+
341+}
342+
343+TEST_F(CompPlaceScreenSizeChangeTestScreenSizeChange, TestScreenChangeWindowsOnSecondViewport)
344+{
345+ CompSize current, old;
346+ compiz::window::Geometry g (1025, 791, 300, 400, 0);
347+ compiz::window::Geometry expected;
348+
349+ MockScreenSizeChangeObject ms (g);
350+
351+ current = CompSize (2048, 1356);
352+
353+ CompRect workArea;
354
355 /* Move the entire window right a viewport */
356-
357 g.setPos (g.pos () + CompPoint (current.width (), 0));
358-
359- ms->setGeometry (g);
360+ ms.setGeometry (g);
361
362 /* Now change the screen resolution again - the window should
363 * move to be within the constrained size of its current
364@@ -301,14 +303,115 @@
365 /* Unplug a "monitor" */
366 old = current;
367 current = CompSize (1024, 1356);
368-
369- workArea = CompRect (0, 0, current.width (), current.height ());
370- reserveStruts (workArea);
371-
372- ms->setWorkArea (workArea);
373-
374- g = ms->adjustForSize (old, current);
375-
376- EXPECT_EQ (g, compiz::window::Geometry (current.width () + 724, 791, 300, 400, 0));
377-}
378-
379+ workArea = CompRect (0, 0, current.width (), current.height ());
380+
381+ expected = compiz::window::Geometry (current.width () + 724, 791, 300, 400, 0);
382+
383+ g = ms.sizeAdjustTest (old, current, workArea);
384+
385+ EXPECT_EQ (expected, g);
386+
387+ /* Replug the monitor, make sure that the geometry is restored */
388+ old = current;
389+ current = CompSize (2048, 1356);
390+ workArea = CompRect (0, 0, current.width (), current.height ());
391+
392+ expected = compiz::window::Geometry (current.width () + 1025, 791, 300, 400, 0);
393+
394+ g = ms.sizeAdjustTest (old, current, workArea);
395+
396+ EXPECT_EQ (expected, g);
397+
398+ /* Replug the monitor and move the window to where it fits on the first
399+ * monitor on the second viewport, then make sure it doesn't move */
400+ old = CompSize (2048, 1356);
401+ current = CompSize (1024, 1356);
402+ workArea = CompRect (0, 0, current.width (), current.height ());
403+
404+ g.setPos (CompPoint (old.width () + 25, 791));
405+ ms.setGeometry (g);
406+ /* clear the saved geometry */
407+ ms.unset();
408+
409+ expected = compiz::window::Geometry (current.width () + 25, 791, 300, 400, 0);
410+
411+ g = ms.sizeAdjustTest (old, current, workArea);
412+
413+ EXPECT_EQ (expected, g);
414+
415+ old = current;
416+ current = CompSize (2048, 1356);
417+ workArea = CompRect (0, 0, current.width (), current.height ());
418+
419+ expected = compiz::window::Geometry (current.width () + 25, 791, 300, 400, 0);
420+
421+ g = ms.sizeAdjustTest (old, current, workArea);
422+
423+ EXPECT_EQ (expected, g);
424+}
425+
426+TEST_F(CompPlaceScreenSizeChangeTestScreenSizeChange, TestScreenChangeWindowsOnPreviousViewport)
427+{
428+ CompSize current, old;
429+ compiz::window::Geometry g (0, 0, 300, 400, 0);
430+ compiz::window::Geometry expected;
431+
432+ MockScreenSizeChangeObject ms (g);
433+
434+ current = CompSize (2048, 1356);
435+
436+ CompRect workArea;
437+
438+ /* Deal with the case where the position is negative, which means
439+ * it's actually wrapped around to the rightmost viewport
440+ */
441+ g.setPos (CompPoint (-300, 200));
442+ ms.setGeometry (g);
443+
444+ expected = g;
445+
446+ /* Unplug the right "monitor" */
447+ old = current;
448+ current = CompSize (1024, 1356);
449+ workArea = CompRect (0, 0, current.width (), current.height ());
450+
451+ g = ms.sizeAdjustTest (old, current, workArea);
452+
453+ EXPECT_EQ (expected, g);
454+
455+ /* Re-plug the right "monitor" */
456+ old = current;
457+ current = CompSize (2048, 1356);
458+ workArea = CompRect (0, 0, current.width (), current.height ());
459+
460+ g = ms.sizeAdjustTest (old, current, workArea);
461+
462+ EXPECT_EQ (expected, g);
463+
464+ /* Move the window to the left monitor, verify that it survives an
465+ * unplug/plug cycle
466+ */
467+ g.setPos (CompPoint (-1324, 200));
468+ ms.setGeometry (g);
469+
470+ old = current;
471+ current = CompSize (1024, 1356);
472+ workArea = CompRect (0, 0, current.width (), current.height ());
473+
474+ expected = compiz::window::Geometry (-300, 200, 300, 400, 0);
475+
476+ g = ms.sizeAdjustTest (old, current, workArea);
477+
478+ EXPECT_EQ (expected, g);
479+
480+ old = current;
481+ current = CompSize (2048, 1356);
482+ workArea = CompRect (0, 0, current.width (), current.height ());
483+
484+ expected = compiz::window::Geometry (-1324, 200, 300, 400, 0);
485+
486+ g = ms.sizeAdjustTest (old, current, workArea);
487+
488+ EXPECT_EQ (expected, g);
489+
490+}

Subscribers

People subscribed via source and target branches