Merge lp:~smspillaz/compiz-core/compiz-core.use-constrainment into lp:compiz-core/0.9.5

Proposed by Sam Spilsbury
Status: Merged
Merged at revision: 2943
Proposed branch: lp:~smspillaz/compiz-core/compiz-core.use-constrainment
Merge into: lp:compiz-core/0.9.5
Diff against target: 270 lines (+36/-147)
5 files modified
cmake/CompizPlugin.cmake (+1/-0)
src/CMakeLists.txt (+7/-2)
src/window.cpp (+21/-139)
src/window/constrainment/include/core/windowconstrainment.h (+2/-2)
src/window/constrainment/src/windowconstrainment.cpp (+5/-4)
To merge this branch: bzr merge lp:~smspillaz/compiz-core/compiz-core.use-constrainment
Reviewer Review Type Date Requested Status
Alan Griffiths Approve
Review via email: mp+89552@code.launchpad.net

Description of the change

Use the tested constrainment to sizeHints path

To post a comment you must log in.
Revision history for this message
Alan Griffiths (alan-griffiths) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cmake/CompizPlugin.cmake'
2--- cmake/CompizPlugin.cmake 2012-01-12 06:48:58 +0000
3+++ cmake/CompizPlugin.cmake 2012-01-21 18:34:31 +0000
4@@ -404,6 +404,7 @@
5 ${${_PLUGIN}_PKG_LIBRARIES}
6 ${${_PLUGIN}_LIBRARIES}
7 ${${_PLUGIN}_MOD_LIBRARIES}
8+ compiz_core
9 )
10
11 install (
12
13=== modified file 'src/CMakeLists.txt'
14--- src/CMakeLists.txt 2012-01-20 15:42:52 +0000
15+++ src/CMakeLists.txt 2012-01-21 18:34:31 +0000
16@@ -77,6 +77,7 @@
17 link_directories (
18 ${COMPIZ_LINK_DIRS}
19 ${CORE_MOD_LIBRARY_DIRS}
20+ ${libdir}
21 )
22
23 add_library (compiz_core SHARED
24@@ -144,10 +145,14 @@
25
26 install (
27 TARGETS compiz_core
28+ LIBRARY DESTINATION ${COMPIZ_DESTDIR}${libdir}
29+)
30+
31+install (
32+ TARGETS compiz
33 RUNTIME DESTINATION ${COMPIZ_DESTDIR}${exec_prefix}
34- LIBRARY DESTINATION ${COMPIZ_DESTDIR}${libdir}
35- ARCHIVE DESTINATION ${COMPIZ_DESTDIR}${libdir}
36 )
37+
38 add_subdirectory(tests)
39
40 enable_coverage_report( TARGETS compiz )
41
42=== modified file 'src/window.cpp'
43--- src/window.cpp 2012-01-19 18:12:31 +0000
44+++ src/window.cpp 2012-01-21 18:34:31 +0000
45@@ -40,6 +40,7 @@
46
47 #include <core/icon.h>
48 #include <core/atoms.h>
49+#include "core/windowconstrainment.h"
50 #include "privatewindow.h"
51 #include "privatescreen.h"
52 #include "privatestackdebugger.h"
53@@ -4702,148 +4703,29 @@
54 int *newWidth,
55 int *newHeight)
56 {
57- const XSizeHints *hints = &priv->sizeHints;
58- int oldWidth = width;
59- int oldHeight = height;
60- int min_width = 0;
61- int min_height = 0;
62- int base_width = 0;
63- int base_height = 0;
64- int xinc = 1;
65- int yinc = 1;
66- int max_width = MAXSHORT;
67- int max_height = MAXSHORT;
68- long flags = hints->flags;
69- long resizeIncFlags = (flags & PResizeInc) ? ~0 : 0;
70+ CompSize size (width, height);
71+ long ignoredHints = 0;
72+ long ignoredResizeHints = 0;
73
74 if (screen->priv->optionGetIgnoreHintsWhenMaximized ())
75 {
76- if (priv->state & MAXIMIZE_STATE)
77- {
78- flags &= ~PAspect;
79-
80- if (priv->state & CompWindowStateMaximizedHorzMask)
81- resizeIncFlags &= ~PHorzResizeInc;
82-
83- if (priv->state & CompWindowStateMaximizedVertMask)
84- resizeIncFlags &= ~PVertResizeInc;
85- }
86- }
87-
88- /* Ater gdk_window_constrain_size(), which is partially borrowed from fvwm.
89- *
90- * Copyright 1993, Robert Nation
91- * You may use this code for any purpose, as long as the original
92- * copyright remains in the source code and all documentation
93- *
94- * which in turn borrows parts of the algorithm from uwm
95- */
96-
97-#define FLOOR(value, base) (((int) ((value) / (base))) * (base))
98-#define FLOOR64(value, base) (((uint64_t) ((value) / (base))) * (base))
99-
100- if ((flags & PBaseSize) && (flags & PMinSize))
101- {
102- base_width = hints->base_width;
103- base_height = hints->base_height;
104- min_width = hints->min_width;
105- min_height = hints->min_height;
106- }
107- else if (flags & PBaseSize)
108- {
109- base_width = hints->base_width;
110- base_height = hints->base_height;
111- min_width = hints->base_width;
112- min_height = hints->base_height;
113- }
114- else if (flags & PMinSize)
115- {
116- base_width = hints->min_width;
117- base_height = hints->min_height;
118- min_width = hints->min_width;
119- min_height = hints->min_height;
120- }
121-
122- if (flags & PMaxSize)
123- {
124- max_width = hints->max_width;
125- max_height = hints->max_height;
126- }
127-
128- if (resizeIncFlags & PHorzResizeInc)
129- xinc = MAX (xinc, hints->width_inc);
130-
131- if (resizeIncFlags & PVertResizeInc)
132- yinc = MAX (yinc, hints->height_inc);
133-
134- /* clamp width and height to min and max values */
135- width = CLAMP (width, min_width, max_width);
136- height = CLAMP (height, min_height, max_height);
137-
138- /* shrink to base + N * inc */
139- width = base_width + FLOOR (width - base_width, xinc);
140- height = base_height + FLOOR (height - base_height, yinc);
141-
142- /* constrain aspect ratio, according to:
143- *
144- * min_aspect.x width max_aspect.x
145- * ------------ <= -------- <= -----------
146- * min_aspect.y height max_aspect.y
147- */
148- if ((flags & PAspect) && hints->min_aspect.y > 0 && hints->max_aspect.x > 0)
149- {
150- /* Use 64 bit arithmetic to prevent overflow */
151-
152- uint64_t min_aspect_x = hints->min_aspect.x;
153- uint64_t min_aspect_y = hints->min_aspect.y;
154- uint64_t max_aspect_x = hints->max_aspect.x;
155- uint64_t max_aspect_y = hints->max_aspect.y;
156- uint64_t delta;
157-
158- if (min_aspect_x * height > width * min_aspect_y)
159- {
160- delta = FLOOR64 (height - width * min_aspect_y / min_aspect_x,
161- yinc);
162- if (height - (int) delta >= min_height)
163- height -= delta;
164- else
165- {
166- delta = FLOOR64 (height * min_aspect_x / min_aspect_y - width,
167- xinc);
168- if (width + (int) delta <= max_width)
169- width += delta;
170- }
171- }
172-
173- if (width * max_aspect_y > max_aspect_x * height)
174- {
175- delta = FLOOR64 (width - height * max_aspect_x / max_aspect_y,
176- xinc);
177- if (width - (int) delta >= min_width)
178- width -= delta;
179- else
180- {
181- delta = FLOOR64 (width * min_aspect_y / min_aspect_x - height,
182- yinc);
183- if (height + (int) delta <= max_height)
184- height += delta;
185- }
186- }
187- }
188-
189-#undef CLAMP
190-#undef FLOOR64
191-#undef FLOOR
192-
193- if (width != oldWidth || height != oldHeight)
194- {
195- *newWidth = width;
196- *newHeight = height;
197-
198- return true;
199- }
200-
201- return false;
202+ ignoredHints |= PAspect;
203+
204+ if (priv->state & CompWindowStateMaximizedHorzMask)
205+ ignoredResizeHints |= PHorzResizeInc;
206+
207+ if (priv->state & CompWindowStateMaximizedVertMask)
208+ ignoredResizeHints |= PVertResizeInc;
209+ }
210+
211+ CompSize ret = compiz::window::constrainment::constrainToHints (priv->sizeHints,
212+ size,
213+ ignoredHints, ignoredResizeHints);
214+
215+ *newWidth = ret.width ();
216+ *newHeight = ret.height ();
217+
218+ return ret != size;
219 }
220
221 void
222
223=== modified file 'src/window/constrainment/include/core/windowconstrainment.h'
224--- src/window/constrainment/include/core/windowconstrainment.h 2012-01-19 20:27:55 +0000
225+++ src/window/constrainment/include/core/windowconstrainment.h 2012-01-21 18:34:31 +0000
226@@ -47,8 +47,8 @@
227
228 CompSize constrainToHints (const XSizeHints &hints,
229 const CompSize &size,
230- unsigned int ignoreHints,
231- unsigned int resizeIgnoreHints);
232+ long ignoreHints,
233+ long resizeIgnoreHints);
234 }
235
236 }
237
238=== modified file 'src/window/constrainment/src/windowconstrainment.cpp'
239--- src/window/constrainment/src/windowconstrainment.cpp 2012-01-19 20:27:55 +0000
240+++ src/window/constrainment/src/windowconstrainment.cpp 2012-01-21 18:34:31 +0000
241@@ -24,6 +24,7 @@
242 */
243
244 #include <core/windowconstrainment.h>
245+#include <stdio.h>
246
247 static inline int constrainmentFloor (int value, int base)
248 {
249@@ -43,8 +44,8 @@
250 CompSize
251 compiz::window::constrainment::constrainToHints (const XSizeHints &hints,
252 const CompSize &size,
253- unsigned int ignoreHints,
254- unsigned int resizeIgnoreHints)
255+ long ignoreHints,
256+ long resizeIgnoreHints)
257 {
258 int width = size.width ();
259 int height = size.height ();
260@@ -56,8 +57,8 @@
261 int yinc = 1;
262 int max_width = std::numeric_limits <short>::max ();
263 int max_height = std::numeric_limits <short>::max ();
264- long flags = hints.flags & ~ignoreHints;
265- long resizeIncFlags = (flags & PResizeInc) ? (~resizeIgnoreHints) : 0;
266+ long flags = hints.flags & ~ignoreHints;
267+ long resizeIncFlags = (flags & PResizeInc) ? ((PHorzResizeInc | PVertResizeInc) & ~resizeIgnoreHints) : 0;
268
269 /* Ater gdk_window_constrain_size(), which is partially borrowed from fvwm.
270 *

Subscribers

People subscribed via source and target branches