6 #include "parser/parse.h"
8 gboolean config_focus_new;
9 gboolean config_focus_follow;
10 gboolean config_focus_last;
11 gboolean config_focus_last_on_desktop;
12 gboolean config_focus_popup;
13 gboolean config_desktop_popup;
17 gchar *config_title_layout;
19 int config_desktops_num;
20 GSList *config_desktops_names;
22 gboolean config_redraw_resize;
24 ObStackingLayer config_dock_layer;
25 gboolean config_dock_floating;
26 ObDirection config_dock_pos;
29 ObOrientation config_dock_orient;
30 gboolean config_dock_hide;
31 guint config_dock_hide_timeout;
33 guint config_keyboard_reset_keycode;
34 guint config_keyboard_reset_state;
36 gint config_mouse_threshold;
37 gint config_mouse_dclicktime;
39 GSList *config_menu_files;
41 gint config_resist_win;
42 gint config_resist_edge;
44 gchar *expand_tilde(const gchar *f)
51 return g_strconcat(g_get_home_dir(), f+1, NULL);
57 <action name="ChangeDesktop">
64 static void parse_key(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
72 if ((n = parse_find_node("chainQuitKey", node))) {
73 key = parse_string(doc, n);
74 translate_key(key, &config_keyboard_reset_state,
75 &config_keyboard_reset_keycode);
79 n = parse_find_node("keybind", node);
81 if (parse_attr_string("key", n, &key)) {
82 keylist = g_list_append(keylist, key);
84 parse_key(i, doc, n->xmlChildrenNode, keylist);
86 it = g_list_last(keylist);
88 keylist = g_list_delete_link(keylist, it);
90 n = parse_find_node("keybind", n->next);
93 nact = parse_find_node("action", node);
95 if ((action = action_parse(i, doc, nact))) {
96 /* validate that its okay for a key binding */
97 if (action->func == action_moveresize &&
98 action->data.moveresize.corner !=
99 prop_atoms.net_wm_moveresize_move_keyboard &&
100 action->data.moveresize.corner !=
101 prop_atoms.net_wm_moveresize_size_keyboard) {
107 keyboard_bind(keylist, action);
109 nact = parse_find_node("action", nact->next);
114 static void parse_keyboard(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
117 parse_key(i, doc, node->xmlChildrenNode, NULL);
122 <context name="Titlebar">
123 <mousebind button="Left" action="Press">
124 <action name="Raise"></action>
130 static void parse_mouse(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
133 xmlNodePtr n, nbut, nact;
139 node = node->xmlChildrenNode;
141 if ((n = parse_find_node("dragThreshold", node)))
142 config_mouse_threshold = parse_int(doc, n);
143 if ((n = parse_find_node("doubleClickTime", node)))
144 config_mouse_dclicktime = parse_int(doc, n);
146 n = parse_find_node("context", node);
148 if (!parse_attr_string("name", n, &contextstr))
150 nbut = parse_find_node("mousebind", n->xmlChildrenNode);
152 if (!parse_attr_string("button", nbut, &buttonstr))
154 if (parse_attr_contains("press", nbut, "action"))
155 mact = OB_MOUSE_ACTION_PRESS;
156 else if (parse_attr_contains("release", nbut, "action"))
157 mact = OB_MOUSE_ACTION_RELEASE;
158 else if (parse_attr_contains("click", nbut, "action"))
159 mact = OB_MOUSE_ACTION_CLICK;
160 else if (parse_attr_contains("doubleclick", nbut,"action"))
161 mact = OB_MOUSE_ACTION_DOUBLE_CLICK;
162 else if (parse_attr_contains("drag", nbut, "action"))
163 mact = OB_MOUSE_ACTION_MOTION;
166 nact = parse_find_node("action", nbut->xmlChildrenNode);
168 if ((action = action_parse(i, doc, nact))) {
169 /* validate that its okay for a mouse binding*/
170 if (mact == OB_MOUSE_ACTION_MOTION) {
171 if (action->func != action_moveresize ||
172 action->data.moveresize.corner ==
173 prop_atoms.net_wm_moveresize_move_keyboard ||
174 action->data.moveresize.corner ==
175 prop_atoms.net_wm_moveresize_size_keyboard) {
180 if (action->func == action_moveresize &&
181 action->data.moveresize.corner !=
182 prop_atoms.net_wm_moveresize_move_keyboard &&
183 action->data.moveresize.corner !=
184 prop_atoms.net_wm_moveresize_size_keyboard) {
190 mouse_bind(buttonstr, contextstr, mact, action);
192 nact = parse_find_node("action", nact->next);
196 nbut = parse_find_node("mousebind", nbut->next);
200 n = parse_find_node("context", n->next);
204 static void parse_focus(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
209 node = node->xmlChildrenNode;
211 if ((n = parse_find_node("focusNew", node)))
212 config_focus_new = parse_bool(doc, n);
213 if ((n = parse_find_node("followMouse", node)))
214 config_focus_follow = parse_bool(doc, n);
215 if ((n = parse_find_node("focusLast", node)))
216 config_focus_last = parse_bool(doc, n);
217 if ((n = parse_find_node("focusLastOnDesktop", node)))
218 config_focus_last_on_desktop = parse_bool(doc, n);
219 if ((n = parse_find_node("cyclingDialog", node)))
220 config_focus_popup = parse_bool(doc, n);
223 static void parse_theme(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
228 node = node->xmlChildrenNode;
230 if ((n = parse_find_node("theme", node))) {
233 g_free(config_theme);
234 c = parse_string(doc, n);
235 config_theme = expand_tilde(c);
238 if ((n = parse_find_node("titleLayout", node))) {
239 g_free(config_title_layout);
240 config_title_layout = parse_string(doc, n);
244 static void parse_desktops(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
249 node = node->xmlChildrenNode;
251 if ((n = parse_find_node("number", node)))
252 config_desktops_num = parse_int(doc, n);
253 if ((n = parse_find_node("names", node))) {
257 for (it = config_desktops_names; it; it = it->next)
259 g_slist_free(config_desktops_names);
260 config_desktops_names = NULL;
262 nname = parse_find_node("name", n->xmlChildrenNode);
264 config_desktops_names = g_slist_append(config_desktops_names,
265 parse_string(doc, nname));
266 nname = parse_find_node("name", nname->next);
269 if ((n = parse_find_node("cyclingDialog", node)))
270 config_desktop_popup = parse_bool(doc, n);
273 static void parse_resize(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
278 node = node->xmlChildrenNode;
280 if ((n = parse_find_node("drawContents", node)))
281 config_redraw_resize = parse_bool(doc, n);
284 static void parse_dock(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, void *d)
288 node = node->xmlChildrenNode;
290 if ((n = parse_find_node("position", node))) {
291 if (parse_contains("TopLeft", doc, n))
292 config_dock_floating = FALSE,
293 config_dock_pos = OB_DIRECTION_NORTHWEST;
294 else if (parse_contains("Top", doc, n))
295 config_dock_floating = FALSE,
296 config_dock_pos = OB_DIRECTION_NORTH;
297 else if (parse_contains("TopRight", doc, n))
298 config_dock_floating = FALSE,
299 config_dock_pos = OB_DIRECTION_NORTHEAST;
300 else if (parse_contains("Right", doc, n))
301 config_dock_floating = FALSE,
302 config_dock_pos = OB_DIRECTION_EAST;
303 else if (parse_contains("BottomRight", doc, n))
304 config_dock_floating = FALSE,
305 config_dock_pos = OB_DIRECTION_SOUTHEAST;
306 else if (parse_contains("Bottom", doc, n))
307 config_dock_floating = FALSE,
308 config_dock_pos = OB_DIRECTION_SOUTH;
309 else if (parse_contains("BottomLeft", doc, n))
310 config_dock_floating = FALSE,
311 config_dock_pos = OB_DIRECTION_SOUTHWEST;
312 else if (parse_contains("Left", doc, n))
313 config_dock_floating = FALSE,
314 config_dock_pos = OB_DIRECTION_WEST;
315 else if (parse_contains("Floating", doc, n))
316 config_dock_floating = TRUE;
318 if (config_dock_floating) {
319 if ((n = parse_find_node("floatingX", node)))
320 config_dock_x = parse_int(doc, n);
321 if ((n = parse_find_node("floatingY", node)))
322 config_dock_y = parse_int(doc, n);
324 if ((n = parse_find_node("stacking", node))) {
325 if (parse_contains("top", doc, n))
326 config_dock_layer = OB_STACKING_LAYER_TOP;
327 else if (parse_contains("normal", doc, n))
328 config_dock_layer = OB_STACKING_LAYER_NORMAL;
329 else if (parse_contains("bottom", doc, n))
330 config_dock_layer = OB_STACKING_LAYER_BELOW;
332 if ((n = parse_find_node("direction", node))) {
333 if (parse_contains("horizontal", doc, n))
334 config_dock_orient = OB_ORIENTATION_HORZ;
335 else if (parse_contains("vertical", doc, n))
336 config_dock_orient = OB_ORIENTATION_VERT;
338 if ((n = parse_find_node("autoHide", node)))
339 config_dock_hide = parse_bool(doc, n);
340 if ((n = parse_find_node("hideTimeout", node)))
341 config_dock_hide_timeout = parse_int(doc, n);
344 static void parse_menu(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, void *d)
346 for (node = node->xmlChildrenNode; node; node = node->next) {
347 if (!xmlStrcasecmp(node->name, (const xmlChar*) "file")) {
350 c = parse_string(doc, node);
351 config_menu_files = g_slist_append(config_menu_files,
358 static void parse_resistance(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
363 node = node->xmlChildrenNode;
364 if ((n = parse_find_node("strength", node)))
365 config_resist_win = parse_int(doc, n);
366 if ((n = parse_find_node("screen_edge_strength", node)))
367 config_resist_edge = parse_int(doc, n);
370 void config_startup(ObParseInst *i)
372 config_focus_new = TRUE;
373 config_focus_follow = FALSE;
374 config_focus_last = TRUE;
375 config_focus_last_on_desktop = TRUE;
376 config_focus_popup = TRUE;
378 parse_register(i, "focus", parse_focus, NULL);
382 config_title_layout = g_strdup("NLIMC");
384 parse_register(i, "theme", parse_theme, NULL);
386 config_desktops_num = 4;
387 config_desktops_names = NULL;
388 config_desktop_popup = TRUE;
390 parse_register(i, "desktops", parse_desktops, NULL);
392 config_redraw_resize = TRUE;
394 parse_register(i, "resize", parse_resize, NULL);
396 config_dock_layer = OB_STACKING_LAYER_TOP;
397 config_dock_pos = OB_DIRECTION_NORTHEAST;
398 config_dock_floating = FALSE;
401 config_dock_orient = OB_ORIENTATION_VERT;
402 config_dock_hide = FALSE;
403 config_dock_hide_timeout = 3000;
405 parse_register(i, "dock", parse_dock, NULL);
407 translate_key("C-g", &config_keyboard_reset_state,
408 &config_keyboard_reset_keycode);
410 parse_register(i, "keyboard", parse_keyboard, NULL);
412 config_mouse_threshold = 3;
413 config_mouse_dclicktime = 200;
415 parse_register(i, "mouse", parse_mouse, NULL);
417 config_resist_win = 10;
418 config_resist_edge = 10;
420 parse_register(i, "resistance", parse_resistance, NULL);
422 config_menu_files = NULL;
424 parse_register(i, "menu", parse_menu, NULL);
427 void config_shutdown()
431 g_free(config_theme);
433 for (it = config_desktops_names; it; it = g_slist_next(it))
435 g_slist_free(config_desktops_names);
437 for (it = config_menu_files; it; it = g_slist_next(it))
439 g_slist_free(config_menu_files);