2 * ion/ioncore/group-cw.c
4 * Copyright (c) Tuomo Valkonen 1999-2007.
6 * See the included file LICENSE for details.
11 #include <libtu/objp.h>
12 #include <libmainloop/defer.h>
16 #include "clientwin.h"
23 #include "framedpholder.h"
24 #include "grouppholder.h"
27 #define DFLT_SZPLCY SIZEPOLICY_FREE_GLUE__SOUTH
30 /*{{{ Add/remove managed */
33 static WPHolder *groupcw_transient_pholder(WGroupCW *cwg,
34 const WClientWin *cwin,
35 const WManageParams *mp)
37 WGroupAttachParams param=GROUPATTACHPARAMS_INIT;
38 WFramedParam fp=FRAMEDPARAM_INIT;
42 param.level=STACKING_LEVEL_MODAL1;
45 param.szplcy=cwg->transient_szplcy;
50 param.geom_weak_set=1;
51 param.geom_weak=REGION_RQGEOM_WEAK_ALL;
53 if(!ioncore_g.framed_transients){
57 return (WPHolder*)create_grouppholder(&cwg->grp, NULL, ¶m);
59 fp.inner_geom_gravity_set=1;
60 fp.inner_geom=mp->geom;
61 fp.gravity=ForgetGravity;
62 fp.mode=FRAME_MODE_TRANSIENT;
64 ph=(WPHolder*)create_grouppholder(&cwg->grp, NULL, ¶m);
66 return pholder_either((WPHolder*)create_framedpholder(ph, &fp), ph);
71 WPHolder *groupcw_prepare_manage(WGroupCW *cwg, const WClientWin *cwin,
72 const WManageParams *param, int priority)
74 if(!MANAGE_PRIORITY_OK(priority, MANAGE_PRIORITY_GROUP))
77 /* Only catch windows with transient mode set to current here. */
78 if(clientwin_get_transient_mode(cwin)!=TRANSIENT_MODE_CURRENT)
81 return groupcw_transient_pholder(cwg, cwin, param);
85 static bool groupcw_should_manage_transient(WGroupCW *cwg,
90 if(group_find_stacking(&cwg->grp, (WRegion*)tfor))
93 mgr=REGION_MANAGER(tfor);
95 if(mgr!=NULL && ioncore_g.framed_transients && OBJ_IS(mgr, WFrame))
96 return (group_find_stacking(&cwg->grp, mgr)!=NULL);
102 WPHolder *groupcw_prepare_manage_transient(WGroupCW *cwg,
103 const WClientWin *transient,
104 const WManageParams *param,
107 WPHolder *ph=region_prepare_manage_transient_default((WRegion*)cwg,
112 if(ph==NULL && groupcw_should_manage_transient(cwg, param->tfor))
113 ph=groupcw_transient_pholder(cwg, transient, param);
126 * Toggle transients managed by \var{cwin} between top/bottom
130 void groupcw_toggle_transients_pos(WGroupCW *cwg)
135 if((cwg->transient_szplcy&SIZEPOLICY_VERT_MASK)==SIZEPOLICY_VERT_TOP){
136 cwg->transient_szplcy&=~SIZEPOLICY_VERT_MASK;
137 cwg->transient_szplcy|=SIZEPOLICY_VERT_BOTTOM;
139 cwg->transient_szplcy&=~SIZEPOLICY_VERT_MASK;
140 cwg->transient_szplcy|=SIZEPOLICY_VERT_TOP;
143 FOR_ALL_NODES_IN_GROUP(&cwg->grp, st, tmp){
144 st->szplcy&=~SIZEPOLICY_VERT_MASK;
145 st->szplcy|=(cwg->transient_szplcy&SIZEPOLICY_VERT_MASK);
150 fp.g=REGION_GEOM(cwg);
152 sizepolicy(&st->szplcy, st->reg, NULL,
153 REGION_RQGEOM_WEAK_ALL, &fp);
154 region_fitrep(st->reg, NULL, &fp);
160 const char *groupcw_displayname(WGroupCW *cwg)
162 const char *name=NULL;
164 if(cwg->grp.bottom!=NULL && cwg->grp.bottom->reg!=NULL)
165 name=region_name(cwg->grp.bottom->reg);
168 name=region_name((WRegion*)cwg);
174 void groupcw_managed_notify(WGroupCW *cwg, WRegion *reg, WRegionNotify how)
176 if(group_bottom(&cwg->grp)==reg && how==ioncore_g.notifies.name){
177 /* Title has changed */
178 region_notify_change((WRegion*)cwg, how);
181 group_managed_notify(&cwg->grp, reg, how);
185 void groupcw_bottom_set(WGroupCW *cwg)
187 region_notify_change((WRegion*)cwg, ioncore_g.notifies.name);
194 /*{{{ WGroupCW class */
197 bool groupcw_init(WGroupCW *cwg, WWindow *parent, const WFitParams *fp)
199 cwg->transient_szplcy=DFLT_SZPLCY;
201 if(!group_init(&(cwg->grp), parent, fp))
204 region_add_bindmap((WRegion*)cwg, ioncore_groupcw_bindmap);
210 WGroupCW *create_groupcw(WWindow *parent, const WFitParams *fp)
212 CREATEOBJ_IMPL(WGroupCW, groupcw, (p, parent, fp));
216 void groupcw_deinit(WGroupCW *cwg)
218 group_deinit(&(cwg->grp));
222 WRegion *groupcw_load(WWindow *par, const WFitParams *fp, ExtlTab tab)
225 ExtlTab substab, subtab;
228 ws=create_groupcw(par, fp);
233 if(!extl_table_gets_t(tab, "managed", &substab))
236 n=extl_table_get_n(substab);
238 if(extl_table_geti_t(substab, i, &subtab)){
239 group_attach_new(&ws->grp, subtab);
240 extl_unref_table(subtab);
244 extl_unref_table(substab);
246 if(ws->grp.managed_list==NULL){
247 destroy_obj((Obj*)ws);
255 static DynFunTab groupcw_dynfuntab[]={
256 {(DynFun*)region_prepare_manage,
257 (DynFun*)groupcw_prepare_manage},
259 {(DynFun*)region_prepare_manage_transient,
260 (DynFun*)groupcw_prepare_manage_transient},
263 {(DynFun*)region_handle_drop,
264 (DynFun*)groupcw_handle_drop},
266 {(DynFun*)group_do_add_managed,
267 (DynFun*)groupcw_do_add_managed},
271 {(DynFun*)region_get_rescue_pholder_for,
272 (DynFun*)groupcw_get_rescue_pholder_for},
275 {(DynFun*)region_prepare_manage,
276 (DynFun*)groupcw_prepare_manage},
278 {(DynFun*)region_prepare_manage_transient,
279 (DynFun*)groupcw_prepare_manage_transient},
281 {(DynFun*)region_displayname,
282 (DynFun*)groupcw_displayname},
284 {region_managed_notify,
285 groupcw_managed_notify},
295 IMPLCLASS(WGroupCW, WGroup, groupcw_deinit, groupcw_dynfuntab);