2 * ion/ioncore/grouppholder.c
4 * Copyright (c) Tuomo Valkonen 2005-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.
12 #include <libtu/objp.h>
13 #include <libtu/obj.h>
14 #include <libtu/pointer.h>
16 #include <ioncore/common.h>
18 #include "grouppholder.h"
21 static void group_watch_handler(Watch *watch, Obj *ws);
27 static void group_watch_handler(Watch *watch, Obj *ws)
29 WGroupPHolder *ph=FIELD_TO_STRUCT(WGroupPHolder,
31 pholder_redirect(&(ph->ph), (WRegion*)ws);
35 static WGroupAttachParams dummy_param=GROUPATTACHPARAMS_INIT;
38 bool grouppholder_init(WGroupPHolder *ph, WGroup *ws,
40 const WGroupAttachParams *param)
42 pholder_init(&(ph->ph));
44 watch_init(&(ph->group_watch));
45 watch_init(&(ph->stack_above_watch));
48 if(!watch_setup(&(ph->group_watch), (Obj*)ws,
49 group_watch_handler)){
50 pholder_deinit(&(ph->ph));
59 /* TODO? Just link to the stacking structure to remember
63 ph->param.szplcy_set=TRUE;
64 ph->param.szplcy=st->szplcy;
65 ph->param.level_set=TRUE;
66 ph->param.level=st->level;
69 ph->param.geom_set=TRUE;
70 ph->param.geom=REGION_GEOM(st->reg);
73 if(st->above!=NULL && st->above->reg!=NULL)
74 ph->param.stack_above=st->above->reg;
76 ph->param.bottom=(st==ws->bottom);
81 ph->param.switchto_set=FALSE;
83 if(ph->param.stack_above!=NULL){
84 /* We must move stack_above pointer into a Watch. */
85 watch_setup(&(ph->stack_above_watch),
86 (Obj*)ph->param.stack_above, NULL);
87 ph->param.stack_above=NULL;
94 WGroupPHolder *create_grouppholder(WGroup *ws,
96 const WGroupAttachParams *param)
98 CREATEOBJ_IMPL(WGroupPHolder, grouppholder, (p, ws, st, param));
102 void grouppholder_deinit(WGroupPHolder *ph)
104 watch_reset(&(ph->group_watch));
105 watch_reset(&(ph->stack_above_watch));
106 pholder_deinit(&(ph->ph));
116 WRegion *grouppholder_do_attach(WGroupPHolder *ph, int flags,
117 WRegionAttachData *data)
119 WGroup *ws=(WGroup*)ph->group_watch.obj;
125 ph->param.switchto_set=1;
126 ph->param.switchto=(flags&PHOLDER_ATTACH_SWITCHTO ? 1 : 0);
128 /* Get stack_above from Watch. */
129 ph->param.stack_above=(WRegion*)ph->stack_above_watch.obj;
131 reg=group_do_attach(ws, &ph->param, data);
133 ph->param.stack_above=NULL;
139 bool grouppholder_do_goto(WGroupPHolder *ph)
141 WGroup *ws=(WGroup*)ph->group_watch.obj;
144 return region_goto((WRegion*)ws);
150 WRegion *grouppholder_do_target(WGroupPHolder *ph)
152 return (WRegion*)ph->group_watch.obj;
159 /*{{{ WGroup stuff */
162 WGroupPHolder *group_managed_get_pholder(WGroup *ws, WRegion *mgd)
164 WStacking *st=group_find_stacking(ws, mgd);
169 return create_grouppholder(ws, st, NULL);
176 /*{{{ Class information */
179 static DynFunTab grouppholder_dynfuntab[]={
180 {(DynFun*)pholder_do_attach,
181 (DynFun*)grouppholder_do_attach},
183 {(DynFun*)pholder_do_goto,
184 (DynFun*)grouppholder_do_goto},
186 {(DynFun*)pholder_do_target,
187 (DynFun*)grouppholder_do_target},
192 IMPLCLASS(WGroupPHolder, WPHolder, grouppholder_deinit,
193 grouppholder_dynfuntab);