34
namespace cp = compiz::place;
35
namespace cw = compiz::window;
35
compiz::place::clampGeometryToWorkArea (compiz::window::Geometry &g,
36
const CompRect &workArea,
37
const CompWindowExtents &border,
39
const CompSize &screenSize)
38
cp::clampGeometryToWorkArea (cw::Geometry &g,
39
const CompRect &workArea,
40
const CompWindowExtents &border,
42
const CompSize &screenSize)
41
44
int x, y, left, right, bottom, top;
134
137
g.setY (g.y () + top - y);
142
cp::constrainPositionToWorkArea (CompPoint &pos,
143
const cw::Geometry &serverGeometry,
144
const CompWindowExtents &border,
145
const CompRect &workArea)
147
CompWindowExtents extents;
150
extents.left = pos.x () - border.left;
151
extents.top = pos.y () - border.top;
152
extents.right = extents.left + serverGeometry.widthIncBorders () +
155
extents.bottom = extents.top + serverGeometry.heightIncBorders () +
159
delta = workArea.right () - extents.right;
161
extents.left += delta;
163
delta = workArea.left () - extents.left;
165
extents.left += delta;
167
delta = workArea.bottom () - extents.bottom;
169
extents.top += delta;
171
delta = workArea.top () - extents.top;
173
extents.top += delta;
175
pos.setX (extents.left + border.left);
176
pos.setY (extents.top + border.top);
181
CompPoint cp::getViewportRelativeCoordinates (const cw::Geometry &geom,
182
const CompSize &screen)
185
/* left, right, top, bottom target coordinates, clamed to viewport
186
* sizes as we don't need to validate movements to other viewports;
187
* we are only interested in inner-viewport movements */
189
int x = geom.x () % screen.width ();
190
if ((geom.x2 ()) < 0)
191
x += screen.width ();
193
int y = geom.y () % screen.height ();
194
if ((geom.y2 ()) < 0)
195
y += screen.height ();
197
return CompPoint (x, y);
200
CompWindowExtents cp::getWindowEdgePositions (const CompPoint &position,
201
const cw::Geometry &geom,
202
const CompWindowExtents &border)
204
CompWindowExtents edgePositions;
206
edgePositions.left = position.x () - border.left;
207
edgePositions.right = edgePositions.left +
208
geom.widthIncBorders () + (border.left +
210
edgePositions.top = position.y () - border.top;
211
edgePositions.bottom = edgePositions.top +
212
geom.heightIncBorders () + (border.top +
215
return edgePositions;
218
void cp::clampHorizontalEdgePositionsToWorkArea (CompWindowExtents &edgePositions,
219
const CompRect &workArea)
221
if ((edgePositions.right - edgePositions.left) > workArea.width ())
223
edgePositions.left = workArea.left ();
224
edgePositions.right = workArea.right ();
228
if (edgePositions.left < workArea.left ())
230
edgePositions.right += workArea.left () - edgePositions.left;
231
edgePositions.left = workArea.left ();
234
if (edgePositions.right > workArea.right ())
236
edgePositions.left -= edgePositions.right - workArea.right ();
237
edgePositions.right = workArea.right ();
243
void cp::clampVerticalEdgePositionsToWorkArea (CompWindowExtents &edgePositions,
244
const CompRect &workArea)
246
if ((edgePositions.bottom - edgePositions.top) > workArea.height ())
248
edgePositions.top = workArea.top ();
249
edgePositions.bottom = workArea.bottom ();
253
if (edgePositions.top < workArea.top ())
255
edgePositions.bottom += workArea.top () - edgePositions.top;
256
edgePositions.top = workArea.top ();
259
if (edgePositions.bottom > workArea.bottom ())
261
edgePositions.top -= edgePositions.bottom - workArea.bottom ();
262
edgePositions.bottom = workArea.bottom ();
267
void cp::subtractBordersFromEdgePositions (CompWindowExtents &edgePositions,
268
const CompWindowExtents &border,
269
unsigned int legacyBorder)
271
const unsigned int doubleBorder = 2 * legacyBorder;
273
edgePositions.left += border.left;
274
edgePositions.right -= border.right + doubleBorder;
275
edgePositions.top += border.top;
276
edgePositions.bottom -= border.bottom + doubleBorder;
279
bool cp::onlySizeChanged (unsigned int mask)
281
return (!(mask & (CWX | CWY)) && (mask & (CWWidth | CWHeight)));
284
bool cp::applyWidthChange (const CompWindowExtents &edgePositions,
288
bool alreadySet = mask & CWWidth;
291
alreadySet = edgePositions.right - edgePositions.left == xwc.width;
295
xwc.width = edgePositions.right - edgePositions.left;
303
bool cp::applyHeightChange (const CompWindowExtents &edgePositions,
307
bool alreadySet = mask & CWHeight;
310
alreadySet = edgePositions.bottom - edgePositions.top == xwc.height;
314
xwc.height = edgePositions.bottom - edgePositions.top;