]>
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.
30 static gboolean
resist_move_window(Rect window
,
31 Rect target
, gint resist
,
34 gint l
, t
, r
, b
; /* requested edges */
35 gint cl
, ct
, cr
, cb
; /* current edges */
36 gint w
, h
; /* current size */
37 gint tl
, tt
, tr
, tb
; /* 1 past the target's edges on each side */
38 gboolean snapx
= 0, snapy
= 0;
48 cl
= RECT_LEFT(window
);
49 ct
= RECT_TOP(window
);
50 cr
= RECT_RIGHT(window
);
51 cb
= RECT_BOTTOM(window
);
53 tl
= RECT_LEFT(target
) - 1;
54 tt
= RECT_TOP(target
) - 1;
55 tr
= RECT_RIGHT(target
) + 1;
56 tb
= RECT_BOTTOM(target
) + 1;
58 /* snapx and snapy ensure that the window snaps to the top-most
59 window edge available, without going all the way from
60 bottom-to-top in the stacking list
63 if (ct
< tb
&& cb
> tt
) {
64 if (cl
>= tr
&& l
< tr
&& l
>= tr
- resist
)
65 *x
= tr
, snapx
= TRUE
;
66 else if (cr
<= tl
&& r
> tl
&&
68 *x
= tl
- w
+ 1, snapx
= TRUE
;
70 /* try to corner snap to the window */
71 if (ct
> tt
&& t
<= tt
&&
73 *y
= tt
+ 1, snapy
= TRUE
;
74 else if (cb
< tb
&& b
>= tb
&&
76 *y
= tb
- h
, snapy
= TRUE
;
81 if (cl
< tr
&& cr
> tl
) {
82 if (ct
>= tb
&& t
< tb
&& t
>= tb
- resist
)
83 *y
= tb
, snapy
= TRUE
;
84 else if (cb
<= tt
&& b
> tt
&&
86 *y
= tt
- h
+ 1, snapy
= TRUE
;
88 /* try to corner snap to the window */
89 if (cl
> tl
&& l
<= tl
&&
91 *x
= tl
+ 1, snapx
= TRUE
;
92 else if (cr
< tr
&& r
>= tr
&&
94 *x
= tr
- w
, snapx
= TRUE
;
99 return snapx
&& snapy
;
102 void resist_move_windows(ObClient
*c
, gint resist
, gint
*x
, gint
*y
)
109 frame_client_gravity(c
->frame
, x
, y
);
112 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
115 if (!WINDOW_IS_CLIENT(it
->data
))
119 /* don't snap to self or non-visibles */
120 if (!target
->frame
->visible
|| target
== c
)
122 /* don't snap to windows set to below and skip_taskbar (desklets) */
123 if (target
->below
&& !c
->below
&& target
->skip_taskbar
)
126 if (resist_move_window(c
->frame
->area
, target
->frame
->area
,
130 dock_get_area(&dock_area
);
131 resist_move_window(c
->frame
->area
, dock_area
, resist
, x
, y
);
133 frame_frame_gravity(c
->frame
, x
, y
);
136 void resist_move_monitors(ObClient
*c
, gint resist
, gint
*x
, gint
*y
)
141 gint l
, t
, r
, b
; /* requested edges */
142 gint al
, at
, ar
, ab
; /* screen area edges */
143 gint pl
, pt
, pr
, pb
; /* physical screen area edges */
144 gint cl
, ct
, cr
, cb
; /* current edges */
145 gint w
, h
; /* current size */
150 frame_client_gravity(c
->frame
, x
, y
);
152 w
= c
->frame
->area
.width
;
153 h
= c
->frame
->area
.height
;
160 cl
= RECT_LEFT(c
->frame
->area
);
161 ct
= RECT_TOP(c
->frame
->area
);
162 cr
= RECT_RIGHT(c
->frame
->area
);
163 cb
= RECT_BOTTOM(c
->frame
->area
);
165 RECT_SET(desired_area
, c
->frame
->area
.x
, c
->frame
->area
.y
,
166 c
->frame
->area
.width
, c
->frame
->area
.height
);
168 for (i
= 0; i
< screen_num_monitors
; ++i
) {
169 parea
= screen_physical_area_monitor(i
);
171 if (!RECT_INTERSECTS_RECT(*parea
, c
->frame
->area
))
174 area
= screen_area(c
->desktop
, SCREEN_AREA_ALL_MONITORS
,
177 al
= RECT_LEFT(*area
);
178 at
= RECT_TOP(*area
);
179 ar
= RECT_RIGHT(*area
);
180 ab
= RECT_BOTTOM(*area
);
181 pl
= RECT_LEFT(*parea
);
182 pt
= RECT_TOP(*parea
);
183 pr
= RECT_RIGHT(*parea
);
184 pb
= RECT_BOTTOM(*parea
);
186 if (cl
>= al
&& l
< al
&& l
>= al
- resist
)
188 else if (cr
<= ar
&& r
> ar
&& r
<= ar
+ resist
)
190 else if (cl
>= pl
&& l
< pl
&& l
>= pl
- resist
)
192 else if (cr
<= pr
&& r
> pr
&& r
<= pr
+ resist
)
195 if (ct
>= at
&& t
< at
&& t
>= at
- resist
)
197 else if (cb
<= ab
&& b
> ab
&& b
< ab
+ resist
)
199 else if (ct
>= pt
&& t
< pt
&& t
>= pt
- resist
)
201 else if (cb
<= pb
&& b
> pb
&& b
< pb
+ resist
)
204 g_slice_free(Rect
, area
);
207 frame_frame_gravity(c
->frame
, x
, y
);
210 static gboolean
resist_size_window(Rect window
, Rect target
, gint resist
,
211 gint
*w
, gint
*h
, ObDirection dir
)
213 gint l
, t
, r
, b
; /* my left, top, right and bottom sides */
214 gint tl
, tt
, tr
, tb
; /* target's left, top, right and bottom bottom sides*/
215 gint dlt
, drb
; /* my destination left/top and right/bottom sides */
216 gboolean snapx
= 0, snapy
= 0;
219 l
= RECT_LEFT(window
);
220 t
= RECT_TOP(window
);
221 r
= RECT_RIGHT(window
);
222 b
= RECT_BOTTOM(window
);
225 orgh
= window
.height
;
227 tl
= RECT_LEFT(target
);
228 tt
= RECT_TOP(target
);
229 tr
= RECT_RIGHT(target
);
230 tb
= RECT_BOTTOM(target
);
233 /* horizontal snapping */
234 if (t
< tb
&& b
> tt
) {
236 case OB_DIRECTION_EAST
:
237 case OB_DIRECTION_NORTHEAST
:
238 case OB_DIRECTION_SOUTHEAST
:
239 case OB_DIRECTION_NORTH
:
240 case OB_DIRECTION_SOUTH
:
243 if (r
< tl
&& drb
>= tl
&&
245 *w
= tl
- l
, snapx
= TRUE
;
247 case OB_DIRECTION_WEST
:
248 case OB_DIRECTION_NORTHWEST
:
249 case OB_DIRECTION_SOUTHWEST
:
252 if (l
> tr
&& dlt
<= tr
&&
254 *w
= r
- tr
, snapx
= TRUE
;
261 /* vertical snapping */
262 if (l
< tr
&& r
> tl
) {
264 case OB_DIRECTION_SOUTH
:
265 case OB_DIRECTION_SOUTHWEST
:
266 case OB_DIRECTION_SOUTHEAST
:
267 case OB_DIRECTION_EAST
:
268 case OB_DIRECTION_WEST
:
271 if (b
< tt
&& drb
>= tt
&&
273 *h
= tt
- t
, snapy
= TRUE
;
275 case OB_DIRECTION_NORTH
:
276 case OB_DIRECTION_NORTHWEST
:
277 case OB_DIRECTION_NORTHEAST
:
280 if (t
> tb
&& dlt
<= tb
&&
282 *h
= b
- tb
, snapy
= TRUE
;
288 /* snapped both ways */
289 return snapx
&& snapy
;
292 void resist_size_windows(ObClient
*c
, gint resist
, gint
*w
, gint
*h
,
296 ObClient
*target
; /* target */
301 for (it
= stacking_list
; it
; it
= g_list_next(it
)) {
302 if (!WINDOW_IS_CLIENT(it
->data
))
306 /* don't snap to invisibles or ourself */
307 if (!target
->frame
->visible
|| target
== c
)
309 /* don't snap to windows set to below and skip_taskbar (desklets) */
310 if (target
->below
&& !c
->below
&& target
->skip_taskbar
)
313 if (resist_size_window(c
->frame
->area
, target
->frame
->area
,
317 dock_get_area(&dock_area
);
318 resist_size_window(c
->frame
->area
, dock_area
,
322 void resist_size_monitors(ObClient
*c
, gint resist
, gint
*w
, gint
*h
,
325 gint l
, t
, r
, b
; /* my left, top, right and bottom sides */
326 gint dlt
, drb
; /* my destination left/top and right/bottom sides */
329 gint al
, at
, ar
, ab
; /* screen boundaries */
330 gint pl
, pt
, pr
, pb
; /* physical screen boundaries */
336 l
= RECT_LEFT(c
->frame
->area
);
337 r
= RECT_RIGHT(c
->frame
->area
);
338 t
= RECT_TOP(c
->frame
->area
);
339 b
= RECT_BOTTOM(c
->frame
->area
);
341 RECT_SET(desired_area
, c
->area
.x
, c
->area
.y
, *w
, *h
);
343 for (i
= 0; i
< screen_num_monitors
; ++i
) {
344 parea
= screen_physical_area_monitor(i
);
346 if (!RECT_INTERSECTS_RECT(*parea
, c
->frame
->area
))
349 area
= screen_area(c
->desktop
, SCREEN_AREA_ALL_MONITORS
,
352 /* get the screen boundaries */
353 al
= RECT_LEFT(*area
);
354 at
= RECT_TOP(*area
);
355 ar
= RECT_RIGHT(*area
);
356 ab
= RECT_BOTTOM(*area
);
357 pl
= RECT_LEFT(*parea
);
358 pt
= RECT_TOP(*parea
);
359 pr
= RECT_RIGHT(*parea
);
360 pb
= RECT_BOTTOM(*parea
);
362 /* horizontal snapping */
364 case OB_DIRECTION_EAST
:
365 case OB_DIRECTION_NORTHEAST
:
366 case OB_DIRECTION_SOUTHEAST
:
367 case OB_DIRECTION_NORTH
:
368 case OB_DIRECTION_SOUTH
:
370 drb
= r
+ *w
- c
->frame
->area
.width
;
371 if (r
<= ar
&& drb
> ar
&& drb
<= ar
+ resist
)
373 else if (r
<= pr
&& drb
> pr
&& drb
<= pr
+ resist
)
376 case OB_DIRECTION_WEST
:
377 case OB_DIRECTION_NORTHWEST
:
378 case OB_DIRECTION_SOUTHWEST
:
379 dlt
= l
- *w
+ c
->frame
->area
.width
;
381 if (l
>= al
&& dlt
< al
&& dlt
>= al
- resist
)
383 else if (l
>= pl
&& dlt
< pl
&& dlt
>= pl
- resist
)
388 /* vertical snapping */
390 case OB_DIRECTION_SOUTH
:
391 case OB_DIRECTION_SOUTHWEST
:
392 case OB_DIRECTION_SOUTHEAST
:
393 case OB_DIRECTION_WEST
:
394 case OB_DIRECTION_EAST
:
396 drb
= b
+ *h
- c
->frame
->area
.height
;
397 if (b
<= ab
&& drb
> ab
&& drb
<= ab
+ resist
)
399 else if (b
<= pb
&& drb
> pb
&& drb
<= pb
+ resist
)
402 case OB_DIRECTION_NORTH
:
403 case OB_DIRECTION_NORTHWEST
:
404 case OB_DIRECTION_NORTHEAST
:
405 dlt
= t
- *h
+ c
->frame
->area
.height
;
407 if (t
>= at
&& dlt
< at
&& dlt
>= at
- resist
)
409 else if (t
>= pt
&& dlt
< pt
&& dlt
>= pt
- resist
)
414 g_slice_free(Rect
, area
);
This page took 0.058065 seconds and 4 git commands to generate.