]> git.decadent.org.uk Git - ion3.git/blob - ioncore/conf.c
[svn-inject] Installing original source of ion3
[ion3.git] / ioncore / conf.c
1 /*
2  * ion/ioncore/conf.c
3  *
4  * Copyright (c) Tuomo Valkonen 1999-2006. 
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 <stdlib.h>
13 #include <string.h>
14
15 #include <libtu/map.h>
16 #include <libtu/minmax.h>
17 #include <libtu/objp.h>
18 #include <libtu/map.h>
19 #include <libextl/readconfig.h>
20
21 #include "common.h"
22 #include "global.h"
23 #include "modules.h"
24 #include "rootwin.h"
25 #include "bindmaps.h"
26 #include "kbresize.h"
27 #include "reginfo.h"
28 #include "group-ws.h"
29 #include "llist.h"
30
31
32 StringIntMap frame_idxs[]={
33     {"last", LLIST_INDEX_LAST},
34     {"next",  LLIST_INDEX_AFTER_CURRENT},
35     {"next-act",  LLIST_INDEX_AFTER_CURRENT_ACT},
36     END_STRINGINTMAP
37 };
38
39
40 /*EXTL_DOC
41  * Set ioncore basic settings. The table \var{tab} may contain the
42  * following fields.
43  * 
44  * \begin{tabularx}{\linewidth}{lX}
45  *  \tabhead{Field & Description}
46  *  \var{opaque_resize} & (boolean) Controls whether interactive move and
47  *                        resize operations simply draw a rubberband during
48  *                        the operation (false) or immediately affect the 
49  *                        object in question at every step (true). \\
50  *  \var{warp} &          (boolean) Should focusing operations move the 
51  *                        pointer to the object to be focused? \\
52  *  \var{switchto} &      (boolean) Should a managing \type{WMPlex} switch
53  *                        to a newly mapped client window? \\
54  *  \var{screen_notify} & (boolean) Should notification tooltips be displayed
55  *                        for hidden workspaces with activity? \\
56  *  \var{frame_default_index} & (string) Specifies where to add new regions
57  *                        on the mutually exclusive list of a frame. One of
58  *                        ''last'', ''next'' (for after current), ''next-act''
59  *                        (for after current and anything with activity right
60  *                        after it). \\
61  *  \var{dblclick_delay} & (integer) Delay between clicks of a double click.\\
62  *  \var{kbresize_delay} & (integer) Delay in milliseconds for ending keyboard
63  *                         resize mode after inactivity. \\
64  *  \var{kbresize_t_max} & (integer) Controls keyboard resize acceleration. 
65  *                         See description below for details. \\
66  *  \var{kbresize_t_min} & (integer) See below. \\
67  *  \var{kbresize_step} & (floating point) See below. \\
68  *  \var{kbresize_maxacc} & (floating point) See below. \\
69  *  \var{framed_transients} & (boolean) Put transients in nested frames. \\
70  *  \var{float_placement_method} & (string) How to place floating frames.
71  *                          One of ''udlr'' (up-down, then left-right), 
72  *                          ''lrud'' (left-right, then up-down) or ''random''. \\
73  *  \var{default_ws_params} & (table) Default workspace layout; the 
74  *                          attach/creation parameters for a \type{WGroup}. \\
75  * \end{tabularx}
76  * 
77  * When a keyboard resize function is called, and at most \var{kbresize_t_max} 
78  * milliseconds has passed from a previous call, acceleration factor is reset 
79  * to 1.0. Otherwise, if at least \var{kbresize_t_min} milliseconds have 
80  * passed from the from previous acceleration update or reset the squere root
81  * of the acceleration factor is incremented by \var{kbresize_step}. The 
82  * maximum acceleration factor (pixels/call modulo size hints) is given by 
83  * \var{kbresize_maxacc}. The default values are (200, 50, 30, 100). 
84  */
85 EXTL_EXPORT
86 void ioncore_set(ExtlTab tab)
87 {
88     int dd, rd;
89     char *wst, *tmp;
90     ExtlTab t;
91     
92     extl_table_gets_b(tab, "opaque_resize", &(ioncore_g.opaque_resize));
93     extl_table_gets_b(tab, "warp", &(ioncore_g.warp_enabled));
94     extl_table_gets_b(tab, "switchto", &(ioncore_g.switchto_new));
95     extl_table_gets_b(tab, "screen_notify", &(ioncore_g.screen_notify));
96     extl_table_gets_b(tab, "framed_transients", &(ioncore_g.framed_transients));
97     
98     if(extl_table_gets_s(tab, "frame_default_index", &tmp)){
99         ioncore_g.frame_default_index=stringintmap_value(frame_idxs, 
100                                                          tmp,
101                                                          ioncore_g.frame_default_index);
102         free(tmp);
103     }
104     
105     if(extl_table_gets_i(tab, "dblclick_delay", &dd))
106         ioncore_g.dblclick_delay=maxof(0, dd);
107     
108     ioncore_set_moveres_accel(tab);
109     
110     ioncore_groupws_set(tab);
111 }
112
113
114 /*EXTL_DOC
115  * Get ioncore basic settings. For details see \fnref{ioncore.set}.
116  */
117 EXTL_SAFE
118 EXTL_EXPORT
119 ExtlTab ioncore_get()
120 {
121     ExtlTab tab=extl_create_table();
122     
123     extl_table_sets_b(tab, "opaque_resize", ioncore_g.opaque_resize);
124     extl_table_sets_b(tab, "warp", ioncore_g.warp_enabled);
125     extl_table_sets_b(tab, "switchto", ioncore_g.switchto_new);
126     extl_table_sets_i(tab, "dblclick_delay", ioncore_g.dblclick_delay);
127     extl_table_sets_b(tab, "screen_notify", ioncore_g.screen_notify);
128
129     extl_table_sets_s(tab, "frame_default_index", 
130                       stringintmap_key(frame_idxs, 
131                                        ioncore_g.frame_default_index,
132                                        NULL));
133     
134     ioncore_get_moveres_accel(tab);
135     
136     ioncore_groupws_get(tab);
137     
138     return tab;
139 }
140         
141
142 /*EXTL_DOC
143  * Get important directories (userdir, sessiondir, searchpath).
144  */
145 EXTL_SAFE
146 EXTL_EXPORT
147 ExtlTab ioncore_get_paths(ExtlTab tab)
148 {
149     tab=extl_create_table();
150     extl_table_sets_s(tab, "userdir", extl_userdir());
151     extl_table_sets_s(tab, "sessiondir", extl_sessiondir());
152     extl_table_sets_s(tab, "searchpath", extl_searchpath());
153     return tab;
154 }
155
156
157 /*EXTL_DOC
158  * Set important directories (sessiondir, searchpath).
159  */
160 EXTL_EXPORT
161 bool ioncore_set_paths(ExtlTab tab)
162 {
163     char *s;
164
165     if(extl_table_gets_s(tab, "userdir", &s)){
166         warn(TR("User directory can not be set."));
167         free(s);
168         return FALSE;
169     }
170     
171     if(extl_table_gets_s(tab, "sessiondir", &s)){
172         extl_set_sessiondir(s);
173         free(s);
174         return FALSE;
175     }
176
177     if(extl_table_gets_s(tab, "searchpath", &s)){
178         extl_set_searchpath(s);
179         free(s);
180         return FALSE;
181     }
182     
183     return TRUE;
184 }
185
186
187 /* Exports these in ioncore. */
188
189 /*EXTL_DOC
190  * Lookup script \var{file}. If \var{try_in_dir} is set, it is tried
191  * before the standard search path.
192  */
193 EXTL_SAFE
194 EXTL_EXPORT_AS(ioncore, lookup_script)
195 char *extl_lookup_script(const char *file, const char *sp);
196
197
198 /*EXTL_DOC
199  * Get a file name to save (session) data in. The string \var{basename} 
200  * should contain no path or extension components.
201  */
202 EXTL_SAFE
203 EXTL_EXPORT_AS(ioncore, get_savefile)
204 char *extl_get_savefile(const char *basename);
205
206
207 /*EXTL_DOC
208  * Write \var{tab} in file with basename \var{basename} in the
209  * session directory.
210  */
211 EXTL_SAFE
212 EXTL_EXPORT_AS(ioncore, write_savefile)
213 bool extl_write_savefile(const char *basename, ExtlTab tab);
214
215
216 /*EXTL_DOC
217  * Read a savefile.
218  */
219 EXTL_SAFE
220 EXTL_EXPORT_AS(ioncore, read_savefile)
221 ExtlTab extl_extl_read_savefile(const char *basename);
222
223     
224
225 bool ioncore_read_main_config(const char *cfgfile)
226 {
227     bool ret;
228     int unset=0;
229
230     if(cfgfile==NULL)
231         cfgfile="cfg_ion";
232     
233     ret=extl_read_config(cfgfile, ".", TRUE);
234     
235     unset+=(ioncore_rootwin_bindmap->nbindings==0);
236     unset+=(ioncore_mplex_bindmap->nbindings==0);
237     unset+=(ioncore_frame_bindmap->nbindings==0);
238     
239     if(unset>0){
240         warn(TR("Some bindmaps were empty, loading ioncore_efbb."));
241         extl_read_config("ioncore_efbb", NULL, TRUE);
242     }
243     
244     return (ret && unset==0);
245 }