7 #include "parser/parse.h"
11 void resist_move(ObClient *c, gint *x, gint *y)
16 gint l, t, r, b; /* requested edges */
17 gint al, at, ar, ab; /* screen area edges */
18 gint cl, ct, cr, cb; /* current edges */
19 gint w, h; /* current size */
20 ObClient *snapx = NULL, *snapy = NULL;
22 w = c->frame->area.width;
23 h = c->frame->area.height;
30 cl = c->frame->area.x;
31 ct = c->frame->area.y;
32 cr = cl + c->frame->area.width - 1;
33 cb = ct + c->frame->area.height - 1;
35 /* snap to other clients */
36 if (config_resist_win)
37 for (it = stacking_list; it != NULL; it = it->next) {
39 int tl, tt, tr, tb; /* 1 past the target's edges on each side */
41 if (!WINDOW_IS_CLIENT(it->data))
44 /* don't snap to self or non-visibles */
45 if (!target->frame->visible || target == c) continue;
47 tl = target->frame->area.x - 1;
48 tt = target->frame->area.y - 1;
49 tr = tl + target->frame->area.width + 1;
50 tb = tt + target->frame->area.height + 1;
52 /* snapx and snapy ensure that the window snaps to the top-most
53 window edge available, without going all the way from
54 bottom-to-top in the stacking list
57 if (ct < tb && cb > tt) {
58 if (cl >= tr && l < tr && l >= tr - config_resist_win)
59 *x = tr, snapx = target;
60 else if (cr <= tl && r > tl &&
61 r <= tl + config_resist_win)
62 *x = tl - w + 1, snapx = target;
64 /* try to corner snap to the window */
65 if (ct > tt && t <= tt &&
66 t > tt - config_resist_win)
67 *y = tt + 1, snapy = target;
68 else if (cb < tb && b >= tb &&
69 b < tb + config_resist_win)
70 *y = tb - h, snapy = target;
75 if (cl < tr && cr > tl) {
76 if (ct >= tb && t < tb && t >= tb - config_resist_win)
77 *y = tb, snapy = target;
78 else if (cb <= tt && b > tt &&
79 b <= tt + config_resist_win)
80 *y = tt - h + 1, snapy = target;
82 /* try to corner snap to the window */
83 if (cl > tl && l <= tl &&
84 l > tl - config_resist_win)
85 *x = tl + 1, snapx = target;
86 else if (cr < tr && r >= tr &&
87 r < tr + config_resist_win)
88 *x = tr - w, snapx = target;
93 if (snapx && snapy) break;
96 /* get the screen boundaries */
97 if (config_resist_edge) {
98 for (i = 0; i < screen_num_monitors; ++i) {
99 area = screen_area_monitor(c->desktop, i);
101 if (!RECT_INTERSECTS_RECT(*area, c->frame->area))
106 ar = al + area->width - 1;
107 ab = at + area->height - 1;
109 /* snap to screen edges */
110 if (cl >= al && l < al && l >= al - config_resist_edge)
112 else if (cr <= ar && r > ar && r <= ar + config_resist_edge)
114 if (ct >= at && t < at && t >= at - config_resist_edge)
116 else if (cb <= ab && b > ab && b < ab + config_resist_edge)
122 void resist_size(ObClient *c, gint *w, gint *h, ObCorner corn)
125 ObClient *target; /* target */
126 gint l, t, r, b; /* my left, top, right and bottom sides */
127 gint dlt, drb; /* my destination left/top and right/bottom sides */
128 gint tl, tt, tr, tb; /* target's left, top, right and bottom bottom sides*/
130 gint al, at, ar, ab; /* screen boundaries */
131 ObClient *snapx = NULL, *snapy = NULL;
133 /* don't snap windows with size increments */
134 if (c->size_inc.width > 1 || c->size_inc.height > 1)
137 l = c->frame->area.x;
138 r = l + c->frame->area.width - 1;
139 t = c->frame->area.y;
140 b = t + c->frame->area.height - 1;
142 /* get the screen boundaries */
143 area = screen_area(c->desktop);
146 ar = al + area->width - 1;
147 ab = at + area->height - 1;
149 /* snap to other windows */
150 if (config_resist_win) {
151 for (it = stacking_list; it != NULL; it = it->next) {
152 if (!WINDOW_IS_CLIENT(it->data))
156 /* don't snap to invisibles or ourself */
157 if (!target->frame->visible || target == c) continue;
159 tl = target->frame->area.x;
160 tr = target->frame->area.x + target->frame->area.width - 1;
161 tt = target->frame->area.y;
162 tb = target->frame->area.y + target->frame->area.height - 1;
165 /* horizontal snapping */
166 if (t < tb && b > tt) {
168 case OB_CORNER_TOPLEFT:
169 case OB_CORNER_BOTTOMLEFT:
171 drb = r + *w - c->frame->area.width;
172 if (r < tl && drb >= tl &&
173 drb < tl + config_resist_win)
174 *w = tl - l, snapx = target;
176 case OB_CORNER_TOPRIGHT:
177 case OB_CORNER_BOTTOMRIGHT:
178 dlt = l - *w + c->frame->area.width;
180 if (l > tr && dlt <= tr &&
181 dlt > tr - config_resist_win)
182 *w = r - tr, snapx = target;
189 /* vertical snapping */
190 if (l < tr && r > tl) {
192 case OB_CORNER_TOPLEFT:
193 case OB_CORNER_TOPRIGHT:
195 drb = b + *h - c->frame->area.height;
196 if (b < tt && drb >= tt &&
197 drb < tt + config_resist_win)
198 *h = tt - t, snapy = target;
200 case OB_CORNER_BOTTOMLEFT:
201 case OB_CORNER_BOTTOMRIGHT:
202 dlt = t - *h + c->frame->area.height;
204 if (t > tb && dlt <= tb &&
205 dlt > tb - config_resist_win)
206 *h = b - tb, snapy = target;
212 /* snapped both ways */
213 if (snapx && snapy) break;
217 /* snap to screen edges */
219 if (config_resist_edge) {
220 /* horizontal snapping */
222 case OB_CORNER_TOPLEFT:
223 case OB_CORNER_BOTTOMLEFT:
225 drb = r + *w - c->frame->area.width;
226 if (r <= ar && drb > ar && drb <= ar + config_resist_edge)
229 case OB_CORNER_TOPRIGHT:
230 case OB_CORNER_BOTTOMRIGHT:
231 dlt = l - *w + c->frame->area.width;
233 if (l >= al && dlt < al && dlt >= al - config_resist_edge)
238 /* vertical snapping */
240 case OB_CORNER_TOPLEFT:
241 case OB_CORNER_TOPRIGHT:
243 drb = b + *h - c->frame->area.height;
244 if (b <= ab && drb > ab && drb <= ab + config_resist_edge)
247 case OB_CORNER_BOTTOMLEFT:
248 case OB_CORNER_BOTTOMRIGHT:
249 dlt = t - *h + c->frame->area.height;
251 if (t >= at && dlt < at && dlt >= at - config_resist_edge)