Revert "link mute/volumeup/volumedown keys to respective amixer commands"
[notion/jeffpc.git] / ioncore / conf.c
blob6602803025e0c7a72d5ea3d1e155249e72e768ee
1 /*
2 * ion/ioncore/conf.c
4 * Copyright (c) Tuomo Valkonen 1999-2009.
6 * See the included file LICENSE for details.
7 */
9 #include <stdlib.h>
10 #include <string.h>
12 #include <libtu/map.h>
13 #include <libtu/minmax.h>
14 #include <libtu/objp.h>
15 #include <libtu/map.h>
16 #include <libextl/readconfig.h>
18 #include "common.h"
19 #include "global.h"
20 #include "modules.h"
21 #include "rootwin.h"
22 #include "bindmaps.h"
23 #include "kbresize.h"
24 #include "reginfo.h"
25 #include "group-ws.h"
26 #include "llist.h"
29 StringIntMap frame_idxs[]={
30 {"last", LLIST_INDEX_LAST},
31 {"next", LLIST_INDEX_AFTER_CURRENT},
32 {"next-act", LLIST_INDEX_AFTER_CURRENT_ACT},
33 END_STRINGINTMAP
36 static bool get_winprop_fn_set=FALSE;
37 static ExtlFn get_winprop_fn;
39 static bool get_layout_fn_set=FALSE;
40 static ExtlFn get_layout_fn;
43 /*EXTL_DOC
44 * Set ioncore basic settings. The table \var{tab} may contain the
45 * following fields.
47 * \begin{tabularx}{\linewidth}{lX}
48 * \tabhead{Field & Description}
49 * \var{opaque_resize} & (boolean) Controls whether interactive move and
50 * resize operations simply draw a rubberband during
51 * the operation (false) or immediately affect the
52 * object in question at every step (true). \\
53 * \var{warp} & (boolean) Should focusing operations move the
54 * pointer to the object to be focused? \\
55 * \var{switchto} & (boolean) Should a managing \type{WMPlex} switch
56 * to a newly mapped client window? \\
57 * \var{screen_notify} & (boolean) Should notification tooltips be displayed
58 * for hidden workspaces with activity? \\
59 * \var{frame_default_index} & (string) Specifies where to add new regions
60 * on the mutually exclusive list of a frame. One of
61 * \codestr{last}, \codestr{next}, (for after current),
62 * or \codestr{next-act}
63 * (for after current and anything with activity right
64 * after it). \\
65 * \var{dblclick_delay} & (integer) Delay between clicks of a double click.\\
66 * \var{kbresize_delay} & (integer) Delay in milliseconds for ending keyboard
67 * resize mode after inactivity. \\
68 * \var{kbresize_t_max} & (integer) Controls keyboard resize acceleration.
69 * See description below for details. \\
70 * \var{kbresize_t_min} & (integer) See below. \\
71 * \var{kbresize_step} & (floating point) See below. \\
72 * \var{kbresize_maxacc} & (floating point) See below. \\
73 * \var{edge_resistance} & (integer) Resize edge resistance in pixels. \\
74 * \var{framed_transients} & (boolean) Put transients in nested frames. \\
75 * \var{float_placement_method} & (string) How to place floating frames.
76 * One of \codestr{udlr} (up-down, then left-right),
77 * \codestr{lrud} (left-right, then up-down), or
78 * \codestr{random}. \\
79 * \var{float_placement_padding} & (integer) Pixels between frames when
80 * \var{float_placement_method} is \codestr{udlr} or
81 * \codestr{lrud}. \\
82 * \var{mousefocus} & (string) Mouse focus mode:
83 * \codestr{disabled} or \codestr{sloppy}. \\
84 * \var{unsqueeze} & (boolean) Auto-unsqueeze transients/menus/queries/etc. \\
85 * \var{autoraise} & (boolean) Autoraise regions in groups on goto. \\
86 * \var{usertime_diff_current} & (integer) Controls switchto timeout. \\
87 * \var{usertime_diff_new} & (integer) Controls switchto timeout. \\
88 * \var{autosave_layout} & (boolean) Automatically save layout on restart and exit. \\
89 * \end{tabularx}
91 * When a keyboard resize function is called, and at most \var{kbresize_t_max}
92 * milliseconds has passed from a previous call, acceleration factor is reset
93 * to 1.0. Otherwise, if at least \var{kbresize_t_min} milliseconds have
94 * passed from the from previous acceleration update or reset the squere root
95 * of the acceleration factor is incremented by \var{kbresize_step}. The
96 * maximum acceleration factor (pixels/call modulo size hints) is given by
97 * \var{kbresize_maxacc}. The default values are (200, 50, 30, 100).
99 EXTL_EXPORT
100 void ioncore_set(ExtlTab tab)
102 int dd, rd;
103 char *wst, *tmp;
104 ExtlTab t;
105 ExtlFn fn;
107 extl_table_gets_b(tab, "opaque_resize", &(ioncore_g.opaque_resize));
108 extl_table_gets_b(tab, "warp", &(ioncore_g.warp_enabled));
109 extl_table_gets_b(tab, "switchto", &(ioncore_g.switchto_new));
110 extl_table_gets_b(tab, "screen_notify", &(ioncore_g.screen_notify));
111 extl_table_gets_b(tab, "framed_transients", &(ioncore_g.framed_transients));
112 extl_table_gets_b(tab, "unsqueeze", &(ioncore_g.unsqueeze_enabled));
113 extl_table_gets_b(tab, "autoraise", &(ioncore_g.autoraise));
114 extl_table_gets_b(tab, "autosave_layout", &(ioncore_g.autosave_layout));
116 if(extl_table_gets_s(tab, "frame_default_index", &tmp)){
117 ioncore_g.frame_default_index=stringintmap_value(frame_idxs,
118 tmp,
119 ioncore_g.frame_default_index);
120 free(tmp);
123 if(extl_table_gets_s(tab, "mousefocus", &tmp)){
124 if(strcmp(tmp, "disabled")==0)
125 ioncore_g.no_mousefocus=TRUE;
126 else if(strcmp(tmp, "sloppy")==0)
127 ioncore_g.no_mousefocus=FALSE;
128 free(tmp);
131 if(extl_table_gets_i(tab, "dblclick_delay", &dd))
132 ioncore_g.dblclick_delay=maxof(0, dd);
134 if(extl_table_gets_i(tab, "usertime_diff_current", &dd))
135 ioncore_g.usertime_diff_current=maxof(0, dd);
137 if(extl_table_gets_i(tab, "usertime_diff_new", &dd))
138 ioncore_g.usertime_diff_new=maxof(0, dd);
140 ioncore_set_moveres_accel(tab);
142 ioncore_groupws_set(tab);
144 /* Internal -- therefore undocumented above */
145 if(extl_table_gets_f(tab, "_get_winprop", &fn)){
146 if(get_winprop_fn_set)
147 extl_unref_fn(get_winprop_fn);
148 get_winprop_fn=fn;
149 get_winprop_fn_set=TRUE;
152 if(extl_table_gets_f(tab, "_get_layout", &fn)){
153 if(get_layout_fn_set)
154 extl_unref_fn(get_layout_fn);
155 get_layout_fn=fn;
156 get_layout_fn_set=TRUE;
162 /*EXTL_DOC
163 * Get ioncore basic settings. For details see \fnref{ioncore.set}.
165 EXTL_SAFE
166 EXTL_EXPORT
167 ExtlTab ioncore_get()
169 ExtlTab tab=extl_create_table();
171 extl_table_sets_b(tab, "opaque_resize", ioncore_g.opaque_resize);
172 extl_table_sets_b(tab, "warp", ioncore_g.warp_enabled);
173 extl_table_sets_b(tab, "switchto", ioncore_g.switchto_new);
174 extl_table_sets_i(tab, "dblclick_delay", ioncore_g.dblclick_delay);
175 extl_table_sets_b(tab, "screen_notify", ioncore_g.screen_notify);
176 extl_table_sets_b(tab, "framed_transients", ioncore_g.framed_transients);
177 extl_table_sets_b(tab, "unsqueeze", ioncore_g.unsqueeze_enabled);
178 extl_table_sets_b(tab, "autoraise", ioncore_g.autoraise);
179 extl_table_sets_b(tab, "autosave_layout", ioncore_g.autosave_layout);
182 extl_table_sets_s(tab, "frame_default_index",
183 stringintmap_key(frame_idxs,
184 ioncore_g.frame_default_index,
185 NULL));
187 extl_table_sets_s(tab, "mousefocus", (ioncore_g.no_mousefocus
188 ? "disabled"
189 : "sloppy"));
191 ioncore_get_moveres_accel(tab);
193 ioncore_groupws_get(tab);
195 return tab;
199 ExtlTab ioncore_get_winprop(WClientWin *cwin)
201 ExtlTab tab=extl_table_none();
203 if(get_winprop_fn_set){
204 extl_protect(NULL);
205 extl_call(get_winprop_fn, "o", "t", cwin, &tab);
206 extl_unprotect(NULL);
209 return tab;
213 ExtlTab ioncore_get_layout(const char *layout)
215 ExtlTab tab=extl_table_none();
217 if(get_layout_fn_set){
218 extl_protect(NULL);
219 extl_call(get_layout_fn, "s", "t", layout, &tab);
220 extl_unprotect(NULL);
223 return tab;
227 /*EXTL_DOC
228 * Get important directories (the fields \var{userdir},
229 * \var{sessiondir}, \var{searchpath} in the returned table).
231 EXTL_SAFE
232 EXTL_EXPORT
233 ExtlTab ioncore_get_paths(ExtlTab tab)
235 tab=extl_create_table();
236 extl_table_sets_s(tab, "userdir", extl_userdir());
237 extl_table_sets_s(tab, "sessiondir", extl_sessiondir());
238 extl_table_sets_s(tab, "searchpath", extl_searchpath());
239 return tab;
243 /*EXTL_DOC
244 * Set important directories (the fields \var{sessiondir}, \var{searchpath}
245 * of \var{tab}).
247 EXTL_EXPORT
248 bool ioncore_set_paths(ExtlTab tab)
250 char *s;
252 if(extl_table_gets_s(tab, "userdir", &s)){
253 warn(TR("User directory can not be set."));
254 free(s);
255 return FALSE;
258 if(extl_table_gets_s(tab, "sessiondir", &s)){
259 extl_set_sessiondir(s);
260 free(s);
261 return FALSE;
264 if(extl_table_gets_s(tab, "searchpath", &s)){
265 extl_set_searchpath(s);
266 free(s);
267 return FALSE;
270 return TRUE;
274 /* Exports these in ioncore. */
276 /*EXTL_DOC
277 * Lookup script \var{file}. If \var{try_in_dir} is set, it is tried
278 * before the standard search path.
280 EXTL_SAFE
281 EXTL_EXPORT_AS(ioncore, lookup_script)
282 char *extl_lookup_script(const char *file, const char *sp);
285 /*EXTL_DOC
286 * Get a file name to save (session) data in. The string \var{basename}
287 * should contain no path or extension components.
289 EXTL_SAFE
290 EXTL_EXPORT_AS(ioncore, get_savefile)
291 char *extl_get_savefile(const char *basename);
294 /*EXTL_DOC
295 * Write \var{tab} in file with basename \var{basename} in the
296 * session directory.
298 EXTL_SAFE
299 EXTL_EXPORT_AS(ioncore, write_savefile)
300 bool extl_write_savefile(const char *basename, ExtlTab tab);
303 /*EXTL_DOC
304 * Read a savefile.
306 EXTL_SAFE
307 EXTL_EXPORT_AS(ioncore, read_savefile)
308 ExtlTab extl_extl_read_savefile(const char *basename);
312 bool ioncore_read_main_config(const char *cfgfile)
314 bool ret;
315 int unset=0;
317 if(cfgfile==NULL)
318 cfgfile="cfg_notion";
320 ret=extl_read_config(cfgfile, ".", TRUE);
322 unset+=(ioncore_screen_bindmap->nbindings==0);
323 unset+=(ioncore_mplex_bindmap->nbindings==0);
324 unset+=(ioncore_frame_bindmap->nbindings==0);
326 if(unset>0){
327 warn(TR("Some bindmaps were empty, loading ioncore_efbb."));
328 extl_read_config("ioncore_efbb", NULL, TRUE);
331 return (ret && unset==0);