2 * ion/ioncore/float-placement.c
4 * Copyright (c) Tuomo Valkonen 1999-2008.
6 * See the included file LICENSE for details.
13 #include "float-placement.h"
16 WFloatPlacement ioncore_placement_method=PLACEMENT_LRUD;
19 static void random_placement(WRectangle box, WRectangle *g)
23 g->x=box.x+(box.w<=0 ? 0 : rand()%box.w);
24 g->y=box.y+(box.h<=0 ? 0 : rand()%box.h);
28 static void ggeom(WRegion *reg, WRectangle *geom)
30 *geom=REGION_GEOM(reg);
34 static bool st_filt(WStacking *st, void *lvl)
36 uint level=*(uint*)lvl;
38 return (st->reg!=NULL &&
39 REGION_IS_MAPPED(st->reg) &&
44 #define FOR_ALL_STACKING_NODES(VAR, WS, LVL, TMP) \
45 for(stacking_iter_init(&(TMP), group_get_stacking(ws), \
47 VAR=stacking_iter_nodes(&(TMP)); \
49 VAR=stacking_iter_nodes(&(TMP)))
52 #define IGNORE_ST(ST, WS) ((ST)->reg==NULL || (ST)==(WS)->bottom)
55 static WRegion* is_occupied(WGroup *ws, uint level, const WRectangle *r)
61 FOR_ALL_STACKING_NODES(st, ws, level, tmp){
79 static int next_least_x(WGroup *ws, uint level, int x)
82 int retx=REGION_GEOM(ws).x+REGION_GEOM(ws).w;
86 FOR_ALL_STACKING_NODES(st, ws, level, tmp){
89 if(p.x+p.w>x && p.x+p.w<retx)
98 static int next_lowest_y(WGroup *ws, uint level, int y)
101 int rety=REGION_GEOM(ws).y+REGION_GEOM(ws).h;
102 WStackingIterTmp tmp;
105 FOR_ALL_STACKING_NODES(st, ws, level, tmp){
108 if(p.y+p.h>y && p.y+p.h<rety)
116 static bool tiling_placement(WGroup *ws, uint level, WRectangle *g)
126 maxx=REGION_GEOM(ws).x+REGION_GEOM(ws).w;
127 maxy=REGION_GEOM(ws).y+REGION_GEOM(ws).h;
129 if(ioncore_placement_method==PLACEMENT_UDLR){
131 p=is_occupied(ws, level, &r);
132 while(p!=NULL && r.y+r.h<maxy){
135 p=is_occupied(ws, level, &r);
137 if(r.y+r.h<maxy && r.x+r.w<maxx){
142 r.x=next_least_x(ws, level, r.x);
148 p=is_occupied(ws, level, &r);
149 while(p!=NULL && r.x+r.w<maxx){
152 p=is_occupied(ws, level, &r);
154 if(r.y+r.h<maxy && r.x+r.w<maxx){
159 r.y=next_lowest_y(ws, level, r.y);
170 void group_calc_placement(WGroup *ws, uint level, WRectangle *geom)
172 if(ioncore_placement_method!=PLACEMENT_RANDOM){
173 if(tiling_placement(ws, level, geom))
176 random_placement(REGION_GEOM(ws), geom);