]> git.decadent.org.uk Git - ion3.git/blob - mod_tiling/placement.c
Imported Upstream version 20090110
[ion3.git] / mod_tiling / placement.c
1 /*
2  * ion/mod_tiling/placement.c
3  *
4  * Copyright (c) Tuomo Valkonen 1999-2009. 
5  *
6  * See the included file LICENSE for details.
7  */
8
9 #include <ioncore/common.h>
10 #include <ioncore/global.h>
11 #include <ioncore/clientwin.h>
12 #include <ioncore/attach.h>
13 #include <ioncore/manage.h>
14 #include <libextl/extl.h>
15 #include <ioncore/framep.h>
16 #include <ioncore/names.h>
17 #include "placement.h"
18 #include "tiling.h"
19
20
21 WHook *tiling_placement_alt=NULL;
22
23
24 static WRegion *find_suitable_target(WTiling *ws)
25 {
26     WRegion *r=tiling_current(ws);
27     
28     if(r==NULL){
29         FOR_ALL_MANAGED_BY_TILING_UNSAFE(r, ws)
30             break;
31     }
32     
33     return r;
34 }
35
36
37 static bool placement_mrsh_extl(ExtlFn fn, WTilingPlacementParams *param)
38 {
39     ExtlTab t, mp;
40     bool ret=FALSE;
41     
42     t=extl_create_table();
43     
44     mp=manageparams_to_table(param->mp);
45     
46     extl_table_sets_o(t, "tiling", (Obj*)param->ws);
47     extl_table_sets_o(t, "reg", (Obj*)param->reg);
48     extl_table_sets_t(t, "mp", mp);
49     
50     extl_unref_table(mp);
51     
52     extl_protect(NULL);
53     ret=extl_call(fn, "t", "b", t, &ret);
54     extl_unprotect(NULL);
55     
56     if(ret){
57         Obj *tmp=NULL;
58         
59         extl_table_gets_o(t, "res_frame", &tmp);
60         
61         param->res_frame=OBJ_CAST(tmp, WFrame);
62         ret=(param->res_frame!=NULL);
63     }
64             
65     extl_unref_table(t);
66     
67     return ret;
68 }
69
70
71 WPHolder *tiling_prepare_manage(WTiling *ws, const WClientWin *cwin,
72                                 const WManageParams *mp, int priority)
73 {
74     int cpriority=MANAGE_PRIORITY_SUBX(priority, MANAGE_PRIORITY_NORMAL);
75     WRegion *target=NULL;
76     WTilingPlacementParams param;
77     WPHolder *ph;
78     bool ret;
79     
80     param.ws=ws;
81     param.reg=(WRegion*)cwin;
82     param.mp=mp;
83     param.res_frame=NULL;
84     
85     ret=hook_call_alt_p(tiling_placement_alt, &param, 
86                         (WHookMarshallExtl*)placement_mrsh_extl);
87         
88     if(ret && param.res_frame!=NULL &&
89        REGION_MANAGER(param.res_frame)==(WRegion*)ws){
90         
91         target=(WRegion*)param.res_frame;
92         
93         ph=region_prepare_manage(target, cwin, mp, cpriority);
94         if(ph!=NULL)
95             return ph;
96     }
97
98     target=find_suitable_target(ws);
99     
100     if(target==NULL){
101         warn(TR("Ooops... could not find a region to attach client window "
102                 "to on workspace %s."), region_name((WRegion*)ws));
103         return NULL;
104     }
105     
106     return region_prepare_manage(target, cwin, mp, cpriority);
107 }
108