~ubuntu-branches/ubuntu/trusty/compiz/trusty

« back to all changes in this revision

Viewing changes to plugins/place/src/constrain-to-workarea/src/constrain-to-workarea.cpp

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release
  • Date: 2013-08-22 06:58:07 UTC
  • mto: This revision was merged to the branch mainline in revision 3352.
  • Revision ID: package-import@ubuntu.com-20130822065807-17nlzez0d30y09so
Tags: upstream-0.9.10+13.10.20130822
ImportĀ upstreamĀ versionĀ 0.9.10+13.10.20130822

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
}
32
32
}
33
33
 
 
34
namespace cp = compiz::place;
 
35
namespace cw = compiz::window;
 
36
 
34
37
void
35
 
compiz::place::clampGeometryToWorkArea (compiz::window::Geometry &g,
36
 
                                        const CompRect           &workArea,
37
 
                                        const CompWindowExtents  &border,
38
 
                                        unsigned int             flags,
39
 
                                        const CompSize           &screenSize)
 
38
cp::clampGeometryToWorkArea (cw::Geometry            &g,
 
39
                             const CompRect          &workArea,
 
40
                             const CompWindowExtents &border,
 
41
                             unsigned int            flags,
 
42
                             const CompSize          &screenSize)
40
43
{
41
44
    int      x, y, left, right, bottom, top;
42
45
 
134
137
            g.setY (g.y () + top - y);
135
138
    }
136
139
}
 
140
 
 
141
CompPoint &
 
142
cp::constrainPositionToWorkArea (CompPoint               &pos,
 
143
                                 const cw::Geometry      &serverGeometry,
 
144
                                 const CompWindowExtents &border,
 
145
                                 const CompRect          &workArea)
 
146
{
 
147
    CompWindowExtents extents;
 
148
    int               delta;
 
149
 
 
150
    extents.left   = pos.x () - border.left;
 
151
    extents.top    = pos.y () - border.top;
 
152
    extents.right  = extents.left + serverGeometry.widthIncBorders () +
 
153
                     (border.left +
 
154
                      border.right);
 
155
    extents.bottom = extents.top + serverGeometry.heightIncBorders () +
 
156
                     (border.top +
 
157
                      border.bottom);
 
158
 
 
159
    delta = workArea.right () - extents.right;
 
160
    if (delta < 0)
 
161
        extents.left += delta;
 
162
 
 
163
    delta = workArea.left () - extents.left;
 
164
    if (delta > 0)
 
165
        extents.left += delta;
 
166
 
 
167
    delta = workArea.bottom () - extents.bottom;
 
168
    if (delta < 0)
 
169
        extents.top += delta;
 
170
 
 
171
    delta = workArea.top () - extents.top;
 
172
    if (delta > 0)
 
173
        extents.top += delta;
 
174
 
 
175
    pos.setX (extents.left + border.left);
 
176
    pos.setY (extents.top  + border.top);
 
177
 
 
178
    return pos;
 
179
}
 
180
 
 
181
CompPoint cp::getViewportRelativeCoordinates (const cw::Geometry &geom,
 
182
                                              const CompSize     &screen)
 
183
{
 
184
 
 
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 */
 
188
 
 
189
    int x = geom.x () % screen.width ();
 
190
    if ((geom.x2 ()) < 0)
 
191
        x += screen.width ();
 
192
 
 
193
    int y = geom.y () % screen.height ();
 
194
    if ((geom.y2 ()) < 0)
 
195
        y += screen.height ();
 
196
 
 
197
    return CompPoint (x, y);
 
198
}
 
199
 
 
200
CompWindowExtents cp::getWindowEdgePositions (const CompPoint         &position,
 
201
                                              const cw::Geometry      &geom,
 
202
                                              const CompWindowExtents &border)
 
203
{
 
204
    CompWindowExtents edgePositions;
 
205
 
 
206
    edgePositions.left   = position.x () - border.left;
 
207
    edgePositions.right  = edgePositions.left +
 
208
                           geom.widthIncBorders () +  (border.left +
 
209
                                                       border.right);
 
210
    edgePositions.top    = position.y () - border.top;
 
211
    edgePositions.bottom = edgePositions.top +
 
212
                           geom.heightIncBorders () + (border.top +
 
213
                                                       border.bottom);
 
214
 
 
215
    return edgePositions;
 
216
}
 
217
 
 
218
void cp::clampHorizontalEdgePositionsToWorkArea (CompWindowExtents &edgePositions,
 
219
                                                 const CompRect    &workArea)
 
220
{
 
221
    if ((edgePositions.right - edgePositions.left) > workArea.width ())
 
222
    {
 
223
        edgePositions.left  = workArea.left ();
 
224
        edgePositions.right = workArea.right ();
 
225
    }
 
226
    else
 
227
    {
 
228
        if (edgePositions.left < workArea.left ())
 
229
        {
 
230
            edgePositions.right += workArea.left () - edgePositions.left;
 
231
            edgePositions.left  = workArea.left ();
 
232
        }
 
233
 
 
234
        if (edgePositions.right > workArea.right ())
 
235
        {
 
236
            edgePositions.left -= edgePositions.right - workArea.right ();
 
237
            edgePositions.right = workArea.right ();
 
238
        }
 
239
    }
 
240
 
 
241
}
 
242
 
 
243
void cp::clampVerticalEdgePositionsToWorkArea (CompWindowExtents &edgePositions,
 
244
                                               const CompRect    &workArea)
 
245
{
 
246
    if ((edgePositions.bottom - edgePositions.top) > workArea.height ())
 
247
    {
 
248
        edgePositions.top    = workArea.top ();
 
249
        edgePositions.bottom = workArea.bottom ();
 
250
    }
 
251
    else
 
252
    {
 
253
        if (edgePositions.top < workArea.top ())
 
254
        {
 
255
            edgePositions.bottom += workArea.top () - edgePositions.top;
 
256
            edgePositions.top    = workArea.top ();
 
257
        }
 
258
 
 
259
        if (edgePositions.bottom > workArea.bottom ())
 
260
        {
 
261
            edgePositions.top   -= edgePositions.bottom - workArea.bottom ();
 
262
            edgePositions.bottom = workArea.bottom ();
 
263
        }
 
264
    }
 
265
}
 
266
 
 
267
void cp::subtractBordersFromEdgePositions (CompWindowExtents       &edgePositions,
 
268
                                           const CompWindowExtents &border,
 
269
                                           unsigned int            legacyBorder)
 
270
{
 
271
    const unsigned int doubleBorder = 2 * legacyBorder;
 
272
 
 
273
    edgePositions.left   += border.left;
 
274
    edgePositions.right  -= border.right + doubleBorder;
 
275
    edgePositions.top    += border.top;
 
276
    edgePositions.bottom -= border.bottom + doubleBorder;
 
277
}
 
278
 
 
279
bool cp::onlySizeChanged (unsigned int mask)
 
280
{
 
281
    return (!(mask & (CWX | CWY)) && (mask & (CWWidth | CWHeight)));
 
282
}
 
283
 
 
284
bool cp::applyWidthChange (const CompWindowExtents &edgePositions,
 
285
                           XWindowChanges          &xwc,
 
286
                           unsigned int            &mask)
 
287
{
 
288
    bool alreadySet = mask & CWWidth;
 
289
 
 
290
    if (alreadySet)
 
291
        alreadySet = edgePositions.right - edgePositions.left == xwc.width;
 
292
 
 
293
    if (!alreadySet)
 
294
    {
 
295
        xwc.width = edgePositions.right - edgePositions.left;
 
296
        mask       |= CWWidth;
 
297
        return true;
 
298
    }
 
299
 
 
300
    return false;
 
301
}
 
302
 
 
303
bool cp::applyHeightChange (const CompWindowExtents &edgePositions,
 
304
                            XWindowChanges          &xwc,
 
305
                            unsigned int            &mask)
 
306
{
 
307
    bool alreadySet = mask & CWHeight;
 
308
 
 
309
    if (alreadySet)
 
310
        alreadySet = edgePositions.bottom - edgePositions.top == xwc.height;
 
311
 
 
312
    if (!alreadySet)
 
313
    {
 
314
        xwc.height = edgePositions.bottom - edgePositions.top;
 
315
        mask        |= CWHeight;
 
316
        return true;
 
317
    }
 
318
 
 
319
    return false;
 
320
}