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