4 * Copyright (c) Tuomo Valkonen 1999-2007.
6 * See the included file LICENSE for details.
11 #include <libtu/minmax.h>
12 #include <libtu/objp.h>
13 #include <libmainloop/defer.h>
30 #include "sizepolicy.h"
37 #include "grouppholder.h"
39 #include "float-placement.h"
43 static void group_place_stdisp(WGroup *ws, WWindow *parent,
44 int pos, WRegion *stdisp);
46 static void group_remanage_stdisp(WGroup *ws);
48 static void group_do_set_bottom(WGroup *grp, WStacking *st);
51 /*{{{ Stacking list stuff */
54 WStacking *group_get_stacking(WGroup *ws)
56 WWindow *par=REGION_PARENT(ws);
60 : window_get_stacking(par));
64 WStacking **group_get_stackingp(WGroup *ws)
66 WWindow *par=REGION_PARENT(ws);
70 : window_get_stackingp(par));
74 static bool wsfilt(WStacking *st, void *ws)
76 return (st->reg!=NULL && REGION_MANAGER(st->reg)==(WRegion*)ws);
80 static bool wsfilt_nostdisp(WStacking *st, void *ws)
82 return (wsfilt(st, ws) && ((WGroup*)ws)->managed_stdisp!=st);
86 void group_iter_init(WGroupIterTmp *tmp, WGroup *ws)
88 stacking_iter_mgr_init(tmp, ws->managed_list, NULL, ws);
92 void group_iter_init_nostdisp(WGroupIterTmp *tmp, WGroup *ws)
94 stacking_iter_mgr_init(tmp, ws->managed_list, wsfilt_nostdisp, ws);
98 WRegion *group_iter(WGroupIterTmp *tmp)
100 return stacking_iter_mgr(tmp);
104 WStacking *group_iter_nodes(WGroupIterTmp *tmp)
106 return stacking_iter_mgr_nodes(tmp);
110 WGroupIterTmp group_iter_default_tmp;
116 /*{{{ region dynfun implementations */
119 static void group_fit(WGroup *ws, const WRectangle *geom)
121 REGION_GEOM(ws)=*geom;
125 bool group_fitrep(WGroup *ws, WWindow *par, const WFitParams *fp)
128 WStacking *unweaved=NULL;
129 int xdiff=0, ydiff=0;
134 oldpar=REGION_PARENT(ws);
137 if(fp->mode®ION_FIT_WHATEVER)
139 REGION_GEOM(ws)=fp->g;
141 if(!region_same_rootwin((WRegion*)ws, (WRegion*)par))
144 if(ws->managed_stdisp!=NULL && ws->managed_stdisp->reg!=NULL)
145 region_detach_manager(ws->managed_stdisp->reg);
147 assert(ws->managed_stdisp==NULL);
149 xdiff=fp->g.x-REGION_GEOM(ws).x;
150 ydiff=fp->g.y-REGION_GEOM(ws).y;
152 region_unset_parent((WRegion*)ws);
153 XReparentWindow(ioncore_g.dpy, ws->dummywin, par->win, -1, -1);
154 region_set_parent((WRegion*)ws, par);
156 REGION_GEOM(ws).x=fp->g.x;
157 REGION_GEOM(ws).y=fp->g.y;
158 if(!(fp->mode®ION_FIT_WHATEVER)){
159 REGION_GEOM(ws).w=fp->g.w;
160 REGION_GEOM(ws).h=fp->g.h;
164 unweaved=stacking_unweave(&oldpar->stacking, wsfilt, (void*)ws);
167 FOR_ALL_NODES_IN_GROUP(ws, st, tmp){
173 g=REGION_GEOM(st->reg);
177 if(fp->mode®ION_FIT_WHATEVER){
180 fp2.g=REGION_GEOM(ws);
181 sizepolicy(&st->szplcy, st->reg, &g, REGION_RQGEOM_WEAK_ALL, &fp2);
184 if(!region_fitrep(st->reg, par, &fp2)){
185 warn(TR("Error reparenting %s."), region_name(st->reg));
186 region_detach_manager(st->reg);
191 stacking_weave(&par->stacking, &unweaved, FALSE);
197 static void group_map(WGroup *ws)
202 REGION_MARK_MAPPED(ws);
203 XMapWindow(ioncore_g.dpy, ws->dummywin);
205 FOR_ALL_MANAGED_BY_GROUP(ws, reg, tmp){
211 static void group_unmap(WGroup *ws)
216 REGION_MARK_UNMAPPED(ws);
217 XUnmapWindow(ioncore_g.dpy, ws->dummywin);
219 FOR_ALL_MANAGED_BY_GROUP(ws, reg, tmp){
225 static WStacking *find_to_focus(WGroup *ws, WStacking *st, bool group_only)
227 WStacking *stacking=group_get_stacking(ws);
232 return stacking_find_to_focus_mapped(stacking, st,
233 (group_only ? (WRegion*)ws : NULL));
237 static void group_do_set_focus(WGroup *ws, bool warp)
239 WStacking *st=find_to_focus(ws, ws->current_managed, FALSE);
241 if(st!=NULL && st->reg!=NULL)
242 region_do_set_focus(st->reg, warp);
244 region_finalise_focusing((WRegion*)ws, ws->dummywin, warp);
248 static bool group_managed_prepare_focus(WGroup *ws, WRegion *reg,
249 int flags, WPrepareFocusResult *res)
251 WMPlex *mplex=OBJ_CAST(REGION_MANAGER(ws), WMPlex);
252 WStacking *st=group_find_stacking(ws, reg);
258 WStacking *node=mplex_find_stacking(mplex, (WRegion*)ws);
263 return mplex_do_prepare_focus(mplex, node, st,
266 if(!region_prepare_focus((WRegion*)ws, flags, res))
269 st=find_to_focus(ws, st, FALSE);
274 if(ioncore_g.autoraise &&
275 !(flags®ION_GOTO_ENTERWINDOW) &&
276 st->level>STACKING_LEVEL_BOTTOM){
277 WStacking **stackingp=group_get_stackingp(ws);
278 stacking_restack(stackingp, st, None, NULL, NULL, FALSE);
284 return (res->reg==reg);
289 void group_managed_remove(WGroup *ws, WRegion *reg)
291 bool mcf=region_may_control_focus((WRegion*)ws);
292 WStacking *st, *next_st=NULL;
293 bool was_stdisp=FALSE, was_bottom=FALSE;
294 bool was_current=FALSE;
296 st=group_find_stacking(ws, reg);
301 group_do_set_bottom(ws, NULL);
304 if(st==ws->managed_stdisp){
305 ws->managed_stdisp=NULL;
309 if(st==ws->current_managed){
310 ws->current_managed=NULL;
314 next_st=stacking_unstack(REGION_PARENT(ws), st);
315 UNLINK_ITEM(ws->managed_list, st, mgr_next, mgr_prev);
316 stacking_unassoc(st);
320 region_unset_manager(reg, (WRegion*)ws);
322 if(!OBJ_IS_BEING_DESTROYED(ws) && was_current){
323 /* This may still potentially cause problems when focus
324 * change is pending. Perhaps we should use region_await_focus,
325 * if it is pointing to our child (and region_may_control_focus
326 * fail if it is pointing somewhere else).
328 WStacking *stf=find_to_focus(ws, next_st, TRUE);
329 if(stf!=NULL && mcf){
330 region_maybewarp_now(stf->reg, FALSE);
332 ws->current_managed=stf;
338 void group_managed_notify(WGroup *ws, WRegion *reg, WRegionNotify how)
340 if(how==ioncore_g.notifies.activated ||
341 how==ioncore_g.notifies.pseudoactivated){
342 ws->current_managed=group_find_stacking(ws, reg);
350 /*{{{ Create/destroy */
353 bool group_init(WGroup *ws, WWindow *par, const WFitParams *fp)
355 ws->current_managed=NULL;
356 ws->managed_stdisp=NULL;
358 ws->managed_list=NULL;
360 ws->dummywin=XCreateWindow(ioncore_g.dpy, par->win,
361 fp->g.x, fp->g.y, 1, 1, 0,
362 CopyFromParent, InputOnly,
363 CopyFromParent, 0, NULL);
364 if(ws->dummywin==None)
367 region_init(&ws->reg, par, fp);
368 region_register(&ws->reg);
370 XSelectInput(ioncore_g.dpy, ws->dummywin,
371 FocusChangeMask|KeyPressMask|KeyReleaseMask|
372 ButtonPressMask|ButtonReleaseMask);
373 XSaveContext(ioncore_g.dpy, ws->dummywin, ioncore_g.win_context,
376 ((WRegion*)ws)->flags|=REGION_GRAB_ON_PARENT;
378 region_add_bindmap((WRegion*)ws, ioncore_group_bindmap);
384 WGroup *create_group(WWindow *par, const WFitParams *fp)
386 CREATEOBJ_IMPL(WGroup, group, (p, par, fp));
390 void group_deinit(WGroup *ws)
395 if(ws->managed_stdisp!=NULL && ws->managed_stdisp->reg!=NULL){
396 group_managed_remove(ws, ws->managed_stdisp->reg);
397 assert(ws->managed_stdisp==NULL);
400 FOR_ALL_MANAGED_BY_GROUP(ws, reg, tmp){
401 destroy_obj((Obj*)reg);
404 assert(ws->managed_list==NULL);
406 XDeleteContext(ioncore_g.dpy, ws->dummywin, ioncore_g.win_context);
407 XDestroyWindow(ioncore_g.dpy, ws->dummywin);
410 region_deinit(&ws->reg);
415 bool group_rescue_clientwins(WGroup *ws, WRescueInfo *info)
419 group_iter_init_nostdisp(&tmp, ws);
421 return region_rescue_some_clientwins((WRegion*)ws, info,
422 (WRegionIterator*)group_iter,
433 void group_bottom_set(WGroup *grp)
435 CALL_DYN(group_bottom_set, grp, (grp));
439 static void group_do_set_bottom(WGroup *grp, WStacking *st)
441 WStacking *was=grp->bottom;
442 WStacking *std=grp->managed_stdisp;
446 if(!OBJ_IS_BEING_DESTROYED(grp)){
447 bool noremanage=((was==st) ||
448 (was==NULL && std==NULL) ||
449 (st!=NULL && st==std) ||
450 (st==NULL && was==std));
453 (st==NULL || HAS_DYN(st->reg, region_manage_stdisp))){
454 group_remanage_stdisp(grp);
457 group_bottom_set(grp);
463 * Sets the `bottom' of \var{ws}. The region \var{reg} must already
464 * be managed by \var{ws}, unless \code{nil}.
467 bool group_set_bottom(WGroup *ws, WRegion *reg)
472 st=group_find_stacking(ws, reg);
478 group_do_set_bottom(ws, st);
485 * Returns the `bottom' of \var{ws}.
489 WRegion *group_bottom(WGroup *ws)
491 return (ws->bottom!=NULL ? ws->bottom->reg : NULL);
501 WStacking *group_do_add_managed(WGroup *ws, WRegion *reg, int level,
505 CALL_DYN_RET(st, WStacking*, group_do_add_managed, ws,
506 (ws, reg, level, szplcy));
511 WStacking *group_do_add_managed_default(WGroup *ws, WRegion *reg, int level,
514 WStacking *st=NULL, *tmp=NULL;
515 Window bottom=None, top=None;
516 WStacking **stackingp=group_get_stackingp(ws);
522 st=create_stacking();
527 if(!stacking_assoc(st, reg)){
532 frame=OBJ_CAST(reg, WFrame);
534 WFrameMode m=frame_mode(frame);
535 if(m==FRAME_MODE_TILED || m==FRAME_MODE_TILED_ALT)
536 frame_set_mode(frame, FRAME_MODE_FLOATING);
542 LINK_ITEM_FIRST(tmp, st, next, prev);
543 stacking_weave(stackingp, &tmp, FALSE);
546 LINK_ITEM(ws->managed_list, st, mgr_next, mgr_prev);
547 region_set_manager(reg, (WRegion*)ws);
549 if(region_is_fully_mapped((WRegion*)ws))
556 static void geom_group_to_parent(WGroup *ws, const WRectangle *g,
559 wg->x=g->x+REGION_GEOM(ws).x;
560 wg->y=g->y+REGION_GEOM(ws).y;
561 wg->w=maxof(1, g->w);
562 wg->h=maxof(1, g->h);
566 static int group_must_focus(WGroup *ws, WStacking *st)
568 WStacking *stacking=group_get_stacking(ws);
570 return (stacking!=NULL && stacking_must_focus(stacking, st));
574 bool group_do_attach_final(WGroup *ws,
576 const WGroupAttachParams *param)
578 WStacking *st, *stabove=NULL;
587 if(param->stack_above!=NULL)
588 stabove=group_find_stacking(ws, param->stack_above);
594 : STACKING_LEVEL_NORMAL));
597 szplcy=(param->szplcy_set
600 ? SIZEPOLICY_FULL_EXACT
601 : SIZEPOLICY_UNCONSTRAINED));
603 weak=(param->geom_weak_set
607 : REGION_RQGEOM_WEAK_ALL));
610 geom_group_to_parent(ws, ¶m->geom, &g);
614 /* If the requested geometry does not overlap the workspaces's geometry,
615 * position request is never honoured.
617 if((g.x+g.w<=REGION_GEOM(ws).x) ||
618 (g.x>=REGION_GEOM(ws).x+REGION_GEOM(ws).w)){
619 weak|=REGION_RQGEOM_WEAK_X;
622 if((g.y+g.h<=REGION_GEOM(ws).y) ||
623 (g.y>=REGION_GEOM(ws).y+REGION_GEOM(ws).h)){
624 weak|=REGION_RQGEOM_WEAK_Y;
627 if(weak&(REGION_RQGEOM_WEAK_X|REGION_RQGEOM_WEAK_Y) &&
628 (szplcy==SIZEPOLICY_UNCONSTRAINED ||
629 szplcy==SIZEPOLICY_FREE ||
630 szplcy==SIZEPOLICY_FREE_GLUE /* without flags */)){
631 /* TODO: use 'weak'? */
632 group_calc_placement(ws, level, &g);
635 fp.g=REGION_GEOM(ws);
636 fp.mode=REGION_FIT_EXACT;
638 sizepolicy(&szplcy, reg, &g, weak, &fp);
640 if(rectangle_compare(&fp.g, ®ION_GEOM(reg))!=RECTANGLE_SAME)
641 region_fitrep(reg, NULL, &fp);
644 st=group_do_add_managed(ws, reg, level, szplcy);
653 group_do_set_bottom(ws, st);
656 sw=((param->switchto_set ? param->switchto : ioncore_g.switchto_new)
657 ? st==find_to_focus(ws, st, FALSE)
658 : group_must_focus(ws, st));
661 if(region_may_control_focus((WRegion*)ws))
662 region_set_focus(st->reg);
664 ws->current_managed=st;
671 WRegion *group_do_attach(WGroup *ws,
672 /*const*/ WGroupAttachParams *param,
673 WRegionAttachData *data)
679 if(ws->bottom!=NULL && param->bottom){
680 warn(TR("'bottom' already set."));
684 par=REGION_PARENT(ws);
688 geom_group_to_parent(ws, ¶m->geom, &fp.g);
689 fp.mode=REGION_FIT_EXACT;
691 fp.g=REGION_GEOM(ws);
692 fp.mode=REGION_FIT_BOUNDS|REGION_FIT_WHATEVER;
695 return region_attach_helper((WRegion*) ws, par, &fp,
696 (WRegionDoAttachFn*)group_do_attach_final,
697 /*(const WRegionAttachParams*)*/param, data);
698 /* ^^^^ doesn't seem to work. */
702 void group_get_attach_params(WGroup *ws, ExtlTab tab,
703 WGroupAttachParams *par)
716 if(extl_table_is_bool_set(tab, "bottom")){
717 par->level=STACKING_LEVEL_BOTTOM;
722 if(extl_table_gets_i(tab, "level", &tmp)){
729 if(!par->level_set && extl_table_is_bool_set(tab, "modal")){
730 par->level=STACKING_LEVEL_MODAL1;
734 if(extl_table_gets_b(tab, "switchto", &tmpb)){
735 par->switchto=(tmpb!=0);
739 if(extl_table_gets_i(tab, "sizepolicy", &tmp)){
742 }else if(extl_table_gets_s(tab, "sizepolicy", &tmps)){
743 if(string2sizepolicy(tmps, &par->szplcy))
748 if(extl_table_gets_t(tab, "geom", &g)){
751 if(extl_table_gets_i(g, "x", &(par->geom.x)))
753 if(extl_table_gets_i(g, "y", &(par->geom.y)))
755 if(extl_table_gets_i(g, "w", &(par->geom.w)))
757 if(extl_table_gets_i(g, "h", &(par->geom.h)))
770 * Attach and reparent existing region \var{reg} to \var{ws}.
771 * The table \var{param} may contain the fields \var{index} and
772 * \var{switchto} that are interpreted as for \fnref{WMPlex.attach_new}.
775 WRegion *group_attach(WGroup *ws, WRegion *reg, ExtlTab param)
777 WGroupAttachParams par=GROUPATTACHPARAMS_INIT;
778 WRegionAttachData data;
783 group_get_attach_params(ws, param, &par);
785 data.type=REGION_ATTACH_REPARENT;
788 return group_do_attach(ws, &par, &data);
793 * Create a new region to be managed by \var{ws}. At least the following
794 * fields in \var{param} are understood:
796 * \begin{tabularx}{\linewidth}{lX}
797 * \tabhead{Field & Description}
798 * \var{type} & (string) Class of the object to be created. Mandatory. \\
799 * \var{name} & (string) Name of the object to be created. \\
800 * \var{switchto} & (boolean) Should the region be switched to? \\
801 * \var{level} & (integer) Stacking level; default is 1. \\
802 * \var{modal} & (boolean) Make object modal; ignored if level is set. \\
803 * \var{sizepolicy} & (string) Size policy; see Section \ref{sec:sizepolicies}. \\
804 * \var{bottom} & (boolean) Mark the attached region as the
805 * ``bottom'' of \var{ws}. \\
808 * In addition parameters to the region to be created are passed in this
812 WRegion *group_attach_new(WGroup *ws, ExtlTab param)
814 WGroupAttachParams par=GROUPATTACHPARAMS_INIT;
815 WRegionAttachData data;
817 group_get_attach_params(ws, param, &par);
819 data.type=REGION_ATTACH_LOAD;
822 return group_do_attach(ws, &par, &data);
829 /*{{{ Status display support */
832 static int stdisp_szplcy(const WMPlexSTDispInfo *di, WRegion *stdisp)
835 int policy=0, gravity=0;
838 if(region_orientation(stdisp)==REGION_ORIENTATION_VERTICAL){
839 if(pos==MPLEX_STDISP_TL || pos==MPLEX_STDISP_BL)
840 policy=SIZEPOLICY_STRETCH_LEFT;
842 policy=SIZEPOLICY_STRETCH_RIGHT;
844 if(pos==MPLEX_STDISP_TL || pos==MPLEX_STDISP_TR)
845 policy=SIZEPOLICY_STRETCH_TOP;
847 policy=SIZEPOLICY_STRETCH_BOTTOM;
850 policy=SIZEPOLICY_GRAVITY;
853 if(pos==MPLEX_STDISP_TL)
854 gravity=SIZEPOLICY_VERT_TOP|SIZEPOLICY_HORIZ_LEFT;
855 else if(pos==MPLEX_STDISP_BL)
856 gravity=SIZEPOLICY_VERT_BOTTOM|SIZEPOLICY_HORIZ_LEFT;
857 else if(pos==MPLEX_STDISP_TR)
858 gravity=SIZEPOLICY_VERT_TOP|SIZEPOLICY_HORIZ_RIGHT;
859 else /*if(pos=MPLEX_STDISP_BR)*/
860 gravity=SIZEPOLICY_VERT_BOTTOM|SIZEPOLICY_HORIZ_RIGHT;
862 return (policy|gravity);
866 void group_manage_stdisp(WGroup *ws, WRegion *stdisp,
867 const WMPlexSTDispInfo *di)
871 WRegion *b=(ws->bottom==NULL ? NULL : ws->bottom->reg);
873 /* Check if 'bottom' wants to manage the stdisp. */
875 && !OBJ_IS_BEING_DESTROYED(b)
876 && HAS_DYN(b, region_manage_stdisp)){
877 region_manage_stdisp(b, stdisp, di);
878 if(REGION_MANAGER(stdisp)==b)
884 szplcy=stdisp_szplcy(di, stdisp)|SIZEPOLICY_SHRUNK;
886 if(ws->managed_stdisp!=NULL && ws->managed_stdisp->reg==stdisp){
887 if(ws->managed_stdisp->szplcy==szplcy)
889 ws->managed_stdisp->szplcy=szplcy;
891 region_detach_manager(stdisp);
892 ws->managed_stdisp=group_do_add_managed(ws, stdisp,
893 STACKING_LEVEL_ON_TOP,
897 stdisp->flags|=REGION_SKIP_FOCUS;
899 fp.g=REGION_GEOM(ws);
900 sizepolicy(&ws->managed_stdisp->szplcy, stdisp, NULL, 0, &fp);
902 region_fitrep(stdisp, NULL, &fp);
906 static void group_remanage_stdisp(WGroup *ws)
908 WMPlex *mplex=OBJ_CAST(REGION_MANAGER(ws), WMPlex);
911 mplex->mx_current!=NULL &&
912 mplex->mx_current->st->reg==(WRegion*)ws){
913 mplex_remanage_stdisp(mplex);
921 /*{{{ Geometry requests */
924 void group_managed_rqgeom(WGroup *ws, WRegion *reg,
925 const WRQGeomParams *rq,
931 st=group_find_stacking(ws, reg);
935 fp.mode=REGION_FIT_EXACT;
937 fp.g=REGION_GEOM(ws);
938 sizepolicy(&st->szplcy, reg, &rq->geom, rq->flags, &fp);
944 if(!(rq->flags®ION_RQGEOM_TRYONLY))
945 region_fitrep(reg, NULL, &fp);
949 void group_managed_rqgeom_absolute(WGroup *grp, WRegion *sub,
950 const WRQGeomParams *rq,
953 if(grp->bottom!=NULL && grp->bottom->reg==sub){
954 region_rqgeom((WRegion*)grp, rq, geomret);
955 if(!(rq->flags®ION_RQGEOM_TRYONLY) && geomret!=NULL)
956 *geomret=REGION_GEOM(sub);
958 WRQGeomParams rq2=*rq;
959 rq2.flags&=~REGION_RQGEOM_ABSOLUTE;
961 region_managed_rqgeom((WRegion*)grp, sub, &rq2, geomret);
972 static WStacking *nxt(WGroup *ws, WStacking *st, bool wrap)
974 return (st->mgr_next!=NULL
976 : (wrap ? ws->managed_list : NULL));
980 static WStacking *prv(WGroup *ws, WStacking *st, bool wrap)
982 return (st!=ws->managed_list
984 : (wrap ? st->mgr_prev : NULL));
988 typedef WStacking *NxtFn(WGroup *ws, WStacking *st, bool wrap);
991 static bool focusable(WGroup *ws, WStacking *st, uint min_level)
993 return (st->reg!=NULL
994 && REGION_IS_MAPPED(st->reg)
995 && !(st->reg->flags®ION_SKIP_FOCUS)
996 && st->level>=min_level);
1000 static WStacking *do_get_next(WGroup *ws, WStacking *sti,
1001 NxtFn *fn, bool wrap, bool sti_ok)
1003 WStacking *st, *stacking;
1006 stacking=group_get_stacking(ws);
1009 min_level=stacking_min_level_mapped(stacking);
1013 st=fn(ws, st, wrap);
1015 if(st==NULL || st==sti)
1018 if(focusable(ws, st, min_level))
1022 if(sti_ok && focusable(ws, sti, min_level))
1029 static WStacking *group_do_navi_first(WGroup *ws, WRegionNavi nh)
1031 WStacking *lst=ws->managed_list;
1036 if(nh==REGION_NAVI_ANY &&
1037 ws->current_managed!=NULL &&
1038 ws->current_managed->reg!=NULL){
1039 return ws->current_managed;
1042 if(nh==REGION_NAVI_ANY || nh==REGION_NAVI_END ||
1043 nh==REGION_NAVI_BOTTOM || nh==REGION_NAVI_RIGHT){
1044 return do_get_next(ws, lst, prv, TRUE, TRUE);
1046 return do_get_next(ws, lst->mgr_prev, nxt, TRUE, TRUE);
1051 static WRegion *group_navi_first(WGroup *ws, WRegionNavi nh,
1052 WRegionNaviData *data)
1054 WStacking *st=group_do_navi_first(ws, nh);
1056 return region_navi_cont(&ws->reg, (st!=NULL ? st->reg : NULL), data);
1060 static WStacking *group_do_navi_next(WGroup *ws, WStacking *st,
1061 WRegionNavi nh, bool wrap)
1064 return group_do_navi_first(ws, nh);
1066 if(nh==REGION_NAVI_ANY || nh==REGION_NAVI_END ||
1067 nh==REGION_NAVI_BOTTOM || nh==REGION_NAVI_RIGHT){
1068 return do_get_next(ws, st, nxt, wrap, FALSE);
1070 return do_get_next(ws, st, prv, wrap, FALSE);
1074 static WRegion *group_navi_next(WGroup *ws, WRegion *reg,
1075 WRegionNavi nh, WRegionNaviData *data)
1077 WStacking *st=group_find_stacking(ws, reg);
1079 st=group_do_navi_next(ws, st, nh, FALSE);
1081 return region_navi_cont(&ws->reg, (st!=NULL ? st->reg : NULL), data);
1092 * Note: Managed objects are considered to be stacked separately from the
1093 * group, slightly violating expectations.
1096 void group_stacking(WGroup *ws, Window *bottomret, Window *topret)
1098 Window win=region_xwindow((WRegion*)ws);
1105 void group_restack(WGroup *ws, Window other, int mode)
1109 win=region_xwindow((WRegion*)ws);
1111 xwindow_restack(win, other, mode);
1118 WStacking *group_find_stacking(WGroup *ws, WRegion *r)
1120 if(r==NULL || REGION_MANAGER(r)!=(WRegion*)ws)
1123 return ioncore_find_stacking(r);
1127 static WStacking *find_stacking_if_not_on_ws(WGroup *ws, Window w)
1129 WRegion *r=xwindow_region_of(w);
1133 if(REGION_MANAGER(r)==(WRegion*)ws)
1135 st=group_find_stacking(ws, r);
1138 r=REGION_MANAGER(r);
1145 bool group_managed_rqorder(WGroup *grp, WRegion *reg, WRegionOrder order)
1147 WStacking **stackingp=group_get_stackingp(grp);
1150 if(stackingp==NULL || *stackingp==NULL)
1153 st=group_find_stacking(grp, reg);
1158 stacking_restack(stackingp, st, None, NULL, NULL,
1159 (order!=REGION_ORDER_FRONT));
1172 * Iterate over managed regions of \var{ws} until \var{iterfn} returns
1174 * The function itself returns \code{true} if it reaches the end of list
1175 * without this happening.
1179 bool group_managed_i(WGroup *ws, ExtlFn iterfn)
1182 group_iter_init(&tmp, ws);
1184 return extl_iter_objlist_(iterfn, (ObjIterator*)group_iter, &tmp);
1188 WRegion* group_current(WGroup *ws)
1190 return (ws->current_managed!=NULL ? ws->current_managed->reg : NULL);
1194 void group_size_hints(WGroup *ws, WSizeHints *hints_ret)
1196 if(ws->bottom==NULL || ws->bottom->reg==NULL){
1197 sizehints_clear(hints_ret);
1199 region_size_hints(ws->bottom->reg, hints_ret);
1200 hints_ret->no_constrain=TRUE;
1205 Window group_xwindow(const WGroup *ws)
1207 return ws->dummywin;
1212 * Returns the group of \var{reg}, if it is managed by one,
1213 * and \var{reg} itself otherwise.
1215 /*EXTL_EXPORT_MEMBER
1216 WRegion *region_group_of(WRegion *reg)
1218 WRegion *mgr=REGION_MANAGER(reg);
1220 return (OBJ_IS(mgr, WGroup) ? mgr : reg);
1225 * Returns the group of \var{reg}, if \var{reg} is its bottom,
1226 * and \var{reg} itself otherwise.
1229 WRegion *region_groupleader_of(WRegion *reg)
1231 WGroup *grp=REGION_MANAGER_CHK(reg, WGroup);
1233 return ((grp!=NULL && group_bottom(grp)==reg)
1245 static ExtlTab group_get_configuration(WGroup *ws)
1247 ExtlTab tab, mgds, subtab, g;
1254 tab=region_get_base_configuration((WRegion*)ws);
1256 mgds=extl_create_table();
1258 extl_table_sets_t(tab, "managed", mgds);
1260 /* TODO: stacking order messed up */
1262 FOR_ALL_NODES_IN_GROUP(ws, st, tmp){
1266 subtab=region_get_configuration(st->reg);
1268 if(subtab!=extl_table_none()){
1269 extl_table_sets_s(subtab, "sizepolicy",
1270 sizepolicy2string(st->szplcy));
1271 extl_table_sets_i(subtab, "level", st->level);
1273 tmpg=REGION_GEOM(st->reg);
1274 tmpg.x-=REGION_GEOM(ws).x;
1275 tmpg.y-=REGION_GEOM(ws).y;
1277 g=extl_table_from_rectangle(&tmpg);
1278 extl_table_sets_t(subtab, "geom", g);
1279 extl_unref_table(g);
1282 extl_table_sets_b(subtab, "bottom", TRUE);
1284 extl_table_seti_t(mgds, ++n, subtab);
1285 extl_unref_table(subtab);
1289 extl_unref_table(mgds);
1295 void group_do_load(WGroup *ws, ExtlTab tab)
1297 ExtlTab substab, subtab;
1300 if(extl_table_gets_t(tab, "managed", &substab)){
1301 n=extl_table_get_n(substab);
1302 for(i=1; i<=n; i++){
1303 if(extl_table_geti_t(substab, i, &subtab)){
1304 group_attach_new(ws, subtab);
1305 extl_unref_table(subtab);
1309 extl_unref_table(substab);
1314 WRegion *group_load(WWindow *par, const WFitParams *fp, ExtlTab tab)
1318 ws=create_group(par, fp);
1323 group_do_load(ws, tab);
1325 return (WRegion*)ws;
1332 /*{{{ Dynamic function table and class implementation */
1335 static DynFunTab group_dynfuntab[]={
1336 {(DynFun*)region_fitrep,
1337 (DynFun*)group_fitrep},
1345 {(DynFun*)region_managed_prepare_focus,
1346 (DynFun*)group_managed_prepare_focus},
1348 {region_do_set_focus,
1349 group_do_set_focus},
1351 {region_managed_notify,
1352 group_managed_notify},
1354 {region_managed_remove,
1355 group_managed_remove},
1357 {(DynFun*)region_get_configuration,
1358 (DynFun*)group_get_configuration},
1360 {(DynFun*)region_current,
1361 (DynFun*)group_current},
1363 {(DynFun*)region_rescue_clientwins,
1364 (DynFun*)group_rescue_clientwins},
1372 {(DynFun*)region_managed_get_pholder,
1373 (DynFun*)group_managed_get_pholder},
1375 {region_managed_rqgeom,
1376 group_managed_rqgeom},
1378 {region_managed_rqgeom_absolute,
1379 group_managed_rqgeom_absolute},
1381 {(DynFun*)group_do_add_managed,
1382 (DynFun*)group_do_add_managed_default},
1387 {(DynFun*)region_xwindow,
1388 (DynFun*)group_xwindow},
1390 {(DynFun*)region_navi_first,
1391 (DynFun*)group_navi_first},
1393 {(DynFun*)region_navi_next,
1394 (DynFun*)group_navi_next},
1396 {(DynFun*)region_managed_rqorder,
1397 (DynFun*)group_managed_rqorder},
1404 IMPLCLASS(WGroup, WRegion, group_deinit, group_dynfuntab);