2 * ion/ioncore/group-cw.c
4 * Copyright (c) Tuomo Valkonen 1999-2006.
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/objp.h>
15 #include <libmainloop/defer.h>
19 #include "clientwin.h"
26 #include "framedpholder.h"
27 #include "grouppholder.h"
30 #define DFLT_SZPLCY SIZEPOLICY_FREE_GLUE__SOUTH
33 /*{{{ Add/remove managed */
36 WRegion *create_transient_frame(WWindow *par,
39 return (WRegion*)create_frame(par, fp, FRAME_MODE_TRANSIENT);
43 static WPHolder *groupcw_transient_pholder(WGroupCW *cwg,
44 const WClientWin *cwin,
45 const WManageParams *mp)
47 WGroupAttachParams param=GROUPATTACHPARAMS_INIT;
48 WFramedParam fp=FRAMEDPARAM_INIT;
52 param.level=STACKING_LEVEL_MODAL1;
55 param.szplcy=cwg->transient_szplcy;
60 param.geom_weak_set=1;
61 param.geom_weak=REGION_RQGEOM_WEAK_ALL;
63 if(!ioncore_g.framed_transients){
67 return (WPHolder*)create_grouppholder(&cwg->grp, NULL, ¶m);
69 fp.inner_geom_gravity_set=1;
70 fp.inner_geom=mp->geom;
71 fp.gravity=ForgetGravity;
72 fp.mkframe=create_transient_frame;
74 ph=(WPHolder*)create_grouppholder(&cwg->grp, NULL, ¶m);
76 return pholder_either((WPHolder*)create_framedpholder(ph, &fp), ph);
81 WPHolder *groupcw_prepare_manage(WGroupCW *cwg, const WClientWin *cwin,
82 const WManageParams *param, int redir)
84 if(redir==MANAGE_REDIR_STRICT_YES)
87 /* Only catch windows with transient mode set to current here. */
88 if(clientwin_get_transient_mode(cwin)!=TRANSIENT_MODE_CURRENT)
91 return groupcw_transient_pholder(cwg, cwin, param);
95 static bool groupcw_should_manage_transient(WGroupCW *cwg,
100 if(group_find_stacking(&cwg->grp, (WRegion*)tfor))
103 mgr=REGION_MANAGER(tfor);
105 if(mgr!=NULL && ioncore_g.framed_transients && OBJ_IS(mgr, WFrame))
106 return (group_find_stacking(&cwg->grp, mgr)!=NULL);
112 WPHolder *groupcw_prepare_manage_transient(WGroupCW *cwg,
113 const WClientWin *transient,
114 const WManageParams *param,
117 WPHolder *ph=region_prepare_manage_transient_default((WRegion*)cwg,
122 if(ph==NULL && groupcw_should_manage_transient(cwg, param->tfor))
123 ph=groupcw_transient_pholder(cwg, transient, param);
136 * Toggle transients managed by \var{cwin} between top/bottom
140 void groupcw_toggle_transients_pos(WGroupCW *cwg)
145 if((cwg->transient_szplcy&SIZEPOLICY_VERT_MASK)==SIZEPOLICY_VERT_TOP){
146 cwg->transient_szplcy&=~SIZEPOLICY_VERT_MASK;
147 cwg->transient_szplcy|=SIZEPOLICY_VERT_BOTTOM;
149 cwg->transient_szplcy&=~SIZEPOLICY_VERT_MASK;
150 cwg->transient_szplcy|=SIZEPOLICY_VERT_TOP;
153 FOR_ALL_NODES_IN_GROUP(&cwg->grp, st, tmp){
154 st->szplcy&=~SIZEPOLICY_VERT_MASK;
155 st->szplcy|=(cwg->transient_szplcy&SIZEPOLICY_VERT_MASK);
160 fp.g=REGION_GEOM(cwg);
162 sizepolicy(&st->szplcy, st->reg, NULL,
163 REGION_RQGEOM_WEAK_ALL, &fp);
164 region_fitrep(st->reg, NULL, &fp);
170 const char *groupcw_displayname(WGroupCW *cwg)
172 const char *name=NULL;
174 if(cwg->grp.bottom!=NULL && cwg->grp.bottom->reg!=NULL)
175 name=region_name(cwg->grp.bottom->reg);
178 name=region_name((WRegion*)cwg);
184 void groupcw_managed_notify(WGroupCW *cwg, WRegion *reg, const char *how)
186 if(group_bottom(&cwg->grp)==reg
187 && strcmp(how, "name")==0){
188 /* Title has changed */
189 region_notify_change((WRegion*)cwg, how);
197 /*{{{ WGroupCW class */
200 bool groupcw_init(WGroupCW *cwg, WWindow *parent, const WFitParams *fp)
202 cwg->transient_szplcy=DFLT_SZPLCY;
203 /*cwg->fs_pholder=NULL;*/
205 if(!group_init(&(cwg->grp), parent, fp))
208 cwg->grp.bottom_last_close=TRUE;
210 region_add_bindmap((WRegion*)cwg, ioncore_groupcw_bindmap);
216 WGroupCW *create_groupcw(WWindow *parent, const WFitParams *fp)
218 CREATEOBJ_IMPL(WGroupCW, groupcw, (p, parent, fp));
222 void groupcw_deinit(WGroupCW *cwg)
224 group_deinit(&(cwg->grp));
228 WRegion *groupcw_load(WWindow *par, const WFitParams *fp, ExtlTab tab)
231 ExtlTab substab, subtab;
234 ws=create_groupcw(par, fp);
239 if(!extl_table_gets_t(tab, "managed", &substab))
242 n=extl_table_get_n(substab);
244 if(extl_table_geti_t(substab, i, &subtab)){
245 group_attach_new(&ws->grp, subtab);
246 extl_unref_table(subtab);
250 extl_unref_table(substab);
252 if(ws->grp.managed_list==NULL){
253 destroy_obj((Obj*)ws);
261 static DynFunTab groupcw_dynfuntab[]={
262 {(DynFun*)region_prepare_manage,
263 (DynFun*)groupcw_prepare_manage},
265 {(DynFun*)region_prepare_manage_transient,
266 (DynFun*)groupcw_prepare_manage_transient},
269 {(DynFun*)region_handle_drop,
270 (DynFun*)groupcw_handle_drop},
272 {(DynFun*)group_do_add_managed,
273 (DynFun*)groupcw_do_add_managed},
277 {(DynFun*)region_get_rescue_pholder_for,
278 (DynFun*)groupcw_get_rescue_pholder_for},
281 {(DynFun*)region_prepare_manage,
282 (DynFun*)groupcw_prepare_manage},
284 {(DynFun*)region_prepare_manage_transient,
285 (DynFun*)groupcw_prepare_manage_transient},
287 {(DynFun*)region_displayname,
288 (DynFun*)groupcw_displayname},
290 {region_managed_notify,
291 groupcw_managed_notify},
298 IMPLCLASS(WGroupCW, WGroup, groupcw_deinit, groupcw_dynfuntab);