]>
Dogcows Code - chaz/openbox/blob - openbox/place.c
545355ce737766662093dca81757fc6964fd8c98
8 static Rect
* pick_head(ObClient
*c
)
10 /* try direct parent first */
11 if (c
->transient_for
&& c
->transient_for
!= OB_TRAN_GROUP
) {
12 return screen_area_monitor(c
->desktop
,
13 client_monitor(c
->transient_for
));
16 /* more than one guy in his group (more than just him) */
17 if (c
->group
&& c
->group
->members
->next
) {
20 /* try on the client's desktop */
21 for (it
= c
->group
->members
; it
; it
= g_slist_next(it
)) {
22 ObClient
*itc
= it
->data
;
24 (itc
->desktop
== c
->desktop
||
25 itc
->desktop
== DESKTOP_ALL
|| c
->desktop
== DESKTOP_ALL
))
26 return screen_area_monitor(c
->desktop
,
27 client_monitor(it
->data
));
30 /* try on all desktops */
31 for (it
= c
->group
->members
; it
; it
= g_slist_next(it
)) {
32 ObClient
*itc
= it
->data
;
34 return screen_area_monitor(c
->desktop
,
35 client_monitor(it
->data
));
43 static gboolean
place_random(ObClient
*client
, gint
*x
, gint
*y
)
48 area
= pick_head(client
);
50 area
= screen_area_monitor(client
->desktop
,
51 g_random_int_range(0, screen_num_monitors
));
55 r
= area
->x
+ area
->width
- client
->frame
->area
.width
;
56 b
= area
->y
+ area
->height
- client
->frame
->area
.height
;
58 if (r
> l
) *x
= g_random_int_range(l
, r
+ 1);
60 if (b
> t
) *y
= g_random_int_range(t
, b
+ 1);
67 static GSList
* area_add(GSList
*list
, Rect
*a
)
69 Rect
*r
= g_new(Rect
, 1);
71 return g_slist_prepend(list
, r
);
75 static GSList
* area_remove(GSList
*list
, Rect
*a
)
78 GSList
*result
= NULL
;
80 for (sit
= list
; sit
; sit
= g_slist_next(sit
)) {
83 if (!RECT_INTERSECTS_RECT(*r
, *a
)) {
84 result
= g_slist_prepend(result
, r
);
85 r
= NULL
; /* dont free it */
89 /* Use an intersection of win and curr to determine the space
90 around curr that we can use.
92 NOTE: the spaces calculated can overlap.
95 RECT_SET_INTERSECTION(isect
, *r
, *a
);
97 if (RECT_LEFT(isect
) > RECT_LEFT(*r
)) {
98 RECT_SET(extra
, r
->x
, r
->y
,
99 RECT_LEFT(isect
) - r
->x
, r
->height
);
100 result
= area_add(result
, &extra
);
103 if (RECT_TOP(isect
) > RECT_TOP(*r
)) {
104 RECT_SET(extra
, r
->x
, r
->y
,
105 r
->width
, RECT_TOP(isect
) - r
->y
+ 1);
106 result
= area_add(result
, &extra
);
109 if (RECT_RIGHT(isect
) < RECT_RIGHT(*r
)) {
110 RECT_SET(extra
, RECT_RIGHT(isect
) + 1, r
->y
,
111 RECT_RIGHT(*r
) - RECT_RIGHT(isect
), r
->height
);
112 result
= area_add(result
, &extra
);
115 if (RECT_BOTTOM(isect
) < RECT_BOTTOM(*r
)) {
116 RECT_SET(extra
, r
->x
, RECT_BOTTOM(isect
) + 1,
117 r
->width
, RECT_BOTTOM(*r
) - RECT_BOTTOM(isect
));
118 result
= area_add(result
, &extra
);
128 static gint
area_cmp(gconstpointer p1
, gconstpointer p2
)
131 const Rect
*a1
= p1
, *a2
= p2
;
133 ret
= RECT_BOTTOM(*a1
) - RECT_BOTTOM(*a2
);
135 ret
= RECT_LEFT(*a1
) - RECT_LEFT(*a2
);
139 static gboolean
place_smart(ObClient
*client
, gint
*x
, gint
*y
)
142 gboolean ret
= FALSE
;
143 GSList
*spaces
, *sit
;
146 list
= focus_order
[client
->desktop
== DESKTOP_ALL
?
147 screen_desktop
: client
->desktop
];
149 for (i
= 0; i
< screen_num_monitors
; ++i
)
150 spaces
= area_add(spaces
, screen_area_monitor(client
->desktop
, i
));
152 for (it
= list
; it
; it
= g_list_next(it
)) {
153 ObClient
*c
= it
->data
;
155 if (c
== client
|| c
->shaded
|| !client_normal(c
))
157 spaces
= area_remove(spaces
, &c
->frame
->area
);
160 spaces
= g_slist_sort(spaces
, area_cmp
);
162 for (sit
= spaces
; sit
; sit
= g_slist_next(sit
)) {
166 if (r
->width
>= client
->frame
->area
.width
&&
167 r
->height
>= client
->frame
->area
.height
) {
176 g_slist_free(spaces
);
181 static gboolean
place_under_mouse(ObClient
*client
, gint
*x
, gint
*y
)
188 screen_pointer_pos(&px
, &py
);
190 for (i
= 0; i
< screen_num_monitors
; ++i
) {
191 area
= screen_area_monitor(client
->desktop
, i
);
192 if (RECT_CONTAINS(*area
, px
, py
))
195 if (i
== screen_num_monitors
)
196 area
= screen_area_monitor(client
->desktop
, 0);
200 r
= area
->x
+ area
->width
- client
->frame
->area
.width
;
201 b
= area
->y
+ area
->height
- client
->frame
->area
.height
;
203 *x
= px
- client
->area
.width
/ 2 - client
->frame
->size
.left
;
204 *x
= MIN(MAX(*x
, l
), r
);
205 *y
= py
- client
->area
.height
/ 2 - client
->frame
->size
.top
;
206 *y
= MIN(MAX(*y
, t
), b
);
211 static gboolean
place_transient(ObClient
*client
, gint
*x
, gint
*y
)
213 if (client
->transient_for
) {
214 if (client
->transient_for
!= OB_TRAN_GROUP
) {
215 ObClient
*c
= client
;
216 ObClient
*p
= client
->transient_for
;
217 *x
= (p
->frame
->area
.width
- c
->frame
->area
.width
) / 2 +
219 *y
= (p
->frame
->area
.height
- c
->frame
->area
.height
) / 2 +
224 gboolean first
= TRUE
;
226 for (it
= client
->group
->members
; it
; it
= it
->next
) {
227 ObClient
*m
= it
->data
;
228 if (!(m
== client
|| m
->transient_for
)) {
230 l
= RECT_LEFT(m
->frame
->area
);
231 t
= RECT_TOP(m
->frame
->area
);
232 r
= RECT_RIGHT(m
->frame
->area
);
233 b
= RECT_BOTTOM(m
->frame
->area
);
236 l
= MIN(l
, RECT_LEFT(m
->frame
->area
));
237 t
= MIN(t
, RECT_TOP(m
->frame
->area
));
238 r
= MAX(r
, RECT_RIGHT(m
->frame
->area
));
239 b
= MAX(b
, RECT_BOTTOM(m
->frame
->area
));
244 *x
= ((r
+ 1 - l
) - client
->frame
->area
.width
) / 2 + l
;
245 *y
= ((b
+ 1 - t
) - client
->frame
->area
.height
) / 2 + t
;
253 static gboolean
place_dialog(ObClient
*client
, gint
*x
, gint
*y
)
255 /* center parentless dialogs on the screen */
256 if (client
->type
== OB_CLIENT_TYPE_DIALOG
) {
259 area
= pick_head(client
);
261 area
= screen_area_monitor(client
->desktop
, 0);
263 *x
= (area
->width
- client
->frame
->area
.width
) / 2 + area
->x
;
264 *y
= (area
->height
- client
->frame
->area
.height
) / 2 + area
->y
;
270 void place_client(ObClient
*client
, gint
*x
, gint
*y
)
272 if (client
->positioned
)
274 if (place_transient(client
, x
, y
) ||
275 place_dialog(client
, x
, y
) ||
276 place_smart(client
, x
, y
) ||
277 place_under_mouse(client
, x
, y
))
279 /* get where the client should be */
280 frame_frame_gravity(client
->frame
, x
, y
);
282 g_assert_not_reached(); /* the last one better succeed */
This page took 0.045373 seconds and 4 git commands to generate.