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
=== modified file 'plugins/place/src/place.cpp'
--- plugins/place/src/place.cpp 2012-09-14 09:33:36 +0000
+++ plugins/place/src/place.cpp 2013-04-12 19:16:27 +0000
@@ -200,7 +200,9 @@
200PlaceScreen::handleEvent (XEvent *event)200PlaceScreen::handleEvent (XEvent *event)
201{201{
202 if (event->type == ConfigureNotify &&202 if (event->type == ConfigureNotify &&
203 event->xconfigure.window == screen->root ())203 event->xconfigure.window == screen->root () &&
204 (event->xconfigure.width != screen->width () ||
205 event->xconfigure.height != screen->height ()))
204 {206 {
205 mPrevSize.setWidth (screen->width ());207 mPrevSize.setWidth (screen->width ());
206 mPrevSize.setHeight (screen->height ());208 mPrevSize.setHeight (screen->height ());
@@ -300,6 +302,14 @@
300302
301PlaceWindow::~PlaceWindow ()303PlaceWindow::~PlaceWindow ()
302{304{
305 if (!ps->mStrutWindows.empty() && window->struts())
306 {
307 ps->mStrutWindows.remove(window);
308 if (ps->mStrutWindows.empty())
309 {
310 ps->doHandleScreenSizeChange(screen->width(), screen->height());
311 }
312 }
303}313}
304314
305bool315bool
306316
=== modified file 'plugins/place/src/screen-size-change/src/screen-size-change.cpp'
--- plugins/place/src/screen-size-change/src/screen-size-change.cpp 2012-01-21 17:16:07 +0000
+++ plugins/place/src/screen-size-change/src/screen-size-change.cpp 2013-04-12 19:16:27 +0000
@@ -37,11 +37,9 @@
37compiz::place::ScreenSizeChangeObject::adjustForSize (const CompSize &oldSize,37compiz::place::ScreenSizeChangeObject::adjustForSize (const CompSize &oldSize,
38 const CompSize &newSize)38 const CompSize &newSize)
39{39{
40 int vpX, vpY, shiftX, shiftY;40 int vpX, vpY;
41 compiz::window::Geometry g, vpRelRect;41 compiz::window::Geometry g, vpRelRect;
42 int pivotX, pivotY;42 int pivotX, pivotY;
43 int curVpOffsetX = getViewport ().x () * newSize.width ();
44 int curVpOffsetY = getViewport ().y () * newSize.height ();
4543
46 g = getGeometry ();44 g = getGeometry ();
47 compiz::window::Geometry og (g);45 compiz::window::Geometry og (g);
@@ -59,24 +57,14 @@
59 if (pivotY < 0)57 if (pivotY < 0)
60 vpY -= 1;58 vpY -= 1;
6159
62 /* if window's target vp is to the left of the leftmost viewport on that
63 row, assign its target vp column as 0 (-s->x rel. to current vp) */
64 if (getViewport ().x () + vpX < 0)
65 vpX = -getViewport ().x ();
66
67 /* if window's target vp is above the topmost viewport on that column,
68 assign its target vp row as 0 (-s->y rel. to current vp) */
69 if (getViewport ().y () + vpY < 0)
70 vpY = -getViewport ().y ();
71
72 unsigned int mask = mSaver.pop (vpRelRect, CHANGE_X | CHANGE_Y |60 unsigned int mask = mSaver.pop (vpRelRect, CHANGE_X | CHANGE_Y |
73 CHANGE_WIDTH | CHANGE_HEIGHT);61 CHANGE_WIDTH | CHANGE_HEIGHT);
7462
75 if (mask)63 if (mask)
76 {64 {
77 /* set position/size to saved original rectangle */65 /* set position/size to saved original rectangle */
78 g.applyChange (compiz::window::Geometry (vpRelRect.x () + vpX * newSize.width (),66 g.applyChange (compiz::window::Geometry (vpRelRect.x (),
79 vpRelRect.y () + vpY * newSize.height (),67 vpRelRect.y (),
80 vpRelRect.width (),68 vpRelRect.width (),
81 vpRelRect.height (),69 vpRelRect.height (),
82 vpRelRect.border ()), mask);70 vpRelRect.border ()), mask);
@@ -90,42 +78,24 @@
90 vpRelRect.setWidth (g.width ());78 vpRelRect.setWidth (g.width ());
91 vpRelRect.setHeight (g.height ());79 vpRelRect.setHeight (g.height ());
9280
93 g.setPos (g.pos ());81 g = vpRelRect;
94
95 shiftX = vpX * (newSize.width () - oldSize.width ());
96 shiftY = vpY * (newSize.width () - oldSize.height ());
9782
98 /* if coords. relative to viewport are outside new viewport area,83 /* if coords. relative to viewport are outside new viewport area,
99 shift window left/up so that it falls inside */84 shift window left/up so that it falls inside */
100 if (vpRelRect.x () >= newSize.width ())85 if (vpRelRect.x () + vpRelRect.width() >= newSize.width ())
101 shiftX -= vpRelRect.x () - (newSize.width () - 1);86 g.setX (g.x () - (vpRelRect.x () + vpRelRect.width () - newSize.width ()));
102 if (vpRelRect.y () >= newSize.height ())87 if (vpRelRect.y () + vpRelRect.height() >= newSize.height ())
103 shiftY -= vpRelRect.y () - (newSize.height () - 1);88 g.setY (g.y () - (vpRelRect.y () + vpRelRect.width () - newSize.height ()));
104
105 if (shiftX)
106 g.setX (g.x () + shiftX);
107
108 if (shiftY)
109 g.setY (g.y () + shiftY);
11089
111 g.setWidth (vpRelRect.width ());90 g.setWidth (vpRelRect.width ());
112 g.setHeight (vpRelRect.height ());91 g.setHeight (vpRelRect.height ());
113 }92 }
11493
115 /* Handle non-(0,0) current viewport by shifting by curVpOffsetX,Y,
116 and bring window to (0,0) by shifting by minus its vp offset */
117
118 g.setX (g.x () + curVpOffsetX - (getViewport ().x () + vpX) * newSize.width ());
119 g.setY (g.y () + curVpOffsetY - (getViewport ().y () + vpY) * newSize.height ());
120
121 unsigned int flags = 0;94 unsigned int flags = 0;
122 const CompRect &workArea = getWorkarea (g);95 const CompRect &workArea = getWorkarea (g);
12396
124 compiz::place::clampGeometryToWorkArea (g, workArea, getExtents (), flags, newSize);97 compiz::place::clampGeometryToWorkArea (g, workArea, getExtents (), flags, newSize);
12598
126 g.setX (g.x () - curVpOffsetX + (getViewport ().x () + vpX) * newSize.width ());
127 g.setY (g.y () - curVpOffsetY + (getViewport ().y () + vpY) * newSize.height ());
128
129 if (!mask)99 if (!mask)
130 {100 {
131 /* save window geometry (relative to viewport) so that it101 /* save window geometry (relative to viewport) so that it
@@ -151,6 +121,9 @@
151 mSaver.push (vpRelRect, remaining);121 mSaver.push (vpRelRect, remaining);
152 }122 }
153123
124 g.setX (g.x () + vpX * newSize.width ());
125 g.setY (g.y () + vpY * newSize.height ());
126
154 /* for maximized/fullscreen windows, update saved pos/size XXX,127 /* for maximized/fullscreen windows, update saved pos/size XXX,
155 * also pull in the old code to handle maximized windows which128 * also pull in the old code to handle maximized windows which
156 * currently can't be implemented yet */129 * currently can't be implemented yet */
157130
=== modified file 'plugins/place/src/screen-size-change/tests/screen-size-change/src/test-place-screen-size-change.cpp'
--- plugins/place/src/screen-size-change/tests/screen-size-change/src/test-place-screen-size-change.cpp 2012-03-30 16:30:13 +0000
+++ plugins/place/src/screen-size-change/tests/screen-size-change/src/test-place-screen-size-change.cpp 2013-04-12 19:16:27 +0000
@@ -57,6 +57,9 @@
57 unsigned int bottom);57 unsigned int bottom);
5858
59 void setGeometry (const compiz::window::Geometry &g);59 void setGeometry (const compiz::window::Geometry &g);
60 compiz::window::Geometry sizeAdjustTest (const CompSize &oldSize,
61 const CompSize &newSize,
62 CompRect &workArea);
6063
61 private:64 private:
6265
@@ -162,21 +165,34 @@
162 workArea.setBottom (workArea.bottom () - 24);165 workArea.setBottom (workArea.bottom () - 24);
163}166}
164167
168compiz::window::Geometry
169MockScreenSizeChangeObject::sizeAdjustTest (const CompSize &oldSize,
170 const CompSize &newSize,
171 CompRect &workArea)
172{
173 /* Reserve top, bottom and left parts of the screen for
174 * fake "24px" panels */
175 reserveStruts (workArea);
176
177 setWorkArea (workArea);
178
179 compiz::window::Geometry g = adjustForSize (oldSize, newSize);
180
181 return g;
182}
183
184
165TEST_F(CompPlaceScreenSizeChangeTestScreenSizeChange, TestScreenSizeChange)185TEST_F(CompPlaceScreenSizeChangeTestScreenSizeChange, TestScreenSizeChange)
166{186{
167 CompSize current, old;187 CompSize current, old;
168 compiz::window::Geometry g (200, 250, 300, 400, 0);188 compiz::window::Geometry g (200, 250, 300, 400, 0);
189 compiz::window::Geometry expected;
169190
170 MockScreenSizeChangeObject *ms = new MockScreenSizeChangeObject (g);191 MockScreenSizeChangeObject ms (g);
171192
172 current = CompSize (1280, 800);193 current = CompSize (1280, 800);
173194
174 /* Reserve top, bottom and left parts of the screen for195 CompRect workArea;
175 * fake "24px" panels */
176 CompRect workArea = CompRect (0, 0, current.width (), current.height ());
177 reserveStruts (workArea);
178
179 ms->setWorkArea (workArea);
180196
181 /* First test that changing the screen size197 /* First test that changing the screen size
182 * to something smaller here doesn't cause our198 * to something smaller here doesn't cause our
@@ -184,115 +200,101 @@
184200
185 old = current;201 old = current;
186 current = CompSize (1024, 768);202 current = CompSize (1024, 768);
187
188 workArea = CompRect (0, 0, current.width (), current.height ());203 workArea = CompRect (0, 0, current.width (), current.height ());
189 reserveStruts (workArea);204
190205 expected = compiz::window::Geometry (200, 250, 300, 400, 0);
191 ms->setWorkArea (workArea);206
192207 g = ms.sizeAdjustTest (old, current, workArea);
193 g = ms->adjustForSize (old, current);208
194209 EXPECT_EQ (expected, g);
195 EXPECT_EQ (g, compiz::window::Geometry (200, 250, 300, 400, 0));
196210
197 /* Making the screen size bigger with no211 /* Making the screen size bigger with no
198 * saved geometry should cause the window not to move */212 * saved geometry should cause the window not to move */
199
200 old = current;213 old = current;
201 current = CompSize (2048, 768);214 current = CompSize (2048, 768);
202
203 workArea = CompRect (0, 0, current.width (), current.height ());215 workArea = CompRect (0, 0, current.width (), current.height ());
204 reserveStruts (workArea);216
205217 g = ms.sizeAdjustTest (old, current, workArea);
206 ms->setWorkArea (workArea);218
207219 EXPECT_EQ (expected, g);
208 g = ms->adjustForSize (old, current);
209
210 EXPECT_EQ (g, compiz::window::Geometry (200, 250, 300, 400, 0));
211220
212 /* Move the window to the other "monitor" */221 /* Move the window to the other "monitor" */
213222 ms.setGeometry (compiz::window::Geometry (1025, 250, 300, 400, 0));
214 ms->setGeometry (compiz::window::Geometry (1025, 250, 300, 400, 0));
215
216 old = current;
217223
218 /* Unplug a "monitor" */224 /* Unplug a "monitor" */
225 old = current;
219 current = CompSize (1024, 768);226 current = CompSize (1024, 768);
220
221 workArea = CompRect (0, 0, current.width (), current.height ());227 workArea = CompRect (0, 0, current.width (), current.height ());
222 reserveStruts (workArea);228
223229 expected = compiz::window::Geometry (724, 250, 300, 400, 0);
224 ms->setWorkArea (workArea);230
225231 g = ms.sizeAdjustTest (old, current, workArea);
226 g = ms->adjustForSize (old, current);232
227233 EXPECT_EQ (expected, g);
228 EXPECT_EQ (g, compiz::window::Geometry (724, 250, 300, 400, 0));
229
230 old = current;
231234
232 /* Re-plug the monitor - window should go back235 /* Re-plug the monitor - window should go back
233 * to the same position */236 * to the same position */
237 old = current;
234 current = CompSize (2048, 768);238 current = CompSize (2048, 768);
235
236 workArea = CompRect (0, 0, current.width (), current.height ());239 workArea = CompRect (0, 0, current.width (), current.height ());
237 reserveStruts (workArea);240
238241 expected = compiz::window::Geometry (1025, 250, 300, 400, 0);
239 ms->setWorkArea (workArea);242
240243 g = ms.sizeAdjustTest (old, current, workArea);
241 g = ms->adjustForSize (old, current);244
242245 EXPECT_EQ (expected, g);
243 EXPECT_EQ (g, compiz::window::Geometry (1025, 250, 300, 400, 0));
244
245 old = current;
246246
247 /* Plug 2 monitors downwards, no change */247 /* Plug 2 monitors downwards, no change */
248 old = current;
248 current = CompSize (2048, 1536);249 current = CompSize (2048, 1536);
249
250 workArea = CompRect (0, 0, current.width (), current.height ());250 workArea = CompRect (0, 0, current.width (), current.height ());
251 reserveStruts (workArea);251
252252 g = ms.sizeAdjustTest (old, current, workArea);
253 ms->setWorkArea (workArea);253
254254 EXPECT_EQ (expected, g);
255 g = ms->adjustForSize (old, current);
256
257 EXPECT_EQ (g, compiz::window::Geometry (1025, 250, 300, 400, 0));
258255
259 /* Move the window to the bottom "monitor" */256 /* Move the window to the bottom "monitor" */
260257 ms.setGeometry (compiz::window::Geometry (1025, 791, 300, 400, 0));
261 ms->setGeometry (compiz::window::Geometry (1025, 791, 300, 400, 0));
262
263 old = current;
264258
265 /* Unplug bottom "monitor" */259 /* Unplug bottom "monitor" */
260 old = current;
266 current = CompSize (2048, 768);261 current = CompSize (2048, 768);
267
268 workArea = CompRect (0, 0, current.width (), current.height ());262 workArea = CompRect (0, 0, current.width (), current.height ());
269 reserveStruts (workArea);263
270264 expected = compiz::window::Geometry (1025, 344, 300, 400, 0);
271 ms->setWorkArea (workArea);265
272266 g = ms.sizeAdjustTest (old, current, workArea);
273 g = ms->adjustForSize (old, current);267
274268 EXPECT_EQ (expected, g);
275 EXPECT_EQ (g, compiz::window::Geometry (1025, 344, 300, 400, 0));
276
277 old = current;
278269
279 /* Re-plug bottom "monitor" */270 /* Re-plug bottom "monitor" */
271 old = current;
280 current = CompSize (2048, 1356);272 current = CompSize (2048, 1356);
281
282 workArea = CompRect (0, 0, current.width (), current.height ());273 workArea = CompRect (0, 0, current.width (), current.height ());
283 reserveStruts (workArea);274
284275 expected = compiz::window::Geometry (1025, 791, 300, 400, 0);
285 ms->setWorkArea (workArea);276
286277 g = ms.sizeAdjustTest (old, current, workArea);
287 g = ms->adjustForSize (old, current);278
288279 EXPECT_EQ (expected, g);
289 EXPECT_EQ (g, compiz::window::Geometry (1025, 791, 300, 400, 0));280
281}
282
283TEST_F(CompPlaceScreenSizeChangeTestScreenSizeChange, TestScreenChangeWindowsOnSecondViewport)
284{
285 CompSize current, old;
286 compiz::window::Geometry g (1025, 791, 300, 400, 0);
287 compiz::window::Geometry expected;
288
289 MockScreenSizeChangeObject ms (g);
290
291 current = CompSize (2048, 1356);
292
293 CompRect workArea;
290294
291 /* Move the entire window right a viewport */295 /* Move the entire window right a viewport */
292
293 g.setPos (g.pos () + CompPoint (current.width (), 0));296 g.setPos (g.pos () + CompPoint (current.width (), 0));
294297 ms.setGeometry (g);
295 ms->setGeometry (g);
296298
297 /* Now change the screen resolution again - the window should299 /* Now change the screen resolution again - the window should
298 * move to be within the constrained size of its current300 * move to be within the constrained size of its current
@@ -301,14 +303,115 @@
301 /* Unplug a "monitor" */303 /* Unplug a "monitor" */
302 old = current;304 old = current;
303 current = CompSize (1024, 1356);305 current = CompSize (1024, 1356);
304306 workArea = CompRect (0, 0, current.width (), current.height ());
305 workArea = CompRect (0, 0, current.width (), current.height ());307
306 reserveStruts (workArea);308 expected = compiz::window::Geometry (current.width () + 724, 791, 300, 400, 0);
307309
308 ms->setWorkArea (workArea);310 g = ms.sizeAdjustTest (old, current, workArea);
309311
310 g = ms->adjustForSize (old, current);312 EXPECT_EQ (expected, g);
311313
312 EXPECT_EQ (g, compiz::window::Geometry (current.width () + 724, 791, 300, 400, 0));314 /* Replug the monitor, make sure that the geometry is restored */
313}315 old = current;
314316 current = CompSize (2048, 1356);
317 workArea = CompRect (0, 0, current.width (), current.height ());
318
319 expected = compiz::window::Geometry (current.width () + 1025, 791, 300, 400, 0);
320
321 g = ms.sizeAdjustTest (old, current, workArea);
322
323 EXPECT_EQ (expected, g);
324
325 /* Replug the monitor and move the window to where it fits on the first
326 * monitor on the second viewport, then make sure it doesn't move */
327 old = CompSize (2048, 1356);
328 current = CompSize (1024, 1356);
329 workArea = CompRect (0, 0, current.width (), current.height ());
330
331 g.setPos (CompPoint (old.width () + 25, 791));
332 ms.setGeometry (g);
333 /* clear the saved geometry */
334 ms.unset();
335
336 expected = compiz::window::Geometry (current.width () + 25, 791, 300, 400, 0);
337
338 g = ms.sizeAdjustTest (old, current, workArea);
339
340 EXPECT_EQ (expected, g);
341
342 old = current;
343 current = CompSize (2048, 1356);
344 workArea = CompRect (0, 0, current.width (), current.height ());
345
346 expected = compiz::window::Geometry (current.width () + 25, 791, 300, 400, 0);
347
348 g = ms.sizeAdjustTest (old, current, workArea);
349
350 EXPECT_EQ (expected, g);
351}
352
353TEST_F(CompPlaceScreenSizeChangeTestScreenSizeChange, TestScreenChangeWindowsOnPreviousViewport)
354{
355 CompSize current, old;
356 compiz::window::Geometry g (0, 0, 300, 400, 0);
357 compiz::window::Geometry expected;
358
359 MockScreenSizeChangeObject ms (g);
360
361 current = CompSize (2048, 1356);
362
363 CompRect workArea;
364
365 /* Deal with the case where the position is negative, which means
366 * it's actually wrapped around to the rightmost viewport
367 */
368 g.setPos (CompPoint (-300, 200));
369 ms.setGeometry (g);
370
371 expected = g;
372
373 /* Unplug the right "monitor" */
374 old = current;
375 current = CompSize (1024, 1356);
376 workArea = CompRect (0, 0, current.width (), current.height ());
377
378 g = ms.sizeAdjustTest (old, current, workArea);
379
380 EXPECT_EQ (expected, g);
381
382 /* Re-plug the right "monitor" */
383 old = current;
384 current = CompSize (2048, 1356);
385 workArea = CompRect (0, 0, current.width (), current.height ());
386
387 g = ms.sizeAdjustTest (old, current, workArea);
388
389 EXPECT_EQ (expected, g);
390
391 /* Move the window to the left monitor, verify that it survives an
392 * unplug/plug cycle
393 */
394 g.setPos (CompPoint (-1324, 200));
395 ms.setGeometry (g);
396
397 old = current;
398 current = CompSize (1024, 1356);
399 workArea = CompRect (0, 0, current.width (), current.height ());
400
401 expected = compiz::window::Geometry (-300, 200, 300, 400, 0);
402
403 g = ms.sizeAdjustTest (old, current, workArea);
404
405 EXPECT_EQ (expected, g);
406
407 old = current;
408 current = CompSize (2048, 1356);
409 workArea = CompRect (0, 0, current.width (), current.height ());
410
411 expected = compiz::window::Geometry (-1324, 200, 300, 400, 0);
412
413 g = ms.sizeAdjustTest (old, current, workArea);
414
415 EXPECT_EQ (expected, g);
416
417}

Subscribers

People subscribed via source and target branches