]>
Dogcows Code - chaz/openbox/blob - openbox/resist.c
1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 resist.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
25 #include "parser/parse.h"
29 void resist_move_windows(ObClient
*c
, gint resist
, gint
*x
, gint
*y
)
32 gint l
, t
, r
, b
; /* requested edges */
33 gint cl
, ct
, cr
, cb
; /* current edges */
34 gint w
, h
; /* current size */
35 ObClient
*snapx
= NULL
, *snapy
= NULL
;
39 frame_client_gravity(c
->frame
, x
, y
, c
->area
.width
, c
->area
.height
);
41 w
= c
->frame
->area
.width
;
42 h
= c
->frame
->area
.height
;
49 cl
= RECT_LEFT(c
->frame
->area
);
50 ct
= RECT_TOP(c
->frame
->area
);
51 cr
= RECT_RIGHT(c
->frame
->area
);
52 cb
= RECT_BOTTOM(c
->frame
->area
);
54 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
56 gint tl
, tt
, tr
, tb
; /* 1 past the target's edges on each side */
58 if (!WINDOW_IS_CLIENT(it
->data
))
62 /* don't snap to self or non-visibles */
63 if (!target
->frame
->visible
|| target
== c
) continue;
65 tl
= RECT_LEFT(target
->frame
->area
) - 1;
66 tt
= RECT_TOP(target
->frame
->area
) - 1;
67 tr
= RECT_RIGHT(target
->frame
->area
) + 1;
68 tb
= RECT_BOTTOM(target
->frame
->area
) + 1;
70 /* snapx and snapy ensure that the window snaps to the top-most
71 window edge available, without going all the way from
72 bottom-to-top in the stacking list
75 if (ct
< tb
&& cb
> tt
) {
76 if (cl
>= tr
&& l
< tr
&& l
>= tr
- resist
)
77 *x
= tr
, snapx
= target
;
78 else if (cr
<= tl
&& r
> tl
&&
80 *x
= tl
- w
+ 1, snapx
= target
;
82 /* try to corner snap to the window */
83 if (ct
> tt
&& t
<= tt
&&
85 *y
= tt
+ 1, snapy
= target
;
86 else if (cb
< tb
&& b
>= tb
&&
88 *y
= tb
- h
, snapy
= target
;
93 if (cl
< tr
&& cr
> tl
) {
94 if (ct
>= tb
&& t
< tb
&& t
>= tb
- resist
)
95 *y
= tb
, snapy
= target
;
96 else if (cb
<= tt
&& b
> tt
&&
98 *y
= tt
- h
+ 1, snapy
= target
;
100 /* try to corner snap to the window */
101 if (cl
> tl
&& l
<= tl
&&
103 *x
= tl
+ 1, snapx
= target
;
104 else if (cr
< tr
&& r
>= tr
&&
106 *x
= tr
- w
, snapx
= target
;
111 if (snapx
&& snapy
) break;
114 frame_frame_gravity(c
->frame
, x
, y
, c
->area
.width
, c
->area
.height
);
117 void resist_move_monitors(ObClient
*c
, gint resist
, gint
*x
, gint
*y
)
121 gint l
, t
, r
, b
; /* requested edges */
122 gint al
, at
, ar
, ab
; /* screen area edges */
123 gint pl
, pt
, pr
, pb
; /* physical screen area edges */
124 gint cl
, ct
, cr
, cb
; /* current edges */
125 gint w
, h
; /* current size */
129 frame_client_gravity(c
->frame
, x
, y
, c
->area
.width
, c
->area
.height
);
131 w
= c
->frame
->area
.width
;
132 h
= c
->frame
->area
.height
;
139 cl
= RECT_LEFT(c
->frame
->area
);
140 ct
= RECT_TOP(c
->frame
->area
);
141 cr
= RECT_RIGHT(c
->frame
->area
);
142 cb
= RECT_BOTTOM(c
->frame
->area
);
144 for (i
= 0; i
< screen_num_monitors
; ++i
) {
145 area
= screen_area_monitor(c
->desktop
, i
);
146 parea
= screen_physical_area_monitor(i
);
148 if (!RECT_INTERSECTS_RECT(*parea
, c
->frame
->area
))
151 al
= RECT_LEFT(*area
);
152 at
= RECT_TOP(*area
);
153 ar
= RECT_RIGHT(*area
);
154 ab
= RECT_BOTTOM(*area
);
155 pl
= RECT_LEFT(*parea
);
156 pt
= RECT_TOP(*parea
);
157 pr
= RECT_RIGHT(*parea
);
158 pb
= RECT_BOTTOM(*parea
);
160 if (cl
>= al
&& l
< al
&& l
>= al
- resist
)
162 else if (cr
<= ar
&& r
> ar
&& r
<= ar
+ resist
)
164 else if (cl
>= pl
&& l
< pl
&& l
>= pl
- resist
)
166 else if (cr
<= pr
&& r
> pr
&& r
<= pr
+ resist
)
169 if (ct
>= at
&& t
< at
&& t
>= at
- resist
)
171 else if (cb
<= ab
&& b
> ab
&& b
< ab
+ resist
)
173 else if (ct
>= pt
&& t
< pt
&& t
>= pt
- resist
)
175 else if (cb
<= pb
&& b
> pb
&& b
< pb
+ resist
)
179 frame_frame_gravity(c
->frame
, x
, y
, c
->area
.width
, c
->area
.height
);
182 void resist_size_windows(ObClient
*c
, gint resist
, gint
*w
, gint
*h
,
186 ObClient
*target
; /* target */
187 gint l
, t
, r
, b
; /* my left, top, right and bottom sides */
188 gint dlt
, drb
; /* my destination left/top and right/bottom sides */
189 gint tl
, tt
, tr
, tb
; /* target's left, top, right and bottom bottom sides*/
191 ObClient
*snapx
= NULL
, *snapy
= NULL
;
195 incw
= c
->size_inc
.width
;
196 inch
= c
->size_inc
.height
;
198 l
= RECT_LEFT(c
->frame
->area
);
199 r
= RECT_RIGHT(c
->frame
->area
);
200 t
= RECT_TOP(c
->frame
->area
);
201 b
= RECT_BOTTOM(c
->frame
->area
);
203 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
204 if (!WINDOW_IS_CLIENT(it
->data
))
208 /* don't snap to invisibles or ourself */
209 if (!target
->frame
->visible
|| target
== c
) continue;
211 tl
= RECT_LEFT(target
->frame
->area
);
212 tr
= RECT_RIGHT(target
->frame
->area
);
213 tt
= RECT_TOP(target
->frame
->area
);
214 tb
= RECT_BOTTOM(target
->frame
->area
);
217 /* horizontal snapping */
218 if (t
< tb
&& b
> tt
) {
220 case OB_CORNER_TOPLEFT
:
221 case OB_CORNER_BOTTOMLEFT
:
223 drb
= r
+ *w
- c
->frame
->area
.width
;
224 if (r
< tl
&& drb
>= tl
&&
226 *w
= tl
- l
, snapx
= target
;
228 case OB_CORNER_TOPRIGHT
:
229 case OB_CORNER_BOTTOMRIGHT
:
230 dlt
= l
- *w
+ c
->frame
->area
.width
;
232 if (l
> tr
&& dlt
<= tr
&&
234 *w
= r
- tr
, snapx
= target
;
241 /* vertical snapping */
242 if (l
< tr
&& r
> tl
) {
244 case OB_CORNER_TOPLEFT
:
245 case OB_CORNER_TOPRIGHT
:
247 drb
= b
+ *h
- c
->frame
->area
.height
;
248 if (b
< tt
&& drb
>= tt
&&
250 *h
= tt
- t
, snapy
= target
;
252 case OB_CORNER_BOTTOMLEFT
:
253 case OB_CORNER_BOTTOMRIGHT
:
254 dlt
= t
- *h
+ c
->frame
->area
.height
;
256 if (t
> tb
&& dlt
<= tb
&&
258 *h
= b
- tb
, snapy
= target
;
264 /* snapped both ways */
265 if (snapx
&& snapy
) break;
269 void resist_size_monitors(ObClient
*c
, gint resist
, gint
*w
, gint
*h
,
272 gint l
, t
, r
, b
; /* my left, top, right and bottom sides */
273 gint dlt
, drb
; /* my destination left/top and right/bottom sides */
275 gint al
, at
, ar
, ab
; /* screen boundaries */
276 gint pl
, pt
, pr
, pb
; /* physical screen boundaries */
282 l
= RECT_LEFT(c
->frame
->area
);
283 r
= RECT_RIGHT(c
->frame
->area
);
284 t
= RECT_TOP(c
->frame
->area
);
285 b
= RECT_BOTTOM(c
->frame
->area
);
287 incw
= c
->size_inc
.width
;
288 inch
= c
->size_inc
.height
;
290 for (i
= 0; i
< screen_num_monitors
; ++i
) {
291 area
= screen_area_monitor(c
->desktop
, i
);
292 parea
= screen_physical_area_monitor(i
);
294 if (!RECT_INTERSECTS_RECT(*parea
, c
->frame
->area
))
297 /* get the screen boundaries */
298 al
= RECT_LEFT(*area
);
299 at
= RECT_TOP(*area
);
300 ar
= RECT_RIGHT(*area
);
301 ab
= RECT_BOTTOM(*area
);
302 pl
= RECT_LEFT(*parea
);
303 pt
= RECT_TOP(*parea
);
304 pr
= RECT_RIGHT(*parea
);
305 pb
= RECT_BOTTOM(*parea
);
307 /* horizontal snapping */
309 case OB_CORNER_TOPLEFT
:
310 case OB_CORNER_BOTTOMLEFT
:
312 drb
= r
+ *w
- c
->frame
->area
.width
;
313 if (r
<= ar
&& drb
> ar
&& drb
<= ar
+ resist
)
315 else if (r
<= pr
&& drb
> pr
&& drb
<= pr
+ resist
)
318 case OB_CORNER_TOPRIGHT
:
319 case OB_CORNER_BOTTOMRIGHT
:
320 dlt
= l
- *w
+ c
->frame
->area
.width
;
322 if (l
>= al
&& dlt
< al
&& dlt
>= al
- resist
)
324 else if (l
>= pl
&& dlt
< pl
&& dlt
>= pl
- resist
)
329 /* vertical snapping */
331 case OB_CORNER_TOPLEFT
:
332 case OB_CORNER_TOPRIGHT
:
334 drb
= b
+ *h
- c
->frame
->area
.height
;
335 if (b
<= ab
&& drb
> ab
&& drb
<= ab
+ resist
)
337 else if (b
<= pb
&& drb
> pb
&& drb
<= pb
+ resist
)
340 case OB_CORNER_BOTTOMLEFT
:
341 case OB_CORNER_BOTTOMRIGHT
:
342 dlt
= t
- *h
+ c
->frame
->area
.height
;
344 if (t
>= at
&& dlt
< at
&& dlt
>= at
- resist
)
346 else if (t
>= pt
&& dlt
< pt
&& dlt
>= pt
- resist
)
This page took 0.051034 seconds and 4 git commands to generate.