]> git.decadent.org.uk Git - ion3.git/blob - ioncore/group-cw.c
[svn-upgrade] Integrating new upstream version, ion3 (20070506)
[ion3.git] / ioncore / group-cw.c
1 /*
2  * ion/ioncore/group-cw.c
3  *
4  * Copyright (c) Tuomo Valkonen 1999-2007. 
5  *
6  * See the included file LICENSE for details.
7  */
8
9 #include <string.h>
10
11 #include <libtu/objp.h>
12 #include <libmainloop/defer.h>
13
14 #include "common.h"
15 #include "group-cw.h"
16 #include "clientwin.h"
17 #include "regbind.h"
18 #include "bindmaps.h"
19 #include "frame.h"
20 #include "resize.h"
21 #include "pholder.h"
22 #include "names.h"
23 #include "framedpholder.h"
24 #include "grouppholder.h"
25
26
27 #define DFLT_SZPLCY SIZEPOLICY_FREE_GLUE__SOUTH
28
29
30 /*{{{ Add/remove managed */
31
32
33 static WPHolder *groupcw_transient_pholder(WGroupCW *cwg, 
34                                            const WClientWin *cwin,
35                                            const WManageParams *mp)
36 {
37     WGroupAttachParams param=GROUPATTACHPARAMS_INIT;
38     WFramedParam fp=FRAMEDPARAM_INIT;
39     WPHolder *ph;
40     
41     param.level_set=1;
42     param.level=STACKING_LEVEL_MODAL1;
43     
44     param.szplcy_set=1;
45     param.szplcy=cwg->transient_szplcy;
46     
47     param.switchto_set=1;
48     param.switchto=1;
49
50     param.geom_weak_set=1;
51     param.geom_weak=REGION_RQGEOM_WEAK_ALL;
52     
53     if(!ioncore_g.framed_transients){
54         param.geom_set=TRUE;
55         param.geom=mp->geom;
56         
57         return (WPHolder*)create_grouppholder(&cwg->grp, NULL, &param);
58     }else{
59         fp.inner_geom_gravity_set=1;
60         fp.inner_geom=mp->geom;
61         fp.gravity=ForgetGravity;
62         fp.mode=FRAME_MODE_TRANSIENT;
63         
64         ph=(WPHolder*)create_grouppholder(&cwg->grp, NULL, &param);
65         
66         return pholder_either((WPHolder*)create_framedpholder(ph, &fp), ph);
67     }
68 }
69
70
71 WPHolder *groupcw_prepare_manage(WGroupCW *cwg, const WClientWin *cwin,
72                                  const WManageParams *param, int priority)
73 {
74     if(!MANAGE_PRIORITY_OK(priority, MANAGE_PRIORITY_GROUP))
75         return NULL;
76     
77     /* Only catch windows with transient mode set to current here. */
78     if(clientwin_get_transient_mode(cwin)!=TRANSIENT_MODE_CURRENT)
79         return NULL;
80     
81     return groupcw_transient_pholder(cwg, cwin, param);
82 }
83
84
85 static bool groupcw_should_manage_transient(WGroupCW *cwg, 
86                                             WClientWin *tfor)
87 {
88     WRegion *mgr;
89     
90     if(group_find_stacking(&cwg->grp, (WRegion*)tfor))
91         return TRUE;
92  
93     mgr=REGION_MANAGER(tfor);
94     
95     if(mgr!=NULL && ioncore_g.framed_transients && OBJ_IS(mgr, WFrame))
96         return (group_find_stacking(&cwg->grp, mgr)!=NULL);
97     
98     return FALSE;
99 }
100
101
102 WPHolder *groupcw_prepare_manage_transient(WGroupCW *cwg, 
103                                            const WClientWin *transient,
104                                            const WManageParams *param,
105                                            int unused)
106 {
107     WPHolder *ph=region_prepare_manage_transient_default((WRegion*)cwg,
108                                                          transient,
109                                                          param,
110                                                          unused);
111     
112     if(ph==NULL && groupcw_should_manage_transient(cwg, param->tfor))
113         ph=groupcw_transient_pholder(cwg, transient, param);
114
115     return ph;
116 }
117
118
119 /*}}}*/
120
121
122 /*{{{ Misc. */
123
124
125 /*_EXTL_DOC
126  * Toggle transients managed by \var{cwin} between top/bottom
127  * of the window.
128  */
129 EXTL_EXPORT_MEMBER
130 void groupcw_toggle_transients_pos(WGroupCW *cwg)
131 {
132     WStacking *st;
133     WGroupIterTmp tmp;
134     
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;
138     }else{
139         cwg->transient_szplcy&=~SIZEPOLICY_VERT_MASK;
140         cwg->transient_szplcy|=SIZEPOLICY_VERT_TOP;
141     }
142
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);
146         
147         if(st->reg!=NULL){
148             WFitParams fp;
149
150             fp.g=REGION_GEOM(cwg);
151             
152             sizepolicy(&st->szplcy, st->reg, NULL, 
153                        REGION_RQGEOM_WEAK_ALL, &fp);
154             region_fitrep(st->reg, NULL, &fp);
155         }
156     }
157 }
158
159
160 const char *groupcw_displayname(WGroupCW *cwg)
161 {
162     const char *name=NULL;
163     
164     if(cwg->grp.bottom!=NULL && cwg->grp.bottom->reg!=NULL)
165         name=region_name(cwg->grp.bottom->reg);
166     
167     if(name==NULL)
168         name=region_name((WRegion*)cwg);
169     
170     return name;
171 }
172
173
174 void groupcw_managed_notify(WGroupCW *cwg, WRegion *reg, WRegionNotify how)
175 {
176     if(group_bottom(&cwg->grp)==reg && how==ioncore_g.notifies.name){
177         /* Title has changed */
178         region_notify_change((WRegion*)cwg, how);
179     }
180     
181     group_managed_notify(&cwg->grp, reg, how);
182 }
183
184
185 /*}}}*/
186
187
188 /*{{{ WGroupCW class */
189
190
191 bool groupcw_init(WGroupCW *cwg, WWindow *parent, const WFitParams *fp)
192 {
193     cwg->transient_szplcy=DFLT_SZPLCY;
194     
195     if(!group_init(&(cwg->grp), parent, fp))
196         return FALSE;
197     
198     region_add_bindmap((WRegion*)cwg, ioncore_groupcw_bindmap);
199     
200     return TRUE;
201 }
202
203
204 WGroupCW *create_groupcw(WWindow *parent, const WFitParams *fp)
205 {
206     CREATEOBJ_IMPL(WGroupCW, groupcw, (p, parent, fp));
207 }
208
209
210 void groupcw_deinit(WGroupCW *cwg)
211 {    
212     group_deinit(&(cwg->grp));
213 }
214
215
216 WRegion *groupcw_load(WWindow *par, const WFitParams *fp, ExtlTab tab)
217 {
218     WGroupCW *ws;
219     ExtlTab substab, subtab;
220     int i, n;
221     
222     ws=create_groupcw(par, fp);
223     
224     if(ws==NULL)
225         return NULL;
226         
227     if(!extl_table_gets_t(tab, "managed", &substab))
228         return (WRegion*)ws;
229
230     n=extl_table_get_n(substab);
231     for(i=1; i<=n; i++){
232         if(extl_table_geti_t(substab, i, &subtab)){
233             group_attach_new(&ws->grp, subtab);
234             extl_unref_table(subtab);
235         }
236     }
237     
238     extl_unref_table(substab);
239     
240     if(ws->grp.managed_list==NULL){
241         destroy_obj((Obj*)ws);
242         return NULL;
243     }
244
245     return (WRegion*)ws;
246 }
247
248
249 static DynFunTab groupcw_dynfuntab[]={
250     {(DynFun*)region_prepare_manage, 
251      (DynFun*)groupcw_prepare_manage},
252     
253     {(DynFun*)region_prepare_manage_transient,
254      (DynFun*)groupcw_prepare_manage_transient},
255     
256     /*
257     {(DynFun*)region_handle_drop,
258      (DynFun*)groupcw_handle_drop},
259     
260     {(DynFun*)group_do_add_managed,
261      (DynFun*)groupcw_do_add_managed},
262     */
263     
264     /*
265     {(DynFun*)region_get_rescue_pholder_for,
266      (DynFun*)groupcw_get_rescue_pholder_for},
267      */
268     
269     {(DynFun*)region_prepare_manage,
270      (DynFun*)groupcw_prepare_manage},
271
272     {(DynFun*)region_prepare_manage_transient,
273      (DynFun*)groupcw_prepare_manage_transient},
274     
275     {(DynFun*)region_displayname,
276      (DynFun*)groupcw_displayname},
277     
278     {region_managed_notify,
279      groupcw_managed_notify},
280     
281     END_DYNFUNTAB
282 };
283
284
285 EXTL_EXPORT
286 IMPLCLASS(WGroupCW, WGroup, groupcw_deinit, groupcw_dynfuntab);
287
288
289 /*}}}*/
290