]>
Dogcows Code - chaz/openbox/blob - openbox/resist.c
6 #include "parser/parse.h"
10 void resist_move_windows(ObClient
*c
, gint
*x
, gint
*y
)
13 gint l
, t
, r
, b
; /* requested edges */
14 gint cl
, ct
, cr
, cb
; /* current edges */
15 gint w
, h
; /* current size */
16 ObClient
*snapx
= NULL
, *snapy
= NULL
;
18 w
= c
->frame
->area
.width
;
19 h
= c
->frame
->area
.height
;
26 cl
= RECT_LEFT(c
->frame
->area
);
27 ct
= RECT_TOP(c
->frame
->area
);
28 cr
= RECT_RIGHT(c
->frame
->area
);
29 cb
= RECT_BOTTOM(c
->frame
->area
);
31 if (config_resist_win
)
32 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
34 int tl
, tt
, tr
, tb
; /* 1 past the target's edges on each side */
36 if (!WINDOW_IS_CLIENT(it
->data
))
39 /* don't snap to self or non-visibles */
40 if (!target
->frame
->visible
|| target
== c
) continue;
42 tl
= RECT_LEFT(target
->frame
->area
) - 1;
43 tt
= RECT_TOP(target
->frame
->area
) - 1;
44 tr
= RECT_RIGHT(target
->frame
->area
)+ 2;
45 tb
= RECT_BOTTOM(target
->frame
->area
) + 2;
47 /* snapx and snapy ensure that the window snaps to the top-most
48 window edge available, without going all the way from
49 bottom-to-top in the stacking list
52 if (ct
< tb
&& cb
> tt
) {
53 if (cl
>= tr
&& l
< tr
&& l
>= tr
- config_resist_win
)
54 *x
= tr
, snapx
= target
;
55 else if (cr
<= tl
&& r
> tl
&&
56 r
<= tl
+ config_resist_win
)
57 *x
= tl
- w
+ 1, snapx
= target
;
59 /* try to corner snap to the window */
60 if (ct
> tt
&& t
<= tt
&&
61 t
> tt
- config_resist_win
)
62 *y
= tt
+ 1, snapy
= target
;
63 else if (cb
< tb
&& b
>= tb
&&
64 b
< tb
+ config_resist_win
)
65 *y
= tb
- h
, snapy
= target
;
70 if (cl
< tr
&& cr
> tl
) {
71 if (ct
>= tb
&& t
< tb
&& t
>= tb
- config_resist_win
)
72 *y
= tb
, snapy
= target
;
73 else if (cb
<= tt
&& b
> tt
&&
74 b
<= tt
+ config_resist_win
)
75 *y
= tt
- h
+ 1, snapy
= target
;
77 /* try to corner snap to the window */
78 if (cl
> tl
&& l
<= tl
&&
79 l
> tl
- config_resist_win
)
80 *x
= tl
+ 1, snapx
= target
;
81 else if (cr
< tr
&& r
>= tr
&&
82 r
< tr
+ config_resist_win
)
83 *x
= tr
- w
, snapx
= target
;
88 if (snapx
&& snapy
) break;
92 void resist_move_monitors(ObClient
*c
, gint
*x
, gint
*y
)
96 gint l
, t
, r
, b
; /* requested edges */
97 gint al
, at
, ar
, ab
; /* screen area edges */
98 gint cl
, ct
, cr
, cb
; /* current edges */
99 gint w
, h
; /* current size */
101 w
= c
->frame
->area
.width
;
102 h
= c
->frame
->area
.height
;
109 cl
= RECT_LEFT(c
->frame
->area
);
110 ct
= RECT_TOP(c
->frame
->area
);
111 cr
= RECT_RIGHT(c
->frame
->area
);
112 cb
= RECT_BOTTOM(c
->frame
->area
);
114 if (config_resist_edge
) {
115 for (i
= 0; i
< screen_num_monitors
; ++i
) {
116 area
= screen_area_monitor(c
->desktop
, i
);
118 if (!RECT_INTERSECTS_RECT(*area
, c
->frame
->area
))
121 al
= RECT_LEFT(*area
);
122 at
= RECT_TOP(*area
);
123 ar
= RECT_RIGHT(*area
);
124 ab
= RECT_BOTTOM(*area
);
126 if (cl
>= al
&& l
< al
&& l
>= al
- config_resist_edge
)
128 else if (cr
<= ar
&& r
> ar
&& r
<= ar
+ config_resist_edge
)
130 if (ct
>= at
&& t
< at
&& t
>= at
- config_resist_edge
)
132 else if (cb
<= ab
&& b
> ab
&& b
< ab
+ config_resist_edge
)
138 void resist_size_windows(ObClient
*c
, gint
*w
, gint
*h
, ObCorner corn
)
141 ObClient
*target
; /* target */
142 gint l
, t
, r
, b
; /* my left, top, right and bottom sides */
143 gint dlt
, drb
; /* my destination left/top and right/bottom sides */
144 gint tl
, tt
, tr
, tb
; /* target's left, top, right and bottom bottom sides*/
146 ObClient
*snapx
= NULL
, *snapy
= NULL
;
148 incw
= c
->size_inc
.width
;
149 inch
= c
->size_inc
.height
;
151 l
= RECT_LEFT(c
->frame
->area
);
152 r
= RECT_RIGHT(c
->frame
->area
);
153 t
= RECT_TOP(c
->frame
->area
);
154 b
= RECT_BOTTOM(c
->frame
->area
);
156 if (config_resist_win
) {
157 for (it
= stacking_list
; it
!= NULL
; it
= it
->next
) {
158 if (!WINDOW_IS_CLIENT(it
->data
))
162 /* don't snap to invisibles or ourself */
163 if (!target
->frame
->visible
|| target
== c
) continue;
165 tl
= RECT_LEFT(target
->frame
->area
);
166 tr
= RECT_RIGHT(target
->frame
->area
);
167 tt
= RECT_TOP(target
->frame
->area
);
168 tb
= RECT_BOTTOM(target
->frame
->area
);
171 /* horizontal snapping */
172 if (t
< tb
&& b
> tt
) {
174 case OB_CORNER_TOPLEFT
:
175 case OB_CORNER_BOTTOMLEFT
:
177 drb
= r
+ *w
- c
->frame
->area
.width
;
178 if (r
< tl
&& drb
>= tl
&&
179 drb
< tl
+ config_resist_win
)
180 *w
= tl
- l
, snapx
= target
;
182 case OB_CORNER_TOPRIGHT
:
183 case OB_CORNER_BOTTOMRIGHT
:
184 dlt
= l
- *w
+ c
->frame
->area
.width
;
186 if (l
> tr
&& dlt
<= tr
&&
187 dlt
> tr
- config_resist_win
)
188 *w
= r
- tr
, snapx
= target
;
195 /* vertical snapping */
196 if (l
< tr
&& r
> tl
) {
198 case OB_CORNER_TOPLEFT
:
199 case OB_CORNER_TOPRIGHT
:
201 drb
= b
+ *h
- c
->frame
->area
.height
;
202 if (b
< tt
&& drb
>= tt
&&
203 drb
< tt
+ config_resist_win
)
204 *h
= tt
- t
, snapy
= target
;
206 case OB_CORNER_BOTTOMLEFT
:
207 case OB_CORNER_BOTTOMRIGHT
:
208 dlt
= t
- *h
+ c
->frame
->area
.height
;
210 if (t
> tb
&& dlt
<= tb
&&
211 dlt
> tb
- config_resist_win
)
212 *h
= b
- tb
, snapy
= target
;
218 /* snapped both ways */
219 if (snapx
&& snapy
) break;
224 void resist_size_monitors(ObClient
*c
, gint
*w
, gint
*h
, ObCorner corn
)
226 gint l
, t
, r
, b
; /* my left, top, right and bottom sides */
227 gint dlt
, drb
; /* my destination left/top and right/bottom sides */
229 gint al
, at
, ar
, ab
; /* screen boundaries */
232 l
= RECT_LEFT(c
->frame
->area
);
233 r
= RECT_RIGHT(c
->frame
->area
);
234 t
= RECT_TOP(c
->frame
->area
);
235 b
= RECT_BOTTOM(c
->frame
->area
);
237 incw
= c
->size_inc
.width
;
238 inch
= c
->size_inc
.height
;
240 /* get the screen boundaries */
241 area
= screen_area(c
->desktop
);
242 al
= RECT_LEFT(*area
);
243 at
= RECT_TOP(*area
);
244 ar
= RECT_RIGHT(*area
);
245 ab
= RECT_BOTTOM(*area
);
247 if (config_resist_edge
) {
248 /* horizontal snapping */
250 case OB_CORNER_TOPLEFT
:
251 case OB_CORNER_BOTTOMLEFT
:
253 drb
= r
+ *w
- c
->frame
->area
.width
;
254 if (r
<= ar
&& drb
> ar
&& drb
<= ar
+ config_resist_edge
)
257 case OB_CORNER_TOPRIGHT
:
258 case OB_CORNER_BOTTOMRIGHT
:
259 dlt
= l
- *w
+ c
->frame
->area
.width
;
261 if (l
>= al
&& dlt
< al
&& dlt
>= al
- config_resist_edge
)
266 /* vertical snapping */
268 case OB_CORNER_TOPLEFT
:
269 case OB_CORNER_TOPRIGHT
:
271 drb
= b
+ *h
- c
->frame
->area
.height
;
272 if (b
<= ab
&& drb
> ab
&& drb
<= ab
+ config_resist_edge
)
275 case OB_CORNER_BOTTOMLEFT
:
276 case OB_CORNER_BOTTOMRIGHT
:
277 dlt
= t
- *h
+ c
->frame
->area
.height
;
279 if (t
>= at
&& dlt
< at
&& dlt
>= at
- config_resist_edge
)
This page took 0.050839 seconds and 4 git commands to generate.