Merge lp:~smspillaz/compiz-core/compiz-core.place-screen-size-change-tests into lp:compiz-core/0.9.5

Proposed by Sam Spilsbury
Status: Merged
Merged at revision: 2928
Proposed branch: lp:~smspillaz/compiz-core/compiz-core.place-screen-size-change-tests
Merge into: lp:compiz-core/0.9.5
Prerequisite: lp:~smspillaz/compiz-core/compiz-core.place-constrainment-tests
Diff against target: 769 lines (+718/-2) (has conflicts)
8 files modified
plugins/place/CMakeLists.txt (+4/-2)
plugins/place/src/screen-size-change/CMakeLists.txt (+76/-0)
plugins/place/src/screen-size-change/include/screen-size-change.h (+67/-0)
plugins/place/src/screen-size-change/src/screen-size-change.cpp (+169/-0)
plugins/place/src/screen-size-change/tests/CMakeLists.txt (+18/-0)
plugins/place/src/screen-size-change/tests/screen-size-change/src/test-place-screen-size-change.cpp (+312/-0)
plugins/place/src/screen-size-change/tests/test-screen-size-change.cpp (+26/-0)
plugins/place/src/screen-size-change/tests/test-screen-size-change.h (+46/-0)
Text conflict in src/CMakeLists.txt
To merge this branch: bzr merge lp:~smspillaz/compiz-core/compiz-core.place-screen-size-change-tests
Reviewer Review Type Date Requested Status
Alan Griffiths Approve
Review via email: mp+89390@code.launchpad.net

Description of the change

Refactored and cleaned up a lot of the place plugin's screen size change handling code.

 * Moved the screen size change handling code into its own worker class which PlaceWindow derives from which automatically handles the save/restore of geometry on screen size changes.
 * Moved screen size change handling code into its own nameespace
 * Removed the two-pass semantics from the function - strut window collection is always done separately and we either wait until all of the external application which provide strut windows (eg, docks, panels) update their struts, or if they don't do it, time out after about 4 seconds and move windows on-screen anyways.
 * Position save now happens at the same time as the geometry is updated.
 * Added testcases for screen size change handling, in test-place-screen-size-change

Only exists as a testing module for now.

To post a comment you must log in.
2926. By Sam Spilsbury

Merged compiz-core.place-constrainment-tests into compiz-core.place-screen-size-change-tests.

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

"Moved screen size change handling code into its own nameespace" - why?

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/place/CMakeLists.txt'
2--- plugins/place/CMakeLists.txt 2012-01-20 09:52:32 +0000
3+++ plugins/place/CMakeLists.txt 2012-01-20 09:52:33 +0000
4@@ -3,6 +3,8 @@
5 include (CompizPlugin)
6
7 include_directories (${CMAKE_CURRENT_SOURCE_DIR}/src/constrain-to-workarea/include/)
8+include_directories (${CMAKE_CURRENT_SOURCE_DIR}/src/screen-size-change/include/)
9+
10 add_subdirectory (src/constrain-to-workarea)
11-
12-compiz_plugin (place LIBRARIES compiz_place_constrain_to_workarea)
13+add_subdirectory (src/screen-size-change)
14+compiz_plugin (place LIBRARIES compiz_place_constrain_to_workarea compiz_place_screen_size_change)
15
16=== added directory 'plugins/place/src/screen-size-change'
17=== added file 'plugins/place/src/screen-size-change/CMakeLists.txt'
18--- plugins/place/src/screen-size-change/CMakeLists.txt 1970-01-01 00:00:00 +0000
19+++ plugins/place/src/screen-size-change/CMakeLists.txt 2012-01-20 09:52:33 +0000
20@@ -0,0 +1,76 @@
21+pkg_check_modules (
22+ GLIBMM
23+ REQUIRED
24+ glibmm-2.4 glib-2.0
25+)
26+
27+INCLUDE_DIRECTORIES (
28+ ${CMAKE_CURRENT_SOURCE_DIR}/include
29+ ${CMAKE_CURRENT_SOURCE_DIR}/src
30+
31+ ${compiz_SOURCE_DIR}/plugins/place/src/constrain-to-workarea/include
32+ ${compiz_SOURCE_DIR}/src/point/include
33+ ${compiz_SOURCE_DIR}/src/rect/include
34+ ${compiz_SOURCE_DIR}/src/window/geometry/include
35+ ${compiz_SOURCE_DIR}/src/window/geometry-saver/include
36+ ${compiz_SOURCE_DIR}/src/window/extents/include
37+ ${compiz_SOURCE_DIR}/include
38+
39+ ${Boost_INCLUDE_DIRS}
40+
41+ ${GLIBMM_INCLUDE_DIRS}
42+)
43+
44+LINK_DIRECTORIES (${GLIBMM_LIBRARY_DIRS})
45+
46+SET (
47+ PUBLIC_HEADERS
48+)
49+
50+SET (
51+ PRIVATE_HEADERS
52+ ${CMAKE_CURRENT_SOURCE_DIR}/include/screen-size-change.h
53+)
54+
55+SET(
56+ SRCS
57+ ${CMAKE_CURRENT_SOURCE_DIR}/src/screen-size-change.cpp
58+)
59+
60+ADD_LIBRARY(
61+ compiz_place_screen_size_change STATIC
62+
63+ ${SRCS}
64+
65+ ${PUBLIC_HEADERS}
66+ ${PRIVATE_HEADERS}
67+)
68+
69+ADD_SUBDIRECTORY( ${CMAKE_CURRENT_SOURCE_DIR}/tests )
70+
71+SET_TARGET_PROPERTIES(
72+ compiz_place_screen_size_change PROPERTIES
73+ PUBLIC_HEADER "${PUBLIC_HEADERS}"
74+ COMPILE_FLAGS "-fPIC"
75+)
76+
77+INSTALL(
78+ TARGETS compiz_place_screen_size_change
79+ RUNTIME DESTINATION bin
80+ LIBRARY DESTINATION lib
81+ ARCHIVE DESTINATION lib
82+ PUBLIC_HEADER DESTINATION include/compiz/core
83+)
84+
85+
86+
87+TARGET_LINK_LIBRARIES(
88+ compiz_place_screen_size_change
89+ compiz_place_constrain_to_workarea
90+ compiz_rect
91+ compiz_point
92+ compiz_window_geometry
93+ compiz_window_geometry_saver
94+
95+ ${GLIBMM_LIBRARIES}
96+)
97
98=== added directory 'plugins/place/src/screen-size-change/include'
99=== added file 'plugins/place/src/screen-size-change/include/screen-size-change.h'
100--- plugins/place/src/screen-size-change/include/screen-size-change.h 1970-01-01 00:00:00 +0000
101+++ plugins/place/src/screen-size-change/include/screen-size-change.h 2012-01-20 09:52:33 +0000
102@@ -0,0 +1,67 @@
103+/*
104+ * Copyright (C) 2001 Havoc Pennington
105+ * Copyright (C) 2002, 2003 Red Hat, Inc.
106+ * Copyright (C) 2003 Rob Adams
107+ * Copyright (C) 2005 Novell, Inc.
108+ *
109+ * This program is free software; you can redistribute it and/or
110+ * modify it under the terms of the GNU General Public License as
111+ * published by the Free Software Foundation; either version 2 of the
112+ * License, or (at your option) any later version.
113+ *
114+ * This program is distributed in the hope that it will be useful, but
115+ * WITHOUT ANY WARRANTY; without even the implied warranty of
116+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
117+ * General Public License for more details.
118+ *
119+ * You should have received a copy of the GNU General Public License
120+ * along with this program; if not, write to the Free Software
121+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
122+ * 02111-1307, USA.
123+ */
124+
125+#ifndef _COMPIZ_PLACE_SCREEN_SIZE_CHANGE_H
126+#define _COMPIZ_PLACE_SCREEN_SIZE_CHANGE_H
127+
128+#include <core/rect.h>
129+#include <core/windowgeometry.h>
130+#include <core/windowgeometrysaver.h>
131+#include <core/windowextents.h>
132+#include <core/size.h>
133+#include <core/point.h>
134+
135+#include "constrain-to-workarea.h"
136+
137+namespace compiz
138+{
139+namespace place
140+{
141+
142+class ScreenSizeChangeObject
143+{
144+ public:
145+
146+ ScreenSizeChangeObject (const compiz::window::Geometry &g);
147+ virtual ~ScreenSizeChangeObject ();
148+
149+ virtual const compiz::window::Geometry & getGeometry () const = 0;
150+ virtual void applyGeometry (compiz::window::Geometry &ng,
151+ compiz::window::Geometry &og) = 0;
152+ virtual const CompPoint & getViewport () const = 0;
153+ virtual const CompRect & getWorkarea (const compiz::window::Geometry &g) const = 0;
154+ virtual const compiz::window::extents::Extents & getExtents () const = 0;
155+
156+ compiz::window::Geometry adjustForSize (const CompSize &oldSize,
157+ const CompSize &newSize);
158+
159+ void unset ();
160+
161+ private:
162+
163+ compiz::window::GeometrySaver mSaver;
164+};
165+
166+}
167+}
168+
169+#endif
170
171=== added directory 'plugins/place/src/screen-size-change/src'
172=== added file 'plugins/place/src/screen-size-change/src/screen-size-change.cpp'
173--- plugins/place/src/screen-size-change/src/screen-size-change.cpp 1970-01-01 00:00:00 +0000
174+++ plugins/place/src/screen-size-change/src/screen-size-change.cpp 2012-01-20 09:52:33 +0000
175@@ -0,0 +1,169 @@
176+/*
177+ * Copyright (C) 2001 Havoc Pennington
178+ * Copyright (C) 2002, 2003 Red Hat, Inc.
179+ * Copyright (C) 2003 Rob Adams
180+ * Copyright (C) 2005 Novell, Inc.
181+ *
182+ * This program is free software; you can redistribute it and/or
183+ * modify it under the terms of the GNU General Public License as
184+ * published by the Free Software Foundation; either version 2 of the
185+ * License, or (at your option) any later version.
186+ *
187+ * This program is distributed in the hope that it will be useful, but
188+ * WITHOUT ANY WARRANTY; without even the implied warranty of
189+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
190+ * General Public License for more details.
191+ *
192+ * You should have received a copy of the GNU General Public License
193+ * along with this program; if not, write to the Free Software
194+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
195+ * 02111-1307, USA.
196+ */
197+
198+#include "screen-size-change.h"
199+
200+
201+compiz::place::ScreenSizeChangeObject::ScreenSizeChangeObject (const compiz::window::Geometry &g) :
202+ mSaver (g)
203+{
204+}
205+
206+compiz::place::ScreenSizeChangeObject::~ScreenSizeChangeObject ()
207+{
208+}
209+
210+compiz::window::Geometry
211+compiz::place::ScreenSizeChangeObject::adjustForSize (const CompSize &oldSize,
212+ const CompSize &newSize)
213+{
214+ int vpX, vpY, shiftX, shiftY;
215+ compiz::window::Geometry g, vpRelRect;
216+ int pivotX, pivotY;
217+ int curVpOffsetX = getViewport ().x () * newSize.width ();
218+ int curVpOffsetY = getViewport ().y () * newSize.height ();
219+
220+ g = getGeometry ();
221+
222+ pivotX = g.x ();
223+ pivotY = g.y ();
224+
225+ /* FIXME: Should use saved geometry for maximized / fullscreen windows */
226+
227+ /* calculate target vp x, y index for window's pivot point */
228+ vpX = pivotX / oldSize.width ();
229+ if (pivotX < 0)
230+ vpX -= 1;
231+ vpY = pivotY / oldSize.height ();
232+ if (pivotY < 0)
233+ vpY -= 1;
234+
235+ /* if window's target vp is to the left of the leftmost viewport on that
236+ row, assign its target vp column as 0 (-s->x rel. to current vp) */
237+ if (getViewport ().x () + vpX < 0)
238+ vpX = -getViewport ().x ();
239+
240+ /* if window's target vp is above the topmost viewport on that column,
241+ assign its target vp row as 0 (-s->y rel. to current vp) */
242+ if (getViewport ().y () + vpY < 0)
243+ vpY = -getViewport ().y ();
244+
245+ unsigned int mask = mSaver.pop (vpRelRect, CHANGE_X | CHANGE_Y |
246+ CHANGE_WIDTH | CHANGE_HEIGHT);
247+
248+ if (mask)
249+ {
250+ /* set position/size to saved original rectangle */
251+ g.applyChange (compiz::window::Geometry (vpRelRect.x () + vpX * newSize.width (),
252+ vpRelRect.y () + vpY * newSize.height (),
253+ vpRelRect.width (),
254+ vpRelRect.height (),
255+ vpRelRect.border ()), mask);
256+ }
257+ else
258+ {
259+ /* set position/size to window's current rectangle
260+ (with position relative to target viewport) */
261+ vpRelRect.setX (g.x () - vpX * oldSize.width ());
262+ vpRelRect.setY (g.y () - vpY * oldSize.height ());
263+ vpRelRect.setWidth (g.width ());
264+ vpRelRect.setHeight (g.height ());
265+
266+ g.setPos (g.pos ());
267+
268+ shiftX = vpX * (newSize.width () - oldSize.width ());
269+ shiftY = vpY * (newSize.width () - oldSize.height ());
270+
271+ /* if coords. relative to viewport are outside new viewport area,
272+ shift window left/up so that it falls inside */
273+ if (vpRelRect.x () >= newSize.width ())
274+ shiftX -= vpRelRect.x () - (newSize.width () - 1);
275+ if (vpRelRect.y () >= newSize.height ())
276+ shiftY -= vpRelRect.y () - (newSize.height () - 1);
277+
278+ if (shiftX)
279+ g.setX (g.x () + shiftX);
280+
281+ if (shiftY)
282+ g.setY (g.y () + shiftY);
283+
284+ g.setWidth (vpRelRect.width ());
285+ g.setHeight (vpRelRect.height ());
286+ }
287+
288+ /* Handle non-(0,0) current viewport by shifting by curVpOffsetX,Y,
289+ and bring window to (0,0) by shifting by minus its vp offset */
290+
291+ g.setX (g.x () + curVpOffsetX - (getViewport ().x () + vpX) * newSize.width ());
292+ g.setY (g.y () + curVpOffsetY - (getViewport ().y () + vpY) * newSize.height ());
293+
294+ unsigned int flags = 0;
295+
296+ compiz::window::Geometry og (g);
297+ const CompRect &workArea = getWorkarea (g);
298+
299+ compiz::place::clampGeometryToWorkArea (g, workArea, getExtents (), flags, newSize);
300+
301+ g.setX (g.x () - curVpOffsetX + (getViewport ().x () + vpX) * newSize.width ());
302+ g.setY (g.y () - curVpOffsetY + (getViewport ().y () + vpY) * newSize.height ());
303+
304+ if (!mask)
305+ {
306+ /* save window geometry (relative to viewport) so that it
307+ can be restored later */
308+ mask = getGeometry ().changeMask (g);
309+ mSaver.push (vpRelRect, mask);
310+ }
311+ else
312+ {
313+ compiz::window::Geometry rg (vpRelRect.x () + vpX * newSize.width (),
314+ vpRelRect.y () + vpY * newSize.height (),
315+ vpRelRect.width (),
316+ vpRelRect.height (), vpRelRect.border ());
317+
318+ /* Don't care about any bits not restored */
319+ rg.applyChange (g, ~mask);
320+
321+ /* Push any bits back on the saver
322+ * that don't match the requested window geometry
323+ * since we will need to restore to them later */
324+
325+ unsigned int remaining = g.changeMask (rg);
326+ mSaver.push (vpRelRect, remaining);
327+ }
328+
329+ /* for maximized/fullscreen windows, update saved pos/size XXX,
330+ * also pull in the old code to handle maximized windows which
331+ * currently can't be implemented yet */
332+
333+ /* actually move/resize window in directions given by mask */
334+ applyGeometry (g, og);
335+
336+ return g;
337+}
338+
339+void
340+compiz::place::ScreenSizeChangeObject::unset ()
341+{
342+ compiz::window::Geometry g;
343+ mSaver.pop (g, !0);
344+}
345
346=== added directory 'plugins/place/src/screen-size-change/tests'
347=== added file 'plugins/place/src/screen-size-change/tests/CMakeLists.txt'
348--- plugins/place/src/screen-size-change/tests/CMakeLists.txt 1970-01-01 00:00:00 +0000
349+++ plugins/place/src/screen-size-change/tests/CMakeLists.txt 2012-01-20 09:52:33 +0000
350@@ -0,0 +1,18 @@
351+include_directories(${CMAKE_CURRENT_SOURCE_DIR})
352+
353+add_library (compiz_place_screen_size_change_test
354+ ${CMAKE_CURRENT_SOURCE_DIR}/test-screen-size-change.cpp)
355+
356+add_executable (compiz_test_place_screen_size_change
357+ ${CMAKE_CURRENT_SOURCE_DIR}/screen-size-change/src/test-place-screen-size-change.cpp)
358+
359+target_link_libraries (compiz_test_place_screen_size_change
360+ compiz_place_screen_size_change_test
361+ compiz_place_screen_size_change
362+ ${GTEST_BOTH_LIBRARIES}
363+ ${GMOCK_LIBRARY}
364+ ${GMOCK_MAIN_LIBRARY}
365+ ${CMAKE_THREAD_LIBS_INIT} # Link in pthread.
366+ )
367+
368+add_test (compiz_place_screen_size_change compiz_test_place_screen_size_change)
369
370=== added directory 'plugins/place/src/screen-size-change/tests/screen-size-change'
371=== added directory 'plugins/place/src/screen-size-change/tests/screen-size-change/src'
372=== added file 'plugins/place/src/screen-size-change/tests/screen-size-change/src/test-place-screen-size-change.cpp'
373--- plugins/place/src/screen-size-change/tests/screen-size-change/src/test-place-screen-size-change.cpp 1970-01-01 00:00:00 +0000
374+++ plugins/place/src/screen-size-change/tests/screen-size-change/src/test-place-screen-size-change.cpp 2012-01-20 09:52:33 +0000
375@@ -0,0 +1,312 @@
376+/*
377+ * Copyright © 2011 Canonical Ltd.
378+ *
379+ * Permission to use, copy, modify, distribute, and sell this software
380+ * and its documentation for any purpose is hereby granted without
381+ * fee, provided that the above copyright notice appear in all copies
382+ * and that both that copyright notice and this permission notice
383+ * appear in supporting documentation, and that the name of
384+ * Canonical Ltd. not be used in advertising or publicity pertaining to
385+ * distribution of the software without specific, written prior permission.
386+ * Canonical Ltd. makes no representations about the suitability of this
387+ * software for any purpose. It is provided "as is" without express or
388+ * implied warranty.
389+ *
390+ * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
391+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
392+ * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
393+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
394+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
395+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
396+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
397+ *
398+ * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
399+ */
400+
401+#include <test-screen-size-change.h>
402+#include <screen-size-change.h>
403+#include <iostream>
404+#include <stdlib.h>
405+#include <cstring>
406+
407+class CompPlaceScreenSizeChangeTestScreenSizeChange :
408+ public CompPlaceScreenSizeChangeTest
409+{
410+};
411+
412+class MockScreenSizeChangeObject :
413+ public compiz::place::ScreenSizeChangeObject
414+{
415+ public:
416+
417+ MockScreenSizeChangeObject (const compiz::window::Geometry &);
418+ ~MockScreenSizeChangeObject ();
419+
420+ const compiz::window::Geometry & getGeometry () const;
421+ void applyGeometry (compiz::window::Geometry &n,
422+ compiz::window::Geometry &o);
423+ const CompPoint & getViewport () const;
424+ const CompRect & getWorkarea (const compiz::window::Geometry &g) const;
425+ const compiz::window::extents::Extents & getExtents () const;
426+
427+ void setVp (const CompPoint &);
428+ void setWorkArea (const CompRect &);
429+ void setExtents (unsigned int left,
430+ unsigned int right,
431+ unsigned int top,
432+ unsigned int bottom);
433+
434+ void setGeometry (const compiz::window::Geometry &g);
435+
436+ private:
437+
438+ CompPoint mCurrentVp;
439+ CompRect mCurrentWorkArea;
440+ compiz::window::extents::Extents mCurrentExtents;
441+ compiz::window::Geometry mCurrentGeometry;
442+};
443+
444+MockScreenSizeChangeObject::MockScreenSizeChangeObject (const compiz::window::Geometry &g) :
445+ ScreenSizeChangeObject (g),
446+ mCurrentVp (0, 0),
447+ mCurrentWorkArea (50, 50, 1000, 1000),
448+ mCurrentGeometry (g)
449+{
450+ memset (&mCurrentExtents, 0, sizeof (compiz::window::extents::Extents));
451+}
452+
453+MockScreenSizeChangeObject::~MockScreenSizeChangeObject ()
454+{
455+}
456+
457+const compiz::window::Geometry &
458+MockScreenSizeChangeObject::getGeometry () const
459+{
460+ return mCurrentGeometry;
461+}
462+
463+void
464+MockScreenSizeChangeObject::applyGeometry (compiz::window::Geometry &n,
465+ compiz::window::Geometry &o)
466+{
467+ std::cout << "DEBUG: new geometry : " << n.x () << " "
468+ << n.y () << " "
469+ << n.width () << " "
470+ << n.height () << " "
471+ << n.border () << std::endl;
472+
473+ std::cout << "DEBUG: old geometry : " << o.x () << " "
474+ << o.y () << " "
475+ << o.width () << " "
476+ << o.height () << " "
477+ << o.border () << std::endl;
478+
479+ mCurrentGeometry = n;
480+}
481+
482+const CompPoint &
483+MockScreenSizeChangeObject::getViewport () const
484+{
485+ return mCurrentVp;
486+}
487+
488+const CompRect &
489+MockScreenSizeChangeObject::getWorkarea (const compiz::window::Geometry &g) const
490+{
491+ return mCurrentWorkArea;
492+}
493+
494+const compiz::window::extents::Extents &
495+MockScreenSizeChangeObject::getExtents () const
496+{
497+ return mCurrentExtents;
498+}
499+
500+void
501+MockScreenSizeChangeObject::setVp (const CompPoint &p)
502+{
503+ mCurrentVp = p;
504+}
505+
506+void
507+MockScreenSizeChangeObject::setWorkArea (const CompRect &wa)
508+{
509+ mCurrentWorkArea = wa;
510+}
511+
512+void
513+MockScreenSizeChangeObject::setExtents (unsigned int left,
514+ unsigned int right,
515+ unsigned int top,
516+ unsigned int bottom)
517+{
518+ mCurrentExtents.left = left;
519+ mCurrentExtents.right = right;
520+ mCurrentExtents.top = top;
521+ mCurrentExtents.bottom = bottom;
522+}
523+
524+void
525+MockScreenSizeChangeObject::setGeometry (const compiz::window::Geometry &g)
526+{
527+ mCurrentGeometry = g;
528+}
529+
530+void
531+reserveStruts (CompRect &workArea)
532+{
533+ workArea.setLeft (workArea.left () + 24);
534+ workArea.setTop (workArea.top () + 24);
535+ workArea.setBottom (workArea.bottom () - 24);
536+}
537+
538+TEST_F (CompPlaceScreenSizeChangeTestScreenSizeChange, TestScreenSizeChange)
539+{
540+ CompSize current, old;
541+ compiz::window::Geometry g (200, 250, 300, 400, 0);
542+
543+ MockScreenSizeChangeObject *ms = new MockScreenSizeChangeObject (g);
544+
545+ current = CompSize (1280, 800);
546+
547+ /* Reserve top, bottom and left parts of the screen for
548+ * fake "24px" panels */
549+ CompRect workArea = CompRect (0, 0, current.width (), current.height ());
550+ reserveStruts (workArea);
551+
552+ ms->setWorkArea (workArea);
553+
554+ /* First test that changing the screen size
555+ * to something smaller here doesn't cause our
556+ * (small) window to be moved */
557+
558+ old = current;
559+ current = CompSize (1024, 768);
560+
561+ workArea = CompRect (0, 0, current.width (), current.height ());
562+ reserveStruts (workArea);
563+
564+ ms->setWorkArea (workArea);
565+
566+ g = ms->adjustForSize (old, current);
567+
568+ EXPECT_EQ (g, compiz::window::Geometry (200, 250, 300, 400, 0));
569+
570+ /* Making the screen size bigger with no
571+ * saved geometry should cause the window not to move */
572+
573+ old = current;
574+ current = CompSize (2048, 768);
575+
576+ workArea = CompRect (0, 0, current.width (), current.height ());
577+ reserveStruts (workArea);
578+
579+ ms->setWorkArea (workArea);
580+
581+ g = ms->adjustForSize (old, current);
582+
583+ EXPECT_EQ (g, compiz::window::Geometry (200, 250, 300, 400, 0));
584+
585+ /* Move the window to the other "monitor" */
586+
587+ ms->setGeometry (compiz::window::Geometry (1025, 250, 300, 400, 0));
588+
589+ old = current;
590+
591+ /* Unplug a "monitor" */
592+ current = CompSize (1024, 768);
593+
594+ workArea = CompRect (0, 0, current.width (), current.height ());
595+ reserveStruts (workArea);
596+
597+ ms->setWorkArea (workArea);
598+
599+ g = ms->adjustForSize (old, current);
600+
601+ EXPECT_EQ (g, compiz::window::Geometry (724, 250, 300, 400, 0));
602+
603+ old = current;
604+
605+ /* Re-plug the monitor - window should go back
606+ * to the same position */
607+ current = CompSize (2048, 768);
608+
609+ workArea = CompRect (0, 0, current.width (), current.height ());
610+ reserveStruts (workArea);
611+
612+ ms->setWorkArea (workArea);
613+
614+ g = ms->adjustForSize (old, current);
615+
616+ EXPECT_EQ (g, compiz::window::Geometry (1025, 250, 300, 400, 0));
617+
618+ old = current;
619+
620+ /* Plug 2 monitors downwards, no change */
621+ current = CompSize (2048, 1536);
622+
623+ workArea = CompRect (0, 0, current.width (), current.height ());
624+ reserveStruts (workArea);
625+
626+ ms->setWorkArea (workArea);
627+
628+ g = ms->adjustForSize (old, current);
629+
630+ EXPECT_EQ (g, compiz::window::Geometry (1025, 250, 300, 400, 0));
631+
632+ /* Move the window to the bottom "monitor" */
633+
634+ ms->setGeometry (compiz::window::Geometry (1025, 791, 300, 400, 0));
635+
636+ old = current;
637+
638+ /* Unplug bottom "monitor" */
639+ current = CompSize (2048, 768);
640+
641+ workArea = CompRect (0, 0, current.width (), current.height ());
642+ reserveStruts (workArea);
643+
644+ ms->setWorkArea (workArea);
645+
646+ g = ms->adjustForSize (old, current);
647+
648+ EXPECT_EQ (g, compiz::window::Geometry (1025, 344, 300, 400, 0));
649+
650+ old = current;
651+
652+ /* Re-plug bottom "monitor" */
653+ current = CompSize (2048, 1356);
654+
655+ workArea = CompRect (0, 0, current.width (), current.height ());
656+ reserveStruts (workArea);
657+
658+ ms->setWorkArea (workArea);
659+
660+ g = ms->adjustForSize (old, current);
661+
662+ EXPECT_EQ (g, compiz::window::Geometry (1025, 791, 300, 400, 0));
663+
664+ /* Move the entire window right a viewport */
665+
666+ g.setPos (g.pos () + CompPoint (current.width (), 0));
667+
668+ ms->setGeometry (g);
669+
670+ /* Now change the screen resolution again - the window should
671+ * move to be within the constrained size of its current
672+ * viewport */
673+
674+ /* Unplug a "monitor" */
675+ old = current;
676+ current = CompSize (1024, 1356);
677+
678+ workArea = CompRect (0, 0, current.width (), current.height ());
679+ reserveStruts (workArea);
680+
681+ ms->setWorkArea (workArea);
682+
683+ g = ms->adjustForSize (old, current);
684+
685+ EXPECT_EQ (g, compiz::window::Geometry (current.width () + 724, 791, 300, 400, 0));
686+}
687+
688
689=== added file 'plugins/place/src/screen-size-change/tests/test-screen-size-change.cpp'
690--- plugins/place/src/screen-size-change/tests/test-screen-size-change.cpp 1970-01-01 00:00:00 +0000
691+++ plugins/place/src/screen-size-change/tests/test-screen-size-change.cpp 2012-01-20 09:52:33 +0000
692@@ -0,0 +1,26 @@
693+/*
694+ * Copyright © 2011 Canonical Ltd.
695+ *
696+ * Permission to use, copy, modify, distribute, and sell this software
697+ * and its documentation for any purpose is hereby granted without
698+ * fee, provided that the above copyright notice appear in all copies
699+ * and that both that copyright notice and this permission notice
700+ * appear in supporting documentation, and that the name of
701+ * Canonical Ltd. not be used in advertising or publicity pertaining to
702+ * distribution of the software without specific, written prior permission.
703+ * Canonical Ltd. makes no representations about the suitability of this
704+ * software for any purpose. It is provided "as is" without express or
705+ * implied warranty.
706+ *
707+ * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
708+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
709+ * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
710+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
711+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
712+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
713+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
714+ *
715+ * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
716+ */
717+
718+#include "test-screen-size-change.h"
719
720=== added file 'plugins/place/src/screen-size-change/tests/test-screen-size-change.h'
721--- plugins/place/src/screen-size-change/tests/test-screen-size-change.h 1970-01-01 00:00:00 +0000
722+++ plugins/place/src/screen-size-change/tests/test-screen-size-change.h 2012-01-20 09:52:33 +0000
723@@ -0,0 +1,46 @@
724+/*
725+ * Copyright © 2011 Canonical Ltd.
726+ *
727+ * Permission to use, copy, modify, distribute, and sell this software
728+ * and its documentation for any purpose is hereby granted without
729+ * fee, provided that the above copyright notice appear in all copies
730+ * and that both that copyright notice and this permission notice
731+ * appear in supporting documentation, and that the name of
732+ * Canonical Ltd. not be used in advertising or publicity pertaining to
733+ * distribution of the software without specific, written prior permission.
734+ * Canonical Ltd. makes no representations about the suitability of this
735+ * software for any purpose. It is provided "as is" without express or
736+ * implied warranty.
737+ *
738+ * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
739+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
740+ * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
741+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
742+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
743+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
744+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
745+ *
746+ * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
747+ */
748+
749+#ifndef _COMPIZ_TEST_PLACE_SCREEN_SIZE_CHANGE_H
750+#define _COMPIZ_TEST_PLACE_SCREEN_SIZE_CHANGE_H
751+
752+#include <gtest/gtest.h>
753+#include <core/rect.h>
754+#include <core/windowgeometry.h>
755+#include <core/windowgeometrysaver.h>
756+#include <core/windowextents.h>
757+#include <core/size.h>
758+#include <core/point.h>
759+#include <string>
760+#include <iostream>
761+#include <stdlib.h>
762+
763+class CompPlaceScreenSizeChangeTest :
764+ public ::testing::Test
765+{
766+public:
767+};
768+
769+#endif

Subscribers

People subscribed via source and target branches