6 #include "parser/parse.h"
9 gboolean config_focus_new;
10 gboolean config_focus_follow;
11 gboolean config_focus_last;
12 gboolean config_focus_last_on_desktop;
13 guint config_focus_delay;
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;
47 <action name="ChangeDesktop">
54 static void parse_key(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
62 if ((n = parse_find_node("chainQuitKey", node))) {
63 key = parse_string(doc, n);
64 translate_key(key, &config_keyboard_reset_state,
65 &config_keyboard_reset_keycode);
69 n = parse_find_node("keybind", node);
71 if (parse_attr_string("key", n, &key)) {
72 keylist = g_list_append(keylist, key);
74 parse_key(i, doc, n->xmlChildrenNode, keylist);
76 it = g_list_last(keylist);
78 keylist = g_list_delete_link(keylist, it);
80 n = parse_find_node("keybind", n->next);
83 nact = parse_find_node("action", node);
85 if ((action = action_parse(i, doc, nact))) {
86 /* validate that its okay for a key binding */
87 if (action->func == action_moveresize &&
88 action->data.moveresize.corner !=
89 prop_atoms.net_wm_moveresize_move_keyboard &&
90 action->data.moveresize.corner !=
91 prop_atoms.net_wm_moveresize_size_keyboard) {
97 keyboard_bind(keylist, action);
99 nact = parse_find_node("action", nact->next);
104 static void parse_keyboard(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
107 parse_key(i, doc, node->xmlChildrenNode, NULL);
112 <context name="Titlebar">
113 <mousebind button="Left" action="Press">
114 <action name="Raise"></action>
120 static void parse_mouse(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
123 xmlNodePtr n, nbut, nact;
129 node = node->xmlChildrenNode;
131 if ((n = parse_find_node("dragThreshold", node)))
132 config_mouse_threshold = parse_int(doc, n);
133 if ((n = parse_find_node("doubleClickTime", node)))
134 config_mouse_dclicktime = parse_int(doc, n);
136 n = parse_find_node("context", node);
138 if (!parse_attr_string("name", n, &contextstr))
140 nbut = parse_find_node("mousebind", n->xmlChildrenNode);
142 if (!parse_attr_string("button", nbut, &buttonstr))
144 if (parse_attr_contains("press", nbut, "action"))
145 mact = OB_MOUSE_ACTION_PRESS;
146 else if (parse_attr_contains("release", nbut, "action"))
147 mact = OB_MOUSE_ACTION_RELEASE;
148 else if (parse_attr_contains("click", nbut, "action"))
149 mact = OB_MOUSE_ACTION_CLICK;
150 else if (parse_attr_contains("doubleclick", nbut,"action"))
151 mact = OB_MOUSE_ACTION_DOUBLE_CLICK;
152 else if (parse_attr_contains("drag", nbut, "action"))
153 mact = OB_MOUSE_ACTION_MOTION;
156 nact = parse_find_node("action", nbut->xmlChildrenNode);
158 if ((action = action_parse(i, doc, nact))) {
159 /* validate that its okay for a mouse binding*/
160 if (mact == OB_MOUSE_ACTION_MOTION) {
161 if (action->func != action_moveresize ||
162 action->data.moveresize.corner ==
163 prop_atoms.net_wm_moveresize_move_keyboard ||
164 action->data.moveresize.corner ==
165 prop_atoms.net_wm_moveresize_size_keyboard) {
170 if (action->func == action_moveresize &&
171 action->data.moveresize.corner !=
172 prop_atoms.net_wm_moveresize_move_keyboard &&
173 action->data.moveresize.corner !=
174 prop_atoms.net_wm_moveresize_size_keyboard) {
180 mouse_bind(buttonstr, contextstr, mact, action);
182 nact = parse_find_node("action", nact->next);
186 nbut = parse_find_node("mousebind", nbut->next);
190 n = parse_find_node("context", n->next);
194 static void parse_focus(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
199 node = node->xmlChildrenNode;
201 if ((n = parse_find_node("focusNew", node)))
202 config_focus_new = parse_bool(doc, n);
203 if ((n = parse_find_node("followMouse", node)))
204 config_focus_follow = parse_bool(doc, n);
205 if ((n = parse_find_node("focusLast", node)))
206 config_focus_last = parse_bool(doc, n);
207 if ((n = parse_find_node("focusLastOnDesktop", node)))
208 config_focus_last_on_desktop = parse_bool(doc, n);
209 if ((n = parse_find_node("focusDelay", node)))
210 config_focus_delay = parse_int(doc, n);
213 static void parse_theme(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
218 node = node->xmlChildrenNode;
220 if ((n = parse_find_node("name", node))) {
223 g_free(config_theme);
224 c = parse_string(doc, n);
225 config_theme = ob_expand_tilde(c);
228 if ((n = parse_find_node("titleLayout", node))) {
229 g_free(config_title_layout);
230 config_title_layout = parse_string(doc, n);
234 static void parse_desktops(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
239 node = node->xmlChildrenNode;
241 if ((n = parse_find_node("number", node)))
242 config_desktops_num = parse_int(doc, n);
243 if ((n = parse_find_node("names", node))) {
247 for (it = config_desktops_names; it; it = it->next)
249 g_slist_free(config_desktops_names);
250 config_desktops_names = NULL;
252 nname = parse_find_node("name", n->xmlChildrenNode);
254 config_desktops_names = g_slist_append(config_desktops_names,
255 parse_string(doc, nname));
256 nname = parse_find_node("name", nname->next);
261 static void parse_resize(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
266 node = node->xmlChildrenNode;
268 if ((n = parse_find_node("drawContents", node)))
269 config_redraw_resize = parse_bool(doc, n);
272 static void parse_dock(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, void *d)
276 node = node->xmlChildrenNode;
278 if ((n = parse_find_node("position", node))) {
279 if (parse_contains("TopLeft", doc, n))
280 config_dock_floating = FALSE,
281 config_dock_pos = OB_DIRECTION_NORTHWEST;
282 else if (parse_contains("Top", doc, n))
283 config_dock_floating = FALSE,
284 config_dock_pos = OB_DIRECTION_NORTH;
285 else if (parse_contains("TopRight", doc, n))
286 config_dock_floating = FALSE,
287 config_dock_pos = OB_DIRECTION_NORTHEAST;
288 else if (parse_contains("Right", doc, n))
289 config_dock_floating = FALSE,
290 config_dock_pos = OB_DIRECTION_EAST;
291 else if (parse_contains("BottomRight", doc, n))
292 config_dock_floating = FALSE,
293 config_dock_pos = OB_DIRECTION_SOUTHEAST;
294 else if (parse_contains("Bottom", doc, n))
295 config_dock_floating = FALSE,
296 config_dock_pos = OB_DIRECTION_SOUTH;
297 else if (parse_contains("BottomLeft", doc, n))
298 config_dock_floating = FALSE,
299 config_dock_pos = OB_DIRECTION_SOUTHWEST;
300 else if (parse_contains("Left", doc, n))
301 config_dock_floating = FALSE,
302 config_dock_pos = OB_DIRECTION_WEST;
303 else if (parse_contains("Floating", doc, n))
304 config_dock_floating = TRUE;
306 if (config_dock_floating) {
307 if ((n = parse_find_node("floatingX", node)))
308 config_dock_x = parse_int(doc, n);
309 if ((n = parse_find_node("floatingY", node)))
310 config_dock_y = parse_int(doc, n);
312 if ((n = parse_find_node("stacking", node))) {
313 if (parse_contains("top", doc, n))
314 config_dock_layer = OB_STACKING_LAYER_TOP;
315 else if (parse_contains("normal", doc, n))
316 config_dock_layer = OB_STACKING_LAYER_NORMAL;
317 else if (parse_contains("bottom", doc, n))
318 config_dock_layer = OB_STACKING_LAYER_BELOW;
320 if ((n = parse_find_node("direction", node))) {
321 if (parse_contains("horizontal", doc, n))
322 config_dock_orient = OB_ORIENTATION_HORZ;
323 else if (parse_contains("vertical", doc, n))
324 config_dock_orient = OB_ORIENTATION_VERT;
326 if ((n = parse_find_node("autoHide", node)))
327 config_dock_hide = parse_bool(doc, n);
328 if ((n = parse_find_node("hideTimeout", node)))
329 config_dock_hide_timeout = parse_int(doc, n);
332 static void parse_menu(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, void *d)
334 for (node = node->xmlChildrenNode; node; node = node->next) {
335 if (!xmlStrcasecmp(node->name, (const xmlChar*) "file")) {
338 c = parse_string(doc, node);
339 config_menu_files = g_slist_append(config_menu_files,
346 static void parse_resistance(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
351 node = node->xmlChildrenNode;
352 if ((n = parse_find_node("strength", node)))
353 config_resist_win = parse_int(doc, n);
354 if ((n = parse_find_node("screen_edge_strength", node)))
355 config_resist_edge = parse_int(doc, n);
358 void config_startup(ObParseInst *i)
360 config_focus_new = TRUE;
361 config_focus_follow = FALSE;
362 config_focus_last = TRUE;
363 config_focus_last_on_desktop = TRUE;
364 config_focus_delay = 150000;
366 parse_register(i, "focus", parse_focus, NULL);
370 config_title_layout = g_strdup("NLIMC");
372 parse_register(i, "theme", parse_theme, NULL);
374 config_desktops_num = 4;
375 config_desktops_names = NULL;
377 parse_register(i, "desktops", parse_desktops, NULL);
379 config_redraw_resize = TRUE;
381 parse_register(i, "resize", parse_resize, NULL);
383 config_dock_layer = OB_STACKING_LAYER_TOP;
384 config_dock_pos = OB_DIRECTION_NORTHEAST;
385 config_dock_floating = FALSE;
388 config_dock_orient = OB_ORIENTATION_VERT;
389 config_dock_hide = FALSE;
390 config_dock_hide_timeout = 3000;
392 parse_register(i, "dock", parse_dock, NULL);
394 translate_key("C-g", &config_keyboard_reset_state,
395 &config_keyboard_reset_keycode);
397 parse_register(i, "keyboard", parse_keyboard, NULL);
399 config_mouse_threshold = 3;
400 config_mouse_dclicktime = 200;
402 parse_register(i, "mouse", parse_mouse, NULL);
404 config_resist_win = 10;
405 config_resist_edge = 20;
407 parse_register(i, "resistance", parse_resistance, NULL);
409 config_menu_files = NULL;
411 parse_register(i, "menu", parse_menu, NULL);
414 void config_shutdown()
418 g_free(config_theme);
420 for (it = config_desktops_names; it; it = g_slist_next(it))
422 g_slist_free(config_desktops_names);
424 for (it = config_menu_files; it; it = g_slist_next(it))
426 g_slist_free(config_menu_files);