]> git.decadent.org.uk Git - ion3.git/blob - mod_tiling/ops.c
Imported Upstream version 20090110
[ion3.git] / mod_tiling / ops.c
1 /*
2  * ion/mod_tiling/ops.c
3  *
4  * Copyright (c) Tuomo Valkonen 1999-2009. 
5  *
6  * See the included file LICENSE for details.
7  */
8
9 #include <libtu/objp.h>
10 #include <ioncore/common.h>
11 #include <ioncore/mplex.h>
12 #include <ioncore/focus.h>
13 #include <ioncore/return.h>
14 #include <ioncore/group.h>
15 #include "tiling.h"
16
17
18 /*{{{ mkbottom */
19
20
21 static WRegion *mkbottom_fn(WWindow *parent, const WFitParams *fp, 
22                             void *param)
23 {
24     WRegion *reg=(WRegion*)param, *res;
25     WRegionAttachData data;
26     WTiling *tiling;
27     WFitParams fp2;
28     
29     fp2.mode=REGION_FIT_EXACT;
30     fp2.g=fp->g;
31     
32     tiling=create_tiling(parent, &fp2, NULL, FALSE);
33     
34     if(tiling==NULL)
35         return NULL;
36         
37     data.type=REGION_ATTACH_REPARENT;
38     data.u.reg=reg;
39     
40     /* Warning! Potentially dangerous call to remove a `reg` from the same
41      * group we're being attached to, and from the attach routine of which
42      * this function is called from!
43      */
44     res=region_attach_helper((WRegion*)tiling, parent, &fp2,
45                              (WRegionDoAttachFn*)tiling_do_attach_initial, 
46                              NULL, &data);
47     
48     if(res==NULL){
49         destroy_obj((Obj*)tiling);
50         return NULL;
51     }
52         
53     return (WRegion*)tiling;
54 }
55
56
57 /*EXTL_DOC
58  * Create a new \type{WTiling} 'bottom' for the group of \var{reg},
59  * consisting of \var{reg}.
60  */
61 EXTL_EXPORT
62 bool mod_tiling_mkbottom(WRegion *reg)
63 {
64     WGroup *grp=REGION_MANAGER_CHK(reg, WGroup);
65     WGroupAttachParams ap=GROUPATTACHPARAMS_INIT;
66     WRegionAttachData data;
67     
68     if(grp==NULL){
69         warn(TR("Not member of a group"));
70         return FALSE;
71     }
72     
73     if(group_bottom(grp)!=NULL){
74         warn(TR("Manager group already has bottom"));
75         return FALSE;
76     }
77     
78     ap.level_set=TRUE;
79     ap.level=STACKING_LEVEL_BOTTOM;
80     
81     ap.szplcy_set=TRUE;
82     ap.szplcy=SIZEPOLICY_FULL_EXACT;
83     
84     ap.switchto_set=TRUE;
85     ap.switchto=region_may_control_focus(reg);
86     
87     ap.bottom=TRUE;
88
89     data.type=REGION_ATTACH_NEW;
90     data.u.n.fn=mkbottom_fn;
91     data.u.n.param=reg;
92     
93     /* See the "Warning!" above. */
94     return (group_do_attach(grp, &ap, &data)!=NULL);
95 }
96
97
98 /*}}}*/
99
100
101 /*{{{ untile */
102
103
104 /*EXTL_DOC
105  * If \var{tiling} is managed by some group, float the frames in
106  * the tiling in that group, and dispose of \var{tiling}.
107  */
108 EXTL_EXPORT
109 bool mod_tiling_untile(WTiling *tiling)
110 {
111     WGroup *grp=REGION_MANAGER_CHK(tiling, WGroup);
112     WGroupAttachParams param=GROUPATTACHPARAMS_INIT;
113     WTilingIterTmp tmp;
114     WRegion *reg, *reg2;
115     
116     if(grp==NULL){
117         warn(TR("Not member of a group"));
118         return FALSE;
119     }
120     
121     if(group_bottom(grp)==(WRegion*)tiling)
122         group_set_bottom(grp, NULL);
123     
124     /* Setting `batchop` will stop `tiling_managed_remove` from 
125      * resizing remaining frames into freed space. It will also 
126      * stop the tiling from being destroyed by actions of
127      * `tiling_managed_disposeroot`.
128      */
129     tiling->batchop=TRUE;
130     
131     FOR_ALL_MANAGED_BY_TILING(reg, tiling, tmp){
132         WRegionAttachData data;
133         
134         /* Don't bother with the status display */
135         if(reg==TILING_STDISP_OF(tiling))
136             continue;
137         
138         /* Don't bother with regions containing no client windows. */
139         if(!region_rescue_needed(reg))
140             continue;
141         
142         data.type=REGION_ATTACH_REPARENT;
143         data.u.reg=reg;
144         
145         param.geom_set=TRUE;
146         param.geom=REGION_GEOM(reg);
147         
148         reg2=group_do_attach(grp, &param, &data);
149         
150         if(reg2==NULL)
151             warn(TR("Unable to move a region from tiling to group."));
152     }
153     
154     tiling->batchop=FALSE;
155     
156     region_dispose((WRegion*)tiling);
157     
158     return TRUE;
159 }
160
161
162 /*}}}*/
163