config.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636
  1. /*
  2. * config.c
  3. * Copyright © 2008, 2009 Martin Duquesnoy <xorg62@gmail.com>
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are
  8. * met:
  9. *
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * * Redistributions in binary form must reproduce the above
  13. * copyright notice, this list of conditions and the following disclaimer
  14. * in the documentation and/or other materials provided with the
  15. * distribution.
  16. * * Neither the name of the nor the names of its
  17. * contributors may be used to endorse or promote products derived from
  18. * this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. #include "wmfs.h"
  33. /* local function definition */
  34. static void conf_section(void (*)(char*), char *, char *);
  35. func_name_list_t tmp_func_list[] =
  36. {
  37. {"spawn", uicb_spawn },
  38. {"client_kill", uicb_client_kill },
  39. {"client_prev", uicb_client_prev },
  40. {"client_next", uicb_client_next },
  41. {"client_swap_next", uicb_client_swap_next },
  42. {"client_swap_prev", uicb_client_swap_prev },
  43. {"client_screen_next", uicb_client_screen_next },
  44. {"client_screen_prev", uicb_client_screen_prev },
  45. {"client_move", uicb_client_move },
  46. {"client_resize", uicb_client_resize },
  47. {"toggle_max", uicb_togglemax },
  48. {"layout_next", uicb_layout_next },
  49. {"layout_prev", uicb_layout_prev },
  50. {"tag", uicb_tag },
  51. {"tag_next", uicb_tag_next },
  52. {"tag_prev", uicb_tag_prev },
  53. {"tag_transfert", uicb_tagtransfert },
  54. {"set_mwfact", uicb_set_mwfact },
  55. {"set_nmaster", uicb_set_nmaster },
  56. {"quit", uicb_quit },
  57. {"toggle_infobar_position", uicb_infobar_togglepos },
  58. {"toggle_resizehint", uicb_toggle_resizehint },
  59. {"mouse_move", uicb_mouse_move },
  60. {"mouse_resize", uicb_mouse_resize },
  61. {"client_raise", uicb_client_raise },
  62. {"toggle_free", uicb_togglefree },
  63. {"toggle_abovefc", uicb_toggle_abovefc },
  64. {"screen_select", uicb_screen_select },
  65. {"screen_next", uicb_screen_next },
  66. {"screen_prev", uicb_screen_prev },
  67. {"reload", uicb_reload },
  68. {"launcher", uicb_launcher },
  69. {"set_layout", uicb_set_layout },
  70. {"menu", uicb_menu },
  71. {"set_client_layer", uicb_set_client_layer },
  72. {"set_layer", uicb_set_layer }
  73. };
  74. key_name_list_t key_list[] =
  75. {
  76. {"Control", ControlMask },
  77. {"Shift", ShiftMask },
  78. {"Lock", LockMask },
  79. {"Alt", Mod1Mask },
  80. {"Mod2", Mod2Mask },
  81. {"Mod3", Mod3Mask },
  82. {"Mod4", Mod4Mask },
  83. {"Super", Mod4Mask },
  84. {"Mod5", Mod5Mask },
  85. {NULL, NoSymbol }
  86. };
  87. name_to_uint_t mouse_button_list[] =
  88. {
  89. {"Button1", Button1 },
  90. {"Button2", Button2 },
  91. {"Button3", Button3 },
  92. {"Button4", Button4 },
  93. {"Button5", Button5 },
  94. {"1", Button1 },
  95. {"2", Button2 },
  96. {"3", Button3 },
  97. {"4", Button4 },
  98. {"5", Button5 },
  99. };
  100. void
  101. mouse_section(MouseBinding mb[], char *src, int ns)
  102. {
  103. int i;
  104. char *tmp;
  105. for(i = 0; i < ns; ++i)
  106. {
  107. tmp = get_nsec(src, "mouse", i);
  108. cfg_set_sauv(tmp);
  109. mb[i].tag = get_opt(tmp, "-1", "tag").num;
  110. mb[i].screen = get_opt(tmp, "-1", "screen").num;
  111. mb[i].button = char_to_button(get_opt(tmp, "1", "button").str, mouse_button_list);
  112. mb[i].func = name_to_func(get_opt(tmp, "", "func").str, func_list);
  113. mb[i].cmd = get_opt(tmp, "", "cmd").str;
  114. cfg_set_sauv(src);
  115. }
  116. return;
  117. }
  118. void
  119. conf_misc_section(char *src)
  120. {
  121. int pad = 12;
  122. cfg_set_sauv(src);
  123. conf.font = get_opt(src, "sans-9", "font").str;
  124. conf.raisefocus = get_opt(src, "false", "raisefocus").bool;
  125. conf.raiseswitch = get_opt(src, "false", "raiseswitch").bool;
  126. conf.focus_fmouse = get_opt(src, "true", "focus_follow_mouse").bool;
  127. conf.status_timing = get_opt(src, "1", "status_timing").num;
  128. pad = get_opt(src, "12", "pad").num;
  129. if(pad > 24 || pad < 1)
  130. {
  131. warnx("configuration : pad value (%d) incorrect.", pad);
  132. pad = 12;
  133. }
  134. conf.pad = pad;
  135. if(conf.status_timing <= 0)
  136. {
  137. warnx("configuration : status_timing value (%d) incorrect.", conf.status_timing);
  138. conf.status_timing = 1;
  139. }
  140. return;
  141. }
  142. void
  143. conf_bar_section(char *src)
  144. {
  145. cfg_set_sauv(src);
  146. conf.border.bar = get_opt(src, "false", "border").bool;
  147. conf.bars.height = get_opt(src, "-1", "height").num;
  148. conf.colors.bar = getcolor(get_opt(src, "#000000", "bg").str);
  149. conf.colors.text = get_opt(src, "#ffffff", "fg").str;
  150. if((conf.bars.nmouse = get_size_sec(src, "mouse")))
  151. {
  152. conf.bars.mouse = emalloc(conf.bars.nmouse, sizeof(MouseBinding));
  153. mouse_section(conf.bars.mouse, src, conf.bars.nmouse);
  154. }
  155. return;
  156. }
  157. void
  158. conf_root_section(char *src)
  159. {
  160. cfg_set_sauv(src);
  161. conf.root.background_command = get_opt(src, "", "background_command").str;
  162. if((conf.root.nmouse = get_size_sec(src, "mouse")))
  163. {
  164. conf.root.mouse = emalloc(conf.root.nmouse, sizeof(MouseBinding));
  165. mouse_section(conf.root.mouse, src, conf.root.nmouse);
  166. }
  167. return;
  168. }
  169. void
  170. conf_client_section(char *src)
  171. {
  172. int i, j, d;
  173. char *tmp, *tmp2, *tmp3, *p;
  174. opt_type *buf;
  175. /* Client misc */
  176. cfg_set_sauv(src);
  177. conf.client.borderheight = (get_opt(src, "1", "border_height").num) ? get_opt(src, "1", "border_height").num : 1;
  178. conf.client.border_shadow = get_opt(src, "false", "border_shadow").bool;
  179. conf.client.place_at_mouse = get_opt(src, "false", "place_at_mouse").bool;
  180. conf.client.bordernormal = getcolor(get_opt(src, "#000000", "border_normal").str);
  181. conf.client.borderfocus = getcolor(get_opt(src, "#ffffff", "border_focus").str);
  182. conf.client.resizecorner_normal = getcolor(get_opt(src, "#222222", "resize_corner_normal").str);
  183. conf.client.resizecorner_focus = getcolor(get_opt(src, "#DDDDDD", "resize_corner_focus").str);
  184. conf.client.mod |= char_to_modkey(get_opt(src, "Alt", "modifier").str, key_list);
  185. conf.client.set_new_win_master = get_opt(src, "true", "set_new_win_master").bool;
  186. if((conf.client.nmouse = get_size_sec(src, "mouse")))
  187. {
  188. conf.client.mouse = emalloc(conf.client.nmouse, sizeof(MouseBinding));
  189. mouse_section(conf.client.mouse, src, conf.client.nmouse);
  190. }
  191. /* Titlebar part {{ */
  192. tmp = get_sec(src, "titlebar");
  193. cfg_set_sauv(tmp);
  194. conf.titlebar.height = get_opt(tmp, "0", "height").num;
  195. conf.titlebar.fg_normal = get_opt(tmp, "#ffffff", "fg_normal").str;
  196. conf.titlebar.fg_focus = get_opt(tmp, "#000000", "fg_focus").str;
  197. /* Stipple */
  198. conf.titlebar.stipple.active = get_opt(tmp, "false", "stipple").bool;
  199. if(!strcmp((p = get_opt(tmp, "-1", "stipple_normal").str), "-1"))
  200. conf.titlebar.stipple.colors.normal = getcolor(conf.titlebar.fg_normal);
  201. else
  202. conf.titlebar.stipple.colors.normal = getcolor(p);
  203. if(!strcmp((p = get_opt(tmp, "-1", "stipple_focus").str), "-1"))
  204. conf.titlebar.stipple.colors.focus = getcolor(conf.titlebar.fg_focus);
  205. else
  206. conf.titlebar.stipple.colors.focus = getcolor(p);
  207. if((conf.titlebar.nmouse = get_size_sec(tmp, "mouse")))
  208. {
  209. conf.titlebar.mouse = emalloc(conf.titlebar.nmouse, sizeof(MouseBinding));
  210. mouse_section(conf.titlebar.mouse, tmp, conf.titlebar.nmouse);
  211. }
  212. /* Multi button part */
  213. if((conf.titlebar.nbutton = get_size_sec(tmp, "button")))
  214. {
  215. conf.titlebar.button = emalloc(conf.titlebar.nbutton, sizeof(Button));
  216. for(i = 0; i < conf.titlebar.nbutton; ++i)
  217. {
  218. tmp2 = get_nsec(tmp, "button", i);
  219. cfg_set_sauv(tmp2);
  220. /* Multi mouse section */
  221. if((conf.titlebar.button[i].nmouse = get_size_sec(tmp2, "mouse")))
  222. {
  223. conf.titlebar.button[i].mouse = emalloc(conf.titlebar.button[i].nmouse, sizeof(MouseBinding));
  224. mouse_section(conf.titlebar.button[i].mouse, tmp2, conf.titlebar.button[i].nmouse);
  225. }
  226. /* Multi line section */
  227. if((conf.titlebar.button[i].nlines = get_size_sec(tmp2, "line")))
  228. {
  229. conf.titlebar.button[i].linecoord = emalloc(conf.titlebar.button[i].nlines, sizeof(XSegment));
  230. for(j = 0; j < conf.titlebar.button[i].nlines; ++j)
  231. {
  232. tmp3 = get_nsec(tmp2, "line", j);
  233. cfg_set_sauv(tmp3);
  234. buf = get_list_opt(tmp3, "{0, 0, 0, 0}", "coord", &d);
  235. conf.titlebar.button[i].linecoord[j].x1 = buf[0].num;
  236. conf.titlebar.button[i].linecoord[j].y1 = buf[1].num;
  237. conf.titlebar.button[i].linecoord[j].x2 = buf[2].num;
  238. conf.titlebar.button[i].linecoord[j].y2 = buf[3].num;
  239. cfg_set_sauv(tmp2);
  240. }
  241. }
  242. cfg_set_sauv(tmp);
  243. }
  244. }
  245. /* }} */
  246. return;
  247. }
  248. void
  249. conf_layout_section(char *src)
  250. {
  251. int i;
  252. char *tmp = NULL, *p;
  253. /* Set conf.layout NULL for conf reload */
  254. for(i = 0; i < NUM_OF_LAYOUT; ++i)
  255. {
  256. conf.layout[i].symbol = NULL;
  257. conf.layout[i].func = NULL;
  258. }
  259. cfg_set_sauv(src);
  260. conf.border.layout = get_opt(src, "false", "border").bool;
  261. conf.colors.layout_fg = get_opt(src, "#ffffff", "fg").str;
  262. conf.colors.layout_bg = getcolor((get_opt(src, "#000000", "bg").str));
  263. if((tmp = get_opt(src, "menu", "system").str) && !strcmp(tmp, "menu"))
  264. conf.layout_system = True;
  265. conf.nlayout = get_size_sec(src, "layout");
  266. if(conf.nlayout > NUM_OF_LAYOUT || !(conf.nlayout))
  267. {
  268. warnx("configuration : Too many or no layouts (%d).", conf.nlayout);
  269. conf.nlayout = 1;
  270. conf.layout[0].symbol = _strdup("TILE");
  271. conf.layout[0].func = tile;
  272. }
  273. if(conf.layout_system && conf.nlayout > 1)
  274. {
  275. menu_init(&menulayout, "menulayout", conf.nlayout,
  276. /* Colors */
  277. conf.colors.layout_bg,
  278. conf.colors.layout_fg,
  279. conf.colors.bar,
  280. conf.colors.text);
  281. }
  282. if(!conf.layout[0].symbol
  283. && !conf.layout[0].func)
  284. {
  285. for(i = 0; i < conf.nlayout; ++i)
  286. {
  287. tmp = get_nsec(src, "layout", i);
  288. cfg_set_sauv(tmp);
  289. if(!name_to_func((p = get_opt(tmp, "tile", "type").str), layout_list))
  290. warnx("configuration : Unknown Layout type : \"%s\".", p);
  291. else
  292. {
  293. if(conf.layout_system && conf.nlayout > 1)
  294. menu_new_item(&menulayout.item[i], get_opt(tmp, "", "symbol").str,
  295. uicb_set_layout, p);
  296. conf.layout[i].symbol = get_opt(tmp, "TILE (default)", "symbol").str;
  297. conf.layout[i].func = name_to_func(p, layout_list);
  298. }
  299. cfg_set_sauv(src);
  300. }
  301. }
  302. return;
  303. }
  304. void
  305. conf_tag_section(char *src)
  306. {
  307. int i, j, k, l = 0, m, n, sc;
  308. char *cfgtmp, *tmp;
  309. opt_type *buf;
  310. /* If there is no tag in the conf or more than
  311. * MAXTAG (32) print an error and create only one.
  312. */
  313. Tag default_tag = { "WMFS", NULL, 0, 1,
  314. 0.50, 1, False, False, False, IB_Top,
  315. layout_name_to_struct(conf.layout, "tile_right", conf.nlayout, layout_list) };
  316. cfg_set_sauv(src);
  317. conf.tag_round = get_opt(src, "false", "tag_round").bool;
  318. conf.colors.tagselfg = get_opt(src, "#ffffff", "sel_fg").str;
  319. conf.colors.tagselbg = getcolor(get_opt(src, "#000000", "sel_bg").str);
  320. conf.colors.tag_occupied_bg = getcolor(get_opt(src, "#222222", "occupied_bg").str);
  321. conf.border.tag = get_opt(src, "false", "border").bool;
  322. sc = screen_count();
  323. /* Alloc all */
  324. conf.ntag = emalloc(sc, sizeof(int));
  325. tags = emalloc(sc, sizeof(Tag*));
  326. seltag = emalloc(sc, sizeof(int));
  327. for(i = 0; i < sc; ++i)
  328. seltag[i] = 1;
  329. for(i = 0; i < sc; ++i)
  330. tags[i] = emalloc(get_size_sec(src, "tag") + 2, sizeof(Tag));
  331. for(i = 0; i < get_size_sec(src, "tag"); ++i)
  332. {
  333. /* printf("%d -> %s\n", i, (cfgtmp = get_nsec(src, "tag", i)));*/
  334. cfgtmp = get_nsec(src, "tag", i);
  335. cfg_set_sauv(cfgtmp);
  336. j = get_opt(cfgtmp, "-1", "screen").num;
  337. if(j < 0 || j > sc - 1)
  338. j = -1;
  339. for(k = ((j == -1) ? 0 : j);
  340. ((j == -1) ? (k < sc) : !l);
  341. ((j == -1) ? ++k : --l))
  342. {
  343. ++conf.ntag[k];
  344. tags[k][conf.ntag[k]].name = get_opt(cfgtmp, "", "name").str;
  345. tags[k][conf.ntag[k]].mwfact = get_opt(cfgtmp, "0.65", "mwfact").fnum;
  346. tags[k][conf.ntag[k]].nmaster = get_opt(cfgtmp, "1", "nmaster").num;
  347. tags[k][conf.ntag[k]].resizehint = get_opt(cfgtmp, "false", "resizehint").bool;
  348. tags[k][conf.ntag[k]].abovefc = get_opt(cfgtmp, "false", "abovefc").bool;
  349. tags[k][conf.ntag[k]].layers = 1;
  350. tmp = _strdup(get_opt(cfgtmp, "top", "infobar_position").str);
  351. if(!strcmp(tmp ,"none") || !strcmp(tmp, "hide") || !strcmp(tmp, "hidden"))
  352. tags[k][conf.ntag[k]].barpos = IB_Hide;
  353. else if(!strcmp(tmp, "bottom") || !strcmp(tmp, "down"))
  354. tags[k][conf.ntag[k]].barpos = IB_Bottom;
  355. else
  356. tags[k][conf.ntag[k]].barpos = IB_Top;
  357. tags[k][conf.ntag[k]].layout = layout_name_to_struct(conf.layout,
  358. get_opt(cfgtmp, "tile_right", "layout").str,
  359. conf.nlayout,
  360. layout_list);
  361. /* Clients list */
  362. buf = get_list_opt(cfgtmp, "", "clients", &n);
  363. if(n)
  364. {
  365. tags[k][conf.ntag[k]].nclients = n;
  366. tags[k][conf.ntag[k]].clients = emalloc(n, sizeof(char *));
  367. for(m = 0; m < n; ++m)
  368. tags[k][conf.ntag[k]].clients[m] = (buf[m].str) ? buf[m].str : NULL;
  369. }
  370. }
  371. l = 0;
  372. cfg_set_sauv(src);
  373. }
  374. for(i = 0; i < sc; ++i)
  375. if(!conf.ntag[i] || conf.ntag[i] > MAXTAG)
  376. {
  377. warnx("configuration : Too many or no tag (%d) in the screen %d.", conf.ntag[i], i);
  378. conf.ntag[i] = 1;
  379. tags[i][1] = default_tag;
  380. }
  381. return;
  382. }
  383. void
  384. conf_menu_section(char *src)
  385. {
  386. char *tmp, *tmp2;
  387. int i, j;
  388. cfg_set_sauv(src);
  389. CHECK((conf.nmenu = get_size_sec(src, "set_menu")));
  390. conf.menu = calloc(conf.nmenu, sizeof(Menu));
  391. for(i = 0; i < conf.nmenu; ++i)
  392. {
  393. tmp = get_nsec(src, "set_menu", i);
  394. cfg_set_sauv(tmp);
  395. conf.menu[i].name = get_opt(tmp, "menu_wname", "name").str;
  396. if(!(conf.menu[i].place_at_mouse = get_opt(tmp, "true", "place_at_mouse").bool))
  397. {
  398. conf.menu[i].x = get_opt(tmp, "0", "x").num;
  399. conf.menu[i].y = get_opt(tmp, "0", "y").num;
  400. }
  401. conf.menu[i].colors.focus.bg = getcolor(get_opt(tmp, "#000000", "bg_focus").str);
  402. conf.menu[i].colors.focus.fg = get_opt(tmp, "#ffffff", "fg_focus").str;
  403. conf.menu[i].colors.normal.bg = getcolor(get_opt(tmp, "#000000", "bg_normal").str);
  404. conf.menu[i].colors.normal.fg = get_opt(tmp, "#ffffff", "fg_normal").str;
  405. if((conf.menu[i].nitem = get_size_sec(tmp, "item")))
  406. {
  407. conf.menu[i].item = emalloc(conf.menu[i].nitem, sizeof(MenuItem));
  408. for(j = 0; j < get_size_sec(tmp, "item"); ++j)
  409. {
  410. tmp2 = get_nsec(tmp, "item", j);
  411. cfg_set_sauv(tmp2);
  412. conf.menu[i].item[j].name = get_opt(tmp2, "item_wname", "name").str;
  413. conf.menu[i].item[j].func = name_to_func(get_opt(tmp2, "", "func").str, func_list);
  414. conf.menu[i].item[j].cmd = (!get_opt(tmp2, "", "cmd").str) ? NULL : get_opt(tmp2, "", "cmd").str;
  415. cfg_set_sauv(tmp);
  416. }
  417. }
  418. cfg_set_sauv(src);
  419. }
  420. return;
  421. }
  422. void
  423. conf_launcher_section(char *src)
  424. {
  425. int i;
  426. char *tmp;
  427. cfg_set_sauv(src);
  428. CHECK((conf.nlauncher = get_size_sec(src, "set_launcher")));
  429. conf.launcher = emalloc(conf.nlauncher, sizeof(Launcher));
  430. for(i = 0; i < conf.nlauncher; ++i)
  431. {
  432. tmp = get_nsec(src, "set_launcher", i);
  433. cfg_set_sauv(tmp);
  434. conf.launcher[i].name = get_opt(tmp, "launcher", "name").str;
  435. conf.launcher[i].prompt = get_opt(tmp, "Exec:", "prompt").str;
  436. conf.launcher[i].command = get_opt(tmp, "exec", "command").str;
  437. cfg_set_sauv(src);
  438. }
  439. return;
  440. }
  441. void
  442. conf_keybind_section(char *src)
  443. {
  444. int i, j, n = 0;
  445. char *tmp;
  446. opt_type *buf;
  447. cfg_set_sauv(src);
  448. conf.nkeybind = get_size_sec(src, "key");
  449. keys = emalloc(conf.nkeybind, sizeof(Key));
  450. for(i = 0; i < conf.nkeybind; ++i)
  451. {
  452. tmp = get_nsec(src, "key", i);
  453. cfg_set_sauv(tmp);
  454. buf = get_list_opt(tmp, "", "mod", &n);
  455. for(j = 0; j < n; ++j)
  456. keys[i].mod |= char_to_modkey(buf[j].str, key_list);
  457. keys[i].keysym = XStringToKeysym(get_opt(tmp, "None", "key").str);
  458. keys[i].func = name_to_func(get_opt(tmp, "", "func").str, func_list);
  459. if(keys[i].func == NULL)
  460. {
  461. warnx("configuration : Unknown Function \"%s\".", get_opt(tmp, "", "func").str);
  462. keys[i].func = uicb_spawn;
  463. }
  464. keys[i].cmd = (!get_opt(tmp, "", "cmd").str) ? NULL : get_opt(tmp, "", "cmd").str;
  465. cfg_set_sauv(src);
  466. }
  467. return;
  468. }
  469. /** Configuration initialization
  470. */
  471. void
  472. init_conf(void)
  473. {
  474. char *file;
  475. if(!(file = file_to_str(conf.confpath)))
  476. {
  477. warnx("parsing configuration file (%s) failed.", conf.confpath);
  478. sprintf(conf.confpath, "%s/wmfs/wmfsrc", XDG_CONFIG_DIR);
  479. warnx("Use the default configuration (%s).", conf.confpath);
  480. file = file_to_str(conf.confpath);
  481. }
  482. /* Set func_list */
  483. func_list = emalloc(LEN(tmp_func_list), sizeof(func_name_list_t));
  484. memcpy(func_list, tmp_func_list, LEN(tmp_func_list) * sizeof(func_name_list_t));
  485. conf_section(conf_misc_section, file, "misc");
  486. conf_section(conf_bar_section, file, "bar");
  487. conf_section(conf_root_section, file, "root");
  488. conf_section(conf_client_section, file, "client");
  489. conf_section(conf_layout_section, file, "layouts");
  490. conf_section(conf_tag_section, file, "tags");
  491. conf_section(conf_menu_section, file, "menu");
  492. conf_section(conf_launcher_section, file, "launcher");
  493. conf_section(conf_keybind_section, file, "keys");
  494. free(file);
  495. return;
  496. }
  497. /** Simple wrapper for calling functions and free pointer
  498. */
  499. static void
  500. conf_section(void (*func)(char*), char *src, char *name)
  501. {
  502. char *sec;
  503. sec = get_sec(src, name);
  504. func(sec);
  505. IFREE(sec);
  506. return;
  507. }