~compiz-team/compiz/raring

« back to all changes in this revision

Viewing changes to plugins/place/src/screen-size-change/tests/screen-size-change/src/test-place-screen-size-change.cpp

  • Committer: Tarmac
  • Author(s): Steve Langasek
  • Date: 2013-04-08 07:53:34 UTC
  • mfrom: (3645.1.1 0.9.9)
  • Revision ID: tarmac-20130408075334-s4qk0h5dthwm1qy4
Fix for bug #763148 (with added test cases): when the desktop is resized,
windows should stay on their original workspace. Fixes: https://bugs.launchpad.net/bugs/763148.

Approved by PS Jenkins bot, Didier Roche.

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
                         unsigned int bottom);
58
58
 
59
59
        void setGeometry (const compiz::window::Geometry &g);
 
60
        compiz::window::Geometry sizeAdjustTest (const CompSize &oldSize,
 
61
                                                 const CompSize &newSize,
 
62
                                                 CompRect &workArea);
60
63
 
61
64
    private:
62
65
 
162
165
    workArea.setBottom (workArea.bottom () - 24);
163
166
}
164
167
 
 
168
compiz::window::Geometry
 
169
MockScreenSizeChangeObject::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
 
165
185
TEST_F(CompPlaceScreenSizeChangeTestScreenSizeChange, TestScreenSizeChange)
166
186
{
167
187
    CompSize                 current, old;
168
188
    compiz::window::Geometry g (200, 250, 300, 400, 0);
 
189
    compiz::window::Geometry expected;
169
190
 
170
191
    MockScreenSizeChangeObject ms (g);
171
192
 
172
193
    current = CompSize (1280, 800);
173
194
 
174
 
    /* Reserve top, bottom and left parts of the screen for
175
 
     * fake "24px" panels */
176
 
    CompRect workArea = CompRect (0, 0, current.width (), current.height ());
177
 
    reserveStruts (workArea);
178
 
 
179
 
    ms.setWorkArea (workArea);
 
195
    CompRect workArea;
180
196
 
181
197
    /* First test that changing the screen size
182
198
     * to something smaller here doesn't cause our
184
200
 
185
201
    old = current;
186
202
    current = CompSize (1024, 768);
187
 
 
188
203
    workArea = CompRect (0, 0, current.width (), current.height ());
189
 
    reserveStruts (workArea);
190
 
 
191
 
    ms.setWorkArea (workArea);
192
 
 
193
 
    g = ms.adjustForSize (old, current);
194
 
 
195
 
    EXPECT_EQ (g, compiz::window::Geometry (200, 250, 300, 400, 0));
 
204
 
 
205
    expected = compiz::window::Geometry (200, 250, 300, 400, 0);
 
206
 
 
207
    g = ms.sizeAdjustTest (old, current, workArea);
 
208
 
 
209
    EXPECT_EQ (expected, g);
196
210
 
197
211
    /* Making the screen size bigger with no
198
212
     * saved geometry should cause the window not to move */
199
 
 
200
213
    old = current;
201
214
    current = CompSize (2048, 768);
202
 
 
203
215
    workArea = CompRect (0, 0, current.width (), current.height ());
204
 
    reserveStruts (workArea);
205
 
 
206
 
    ms.setWorkArea (workArea);
207
 
 
208
 
    g = ms.adjustForSize (old, current);
209
 
 
210
 
    EXPECT_EQ (g, compiz::window::Geometry (200, 250, 300, 400, 0));
 
216
 
 
217
    g = ms.sizeAdjustTest (old, current, workArea);
 
218
 
 
219
    EXPECT_EQ (expected, g);
211
220
 
212
221
    /* Move the window to the other "monitor" */
213
 
 
214
222
    ms.setGeometry (compiz::window::Geometry (1025, 250, 300, 400, 0));
215
223
 
216
 
    old = current;
217
 
 
218
224
    /* Unplug a "monitor" */
 
225
    old = current;
219
226
    current = CompSize (1024, 768);
220
 
 
221
227
    workArea = CompRect (0, 0, current.width (), current.height ());
222
 
    reserveStruts (workArea);
223
 
 
224
 
    ms.setWorkArea (workArea);
225
 
 
226
 
    g = ms.adjustForSize (old, current);
227
 
 
228
 
    EXPECT_EQ (g, compiz::window::Geometry (724, 250, 300, 400, 0));
229
 
 
230
 
    old = current;
 
228
 
 
229
    expected = compiz::window::Geometry (724, 250, 300, 400, 0);
 
230
 
 
231
    g = ms.sizeAdjustTest (old, current, workArea);
 
232
 
 
233
    EXPECT_EQ (expected, g);
231
234
 
232
235
    /* Re-plug the monitor - window should go back
233
236
     * to the same position */
 
237
    old = current;
234
238
    current = CompSize (2048, 768);
235
 
 
236
239
    workArea = CompRect (0, 0, current.width (), current.height ());
237
 
    reserveStruts (workArea);
238
 
 
239
 
    ms.setWorkArea (workArea);
240
 
 
241
 
    g = ms.adjustForSize (old, current);
242
 
 
243
 
    EXPECT_EQ (g, compiz::window::Geometry (1025, 250, 300, 400, 0));
244
 
 
245
 
    old = current;
 
240
 
 
241
    expected = compiz::window::Geometry (1025, 250, 300, 400, 0);
 
242
 
 
243
    g = ms.sizeAdjustTest (old, current, workArea);
 
244
 
 
245
    EXPECT_EQ (expected, g);
246
246
 
247
247
    /* Plug 2 monitors downwards, no change */
 
248
    old = current;
248
249
    current = CompSize (2048, 1536);
249
 
 
250
250
    workArea = CompRect (0, 0, current.width (), current.height ());
251
 
    reserveStruts (workArea);
252
 
 
253
 
    ms.setWorkArea (workArea);
254
 
 
255
 
    g = ms.adjustForSize (old, current);
256
 
 
257
 
    EXPECT_EQ (g, compiz::window::Geometry (1025, 250, 300, 400, 0));
 
251
 
 
252
    g = ms.sizeAdjustTest (old, current, workArea);
 
253
 
 
254
    EXPECT_EQ (expected, g);
258
255
 
259
256
    /* Move the window to the bottom "monitor" */
260
 
 
261
257
    ms.setGeometry (compiz::window::Geometry (1025, 791, 300, 400, 0));
262
258
 
263
 
    old = current;
264
 
 
265
259
    /* Unplug bottom "monitor" */
 
260
    old = current;
266
261
    current = CompSize (2048, 768);
267
 
 
268
262
    workArea = CompRect (0, 0, current.width (), current.height ());
269
 
    reserveStruts (workArea);
270
 
 
271
 
    ms.setWorkArea (workArea);
272
 
 
273
 
    g = ms.adjustForSize (old, current);
274
 
 
275
 
    EXPECT_EQ (g, compiz::window::Geometry (1025, 344, 300, 400, 0));
276
 
 
277
 
    old = current;
 
263
 
 
264
    expected = compiz::window::Geometry (1025, 344, 300, 400, 0);
 
265
 
 
266
    g = ms.sizeAdjustTest (old, current, workArea);
 
267
 
 
268
    EXPECT_EQ (expected, g);
278
269
 
279
270
    /* Re-plug bottom "monitor" */
 
271
    old = current;
280
272
    current = CompSize (2048, 1356);
281
 
 
282
273
    workArea = CompRect (0, 0, current.width (), current.height ());
283
 
    reserveStruts (workArea);
284
 
 
285
 
    ms.setWorkArea (workArea);
286
 
 
287
 
    g = ms.adjustForSize (old, current);
288
 
 
289
 
    EXPECT_EQ (g, compiz::window::Geometry (1025, 791, 300, 400, 0));
 
274
 
 
275
    expected = compiz::window::Geometry (1025, 791, 300, 400, 0);
 
276
 
 
277
    g = ms.sizeAdjustTest (old, current, workArea);
 
278
 
 
279
    EXPECT_EQ (expected, g);
 
280
 
 
281
}
 
282
 
 
283
TEST_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;
290
294
 
291
295
    /* Move the entire window right a viewport */
292
 
 
293
296
    g.setPos (g.pos () + CompPoint (current.width (), 0));
294
 
 
295
297
    ms.setGeometry (g);
296
298
 
297
299
    /* Now change the screen resolution again - the window should
301
303
    /* Unplug a "monitor" */
302
304
    old = current;
303
305
    current = CompSize (1024, 1356);
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 (current.width () + 724, 791, 300, 400, 0));
313
 
}
314
 
 
 
306
    workArea = CompRect (0, 0, current.width (), current.height ());
 
307
 
 
308
    expected = compiz::window::Geometry (current.width () + 724, 791, 300, 400, 0);
 
309
 
 
310
    g = ms.sizeAdjustTest (old, current, workArea);
 
311
 
 
312
    EXPECT_EQ (expected, g);
 
313
 
 
314
    /* Replug the monitor, make sure that the geometry is restored */
 
315
    old = current;
 
316
    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
 
 
353
TEST_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
}