6 static int resistance
= 10;
7 static gboolean edge_resistance
= TRUE
; /* window-to-edge */
8 static gboolean window_resistance
= TRUE
; /* window-to-window */
10 void snap_move(Client
*c
, int *x
, int *y
, int w
, int h
)
14 int l
, t
, r
, b
; /* requested edges */
15 int al
, at
, ar
, ab
; /* screen area edges */
16 int cl
, ct
, cr
, cb
; /* current edges */
17 gboolean snapx
= FALSE
, snapy
= FALSE
;
19 if (!edge_resistance
) return;
21 /* add the frame to the dimensions */
27 cl
= c
->frame
->area
.x
;
28 ct
= c
->frame
->area
.y
;
29 cr
= cl
+ c
->frame
->area
.width
- 1;
30 cb
= ct
+ c
->frame
->area
.height
- 1;
32 /* snap to other clients */
33 if (window_resistance
)
34 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
36 int tl
, tt
, tr
, tb
; /* 1 past the target's edges on each side */
40 tl
= target
->frame
->area
.x
- 1;
41 tt
= target
->frame
->area
.y
- 1;
42 tr
= tl
+ target
->frame
->area
.width
+ 1;
43 tb
= tt
+ target
->frame
->area
.height
+ 1;
45 /* snapx and snapy ensure that the window snaps to the top-most
46 window edge available, without going all the way from
47 bottom-to-top in the stacking list
49 if (!snapx
&& cl
>= tr
&& l
< tr
&& l
>= tr
- resistance
)
50 *x
= tr
, snapx
= TRUE
;
51 else if (!snapx
&& cr
<= tl
&& r
> tl
&& r
<= tl
+ resistance
)
52 *x
= tl
- w
+ 1, snapx
= TRUE
;
53 else if (!snapy
&& ct
>= tb
&& t
< tb
&& t
>= tb
- resistance
)
54 *y
= tb
, snapy
= TRUE
;
55 else if (!snapy
&& cb
<= tt
&& b
> tt
&& b
<= tt
+ resistance
)
56 *y
= tt
- h
+ 1, snapy
= TRUE
;
58 if (snapx
&& snapy
) break;
61 /* get the screen boundaries */
62 area
= screen_area(c
->desktop
);
65 ar
= al
+ area
->width
- 1;
66 ab
= at
+ area
->height
- 1;
68 /* snap to screen edges */
69 if (cl
>= al
&& l
< al
&& l
>= al
- resistance
)
71 else if (cr
<= ar
&& r
> ar
&& r
<= ar
+ resistance
)
73 if (ct
>= at
&& t
< at
&& t
>= at
- resistance
)
75 else if (cb
<= ab
&& b
> ab
&& b
< ab
+ resistance
)