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