]>
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
= c
->frame
->area
.x
;
27 ct
= c
->frame
->area
.y
;
28 cr
= cl
+ c
->frame
->area
.width
- 1;
29 cb
= ct
+ c
->frame
->area
.height
- 1;
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
= target
->frame
->area
.x
- 1;
43 tt
= target
->frame
->area
.y
- 1;
44 tr
= tl
+ target
->frame
->area
.width
+ 1;
45 tb
= tt
+ target
->frame
->area
.height
+ 1;
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
= c
->frame
->area
.x
;
110 ct
= c
->frame
->area
.y
;
111 cr
= cl
+ c
->frame
->area
.width
- 1;
112 cb
= ct
+ c
->frame
->area
.height
- 1;
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
))
123 ar
= al
+ area
->width
- 1;
124 ab
= at
+ area
->height
- 1;
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
= c
->frame
->area
.x
;
152 r
= l
+ c
->frame
->area
.width
- 1;
153 t
= c
->frame
->area
.y
;
154 b
= t
+ c
->frame
->area
.height
- 1;
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
= target
->frame
->area
.x
;
166 tr
= target
->frame
->area
.x
+ target
->frame
->area
.width
- 1;
167 tt
= target
->frame
->area
.y
;
168 tb
= target
->frame
->area
.y
+ target
->frame
->area
.height
- 1;
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
= c
->frame
->area
.x
;
233 r
= l
+ c
->frame
->area
.width
- 1;
234 t
= c
->frame
->area
.y
;
235 b
= t
+ c
->frame
->area
.height
- 1;
237 incw
= c
->size_inc
.width
;
238 inch
= c
->size_inc
.height
;
240 /* get the screen boundaries */
241 area
= screen_area(c
->desktop
);
244 ar
= al
+ area
->width
- 1;
245 ab
= at
+ area
->height
- 1;
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.045635 seconds and 4 git commands to generate.