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.
14 #include <libtu/minmax.h>
15 #include <libtu/objp.h>
16 #include <libmainloop/defer.h>
33 #include "sizepolicy.h"
40 #include "grouppholder.h"
42 #include "float-placement.h"
46 static void group_place_stdisp(WGroup *ws, WWindow *parent,
47 int pos, WRegion *stdisp);
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 bool group_refocus_(WGroup *ws, WStacking *st)
239 if(st!=ws->current_managed && st->reg!=NULL){
240 if(region_may_control_focus((WRegion*)ws))
241 region_set_focus(st->reg);
243 ws->current_managed=st;
251 static void group_do_set_focus(WGroup *ws, bool warp)
253 WStacking *st=ws->current_managed;
255 if(st==NULL || st->reg==NULL)
256 st=find_to_focus(ws, NULL, TRUE);
258 if(st!=NULL && st->reg!=NULL)
259 region_do_set_focus(st->reg, warp);
261 region_finalise_focusing((WRegion*)ws, ws->dummywin, warp);
265 static bool group_managed_prepare_focus(WGroup *ws, WRegion *reg,
266 int flags, WPrepareFocusResult *res)
268 WMPlex *mplex=OBJ_CAST(REGION_MANAGER(ws), WMPlex);
269 WStacking *st=group_find_stacking(ws, reg);
275 WStacking *node=mplex_find_stacking(mplex, (WRegion*)ws);
280 return mplex_do_prepare_focus(mplex, node, st,
285 if(!region_prepare_focus((WRegion*)ws, flags, res))
288 stacking=group_get_stacking(ws);
289 st=find_to_focus(ws, st, FALSE);
291 #warning "TODO: raise in some cases (not enter-window)?"
299 return (res->reg==reg);
304 static bool group_essentially_empty(WGroup *ws)
309 FOR_ALL_NODES_IN_GROUP(ws, st, tmp){
310 if(st!=ws->managed_stdisp)
318 void group_managed_remove(WGroup *ws, WRegion *reg)
320 bool mcf=region_may_control_focus((WRegion*)ws);
321 bool ds=OBJ_IS_BEING_DESTROYED(ws);
322 WStacking *st, *next_st=NULL;
323 bool was_stdisp=FALSE, was_bottom=FALSE;
327 st=group_find_stacking(ws, reg);
330 next_st=stacking_unstack(REGION_PARENT(ws), st);
332 UNLINK_ITEM(ws->managed_list, st, mgr_next, mgr_prev);
334 if(st==ws->managed_stdisp){
335 ws->managed_stdisp=NULL;
342 if(ws->bottom_last_close && group_essentially_empty(ws))
346 if(st==ws->current_managed){
348 ws->current_managed=NULL;
351 stacking_unassoc(st);
355 region_unset_manager(reg, (WRegion*)ws);
358 if(was_bottom && !was_stdisp && ws->managed_stdisp==NULL){
359 /* We should probably be managing any stdisp, that 'bottom'
362 WMPlex *mplex=OBJ_CAST(REGION_MANAGER(ws), WMPlex);
365 && mplex->mx_current!=NULL
366 && mplex->mx_current->st->reg==(WRegion*)ws){
367 mplex_remanage_stdisp(mplex);
372 /* This may still potentially cause problems when focus
373 * change is pending. Perhaps we should use region_await_focus,
374 * if it is pointing to our child (and region_may_control_focus
375 * fail if it is pointing somewhere else).
377 WStacking *stf=find_to_focus(ws, next_st, TRUE);
378 if(stf!=NULL && mcf){
379 region_maybewarp_now(stf->reg, FALSE);
381 ws->current_managed=stf;
384 }else if(dest && !ds){
385 region_dispose((WRegion*)ws, mcf);
390 static void group_managed_notify(WGroup *ws, WRegion *reg, WRegionNotify how)
392 if(how==ioncore_g.notifies.activated ||
393 how==ioncore_g.notifies.pseudoactivated){
394 ws->current_managed=group_find_stacking(ws, reg);
402 /*{{{ Create/destroy */
405 bool group_init(WGroup *ws, WWindow *par, const WFitParams *fp)
407 ws->current_managed=NULL;
408 ws->managed_stdisp=NULL;
410 ws->managed_list=NULL;
412 ws->dummywin=XCreateWindow(ioncore_g.dpy, par->win,
413 fp->g.x, fp->g.y, 1, 1, 0,
414 CopyFromParent, InputOnly,
415 CopyFromParent, 0, NULL);
416 if(ws->dummywin==None)
419 region_init(&ws->reg, par, fp);
420 region_register(&ws->reg);
422 XSelectInput(ioncore_g.dpy, ws->dummywin,
423 FocusChangeMask|KeyPressMask|KeyReleaseMask|
424 ButtonPressMask|ButtonReleaseMask);
425 XSaveContext(ioncore_g.dpy, ws->dummywin, ioncore_g.win_context,
428 ((WRegion*)ws)->flags|=REGION_GRAB_ON_PARENT;
430 region_add_bindmap((WRegion*)ws, ioncore_group_bindmap);
436 WGroup *create_group(WWindow *par, const WFitParams *fp)
438 CREATEOBJ_IMPL(WGroup, group, (p, par, fp));
442 void group_deinit(WGroup *ws)
447 if(ws->managed_stdisp!=NULL && ws->managed_stdisp->reg!=NULL){
448 group_managed_remove(ws, ws->managed_stdisp->reg);
449 assert(ws->managed_stdisp==NULL);
452 FOR_ALL_MANAGED_BY_GROUP(ws, reg, tmp){
453 destroy_obj((Obj*)reg);
456 assert(ws->managed_list==NULL);
458 XDeleteContext(ioncore_g.dpy, ws->dummywin, ioncore_g.win_context);
459 XDestroyWindow(ioncore_g.dpy, ws->dummywin);
462 region_deinit(&ws->reg);
467 bool group_rescue_clientwins(WGroup *ws, WPHolder *ph)
471 group_iter_init_nostdisp(&tmp, ws);
473 return region_rescue_some_clientwins((WRegion*)ws, ph,
474 (WRegionIterator*)group_iter,
479 bool group_may_destroy(WGroup *ws)
481 bool ret=group_essentially_empty(ws);
483 warn(TR("Workspace not empty - refusing to destroy."));
488 static bool group_managed_may_destroy(WGroup *ws, WRegion *reg)
500 WStacking *group_do_add_managed(WGroup *ws, WRegion *reg, int level,
504 CALL_DYN_RET(st, WStacking*, group_do_add_managed, ws,
505 (ws, reg, level, szplcy));
510 WStacking *group_do_add_managed_default(WGroup *ws, WRegion *reg, int level,
513 WStacking *st=NULL, *tmp=NULL;
514 Window bottom=None, top=None;
515 WStacking **stackingp=group_get_stackingp(ws);
521 st=create_stacking();
526 if(!stacking_assoc(st, reg)){
531 frame=OBJ_CAST(reg, WFrame);
533 WFrameMode m=frame_mode(frame);
534 if(m!=FRAME_MODE_FLOATING && m!=FRAME_MODE_TRANSIENT)
535 frame_set_mode(frame, FRAME_MODE_FLOATING);
541 LINK_ITEM_FIRST(tmp, st, next, prev);
542 stacking_weave(stackingp, &tmp, FALSE);
545 LINK_ITEM(ws->managed_list, st, mgr_next, mgr_prev);
546 region_set_manager(reg, (WRegion*)ws);
548 if(region_is_fully_mapped((WRegion*)ws))
555 static void geom_group_to_parent(WGroup *ws, const WRectangle *g,
558 wg->x=g->x+REGION_GEOM(ws).x;
559 wg->y=g->y+REGION_GEOM(ws).y;
560 wg->w=maxof(1, g->w);
561 wg->h=maxof(1, g->h);
565 bool group_do_attach_final(WGroup *ws,
567 const WGroupAttachParams *param)
569 WStacking *st, *stabove=NULL;
578 szplcy=(param->szplcy_set
581 ? SIZEPOLICY_FULL_EXACT
582 : SIZEPOLICY_UNCONSTRAINED));
584 weak=(param->geom_weak_set
588 : REGION_RQGEOM_WEAK_ALL));
591 geom_group_to_parent(ws, ¶m->geom, &g);
595 /* If the requested geometry does not overlap the workspaces's geometry,
596 * position request is never honoured.
598 if((g.x+g.w<=REGION_GEOM(ws).x) ||
599 (g.x>=REGION_GEOM(ws).x+REGION_GEOM(ws).w)){
600 weak|=REGION_RQGEOM_WEAK_X;
603 if((g.y+g.h<=REGION_GEOM(ws).y) ||
604 (g.y>=REGION_GEOM(ws).y+REGION_GEOM(ws).h)){
605 weak|=REGION_RQGEOM_WEAK_Y;
608 if(weak&(REGION_RQGEOM_WEAK_X|REGION_RQGEOM_WEAK_Y) &&
609 (szplcy==SIZEPOLICY_UNCONSTRAINED ||
610 szplcy==SIZEPOLICY_FREE ||
611 szplcy==SIZEPOLICY_FREE_GLUE /* without flags */)){
612 /* TODO: use 'weak'? */
613 group_calc_placement(ws, &g);
616 fp.g=REGION_GEOM(ws);
617 fp.mode=REGION_FIT_EXACT;
619 sizepolicy(&szplcy, reg, &g, weak, &fp);
621 if(rectangle_compare(&fp.g, ®ION_GEOM(reg))!=RECTANGLE_SAME)
622 region_fitrep(reg, NULL, &fp);
625 if(param->stack_above!=NULL)
626 stabove=group_find_stacking(ws, param->stack_above);
632 : STACKING_LEVEL_NORMAL));
634 st=group_do_add_managed(ws, reg, level, szplcy);
646 if(HAS_DYN(reg, region_manage_stdisp) && ws->managed_stdisp!=NULL){
647 WMPlex *mplex=OBJ_CAST(REGION_MANAGER(ws), WMPlex);
648 if(mplex!=NULL){ /* should always hold */
650 WRegion *stdisp=NULL;
651 mplex_get_stdisp(mplex, &stdisp, &di);
653 assert(stdisp==ws->managed_stdisp->reg);
654 /* WARNING! Calls back to group code (managed_remove). */
655 region_manage_stdisp(reg, stdisp, &di);
661 sw=(param->switchto_set ? param->switchto : ioncore_g.switchto_new);
663 if(sw || st->level>=STACKING_LEVEL_MODAL1){
664 WStacking *stf=find_to_focus(ws, st, FALSE);
667 /* Ok, the new region can be focused */
668 group_refocus_(ws, stf);
676 WRegion *group_do_attach(WGroup *ws,
677 /*const*/ WGroupAttachParams *param,
678 WRegionAttachData *data)
684 if(ws->bottom!=NULL && param->bottom){
685 warn(TR("'bottom' already set."));
689 par=REGION_PARENT(ws);
693 geom_group_to_parent(ws, ¶m->geom, &fp.g);
694 fp.mode=REGION_FIT_EXACT;
696 fp.g=REGION_GEOM(ws);
697 fp.mode=REGION_FIT_BOUNDS|REGION_FIT_WHATEVER;
700 return region_attach_helper((WRegion*) ws, par, &fp,
701 (WRegionDoAttachFn*)group_do_attach_final,
702 /*(const WRegionAttachParams*)*/param, data);
703 /* ^^^^ doesn't seem to work. */
707 static void get_params(WGroup *ws, ExtlTab tab, WGroupAttachParams *par)
719 if(extl_table_gets_i(tab, "level", &tmp)){
721 par->level_set=STACKING_LEVEL_NORMAL;
726 if(extl_table_is_bool_set(tab, "bottom")){
727 par->level=STACKING_LEVEL_BOTTOM;
732 if(!par->level_set && extl_table_is_bool_set(tab, "modal")){
733 par->level=STACKING_LEVEL_MODAL1;
737 if(extl_table_is_bool_set(tab, "switchto"))
740 if(extl_table_gets_i(tab, "sizepolicy", &tmp)){
743 }else if(extl_table_gets_s(tab, "sizepolicy", &tmps)){
744 if(string2sizepolicy(tmps, &par->szplcy))
749 if(extl_table_gets_t(tab, "geom", &g)){
752 if(extl_table_gets_i(g, "x", &(par->geom.x)))
754 if(extl_table_gets_i(g, "y", &(par->geom.y)))
756 if(extl_table_gets_i(g, "w", &(par->geom.w)))
758 if(extl_table_gets_i(g, "h", &(par->geom.h)))
771 * Attach and reparent existing region \var{reg} to \var{ws}.
772 * The table \var{param} may contain the fields \var{index} and
773 * \var{switchto} that are interpreted as for \fnref{WMPlex.attach_new}.
776 WRegion *group_attach(WGroup *ws, WRegion *reg, ExtlTab param)
778 WGroupAttachParams par=GROUPATTACHPARAMS_INIT;
779 WRegionAttachData data;
784 get_params(ws, param, &par);
786 data.type=REGION_ATTACH_REPARENT;
789 return group_do_attach(ws, &par, &data);
794 * Create a new region to be managed by \var{ws}. At least the following
795 * fields in \var{param} are understood:
797 * \begin{tabularx}{\linewidth}{lX}
798 * \tabhead{Field & Description}
799 * \var{type} & Class name (a string) of the object to be created. Mandatory. \\
800 * \var{name} & Name of the object to be created (a string). Optional. \\
801 * \var{switchto} & Should the region be switched to (boolean)? Optional. \\
802 * \var{level} & Stacking level; default is 1. \\
803 * \var{modal} & Make object modal; ignored if level is set. \\
804 * \var{sizepolicy} & Size policy. \\
807 * In addition parameters to the region to be created are passed in this
811 WRegion *group_attach_new(WGroup *ws, ExtlTab param)
813 WGroupAttachParams par=GROUPATTACHPARAMS_INIT;
814 WRegionAttachData data;
816 get_params(ws, param, &par);
818 data.type=REGION_ATTACH_LOAD;
821 return group_do_attach(ws, &par, &data);
828 /*{{{ Status display support */
831 static int stdisp_szplcy(const WMPlexSTDispInfo *di, WRegion *stdisp)
836 if(region_orientation(stdisp)==REGION_ORIENTATION_VERTICAL){
837 if(pos==MPLEX_STDISP_TL || pos==MPLEX_STDISP_BL)
838 return SIZEPOLICY_STRETCH_LEFT;
840 return SIZEPOLICY_STRETCH_RIGHT;
842 if(pos==MPLEX_STDISP_TL || pos==MPLEX_STDISP_TR)
843 return SIZEPOLICY_STRETCH_TOP;
845 return SIZEPOLICY_STRETCH_BOTTOM;
848 if(pos==MPLEX_STDISP_TL)
849 return SIZEPOLICY_GRAVITY_NORTHWEST;
850 else if(pos==MPLEX_STDISP_BL)
851 return SIZEPOLICY_GRAVITY_SOUTHWEST;
852 else if(pos==MPLEX_STDISP_TR)
853 return SIZEPOLICY_GRAVITY_NORTHEAST;
854 else /*if(pos=MPLEX_STDISP_BR)*/
855 return SIZEPOLICY_GRAVITY_SOUTHEAST;
860 void group_manage_stdisp(WGroup *ws, WRegion *stdisp,
861 const WMPlexSTDispInfo *di)
865 WRegion *b=(ws->bottom==NULL ? NULL : ws->bottom->reg);
867 /* Check if 'bottom' wants to manage the stdisp. */
869 && !OBJ_IS_BEING_DESTROYED(b)
870 && HAS_DYN(b, region_manage_stdisp)){
871 region_manage_stdisp(b, stdisp, di);
872 if(REGION_MANAGER(stdisp)==b)
878 szplcy=stdisp_szplcy(di, stdisp)|SIZEPOLICY_SHRUNK;
880 if(ws->managed_stdisp!=NULL && ws->managed_stdisp->reg==stdisp){
881 if(ws->managed_stdisp->szplcy==szplcy)
883 ws->managed_stdisp->szplcy=szplcy;
885 region_detach_manager(stdisp);
886 ws->managed_stdisp=group_do_add_managed(ws, stdisp,
887 STACKING_LEVEL_ON_TOP,
891 fp.g=REGION_GEOM(ws);
892 sizepolicy(&ws->managed_stdisp->szplcy, stdisp, NULL, 0, &fp);
894 region_fitrep(stdisp, NULL, &fp);
898 void group_managed_rqgeom(WGroup *ws, WRegion *reg,
899 const WRQGeomParams *rq,
905 st=group_find_stacking(ws, reg);
909 fp.mode=REGION_FIT_EXACT;
911 fp.g=REGION_GEOM(ws);
912 sizepolicy(&st->szplcy, reg, &rq->geom, rq->flags, &fp);
918 if(!(rq->flags®ION_RQGEOM_TRYONLY))
919 region_fitrep(reg, NULL, &fp);
923 void group_managed_rqgeom_absolute(WGroup *grp, WRegion *sub,
924 const WRQGeomParams *rq,
927 if(grp->bottom!=NULL && grp->bottom->reg==sub){
928 region_rqgeom((WRegion*)grp, rq, geomret);
929 if(!(rq->flags®ION_RQGEOM_TRYONLY) && geomret!=NULL)
930 *geomret=REGION_GEOM(sub);
932 WRQGeomParams rq2=*rq;
933 rq2.flags&=~REGION_RQGEOM_ABSOLUTE;
935 region_managed_rqgeom((WRegion*)grp, sub, &rq2, geomret);
946 static WStacking *nxt(WGroup *ws, WStacking *st, bool wrap)
948 return (st->mgr_next!=NULL
950 : (wrap ? ws->managed_list : NULL));
954 static WStacking *prv(WGroup *ws, WStacking *st, bool wrap)
956 return (st!=ws->managed_list
958 : (wrap ? st->mgr_prev : NULL));
962 typedef WStacking *NxtFn(WGroup *ws, WStacking *st, bool wrap);
965 static bool mapped_filt(WStacking *st, void *unused)
967 return (st->reg!=NULL && REGION_IS_MAPPED(st->reg));
971 static bool focusable(WGroup *ws, WStacking *st, uint min_level)
973 return (st->reg!=NULL
974 && REGION_IS_MAPPED(st->reg)
975 && !(st->reg->flags®ION_SKIP_FOCUS)
976 && st->level>=min_level);
980 static WStacking *do_get_next(WGroup *ws, WStacking *sti,
981 NxtFn *fn, bool wrap, bool sti_ok)
983 WStacking *st, *stacking;
986 stacking=group_get_stacking(ws);
989 min_level=stacking_min_level(stacking, mapped_filt, NULL);
995 if(st==NULL || st==sti)
998 if(focusable(ws, st, min_level))
1002 if(sti_ok && focusable(ws, sti, min_level))
1009 static WStacking *group_do_navi_first(WGroup *ws, WRegionNavi nh)
1011 WStacking *lst=ws->managed_list;
1016 if(nh==REGION_NAVI_ANY &&
1017 ws->current_managed!=NULL &&
1018 ws->current_managed->reg!=NULL){
1019 return ws->current_managed;
1022 if(nh==REGION_NAVI_ANY || nh==REGION_NAVI_END ||
1023 nh==REGION_NAVI_BOTTOM || nh==REGION_NAVI_RIGHT){
1024 return do_get_next(ws, lst, prv, TRUE, TRUE);
1026 return do_get_next(ws, lst->mgr_prev, nxt, TRUE, TRUE);
1031 static WRegion *group_navi_first(WGroup *ws, WRegionNavi nh,
1032 WRegionNaviData *data)
1034 WStacking *st=group_do_navi_first(ws, nh);
1036 return region_navi_cont(&ws->reg, (st!=NULL ? st->reg : NULL), data);
1040 static WStacking *group_do_navi_next(WGroup *ws, WStacking *st,
1041 WRegionNavi nh, bool wrap)
1044 return group_do_navi_first(ws, nh);
1046 if(nh==REGION_NAVI_ANY || nh==REGION_NAVI_END ||
1047 nh==REGION_NAVI_BOTTOM || nh==REGION_NAVI_RIGHT){
1048 return do_get_next(ws, st, nxt, wrap, FALSE);
1050 return do_get_next(ws, st, prv, wrap, FALSE);
1054 static WRegion *group_navi_next(WGroup *ws, WRegion *reg,
1055 WRegionNavi nh, WRegionNaviData *data)
1057 WStacking *st=group_find_stacking(ws, reg);
1059 st=group_do_navi_next(ws, st, nh, FALSE);
1061 return region_navi_cont(&ws->reg, (st!=NULL ? st->reg : NULL), data);
1072 * Note: Managed objects are considered to be stacked separately from the
1073 * group, slightly violating expectations.
1076 void group_stacking(WGroup *ws, Window *bottomret, Window *topret)
1078 Window win=region_xwindow((WRegion*)ws);
1085 void group_restack(WGroup *ws, Window other, int mode)
1089 win=region_xwindow((WRegion*)ws);
1091 xwindow_restack(win, other, mode);
1098 WStacking *group_find_stacking(WGroup *ws, WRegion *r)
1100 if(r==NULL || REGION_MANAGER(r)!=(WRegion*)ws)
1103 return ioncore_find_stacking(r);
1107 static WStacking *find_stacking_if_not_on_ws(WGroup *ws, Window w)
1109 WRegion *r=xwindow_region_of(w);
1113 if(REGION_MANAGER(r)==(WRegion*)ws)
1115 st=group_find_stacking(ws, r);
1118 r=REGION_MANAGER(r);
1125 bool group_managed_rqorder(WGroup *grp, WRegion *reg, WRegionOrder order)
1127 WStacking **stackingp=group_get_stackingp(grp);
1130 if(stackingp==NULL || *stackingp==NULL)
1133 st=group_find_stacking(grp, reg);
1138 stacking_restack(stackingp, st, None, NULL, NULL,
1139 (order!=REGION_ORDER_FRONT));
1152 * Returns the 'bottom' of \var{ws}.
1155 WRegion *group_bottom(WGroup *ws)
1157 return (ws->bottom!=NULL ? ws->bottom->reg : NULL);
1162 * Iterate over managed regions of \var{ws} until \var{iterfn} returns
1164 * The function itself returns \code{true} if it reaches the end of list
1165 * without this happening.
1169 bool group_managed_i(WGroup *ws, ExtlFn iterfn)
1172 group_iter_init(&tmp, ws);
1174 return extl_iter_objlist_(iterfn, (ObjIterator*)group_iter, &tmp);
1178 WRegion* group_current(WGroup *ws)
1180 return (ws->current_managed!=NULL ? ws->current_managed->reg : NULL);
1184 void group_size_hints(WGroup *ws, WSizeHints *hints_ret)
1186 if(ws->bottom==NULL || ws->bottom->reg==NULL){
1187 sizehints_clear(hints_ret);
1189 region_size_hints(ws->bottom->reg, hints_ret);
1190 hints_ret->no_constrain=TRUE;
1195 Window group_xwindow(const WGroup *ws)
1197 return ws->dummywin;
1201 WRegion *region_group_if_bottom(WRegion *reg)
1203 WGroup *grp=REGION_MANAGER_CHK(reg, WGroup);
1205 if(grp!=NULL && group_bottom(grp)==reg)
1206 return (WRegion*)grp;
1218 static ExtlTab group_get_configuration(WGroup *ws)
1220 ExtlTab tab, mgds, subtab, g;
1227 tab=region_get_base_configuration((WRegion*)ws);
1229 mgds=extl_create_table();
1231 extl_table_sets_t(tab, "managed", mgds);
1233 /* TODO: stacking order messed up */
1235 FOR_ALL_NODES_IN_GROUP(ws, st, tmp){
1239 subtab=region_get_configuration(st->reg);
1241 if(subtab!=extl_table_none()){
1242 extl_table_sets_i(subtab, "sizepolicy", st->szplcy);
1243 extl_table_sets_i(subtab, "level", st->level);
1245 tmpg=REGION_GEOM(st->reg);
1246 tmpg.x-=REGION_GEOM(ws).x;
1247 tmpg.y-=REGION_GEOM(ws).y;
1249 g=extl_table_from_rectangle(&tmpg);
1250 extl_table_sets_t(subtab, "geom", g);
1251 extl_unref_table(g);
1254 extl_table_sets_b(subtab, "bottom", TRUE);
1256 extl_table_seti_t(mgds, ++n, subtab);
1257 extl_unref_table(subtab);
1261 extl_unref_table(mgds);
1267 void group_do_load(WGroup *ws, ExtlTab tab)
1269 ExtlTab substab, subtab;
1272 if(extl_table_gets_t(tab, "managed", &substab)){
1273 n=extl_table_get_n(substab);
1274 for(i=1; i<=n; i++){
1275 if(extl_table_geti_t(substab, i, &subtab)){
1276 group_attach_new(ws, subtab);
1277 extl_unref_table(subtab);
1281 extl_unref_table(substab);
1284 ws->bottom_last_close=extl_table_is_bool_set(tab, "bottom_last_close");
1288 WRegion *group_load(WWindow *par, const WFitParams *fp, ExtlTab tab)
1292 ws=create_group(par, fp);
1297 group_do_load(ws, tab);
1299 return (WRegion*)ws;
1306 /*{{{ Dynamic function table and class implementation */
1309 static DynFunTab group_dynfuntab[]={
1310 {(DynFun*)region_fitrep,
1311 (DynFun*)group_fitrep},
1319 {(DynFun*)region_managed_prepare_focus,
1320 (DynFun*)group_managed_prepare_focus},
1322 {region_do_set_focus,
1323 group_do_set_focus},
1325 {region_managed_notify,
1326 group_managed_notify},
1328 {region_managed_remove,
1329 group_managed_remove},
1331 {(DynFun*)region_get_configuration,
1332 (DynFun*)group_get_configuration},
1334 {(DynFun*)region_may_destroy,
1335 (DynFun*)group_may_destroy},
1337 {(DynFun*)region_managed_may_destroy,
1338 (DynFun*)group_managed_may_destroy},
1340 {(DynFun*)region_current,
1341 (DynFun*)group_current},
1343 {(DynFun*)region_rescue_clientwins,
1344 (DynFun*)group_rescue_clientwins},
1352 {(DynFun*)region_managed_get_pholder,
1353 (DynFun*)group_managed_get_pholder},
1355 {region_managed_rqgeom,
1356 group_managed_rqgeom},
1358 {region_managed_rqgeom_absolute,
1359 group_managed_rqgeom_absolute},
1361 {(DynFun*)group_do_add_managed,
1362 (DynFun*)group_do_add_managed_default},
1367 {(DynFun*)region_xwindow,
1368 (DynFun*)group_xwindow},
1370 {(DynFun*)region_navi_first,
1371 (DynFun*)group_navi_first},
1373 {(DynFun*)region_navi_next,
1374 (DynFun*)group_navi_next},
1376 {(DynFun*)region_managed_rqorder,
1377 (DynFun*)group_managed_rqorder},
1384 IMPLCLASS(WGroup, WRegion, group_deinit, group_dynfuntab);