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;
16 gchar *config_title_layout;
18 int config_desktops_num;
19 GSList *config_desktops_names;
21 gboolean config_redraw_resize;
23 ObStackingLayer config_dock_layer;
24 gboolean config_dock_floating;
25 ObDirection config_dock_pos;
28 ObOrientation config_dock_orient;
29 gboolean config_dock_hide;
30 guint config_dock_hide_timeout;
32 guint config_keyboard_reset_keycode;
33 guint config_keyboard_reset_state;
35 gint config_mouse_threshold;
36 gint config_mouse_dclicktime;
38 GSList *config_menu_files;
40 gint config_resist_win;
41 gint config_resist_edge;
46 <action name="ChangeDesktop">
53 static void parse_key(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
61 if ((n = parse_find_node("chainQuitKey", node))) {
62 key = parse_string(doc, n);
63 translate_key(key, &config_keyboard_reset_state,
64 &config_keyboard_reset_keycode);
68 n = parse_find_node("keybind", node);
70 if (parse_attr_string("key", n, &key)) {
71 keylist = g_list_append(keylist, key);
73 parse_key(i, doc, n->xmlChildrenNode, keylist);
75 it = g_list_last(keylist);
77 keylist = g_list_delete_link(keylist, it);
79 n = parse_find_node("keybind", n->next);
82 nact = parse_find_node("action", node);
84 if ((action = action_parse(i, doc, nact))) {
85 /* validate that its okay for a key binding */
86 if (action->func == action_moveresize &&
87 action->data.moveresize.corner !=
88 prop_atoms.net_wm_moveresize_move_keyboard &&
89 action->data.moveresize.corner !=
90 prop_atoms.net_wm_moveresize_size_keyboard) {
96 keyboard_bind(keylist, action);
98 nact = parse_find_node("action", nact->next);
103 static void parse_keyboard(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
106 parse_key(i, doc, node->xmlChildrenNode, NULL);
111 <context name="Titlebar">
112 <mousebind button="Left" action="Press">
113 <action name="Raise"></action>
119 static void parse_mouse(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
122 xmlNodePtr n, nbut, nact;
128 node = node->xmlChildrenNode;
130 if ((n = parse_find_node("dragThreshold", node)))
131 config_mouse_threshold = parse_int(doc, n);
132 if ((n = parse_find_node("doubleClickTime", node)))
133 config_mouse_dclicktime = parse_int(doc, n);
135 n = parse_find_node("context", node);
137 if (!parse_attr_string("name", n, &contextstr))
139 nbut = parse_find_node("mousebind", n->xmlChildrenNode);
141 if (!parse_attr_string("button", nbut, &buttonstr))
143 if (parse_attr_contains("press", nbut, "action"))
144 mact = OB_MOUSE_ACTION_PRESS;
145 else if (parse_attr_contains("release", nbut, "action"))
146 mact = OB_MOUSE_ACTION_RELEASE;
147 else if (parse_attr_contains("click", nbut, "action"))
148 mact = OB_MOUSE_ACTION_CLICK;
149 else if (parse_attr_contains("doubleclick", nbut,"action"))
150 mact = OB_MOUSE_ACTION_DOUBLE_CLICK;
151 else if (parse_attr_contains("drag", nbut, "action"))
152 mact = OB_MOUSE_ACTION_MOTION;
155 nact = parse_find_node("action", nbut->xmlChildrenNode);
157 if ((action = action_parse(i, doc, nact))) {
158 /* validate that its okay for a mouse binding*/
159 if (mact == OB_MOUSE_ACTION_MOTION) {
160 if (action->func != action_moveresize ||
161 action->data.moveresize.corner ==
162 prop_atoms.net_wm_moveresize_move_keyboard ||
163 action->data.moveresize.corner ==
164 prop_atoms.net_wm_moveresize_size_keyboard) {
169 if (action->func == action_moveresize &&
170 action->data.moveresize.corner !=
171 prop_atoms.net_wm_moveresize_move_keyboard &&
172 action->data.moveresize.corner !=
173 prop_atoms.net_wm_moveresize_size_keyboard) {
179 mouse_bind(buttonstr, contextstr, mact, action);
181 nact = parse_find_node("action", nact->next);
185 nbut = parse_find_node("mousebind", nbut->next);
189 n = parse_find_node("context", n->next);
193 static void parse_focus(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
198 node = node->xmlChildrenNode;
200 if ((n = parse_find_node("focusNew", node)))
201 config_focus_new = parse_bool(doc, n);
202 if ((n = parse_find_node("followMouse", node)))
203 config_focus_follow = parse_bool(doc, n);
204 if ((n = parse_find_node("focusLast", node)))
205 config_focus_last = parse_bool(doc, n);
206 if ((n = parse_find_node("focusLastOnDesktop", node)))
207 config_focus_last_on_desktop = parse_bool(doc, n);
210 static void parse_theme(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
215 node = node->xmlChildrenNode;
217 if ((n = parse_find_node("theme", node))) {
220 g_free(config_theme);
221 c = parse_string(doc, n);
222 config_theme = ob_expand_tilde(c);
225 if ((n = parse_find_node("titleLayout", node))) {
226 g_free(config_title_layout);
227 config_title_layout = parse_string(doc, n);
231 static void parse_desktops(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
236 node = node->xmlChildrenNode;
238 if ((n = parse_find_node("number", node)))
239 config_desktops_num = parse_int(doc, n);
240 if ((n = parse_find_node("names", node))) {
244 for (it = config_desktops_names; it; it = it->next)
246 g_slist_free(config_desktops_names);
247 config_desktops_names = NULL;
249 nname = parse_find_node("name", n->xmlChildrenNode);
251 config_desktops_names = g_slist_append(config_desktops_names,
252 parse_string(doc, nname));
253 nname = parse_find_node("name", nname->next);
258 static void parse_resize(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
263 node = node->xmlChildrenNode;
265 if ((n = parse_find_node("drawContents", node)))
266 config_redraw_resize = parse_bool(doc, n);
269 static void parse_dock(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, void *d)
273 node = node->xmlChildrenNode;
275 if ((n = parse_find_node("position", node))) {
276 if (parse_contains("TopLeft", doc, n))
277 config_dock_floating = FALSE,
278 config_dock_pos = OB_DIRECTION_NORTHWEST;
279 else if (parse_contains("Top", doc, n))
280 config_dock_floating = FALSE,
281 config_dock_pos = OB_DIRECTION_NORTH;
282 else if (parse_contains("TopRight", doc, n))
283 config_dock_floating = FALSE,
284 config_dock_pos = OB_DIRECTION_NORTHEAST;
285 else if (parse_contains("Right", doc, n))
286 config_dock_floating = FALSE,
287 config_dock_pos = OB_DIRECTION_EAST;
288 else if (parse_contains("BottomRight", doc, n))
289 config_dock_floating = FALSE,
290 config_dock_pos = OB_DIRECTION_SOUTHEAST;
291 else if (parse_contains("Bottom", doc, n))
292 config_dock_floating = FALSE,
293 config_dock_pos = OB_DIRECTION_SOUTH;
294 else if (parse_contains("BottomLeft", doc, n))
295 config_dock_floating = FALSE,
296 config_dock_pos = OB_DIRECTION_SOUTHWEST;
297 else if (parse_contains("Left", doc, n))
298 config_dock_floating = FALSE,
299 config_dock_pos = OB_DIRECTION_WEST;
300 else if (parse_contains("Floating", doc, n))
301 config_dock_floating = TRUE;
303 if (config_dock_floating) {
304 if ((n = parse_find_node("floatingX", node)))
305 config_dock_x = parse_int(doc, n);
306 if ((n = parse_find_node("floatingY", node)))
307 config_dock_y = parse_int(doc, n);
309 if ((n = parse_find_node("stacking", node))) {
310 if (parse_contains("top", doc, n))
311 config_dock_layer = OB_STACKING_LAYER_TOP;
312 else if (parse_contains("normal", doc, n))
313 config_dock_layer = OB_STACKING_LAYER_NORMAL;
314 else if (parse_contains("bottom", doc, n))
315 config_dock_layer = OB_STACKING_LAYER_BELOW;
317 if ((n = parse_find_node("direction", node))) {
318 if (parse_contains("horizontal", doc, n))
319 config_dock_orient = OB_ORIENTATION_HORZ;
320 else if (parse_contains("vertical", doc, n))
321 config_dock_orient = OB_ORIENTATION_VERT;
323 if ((n = parse_find_node("autoHide", node)))
324 config_dock_hide = parse_bool(doc, n);
325 if ((n = parse_find_node("hideTimeout", node)))
326 config_dock_hide_timeout = parse_int(doc, n);
329 static void parse_menu(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, void *d)
331 for (node = node->xmlChildrenNode; node; node = node->next) {
332 if (!xmlStrcasecmp(node->name, (const xmlChar*) "file")) {
335 c = parse_string(doc, node);
336 config_menu_files = g_slist_append(config_menu_files,
343 static void parse_resistance(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
348 node = node->xmlChildrenNode;
349 if ((n = parse_find_node("strength", node)))
350 config_resist_win = parse_int(doc, n);
351 if ((n = parse_find_node("screen_edge_strength", node)))
352 config_resist_edge = parse_int(doc, n);
355 void config_startup(ObParseInst *i)
357 config_focus_new = TRUE;
358 config_focus_follow = FALSE;
359 config_focus_last = TRUE;
360 config_focus_last_on_desktop = TRUE;
362 parse_register(i, "focus", parse_focus, NULL);
366 config_title_layout = g_strdup("NLIMC");
368 parse_register(i, "theme", parse_theme, NULL);
370 config_desktops_num = 4;
371 config_desktops_names = NULL;
373 parse_register(i, "desktops", parse_desktops, NULL);
375 config_redraw_resize = TRUE;
377 parse_register(i, "resize", parse_resize, NULL);
379 config_dock_layer = OB_STACKING_LAYER_TOP;
380 config_dock_pos = OB_DIRECTION_NORTHEAST;
381 config_dock_floating = FALSE;
384 config_dock_orient = OB_ORIENTATION_VERT;
385 config_dock_hide = FALSE;
386 config_dock_hide_timeout = 3000;
388 parse_register(i, "dock", parse_dock, NULL);
390 translate_key("C-g", &config_keyboard_reset_state,
391 &config_keyboard_reset_keycode);
393 parse_register(i, "keyboard", parse_keyboard, NULL);
395 config_mouse_threshold = 3;
396 config_mouse_dclicktime = 200;
398 parse_register(i, "mouse", parse_mouse, NULL);
400 config_resist_win = 10;
401 config_resist_edge = 10;
403 parse_register(i, "resistance", parse_resistance, NULL);
405 config_menu_files = NULL;
407 parse_register(i, "menu", parse_menu, NULL);
410 void config_shutdown()
414 g_free(config_theme);
416 for (it = config_desktops_names; it; it = g_slist_next(it))
418 g_slist_free(config_desktops_names);
420 for (it = config_menu_files; it; it = g_slist_next(it))
422 g_slist_free(config_menu_files);