+ for (i = 0; i < screen_num_monitors; ++i) {
+ parea = screen_physical_area_monitor(i);
+
+ if (!RECT_INTERSECTS_RECT(*parea, c->frame->area))
+ continue;
+
+ area = screen_area(c->desktop, SCREEN_AREA_ALL_MONITORS,
+ &desired_area);
+
+ al = RECT_LEFT(*area);
+ at = RECT_TOP(*area);
+ ar = RECT_RIGHT(*area);
+ ab = RECT_BOTTOM(*area);
+ pl = RECT_LEFT(*parea);
+ pt = RECT_TOP(*parea);
+ pr = RECT_RIGHT(*parea);
+ pb = RECT_BOTTOM(*parea);
+
+ if (cl >= al && l < al && l >= al - resist)
+ *x = al;
+ else if (cr <= ar && r > ar && r <= ar + resist)
+ *x = ar - w + 1;
+ else if (cl >= pl && l < pl && l >= pl - resist)
+ *x = pl;
+ else if (cr <= pr && r > pr && r <= pr + resist)
+ *x = pr - w + 1;
+
+ if (ct >= at && t < at && t >= at - resist)
+ *y = at;
+ else if (cb <= ab && b > ab && b < ab + resist)
+ *y = ab - h + 1;
+ else if (ct >= pt && t < pt && t >= pt - resist)
+ *y = pt;
+ else if (cb <= pb && b > pb && b < pb + resist)
+ *y = pb - h + 1;
+
+ g_slice_free(Rect, area);
+ }
+
+ frame_frame_gravity(c->frame, x, y);
+}
+
+static gboolean resist_size_window(Rect window, Rect target, gint resist,
+ gint *w, gint *h, ObDirection dir)
+{
+ gint l, t, r, b; /* my left, top, right and bottom sides */
+ gint tl, tt, tr, tb; /* target's left, top, right and bottom bottom sides*/
+ gint dlt, drb; /* my destination left/top and right/bottom sides */
+ gboolean snapx = 0, snapy = 0;
+ gint orgw, orgh;
+
+ l = RECT_LEFT(window);
+ t = RECT_TOP(window);
+ r = RECT_RIGHT(window);
+ b = RECT_BOTTOM(window);
+
+ orgw = window.width;
+ orgh = window.height;
+
+ tl = RECT_LEFT(target);
+ tt = RECT_TOP(target);
+ tr = RECT_RIGHT(target);
+ tb = RECT_BOTTOM(target);
+
+ if (!snapx) {
+ /* horizontal snapping */
+ if (t < tb && b > tt) {
+ switch (dir) {
+ case OB_DIRECTION_EAST:
+ case OB_DIRECTION_NORTHEAST:
+ case OB_DIRECTION_SOUTHEAST:
+ case OB_DIRECTION_NORTH:
+ case OB_DIRECTION_SOUTH:
+ dlt = l;
+ drb = r + *w - orgw;
+ if (r < tl && drb >= tl &&
+ drb < tl + resist)
+ *w = tl - l, snapx = TRUE;
+ break;
+ case OB_DIRECTION_WEST:
+ case OB_DIRECTION_NORTHWEST:
+ case OB_DIRECTION_SOUTHWEST:
+ dlt = l - *w + orgw;
+ drb = r;
+ if (l > tr && dlt <= tr &&
+ dlt > tr - resist)
+ *w = r - tr, snapx = TRUE;
+ break;
+ }