4 * Copyright (c) Tuomo Valkonen 1999-2007.
6 * See the included file LICENSE for details.
9 #include <libtu/objp.h>
10 #include <libtu/setparam.h>
11 #include <libtu/minmax.h>
13 #include <ioncore/common.h>
14 #include <ioncore/global.h>
15 #include <ioncore/mplex.h>
16 #include <ioncore/focus.h>
17 #include <ioncore/group.h>
18 #include <ioncore/group-ws.h>
19 #include <ioncore/framedpholder.h>
20 #include <ioncore/return.h>
21 #include <ioncore/sizehint.h>
22 #include <ioncore/resize.h>
25 static void get_relative_geom(WRectangle *g, WRegion *reg, WRegion *mgr)
27 WWindow *rel=REGION_PARENT(mgr), *w;
31 for(w=REGION_PARENT(reg);
32 w!=rel && (WRegion*)w!=mgr;
35 g->x+=REGION_GEOM(w).x;
36 g->y+=REGION_GEOM(w).y;
41 static bool ioncore_do_detach(WRegion *reg, WGroup *grp, WFrameMode framemode,
44 WGroupAttachParams ap=GROUPATTACHPARAMS_INIT;
45 WRegionAttachData data;
51 ap.switchto=region_may_control_focus(reg);
53 data.type=REGION_ATTACH_REPARENT;
56 ph=region_unset_get_return(reg);
59 ph=region_make_return_pholder(reg);
63 if(framemode!=FRAME_MODE_UNKNOWN){
64 WFramedParam fpa=FRAMEDPARAM_INIT;
67 fpa.inner_geom_gravity_set=TRUE;
68 fpa.gravity=ForgetGravity;
70 ap.geom_weak_set=TRUE;
74 ap.level=framelevel+1;
76 get_relative_geom(&fpa.inner_geom, reg, (WRegion*)grp);
78 ret=(region_attach_framed((WRegion*)grp, &fpa,
79 (WRegionAttachFn*)group_do_attach,
82 WStacking *st=ioncore_find_stacking(reg);
89 ap.level=maxof(st->level, STACKING_LEVEL_NORMAL);
93 get_relative_geom(&ap.geom, reg, (WRegion*)grp);
95 ret=(group_do_attach(grp, &ap, &data)!=NULL);
99 destroy_obj((Obj*)ph);
100 else if(!region_do_set_return(reg, ph))
101 destroy_obj((Obj*)ph);
107 static WRegion *check_mplex(WRegion *reg, WFrameMode *mode)
109 WMPlex *mplex=REGION_MANAGER_CHK(reg, WMPlex);
111 if(OBJ_IS(reg, WWindow) || mplex==NULL){
112 *mode=FRAME_MODE_UNKNOWN;
116 *mode=FRAME_MODE_FLOATING;
118 if(OBJ_IS(mplex, WFrame)
119 && frame_mode((WFrame*)mplex)==FRAME_MODE_TRANSIENT){
120 *mode=FRAME_MODE_TRANSIENT;
123 return (WRegion*)mplex;
127 static WGroup *find_group(WRegion *reg, uint *level)
129 WRegion *mgr=REGION_MANAGER(reg);
133 mgr=REGION_MANAGER(mgr);
134 if(OBJ_IS(mgr, WGroup)){
135 WStacking *st=ioncore_find_stacking((WRegion*)reg);
146 bool ioncore_detach(WRegion *reg, int sp)
148 WPHolder *ph=region_get_return(reg);
152 uint level=STACKING_LEVEL_NORMAL;
154 reg=region_groupleader_of(reg);
156 grp=find_group(check_mplex(reg, &mode), &level);
158 /* reg is only considered detached if there's no higher-level group
159 * to attach to, thus causing 'toggle' to cycle.
162 nset=libtu_do_setparam(sp, set);
168 return ioncore_do_detach(reg, grp, mode, level);
170 WPHolder *ph=region_get_return(reg);
173 if(!pholder_attach_mcfgoto(ph, PHOLDER_ATTACH_SWITCHTO, reg)){
174 warn(TR("Failed to reattach."));
177 region_unset_return(reg);
186 * Detach or reattach \var{reg}, depending on whether \var{how}
187 * is \codestr{set}, \codestr{unset} or \codestr{toggle}. (Detaching
188 * means making \var{reg} managed by its nearest ancestor \type{WGroup},
189 * framed if \var{reg} is not itself \type{WFrame}. Reattaching means
190 * making it managed where it used to be managed, if a return-placeholder
192 * If \var{reg} is the `bottom' of some group, the whole group is
193 * detached. If \var{reg} is a \type{WWindow}, it is put into a
196 EXTL_EXPORT_AS(ioncore, detach)
197 bool ioncore_detach_extl(WRegion *reg, const char *how)
202 return ioncore_detach(reg, libtu_string_to_setparam(how));
206 void do_unsqueeze(WRegion *reg)
209 WRegion *mgr=REGION_MANAGER(reg);
211 if(OBJ_IS(reg, WScreen))
214 region_size_hints(reg, &h);
219 if(h.min_width<=REGION_GEOM(reg).w &&
220 h.min_height<=REGION_GEOM(reg).h){
224 ioncore_detach(reg, SETPARAM_SET);
226 if(REGION_MANAGER(reg)==mgr)
234 * Try to detach \var{reg} if it fits poorly in its
235 * current location. This function does not do anything,
236 * unless \var{override} is set or the \var{unsqueeze} option
237 * of \fnref{ioncore.set} is set.
240 void ioncore_unsqueeze(WRegion *reg, bool override)
242 if(ioncore_g.unsqueeze_enabled || override)
243 do_unsqueeze(region_groupleader_of(reg));