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}. \\
830 * In addition parameters to the region to be created are passed in this
834 WRegion *group_attach_new(WGroup *ws, ExtlTab param)
836 WGroupAttachParams par=GROUPATTACHPARAMS_INIT;
837 WRegionAttachData data;
839 get_params(ws, param, &par);
841 data.type=REGION_ATTACH_LOAD;
844 return group_do_attach(ws, &par, &data);
851 /*{{{ Status display support */
854 static int stdisp_szplcy(const WMPlexSTDispInfo *di, WRegion *stdisp)
859 if(region_orientation(stdisp)==REGION_ORIENTATION_VERTICAL){
860 if(pos==MPLEX_STDISP_TL || pos==MPLEX_STDISP_BL)
861 return SIZEPOLICY_STRETCH_LEFT;
863 return SIZEPOLICY_STRETCH_RIGHT;
865 if(pos==MPLEX_STDISP_TL || pos==MPLEX_STDISP_TR)
866 return SIZEPOLICY_STRETCH_TOP;
868 return SIZEPOLICY_STRETCH_BOTTOM;
871 if(pos==MPLEX_STDISP_TL)
872 return SIZEPOLICY_GRAVITY_NORTHWEST;
873 else if(pos==MPLEX_STDISP_BL)
874 return SIZEPOLICY_GRAVITY_SOUTHWEST;
875 else if(pos==MPLEX_STDISP_TR)
876 return SIZEPOLICY_GRAVITY_NORTHEAST;
877 else /*if(pos=MPLEX_STDISP_BR)*/
878 return SIZEPOLICY_GRAVITY_SOUTHEAST;
883 void group_manage_stdisp(WGroup *ws, WRegion *stdisp,
884 const WMPlexSTDispInfo *di)
888 WRegion *b=(ws->bottom==NULL ? NULL : ws->bottom->reg);
890 /* Check if 'bottom' wants to manage the stdisp. */
892 && !OBJ_IS_BEING_DESTROYED(b)
893 && HAS_DYN(b, region_manage_stdisp)){
894 region_manage_stdisp(b, stdisp, di);
895 if(REGION_MANAGER(stdisp)==b)
901 szplcy=stdisp_szplcy(di, stdisp)|SIZEPOLICY_SHRUNK;
903 if(ws->managed_stdisp!=NULL && ws->managed_stdisp->reg==stdisp){
904 if(ws->managed_stdisp->szplcy==szplcy)
906 ws->managed_stdisp->szplcy=szplcy;
908 region_detach_manager(stdisp);
909 ws->managed_stdisp=group_do_add_managed(ws, stdisp,
910 STACKING_LEVEL_ON_TOP,
914 fp.g=REGION_GEOM(ws);
915 sizepolicy(&ws->managed_stdisp->szplcy, stdisp, NULL, 0, &fp);
917 region_fitrep(stdisp, NULL, &fp);
921 static void group_remanage_stdisp(WGroup *ws)
923 WMPlex *mplex=OBJ_CAST(REGION_MANAGER(ws), WMPlex);
926 mplex->mx_current!=NULL &&
927 mplex->mx_current->st->reg==(WRegion*)ws){
928 mplex_remanage_stdisp(mplex);
936 /*{{{ Geometry requests */
939 void group_managed_rqgeom(WGroup *ws, WRegion *reg,
940 const WRQGeomParams *rq,
946 st=group_find_stacking(ws, reg);
950 fp.mode=REGION_FIT_EXACT;
952 fp.g=REGION_GEOM(ws);
953 sizepolicy(&st->szplcy, reg, &rq->geom, rq->flags, &fp);
959 if(!(rq->flags®ION_RQGEOM_TRYONLY))
960 region_fitrep(reg, NULL, &fp);
964 void group_managed_rqgeom_absolute(WGroup *grp, WRegion *sub,
965 const WRQGeomParams *rq,
968 if(grp->bottom!=NULL && grp->bottom->reg==sub){
969 region_rqgeom((WRegion*)grp, rq, geomret);
970 if(!(rq->flags®ION_RQGEOM_TRYONLY) && geomret!=NULL)
971 *geomret=REGION_GEOM(sub);
973 WRQGeomParams rq2=*rq;
974 rq2.flags&=~REGION_RQGEOM_ABSOLUTE;
976 region_managed_rqgeom((WRegion*)grp, sub, &rq2, geomret);
987 static WStacking *nxt(WGroup *ws, WStacking *st, bool wrap)
989 return (st->mgr_next!=NULL
991 : (wrap ? ws->managed_list : NULL));
995 static WStacking *prv(WGroup *ws, WStacking *st, bool wrap)
997 return (st!=ws->managed_list
999 : (wrap ? st->mgr_prev : NULL));
1003 typedef WStacking *NxtFn(WGroup *ws, WStacking *st, bool wrap);
1006 static bool focusable(WGroup *ws, WStacking *st, uint min_level)
1008 return (st->reg!=NULL
1009 && REGION_IS_MAPPED(st->reg)
1010 && !(st->reg->flags®ION_SKIP_FOCUS)
1011 && st->level>=min_level);
1015 static WStacking *do_get_next(WGroup *ws, WStacking *sti,
1016 NxtFn *fn, bool wrap, bool sti_ok)
1018 WStacking *st, *stacking;
1021 stacking=group_get_stacking(ws);
1024 min_level=stacking_min_level_mapped(stacking);
1028 st=fn(ws, st, wrap);
1030 if(st==NULL || st==sti)
1033 if(focusable(ws, st, min_level))
1037 if(sti_ok && focusable(ws, sti, min_level))
1044 static WStacking *group_do_navi_first(WGroup *ws, WRegionNavi nh)
1046 WStacking *lst=ws->managed_list;
1051 if(nh==REGION_NAVI_ANY &&
1052 ws->current_managed!=NULL &&
1053 ws->current_managed->reg!=NULL){
1054 return ws->current_managed;
1057 if(nh==REGION_NAVI_ANY || nh==REGION_NAVI_END ||
1058 nh==REGION_NAVI_BOTTOM || nh==REGION_NAVI_RIGHT){
1059 return do_get_next(ws, lst, prv, TRUE, TRUE);
1061 return do_get_next(ws, lst->mgr_prev, nxt, TRUE, TRUE);
1066 static WRegion *group_navi_first(WGroup *ws, WRegionNavi nh,
1067 WRegionNaviData *data)
1069 WStacking *st=group_do_navi_first(ws, nh);
1071 return region_navi_cont(&ws->reg, (st!=NULL ? st->reg : NULL), data);
1075 static WStacking *group_do_navi_next(WGroup *ws, WStacking *st,
1076 WRegionNavi nh, bool wrap)
1079 return group_do_navi_first(ws, nh);
1081 if(nh==REGION_NAVI_ANY || nh==REGION_NAVI_END ||
1082 nh==REGION_NAVI_BOTTOM || nh==REGION_NAVI_RIGHT){
1083 return do_get_next(ws, st, nxt, wrap, FALSE);
1085 return do_get_next(ws, st, prv, wrap, FALSE);
1089 static WRegion *group_navi_next(WGroup *ws, WRegion *reg,
1090 WRegionNavi nh, WRegionNaviData *data)
1092 WStacking *st=group_find_stacking(ws, reg);
1094 st=group_do_navi_next(ws, st, nh, FALSE);
1096 return region_navi_cont(&ws->reg, (st!=NULL ? st->reg : NULL), data);
1107 * Note: Managed objects are considered to be stacked separately from the
1108 * group, slightly violating expectations.
1111 void group_stacking(WGroup *ws, Window *bottomret, Window *topret)
1113 Window win=region_xwindow((WRegion*)ws);
1120 void group_restack(WGroup *ws, Window other, int mode)
1124 win=region_xwindow((WRegion*)ws);
1126 xwindow_restack(win, other, mode);
1133 WStacking *group_find_stacking(WGroup *ws, WRegion *r)
1135 if(r==NULL || REGION_MANAGER(r)!=(WRegion*)ws)
1138 return ioncore_find_stacking(r);
1142 static WStacking *find_stacking_if_not_on_ws(WGroup *ws, Window w)
1144 WRegion *r=xwindow_region_of(w);
1148 if(REGION_MANAGER(r)==(WRegion*)ws)
1150 st=group_find_stacking(ws, r);
1153 r=REGION_MANAGER(r);
1160 bool group_managed_rqorder(WGroup *grp, WRegion *reg, WRegionOrder order)
1162 WStacking **stackingp=group_get_stackingp(grp);
1165 if(stackingp==NULL || *stackingp==NULL)
1168 st=group_find_stacking(grp, reg);
1173 stacking_restack(stackingp, st, None, NULL, NULL,
1174 (order!=REGION_ORDER_FRONT));
1187 * Iterate over managed regions of \var{ws} until \var{iterfn} returns
1189 * The function itself returns \code{true} if it reaches the end of list
1190 * without this happening.
1194 bool group_managed_i(WGroup *ws, ExtlFn iterfn)
1197 group_iter_init(&tmp, ws);
1199 return extl_iter_objlist_(iterfn, (ObjIterator*)group_iter, &tmp);
1203 WRegion* group_current(WGroup *ws)
1205 return (ws->current_managed!=NULL ? ws->current_managed->reg : NULL);
1209 void group_size_hints(WGroup *ws, WSizeHints *hints_ret)
1211 if(ws->bottom==NULL || ws->bottom->reg==NULL){
1212 sizehints_clear(hints_ret);
1214 region_size_hints(ws->bottom->reg, hints_ret);
1215 hints_ret->no_constrain=TRUE;
1220 Window group_xwindow(const WGroup *ws)
1222 return ws->dummywin;
1227 * Returns the group of \var{reg}, if it is managed by one,
1228 * and \var{reg} itself otherwise.
1230 /*EXTL_EXPORT_MEMBER
1231 WRegion *region_group_of(WRegion *reg)
1233 WRegion *mgr=REGION_MANAGER(reg);
1235 return (OBJ_IS(mgr, WGroup) ? mgr : reg);
1240 * Returns the group of \var{reg}, if \var{reg} is its bottom,
1241 * and \var{reg} itself otherwise.
1244 WRegion *region_groupleader_of(WRegion *reg)
1246 WGroup *grp=REGION_MANAGER_CHK(reg, WGroup);
1248 return ((grp!=NULL && group_bottom(grp)==reg)
1260 static ExtlTab group_get_configuration(WGroup *ws)
1262 ExtlTab tab, mgds, subtab, g;
1269 tab=region_get_base_configuration((WRegion*)ws);
1271 mgds=extl_create_table();
1273 extl_table_sets_t(tab, "managed", mgds);
1275 /* TODO: stacking order messed up */
1277 FOR_ALL_NODES_IN_GROUP(ws, st, tmp){
1281 subtab=region_get_configuration(st->reg);
1283 if(subtab!=extl_table_none()){
1284 extl_table_sets_s(subtab, "sizepolicy",
1285 sizepolicy2string(st->szplcy));
1286 extl_table_sets_i(subtab, "level", st->level);
1288 tmpg=REGION_GEOM(st->reg);
1289 tmpg.x-=REGION_GEOM(ws).x;
1290 tmpg.y-=REGION_GEOM(ws).y;
1292 g=extl_table_from_rectangle(&tmpg);
1293 extl_table_sets_t(subtab, "geom", g);
1294 extl_unref_table(g);
1297 extl_table_sets_b(subtab, "bottom", TRUE);
1299 extl_table_seti_t(mgds, ++n, subtab);
1300 extl_unref_table(subtab);
1304 extl_unref_table(mgds);
1310 void group_do_load(WGroup *ws, ExtlTab tab)
1312 ExtlTab substab, subtab;
1315 if(extl_table_gets_t(tab, "managed", &substab)){
1316 n=extl_table_get_n(substab);
1317 for(i=1; i<=n; i++){
1318 if(extl_table_geti_t(substab, i, &subtab)){
1319 group_attach_new(ws, subtab);
1320 extl_unref_table(subtab);
1324 extl_unref_table(substab);
1329 WRegion *group_load(WWindow *par, const WFitParams *fp, ExtlTab tab)
1333 ws=create_group(par, fp);
1338 group_do_load(ws, tab);
1340 return (WRegion*)ws;
1347 /*{{{ Dynamic function table and class implementation */
1350 static DynFunTab group_dynfuntab[]={
1351 {(DynFun*)region_fitrep,
1352 (DynFun*)group_fitrep},
1360 {(DynFun*)region_managed_prepare_focus,
1361 (DynFun*)group_managed_prepare_focus},
1363 {region_do_set_focus,
1364 group_do_set_focus},
1366 {region_managed_notify,
1367 group_managed_notify},
1369 {region_managed_remove,
1370 group_managed_remove},
1372 {(DynFun*)region_get_configuration,
1373 (DynFun*)group_get_configuration},
1375 {(DynFun*)region_managed_disposeroot,
1376 (DynFun*)group_managed_disposeroot},
1378 {(DynFun*)region_current,
1379 (DynFun*)group_current},
1381 {(DynFun*)region_rescue_clientwins,
1382 (DynFun*)group_rescue_clientwins},
1390 {(DynFun*)region_managed_get_pholder,
1391 (DynFun*)group_managed_get_pholder},
1393 {region_managed_rqgeom,
1394 group_managed_rqgeom},
1396 {region_managed_rqgeom_absolute,
1397 group_managed_rqgeom_absolute},
1399 {(DynFun*)group_do_add_managed,
1400 (DynFun*)group_do_add_managed_default},
1405 {(DynFun*)region_xwindow,
1406 (DynFun*)group_xwindow},
1408 {(DynFun*)region_navi_first,
1409 (DynFun*)group_navi_first},
1411 {(DynFun*)region_navi_next,
1412 (DynFun*)group_navi_next},
1414 {(DynFun*)region_managed_rqorder,
1415 (DynFun*)group_managed_rqorder},
1422 IMPLCLASS(WGroup, WRegion, group_deinit, group_dynfuntab);