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
;
15 gchar
*config_title_layout
;
17 int config_desktops_num
;
18 GSList
*config_desktops_names
;
20 gboolean config_redraw_resize
;
22 ObStackingLayer config_dock_layer
;
23 gboolean config_dock_floating
;
24 ObDirection config_dock_pos
;
27 ObOrientation config_dock_orient
;
28 gboolean config_dock_hide
;
29 guint config_dock_hide_timeout
;
31 guint config_keyboard_reset_keycode
;
32 guint config_keyboard_reset_state
;
34 gint config_mouse_threshold
;
35 gint config_mouse_dclicktime
;
37 GSList
*config_menu_files
;
39 gint config_resist_win
;
40 gint config_resist_edge
;
42 gchar
*expand_tilde(const gchar
*f
)
49 return g_strconcat(g_get_home_dir(), f
+1, NULL
);
55 <action name="ChangeDesktop">
62 static void parse_key(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
70 if ((n
= parse_find_node("chainQuitKey", node
))) {
71 key
= parse_string(doc
, n
);
72 translate_key(key
, &config_keyboard_reset_state
,
73 &config_keyboard_reset_keycode
);
77 n
= parse_find_node("keybind", node
);
79 if (parse_attr_string("key", n
, &key
)) {
80 keylist
= g_list_append(keylist
, key
);
82 parse_key(i
, doc
, n
->xmlChildrenNode
, keylist
);
84 it
= g_list_last(keylist
);
86 keylist
= g_list_delete_link(keylist
, it
);
88 n
= parse_find_node("keybind", n
->next
);
91 nact
= parse_find_node("action", node
);
93 if ((action
= action_parse(i
, doc
, nact
))) {
94 /* validate that its okay for a key binding */
95 if (action
->func
== action_moveresize
&&
96 action
->data
.moveresize
.corner
!=
97 prop_atoms
.net_wm_moveresize_move_keyboard
&&
98 action
->data
.moveresize
.corner
!=
99 prop_atoms
.net_wm_moveresize_size_keyboard
) {
105 keyboard_bind(keylist
, action
);
107 nact
= parse_find_node("action", nact
->next
);
112 static void parse_keyboard(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
115 parse_key(i
, doc
, node
->xmlChildrenNode
, NULL
);
120 <context name="Titlebar">
121 <mousebind button="Left" action="Press">
122 <action name="Raise"></action>
128 static void parse_mouse(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
131 xmlNodePtr n
, nbut
, nact
;
137 node
= node
->xmlChildrenNode
;
139 if ((n
= parse_find_node("dragThreshold", node
)))
140 config_mouse_threshold
= parse_int(doc
, n
);
141 if ((n
= parse_find_node("doubleClickTime", node
)))
142 config_mouse_dclicktime
= parse_int(doc
, n
);
144 n
= parse_find_node("context", node
);
146 if (!parse_attr_string("name", n
, &contextstr
))
148 nbut
= parse_find_node("mousebind", n
->xmlChildrenNode
);
150 if (!parse_attr_string("button", nbut
, &buttonstr
))
152 if (parse_attr_contains("press", nbut
, "action"))
153 mact
= OB_MOUSE_ACTION_PRESS
;
154 else if (parse_attr_contains("release", nbut
, "action"))
155 mact
= OB_MOUSE_ACTION_RELEASE
;
156 else if (parse_attr_contains("click", nbut
, "action"))
157 mact
= OB_MOUSE_ACTION_CLICK
;
158 else if (parse_attr_contains("doubleclick", nbut
,"action"))
159 mact
= OB_MOUSE_ACTION_DOUBLE_CLICK
;
160 else if (parse_attr_contains("drag", nbut
, "action"))
161 mact
= OB_MOUSE_ACTION_MOTION
;
164 nact
= parse_find_node("action", nbut
->xmlChildrenNode
);
166 if ((action
= action_parse(i
, doc
, nact
))) {
167 /* validate that its okay for a mouse binding*/
168 if (mact
== OB_MOUSE_ACTION_MOTION
) {
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
) {
178 if (action
->func
== action_moveresize
&&
179 action
->data
.moveresize
.corner
!=
180 prop_atoms
.net_wm_moveresize_move_keyboard
&&
181 action
->data
.moveresize
.corner
!=
182 prop_atoms
.net_wm_moveresize_size_keyboard
) {
188 mouse_bind(buttonstr
, contextstr
, mact
, action
);
190 nact
= parse_find_node("action", nact
->next
);
194 nbut
= parse_find_node("mousebind", nbut
->next
);
198 n
= parse_find_node("context", n
->next
);
202 static void parse_focus(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
207 node
= node
->xmlChildrenNode
;
209 if ((n
= parse_find_node("focusNew", node
)))
210 config_focus_new
= parse_bool(doc
, n
);
211 if ((n
= parse_find_node("followMouse", node
)))
212 config_focus_follow
= parse_bool(doc
, n
);
213 if ((n
= parse_find_node("focusLast", node
)))
214 config_focus_last
= parse_bool(doc
, n
);
215 if ((n
= parse_find_node("focusLastOnDesktop", node
)))
216 config_focus_last_on_desktop
= parse_bool(doc
, n
);
219 static void parse_theme(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
224 node
= node
->xmlChildrenNode
;
226 if ((n
= parse_find_node("theme", node
))) {
229 g_free(config_theme
);
230 c
= parse_string(doc
, n
);
231 config_theme
= expand_tilde(c
);
234 if ((n
= parse_find_node("titleLayout", node
))) {
235 g_free(config_title_layout
);
236 config_title_layout
= parse_string(doc
, n
);
240 static void parse_desktops(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
245 node
= node
->xmlChildrenNode
;
247 if ((n
= parse_find_node("number", node
)))
248 config_desktops_num
= parse_int(doc
, n
);
249 if ((n
= parse_find_node("names", node
))) {
253 for (it
= config_desktops_names
; it
; it
= it
->next
)
255 g_slist_free(config_desktops_names
);
256 config_desktops_names
= NULL
;
258 nname
= parse_find_node("name", n
->xmlChildrenNode
);
260 config_desktops_names
= g_slist_append(config_desktops_names
,
261 parse_string(doc
, nname
));
262 nname
= parse_find_node("name", nname
->next
);
267 static void parse_resize(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
272 node
= node
->xmlChildrenNode
;
274 if ((n
= parse_find_node("drawContents", node
)))
275 config_redraw_resize
= parse_bool(doc
, n
);
278 static void parse_dock(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
, void *d
)
282 node
= node
->xmlChildrenNode
;
284 if ((n
= parse_find_node("position", node
))) {
285 if (parse_contains("TopLeft", doc
, n
))
286 config_dock_floating
= FALSE
,
287 config_dock_pos
= OB_DIRECTION_NORTHWEST
;
288 else if (parse_contains("Top", doc
, n
))
289 config_dock_floating
= FALSE
,
290 config_dock_pos
= OB_DIRECTION_NORTH
;
291 else if (parse_contains("TopRight", doc
, n
))
292 config_dock_floating
= FALSE
,
293 config_dock_pos
= OB_DIRECTION_NORTHEAST
;
294 else if (parse_contains("Right", doc
, n
))
295 config_dock_floating
= FALSE
,
296 config_dock_pos
= OB_DIRECTION_EAST
;
297 else if (parse_contains("BottomRight", doc
, n
))
298 config_dock_floating
= FALSE
,
299 config_dock_pos
= OB_DIRECTION_SOUTHEAST
;
300 else if (parse_contains("Bottom", doc
, n
))
301 config_dock_floating
= FALSE
,
302 config_dock_pos
= OB_DIRECTION_SOUTH
;
303 else if (parse_contains("BottomLeft", doc
, n
))
304 config_dock_floating
= FALSE
,
305 config_dock_pos
= OB_DIRECTION_SOUTHWEST
;
306 else if (parse_contains("Left", doc
, n
))
307 config_dock_floating
= FALSE
,
308 config_dock_pos
= OB_DIRECTION_WEST
;
309 else if (parse_contains("Floating", doc
, n
))
310 config_dock_floating
= TRUE
;
312 if (config_dock_floating
) {
313 if ((n
= parse_find_node("floatingX", node
)))
314 config_dock_x
= parse_int(doc
, n
);
315 if ((n
= parse_find_node("floatingY", node
)))
316 config_dock_y
= parse_int(doc
, n
);
318 if ((n
= parse_find_node("stacking", node
))) {
319 if (parse_contains("top", doc
, n
))
320 config_dock_layer
= OB_STACKING_LAYER_TOP
;
321 else if (parse_contains("normal", doc
, n
))
322 config_dock_layer
= OB_STACKING_LAYER_NORMAL
;
323 else if (parse_contains("bottom", doc
, n
))
324 config_dock_layer
= OB_STACKING_LAYER_BELOW
;
326 if ((n
= parse_find_node("direction", node
))) {
327 if (parse_contains("horizontal", doc
, n
))
328 config_dock_orient
= OB_ORIENTATION_HORZ
;
329 else if (parse_contains("vertical", doc
, n
))
330 config_dock_orient
= OB_ORIENTATION_VERT
;
332 if ((n
= parse_find_node("autoHide", node
)))
333 config_dock_hide
= parse_bool(doc
, n
);
334 if ((n
= parse_find_node("hideTimeout", node
)))
335 config_dock_hide_timeout
= parse_int(doc
, n
);
338 static void parse_menu(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
, void *d
)
340 for (node
= node
->xmlChildrenNode
; node
; node
= node
->next
) {
341 if (!xmlStrcasecmp(node
->name
, (const xmlChar
*) "file")) {
344 c
= parse_string(doc
, node
);
345 config_menu_files
= g_slist_append(config_menu_files
,
352 static void parse_resistance(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
357 node
= node
->xmlChildrenNode
;
358 if ((n
= parse_find_node("strength", node
)))
359 config_resist_win
= parse_int(doc
, n
);
360 if ((n
= parse_find_node("screen_edge_strength", node
)))
361 config_resist_edge
= parse_int(doc
, n
);
364 void config_startup(ObParseInst
*i
)
366 config_focus_new
= TRUE
;
367 config_focus_follow
= FALSE
;
368 config_focus_last
= TRUE
;
369 config_focus_last_on_desktop
= TRUE
;
371 parse_register(i
, "focus", parse_focus
, NULL
);
375 config_title_layout
= g_strdup("NLIMC");
377 parse_register(i
, "theme", parse_theme
, NULL
);
379 config_desktops_num
= 4;
380 config_desktops_names
= NULL
;
382 parse_register(i
, "desktops", parse_desktops
, NULL
);
384 config_redraw_resize
= TRUE
;
386 parse_register(i
, "resize", parse_resize
, NULL
);
388 config_dock_layer
= OB_STACKING_LAYER_TOP
;
389 config_dock_pos
= OB_DIRECTION_NORTHEAST
;
390 config_dock_floating
= FALSE
;
393 config_dock_orient
= OB_ORIENTATION_VERT
;
394 config_dock_hide
= FALSE
;
395 config_dock_hide_timeout
= 3000;
397 parse_register(i
, "dock", parse_dock
, NULL
);
399 translate_key("C-g", &config_keyboard_reset_state
,
400 &config_keyboard_reset_keycode
);
402 parse_register(i
, "keyboard", parse_keyboard
, NULL
);
404 config_mouse_threshold
= 3;
405 config_mouse_dclicktime
= 200;
407 parse_register(i
, "mouse", parse_mouse
, NULL
);
409 config_resist_win
= 10;
410 config_resist_edge
= 10;
412 parse_register(i
, "resistance", parse_resistance
, NULL
);
414 config_menu_files
= NULL
;
416 parse_register(i
, "menu", parse_menu
, NULL
);
419 void config_shutdown()
423 g_free(config_theme
);
425 for (it
= config_desktops_names
; it
; it
= g_slist_next(it
))
427 g_slist_free(config_desktops_names
);
429 for (it
= config_menu_files
; it
; it
= g_slist_next(it
))
431 g_slist_free(config_menu_files
);