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);
49 /*{{{ Stacking list stuff */
52 WStacking *group_get_stacking(WGroup *ws)
54 WWindow *par=REGION_PARENT(ws);
58 : window_get_stacking(par));
62 WStacking **group_get_stackingp(WGroup *ws)
64 WWindow *par=REGION_PARENT(ws);
68 : window_get_stackingp(par));
72 static bool wsfilt(WStacking *st, void *ws)
74 return (st->reg!=NULL && REGION_MANAGER(st->reg)==(WRegion*)ws);
78 static bool wsfilt_nostdisp(WStacking *st, void *ws)
80 return (wsfilt(st, ws) && ((WGroup*)ws)->managed_stdisp!=st);
84 void group_iter_init(WGroupIterTmp *tmp, WGroup *ws)
86 stacking_iter_mgr_init(tmp, ws->managed_list, NULL, ws);
90 void group_iter_init_nostdisp(WGroupIterTmp *tmp, WGroup *ws)
92 stacking_iter_mgr_init(tmp, ws->managed_list, wsfilt_nostdisp, ws);
96 WRegion *group_iter(WGroupIterTmp *tmp)
98 return stacking_iter_mgr(tmp);
102 WStacking *group_iter_nodes(WGroupIterTmp *tmp)
104 return stacking_iter_mgr_nodes(tmp);
108 WGroupIterTmp group_iter_default_tmp;
114 /*{{{ region dynfun implementations */
117 static void group_fit(WGroup *ws, const WRectangle *geom)
119 REGION_GEOM(ws)=*geom;
123 bool group_fitrep(WGroup *ws, WWindow *par, const WFitParams *fp)
126 WStacking *unweaved=NULL;
127 int xdiff=0, ydiff=0;
132 oldpar=REGION_PARENT(ws);
135 if(fp->mode®ION_FIT_WHATEVER)
137 REGION_GEOM(ws)=fp->g;
139 if(!region_same_rootwin((WRegion*)ws, (WRegion*)par))
142 if(ws->managed_stdisp!=NULL && ws->managed_stdisp->reg!=NULL)
143 region_detach_manager(ws->managed_stdisp->reg);
145 assert(ws->managed_stdisp==NULL);
147 xdiff=fp->g.x-REGION_GEOM(ws).x;
148 ydiff=fp->g.y-REGION_GEOM(ws).y;
150 region_unset_parent((WRegion*)ws);
151 XReparentWindow(ioncore_g.dpy, ws->dummywin, par->win, -1, -1);
152 region_set_parent((WRegion*)ws, par);
154 REGION_GEOM(ws).x=fp->g.x;
155 REGION_GEOM(ws).y=fp->g.y;
156 if(!(fp->mode®ION_FIT_WHATEVER)){
157 REGION_GEOM(ws).w=fp->g.w;
158 REGION_GEOM(ws).h=fp->g.h;
162 unweaved=stacking_unweave(&oldpar->stacking, wsfilt, (void*)ws);
165 FOR_ALL_NODES_IN_GROUP(ws, st, tmp){
171 g=REGION_GEOM(st->reg);
175 if(fp->mode®ION_FIT_WHATEVER){
178 fp2.g=REGION_GEOM(ws);
179 sizepolicy(&st->szplcy, st->reg, &g, REGION_RQGEOM_WEAK_ALL, &fp2);
182 if(!region_fitrep(st->reg, par, &fp2)){
183 warn(TR("Error reparenting %s."), region_name(st->reg));
184 region_detach_manager(st->reg);
189 stacking_weave(&par->stacking, &unweaved, FALSE);
195 static void group_map(WGroup *ws)
200 REGION_MARK_MAPPED(ws);
201 XMapWindow(ioncore_g.dpy, ws->dummywin);
203 FOR_ALL_MANAGED_BY_GROUP(ws, reg, tmp){
209 static void group_unmap(WGroup *ws)
214 REGION_MARK_UNMAPPED(ws);
215 XUnmapWindow(ioncore_g.dpy, ws->dummywin);
217 FOR_ALL_MANAGED_BY_GROUP(ws, reg, tmp){
223 static WStacking *find_to_focus(WGroup *ws, WStacking *st, bool group_only)
225 WStacking *stacking=group_get_stacking(ws);
230 return stacking_find_to_focus_mapped(stacking, st,
231 (group_only ? (WRegion*)ws : NULL));
235 static bool group_refocus_(WGroup *ws, WStacking *st)
237 if(st!=ws->current_managed && st->reg!=NULL){
238 if(region_may_control_focus((WRegion*)ws))
239 region_set_focus(st->reg);
241 ws->current_managed=st;
249 static void group_do_set_focus(WGroup *ws, bool warp)
251 WStacking *st=ws->current_managed;
253 if(st==NULL || st->reg==NULL)
254 st=find_to_focus(ws, NULL, TRUE);
256 if(st!=NULL && st->reg!=NULL)
257 region_do_set_focus(st->reg, warp);
259 region_finalise_focusing((WRegion*)ws, ws->dummywin, warp);
263 static bool group_managed_prepare_focus(WGroup *ws, WRegion *reg,
264 int flags, WPrepareFocusResult *res)
266 WMPlex *mplex=OBJ_CAST(REGION_MANAGER(ws), WMPlex);
267 WStacking *st=group_find_stacking(ws, reg);
273 WStacking *node=mplex_find_stacking(mplex, (WRegion*)ws);
278 return mplex_do_prepare_focus(mplex, node, st,
281 if(!region_prepare_focus((WRegion*)ws, flags, res))
284 st=find_to_focus(ws, st, FALSE);
289 if(ioncore_g.autoraise &&
290 !(flags®ION_GOTO_ENTERWINDOW) &&
291 st->level>STACKING_LEVEL_BOTTOM){
292 WStacking **stackingp=group_get_stackingp(ws);
293 stacking_restack(stackingp, st, None, NULL, NULL, FALSE);
299 return (res->reg==reg);
304 void group_managed_remove(WGroup *ws, WRegion *reg)
306 bool mcf=region_may_control_focus((WRegion*)ws);
307 WStacking *st, *next_st=NULL;
308 bool was_stdisp=FALSE, was_bottom=FALSE;
309 bool was_current=FALSE;
311 st=group_find_stacking(ws, reg);
314 next_st=stacking_unstack(REGION_PARENT(ws), st);
316 UNLINK_ITEM(ws->managed_list, st, mgr_next, mgr_prev);
318 if(st==ws->managed_stdisp){
319 ws->managed_stdisp=NULL;
328 if(st==ws->current_managed){
329 ws->current_managed=NULL;
333 stacking_unassoc(st);
337 region_unset_manager(reg, (WRegion*)ws);
339 if(!OBJ_IS_BEING_DESTROYED(ws)){
340 if(was_bottom && !was_stdisp && ws->managed_stdisp==NULL){
341 /* We should probably be managing any stdisp, that 'bottom'
344 group_remanage_stdisp(ws);
348 /* This may still potentially cause problems when focus
349 * change is pending. Perhaps we should use region_await_focus,
350 * if it is pointing to our child (and region_may_control_focus
351 * fail if it is pointing somewhere else).
353 WStacking *stf=find_to_focus(ws, next_st, TRUE);
354 if(stf!=NULL && mcf){
355 region_maybewarp_now(stf->reg, FALSE);
357 ws->current_managed=stf;
364 void group_managed_notify(WGroup *ws, WRegion *reg, WRegionNotify how)
366 if(how==ioncore_g.notifies.activated ||
367 how==ioncore_g.notifies.pseudoactivated){
368 ws->current_managed=group_find_stacking(ws, reg);
376 /*{{{ Create/destroy */
379 bool group_init(WGroup *ws, WWindow *par, const WFitParams *fp)
381 ws->current_managed=NULL;
382 ws->managed_stdisp=NULL;
384 ws->managed_list=NULL;
386 ws->dummywin=XCreateWindow(ioncore_g.dpy, par->win,
387 fp->g.x, fp->g.y, 1, 1, 0,
388 CopyFromParent, InputOnly,
389 CopyFromParent, 0, NULL);
390 if(ws->dummywin==None)
393 region_init(&ws->reg, par, fp);
394 region_register(&ws->reg);
396 XSelectInput(ioncore_g.dpy, ws->dummywin,
397 FocusChangeMask|KeyPressMask|KeyReleaseMask|
398 ButtonPressMask|ButtonReleaseMask);
399 XSaveContext(ioncore_g.dpy, ws->dummywin, ioncore_g.win_context,
402 ((WRegion*)ws)->flags|=REGION_GRAB_ON_PARENT;
404 region_add_bindmap((WRegion*)ws, ioncore_group_bindmap);
410 WGroup *create_group(WWindow *par, const WFitParams *fp)
412 CREATEOBJ_IMPL(WGroup, group, (p, par, fp));
416 void group_deinit(WGroup *ws)
421 if(ws->managed_stdisp!=NULL && ws->managed_stdisp->reg!=NULL){
422 group_managed_remove(ws, ws->managed_stdisp->reg);
423 assert(ws->managed_stdisp==NULL);
426 FOR_ALL_MANAGED_BY_GROUP(ws, reg, tmp){
427 destroy_obj((Obj*)reg);
430 assert(ws->managed_list==NULL);
432 XDeleteContext(ioncore_g.dpy, ws->dummywin, ioncore_g.win_context);
433 XDestroyWindow(ioncore_g.dpy, ws->dummywin);
436 region_deinit(&ws->reg);
441 bool group_rescue_clientwins(WGroup *ws, WRescueInfo *info)
445 group_iter_init_nostdisp(&tmp, ws);
447 return region_rescue_some_clientwins((WRegion*)ws, info,
448 (WRegionIterator*)group_iter,
453 static bool group_empty_for_bottom_stdisp(WGroup *ws)
458 FOR_ALL_NODES_IN_GROUP(ws, st, tmp){
459 if(st!=ws->bottom && st!=ws->managed_stdisp)
467 static WRegion *group_managed_disposeroot(WGroup *ws, WRegion *reg)
469 if(group_bottom(ws)==reg){
470 if(group_empty_for_bottom_stdisp(ws))
471 return region_disposeroot((WRegion*)ws);
484 static void group_do_set_bottom(WGroup *grp, WStacking *st)
486 WStacking *was=grp->bottom;
491 if(st==NULL || HAS_DYN(st->reg, region_manage_stdisp))
492 group_remanage_stdisp(grp);
499 * Sets the `bottom' of \var{ws}. The region \var{reg} must already
500 * be managed by \var{ws}, unless \code{nil}.
503 bool group_set_bottom(WGroup *ws, WRegion *reg)
508 st=group_find_stacking(ws, reg);
514 group_do_set_bottom(ws, st);
521 * Returns the `bottom' of \var{ws}.
525 WRegion *group_bottom(WGroup *ws)
527 return (ws->bottom!=NULL ? ws->bottom->reg : NULL);
537 WStacking *group_do_add_managed(WGroup *ws, WRegion *reg, int level,
541 CALL_DYN_RET(st, WStacking*, group_do_add_managed, ws,
542 (ws, reg, level, szplcy));
547 WStacking *group_do_add_managed_default(WGroup *ws, WRegion *reg, int level,
550 WStacking *st=NULL, *tmp=NULL;
551 Window bottom=None, top=None;
552 WStacking **stackingp=group_get_stackingp(ws);
558 st=create_stacking();
563 if(!stacking_assoc(st, reg)){
568 frame=OBJ_CAST(reg, WFrame);
570 WFrameMode m=frame_mode(frame);
571 if(m==FRAME_MODE_TILED || m==FRAME_MODE_TILED_ALT)
572 frame_set_mode(frame, FRAME_MODE_FLOATING);
578 LINK_ITEM_FIRST(tmp, st, next, prev);
579 stacking_weave(stackingp, &tmp, FALSE);
582 LINK_ITEM(ws->managed_list, st, mgr_next, mgr_prev);
583 region_set_manager(reg, (WRegion*)ws);
585 if(region_is_fully_mapped((WRegion*)ws))
592 static void geom_group_to_parent(WGroup *ws, const WRectangle *g,
595 wg->x=g->x+REGION_GEOM(ws).x;
596 wg->y=g->y+REGION_GEOM(ws).y;
597 wg->w=maxof(1, g->w);
598 wg->h=maxof(1, g->h);
602 bool group_do_attach_final(WGroup *ws,
604 const WGroupAttachParams *param)
606 WStacking *st, *stabove=NULL;
615 if(param->stack_above!=NULL)
616 stabove=group_find_stacking(ws, param->stack_above);
622 : STACKING_LEVEL_NORMAL));
625 szplcy=(param->szplcy_set
628 ? SIZEPOLICY_FULL_EXACT
629 : SIZEPOLICY_UNCONSTRAINED));
631 weak=(param->geom_weak_set
635 : REGION_RQGEOM_WEAK_ALL));
638 geom_group_to_parent(ws, ¶m->geom, &g);
642 /* If the requested geometry does not overlap the workspaces's geometry,
643 * position request is never honoured.
645 if((g.x+g.w<=REGION_GEOM(ws).x) ||
646 (g.x>=REGION_GEOM(ws).x+REGION_GEOM(ws).w)){
647 weak|=REGION_RQGEOM_WEAK_X;
650 if((g.y+g.h<=REGION_GEOM(ws).y) ||
651 (g.y>=REGION_GEOM(ws).y+REGION_GEOM(ws).h)){
652 weak|=REGION_RQGEOM_WEAK_Y;
655 if(weak&(REGION_RQGEOM_WEAK_X|REGION_RQGEOM_WEAK_Y) &&
656 (szplcy==SIZEPOLICY_UNCONSTRAINED ||
657 szplcy==SIZEPOLICY_FREE ||
658 szplcy==SIZEPOLICY_FREE_GLUE /* without flags */)){
659 /* TODO: use 'weak'? */
660 group_calc_placement(ws, level, &g);
663 fp.g=REGION_GEOM(ws);
664 fp.mode=REGION_FIT_EXACT;
666 sizepolicy(&szplcy, reg, &g, weak, &fp);
668 if(rectangle_compare(&fp.g, ®ION_GEOM(reg))!=RECTANGLE_SAME)
669 region_fitrep(reg, NULL, &fp);
672 st=group_do_add_managed(ws, reg, level, szplcy);
681 group_do_set_bottom(ws, st);
684 sw=(param->switchto_set ? param->switchto : ioncore_g.switchto_new);
686 if(sw || st->level>=STACKING_LEVEL_MODAL1){
687 WStacking *stf=find_to_focus(ws, st, FALSE);
690 /* Ok, the new region can be focused */
691 group_refocus_(ws, stf);
699 WRegion *group_do_attach(WGroup *ws,
700 /*const*/ WGroupAttachParams *param,
701 WRegionAttachData *data)
707 if(ws->bottom!=NULL && param->bottom){
708 warn(TR("'bottom' already set."));
712 par=REGION_PARENT(ws);
716 geom_group_to_parent(ws, ¶m->geom, &fp.g);
717 fp.mode=REGION_FIT_EXACT;
719 fp.g=REGION_GEOM(ws);
720 fp.mode=REGION_FIT_BOUNDS|REGION_FIT_WHATEVER;
723 return region_attach_helper((WRegion*) ws, par, &fp,
724 (WRegionDoAttachFn*)group_do_attach_final,
725 /*(const WRegionAttachParams*)*/param, data);
726 /* ^^^^ doesn't seem to work. */
730 static void get_params(WGroup *ws, ExtlTab tab, WGroupAttachParams *par)
742 if(extl_table_is_bool_set(tab, "bottom")){
743 par->level=STACKING_LEVEL_BOTTOM;
748 if(extl_table_gets_i(tab, "level", &tmp)){
750 par->level_set=STACKING_LEVEL_NORMAL;
755 if(!par->level_set && extl_table_is_bool_set(tab, "modal")){
756 par->level=STACKING_LEVEL_MODAL1;
760 if(extl_table_is_bool_set(tab, "switchto"))
763 if(extl_table_gets_i(tab, "sizepolicy", &tmp)){
766 }else if(extl_table_gets_s(tab, "sizepolicy", &tmps)){
767 if(string2sizepolicy(tmps, &par->szplcy))
772 if(extl_table_gets_t(tab, "geom", &g)){
775 if(extl_table_gets_i(g, "x", &(par->geom.x)))
777 if(extl_table_gets_i(g, "y", &(par->geom.y)))
779 if(extl_table_gets_i(g, "w", &(par->geom.w)))
781 if(extl_table_gets_i(g, "h", &(par->geom.h)))
794 * Attach and reparent existing region \var{reg} to \var{ws}.
795 * The table \var{param} may contain the fields \var{index} and
796 * \var{switchto} that are interpreted as for \fnref{WMPlex.attach_new}.
799 WRegion *group_attach(WGroup *ws, WRegion *reg, ExtlTab param)
801 WGroupAttachParams par=GROUPATTACHPARAMS_INIT;
802 WRegionAttachData data;
807 get_params(ws, param, &par);
809 data.type=REGION_ATTACH_REPARENT;
812 return group_do_attach(ws, &par, &data);
817 * Create a new region to be managed by \var{ws}. At least the following
818 * fields in \var{param} are understood:
820 * \begin{tabularx}{\linewidth}{lX}
821 * \tabhead{Field & Description}
822 * \var{type} & (string) Class of the object to be created. Mandatory. \\
823 * \var{name} & (string) Name of the object to be created. \\
824 * \var{switchto} & (boolean) Should the region be switched to? \\
825 * \var{level} & (integer) Stacking level; default is 1. \\
826 * \var{modal} & (boolean) Make object modal; ignored if level is set. \\
827 * \var{sizepolicy} & (string) Size policy; see Section \ref{sec:sizepolicies}. \\
828 * \var{bottom} & (boolean) Mark the attached region as the
829 * ``bottom'' of \var{ws}. \\
832 * In addition parameters to the region to be created are passed in this
836 WRegion *group_attach_new(WGroup *ws, ExtlTab param)
838 WGroupAttachParams par=GROUPATTACHPARAMS_INIT;
839 WRegionAttachData data;
841 get_params(ws, param, &par);
843 data.type=REGION_ATTACH_LOAD;
846 return group_do_attach(ws, &par, &data);
853 /*{{{ Status display support */
856 static int stdisp_szplcy(const WMPlexSTDispInfo *di, WRegion *stdisp)
861 if(region_orientation(stdisp)==REGION_ORIENTATION_VERTICAL){
862 if(pos==MPLEX_STDISP_TL || pos==MPLEX_STDISP_BL)
863 return SIZEPOLICY_STRETCH_LEFT;
865 return SIZEPOLICY_STRETCH_RIGHT;
867 if(pos==MPLEX_STDISP_TL || pos==MPLEX_STDISP_TR)
868 return SIZEPOLICY_STRETCH_TOP;
870 return SIZEPOLICY_STRETCH_BOTTOM;
873 if(pos==MPLEX_STDISP_TL)
874 return SIZEPOLICY_GRAVITY_NORTHWEST;
875 else if(pos==MPLEX_STDISP_BL)
876 return SIZEPOLICY_GRAVITY_SOUTHWEST;
877 else if(pos==MPLEX_STDISP_TR)
878 return SIZEPOLICY_GRAVITY_NORTHEAST;
879 else /*if(pos=MPLEX_STDISP_BR)*/
880 return SIZEPOLICY_GRAVITY_SOUTHEAST;
885 void group_manage_stdisp(WGroup *ws, WRegion *stdisp,
886 const WMPlexSTDispInfo *di)
890 WRegion *b=(ws->bottom==NULL ? NULL : ws->bottom->reg);
892 /* Check if 'bottom' wants to manage the stdisp. */
894 && !OBJ_IS_BEING_DESTROYED(b)
895 && HAS_DYN(b, region_manage_stdisp)){
896 region_manage_stdisp(b, stdisp, di);
897 if(REGION_MANAGER(stdisp)==b)
903 szplcy=stdisp_szplcy(di, stdisp)|SIZEPOLICY_SHRUNK;
905 if(ws->managed_stdisp!=NULL && ws->managed_stdisp->reg==stdisp){
906 if(ws->managed_stdisp->szplcy==szplcy)
908 ws->managed_stdisp->szplcy=szplcy;
910 region_detach_manager(stdisp);
911 ws->managed_stdisp=group_do_add_managed(ws, stdisp,
912 STACKING_LEVEL_ON_TOP,
916 fp.g=REGION_GEOM(ws);
917 sizepolicy(&ws->managed_stdisp->szplcy, stdisp, NULL, 0, &fp);
919 region_fitrep(stdisp, NULL, &fp);
923 static void group_remanage_stdisp(WGroup *ws)
925 WMPlex *mplex=OBJ_CAST(REGION_MANAGER(ws), WMPlex);
928 mplex->mx_current!=NULL &&
929 mplex->mx_current->st->reg==(WRegion*)ws){
930 mplex_remanage_stdisp(mplex);
938 /*{{{ Geometry requests */
941 void group_managed_rqgeom(WGroup *ws, WRegion *reg,
942 const WRQGeomParams *rq,
948 st=group_find_stacking(ws, reg);
952 fp.mode=REGION_FIT_EXACT;
954 fp.g=REGION_GEOM(ws);
955 sizepolicy(&st->szplcy, reg, &rq->geom, rq->flags, &fp);
961 if(!(rq->flags®ION_RQGEOM_TRYONLY))
962 region_fitrep(reg, NULL, &fp);
966 void group_managed_rqgeom_absolute(WGroup *grp, WRegion *sub,
967 const WRQGeomParams *rq,
970 if(grp->bottom!=NULL && grp->bottom->reg==sub){
971 region_rqgeom((WRegion*)grp, rq, geomret);
972 if(!(rq->flags®ION_RQGEOM_TRYONLY) && geomret!=NULL)
973 *geomret=REGION_GEOM(sub);
975 WRQGeomParams rq2=*rq;
976 rq2.flags&=~REGION_RQGEOM_ABSOLUTE;
978 region_managed_rqgeom((WRegion*)grp, sub, &rq2, geomret);
989 static WStacking *nxt(WGroup *ws, WStacking *st, bool wrap)
991 return (st->mgr_next!=NULL
993 : (wrap ? ws->managed_list : NULL));
997 static WStacking *prv(WGroup *ws, WStacking *st, bool wrap)
999 return (st!=ws->managed_list
1001 : (wrap ? st->mgr_prev : NULL));
1005 typedef WStacking *NxtFn(WGroup *ws, WStacking *st, bool wrap);
1008 static bool focusable(WGroup *ws, WStacking *st, uint min_level)
1010 return (st->reg!=NULL
1011 && REGION_IS_MAPPED(st->reg)
1012 && !(st->reg->flags®ION_SKIP_FOCUS)
1013 && st->level>=min_level);
1017 static WStacking *do_get_next(WGroup *ws, WStacking *sti,
1018 NxtFn *fn, bool wrap, bool sti_ok)
1020 WStacking *st, *stacking;
1023 stacking=group_get_stacking(ws);
1026 min_level=stacking_min_level_mapped(stacking);
1030 st=fn(ws, st, wrap);
1032 if(st==NULL || st==sti)
1035 if(focusable(ws, st, min_level))
1039 if(sti_ok && focusable(ws, sti, min_level))
1046 static WStacking *group_do_navi_first(WGroup *ws, WRegionNavi nh)
1048 WStacking *lst=ws->managed_list;
1053 if(nh==REGION_NAVI_ANY &&
1054 ws->current_managed!=NULL &&
1055 ws->current_managed->reg!=NULL){
1056 return ws->current_managed;
1059 if(nh==REGION_NAVI_ANY || nh==REGION_NAVI_END ||
1060 nh==REGION_NAVI_BOTTOM || nh==REGION_NAVI_RIGHT){
1061 return do_get_next(ws, lst, prv, TRUE, TRUE);
1063 return do_get_next(ws, lst->mgr_prev, nxt, TRUE, TRUE);
1068 static WRegion *group_navi_first(WGroup *ws, WRegionNavi nh,
1069 WRegionNaviData *data)
1071 WStacking *st=group_do_navi_first(ws, nh);
1073 return region_navi_cont(&ws->reg, (st!=NULL ? st->reg : NULL), data);
1077 static WStacking *group_do_navi_next(WGroup *ws, WStacking *st,
1078 WRegionNavi nh, bool wrap)
1081 return group_do_navi_first(ws, nh);
1083 if(nh==REGION_NAVI_ANY || nh==REGION_NAVI_END ||
1084 nh==REGION_NAVI_BOTTOM || nh==REGION_NAVI_RIGHT){
1085 return do_get_next(ws, st, nxt, wrap, FALSE);
1087 return do_get_next(ws, st, prv, wrap, FALSE);
1091 static WRegion *group_navi_next(WGroup *ws, WRegion *reg,
1092 WRegionNavi nh, WRegionNaviData *data)
1094 WStacking *st=group_find_stacking(ws, reg);
1096 st=group_do_navi_next(ws, st, nh, FALSE);
1098 return region_navi_cont(&ws->reg, (st!=NULL ? st->reg : NULL), data);
1109 * Note: Managed objects are considered to be stacked separately from the
1110 * group, slightly violating expectations.
1113 void group_stacking(WGroup *ws, Window *bottomret, Window *topret)
1115 Window win=region_xwindow((WRegion*)ws);
1122 void group_restack(WGroup *ws, Window other, int mode)
1126 win=region_xwindow((WRegion*)ws);
1128 xwindow_restack(win, other, mode);
1135 WStacking *group_find_stacking(WGroup *ws, WRegion *r)
1137 if(r==NULL || REGION_MANAGER(r)!=(WRegion*)ws)
1140 return ioncore_find_stacking(r);
1144 static WStacking *find_stacking_if_not_on_ws(WGroup *ws, Window w)
1146 WRegion *r=xwindow_region_of(w);
1150 if(REGION_MANAGER(r)==(WRegion*)ws)
1152 st=group_find_stacking(ws, r);
1155 r=REGION_MANAGER(r);
1162 bool group_managed_rqorder(WGroup *grp, WRegion *reg, WRegionOrder order)
1164 WStacking **stackingp=group_get_stackingp(grp);
1167 if(stackingp==NULL || *stackingp==NULL)
1170 st=group_find_stacking(grp, reg);
1175 stacking_restack(stackingp, st, None, NULL, NULL,
1176 (order!=REGION_ORDER_FRONT));
1189 * Iterate over managed regions of \var{ws} until \var{iterfn} returns
1191 * The function itself returns \code{true} if it reaches the end of list
1192 * without this happening.
1196 bool group_managed_i(WGroup *ws, ExtlFn iterfn)
1199 group_iter_init(&tmp, ws);
1201 return extl_iter_objlist_(iterfn, (ObjIterator*)group_iter, &tmp);
1205 WRegion* group_current(WGroup *ws)
1207 return (ws->current_managed!=NULL ? ws->current_managed->reg : NULL);
1211 void group_size_hints(WGroup *ws, WSizeHints *hints_ret)
1213 if(ws->bottom==NULL || ws->bottom->reg==NULL){
1214 sizehints_clear(hints_ret);
1216 region_size_hints(ws->bottom->reg, hints_ret);
1217 hints_ret->no_constrain=TRUE;
1222 Window group_xwindow(const WGroup *ws)
1224 return ws->dummywin;
1229 * Returns the group of \var{reg}, if it is managed by one,
1230 * and \var{reg} itself otherwise.
1232 /*EXTL_EXPORT_MEMBER
1233 WRegion *region_group_of(WRegion *reg)
1235 WRegion *mgr=REGION_MANAGER(reg);
1237 return (OBJ_IS(mgr, WGroup) ? mgr : reg);
1242 * Returns the group of \var{reg}, if \var{reg} is its bottom,
1243 * and \var{reg} itself otherwise.
1246 WRegion *region_groupleader_of(WRegion *reg)
1248 WGroup *grp=REGION_MANAGER_CHK(reg, WGroup);
1250 return ((grp!=NULL && group_bottom(grp)==reg)
1262 static ExtlTab group_get_configuration(WGroup *ws)
1264 ExtlTab tab, mgds, subtab, g;
1271 tab=region_get_base_configuration((WRegion*)ws);
1273 mgds=extl_create_table();
1275 extl_table_sets_t(tab, "managed", mgds);
1277 /* TODO: stacking order messed up */
1279 FOR_ALL_NODES_IN_GROUP(ws, st, tmp){
1283 subtab=region_get_configuration(st->reg);
1285 if(subtab!=extl_table_none()){
1286 extl_table_sets_s(subtab, "sizepolicy",
1287 sizepolicy2string(st->szplcy));
1288 extl_table_sets_i(subtab, "level", st->level);
1290 tmpg=REGION_GEOM(st->reg);
1291 tmpg.x-=REGION_GEOM(ws).x;
1292 tmpg.y-=REGION_GEOM(ws).y;
1294 g=extl_table_from_rectangle(&tmpg);
1295 extl_table_sets_t(subtab, "geom", g);
1296 extl_unref_table(g);
1299 extl_table_sets_b(subtab, "bottom", TRUE);
1301 extl_table_seti_t(mgds, ++n, subtab);
1302 extl_unref_table(subtab);
1306 extl_unref_table(mgds);
1312 void group_do_load(WGroup *ws, ExtlTab tab)
1314 ExtlTab substab, subtab;
1317 if(extl_table_gets_t(tab, "managed", &substab)){
1318 n=extl_table_get_n(substab);
1319 for(i=1; i<=n; i++){
1320 if(extl_table_geti_t(substab, i, &subtab)){
1321 group_attach_new(ws, subtab);
1322 extl_unref_table(subtab);
1326 extl_unref_table(substab);
1331 WRegion *group_load(WWindow *par, const WFitParams *fp, ExtlTab tab)
1335 ws=create_group(par, fp);
1340 group_do_load(ws, tab);
1342 return (WRegion*)ws;
1349 /*{{{ Dynamic function table and class implementation */
1352 static DynFunTab group_dynfuntab[]={
1353 {(DynFun*)region_fitrep,
1354 (DynFun*)group_fitrep},
1362 {(DynFun*)region_managed_prepare_focus,
1363 (DynFun*)group_managed_prepare_focus},
1365 {region_do_set_focus,
1366 group_do_set_focus},
1368 {region_managed_notify,
1369 group_managed_notify},
1371 {region_managed_remove,
1372 group_managed_remove},
1374 {(DynFun*)region_get_configuration,
1375 (DynFun*)group_get_configuration},
1377 {(DynFun*)region_managed_disposeroot,
1378 (DynFun*)group_managed_disposeroot},
1380 {(DynFun*)region_current,
1381 (DynFun*)group_current},
1383 {(DynFun*)region_rescue_clientwins,
1384 (DynFun*)group_rescue_clientwins},
1392 {(DynFun*)region_managed_get_pholder,
1393 (DynFun*)group_managed_get_pholder},
1395 {region_managed_rqgeom,
1396 group_managed_rqgeom},
1398 {region_managed_rqgeom_absolute,
1399 group_managed_rqgeom_absolute},
1401 {(DynFun*)group_do_add_managed,
1402 (DynFun*)group_do_add_managed_default},
1407 {(DynFun*)region_xwindow,
1408 (DynFun*)group_xwindow},
1410 {(DynFun*)region_navi_first,
1411 (DynFun*)group_navi_first},
1413 {(DynFun*)region_navi_next,
1414 (DynFun*)group_navi_next},
1416 {(DynFun*)region_managed_rqorder,
1417 (DynFun*)group_managed_rqorder},
1424 IMPLCLASS(WGroup, WRegion, group_deinit, group_dynfuntab);