Merge lp:~smspillaz/compiz-core/fix_898949 into lp:compiz-core/0.9.5

Proposed by Sam Spilsbury
Status: Rejected
Rejected by: Sam Spilsbury
Proposed branch: lp:~smspillaz/compiz-core/fix_898949
Merge into: lp:compiz-core/0.9.5
Prerequisite: lp:~compiz-team/compiz-core/fix_898469
Diff against target: 2625 lines (+1629/-400)
43 files modified
include/core/screen.h (+1/-1)
include/core/size.h (+2/-0)
include/core/window.h (+12/-3)
plugins/CMakeLists.txt (+1/-0)
plugins/decor/src/decor.cpp (+2/-2)
plugins/place/CMakeLists.txt (+4/-3)
plugins/place/src/constrain-to-workarea/CMakeLists.txt (+1/-0)
plugins/place/src/constrain-to-workarea/tests/constrain-to-workarea/src/CMakeLists.txt (+9/-4)
plugins/place/src/constrain-to-workarea/tests/constrain-to-workarea/src/test-place-constrain-to-workarea.cpp (+52/-0)
plugins/place/src/constrain-to-workarea/tests/test-constrain-to-workarea.h (+1/-0)
plugins/place/src/place.cpp (+90/-205)
plugins/place/src/place.h (+23/-5)
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 (+324/-0)
plugins/place/src/screen-size-change/tests/test-screen-size-change.cpp (+34/-0)
plugins/place/src/screen-size-change/tests/test-screen-size-change.h (+49/-0)
plugins/resize/src/resize.cpp (+9/-1)
src/CMakeLists.txt (+4/-0)
src/logmessage/CMakeLists.txt (+1/-0)
src/pluginclasshandler/CMakeLists.txt (+1/-0)
src/pluginclasshandler/src/valueholder.h (+1/-0)
src/pluginclasshandler/tests/test-pluginclasshandler.h (+1/-0)
src/point/CMakeLists.txt (+1/-0)
src/rect/CMakeLists.txt (+1/-0)
src/screen.cpp (+2/-2)
src/size.cpp (+13/-0)
src/string/CMakeLists.txt (+1/-0)
src/timer/CMakeLists.txt (+1/-0)
src/window.cpp (+58/-174)
src/window/CMakeLists.txt (+1/-0)
src/window/constrainment/CMakeLists.txt (+72/-0)
src/window/constrainment/include/core/windowconstrainment.h (+57/-0)
src/window/constrainment/src/windowconstrainment.cpp (+161/-0)
src/window/constrainment/tests/CMakeLists.txt (+19/-0)
src/window/constrainment/tests/test-window-constrainment.cpp (+34/-0)
src/window/constrainment/tests/test-window-constrainment.h (+43/-0)
src/window/constrainment/tests/to-hints/src/test-window-constrainment-to-hints.cpp (+210/-0)
src/window/extents/CMakeLists.txt (+1/-0)
src/window/geometry-saver/CMakeLists.txt (+1/-0)
src/window/geometry/CMakeLists.txt (+1/-0)
To merge this branch: bzr merge lp:~smspillaz/compiz-core/fix_898949
Reviewer Review Type Date Requested Status
Thomi Richards Pending
Thomas Voß Pending
Review via email: mp+88495@code.launchpad.net

This proposal supersedes a proposal from 2011-12-05.

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

Next pipe: lp:~smspillaz/compiz-core/fix_899557

To post a comment you must log in.
Revision history for this message
Sam Spilsbury (smspillaz) wrote : Posted in a previous version of this proposal

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

Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote : Posted in a previous version of this proposal

Diff lines 437, 443, maybe 449, and 455: can these methods be marked as 'const'? At a glance it looks like they should be.

ditto diff lines 620 - 623.

Diff line 690 - 711 - Don't leave commented out code in the merge. If it's for future features, move it into a separate Bazaar branch. Future developers will look at this and think "I wonder why that's commented out?".

Ditto lines 815 - 874.

Diff lines 940, 941 & 942 - can these be made const?

Diff lines 1177 - 1187 - did you mean to leave this in?

Diff lines 1803, 1808, 1870, 1875 - Is it possible for 'base' to be 0 here? If so, you've got a problem. It may pay to be a bit more defensive and do something more sensible than crash if it ever happens.

ln 2094 - WHy the cast?

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

> Diff lines 437, 443, maybe 449, and 455: can these methods be marked as
> 'const'? At a glance it looks like they should be.
>
> ditto diff lines 620 - 623.

Ack.

>
> Diff line 690 - 711 - Don't leave commented out code in the merge. If it's for
> future features, move it into a separate Bazaar branch. Future developers will
> look at this and think "I wonder why that's commented out?".
>
> Ditto lines 815 - 874.
>
> Diff lines 940, 941 & 942 - can these be made const?
>
> Diff lines 1177 - 1187 - did you mean to leave this in?
>

Ack.

> Diff lines 1803, 1808, 1870, 1875 - Is it possible for 'base' to be 0 here? If
> so, you've got a problem. It may pay to be a bit more defensive and do
> something more sensible than crash if it ever happens.
>

Done, although I think in those codepaths only yinc and xinc were being passed as the base value and they are already constrained to start from 1. However, it doesn't make sense for an object to have a width or height of zero anyways, and we shouldn't allow windows to specify that since trying to resize to that will result in a BadValue error on the server and will generally wreak havoc on the system because it thinks the window is smaller than it is. So I've constrained to start from 1 on all the other width/height values too.

> ln 2094 - WHy the cast?

Revision history for this message
Thomas Voß (thomas-voss) wrote : Posted in a previous version of this proposal

In addition to Thomi's remarks:

  * In compiz::window::Extents:

    * Get rid of the public identifier. Extents is a struct and thus, default visibility is public.

    * You can leave out the custom operator== and operator!= and rely on the compiler generated ones.
      Nevertheless, you should leave a comment in there.

    * Defining a default c'tor assigning default values to the members is missing.

review: Needs Fixing

Unmerged revisions

2982. By Sam Spilsbury

Merge

2981. By Sam Spilsbury

Merged compiz-core.fix_898469 into compiz-core.fix_898949.

2980. By Sam Spilsbury

Merged compiz-core.fix_898469 into compiz-core.fix_898949.

2979. By Sam Spilsbury

Merged compiz-core.fix_898469 into compiz-core.fix_898949.

2978. By Sam Spilsbury

Merged compiz-core.fix_898469 into compiz-core.fix_898949.

2977. By Sam Spilsbury

Merged compiz-core.fix_898469 into compiz-core.fix_898949.

2976. By Sam Spilsbury

Merged compiz-core.fix_898469 into compiz-core.fix_898949.

2975. By Sam Spilsbury

Merged compiz-core.fix_898469 into compiz-core.fix_898949.

2974. By Sam Spilsbury

Merged compiz-core.fix_898469 into compiz-core.fix_898949.

2973. By Sam Spilsbury

Merged compiz-core.fix_898469 into compiz-core.fix_898949.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/core/screen.h'
2--- include/core/screen.h 2012-01-13 13:20:02 +0000
3+++ include/core/screen.h 2012-01-13 13:20:03 +0000
4@@ -324,7 +324,7 @@
5
6 int outputDeviceForGeometry (const compiz::window::Geometry& gm);
7
8- CompPoint vp ();
9+ const CompPoint & vp () const;
10
11 CompSize vpSize ();
12
13
14=== modified file 'include/core/size.h'
15--- include/core/size.h 2010-03-24 09:37:19 +0000
16+++ include/core/size.h 2012-01-13 13:20:03 +0000
17@@ -50,6 +50,8 @@
18 typedef std::list<CompSize> list;
19 typedef std::list<CompSize *> ptrList;
20
21+ bool operator== (const CompSize &other) const;
22+ bool operator!= (const CompSize &other) const;
23 private:
24 int mWidth, mHeight;
25 };
26
27=== modified file 'include/core/window.h'
28--- include/core/window.h 2012-01-13 13:20:02 +0000
29+++ include/core/window.h 2012-01-13 13:20:03 +0000
30@@ -44,6 +44,7 @@
31 #include <core/windowgeometry.h>
32 #include <core/windowgeometrysaver.h>
33 #include <core/windowextents.h>
34+#include <core/windowconstrainment.h>
35
36 #include <core/wrapsystem.h>
37
38@@ -235,9 +236,17 @@
39 */
40 static const unsigned int ConstrainPositionVirtualScreen (1 << 2);
41
42-
43-}
44-}
45+namespace constrainment
46+{
47+
48+CompSize constrainToHints (CompWindow *w,
49+ const CompSize &size);
50+}
51+
52+}
53+}
54+
55+
56 /**
57 * Wrappable core window functions. Derive from this class
58 * and overload these functions in order to have your function called
59
60=== modified file 'plugins/CMakeLists.txt'
61--- plugins/CMakeLists.txt 2012-01-13 13:20:02 +0000
62+++ plugins/CMakeLists.txt 2012-01-13 13:20:03 +0000
63@@ -18,6 +18,7 @@
64 ${CMAKE_CURRENT_SOURCE_DIR}/../src/window/geometry/include
65 ${CMAKE_CURRENT_SOURCE_DIR}/../src/window/geometry-saver/include
66 ${CMAKE_CURRENT_SOURCE_DIR}/../src/window/extents/include
67+ ${CMAKE_CURRENT_SOURCE_DIR}/../src/window/constrainment/include
68 ${CMAKE_CURRENT_SOURCE_DIR}/../src/point/include
69 ${CMAKE_CURRENT_SOURCE_DIR}/../src/rect/include
70 )
71
72=== modified file 'plugins/decor/src/decor.cpp'
73--- plugins/decor/src/decor.cpp 2012-01-13 13:20:02 +0000
74+++ plugins/decor/src/decor.cpp 2012-01-13 13:20:03 +0000
75@@ -1472,7 +1472,7 @@
76 if (old)
77 {
78 oldShift = compiz::window::extents::shift (window->border (),
79- window->sizeHints ().win_gravity);
80+ window->sizeHints ().win_gravity);
81
82 WindowDecoration::destroy (wd);
83
84@@ -1504,7 +1504,7 @@
85 &wd->decor->input);
86
87 movement = compiz::window::extents::shift (window->border (),
88- window->sizeHints ().win_gravity) - oldShift;
89+ window->sizeHints ().win_gravity) - oldShift;
90
91 /* Update the input and output frame */
92 if (decorate)
93
94=== modified file 'plugins/place/CMakeLists.txt'
95--- plugins/place/CMakeLists.txt 2012-01-13 13:20:02 +0000
96+++ plugins/place/CMakeLists.txt 2012-01-13 13:20:03 +0000
97@@ -5,7 +5,8 @@
98 # FIXME: Remove once MODULES support lands
99
100 add_subdirectory (src/constrain-to-workarea)
101-add_subdirectory (tests)
102+add_subdirectory (src/screen-size-change)
103
104-include_directories (${CMAKE_CURRENT_SOURCE_DIR}/src/constrain-to-workarea/include/)
105-compiz_plugin (place LIBRARIES compiz_place_constrain_to_workarea)
106+include_directories (${CMAKE_CURRENT_SOURCE_DIR}/src/constrain-to-workarea/include/
107+include_directories (${CMAKE_CURRENT_SOURCE_DIR}/src/screen-size-change/include/))
108+compiz_plugin (place LIBRARIES compiz_place_constrain_to_workarea compiz_place_screen_size_change)
109
110=== modified file 'plugins/place/src/constrain-to-workarea/CMakeLists.txt'
111--- plugins/place/src/constrain-to-workarea/CMakeLists.txt 2012-01-13 13:20:02 +0000
112+++ plugins/place/src/constrain-to-workarea/CMakeLists.txt 2012-01-13 13:20:03 +0000
113@@ -51,6 +51,7 @@
114 SET_TARGET_PROPERTIES(
115 compiz_place_constrain_to_workarea PROPERTIES
116 PUBLIC_HEADER "${PUBLIC_HEADERS}"
117+ COMPILE_FLAGS "-fPIC"
118 )
119
120 INSTALL(
121
122=== modified file 'plugins/place/src/constrain-to-workarea/tests/constrain-to-workarea/src/CMakeLists.txt'
123--- plugins/place/src/constrain-to-workarea/tests/constrain-to-workarea/src/CMakeLists.txt 2012-01-13 13:20:02 +0000
124+++ plugins/place/src/constrain-to-workarea/tests/constrain-to-workarea/src/CMakeLists.txt 2012-01-13 13:20:03 +0000
125@@ -6,19 +6,24 @@
126 ${compiz_BINARY_DIR}/generated
127 ${compiz_SOURCE_DIR}/src
128 ${compiz_SOURCE_DIR}/plugins/place/src
129+ ${compiz_SOURCE_DIR}/src/window/geometry/include/
130+ ${compiz_SOURCE_DIR}/src/window/geometry-saver/include/
131+ ${compiz_SOURCE_DIR}/src/window/extents/include/
132+ ${compiz_SOURCE_DIR}/src/point/include/
133+ ${compiz_SOURCE_DIR}/src/rect/include/
134 ${COMPIZ_PLACE_TEST_BASE_DIR})
135
136 add_executable (test-place-clamp-to-workarea
137 test-place-constrain-to-workarea.cpp
138 ../test-place.cpp
139 ${compiz_SOURCE_DIR}/plugins/place/src/constrain-to-workarea.cpp
140- ${compiz_SOURCE_DIR}/src/windowextents.cpp
141- ${compiz_SOURCE_DIR}/src/windowgeometry.cpp
142- ${compiz_SOURCE_DIR}/src/rect.cpp
143- ${compiz_SOURCE_DIR}/src/point.cpp
144 ${compiz_SOURCE_DIR}/src/size.cpp)
145
146 target_link_libraries (test-place-clamp-to-workarea
147+ compiz_window_geometry
148+ compiz_window_extents
149+ compiz_point
150+ compiz_rect
151 ${COMPIZ_TEST_PLACE_LIBRARIES})
152
153 add_test (test-place-clamp-to-workarea
154
155=== modified file 'plugins/place/src/constrain-to-workarea/tests/constrain-to-workarea/src/test-place-constrain-to-workarea.cpp'
156--- plugins/place/src/constrain-to-workarea/tests/constrain-to-workarea/src/test-place-constrain-to-workarea.cpp 2012-01-13 13:20:02 +0000
157+++ plugins/place/src/constrain-to-workarea/tests/constrain-to-workarea/src/test-place-constrain-to-workarea.cpp 2012-01-13 13:20:03 +0000
158@@ -60,4 +60,56 @@
159 compiz::place::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);
160
161 EXPECT_EQ (g, compiz::window::Geometry (100, 100, 200, 200, 0));
162+
163+ /* Larger than workArea */
164+ g = compiz::window::Geometry (50, 50, 950, 1950, 0);
165+
166+ compiz::place::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);
167+
168+ EXPECT_EQ (g, compiz::window::Geometry (50, 50, 900, 1900, 0));
169+
170+ /* Outside top left */
171+ g = compiz::window::Geometry (0, 0, 900, 1900, 0);
172+
173+ compiz::place::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);
174+
175+ EXPECT_EQ (g, compiz::window::Geometry (50, 50, 900, 1900, 0));
176+
177+ /* Outside top right */
178+ g = compiz::window::Geometry (100, 0, 900, 1900, 0);
179+
180+ compiz::place::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);
181+
182+ EXPECT_EQ (g, compiz::window::Geometry (50, 50, 900, 1900, 0));
183+
184+ /* Outside bottom left */
185+ g = compiz::window::Geometry (0, 100, 900, 1900, 0);
186+
187+ compiz::place::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);
188+
189+ EXPECT_EQ (g, compiz::window::Geometry (50, 50, 900, 1900, 0));
190+
191+ /* Outside bottom right */
192+ g = compiz::window::Geometry (100, 100, 900, 1900, 0);
193+
194+ compiz::place::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);
195+
196+ EXPECT_EQ (g, compiz::window::Geometry (50, 50, 900, 1900, 0));
197+
198+ /* For the size only case, we should not
199+ * change the position of the window if
200+ * the size does not change */
201+ g = compiz::window::Geometry (0, 0, 900, 1900, 0);
202+ flags = compiz::place::clampGeometrySizeOnly;
203+
204+ compiz::place::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);
205+
206+ EXPECT_EQ (g, compiz::window::Geometry (0, 0, 900, 1900, 0));
207+
208+ g = compiz::window::Geometry (0, 0, 1000, 2000, 0);
209+ flags = compiz::place::clampGeometrySizeOnly;
210+
211+ compiz::place::clampGeometryToWorkArea (g, workArea, extents, flags, screensize);
212+
213+ EXPECT_EQ (g, compiz::window::Geometry (50, 50, 900, 1900, 0));
214 }
215
216=== modified file 'plugins/place/src/constrain-to-workarea/tests/test-constrain-to-workarea.h'
217--- plugins/place/src/constrain-to-workarea/tests/test-constrain-to-workarea.h 2012-01-13 13:20:02 +0000
218+++ plugins/place/src/constrain-to-workarea/tests/test-constrain-to-workarea.h 2012-01-13 13:20:03 +0000
219@@ -29,6 +29,7 @@
220 #include <gtest/gtest.h>
221 #include <core/rect.h>
222 #include <core/windowgeometry.h>
223+#include <core/windowgeometrysaver.h>
224 #include <core/windowextents.h>
225 #include <core/size.h>
226 #include <core/point.h>
227
228=== modified file 'plugins/place/src/place.cpp'
229--- plugins/place/src/place.cpp 2012-01-13 13:20:02 +0000
230+++ plugins/place/src/place.cpp 2012-01-13 13:20:03 +0000
231@@ -27,7 +27,7 @@
232 PlaceScreen::PlaceScreen (CompScreen *screen) :
233 PluginClassHandler<PlaceScreen, CompScreen> (screen),
234 mPrevSize (screen->width (), screen->height ()),
235- mStrutWindowCount (0),
236+ mStrutWindows (0),
237 fullPlacementAtom (XInternAtom (screen->dpy (),
238 "_NET_WM_FULL_PLACEMENT", 0))
239 {
240@@ -45,25 +45,29 @@
241 screen->updateSupportedWmHints ();
242 }
243
244-/* FIXME: This should really be in core */
245+CompWindowList
246+compiz::place::collectStrutWindows (const CompWindowList &all)
247+{
248+ CompWindowList l;
249+
250+ foreach (CompWindow *w, all)
251+ {
252+ if (!w->managed () ||
253+ w->overrideRedirect ())
254+ continue;
255+
256+ if (w->struts ())
257+ l.push_back (w);
258+ }
259+
260+ return l;
261+}
262+
263 void
264 PlaceScreen::doHandleScreenSizeChange (bool firstPass,
265 int newWidth,
266 int newHeight)
267 {
268- int vpX, vpY, shiftX, shiftY;
269- CompRect extents;
270- compiz::window::Geometry g;
271- CompRect vpRelRect, winRect, workArea;
272- int pivotX, pivotY;
273- int curVpOffsetX = screen->vp ().x () * newWidth;
274- int curVpOffsetY = screen->vp ().y () * newHeight;
275-
276- if (firstPass)
277- mStrutWindowCount = 0;
278- else if (mResChangeFallbackHandle.active ())
279- mResChangeFallbackHandle.stop ();
280-
281 foreach (CompWindow *w, screen->windows ())
282 {
283 if (!w->managed ())
284@@ -73,10 +77,6 @@
285
286 if (firstPass)
287 {
288- /* count the windows that have struts */
289- if (w->struts ())
290- mStrutWindowCount++;
291-
292 /* for maximized/fullscreen windows, keep window coords before
293 * screen resize, as they are sometimes automaticall changed
294 * before the 2nd pass */
295@@ -95,175 +95,55 @@
296 continue;
297 }
298
299- /* Also in the first pass, we save the rectangle of those windows that
300- * don't already have a saved one. So, skip those tat do. */
301-
302- if (firstPass && pw->mSavedOriginal)
303- continue;
304-
305- winRect = ((CompRect) w->serverGeometry ());
306-
307- pivotX = winRect.x ();
308- pivotY = winRect.y ();
309-
310- /* FIXME: used the saved geometry for windows that are maximized
311- * or fullscreen to determine which screen or viewport they actually
312- * lie on */
313- if (w->type () & CompWindowTypeFullscreenMask ||
314- (w->state () & (CompWindowStateMaximizedVertMask |
315- CompWindowStateMaximizedHorzMask)))
316- {
317- pivotX = pw->mPrevServer.x ();
318- pivotY = pw->mPrevServer.y ();
319- }
320-
321- /* calculate target vp x, y index for window's pivot point */
322- vpX = pivotX / mPrevSize.width ();
323- if (pivotX < 0)
324- vpX -= 1;
325- vpY = pivotY / mPrevSize.height ();
326- if (pivotY < 0)
327- vpY -= 1;
328-
329- /* if window's target vp is to the left of the leftmost viewport on that
330- row, assign its target vp column as 0 (-s->x rel. to current vp) */
331- if (screen->vp ().x () + vpX < 0)
332- vpX = -screen->vp ().x ();
333-
334- /* if window's target vp is above the topmost viewport on that column,
335- assign its target vp row as 0 (-s->y rel. to current vp) */
336- if (screen->vp ().y () + vpY < 0)
337- vpY = -screen->vp ().y ();
338-
339- if (pw->mSavedOriginal)
340- {
341- /* set position/size to saved original rectangle */
342- vpRelRect = pw->mOrigVpRelRect;
343-
344- g.setPos (CompPoint (pw->mOrigVpRelRect.x () + vpX * newWidth,
345- pw->mOrigVpRelRect.y () + vpY * newHeight));
346- }
347- else
348- {
349- /* set position/size to window's current rectangle
350- (with position relative to target viewport) */
351- vpRelRect.setX (winRect.x () - vpX * mPrevSize.width ());
352- vpRelRect.setY (winRect.y () - vpY * mPrevSize.height ());
353- vpRelRect.setWidth (winRect.width ());
354- vpRelRect.setHeight (winRect.height ());
355-
356- g.setPos (winRect.pos ());
357-
358- shiftX = vpX * (newWidth - newWidth);
359- shiftY = vpY * (newWidth - newHeight);
360-
361- /* if coords. relative to viewport are outside new viewport area,
362- shift window left/up so that it falls inside */
363- if (vpRelRect.x () >= newWidth)
364- shiftX -= vpRelRect.x () - (newWidth - 1);
365- if (vpRelRect.y () >= newHeight)
366- shiftY -= vpRelRect.y () - (newHeight - 1);
367-
368- if (shiftX)
369- g.setX (g.x () + shiftX);
370-
371- if (shiftY)
372- g.setY (g.y () + shiftY);
373- }
374-
375- g.setWidth (vpRelRect.width ());
376- g.setHeight (vpRelRect.height ());
377-
378- /* Handle non-(0,0) current viewport by shifting by curVpOffsetX,Y,
379- and bring window to (0,0) by shifting by minus its vp offset */
380-
381- g.setX (g.x () + curVpOffsetX - (screen->vp ().x () + vpX) * newWidth);
382- g.setY (g.y () + curVpOffsetY - (screen->vp ().y () + vpY) * newHeight);
383-
384- unsigned int flags = 0;
385-
386- compiz::window::Geometry og (g);
387- CompRect workArea = screen->getWorkareaForOutput (
388- screen->outputDeviceForGeometry (g));
389-
390- compiz::place::clampGeometryToWorkArea (g, workArea, w->border (), flags, *screen);
391-
392- g.setX (g.x () - curVpOffsetX - (screen->vp ().x () + vpX) * newWidth);
393- g.setY (g.y () - curVpOffsetY - (screen->vp ().y () + vpY) * newHeight);
394-
395- if (!pw->mSavedOriginal)
396- {
397- if (w->serverGeometry ().changeMask (g))
398- {
399- /* save window geometry (relative to viewport) so that it
400- can be restored later */
401- pw->mSavedOriginal = TRUE;
402- pw->mOrigVpRelRect = vpRelRect;
403- }
404- }
405- else if (CompRect (pw->mOrigVpRelRect.x () + vpX * newWidth,
406- pw->mOrigVpRelRect.y () + vpY * newHeight,
407- pw->mOrigVpRelRect.width (),
408- pw->mOrigVpRelRect.height ()) == ((CompRect &) g))
409- {
410- /* if size and position is back to original, clear saved rect */
411- pw->mSavedOriginal = FALSE;
412- }
413-
414- if (firstPass) /* if first pass, don't actually move the window */
415- continue;
416-
417- /* for maximized/fullscreen windows, update saved pos/size XXX */
418- if (w->type () & CompWindowTypeFullscreenMask ||
419- (w->state () & (CompWindowStateMaximizedVertMask |
420- CompWindowStateMaximizedHorzMask)))
421- {
422- /* FIXME: That won't work with the fullscreen_monitors case */
423- if (w->type () & CompWindowTypeFullscreenMask)
424- {
425- g = compiz::window::Geometry (w->serverGeometry ());
426- g.applyChange (compiz::window::Geometry (vpX * newWidth,
427- vpY * newHeight,
428- newWidth,
429- newHeight,
430- 0), CHANGE_X |
431- CHANGE_Y |
432- CHANGE_WIDTH |
433- CHANGE_HEIGHT);
434- }
435- else
436- {
437- if (w->state () & CompWindowStateMaximizedHorzMask)
438- {
439- g.setX (vpX * newWidth + workArea.x () + w->border ().left);
440- g.setWidth (workArea.width () -
441- (2 * w->serverGeometry ().border () +
442- w->border ().left + w->border ().right));
443- }
444- if (w->state () & CompWindowStateMaximizedVertMask)
445- {
446- g.setY (vpY * newHeight + workArea.y () + w->border ().top);
447- g.setHeight (workArea.height () -
448- (2 * w->serverGeometry ().border () +
449- w->border ().top + w->border ().bottom));
450- }
451- }
452- }
453-
454- /* actually move/resize window in directions given by mask */
455- w->positionSetEnabled (PlaceWindow::get (w), false);
456- w->position (g, 0);
457- w->positionSetEnabled (PlaceWindow::get (w), true);
458-
459- if ((w->actions () & MAXIMIZE_STATE) == MAXIMIZE_STATE &&
460- (w->mwmDecor () & (MwmDecorAll | MwmDecorTitle)) &&
461- !(w->state () & CompWindowStateFullscreenMask))
462- {
463- if (og.width () >= workArea.width () &&
464- og.height () >= workArea.height ())
465- {
466- PlaceWindow::get (w)->sendMaximizationRequest ();
467- }
468+ if (!firstPass)
469+ pw->adjustForSize (mPrevSize, CompSize (newWidth, newHeight));
470+
471+ }
472+}
473+
474+const compiz::window::Geometry &
475+PlaceWindow::getGeometry () const
476+{
477+ return window->serverGeometry ();
478+}
479+
480+const CompPoint &
481+PlaceWindow::getViewport () const
482+{
483+ return screen->vp ();
484+}
485+
486+const CompRect &
487+PlaceWindow::getWorkarea (const compiz::window::Geometry &g) const
488+{
489+ return screen->getWorkareaForOutput (screen->outputDeviceForGeometry (g));
490+}
491+
492+const compiz::window::extents::Extents &
493+PlaceWindow::getExtents () const
494+{
495+ return window->border ();
496+}
497+
498+void
499+PlaceWindow::applyGeometry (compiz::window::Geometry &ng,
500+ compiz::window::Geometry &og)
501+{
502+ CompRect workArea = screen->getWorkareaForOutput (
503+ screen->outputDeviceForGeometry (og));
504+
505+ window->positionSetEnabled (this, false);
506+ window->position (ng, 0, 0);
507+ window->positionSetEnabled (this, true);
508+
509+ if ((window->actions () & MAXIMIZE_STATE) == MAXIMIZE_STATE &&
510+ (window->mwmDecor () & (MwmDecorAll | MwmDecorTitle)) &&
511+ !(window->state () & CompWindowStateFullscreenMask))
512+ {
513+ if (og.width () >= workArea.width () &&
514+ og.height () >= workArea.height ())
515+ {
516+ sendMaximizationRequest ();
517 }
518 }
519 }
520@@ -275,9 +155,13 @@
521 /* If countdown is not finished yet (i.e. at least one struct window didn't
522 * update its struts), reset the count down and do the 2nd pass here */
523
524- if (mStrutWindowCount > 0) /* no windows with struts found */
525+ if (!mStrutWindows.empty ()) /* no windows with struts found */
526 {
527- mStrutWindowCount = 0;
528+ compLogMessage ("place", CompLogLevelWarn, "broken clients didn't update their struts");
529+ foreach (CompWindow *w, mStrutWindows)
530+ compLogMessage ("place", CompLogLevelWarn, "client id: 0x%x", w->id ());
531+
532+ mStrutWindows.clear ();
533 doHandleScreenSizeChange (false, width, height);
534 }
535
536@@ -288,17 +172,17 @@
537 PlaceScreen::handleScreenSizeChange (int width,
538 int height)
539 {
540- CompRect extents;
541-
542 if (mPrevSize.width () == width && mPrevSize.height () == height)
543 return;
544
545 if (mResChangeFallbackHandle.active ())
546 mResChangeFallbackHandle.stop ();
547
548+ mStrutWindows = compiz::place::collectStrutWindows (screen->windows ());
549+
550 doHandleScreenSizeChange (true, width, height);
551
552- if (mStrutWindowCount == 0) /* no windows with struts found */
553+ if (mStrutWindows.empty ()) /* no windows with struts found */
554 {
555 mResChangeFallbackHandle.stop ();
556 /* do the 2nd pass right here instead of handleEvent */
557@@ -361,16 +245,18 @@
558 {
559 /* Only do when handling screen size change.
560 ps->strutWindowCount is 0 at any other time */
561- if (mStrutWindowCount > 0 &&
562- w->updateStruts ())
563+ if (std::find (mStrutWindows.begin (),
564+ mStrutWindows.end (),
565+ w) != mStrutWindows.end ())
566 {
567- mStrutWindowCount--;
568- screen->updateWorkarea ();
569+ mStrutWindows.remove (w);
570
571 /* if this was the last window with struts */
572- if (!mStrutWindowCount)
573+ if (mStrutWindows.empty ())
574+ {
575 doHandleScreenSizeChange (false, screen->width (),
576 screen->height ()); /* 2nd pass */
577+ }
578 }
579 }
580 }
581@@ -426,7 +312,7 @@
582
583 PlaceWindow::PlaceWindow (CompWindow *w) :
584 PluginClassHandler<PlaceWindow, CompWindow> (w),
585- mSavedOriginal (false),
586+ compiz::place::ScreenSizeChangeObject (w->serverGeometry ()),
587 window (w),
588 ps (PlaceScreen::get (screen))
589 {
590@@ -1558,12 +1444,11 @@
591 unsigned int state,
592 unsigned int mask)
593 {
594- if (mSavedOriginal)
595- {
596- if (screen->grabExist ("move") ||
597- screen->grabExist ("resize"))
598- mSavedOriginal = false;
599- }
600+ /* Remove all bits if the user
601+ * moves the window */
602+ if (screen->grabExist ("move") ||
603+ screen->grabExist ("resize"))
604+ unset ();
605
606 window->grabNotify (x, y, state, mask);
607 }
608
609=== modified file 'plugins/place/src/place.h'
610--- plugins/place/src/place.h 2012-01-13 13:20:02 +0000
611+++ plugins/place/src/place.h 2012-01-13 13:20:03 +0000
612@@ -31,6 +31,15 @@
613
614 #include "place_options.h"
615 #include "constrain-to-workarea.h"
616+#include "screen-size-change.h"
617+
618+namespace compiz
619+{
620+namespace place
621+{
622+CompWindowList collectStrutWindows (const CompWindowList &all);
623+}
624+}
625
626 class PlaceScreen :
627 public PluginClassHandler<PlaceScreen, CompScreen>,
628@@ -51,6 +60,7 @@
629 CompSize mPrevSize;
630 int mStrutWindowCount;
631 CompTimer mResChangeFallbackHandle;
632+ CompWindowList mStrutWindows;
633
634 Atom fullPlacementAtom;
635 };
636@@ -60,6 +70,7 @@
637
638 class PlaceWindow :
639 public PluginClassHandler<PlaceWindow, CompWindow>,
640+ public compiz::place::ScreenSizeChangeObject,
641 public WindowInterface
642 {
643 public:
644@@ -70,12 +81,17 @@
645 bool position (compiz::window::Geometry &g,
646 unsigned int source,
647 unsigned int constrainment);
648- void grabNotify (int, int, unsigned int, unsigned int);
649- bool mSavedOriginal;
650- CompRect mOrigVpRelRect;
651+ void grabNotify (int, int, unsigned int, unsigned int);
652 CompPoint mPrevServer;
653-
654- void sendMaximizationRequest ();
655+
656+ protected:
657+
658+ void applyGeometry (compiz::window::Geometry &,
659+ compiz::window::Geometry &);
660+ const compiz::window::Geometry & getGeometry () const;
661+ const CompPoint & getViewport () const;
662+ const CompRect & getWorkarea (const compiz::window::Geometry &g) const;
663+ const compiz::window::extents::Extents & getExtents () const;
664
665 private:
666 typedef enum {
667@@ -87,6 +103,8 @@
668 PlaceCenteredOnScreen
669 } PlacementStrategy;
670
671+ void sendMaximizationRequest ();
672+
673 void doPlacement (CompPoint &pos);
674 bool windowIsPlaceRelevant (CompWindow *w);
675 bool hasUserDefinedPosition (bool);
676
677=== added directory 'plugins/place/src/screen-size-change'
678=== added file 'plugins/place/src/screen-size-change/CMakeLists.txt'
679--- plugins/place/src/screen-size-change/CMakeLists.txt 1970-01-01 00:00:00 +0000
680+++ plugins/place/src/screen-size-change/CMakeLists.txt 2012-01-13 13:20:03 +0000
681@@ -0,0 +1,76 @@
682+pkg_check_modules (
683+ GLIBMM
684+ REQUIRED
685+ glibmm-2.4 glib-2.0
686+)
687+
688+INCLUDE_DIRECTORIES (
689+ ${CMAKE_CURRENT_SOURCE_DIR}/include
690+ ${CMAKE_CURRENT_SOURCE_DIR}/src
691+
692+ ${compiz_SOURCE_DIR}/plugins/place/src/constrain-to-workarea/include
693+ ${compiz_SOURCE_DIR}/src/point/include
694+ ${compiz_SOURCE_DIR}/src/rect/include
695+ ${compiz_SOURCE_DIR}/src/window/geometry/include
696+ ${compiz_SOURCE_DIR}/src/window/geometry-saver/include
697+ ${compiz_SOURCE_DIR}/src/window/extents/include
698+ ${compiz_SOURCE_DIR}/include
699+
700+ ${Boost_INCLUDE_DIRS}
701+
702+ ${GLIBMM_INCLUDE_DIRS}
703+)
704+
705+LINK_DIRECTORIES (${GLIBMM_LIBRARY_DIRS})
706+
707+SET (
708+ PUBLIC_HEADERS
709+)
710+
711+SET (
712+ PRIVATE_HEADERS
713+ ${CMAKE_CURRENT_SOURCE_DIR}/include/screen-size-change.h
714+)
715+
716+SET(
717+ SRCS
718+ ${CMAKE_CURRENT_SOURCE_DIR}/src/screen-size-change.cpp
719+)
720+
721+ADD_LIBRARY(
722+ compiz_place_screen_size_change STATIC
723+
724+ ${SRCS}
725+
726+ ${PUBLIC_HEADERS}
727+ ${PRIVATE_HEADERS}
728+)
729+
730+ADD_SUBDIRECTORY( ${CMAKE_CURRENT_SOURCE_DIR}/tests )
731+
732+SET_TARGET_PROPERTIES(
733+ compiz_place_screen_size_change PROPERTIES
734+ PUBLIC_HEADER "${PUBLIC_HEADERS}"
735+ COMPILE_FLAGS "-fPIC"
736+)
737+
738+INSTALL(
739+ TARGETS compiz_place_screen_size_change
740+ RUNTIME DESTINATION bin
741+ LIBRARY DESTINATION lib
742+ ARCHIVE DESTINATION lib
743+ PUBLIC_HEADER DESTINATION include/compiz
744+)
745+
746+
747+
748+TARGET_LINK_LIBRARIES(
749+ compiz_place_screen_size_change
750+ compiz_place_constrain_to_workarea
751+ compiz_rect
752+ compiz_point
753+ compiz_window_geometry
754+ compiz_window_geometry_saver
755+
756+ ${GLIBMM_LIBRARIES}
757+)
758
759=== added directory 'plugins/place/src/screen-size-change/include'
760=== added file 'plugins/place/src/screen-size-change/include/screen-size-change.h'
761--- plugins/place/src/screen-size-change/include/screen-size-change.h 1970-01-01 00:00:00 +0000
762+++ plugins/place/src/screen-size-change/include/screen-size-change.h 2012-01-13 13:20:03 +0000
763@@ -0,0 +1,67 @@
764+/*
765+ * Copyright (C) 2001 Havoc Pennington
766+ * Copyright (C) 2002, 2003 Red Hat, Inc.
767+ * Copyright (C) 2003 Rob Adams
768+ * Copyright (C) 2005 Novell, Inc.
769+ *
770+ * This program is free software; you can redistribute it and/or
771+ * modify it under the terms of the GNU General Public License as
772+ * published by the Free Software Foundation; either version 2 of the
773+ * License, or (at your option) any later version.
774+ *
775+ * This program is distributed in the hope that it will be useful, but
776+ * WITHOUT ANY WARRANTY; without even the implied warranty of
777+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
778+ * General Public License for more details.
779+ *
780+ * You should have received a copy of the GNU General Public License
781+ * along with this program; if not, write to the Free Software
782+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
783+ * 02111-1307, USA.
784+ */
785+
786+#ifndef _COMPIZ_PLACE_SCREEN_SIZE_CHANGE_H
787+#define _COMPIZ_PLACE_SCREEN_SIZE_CHANGE_H
788+
789+#include <core/rect.h>
790+#include <core/windowgeometry.h>
791+#include <core/windowgeometrysaver.h>
792+#include <core/windowextents.h>
793+#include <core/size.h>
794+#include <core/point.h>
795+
796+#include "constrain-to-workarea.h"
797+
798+namespace compiz
799+{
800+namespace place
801+{
802+
803+class ScreenSizeChangeObject
804+{
805+ public:
806+
807+ ScreenSizeChangeObject (const compiz::window::Geometry &g);
808+ virtual ~ScreenSizeChangeObject ();
809+
810+ virtual const compiz::window::Geometry & getGeometry () const = 0;
811+ virtual void applyGeometry (compiz::window::Geometry &ng,
812+ compiz::window::Geometry &og) = 0;
813+ virtual const CompPoint & getViewport () const = 0;
814+ virtual const CompRect & getWorkarea (const compiz::window::Geometry &g) const = 0;
815+ virtual const compiz::window::extents::Extents & getExtents () const = 0;
816+
817+ compiz::window::Geometry adjustForSize (const CompSize &oldSize,
818+ const CompSize &newSize);
819+
820+ void unset ();
821+
822+ private:
823+
824+ compiz::window::GeometrySaver mSaver;
825+};
826+
827+}
828+}
829+
830+#endif
831
832=== added directory 'plugins/place/src/screen-size-change/src'
833=== added file 'plugins/place/src/screen-size-change/src/screen-size-change.cpp'
834--- plugins/place/src/screen-size-change/src/screen-size-change.cpp 1970-01-01 00:00:00 +0000
835+++ plugins/place/src/screen-size-change/src/screen-size-change.cpp 2012-01-13 13:20:03 +0000
836@@ -0,0 +1,169 @@
837+/*
838+ * Copyright (C) 2001 Havoc Pennington
839+ * Copyright (C) 2002, 2003 Red Hat, Inc.
840+ * Copyright (C) 2003 Rob Adams
841+ * Copyright (C) 2005 Novell, Inc.
842+ *
843+ * This program is free software; you can redistribute it and/or
844+ * modify it under the terms of the GNU General Public License as
845+ * published by the Free Software Foundation; either version 2 of the
846+ * License, or (at your option) any later version.
847+ *
848+ * This program is distributed in the hope that it will be useful, but
849+ * WITHOUT ANY WARRANTY; without even the implied warranty of
850+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
851+ * General Public License for more details.
852+ *
853+ * You should have received a copy of the GNU General Public License
854+ * along with this program; if not, write to the Free Software
855+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
856+ * 02111-1307, USA.
857+ */
858+
859+#include "screen-size-change.h"
860+
861+
862+compiz::place::ScreenSizeChangeObject::ScreenSizeChangeObject (const compiz::window::Geometry &g) :
863+ mSaver (g)
864+{
865+}
866+
867+compiz::place::ScreenSizeChangeObject::~ScreenSizeChangeObject ()
868+{
869+}
870+
871+compiz::window::Geometry
872+compiz::place::ScreenSizeChangeObject::adjustForSize (const CompSize &oldSize,
873+ const CompSize &newSize)
874+{
875+ int vpX, vpY, shiftX, shiftY;
876+ compiz::window::Geometry g, vpRelRect;
877+ int pivotX, pivotY;
878+ int curVpOffsetX = getViewport ().x () * newSize.width ();
879+ int curVpOffsetY = getViewport ().y () * newSize.height ();
880+
881+ g = getGeometry ();
882+
883+ pivotX = g.x ();
884+ pivotY = g.y ();
885+
886+ /* FIXME: Should use saved geometry for maximized / fullscreen windows */
887+
888+ /* calculate target vp x, y index for window's pivot point */
889+ vpX = pivotX / oldSize.width ();
890+ if (pivotX < 0)
891+ vpX -= 1;
892+ vpY = pivotY / oldSize.height ();
893+ if (pivotY < 0)
894+ vpY -= 1;
895+
896+ /* if window's target vp is to the left of the leftmost viewport on that
897+ row, assign its target vp column as 0 (-s->x rel. to current vp) */
898+ if (getViewport ().x () + vpX < 0)
899+ vpX = -getViewport ().x ();
900+
901+ /* if window's target vp is above the topmost viewport on that column,
902+ assign its target vp row as 0 (-s->y rel. to current vp) */
903+ if (getViewport ().y () + vpY < 0)
904+ vpY = -getViewport ().y ();
905+
906+ unsigned int mask = mSaver.pop (vpRelRect, CHANGE_X | CHANGE_Y |
907+ CHANGE_WIDTH | CHANGE_HEIGHT);
908+
909+ if (mask)
910+ {
911+ /* set position/size to saved original rectangle */
912+ g.applyChange (compiz::window::Geometry (vpRelRect.x () + vpX * newSize.width (),
913+ vpRelRect.y () + vpY * newSize.height (),
914+ vpRelRect.width (),
915+ vpRelRect.height (),
916+ vpRelRect.border ()), mask);
917+ }
918+ else
919+ {
920+ /* set position/size to window's current rectangle
921+ (with position relative to target viewport) */
922+ vpRelRect.setX (g.x () - vpX * oldSize.width ());
923+ vpRelRect.setY (g.y () - vpY * oldSize.height ());
924+ vpRelRect.setWidth (g.width ());
925+ vpRelRect.setHeight (g.height ());
926+
927+ g.setPos (g.pos ());
928+
929+ shiftX = vpX * (newSize.width () - oldSize.width ());
930+ shiftY = vpY * (newSize.width () - oldSize.height ());
931+
932+ /* if coords. relative to viewport are outside new viewport area,
933+ shift window left/up so that it falls inside */
934+ if (vpRelRect.x () >= newSize.width ())
935+ shiftX -= vpRelRect.x () - (newSize.width () - 1);
936+ if (vpRelRect.y () >= newSize.height ())
937+ shiftY -= vpRelRect.y () - (newSize.height () - 1);
938+
939+ if (shiftX)
940+ g.setX (g.x () + shiftX);
941+
942+ if (shiftY)
943+ g.setY (g.y () + shiftY);
944+
945+ g.setWidth (vpRelRect.width ());
946+ g.setHeight (vpRelRect.height ());
947+ }
948+
949+ /* Handle non-(0,0) current viewport by shifting by curVpOffsetX,Y,
950+ and bring window to (0,0) by shifting by minus its vp offset */
951+
952+ g.setX (g.x () + curVpOffsetX - (getViewport ().x () + vpX) * newSize.width ());
953+ g.setY (g.y () + curVpOffsetY - (getViewport ().y () + vpY) * newSize.height ());
954+
955+ unsigned int flags = 0;
956+
957+ compiz::window::Geometry og (g);
958+ const CompRect &workArea = getWorkarea (g);
959+
960+ compiz::place::clampGeometryToWorkArea (g, workArea, getExtents (), flags, newSize);
961+
962+ g.setX (g.x () - curVpOffsetX + (getViewport ().x () + vpX) * newSize.width ());
963+ g.setY (g.y () - curVpOffsetY + (getViewport ().y () + vpY) * newSize.height ());
964+
965+ if (!mask)
966+ {
967+ /* save window geometry (relative to viewport) so that it
968+ can be restored later */
969+ mask = getGeometry ().changeMask (g);
970+ mSaver.push (vpRelRect, mask);
971+ }
972+ else
973+ {
974+ compiz::window::Geometry rg (vpRelRect.x () + vpX * newSize.width (),
975+ vpRelRect.y () + vpY * newSize.height (),
976+ vpRelRect.width (),
977+ vpRelRect.height (), vpRelRect.border ());
978+
979+ /* Don't care about any bits not restored */
980+ rg.applyChange (g, ~mask);
981+
982+ /* Push any bits back on the saver
983+ * that don't match the requested window geometry
984+ * since we will need to restore to them later */
985+
986+ unsigned int remaining = g.changeMask (rg);
987+ mSaver.push (vpRelRect, remaining);
988+ }
989+
990+ /* for maximized/fullscreen windows, update saved pos/size XXX,
991+ * also pull in the old code to handle maximized windows which
992+ * currently can't be implemented yet */
993+
994+ /* actually move/resize window in directions given by mask */
995+ applyGeometry (g, og);
996+
997+ return g;
998+}
999+
1000+void
1001+compiz::place::ScreenSizeChangeObject::unset ()
1002+{
1003+ compiz::window::Geometry g;
1004+ mSaver.pop (g, !0);
1005+}
1006
1007=== added directory 'plugins/place/src/screen-size-change/tests'
1008=== added file 'plugins/place/src/screen-size-change/tests/CMakeLists.txt'
1009--- plugins/place/src/screen-size-change/tests/CMakeLists.txt 1970-01-01 00:00:00 +0000
1010+++ plugins/place/src/screen-size-change/tests/CMakeLists.txt 2012-01-13 13:20:03 +0000
1011@@ -0,0 +1,18 @@
1012+include_directories(${CMAKE_CURRENT_SOURCE_DIR})
1013+
1014+add_library (compiz_place_screen_size_change_test
1015+ ${CMAKE_CURRENT_SOURCE_DIR}/test-screen-size-change.cpp)
1016+
1017+add_executable (compiz_test_place_screen_size_change
1018+ ${CMAKE_CURRENT_SOURCE_DIR}/screen-size-change/src/test-place-screen-size-change.cpp)
1019+
1020+target_link_libraries (compiz_test_place_screen_size_change
1021+ compiz_place_screen_size_change_test
1022+ compiz_place_screen_size_change
1023+ ${GTEST_BOTH_LIBRARIES}
1024+ ${GMOCK_LIBRARY}
1025+ ${GMOCK_MAIN_LIBRARY}
1026+ ${CMAKE_THREAD_LIBS_INIT} # Link in pthread.
1027+ )
1028+
1029+add_test (compiz_place_screen_size_change compiz_test_place_screen_size_change)
1030
1031=== added directory 'plugins/place/src/screen-size-change/tests/screen-size-change'
1032=== added directory 'plugins/place/src/screen-size-change/tests/screen-size-change/src'
1033=== added file 'plugins/place/src/screen-size-change/tests/screen-size-change/src/test-place-screen-size-change.cpp'
1034--- plugins/place/src/screen-size-change/tests/screen-size-change/src/test-place-screen-size-change.cpp 1970-01-01 00:00:00 +0000
1035+++ plugins/place/src/screen-size-change/tests/screen-size-change/src/test-place-screen-size-change.cpp 2012-01-13 13:20:03 +0000
1036@@ -0,0 +1,324 @@
1037+/*
1038+ * Copyright © 2011 Canonical Ltd.
1039+ *
1040+ * Permission to use, copy, modify, distribute, and sell this software
1041+ * and its documentation for any purpose is hereby granted without
1042+ * fee, provided that the above copyright notice appear in all copies
1043+ * and that both that copyright notice and this permission notice
1044+ * appear in supporting documentation, and that the name of
1045+ * Canonical Ltd. not be used in advertising or publicity pertaining to
1046+ * distribution of the software without specific, written prior permission.
1047+ * Canonical Ltd. makes no representations about the suitability of this
1048+ * software for any purpose. It is provided "as is" without express or
1049+ * implied warranty.
1050+ *
1051+ * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
1052+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
1053+ * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
1054+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
1055+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
1056+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
1057+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1058+ *
1059+ * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
1060+ */
1061+
1062+#include <test-screen-size-change.h>
1063+#include <screen-size-change.h>
1064+#include <iostream>
1065+#include <stdlib.h>
1066+#include <cstring>
1067+
1068+class CompPlaceScreenSizeChangeTestScreenSizeChange :
1069+ public CompPlaceScreenSizeChangeTest
1070+{
1071+public:
1072+
1073+ CompPlaceScreenSizeChangeTestScreenSizeChange ();
1074+ ~CompPlaceScreenSizeChangeTestScreenSizeChange ();
1075+};
1076+
1077+CompPlaceScreenSizeChangeTestScreenSizeChange::CompPlaceScreenSizeChangeTestScreenSizeChange ()
1078+{
1079+}
1080+
1081+CompPlaceScreenSizeChangeTestScreenSizeChange::~CompPlaceScreenSizeChangeTestScreenSizeChange ()
1082+{
1083+}
1084+
1085+class MockScreenSizeChangeObject :
1086+ public compiz::place::ScreenSizeChangeObject
1087+{
1088+ public:
1089+
1090+ MockScreenSizeChangeObject (const compiz::window::Geometry &);
1091+ ~MockScreenSizeChangeObject ();
1092+
1093+ const compiz::window::Geometry & getGeometry () const;
1094+ void applyGeometry (compiz::window::Geometry &n,
1095+ compiz::window::Geometry &o);
1096+ const CompPoint & getViewport () const;
1097+ const CompRect & getWorkarea (const compiz::window::Geometry &g) const;
1098+ const compiz::window::extents::Extents & getExtents () const;
1099+
1100+ void setVp (const CompPoint &);
1101+ void setWorkArea (const CompRect &);
1102+ void setExtents (unsigned int left,
1103+ unsigned int right,
1104+ unsigned int top,
1105+ unsigned int bottom);
1106+
1107+ void setGeometry (const compiz::window::Geometry &g);
1108+
1109+ private:
1110+
1111+ CompPoint mCurrentVp;
1112+ CompRect mCurrentWorkArea;
1113+ compiz::window::extents::Extents mCurrentExtents;
1114+ compiz::window::Geometry mCurrentGeometry;
1115+};
1116+
1117+MockScreenSizeChangeObject::MockScreenSizeChangeObject (const compiz::window::Geometry &g) :
1118+ ScreenSizeChangeObject (g),
1119+ mCurrentVp (0, 0),
1120+ mCurrentWorkArea (50, 50, 1000, 1000),
1121+ mCurrentGeometry (g)
1122+{
1123+ memset (&mCurrentExtents, 0, sizeof (compiz::window::extents::Extents));
1124+}
1125+
1126+MockScreenSizeChangeObject::~MockScreenSizeChangeObject ()
1127+{
1128+}
1129+
1130+const compiz::window::Geometry &
1131+MockScreenSizeChangeObject::getGeometry () const
1132+{
1133+ return mCurrentGeometry;
1134+}
1135+
1136+void
1137+MockScreenSizeChangeObject::applyGeometry (compiz::window::Geometry &n,
1138+ compiz::window::Geometry &o)
1139+{
1140+ std::cout << "DEBUG: new geometry : " << n.x () << " "
1141+ << n.y () << " "
1142+ << n.width () << " "
1143+ << n.height () << " "
1144+ << n.border () << std::endl;
1145+
1146+ std::cout << "DEBUG: old geometry : " << o.x () << " "
1147+ << o.y () << " "
1148+ << o.width () << " "
1149+ << o.height () << " "
1150+ << o.border () << std::endl;
1151+
1152+ mCurrentGeometry = n;
1153+}
1154+
1155+const CompPoint &
1156+MockScreenSizeChangeObject::getViewport () const
1157+{
1158+ return mCurrentVp;
1159+}
1160+
1161+const CompRect &
1162+MockScreenSizeChangeObject::getWorkarea (const compiz::window::Geometry &g) const
1163+{
1164+ return mCurrentWorkArea;
1165+}
1166+
1167+const compiz::window::extents::Extents &
1168+MockScreenSizeChangeObject::getExtents () const
1169+{
1170+ return mCurrentExtents;
1171+}
1172+
1173+void
1174+MockScreenSizeChangeObject::setVp (const CompPoint &p)
1175+{
1176+ mCurrentVp = p;
1177+}
1178+
1179+void
1180+MockScreenSizeChangeObject::setWorkArea (const CompRect &wa)
1181+{
1182+ mCurrentWorkArea = wa;
1183+}
1184+
1185+void
1186+MockScreenSizeChangeObject::setExtents (unsigned int left,
1187+ unsigned int right,
1188+ unsigned int top,
1189+ unsigned int bottom)
1190+{
1191+ mCurrentExtents.left = left;
1192+ mCurrentExtents.right = right;
1193+ mCurrentExtents.top = top;
1194+ mCurrentExtents.bottom = bottom;
1195+}
1196+
1197+void
1198+MockScreenSizeChangeObject::setGeometry (const compiz::window::Geometry &g)
1199+{
1200+ mCurrentGeometry = g;
1201+}
1202+
1203+void
1204+reserveStruts (CompRect &workArea)
1205+{
1206+ workArea.setLeft (workArea.left () + 24);
1207+ workArea.setTop (workArea.top () + 24);
1208+ workArea.setBottom (workArea.bottom () - 24);
1209+}
1210+
1211+TEST_F (CompPlaceScreenSizeChangeTestScreenSizeChange, TestScreenSizeChange)
1212+{
1213+ CompSize current, old;
1214+ compiz::window::Geometry g (200, 250, 300, 400, 0);
1215+
1216+ MockScreenSizeChangeObject *ms = new MockScreenSizeChangeObject (g);
1217+
1218+ current = CompSize (1280, 800);
1219+
1220+ /* Reserve top, bottom and left parts of the screen for
1221+ * fake "24px" panels */
1222+ CompRect workArea = CompRect (0, 0, current.width (), current.height ());
1223+ reserveStruts (workArea);
1224+
1225+ ms->setWorkArea (workArea);
1226+
1227+ /* First test that changing the screen size
1228+ * to something smaller here doesn't cause our
1229+ * (small) window to be moved */
1230+
1231+ old = current;
1232+ current = CompSize (1024, 768);
1233+
1234+ workArea = CompRect (0, 0, current.width (), current.height ());
1235+ reserveStruts (workArea);
1236+
1237+ ms->setWorkArea (workArea);
1238+
1239+ g = ms->adjustForSize (old, current);
1240+
1241+ EXPECT_EQ (g, compiz::window::Geometry (200, 250, 300, 400, 0));
1242+
1243+ /* Making the screen size bigger with no
1244+ * saved geometry should cause the window not to move */
1245+
1246+ old = current;
1247+ current = CompSize (2048, 768);
1248+
1249+ workArea = CompRect (0, 0, current.width (), current.height ());
1250+ reserveStruts (workArea);
1251+
1252+ ms->setWorkArea (workArea);
1253+
1254+ g = ms->adjustForSize (old, current);
1255+
1256+ EXPECT_EQ (g, compiz::window::Geometry (200, 250, 300, 400, 0));
1257+
1258+ /* Move the window to the other "monitor" */
1259+
1260+ ms->setGeometry (compiz::window::Geometry (1025, 250, 300, 400, 0));
1261+
1262+ old = current;
1263+
1264+ /* Unplug a "monitor" */
1265+ current = CompSize (1024, 768);
1266+
1267+ workArea = CompRect (0, 0, current.width (), current.height ());
1268+ reserveStruts (workArea);
1269+
1270+ ms->setWorkArea (workArea);
1271+
1272+ g = ms->adjustForSize (old, current);
1273+
1274+ EXPECT_EQ (g, compiz::window::Geometry (724, 250, 300, 400, 0));
1275+
1276+ old = current;
1277+
1278+ /* Re-plug the monitor - window should go back
1279+ * to the same position */
1280+ current = CompSize (2048, 768);
1281+
1282+ workArea = CompRect (0, 0, current.width (), current.height ());
1283+ reserveStruts (workArea);
1284+
1285+ ms->setWorkArea (workArea);
1286+
1287+ g = ms->adjustForSize (old, current);
1288+
1289+ EXPECT_EQ (g, compiz::window::Geometry (1025, 250, 300, 400, 0));
1290+
1291+ old = current;
1292+
1293+ /* Plug 2 monitors downwards, no change */
1294+ current = CompSize (2048, 1536);
1295+
1296+ workArea = CompRect (0, 0, current.width (), current.height ());
1297+ reserveStruts (workArea);
1298+
1299+ ms->setWorkArea (workArea);
1300+
1301+ g = ms->adjustForSize (old, current);
1302+
1303+ EXPECT_EQ (g, compiz::window::Geometry (1025, 250, 300, 400, 0));
1304+
1305+ /* Move the window to the bottom "monitor" */
1306+
1307+ ms->setGeometry (compiz::window::Geometry (1025, 791, 300, 400, 0));
1308+
1309+ old = current;
1310+
1311+ /* Unplug bottom "monitor" */
1312+ current = CompSize (2048, 768);
1313+
1314+ workArea = CompRect (0, 0, current.width (), current.height ());
1315+ reserveStruts (workArea);
1316+
1317+ ms->setWorkArea (workArea);
1318+
1319+ g = ms->adjustForSize (old, current);
1320+
1321+ EXPECT_EQ (g, compiz::window::Geometry (1025, 344, 300, 400, 0));
1322+
1323+ old = current;
1324+
1325+ /* Re-plug bottom "monitor" */
1326+ current = CompSize (2048, 1356);
1327+
1328+ workArea = CompRect (0, 0, current.width (), current.height ());
1329+ reserveStruts (workArea);
1330+
1331+ ms->setWorkArea (workArea);
1332+
1333+ g = ms->adjustForSize (old, current);
1334+
1335+ EXPECT_EQ (g, compiz::window::Geometry (1025, 791, 300, 400, 0));
1336+
1337+ /* Move the entire window right a viewport */
1338+
1339+ g.setPos (g.pos () + CompPoint (current.width (), 0));
1340+
1341+ ms->setGeometry (g);
1342+
1343+ /* Now change the screen resolution again - the window should
1344+ * move to be within the constrained size of its current
1345+ * viewport */
1346+
1347+ /* Unplug a "monitor" */
1348+ old = current;
1349+ current = CompSize (1024, 1356);
1350+
1351+ workArea = CompRect (0, 0, current.width (), current.height ());
1352+ reserveStruts (workArea);
1353+
1354+ ms->setWorkArea (workArea);
1355+
1356+ g = ms->adjustForSize (old, current);
1357+
1358+ EXPECT_EQ (g, compiz::window::Geometry (current.width () + 724, 791, 300, 400, 0));
1359+}
1360+
1361
1362=== added file 'plugins/place/src/screen-size-change/tests/test-screen-size-change.cpp'
1363--- plugins/place/src/screen-size-change/tests/test-screen-size-change.cpp 1970-01-01 00:00:00 +0000
1364+++ plugins/place/src/screen-size-change/tests/test-screen-size-change.cpp 2012-01-13 13:20:03 +0000
1365@@ -0,0 +1,34 @@
1366+/*
1367+ * Copyright © 2011 Canonical Ltd.
1368+ *
1369+ * Permission to use, copy, modify, distribute, and sell this software
1370+ * and its documentation for any purpose is hereby granted without
1371+ * fee, provided that the above copyright notice appear in all copies
1372+ * and that both that copyright notice and this permission notice
1373+ * appear in supporting documentation, and that the name of
1374+ * Canonical Ltd. not be used in advertising or publicity pertaining to
1375+ * distribution of the software without specific, written prior permission.
1376+ * Canonical Ltd. makes no representations about the suitability of this
1377+ * software for any purpose. It is provided "as is" without express or
1378+ * implied warranty.
1379+ *
1380+ * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
1381+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
1382+ * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
1383+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
1384+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
1385+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
1386+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1387+ *
1388+ * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
1389+ */
1390+
1391+#include "test-screen-size-change.h"
1392+
1393+CompPlaceScreenSizeChangeTest::CompPlaceScreenSizeChangeTest ()
1394+{
1395+}
1396+
1397+CompPlaceScreenSizeChangeTest::~CompPlaceScreenSizeChangeTest ()
1398+{
1399+}
1400
1401=== added file 'plugins/place/src/screen-size-change/tests/test-screen-size-change.h'
1402--- plugins/place/src/screen-size-change/tests/test-screen-size-change.h 1970-01-01 00:00:00 +0000
1403+++ plugins/place/src/screen-size-change/tests/test-screen-size-change.h 2012-01-13 13:20:03 +0000
1404@@ -0,0 +1,49 @@
1405+/*
1406+ * Copyright © 2011 Canonical Ltd.
1407+ *
1408+ * Permission to use, copy, modify, distribute, and sell this software
1409+ * and its documentation for any purpose is hereby granted without
1410+ * fee, provided that the above copyright notice appear in all copies
1411+ * and that both that copyright notice and this permission notice
1412+ * appear in supporting documentation, and that the name of
1413+ * Canonical Ltd. not be used in advertising or publicity pertaining to
1414+ * distribution of the software without specific, written prior permission.
1415+ * Canonical Ltd. makes no representations about the suitability of this
1416+ * software for any purpose. It is provided "as is" without express or
1417+ * implied warranty.
1418+ *
1419+ * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
1420+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
1421+ * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
1422+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
1423+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
1424+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
1425+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1426+ *
1427+ * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
1428+ */
1429+
1430+#ifndef _COMPIZ_TEST_PLACE_SCREEN_SIZE_CHANGE_H
1431+#define _COMPIZ_TEST_PLACE_SCREEN_SIZE_CHANGE_H
1432+
1433+#include <gtest/gtest.h>
1434+#include <core/rect.h>
1435+#include <core/windowgeometry.h>
1436+#include <core/windowgeometrysaver.h>
1437+#include <core/windowextents.h>
1438+#include <core/size.h>
1439+#include <core/point.h>
1440+#include <string>
1441+#include <iostream>
1442+#include <stdlib.h>
1443+
1444+class CompPlaceScreenSizeChangeTest :
1445+ public ::testing::Test
1446+{
1447+public:
1448+
1449+ CompPlaceScreenSizeChangeTest ();
1450+ virtual ~CompPlaceScreenSizeChangeTest ();
1451+};
1452+
1453+#endif
1454
1455=== removed directory 'plugins/place/tests'
1456=== removed file 'plugins/place/tests/CMakeLists.txt'
1457=== removed directory 'plugins/place/tests/place'
1458=== modified file 'plugins/resize/src/resize.cpp'
1459--- plugins/resize/src/resize.cpp 2012-01-13 13:20:02 +0000
1460+++ plugins/resize/src/resize.cpp 2012-01-13 13:20:03 +0000
1461@@ -885,7 +885,12 @@
1462 cwi = wi;
1463 che = he;
1464
1465- if (w->constrainNewWindowSize (wi, he, &cwi, &che) &&
1466+ CompSize size (wi, he);
1467+ CompSize constrained =
1468+ compiz::window::constrainment::constrainToHints (w,
1469+ size);
1470+
1471+ if (constrained != size &&
1472 mode != ResizeOptions::ModeNormal)
1473 {
1474 Box box;
1475@@ -900,6 +905,9 @@
1476 damageRectangle (&box);
1477 }
1478
1479+ cwi = constrained.width ();
1480+ che = constrained.height ();
1481+
1482 /* constrain to work area */
1483 if (offWorkAreaConstrained)
1484 {
1485
1486=== modified file 'src/CMakeLists.txt'
1487--- src/CMakeLists.txt 2012-01-13 13:20:02 +0000
1488+++ src/CMakeLists.txt 2012-01-13 13:20:03 +0000
1489@@ -57,6 +57,9 @@
1490
1491 ${CMAKE_CURRENT_SOURCE_DIR}/window/extents/include
1492 ${CMAKE_CURRENT_SOURCE_DIR}/window/extents/src
1493+
1494+ ${CMAKE_CURRENT_SOURCE_DIR}/window/constrainment/include
1495+ ${CMAKE_CURRENT_SOURCE_DIR}/window/constrainment/src
1496 )
1497
1498 add_definitions (
1499@@ -121,6 +124,7 @@
1500 compiz_window_geometry
1501 compiz_window_geometry_saver
1502 compiz_window_extents
1503+ compiz_window_constrainment
1504 # ${CORE_MOD_LIBRARIES}
1505 )
1506
1507
1508=== modified file 'src/logmessage/CMakeLists.txt'
1509--- src/logmessage/CMakeLists.txt 2012-01-12 08:35:59 +0000
1510+++ src/logmessage/CMakeLists.txt 2012-01-13 13:20:03 +0000
1511@@ -26,6 +26,7 @@
1512 SET_TARGET_PROPERTIES(
1513 compiz_logmessage PROPERTIES
1514 PUBLIC_HEADER "${PUBLIC_HEADERS}"
1515+ COMPILE_FLAGS "-fPIC"
1516 )
1517
1518 INSTALL(
1519
1520=== modified file 'src/pluginclasshandler/CMakeLists.txt'
1521--- src/pluginclasshandler/CMakeLists.txt 2012-01-12 08:35:59 +0000
1522+++ src/pluginclasshandler/CMakeLists.txt 2012-01-13 13:20:03 +0000
1523@@ -40,6 +40,7 @@
1524 SET_TARGET_PROPERTIES(
1525 compiz_pluginclasshandler PROPERTIES
1526 PUBLIC_HEADER "${PUBLIC_HEADERS}"
1527+ COMPILE_FLAGS "-fPIC"
1528 )
1529
1530 INSTALL(
1531
1532=== modified file 'src/pluginclasshandler/src/valueholder.h'
1533--- src/pluginclasshandler/src/valueholder.h 2011-10-31 13:51:00 +0000
1534+++ src/pluginclasshandler/src/valueholder.h 2012-01-13 13:20:03 +0000
1535@@ -30,6 +30,7 @@
1536 public:
1537
1538 ValueHolder ();
1539+ virtual ~ValueHolder () { delete priv; };
1540
1541 void hasValue (CompString key);
1542 void storeValue (CompString key, CompPrivate value);
1543
1544=== modified file 'src/pluginclasshandler/tests/test-pluginclasshandler.h'
1545--- src/pluginclasshandler/tests/test-pluginclasshandler.h 2011-12-19 07:06:22 +0000
1546+++ src/pluginclasshandler/tests/test-pluginclasshandler.h 2012-01-13 13:20:03 +0000
1547@@ -23,6 +23,7 @@
1548 public:
1549
1550 Global ();
1551+ ~Global () {}
1552
1553 std::list <Base *> bases;
1554 };
1555
1556=== modified file 'src/point/CMakeLists.txt'
1557--- src/point/CMakeLists.txt 2012-01-13 13:20:02 +0000
1558+++ src/point/CMakeLists.txt 2012-01-13 13:20:03 +0000
1559@@ -48,6 +48,7 @@
1560 SET_TARGET_PROPERTIES(
1561 compiz_point PROPERTIES
1562 PUBLIC_HEADER "${PUBLIC_HEADERS}"
1563+ COMPILE_FLAGS "-fPIC"
1564 )
1565
1566 INSTALL(
1567
1568=== modified file 'src/rect/CMakeLists.txt'
1569--- src/rect/CMakeLists.txt 2012-01-13 13:20:02 +0000
1570+++ src/rect/CMakeLists.txt 2012-01-13 13:20:03 +0000
1571@@ -46,6 +46,7 @@
1572 SET_TARGET_PROPERTIES(
1573 compiz_rect PROPERTIES
1574 PUBLIC_HEADER "${PUBLIC_HEADERS}"
1575+ COMPILE_FLAGS "-fPIC"
1576 )
1577
1578 INSTALL(
1579
1580=== modified file 'src/screen.cpp'
1581--- src/screen.cpp 2012-01-13 13:20:02 +0000
1582+++ src/screen.cpp 2012-01-13 13:20:03 +0000
1583@@ -4141,8 +4141,8 @@
1584 return priv->screenNum;
1585 }
1586
1587-CompPoint
1588-CompScreen::vp ()
1589+const CompPoint &
1590+CompScreen::vp () const
1591 {
1592 return priv->vp;
1593 }
1594
1595=== modified file 'src/size.cpp'
1596--- src/size.cpp 2009-07-30 23:21:10 +0000
1597+++ src/size.cpp 2012-01-13 13:20:03 +0000
1598@@ -48,3 +48,16 @@
1599 {
1600 mHeight = height;
1601 }
1602+
1603+bool
1604+CompSize::operator== (const CompSize &other) const
1605+{
1606+ return (width () == other.width () &&
1607+ height () == other.height ());
1608+}
1609+
1610+bool
1611+CompSize::operator!= (const CompSize &other) const
1612+{
1613+ return !(*this == other);
1614+}
1615
1616=== modified file 'src/string/CMakeLists.txt'
1617--- src/string/CMakeLists.txt 2011-12-19 07:06:22 +0000
1618+++ src/string/CMakeLists.txt 2012-01-13 13:20:03 +0000
1619@@ -24,6 +24,7 @@
1620 SET_TARGET_PROPERTIES(
1621 compiz_string PROPERTIES
1622 PUBLIC_HEADER "${PUBLIC_HEADERS}"
1623+ COMPILE_FLAGS "-fPIC"
1624 )
1625
1626 INSTALL(
1627
1628=== modified file 'src/timer/CMakeLists.txt'
1629--- src/timer/CMakeLists.txt 2012-01-12 08:35:59 +0000
1630+++ src/timer/CMakeLists.txt 2012-01-13 13:20:03 +0000
1631@@ -51,6 +51,7 @@
1632 SET_TARGET_PROPERTIES(
1633 compiz_timer PROPERTIES
1634 PUBLIC_HEADER "${PUBLIC_HEADERS}"
1635+ COMPILE_FLAGS "-fPIC"
1636 )
1637
1638 INSTALL(
1639
1640=== modified file 'src/window.cpp'
1641--- src/window.cpp 2012-01-13 13:20:02 +0000
1642+++ src/window.cpp 2012-01-13 13:20:03 +0000
1643@@ -3765,12 +3765,11 @@
1644 if (state & CompWindowStateFullscreenMask ||
1645 state & CompWindowStateMaximizedHorzMask)
1646 {
1647- int width = old.width ();
1648- int height = old.height ();
1649-
1650- window->constrainNewWindowSize (width, height, &width, &height);
1651-
1652- if (width > output->width ())
1653+ CompSize size = CompSize (old.width (), old.height ());
1654+ size = compiz::window::constrainment::constrainToHints (window,
1655+ size);
1656+
1657+ if (size.width () > output->width ())
1658 {
1659 int distance = std::numeric_limits <int>::max ();
1660 CompOutput *selected = output;
1661@@ -3778,7 +3777,7 @@
1662 * which has a large enough size */
1663 foreach (CompOutput &o, screen->outputDevs ())
1664 {
1665- if (o.workArea ().width () > width)
1666+ if (o.workArea ().width () > size.width ())
1667 {
1668 int tDistance = sqrt (pow (abs (o.x () - output->x ()), 2) +
1669 pow (abs (o.y () - output->y ()), 2));
1670@@ -3798,12 +3797,11 @@
1671 if (state & CompWindowStateFullscreenMask ||
1672 state & CompWindowStateMaximizedVertMask)
1673 {
1674- int width = old.width ();
1675- int height = old.height ();
1676-
1677- window->constrainNewWindowSize (width, height, &width, &height);
1678-
1679- if (height > output->height ())
1680+ CompSize size = CompSize (old.width (), old.height ());
1681+ size = compiz::window::constrainment::constrainToHints (window,
1682+ size);
1683+
1684+ if (size.height () > output->height ())
1685 {
1686 int distance = std::numeric_limits <int>::max ();
1687 CompOutput *selected = output;
1688@@ -3811,7 +3809,7 @@
1689 * which has a large enough size */
1690 foreach (CompOutput &o, screen->outputDevs ())
1691 {
1692- if (o.workArea ().height () > height)
1693+ if (o.workArea ().height () > size.height ())
1694 {
1695 int tDistance = sqrt (pow (abs (o.x () - output->x ()), 2) +
1696 pow (abs (o.y () - output->y ()), 2));
1697@@ -3851,7 +3849,7 @@
1698 output = selectOutputForGeometry (old);
1699 workArea = output->workArea ();
1700
1701- if (!priv->placed)
1702+ if (priv->placed)
1703 {
1704 if (type & CompWindowTypeFullscreenMask)
1705 {
1706@@ -3943,15 +3941,18 @@
1707 if (changeMask & (CHANGE_WIDTH | CHANGE_HEIGHT))
1708 {
1709 compiz::window::Geometry constrained = old;
1710+ CompSize size;
1711 int width, height, max;
1712
1713 constrained.applyChange (ng, changeMask);
1714 ng.setSize (CompSize (old.width (), old.height ()));
1715-
1716- width = constrained.width ();
1717- height = constrained.height ();
1718-
1719- window->constrainNewWindowSize (width, height, &width, &height);
1720+ size =
1721+ compiz::window::constrainment::constrainToHints (window,
1722+ CompSize (constrained.width (),
1723+ constrained.height ()));
1724+
1725+ width = size.width ();
1726+ height = size.height ();
1727
1728 if (width != (int) old.width ())
1729 {
1730@@ -3969,6 +3970,7 @@
1731 else
1732 changeMask &= ~CHANGE_HEIGHT;
1733
1734+
1735 if (state & CompWindowStateMaximizedVertMask)
1736 {
1737 /* If the window is still offscreen, then we need to constrain it
1738@@ -4167,9 +4169,11 @@
1739
1740 if (changeMask & (CHANGE_WIDTH | CHANGE_HEIGHT))
1741 {
1742- int width, height;
1743+ CompSize size = compiz::window::constrainment::constrainToHints (window,
1744+ CompSize (ng.width (),
1745+ ng.height ()));
1746
1747- if (window->constrainNewWindowSize (ng.width (), ng.height (), &width, &height))
1748+ if (size.width () != ng.width () && size.height () != ng.height ())
1749 {
1750 if (width != ng.width ())
1751 changeMask |= CHANGE_WIDTH;
1752@@ -4697,158 +4701,38 @@
1753 moveInputFocusTo ();
1754 }
1755
1756-
1757-#define PVertResizeInc (1 << 0)
1758-#define PHorzResizeInc (1 << 1)
1759-
1760-bool
1761-CompWindow::constrainNewWindowSize (int width,
1762- int height,
1763- int *newWidth,
1764- int *newHeight)
1765-{
1766- const XSizeHints *hints = &priv->sizeHints;
1767- int oldWidth = width;
1768- int oldHeight = height;
1769- int min_width = 0;
1770- int min_height = 0;
1771- int base_width = 0;
1772- int base_height = 0;
1773- int xinc = 1;
1774- int yinc = 1;
1775- int max_width = MAXSHORT;
1776- int max_height = MAXSHORT;
1777- long flags = hints->flags;
1778- long resizeIncFlags = (flags & PResizeInc) ? ~0 : 0;
1779-
1780- if (screen->priv->optionGetIgnoreHintsWhenMaximized ())
1781- {
1782- if (priv->state & MAXIMIZE_STATE)
1783- {
1784- flags &= ~PAspect;
1785-
1786- if (priv->state & CompWindowStateMaximizedHorzMask)
1787- resizeIncFlags &= ~PHorzResizeInc;
1788-
1789- if (priv->state & CompWindowStateMaximizedVertMask)
1790- resizeIncFlags &= ~PVertResizeInc;
1791- }
1792- }
1793-
1794- /* Ater gdk_window_constrain_size(), which is partially borrowed from fvwm.
1795- *
1796- * Copyright 1993, Robert Nation
1797- * You may use this code for any purpose, as long as the original
1798- * copyright remains in the source code and all documentation
1799- *
1800- * which in turn borrows parts of the algorithm from uwm
1801- */
1802-
1803-#define FLOOR(value, base) (((int) ((value) / (base))) * (base))
1804-#define FLOOR64(value, base) (((uint64_t) ((value) / (base))) * (base))
1805-
1806- if ((flags & PBaseSize) && (flags & PMinSize))
1807- {
1808- base_width = hints->base_width;
1809- base_height = hints->base_height;
1810- min_width = hints->min_width;
1811- min_height = hints->min_height;
1812- }
1813- else if (flags & PBaseSize)
1814- {
1815- base_width = hints->base_width;
1816- base_height = hints->base_height;
1817- min_width = hints->base_width;
1818- min_height = hints->base_height;
1819- }
1820- else if (flags & PMinSize)
1821- {
1822- base_width = hints->min_width;
1823- base_height = hints->min_height;
1824- min_width = hints->min_width;
1825- min_height = hints->min_height;
1826- }
1827-
1828- if (flags & PMaxSize)
1829- {
1830- max_width = hints->max_width;
1831- max_height = hints->max_height;
1832- }
1833-
1834- if (resizeIncFlags & PHorzResizeInc)
1835- xinc = MAX (xinc, hints->width_inc);
1836-
1837- if (resizeIncFlags & PVertResizeInc)
1838- yinc = MAX (yinc, hints->height_inc);
1839-
1840- /* clamp width and height to min and max values */
1841- width = CLAMP (width, min_width, max_width);
1842- height = CLAMP (height, min_height, max_height);
1843-
1844- /* shrink to base + N * inc */
1845- width = base_width + FLOOR (width - base_width, xinc);
1846- height = base_height + FLOOR (height - base_height, yinc);
1847-
1848- /* constrain aspect ratio, according to:
1849- *
1850- * min_aspect.x width max_aspect.x
1851- * ------------ <= -------- <= -----------
1852- * min_aspect.y height max_aspect.y
1853- */
1854- if ((flags & PAspect) && hints->min_aspect.y > 0 && hints->max_aspect.x > 0)
1855- {
1856- /* Use 64 bit arithmetic to prevent overflow */
1857-
1858- uint64_t min_aspect_x = hints->min_aspect.x;
1859- uint64_t min_aspect_y = hints->min_aspect.y;
1860- uint64_t max_aspect_x = hints->max_aspect.x;
1861- uint64_t max_aspect_y = hints->max_aspect.y;
1862- uint64_t delta;
1863-
1864- if (min_aspect_x * height > width * min_aspect_y)
1865- {
1866- delta = FLOOR64 (height - width * min_aspect_y / min_aspect_x,
1867- yinc);
1868- if (height - (int) delta >= min_height)
1869- height -= delta;
1870- else
1871- {
1872- delta = FLOOR64 (height * min_aspect_x / min_aspect_y - width,
1873- xinc);
1874- if (width + (int) delta <= max_width)
1875- width += delta;
1876- }
1877- }
1878-
1879- if (width * max_aspect_y > max_aspect_x * height)
1880- {
1881- delta = FLOOR64 (width - height * max_aspect_x / max_aspect_y,
1882- xinc);
1883- if (width - (int) delta >= min_width)
1884- width -= delta;
1885- else
1886- {
1887- delta = FLOOR64 (width * min_aspect_y / min_aspect_x - height,
1888- yinc);
1889- if (height + (int) delta <= max_height)
1890- height += delta;
1891- }
1892- }
1893- }
1894-
1895-#undef CLAMP
1896-#undef FLOOR64
1897-#undef FLOOR
1898-
1899- if (width != oldWidth || height != oldHeight)
1900- {
1901- *newWidth = width;
1902- *newHeight = height;
1903-
1904- return true;
1905- }
1906-
1907- return false;
1908+static inline int constrainmentFloor (int value, int base)
1909+{
1910+ return (value / base) * base;
1911+}
1912+
1913+static inline uint64_t constrainment64Floor (uint64_t value, uint64_t base)
1914+{
1915+ return (value / base) * base;
1916+}
1917+
1918+CompSize
1919+compiz::window::constrainment::constrainToHints (CompWindow *w,
1920+ const CompSize &size)
1921+{
1922+ unsigned int resizeIgnoreHints = 0;
1923+ unsigned int ignoreHints = 0;
1924+
1925+ if (screen->getOption ("ignore_hints_when_maximized"))
1926+ {
1927+ if (w->state () & MAXIMIZE_STATE)
1928+ {
1929+ ignoreHints |= PAspect;
1930+
1931+ if (w->state () & CompWindowStateMaximizedHorzMask)
1932+ resizeIgnoreHints |= PHorzResizeInc;
1933+
1934+ if (w->state () & CompWindowStateMaximizedVertMask)
1935+ resizeIgnoreHints |= PVertResizeInc;
1936+ }
1937+ }
1938+
1939+ return constrainToHints (w->sizeHints (), size, ignoreHints, resizeIgnoreHints);
1940 }
1941
1942 void
1943
1944=== modified file 'src/window/CMakeLists.txt'
1945--- src/window/CMakeLists.txt 2012-01-13 13:20:02 +0000
1946+++ src/window/CMakeLists.txt 2012-01-13 13:20:03 +0000
1947@@ -1,3 +1,4 @@
1948 add_subdirectory (geometry)
1949 add_subdirectory (geometry-saver)
1950 add_subdirectory (extents)
1951+add_subdirectory (constrainment)
1952
1953=== added directory 'src/window/constrainment'
1954=== added file 'src/window/constrainment/CMakeLists.txt'
1955--- src/window/constrainment/CMakeLists.txt 1970-01-01 00:00:00 +0000
1956+++ src/window/constrainment/CMakeLists.txt 2012-01-13 13:20:03 +0000
1957@@ -0,0 +1,72 @@
1958+pkg_check_modules (
1959+ GLIBMM
1960+ REQUIRED
1961+ glibmm-2.4 glib-2.0
1962+)
1963+
1964+INCLUDE_DIRECTORIES (
1965+ ${CMAKE_CURRENT_SOURCE_DIR}/include
1966+ ${CMAKE_CURRENT_SOURCE_DIR}/src
1967+
1968+ ${compiz_SOURCE_DIR}/include
1969+
1970+ ${compiz_SOURCE_DIR}/src/point/include
1971+ ${compiz_SOURCE_DIR}/src/rect/include
1972+ ${compiz_SOURCE_DIR}/src/window/geometry/include
1973+ ${compiz_SOURCE_DIR}/src/window/geometry-saver/include
1974+ ${Boost_INCLUDE_DIRS}
1975+
1976+ ${GLIBMM_INCLUDE_DIRS}
1977+)
1978+
1979+LINK_DIRECTORIES (${GLIBMM_LIBRARY_DIRS})
1980+
1981+SET (
1982+ PUBLIC_HEADERS
1983+ ${CMAKE_CURRENT_SOURCE_DIR}/include/core/windowconstrainment.h
1984+)
1985+
1986+SET (
1987+ PRIVATE_HEADERS
1988+)
1989+
1990+SET(
1991+ SRCS
1992+ ${CMAKE_CURRENT_SOURCE_DIR}/src/windowconstrainment.cpp
1993+)
1994+
1995+ADD_LIBRARY(
1996+ compiz_window_constrainment STATIC
1997+
1998+ ${SRCS}
1999+
2000+ ${PUBLIC_HEADERS}
2001+ ${PRIVATE_HEADERS}
2002+)
2003+
2004+ADD_SUBDIRECTORY( ${CMAKE_CURRENT_SOURCE_DIR}/tests )
2005+
2006+SET_TARGET_PROPERTIES(
2007+ compiz_window_constrainment PROPERTIES
2008+ PUBLIC_HEADER "${PUBLIC_HEADERS}"
2009+ COMPILE_FLAGS "-fPIC"
2010+)
2011+
2012+INSTALL(
2013+ TARGETS compiz_window_constrainment
2014+ RUNTIME DESTINATION bin
2015+ LIBRARY DESTINATION lib
2016+ ARCHIVE DESTINATION lib
2017+ PUBLIC_HEADER DESTINATION include/compiz
2018+)
2019+
2020+
2021+
2022+TARGET_LINK_LIBRARIES(
2023+ compiz_window_constrainment
2024+ compiz_window_geometry
2025+ compiz_point
2026+ compiz_rect
2027+
2028+ ${GLIBMM_LIBRARIES}
2029+)
2030
2031=== added directory 'src/window/constrainment/include'
2032=== added directory 'src/window/constrainment/include/core'
2033=== added file 'src/window/constrainment/include/core/windowconstrainment.h'
2034--- src/window/constrainment/include/core/windowconstrainment.h 1970-01-01 00:00:00 +0000
2035+++ src/window/constrainment/include/core/windowconstrainment.h 2012-01-13 13:20:03 +0000
2036@@ -0,0 +1,57 @@
2037+/*
2038+ * Copyright © 2008 Dennis Kasprzyk
2039+ * Copyright © 2007 Novell, Inc.
2040+ *
2041+ * Permission to use, copy, modify, distribute, and sell this software
2042+ * and its documentation for any purpose is hereby granted without
2043+ * fee, provided that the above copyright notice appear in all copies
2044+ * and that both that copyright notice and this permission notice
2045+ * appear in supporting documentation, and that the name of
2046+ * Dennis Kasprzyk not be used in advertising or publicity pertaining to
2047+ * distribution of the software without specific, written prior permission.
2048+ * Dennis Kasprzyk makes no representations about the suitability of this
2049+ * software for any purpose. It is provided "as is" without express or
2050+ * implied warranty.
2051+ *
2052+ * DENNIS KASPRZYK DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
2053+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
2054+ * NO EVENT SHALL DENNIS KASPRZYK BE LIABLE FOR ANY SPECIAL, INDIRECT OR
2055+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
2056+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
2057+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
2058+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2059+ *
2060+ * Authors: Dennis Kasprzyk <onestone@compiz-fusion.org>
2061+ * David Reveman <davidr@novell.com>
2062+ */
2063+
2064+#ifndef _COMPWINDOWCONSTRAINMENT_H
2065+#define _COMPWINDOWCONSTRAINMENT_H
2066+
2067+#include <inttypes.h>
2068+#include <core/size.h>
2069+#include <core/rect.h>
2070+#include <X11/Xlib.h>
2071+#include <X11/Xutil.h>
2072+#include <limits>
2073+
2074+namespace compiz
2075+{
2076+namespace window
2077+{
2078+
2079+namespace constrainment
2080+{
2081+const unsigned int PVertResizeInc = (1 << 0);
2082+const unsigned int PHorzResizeInc = (1 << 1);
2083+
2084+CompSize constrainToHints (const XSizeHints &hints,
2085+ const CompSize &size,
2086+ unsigned int ignoreHints,
2087+ unsigned int resizeIgnoreHints);
2088+}
2089+
2090+}
2091+}
2092+
2093+#endif
2094
2095=== added directory 'src/window/constrainment/src'
2096=== added file 'src/window/constrainment/src/windowconstrainment.cpp'
2097--- src/window/constrainment/src/windowconstrainment.cpp 1970-01-01 00:00:00 +0000
2098+++ src/window/constrainment/src/windowconstrainment.cpp 2012-01-13 13:20:03 +0000
2099@@ -0,0 +1,161 @@
2100+/*
2101+ * Copyright © 2005 Novell, Inc.
2102+ *
2103+ * Permission to use, copy, modify, distribute, and sell this software
2104+ * and its documentation for any purpose is hereby granted without
2105+ * fee, provided that the above copyright notice appear in all copies
2106+ * and that both that copyright notice and this permission notice
2107+ * appear in supporting documentation, and that the name of
2108+ * Novell, Inc. not be used in advertising or publicity pertaining to
2109+ * distribution of the software without specific, written prior permission.
2110+ * Novell, Inc. makes no representations about the suitability of this
2111+ * software for any purpose. It is provided "as is" without express or
2112+ * implied warranty.
2113+ *
2114+ * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
2115+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
2116+ * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
2117+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
2118+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
2119+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
2120+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2121+ *
2122+ * Author: David Reveman <davidr@novell.com>
2123+ */
2124+
2125+#include <core/windowconstrainment.h>
2126+
2127+static inline int constrainmentFloor (int value, int base)
2128+{
2129+ return (value / base) * base;
2130+}
2131+
2132+static inline uint64_t constrainment64Floor (uint64_t value, uint64_t base)
2133+{
2134+ return (value / base) * base;
2135+}
2136+
2137+static inline float constrainmentClamp(float x, float a, float b)
2138+{
2139+ return x < a ? a : (x > b ? b : x);
2140+}
2141+
2142+CompSize
2143+compiz::window::constrainment::constrainToHints (const XSizeHints &hints,
2144+ const CompSize &size,
2145+ unsigned int ignoreHints,
2146+ unsigned int resizeIgnoreHints)
2147+{
2148+ int width = size.width ();
2149+ int height = size.height ();
2150+ int min_width = 1;
2151+ int min_height = 1;
2152+ int base_width = 1;
2153+ int base_height = 1;
2154+ int xinc = 1;
2155+ int yinc = 1;
2156+ int max_width = std::numeric_limits <short>::max ();
2157+ int max_height = std::numeric_limits <short>::max ();
2158+ long flags = hints.flags & ~ignoreHints;
2159+ long resizeIncFlags = (flags & PResizeInc) ? (~resizeIgnoreHints) : 0;
2160+
2161+ /* Ater gdk_window_constrain_size(), which is partially borrowed from fvwm.
2162+ *
2163+ * Copyright 1993, Robert Nation
2164+ * You may use this code for any purpose, as long as the original
2165+ * copyright remains in the source code and all documentation
2166+ *
2167+ * which in turn borrows parts of the algorithm from uwm
2168+ */
2169+
2170+ if ((flags & PBaseSize) && (flags & PMinSize))
2171+ {
2172+ base_width = std::max (1, hints.base_width);
2173+ base_height = std::max (1, hints.base_height);
2174+ min_width = std::max (1, hints.min_width);
2175+ min_height = std::max (1, hints.min_height);
2176+ }
2177+ else if (flags & PBaseSize)
2178+ {
2179+ base_width = std::max (1, hints.base_width);
2180+ base_height = std::max (1, hints.base_height);
2181+ min_width = std::max (1, hints.base_width);
2182+ min_height = std::max (1, hints.base_height);
2183+ }
2184+ else if (flags & PMinSize)
2185+ {
2186+ base_width = std::max (1, hints.min_width);
2187+ base_height = std::max (1, hints.min_height);
2188+ min_width = std::max (1, hints.min_width);
2189+ min_height = std::max (1, hints.min_height);
2190+ }
2191+
2192+ if (flags & PMaxSize)
2193+ {
2194+ max_width = std::max (1, hints.max_width);
2195+ max_height = std::max (1, hints.max_height);
2196+ }
2197+
2198+ if (resizeIncFlags & PHorzResizeInc)
2199+ xinc = std::max (xinc, hints.width_inc);
2200+
2201+ if (resizeIncFlags & PVertResizeInc)
2202+ yinc = std::max (yinc, hints.height_inc);
2203+
2204+ /* clamp width and height to min and max values */
2205+ width = constrainmentClamp (width, min_width, max_width);
2206+ height = constrainmentClamp (height, min_height, max_height);
2207+
2208+ /* shrink to base + N * inc */
2209+ width = base_width + constrainmentFloor (width - base_width, xinc);
2210+ height = base_height + constrainmentFloor (height - base_height, yinc);
2211+
2212+ /* constrain aspect ratio, according to:
2213+ *
2214+ * min_aspect.x width max_aspect.x
2215+ * ------------ <= -------- <= -----------
2216+ * min_aspect.y height max_aspect.y
2217+ */
2218+ if ((flags & PAspect) && hints.min_aspect.y > 0 && hints.max_aspect.x > 0)
2219+ {
2220+ /* Use 64 bit arithmetic to prevent overflow */
2221+
2222+ uint64_t min_aspect_x = hints.min_aspect.x;
2223+ uint64_t min_aspect_y = hints.min_aspect.y;
2224+ uint64_t max_aspect_x = hints.max_aspect.x;
2225+ uint64_t max_aspect_y = hints.max_aspect.y;
2226+ uint64_t delta;
2227+
2228+ if (min_aspect_x * height > width * min_aspect_y)
2229+ {
2230+ delta = constrainment64Floor (height - width * min_aspect_y / min_aspect_x,
2231+ yinc);
2232+ if (height - (int) delta >= min_height)
2233+ height -= delta;
2234+ else
2235+ {
2236+ delta = constrainment64Floor (height * min_aspect_x / min_aspect_y - width,
2237+ xinc);
2238+ if (width + (int) delta <= max_width)
2239+ width += delta;
2240+ }
2241+ }
2242+
2243+ if (width * max_aspect_y > max_aspect_x * height)
2244+ {
2245+ delta = constrainment64Floor (width - height * max_aspect_x / max_aspect_y,
2246+ xinc);
2247+ if (width - (int) delta >= min_width)
2248+ width -= delta;
2249+ else
2250+ {
2251+ delta = constrainment64Floor (width * min_aspect_y / min_aspect_x - height,
2252+ yinc);
2253+ if (height + (int) delta <= max_height)
2254+ height += delta;
2255+ }
2256+ }
2257+ }
2258+
2259+ return CompSize (width, height);
2260+}
2261
2262=== added directory 'src/window/constrainment/tests'
2263=== added file 'src/window/constrainment/tests/CMakeLists.txt'
2264--- src/window/constrainment/tests/CMakeLists.txt 1970-01-01 00:00:00 +0000
2265+++ src/window/constrainment/tests/CMakeLists.txt 2012-01-13 13:20:03 +0000
2266@@ -0,0 +1,19 @@
2267+include_directories(${CMAKE_CURRENT_SOURCE_DIR})
2268+
2269+add_library (compiz_window_constrainment_test
2270+ ${CMAKE_CURRENT_SOURCE_DIR}/test-window-constrainment.cpp)
2271+
2272+add_executable (compiz_test_window_constrainment_to_hints
2273+ ${CMAKE_CURRENT_SOURCE_DIR}/to-hints/src/test-window-constrainment-to-hints.cpp
2274+ ${compiz_SOURCE_DIR}/src/size.cpp)
2275+
2276+target_link_libraries (compiz_test_window_constrainment_to_hints
2277+ compiz_window_constrainment_test
2278+ compiz_window_constrainment
2279+ ${GTEST_BOTH_LIBRARIES}
2280+ ${GMOCK_LIBRARY}
2281+ ${GMOCK_MAIN_LIBRARY}
2282+ ${CMAKE_THREAD_LIBS_INIT} # Link in pthread.
2283+ )
2284+
2285+add_test (compiz_window_constrainment_to_hints compiz_test_window_constrainment_to_hints)
2286
2287=== added file 'src/window/constrainment/tests/test-window-constrainment.cpp'
2288--- src/window/constrainment/tests/test-window-constrainment.cpp 1970-01-01 00:00:00 +0000
2289+++ src/window/constrainment/tests/test-window-constrainment.cpp 2012-01-13 13:20:03 +0000
2290@@ -0,0 +1,34 @@
2291+/*
2292+ * Copyright © 2011 Canonical Ltd.
2293+ *
2294+ * Permission to use, copy, modify, distribute, and sell this software
2295+ * and its documentation for any purpose is hereby granted without
2296+ * fee, provided that the above copyright notice appear in all copies
2297+ * and that both that copyright notice and this permission notice
2298+ * appear in supporting documentation, and that the name of
2299+ * Canonical Ltd. not be used in advertising or publicity pertaining to
2300+ * distribution of the software without specific, written prior permission.
2301+ * Canonical Ltd. makes no representations about the suitability of this
2302+ * software for any purpose. It is provided "as is" without express or
2303+ * implied warranty.
2304+ *
2305+ * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
2306+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
2307+ * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
2308+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
2309+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
2310+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
2311+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2312+ *
2313+ * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
2314+ */
2315+
2316+#include "test-window-constrainment.h"
2317+
2318+CompWindowConstrainmentTest::CompWindowConstrainmentTest ()
2319+{
2320+}
2321+
2322+CompWindowConstrainmentTest::~CompWindowConstrainmentTest ()
2323+{
2324+}
2325
2326=== added file 'src/window/constrainment/tests/test-window-constrainment.h'
2327--- src/window/constrainment/tests/test-window-constrainment.h 1970-01-01 00:00:00 +0000
2328+++ src/window/constrainment/tests/test-window-constrainment.h 2012-01-13 13:20:03 +0000
2329@@ -0,0 +1,43 @@
2330+/*
2331+ * Copyright © 2011 Canonical Ltd.
2332+ *
2333+ * Permission to use, copy, modify, distribute, and sell this software
2334+ * and its documentation for any purpose is hereby granted without
2335+ * fee, provided that the above copyright notice appear in all copies
2336+ * and that both that copyright notice and this permission notice
2337+ * appear in supporting documentation, and that the name of
2338+ * Canonical Ltd. not be used in advertising or publicity pertaining to
2339+ * distribution of the software without specific, written prior permission.
2340+ * Canonical Ltd. makes no representations about the suitability of this
2341+ * software for any purpose. It is provided "as is" without express or
2342+ * implied warranty.
2343+ *
2344+ * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
2345+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
2346+ * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
2347+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
2348+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
2349+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
2350+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2351+ *
2352+ * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
2353+ */
2354+
2355+#ifndef _COMPIZ_TEST_WINDOW_CONSTRAINMENT_H
2356+#define _COMPIZ_TEST_WINDOW_CONSTRAINMENT_H
2357+
2358+#include <gtest/gtest.h>
2359+#include <core/windowconstrainment.h>
2360+#include <core/windowgeometry.h>
2361+#include <iostream>
2362+#include <boost/bind.hpp>
2363+
2364+class CompWindowConstrainmentTest : public ::testing::Test
2365+{
2366+public:
2367+
2368+ CompWindowConstrainmentTest ();
2369+ virtual ~CompWindowConstrainmentTest ();
2370+};
2371+
2372+#endif
2373
2374=== added directory 'src/window/constrainment/tests/to-hints'
2375=== added directory 'src/window/constrainment/tests/to-hints/src'
2376=== added file 'src/window/constrainment/tests/to-hints/src/test-window-constrainment-to-hints.cpp'
2377--- src/window/constrainment/tests/to-hints/src/test-window-constrainment-to-hints.cpp 1970-01-01 00:00:00 +0000
2378+++ src/window/constrainment/tests/to-hints/src/test-window-constrainment-to-hints.cpp 2012-01-13 13:20:03 +0000
2379@@ -0,0 +1,210 @@
2380+/*
2381+ * Copyright © 2011 Canonical Ltd.
2382+ *
2383+ * Permission to use, copy, modify, distribute, and sell this software
2384+ * and its documentation for any purpose is hereby granted without
2385+ * fee, provided that the above copyright notice appear in all copies
2386+ * and that both that copyright notice and this permission notice
2387+ * appear in supporting documentation, and that the name of
2388+ * Canonical Ltd. not be used in advertising or publicity pertaining to
2389+ * distribution of the software without specific, written prior permission.
2390+ * Canonical Ltd. makes no representations about the suitability of this
2391+ * software for any purpose. It is provided "as is" without express or
2392+ * implied warranty.
2393+ *
2394+ * CANONICAL, LTD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
2395+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
2396+ * NO EVENT SHALL CANONICAL, LTD. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
2397+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
2398+ * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
2399+ * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
2400+ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2401+ *
2402+ * Authored by: Sam Spilsbury <sam.spilsbury@canonical.com>
2403+ */
2404+
2405+#include "test-window-constrainment.h"
2406+#include <cstring>
2407+
2408+class CompWindowConstrainmentTestToHints :
2409+ public CompWindowConstrainmentTest
2410+{
2411+public:
2412+
2413+ CompWindowConstrainmentTestToHints ();
2414+ virtual ~CompWindowConstrainmentTestToHints ();
2415+};
2416+
2417+CompWindowConstrainmentTestToHints::CompWindowConstrainmentTestToHints ()
2418+{
2419+}
2420+
2421+CompWindowConstrainmentTestToHints::~CompWindowConstrainmentTestToHints ()
2422+{
2423+}
2424+
2425+TEST_F (CompWindowConstrainmentTestToHints, ToHints)
2426+{
2427+ /* No hints, size is the same */
2428+ XSizeHints hints;
2429+ CompSize size (1000, 1000);
2430+
2431+ memset (&hints, 0, sizeof (XSizeHints));
2432+
2433+ size = compiz::window::constrainment::constrainToHints (hints, size, 0, 0);
2434+
2435+ EXPECT_EQ (size, CompSize (1000, 1000));
2436+
2437+ /* Minimum size specified, constrain to minimum size */
2438+ size = CompSize (100, 100);
2439+ memset (&hints, 0, sizeof (XSizeHints));
2440+
2441+ hints.flags |= PMinSize;
2442+ hints.min_width = 500;
2443+ hints.min_height = 500;
2444+
2445+ size = compiz::window::constrainment::constrainToHints (hints, size, 0, 0);
2446+
2447+ EXPECT_EQ (size, CompSize (500, 500));
2448+
2449+ /* Base size specified, constrain to base size as minimum size */
2450+ size = CompSize (100, 100);
2451+ memset (&hints, 0, sizeof (XSizeHints));
2452+
2453+ hints.flags |= PBaseSize;
2454+ hints.base_width = 500;
2455+ hints.base_height = 500;
2456+
2457+ size = compiz::window::constrainment::constrainToHints (hints, size, 0, 0);
2458+
2459+ EXPECT_EQ (size, CompSize (500, 500));
2460+
2461+ /* Minimum and base size specified, constrain to min size as minimum size */
2462+ size = CompSize (100, 100);
2463+ memset (&hints, 0, sizeof (XSizeHints));
2464+
2465+ hints.flags |= PBaseSize | PMinSize;
2466+ hints.base_width = 700;
2467+ hints.base_height = 700;
2468+ hints.min_width = 500;
2469+ hints.min_height = 500;
2470+
2471+ size = compiz::window::constrainment::constrainToHints (hints, size, 0, 0);
2472+
2473+ EXPECT_EQ (size, CompSize (500, 500));
2474+
2475+ /* Maximum size specified, constrain to minimum size */
2476+ size = CompSize (1000, 1000);
2477+ memset (&hints, 0, sizeof (XSizeHints));
2478+
2479+ hints.flags |= PMaxSize;
2480+ hints.max_width = 500;
2481+ hints.max_height = 500;
2482+
2483+ size = compiz::window::constrainment::constrainToHints (hints, size, 0, 0);
2484+
2485+ EXPECT_EQ (size, CompSize (500, 500));
2486+
2487+ /* Resize flags specified, constrain to closest low step of
2488+ * increments for size specified */
2489+ size = CompSize (1002, 1002);
2490+ memset (&hints, 0, sizeof (XSizeHints));
2491+
2492+ hints.flags |= PBaseSize | PResizeInc;
2493+ hints.base_width = 500;
2494+ hints.base_height = 500;
2495+ hints.width_inc = 5;
2496+ hints.height_inc = 5;
2497+
2498+ size = compiz::window::constrainment::constrainToHints (hints, size, 0, 0);
2499+
2500+ EXPECT_EQ (size, CompSize (1000, 1000));
2501+
2502+ /* Resize flags specified, constrain to closest low step of
2503+ * increments for size specified */
2504+ size = CompSize (1004, 1004);
2505+ memset (&hints, 0, sizeof (XSizeHints));
2506+
2507+ hints.flags |= PBaseSize | PResizeInc;
2508+ hints.base_width = 500;
2509+ hints.base_height = 500;
2510+ hints.width_inc = 5;
2511+ hints.height_inc = 5;
2512+
2513+ size = compiz::window::constrainment::constrainToHints (hints, size, 0, 0);
2514+
2515+ EXPECT_EQ (size, CompSize (1000, 1000));
2516+
2517+ /* Resize flags specified, constrain to closest low step of
2518+ * increments for size specified */
2519+ size = CompSize (1006, 1006);
2520+ memset (&hints, 0, sizeof (XSizeHints));
2521+
2522+ hints.flags |= PBaseSize | PResizeInc;
2523+ hints.base_width = 500;
2524+ hints.base_height = 500;
2525+ hints.width_inc = 5;
2526+ hints.height_inc = 5;
2527+
2528+ size = compiz::window::constrainment::constrainToHints (hints, size, 0, 0);
2529+
2530+ EXPECT_EQ (size, CompSize (1005, 1005));
2531+
2532+ /* Don't require constrainment on width */
2533+ size = CompSize (1002, 1002);
2534+ memset (&hints, 0, sizeof (XSizeHints));
2535+
2536+ hints.flags |= PBaseSize | PResizeInc;
2537+ hints.base_width = 500;
2538+ hints.base_height = 500;
2539+ hints.width_inc = 5;
2540+ hints.height_inc = 5;
2541+
2542+ size = compiz::window::constrainment::constrainToHints (hints, size, 0, compiz::window::constrainment::PHorzResizeInc);
2543+
2544+ EXPECT_EQ (size, CompSize (1002, 1000));
2545+
2546+ /* Don't require constrainment on height */
2547+ size = CompSize (1002, 1002);
2548+ memset (&hints, 0, sizeof (XSizeHints));
2549+
2550+ hints.flags |= PBaseSize | PResizeInc;
2551+ hints.base_width = 500;
2552+ hints.base_height = 500;
2553+ hints.width_inc = 5;
2554+ hints.height_inc = 5;
2555+
2556+ size = compiz::window::constrainment::constrainToHints (hints, size, 0, compiz::window::constrainment::PVertResizeInc);
2557+
2558+ EXPECT_EQ (size, CompSize (1000, 1002));
2559+
2560+ /* Aspect ratios - don't allow sizes less than 1:2 or more than 2:5
2561+ * clamping to the largest size */
2562+ size = CompSize (4000, 5000);
2563+ memset (&hints, 0, sizeof (XSizeHints));
2564+
2565+ hints.flags |= PAspect;
2566+ hints.min_aspect.x = 1;
2567+ hints.min_aspect.y = 2;
2568+ hints.max_aspect.x = 2;
2569+ hints.max_aspect.y = 5;
2570+
2571+ size = compiz::window::constrainment::constrainToHints (hints, size, 0, 0);
2572+
2573+ EXPECT_EQ (size, CompSize (2000, 5000));
2574+
2575+ /* Aspect ratios - don't allow sizes less than 1:2 or more than 2:5
2576+ * clamping to the largest size */
2577+ size = CompSize (12, 20);
2578+ memset (&hints, 0, sizeof (XSizeHints));
2579+
2580+ hints.flags |= PAspect;
2581+ hints.min_aspect.x = 1;
2582+ hints.min_aspect.y = 2;
2583+ hints.max_aspect.x = 2;
2584+ hints.max_aspect.y = 5;
2585+
2586+ size = compiz::window::constrainment::constrainToHints (hints, size, 0, 0);
2587+
2588+ EXPECT_EQ (size, CompSize (8, 20));
2589+}
2590
2591=== modified file 'src/window/extents/CMakeLists.txt'
2592--- src/window/extents/CMakeLists.txt 2012-01-13 13:20:02 +0000
2593+++ src/window/extents/CMakeLists.txt 2012-01-13 13:20:03 +0000
2594@@ -47,6 +47,7 @@
2595 SET_TARGET_PROPERTIES(
2596 compiz_window_extents PROPERTIES
2597 PUBLIC_HEADER "${PUBLIC_HEADERS}"
2598+ COMPILE_FLAGS "-fPIC"
2599 )
2600
2601 INSTALL(
2602
2603=== modified file 'src/window/geometry-saver/CMakeLists.txt'
2604--- src/window/geometry-saver/CMakeLists.txt 2012-01-13 13:20:02 +0000
2605+++ src/window/geometry-saver/CMakeLists.txt 2012-01-13 13:20:03 +0000
2606@@ -49,6 +49,7 @@
2607 SET_TARGET_PROPERTIES(
2608 compiz_window_geometry_saver PROPERTIES
2609 PUBLIC_HEADER "${PUBLIC_HEADERS}"
2610+ COMPILE_FLAGS "-fPIC"
2611 )
2612
2613 INSTALL(
2614
2615=== modified file 'src/window/geometry/CMakeLists.txt'
2616--- src/window/geometry/CMakeLists.txt 2012-01-13 13:20:02 +0000
2617+++ src/window/geometry/CMakeLists.txt 2012-01-13 13:20:03 +0000
2618@@ -47,6 +47,7 @@
2619 SET_TARGET_PROPERTIES(
2620 compiz_window_geometry PROPERTIES
2621 PUBLIC_HEADER "${PUBLIC_HEADERS}"
2622+ COMPILE_FLAGS "-fPIC"
2623 )
2624
2625 INSTALL(

Subscribers

People subscribed via source and target branches