]> git.decadent.org.uk Git - ion3.git/blob - ioncore/group-cw.c
[svn-upgrade] Integrating new upstream version, ion3 (20070708)
[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 void groupcw_bottom_set(WGroupCW *cwg)
186 {
187     region_notify_change((WRegion*)cwg, ioncore_g.notifies.name);
188 }
189
190
191 /*}}}*/
192
193
194 /*{{{ WGroupCW class */
195
196
197 bool groupcw_init(WGroupCW *cwg, WWindow *parent, const WFitParams *fp)
198 {
199     cwg->transient_szplcy=DFLT_SZPLCY;
200     
201     if(!group_init(&(cwg->grp), parent, fp))
202         return FALSE;
203     
204     region_add_bindmap((WRegion*)cwg, ioncore_groupcw_bindmap);
205     
206     return TRUE;
207 }
208
209
210 WGroupCW *create_groupcw(WWindow *parent, const WFitParams *fp)
211 {
212     CREATEOBJ_IMPL(WGroupCW, groupcw, (p, parent, fp));
213 }
214
215
216 void groupcw_deinit(WGroupCW *cwg)
217 {    
218     group_deinit(&(cwg->grp));
219 }
220
221
222 WRegion *groupcw_load(WWindow *par, const WFitParams *fp, ExtlTab tab)
223 {
224     WGroupCW *ws;
225     ExtlTab substab, subtab;
226     int i, n;
227     
228     ws=create_groupcw(par, fp);
229     
230     if(ws==NULL)
231         return NULL;
232         
233     if(!extl_table_gets_t(tab, "managed", &substab))
234         return (WRegion*)ws;
235
236     n=extl_table_get_n(substab);
237     for(i=1; i<=n; i++){
238         if(extl_table_geti_t(substab, i, &subtab)){
239             group_attach_new(&ws->grp, subtab);
240             extl_unref_table(subtab);
241         }
242     }
243     
244     extl_unref_table(substab);
245     
246     if(ws->grp.managed_list==NULL){
247         destroy_obj((Obj*)ws);
248         return NULL;
249     }
250
251     return (WRegion*)ws;
252 }
253
254
255 static DynFunTab groupcw_dynfuntab[]={
256     {(DynFun*)region_prepare_manage, 
257      (DynFun*)groupcw_prepare_manage},
258     
259     {(DynFun*)region_prepare_manage_transient,
260      (DynFun*)groupcw_prepare_manage_transient},
261     
262     /*
263     {(DynFun*)region_handle_drop,
264      (DynFun*)groupcw_handle_drop},
265     
266     {(DynFun*)group_do_add_managed,
267      (DynFun*)groupcw_do_add_managed},
268     */
269     
270     /*
271     {(DynFun*)region_get_rescue_pholder_for,
272      (DynFun*)groupcw_get_rescue_pholder_for},
273      */
274     
275     {(DynFun*)region_prepare_manage,
276      (DynFun*)groupcw_prepare_manage},
277
278     {(DynFun*)region_prepare_manage_transient,
279      (DynFun*)groupcw_prepare_manage_transient},
280     
281     {(DynFun*)region_displayname,
282      (DynFun*)groupcw_displayname},
283     
284     {region_managed_notify,
285      groupcw_managed_notify},
286      
287     {group_bottom_set,
288      groupcw_bottom_set},
289     
290     END_DYNFUNTAB
291 };
292
293
294 EXTL_EXPORT
295 IMPLCLASS(WGroupCW, WGroup, groupcw_deinit, groupcw_dynfuntab);
296
297
298 /*}}}*/
299