-static WGroup *find_group(WRegion *reg, bool *detach_framed)
-{
- WRegion *mgr=REGION_MANAGER(reg);
- bool was_grouped=FALSE;
-
- if(OBJ_IS(mgr, WMPlex)){
- WMPlex *mplex=(WMPlex*)mgr;
- *detach_framed=TRUE;
- mgr=REGION_MANAGER(mgr);
- if(OBJ_IS(mgr, WGroup)){
- assert(mplex->mgd!=NULL);
- if(mplex->mgd->reg==reg && mplex->mgd->mgr_next==NULL){
- /* Nothing to detach */
- return NULL;
- }
- }
- }else{
- was_grouped=OBJ_IS(mgr, WGroup);
- *detach_framed=FALSE;
- }
-
- while(mgr!=NULL){
- mgr=REGION_MANAGER(mgr);
- if(OBJ_IS(mgr, WGroup))
- break;
- }
-
- if(mgr==NULL && was_grouped)
- warn(TR("Already detached."));
-
- return (WGroup*)mgr;
-}
-
-
-static void get_relative_geom(WRectangle *g, WRegion *reg, WRegion *mgr)
-{
- WWindow *rel=REGION_PARENT(mgr), *w;
-
- *g=REGION_GEOM(reg);
-
- for(w=REGION_PARENT(reg);
- w!=rel && (WRegion*)w!=mgr;
- w=REGION_PARENT(w)){
-
- g->x+=REGION_GEOM(w).x;
- g->y+=REGION_GEOM(w).y;
- }
-}
-
-
-/*EXTL_DOC
- * Detach \var{reg}, i.e. make it managed by its nearest ancestor
- * \type{WGroup}, framed if \var{reg} is not itself \type{WFrame}.
- */
-EXTL_EXPORT
-bool mod_tiling_detach(WRegion *reg)
-{
- bool detach_framed=!OBJ_IS(reg, WFrame);
- WGroupAttachParams ap=GROUPATTACHPARAMS_INIT;
- WRegionAttachData data;
- WGroup *grp;
-
- grp=find_group(reg, &detach_framed);
-
- if(grp==NULL)
- return FALSE;
-
- ap.switchto_set=TRUE;
- ap.switchto=region_may_control_focus(reg);
-
- ap.geom_set=TRUE;
- get_relative_geom(&ap.geom, reg, (WRegion*)grp);
-
- /* TODO: Retain (root-relative) geometry of reg for framed
- * detach instead of making a frame of this size?
- */
-
- data.type=REGION_ATTACH_REPARENT;
- data.u.reg=reg;
-
- if(detach_framed){
- WFramedParam fp=FRAMEDPARAM_INIT;
-
- return (region_attach_framed((WRegion*)grp, &fp,
- (WRegionAttachFn*)group_do_attach,
- &ap, &data)!=NULL);
- }else{
- return (group_do_attach(grp, &ap, &data)!=NULL);
- }
-}