]> git.decadent.org.uk Git - ion3.git/blob - ioncore/grouppholder.c
[svn-inject] Installing original source of ion3
[ion3.git] / ioncore / grouppholder.c
1 /*
2  * ion/ioncore/grouppholder.c
3  *
4  * Copyright (c) Tuomo Valkonen 2005-2006. 
5  *
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.
10  */
11
12 #include <libtu/objp.h>
13 #include <libtu/obj.h>
14 #include <libtu/pointer.h>
15
16 #include <ioncore/common.h>
17 #include "group.h"
18 #include "grouppholder.h"
19
20
21 static void group_watch_handler(Watch *watch, Obj *ws);
22
23
24 /*{{{ Init/deinit */
25
26
27 static void group_watch_handler(Watch *watch, Obj *ws)
28 {
29     WGroupPHolder *ph=FIELD_TO_STRUCT(WGroupPHolder, 
30                                       group_watch, watch);
31     pholder_redirect(&(ph->ph), (WRegion*)ws);
32 }
33
34
35 static WGroupAttachParams dummy_param=GROUPATTACHPARAMS_INIT;
36
37
38 bool grouppholder_init(WGroupPHolder *ph, WGroup *ws,
39                        const WStacking *st,
40                        const WGroupAttachParams *param)
41 {
42     pholder_init(&(ph->ph));
43
44     watch_init(&(ph->group_watch));
45     watch_init(&(ph->stack_above_watch));
46     
47     if(ws!=NULL){
48         if(!watch_setup(&(ph->group_watch), (Obj*)ws, 
49                         group_watch_handler)){
50             pholder_deinit(&(ph->ph));
51             return FALSE;
52         }
53     }
54     
55     if(param==NULL)
56         param=&dummy_param;
57     
58     if(st!=NULL){
59         /* TODO? Just link to the stacking structure to remember 
60          * stacking order? 
61          */
62         
63         ph->param.szplcy_set=TRUE;
64         ph->param.szplcy=st->szplcy;
65         ph->param.level_set=TRUE;
66         ph->param.level=st->level;
67         
68         if(st->reg!=NULL){
69             ph->param.geom_set=TRUE;
70             ph->param.geom=REGION_GEOM(st->reg);
71         }
72         
73         if(st->above!=NULL && st->above->reg!=NULL)
74             ph->param.stack_above=st->above->reg;
75         
76         ph->param.modal=FALSE;
77         ph->param.bottom=(st==ws->bottom);
78         /*ph->passive=FALSE;*/
79     }else{
80         ph->param=*param;
81     }
82
83     ph->param.switchto_set=FALSE;
84
85     if(ph->param.stack_above!=NULL){
86         /* We must move stack_above pointer into a Watch. */
87         watch_setup(&(ph->stack_above_watch), 
88                     (Obj*)ph->param.stack_above, NULL);
89         ph->param.stack_above=NULL;
90     }
91     
92     return TRUE;
93 }
94  
95
96 WGroupPHolder *create_grouppholder(WGroup *ws,
97                                    const WStacking *st,
98                                    const WGroupAttachParams *param)
99 {
100     CREATEOBJ_IMPL(WGroupPHolder, grouppholder, (p, ws, st, param));
101 }
102
103
104 void grouppholder_deinit(WGroupPHolder *ph)
105 {
106     watch_reset(&(ph->group_watch));
107     watch_reset(&(ph->stack_above_watch));
108     pholder_deinit(&(ph->ph));
109 }
110
111
112 /*}}}*/
113
114
115 /*{{{ Dynfuns */
116
117
118 WRegion *grouppholder_do_attach(WGroupPHolder *ph, int flags,
119                                 WRegionAttachData *data)
120 {
121     WGroup *ws=(WGroup*)ph->group_watch.obj;
122     WRegion *reg;
123
124     if(ws==NULL)
125         return FALSE;
126
127     ph->param.switchto_set=1;
128     ph->param.switchto=(flags&PHOLDER_ATTACH_SWITCHTO ? 1 : 0);
129     
130     /* Get stack_above from Watch. */
131     ph->param.stack_above=(WRegion*)ph->stack_above_watch.obj;
132     
133     reg=group_do_attach(ws, &ph->param, data);
134     
135     ph->param.stack_above=NULL;
136
137     return reg;
138 }
139
140
141 bool grouppholder_do_goto(WGroupPHolder *ph)
142 {
143     WGroup *ws=(WGroup*)ph->group_watch.obj;
144     
145     if(ws!=NULL)
146         return region_goto((WRegion*)ws);
147     
148     return FALSE;
149 }
150
151
152 WRegion *grouppholder_do_target(WGroupPHolder *ph)
153 {
154     return (WRegion*)ph->group_watch.obj;
155 }
156
157
158 /*}}}*/
159
160
161 /*{{{ WGroup stuff */
162
163
164 WGroupPHolder *group_managed_get_pholder(WGroup *ws, WRegion *mgd)
165 {
166     WStacking *st=group_find_stacking(ws, mgd);
167     
168     if(mgd==NULL)
169         return NULL;
170     else
171         return create_grouppholder(ws, st, NULL);
172 }
173
174
175 /*}}}*/
176
177
178 /*{{{ Class information */
179
180
181 static DynFunTab grouppholder_dynfuntab[]={
182     {(DynFun*)pholder_do_attach, 
183      (DynFun*)grouppholder_do_attach},
184
185     {(DynFun*)pholder_do_goto, 
186      (DynFun*)grouppholder_do_goto},
187
188     {(DynFun*)pholder_do_target, 
189      (DynFun*)grouppholder_do_target},
190     
191     END_DYNFUNTAB
192 };
193
194 IMPLCLASS(WGroupPHolder, WPHolder, grouppholder_deinit, 
195           grouppholder_dynfuntab);
196
197
198 /*}}}*/
199