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.
12 #include <libtu/objp.h>
13 #include <libtu/setparam.h>
14 #include <libtu/minmax.h>
16 #include <ioncore/common.h>
17 #include <ioncore/global.h>
18 #include <ioncore/mplex.h>
19 #include <ioncore/focus.h>
20 #include <ioncore/group.h>
21 #include <ioncore/group-ws.h>
22 #include <ioncore/framedpholder.h>
23 #include <ioncore/return.h>
24 #include <ioncore/sizehint.h>
25 #include <ioncore/resize.h>
28 static void get_relative_geom(WRectangle *g, WRegion *reg, WRegion *mgr)
30 WWindow *rel=REGION_PARENT(mgr), *w;
34 for(w=REGION_PARENT(reg);
35 w!=rel && (WRegion*)w!=mgr;
38 g->x+=REGION_GEOM(w).x;
39 g->y+=REGION_GEOM(w).y;
44 bool ioncore_do_detach(WRegion *reg, WGroup *grp, WFrameMode framemode)
46 WGroupAttachParams ap=GROUPATTACHPARAMS_INIT;
47 WRegionAttachData data;
53 ap.switchto=region_may_control_focus(reg);
55 data.type=REGION_ATTACH_REPARENT;
58 ph=region_unset_get_return(reg);
61 ph=region_make_return_pholder(reg);
65 if(framemode!=FRAME_MODE_UNKNOWN){
66 WFramedParam fpa=FRAMEDPARAM_INIT;
69 fpa.inner_geom_gravity_set=TRUE;
70 fpa.gravity=ForgetGravity;
72 ap.geom_weak_set=TRUE;
75 get_relative_geom(&fpa.inner_geom, reg, (WRegion*)grp);
77 ret=(region_attach_framed((WRegion*)grp, &fpa,
78 (WRegionAttachFn*)group_do_attach,
81 WStacking *st=ioncore_find_stacking(reg);
87 ap.level=maxof(st->level, STACKING_LEVEL_NORMAL);
92 get_relative_geom(&ap.geom, reg, (WRegion*)grp);
94 ret=(group_do_attach(grp, &ap, &data)!=NULL);
98 destroy_obj((Obj*)ph);
99 else if(!region_do_set_return(reg, ph))
100 destroy_obj((Obj*)ph);
106 static WRegion *check_mplex(WRegion *reg, WFrameMode *mode)
108 WMPlex *mplex=REGION_MANAGER_CHK(reg, WMPlex);
110 if(OBJ_IS(reg, WWindow) || mplex==NULL){
111 *mode=FRAME_MODE_UNKNOWN;
115 *mode=FRAME_MODE_FLOATING;
117 if(OBJ_IS(mplex, WFrame)
118 && frame_mode((WFrame*)mplex)==FRAME_MODE_TRANSIENT){
119 *mode=FRAME_MODE_TRANSIENT;
122 return (WRegion*)mplex;
126 static WGroup *find_group(WRegion *reg)
128 WRegion *mgr=REGION_MANAGER(reg);
131 mgr=REGION_MANAGER(mgr);
132 if(OBJ_IS(mgr, WGroup))
140 bool ioncore_detach(WRegion *reg, int sp)
142 WPHolder *ph=region_get_return(reg);
147 reg=region_groupleader_of(reg);
149 grp=find_group(check_mplex(reg, &mode));
151 /* reg is only considered detached if there's no higher-level group
152 * to attach to, thus causing 'toggle' to cycle.
155 nset=libtu_do_setparam(sp, set);
161 return ioncore_do_detach(reg, grp, mode);
163 WPHolder *ph=region_get_return(reg);
166 if(!pholder_attach_mcfgoto(ph, PHOLDER_ATTACH_SWITCHTO, reg)){
167 warn(TR("Failed to reattach."));
170 region_unset_return(reg);
179 * Detach or reattach \var{reg}, depending on whether \var{how}
180 * is 'set'/'unset'/'toggle'. (Detaching means making \var{reg}
181 * managed by its nearest ancestor \type{WGroup}, framed if \var{reg} is
182 * not itself \type{WFrame}. Reattaching means making it managed where
183 * it used to be managed, if a return-placeholder exists.)
184 * If \var{reg} is the 'bottom' of some group, the whole group is
185 * detached. If \var{reg} is a \type{WWindow}, it is put into a
188 EXTL_EXPORT_AS(ioncore, detach)
189 bool ioncore_detach_extl(WRegion *reg, const char *how)
194 return ioncore_detach(reg, libtu_string_to_setparam(how));
198 void do_unsqueeze(WRegion *reg)
202 if(REGION_MANAGER_CHK(reg, WScreen)!=NULL)
205 region_size_hints(reg, &hints);
210 if(hints.min_width<=REGION_GEOM(reg).w &&
211 hints.min_height<=REGION_GEOM(reg).h){
215 if(!ioncore_detach(reg, SETPARAM_SET))
223 * Try to detach \var{reg} if it fits poorly in its
224 * current location. This function does not do anything,
225 * unless \var{override} is set or the \var{unsqueeze} option
226 * of \fnref{ioncore.set} is set.
229 void ioncore_unsqueeze(WRegion *reg, bool override)
231 if(ioncore_g.unsqueeze_enabled || override)
232 do_unsqueeze(region_groupleader_of(reg));