]>
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 */
130 frame_client_gravity(c
->frame
, x
, y
, c
->area
.width
, c
->area
.height
);
132 w
= c
->frame
->area
.width
;
133 h
= c
->frame
->area
.height
;
140 cl
= RECT_LEFT(c
->frame
->area
);
141 ct
= RECT_TOP(c
->frame
->area
);
142 cr
= RECT_RIGHT(c
->frame
->area
);
143 cb
= RECT_BOTTOM(c
->frame
->area
);
145 RECT_SET(desired_area
, *x
, *y
, c
->area
.width
, c
->area
.height
);
147 for (i
= 0; i
< screen_num_monitors
; ++i
) {
148 parea
= screen_physical_area_monitor(i
);
150 if (!RECT_INTERSECTS_RECT(*parea
, c
->frame
->area
)) {
155 area
= screen_area(c
->desktop
, SCREEN_AREA_ALL_MONITORS
,
158 al
= RECT_LEFT(*area
);
159 at
= RECT_TOP(*area
);
160 ar
= RECT_RIGHT(*area
);
161 ab
= RECT_BOTTOM(*area
);
162 pl
= RECT_LEFT(*parea
);
163 pt
= RECT_TOP(*parea
);
164 pr
= RECT_RIGHT(*parea
);
165 pb
= RECT_BOTTOM(*parea
);
167 if (cl
>= al
&& l
< al
&& l
>= al
- resist
)
169 else if (cr
<= ar
&& r
> ar
&& r
<= ar
+ resist
)
171 else if (cl
>= pl
&& l
< pl
&& l
>= pl
- resist
)
173 else if (cr
<= pr
&& r
> pr
&& r
<= pr
+ resist
)
176 if (ct
>= at
&& t
< at
&& t
>= at
- resist
)
178 else if (cb
<= ab
&& b
> ab
&& b
< ab
+ resist
)
180 else if (ct
>= pt
&& t
< pt
&& t
>= pt
- resist
)
182 else if (cb
<= pb
&& b
> pb
&& b
< pb
+ resist
)
189 frame_frame_gravity(c
->frame
, x
, y
, c
->area
.width
, c
->area
.height
);
192 void resist_size_windows(ObClient
*c
, gint resist
, gint
*w
, gint
*h
,
196 ObClient
*target
; /* target */
197 gint l
, t
, r
, b
; /* my left, top, right and bottom sides */
198 gint dlt
, drb
; /* my destination left/top and right/bottom sides */
199 gint tl
, tt
, tr
, tb
; /* target's left, top, right and bottom bottom sides*/
201 ObClient
*snapx
= NULL
, *snapy
= NULL
;
205 incw
= c
->size_inc
.width
;
206 inch
= c
->size_inc
.height
;
208 l
= RECT_LEFT(c
->frame
->area
);
209 r
= RECT_RIGHT(c
->frame
->area
);
210 t
= RECT_TOP(c
->frame
->area
);
211 b
= RECT_BOTTOM(c
->frame
->area
);
213 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
214 if (!WINDOW_IS_CLIENT(it
->data
))
218 /* don't snap to invisibles or ourself */
219 if (!target
->frame
->visible
|| target
== c
) continue;
221 tl
= RECT_LEFT(target
->frame
->area
);
222 tr
= RECT_RIGHT(target
->frame
->area
);
223 tt
= RECT_TOP(target
->frame
->area
);
224 tb
= RECT_BOTTOM(target
->frame
->area
);
227 /* horizontal snapping */
228 if (t
< tb
&& b
> tt
) {
230 case OB_CORNER_TOPLEFT
:
231 case OB_CORNER_BOTTOMLEFT
:
233 drb
= r
+ *w
- c
->frame
->area
.width
;
234 if (r
< tl
&& drb
>= tl
&&
236 *w
= tl
- l
, snapx
= target
;
238 case OB_CORNER_TOPRIGHT
:
239 case OB_CORNER_BOTTOMRIGHT
:
240 dlt
= l
- *w
+ c
->frame
->area
.width
;
242 if (l
> tr
&& dlt
<= tr
&&
244 *w
= r
- tr
, snapx
= target
;
251 /* vertical snapping */
252 if (l
< tr
&& r
> tl
) {
254 case OB_CORNER_TOPLEFT
:
255 case OB_CORNER_TOPRIGHT
:
257 drb
= b
+ *h
- c
->frame
->area
.height
;
258 if (b
< tt
&& drb
>= tt
&&
260 *h
= tt
- t
, snapy
= target
;
262 case OB_CORNER_BOTTOMLEFT
:
263 case OB_CORNER_BOTTOMRIGHT
:
264 dlt
= t
- *h
+ c
->frame
->area
.height
;
266 if (t
> tb
&& dlt
<= tb
&&
268 *h
= b
- tb
, snapy
= target
;
274 /* snapped both ways */
275 if (snapx
&& snapy
) break;
279 void resist_size_monitors(ObClient
*c
, gint resist
, gint
*w
, gint
*h
,
282 gint l
, t
, r
, b
; /* my left, top, right and bottom sides */
283 gint dlt
, drb
; /* my destination left/top and right/bottom sides */
285 gint al
, at
, ar
, ab
; /* screen boundaries */
286 gint pl
, pt
, pr
, pb
; /* physical screen boundaries */
293 l
= RECT_LEFT(c
->frame
->area
);
294 r
= RECT_RIGHT(c
->frame
->area
);
295 t
= RECT_TOP(c
->frame
->area
);
296 b
= RECT_BOTTOM(c
->frame
->area
);
298 incw
= c
->size_inc
.width
;
299 inch
= c
->size_inc
.height
;
301 RECT_SET(desired_area
, c
->area
.x
, c
->area
.y
, *w
, *h
);
303 for (i
= 0; i
< screen_num_monitors
; ++i
) {
304 parea
= screen_physical_area_monitor(i
);
306 if (!RECT_INTERSECTS_RECT(*parea
, c
->frame
->area
)) {
311 area
= screen_area(c
->desktop
, SCREEN_AREA_ALL_MONITORS
,
314 /* get the screen boundaries */
315 al
= RECT_LEFT(*area
);
316 at
= RECT_TOP(*area
);
317 ar
= RECT_RIGHT(*area
);
318 ab
= RECT_BOTTOM(*area
);
319 pl
= RECT_LEFT(*parea
);
320 pt
= RECT_TOP(*parea
);
321 pr
= RECT_RIGHT(*parea
);
322 pb
= RECT_BOTTOM(*parea
);
324 /* horizontal snapping */
326 case OB_CORNER_TOPLEFT
:
327 case OB_CORNER_BOTTOMLEFT
:
329 drb
= r
+ *w
- c
->frame
->area
.width
;
330 if (r
<= ar
&& drb
> ar
&& drb
<= ar
+ resist
)
332 else if (r
<= pr
&& drb
> pr
&& drb
<= pr
+ resist
)
335 case OB_CORNER_TOPRIGHT
:
336 case OB_CORNER_BOTTOMRIGHT
:
337 dlt
= l
- *w
+ c
->frame
->area
.width
;
339 if (l
>= al
&& dlt
< al
&& dlt
>= al
- resist
)
341 else if (l
>= pl
&& dlt
< pl
&& dlt
>= pl
- resist
)
346 /* vertical snapping */
348 case OB_CORNER_TOPLEFT
:
349 case OB_CORNER_TOPRIGHT
:
351 drb
= b
+ *h
- c
->frame
->area
.height
;
352 if (b
<= ab
&& drb
> ab
&& drb
<= ab
+ resist
)
354 else if (b
<= pb
&& drb
> pb
&& drb
<= pb
+ resist
)
357 case OB_CORNER_BOTTOMLEFT
:
358 case OB_CORNER_BOTTOMRIGHT
:
359 dlt
= t
- *h
+ c
->frame
->area
.height
;
361 if (t
>= at
&& dlt
< at
&& dlt
>= at
- resist
)
363 else if (t
>= pt
&& dlt
< pt
&& dlt
>= pt
- resist
)
This page took 0.051161 seconds and 4 git commands to generate.