]> git.decadent.org.uk Git - ion3.git/blob - mod_tiling/main.c
47878700806c2fd6a3e6f87860436dfa40df6024
[ion3.git] / mod_tiling / main.c
1 /*
2  * ion/mod_tiling/main.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/map.h>
13
14 #include <ioncore/common.h>
15 #include <ioncore/reginfo.h>
16 #include <libextl/readconfig.h>
17 #include <ioncore/framep.h>
18 #include <ioncore/bindmaps.h>
19 #include <ioncore/bindmaps.h>
20
21 #include "main.h"
22 #include "tiling.h"
23 #include "placement.h"
24 #include "exports.h"
25
26
27 /*{{{ Module information */
28
29
30 #include "../version.h"
31
32 char mod_tiling_ion_api_version[]=ION_API_VERSION;
33
34
35 /*}}}*/
36
37
38 /*{{{ Bindmaps and configuration variables */
39
40
41 WBindmap *mod_tiling_tiling_bindmap=NULL;
42
43 int mod_tiling_raise_delay=CF_RAISE_DELAY;
44
45
46 /*}}}*/
47
48
49 /*{{{ Configuration */
50
51
52 /*EXTL_DOC
53  * Set parameters. Currently only \var{raise_delay} (in milliseconds)
54  * is supported.
55  */
56 EXTL_EXPORT
57 void mod_tiling_set(ExtlTab tab)
58 {
59     int d;
60     if(extl_table_gets_i(tab, "raise_delay", &d)){
61         if(d>=0)
62             mod_tiling_raise_delay=d;
63     }
64 }
65
66
67 /*EXTL_DOC
68  * Get parameters. For details see \fnref{mod_tiling.set}.
69  */
70 EXTL_SAFE
71 EXTL_EXPORT
72 ExtlTab mod_tiling_get()
73 {
74     ExtlTab tab=extl_create_table();
75     
76     extl_table_sets_i(tab, "raise_delay", mod_tiling_raise_delay);
77     
78     return tab;
79 }
80
81
82
83 /*}}}*/
84
85
86
87 /*{{{ Module init & deinit */
88
89
90 void mod_tiling_deinit()
91 {
92     mod_tiling_unregister_exports();
93     ioncore_unregister_regclass(&CLASSDESCR(WTiling));
94     
95     if(mod_tiling_tiling_bindmap!=NULL){
96         ioncore_free_bindmap("WTiling", mod_tiling_tiling_bindmap);
97         mod_tiling_tiling_bindmap=NULL;
98     }
99     
100     if(tiling_placement_alt!=NULL){
101         destroy_obj((Obj*)tiling_placement_alt);
102         tiling_placement_alt=NULL;
103     }
104 }
105
106
107 static bool register_regions()
108 {
109     if(!ioncore_register_regclass(&CLASSDESCR(WTiling),
110                                   (WRegionLoadCreateFn*)tiling_load)){
111         return FALSE;
112     }
113     
114     return TRUE;
115 }
116
117
118 #define INIT_HOOK_(NM)                             \
119     NM=mainloop_register_hook(#NM, create_hook()); \
120     if(NM==NULL) return FALSE;
121
122
123 static bool init_hooks()
124 {
125     INIT_HOOK_(tiling_placement_alt);
126     return TRUE;
127 }
128
129
130 bool mod_tiling_init()
131 {
132     if(!init_hooks())
133         goto err;
134             
135     mod_tiling_tiling_bindmap=ioncore_alloc_bindmap("WTiling", NULL);
136
137     if(mod_tiling_tiling_bindmap==NULL)
138         goto err;
139
140     if(!mod_tiling_register_exports())
141         goto err;
142
143     if(!register_regions())
144         goto err;
145     
146     extl_read_config("cfg_tiling", NULL, TRUE);
147
148     return TRUE;
149     
150 err:
151     mod_tiling_deinit();
152     return FALSE;
153 }
154
155
156 /*}}}*/
157