2 * ion/ioncore/float-placement.c
4 * Copyright (c) Tuomo Valkonen 1999-2007.
6 * Ion is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
16 #include "float-placement.h"
19 WFloatPlacement ioncore_placement_method=PLACEMENT_LRUD;
22 static void random_placement(WRectangle box, WRectangle *g)
26 g->x=box.x+(box.w<=0 ? 0 : rand()%box.w);
27 g->y=box.y+(box.h<=0 ? 0 : rand()%box.h);
31 static void ggeom(WRegion *reg, WRectangle *geom)
33 *geom=REGION_GEOM(reg);
37 #define IGNORE_ST(ST, WS) ((ST)->reg==NULL || (ST)==(WS)->bottom)
39 static WRegion* is_occupied(WGroup *ws, const WRectangle *r)
45 FOR_ALL_NODES_IN_GROUP(ws, st, tmp){
66 static int next_least_x(WGroup *ws, int x)
69 int retx=REGION_GEOM(ws).x+REGION_GEOM(ws).w;
73 FOR_ALL_NODES_IN_GROUP(ws, st, tmp){
79 if(p.x+p.w>x && p.x+p.w<retx)
87 static int next_lowest_y(WGroup *ws, int y)
90 int rety=REGION_GEOM(ws).y+REGION_GEOM(ws).h;
94 FOR_ALL_NODES_IN_GROUP(ws, st, tmp){
100 if(p.y+p.h>y && p.y+p.h<rety)
108 static bool tiling_placement(WGroup *ws, WRectangle *g)
118 maxx=REGION_GEOM(ws).x+REGION_GEOM(ws).w;
119 maxy=REGION_GEOM(ws).y+REGION_GEOM(ws).h;
121 if(ioncore_placement_method==PLACEMENT_UDLR){
123 p=is_occupied(ws, &r);
124 while(p!=NULL && r.y+r.h<maxy){
127 p=is_occupied(ws, &r);
129 if(r.y+r.h<maxy && r.x+r.w<maxx){
134 r.x=next_least_x(ws, r.x);
140 p=is_occupied(ws, &r);
141 while(p!=NULL && r.x+r.w<maxx){
144 p=is_occupied(ws, &r);
146 if(r.y+r.h<maxy && r.x+r.w<maxx){
151 r.y=next_lowest_y(ws, r.y);
162 void group_calc_placement(WGroup *ws, WRectangle *geom)
164 if(ioncore_placement_method!=PLACEMENT_RANDOM){
165 if(tiling_placement(ws, geom))
168 random_placement(REGION_GEOM(ws), geom);