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->children, 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 OB_USER_ACTION_KEYBOARD_KEY)))
87 keyboard_bind(keylist, action);
88 nact = parse_find_node("action", nact->next);
93 static void parse_keyboard(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
96 parse_key(i, doc, node->children, NULL);
101 <context name="Titlebar">
102 <mousebind button="Left" action="Press">
103 <action name="Raise"></action>
109 static void parse_mouse(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
112 xmlNodePtr n, nbut, nact;
119 node = node->children;
121 if ((n = parse_find_node("dragThreshold", node)))
122 config_mouse_threshold = parse_int(doc, n);
123 if ((n = parse_find_node("doubleClickTime", node)))
124 config_mouse_dclicktime = parse_int(doc, n);
126 n = parse_find_node("context", node);
128 if (!parse_attr_string("name", n, &contextstr))
130 nbut = parse_find_node("mousebind", n->children);
132 if (!parse_attr_string("button", nbut, &buttonstr))
134 if (parse_attr_contains("press", nbut, "action")) {
135 uact = OB_USER_ACTION_MOUSE_PRESS;
136 mact = OB_MOUSE_ACTION_PRESS;
137 } else if (parse_attr_contains("release", nbut, "action")) {
138 uact = OB_USER_ACTION_MOUSE_RELEASE;
139 mact = OB_MOUSE_ACTION_RELEASE;
140 } else if (parse_attr_contains("click", nbut, "action")) {
141 uact = OB_USER_ACTION_MOUSE_CLICK;
142 mact = OB_MOUSE_ACTION_CLICK;
143 } else if (parse_attr_contains("doubleclick", nbut,"action")) {
144 uact = OB_USER_ACTION_MOUSE_DOUBLE_CLICK;
145 mact = OB_MOUSE_ACTION_DOUBLE_CLICK;
146 } else if (parse_attr_contains("drag", nbut, "action")) {
147 uact = OB_USER_ACTION_MOUSE_MOTION;
148 mact = OB_MOUSE_ACTION_MOTION;
151 nact = parse_find_node("action", nbut->children);
153 if ((action = action_parse(i, doc, nact, uact)))
154 mouse_bind(buttonstr, contextstr, mact, action);
155 nact = parse_find_node("action", nact->next);
159 nbut = parse_find_node("mousebind", nbut->next);
163 n = parse_find_node("context", n->next);
167 static void parse_focus(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
172 node = node->children;
174 if ((n = parse_find_node("focusNew", node)))
175 config_focus_new = parse_bool(doc, n);
176 if ((n = parse_find_node("followMouse", node)))
177 config_focus_follow = parse_bool(doc, n);
178 if ((n = parse_find_node("focusLast", node)))
179 config_focus_last = parse_bool(doc, n);
180 if ((n = parse_find_node("focusLastOnDesktop", node)))
181 config_focus_last_on_desktop = parse_bool(doc, n);
182 if ((n = parse_find_node("focusDelay", node)))
183 config_focus_delay = parse_int(doc, n) * 1000;
186 static void parse_theme(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
191 node = node->children;
193 if ((n = parse_find_node("name", node))) {
196 g_free(config_theme);
197 c = parse_string(doc, n);
198 config_theme = ob_expand_tilde(c);
201 if ((n = parse_find_node("titleLayout", node))) {
202 g_free(config_title_layout);
203 config_title_layout = parse_string(doc, n);
207 static void parse_desktops(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
212 node = node->children;
214 if ((n = parse_find_node("number", node)))
215 config_desktops_num = parse_int(doc, n);
216 if ((n = parse_find_node("names", node))) {
220 for (it = config_desktops_names; it; it = it->next)
222 g_slist_free(config_desktops_names);
223 config_desktops_names = NULL;
225 nname = parse_find_node("name", n->children);
227 config_desktops_names = g_slist_append(config_desktops_names,
228 parse_string(doc, nname));
229 nname = parse_find_node("name", nname->next);
234 static void parse_resize(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
239 node = node->children;
241 if ((n = parse_find_node("drawContents", node)))
242 config_redraw_resize = parse_bool(doc, n);
245 static void parse_dock(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, void *d)
249 node = node->children;
251 if ((n = parse_find_node("position", node))) {
252 if (parse_contains("TopLeft", doc, n))
253 config_dock_floating = FALSE,
254 config_dock_pos = OB_DIRECTION_NORTHWEST;
255 else if (parse_contains("Top", doc, n))
256 config_dock_floating = FALSE,
257 config_dock_pos = OB_DIRECTION_NORTH;
258 else if (parse_contains("TopRight", doc, n))
259 config_dock_floating = FALSE,
260 config_dock_pos = OB_DIRECTION_NORTHEAST;
261 else if (parse_contains("Right", doc, n))
262 config_dock_floating = FALSE,
263 config_dock_pos = OB_DIRECTION_EAST;
264 else if (parse_contains("BottomRight", doc, n))
265 config_dock_floating = FALSE,
266 config_dock_pos = OB_DIRECTION_SOUTHEAST;
267 else if (parse_contains("Bottom", doc, n))
268 config_dock_floating = FALSE,
269 config_dock_pos = OB_DIRECTION_SOUTH;
270 else if (parse_contains("BottomLeft", doc, n))
271 config_dock_floating = FALSE,
272 config_dock_pos = OB_DIRECTION_SOUTHWEST;
273 else if (parse_contains("Left", doc, n))
274 config_dock_floating = FALSE,
275 config_dock_pos = OB_DIRECTION_WEST;
276 else if (parse_contains("Floating", doc, n))
277 config_dock_floating = TRUE;
279 if (config_dock_floating) {
280 if ((n = parse_find_node("floatingX", node)))
281 config_dock_x = parse_int(doc, n);
282 if ((n = parse_find_node("floatingY", node)))
283 config_dock_y = parse_int(doc, n);
285 if ((n = parse_find_node("stacking", node))) {
286 if (parse_contains("top", doc, n))
287 config_dock_layer = OB_STACKING_LAYER_TOP;
288 else if (parse_contains("normal", doc, n))
289 config_dock_layer = OB_STACKING_LAYER_NORMAL;
290 else if (parse_contains("bottom", doc, n))
291 config_dock_layer = OB_STACKING_LAYER_BELOW;
293 if ((n = parse_find_node("direction", node))) {
294 if (parse_contains("horizontal", doc, n))
295 config_dock_orient = OB_ORIENTATION_HORZ;
296 else if (parse_contains("vertical", doc, n))
297 config_dock_orient = OB_ORIENTATION_VERT;
299 if ((n = parse_find_node("autoHide", node)))
300 config_dock_hide = parse_bool(doc, n);
301 if ((n = parse_find_node("hideTimeout", node)))
302 config_dock_hide_timeout = parse_int(doc, n) * 1000;
305 static void parse_menu(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, void *d)
307 for (node = node->children; node; node = node->next) {
308 if (!xmlStrcasecmp(node->name, (const xmlChar*) "file")) {
311 c = parse_string(doc, node);
312 config_menu_files = g_slist_append(config_menu_files,
319 static void parse_resistance(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
324 node = node->children;
325 if ((n = parse_find_node("strength", node)))
326 config_resist_win = parse_int(doc, n);
327 if ((n = parse_find_node("screen_edge_strength", node)))
328 config_resist_edge = parse_int(doc, n);
331 void config_startup(ObParseInst *i)
333 config_focus_new = TRUE;
334 config_focus_follow = FALSE;
335 config_focus_last = TRUE;
336 config_focus_last_on_desktop = TRUE;
337 config_focus_delay = 0;
339 parse_register(i, "focus", parse_focus, NULL);
343 config_title_layout = g_strdup("NLIMC");
345 parse_register(i, "theme", parse_theme, NULL);
347 config_desktops_num = 4;
348 config_desktops_names = NULL;
350 parse_register(i, "desktops", parse_desktops, NULL);
352 config_redraw_resize = TRUE;
354 parse_register(i, "resize", parse_resize, NULL);
356 config_dock_layer = OB_STACKING_LAYER_TOP;
357 config_dock_pos = OB_DIRECTION_NORTHEAST;
358 config_dock_floating = FALSE;
361 config_dock_orient = OB_ORIENTATION_VERT;
362 config_dock_hide = FALSE;
363 config_dock_hide_timeout = 300;
365 parse_register(i, "dock", parse_dock, NULL);
367 translate_key("C-g", &config_keyboard_reset_state,
368 &config_keyboard_reset_keycode);
370 parse_register(i, "keyboard", parse_keyboard, NULL);
372 config_mouse_threshold = 3;
373 config_mouse_dclicktime = 200;
375 parse_register(i, "mouse", parse_mouse, NULL);
377 config_resist_win = 10;
378 config_resist_edge = 20;
380 parse_register(i, "resistance", parse_resistance, NULL);
382 config_menu_files = NULL;
384 parse_register(i, "menu", parse_menu, NULL);
387 void config_shutdown()
391 g_free(config_theme);
393 for (it = config_desktops_names; it; it = g_slist_next(it))
395 g_slist_free(config_desktops_names);
397 for (it = config_menu_files; it; it = g_slist_next(it))
399 g_slist_free(config_menu_files);