1 /* -*- indent-tabs-mode: t; tab-width: 4; c-basic-offset: 4; -*-
3 config.c for the Openbox window manager
4 Copyright (c) 2003 Ben Jansens
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 See the COPYING file for a copy of the GNU General Public License.
23 #include "translate.h"
24 #include "parser/parse.h"
27 gboolean config_focus_new;
28 gboolean config_focus_follow;
29 guint config_focus_delay;
33 gchar *config_title_layout;
35 int config_desktops_num;
36 GSList *config_desktops_names;
38 gboolean config_redraw_resize;
40 ObStackingLayer config_dock_layer;
41 gboolean config_dock_floating;
42 ObDirection config_dock_pos;
45 ObOrientation config_dock_orient;
46 gboolean config_dock_hide;
47 guint config_dock_hide_timeout;
49 guint config_keyboard_reset_keycode;
50 guint config_keyboard_reset_state;
52 gint config_mouse_threshold;
53 gint config_mouse_dclicktime;
55 GSList *config_menu_files;
57 gint config_resist_win;
58 gint config_resist_edge;
63 <action name="ChangeDesktop">
70 static void parse_key(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
78 if ((n = parse_find_node("chainQuitKey", node))) {
79 key = parse_string(doc, n);
80 translate_key(key, &config_keyboard_reset_state,
81 &config_keyboard_reset_keycode);
85 n = parse_find_node("keybind", node);
87 if (parse_attr_string("key", n, &key)) {
88 keylist = g_list_append(keylist, key);
90 parse_key(i, doc, n->children, keylist);
92 it = g_list_last(keylist);
94 keylist = g_list_delete_link(keylist, it);
96 n = parse_find_node("keybind", n->next);
99 nact = parse_find_node("action", node);
101 if ((action = action_parse(i, doc, nact,
102 OB_USER_ACTION_KEYBOARD_KEY)))
103 keyboard_bind(keylist, action);
104 nact = parse_find_node("action", nact->next);
109 static void parse_keyboard(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
112 parse_key(i, doc, node->children, NULL);
117 <context name="Titlebar">
118 <mousebind button="Left" action="Press">
119 <action name="Raise"></action>
125 static void parse_mouse(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
128 xmlNodePtr n, nbut, nact;
135 node = node->children;
137 if ((n = parse_find_node("dragThreshold", node)))
138 config_mouse_threshold = parse_int(doc, n);
139 if ((n = parse_find_node("doubleClickTime", node)))
140 config_mouse_dclicktime = parse_int(doc, n);
142 n = parse_find_node("context", node);
144 if (!parse_attr_string("name", n, &contextstr))
146 nbut = parse_find_node("mousebind", n->children);
148 if (!parse_attr_string("button", nbut, &buttonstr))
150 if (parse_attr_contains("press", nbut, "action")) {
151 uact = OB_USER_ACTION_MOUSE_PRESS;
152 mact = OB_MOUSE_ACTION_PRESS;
153 } else if (parse_attr_contains("release", nbut, "action")) {
154 uact = OB_USER_ACTION_MOUSE_RELEASE;
155 mact = OB_MOUSE_ACTION_RELEASE;
156 } else if (parse_attr_contains("click", nbut, "action")) {
157 uact = OB_USER_ACTION_MOUSE_CLICK;
158 mact = OB_MOUSE_ACTION_CLICK;
159 } else if (parse_attr_contains("doubleclick", nbut,"action")) {
160 uact = OB_USER_ACTION_MOUSE_DOUBLE_CLICK;
161 mact = OB_MOUSE_ACTION_DOUBLE_CLICK;
162 } else if (parse_attr_contains("drag", nbut, "action")) {
163 uact = OB_USER_ACTION_MOUSE_MOTION;
164 mact = OB_MOUSE_ACTION_MOTION;
167 nact = parse_find_node("action", nbut->children);
169 if ((action = action_parse(i, doc, nact, uact)))
170 mouse_bind(buttonstr, contextstr, mact, action);
171 nact = parse_find_node("action", nact->next);
175 nbut = parse_find_node("mousebind", nbut->next);
179 n = parse_find_node("context", n->next);
183 static void parse_focus(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
188 node = node->children;
190 if ((n = parse_find_node("focusNew", node)))
191 config_focus_new = parse_bool(doc, n);
192 if ((n = parse_find_node("followMouse", node)))
193 config_focus_follow = parse_bool(doc, n);
194 if ((n = parse_find_node("focusDelay", node)))
195 config_focus_delay = parse_int(doc, n) * 1000;
198 static void parse_theme(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
203 node = node->children;
205 if ((n = parse_find_node("name", node))) {
208 g_free(config_theme);
209 c = parse_string(doc, n);
210 config_theme = parse_expand_tilde(c);
213 if ((n = parse_find_node("titleLayout", node))) {
214 g_free(config_title_layout);
215 config_title_layout = parse_string(doc, n);
219 static void parse_desktops(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
224 node = node->children;
226 if ((n = parse_find_node("number", node)))
227 config_desktops_num = parse_int(doc, n);
228 if ((n = parse_find_node("names", node))) {
232 for (it = config_desktops_names; it; it = it->next)
234 g_slist_free(config_desktops_names);
235 config_desktops_names = NULL;
237 nname = parse_find_node("name", n->children);
239 config_desktops_names = g_slist_append(config_desktops_names,
240 parse_string(doc, nname));
241 nname = parse_find_node("name", nname->next);
246 static void parse_resize(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
251 node = node->children;
253 if ((n = parse_find_node("drawContents", node)))
254 config_redraw_resize = parse_bool(doc, n);
257 static void parse_dock(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, void *d)
261 node = node->children;
263 if ((n = parse_find_node("position", node))) {
264 if (parse_contains("TopLeft", doc, n))
265 config_dock_floating = FALSE,
266 config_dock_pos = OB_DIRECTION_NORTHWEST;
267 else if (parse_contains("Top", doc, n))
268 config_dock_floating = FALSE,
269 config_dock_pos = OB_DIRECTION_NORTH;
270 else if (parse_contains("TopRight", doc, n))
271 config_dock_floating = FALSE,
272 config_dock_pos = OB_DIRECTION_NORTHEAST;
273 else if (parse_contains("Right", doc, n))
274 config_dock_floating = FALSE,
275 config_dock_pos = OB_DIRECTION_EAST;
276 else if (parse_contains("BottomRight", doc, n))
277 config_dock_floating = FALSE,
278 config_dock_pos = OB_DIRECTION_SOUTHEAST;
279 else if (parse_contains("Bottom", doc, n))
280 config_dock_floating = FALSE,
281 config_dock_pos = OB_DIRECTION_SOUTH;
282 else if (parse_contains("BottomLeft", doc, n))
283 config_dock_floating = FALSE,
284 config_dock_pos = OB_DIRECTION_SOUTHWEST;
285 else if (parse_contains("Left", doc, n))
286 config_dock_floating = FALSE,
287 config_dock_pos = OB_DIRECTION_WEST;
288 else if (parse_contains("Floating", doc, n))
289 config_dock_floating = TRUE;
291 if (config_dock_floating) {
292 if ((n = parse_find_node("floatingX", node)))
293 config_dock_x = parse_int(doc, n);
294 if ((n = parse_find_node("floatingY", node)))
295 config_dock_y = parse_int(doc, n);
297 if ((n = parse_find_node("stacking", node))) {
298 if (parse_contains("top", doc, n))
299 config_dock_layer = OB_STACKING_LAYER_TOP;
300 else if (parse_contains("normal", doc, n))
301 config_dock_layer = OB_STACKING_LAYER_NORMAL;
302 else if (parse_contains("bottom", doc, n))
303 config_dock_layer = OB_STACKING_LAYER_BELOW;
305 if ((n = parse_find_node("direction", node))) {
306 if (parse_contains("horizontal", doc, n))
307 config_dock_orient = OB_ORIENTATION_HORZ;
308 else if (parse_contains("vertical", doc, n))
309 config_dock_orient = OB_ORIENTATION_VERT;
311 if ((n = parse_find_node("autoHide", node)))
312 config_dock_hide = parse_bool(doc, n);
313 if ((n = parse_find_node("hideTimeout", node)))
314 config_dock_hide_timeout = parse_int(doc, n) * 1000;
317 static void parse_menu(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, void *d)
319 for (node = node->children; node; node = node->next) {
320 if (!xmlStrcasecmp(node->name, (const xmlChar*) "file")) {
323 c = parse_string(doc, node);
324 config_menu_files = g_slist_append(config_menu_files,
325 parse_expand_tilde(c));
331 static void parse_resistance(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
336 node = node->children;
337 if ((n = parse_find_node("strength", node)))
338 config_resist_win = parse_int(doc, n);
339 if ((n = parse_find_node("screen_edge_strength", node)))
340 config_resist_edge = parse_int(doc, n);
343 void config_startup(ObParseInst *i)
345 config_focus_new = TRUE;
346 config_focus_follow = FALSE;
347 config_focus_delay = 0;
349 parse_register(i, "focus", parse_focus, NULL);
353 config_title_layout = g_strdup("NLIMC");
355 parse_register(i, "theme", parse_theme, NULL);
357 config_desktops_num = 4;
358 config_desktops_names = NULL;
360 parse_register(i, "desktops", parse_desktops, NULL);
362 config_redraw_resize = TRUE;
364 parse_register(i, "resize", parse_resize, NULL);
366 config_dock_layer = OB_STACKING_LAYER_TOP;
367 config_dock_pos = OB_DIRECTION_NORTHEAST;
368 config_dock_floating = FALSE;
371 config_dock_orient = OB_ORIENTATION_VERT;
372 config_dock_hide = FALSE;
373 config_dock_hide_timeout = 300;
375 parse_register(i, "dock", parse_dock, NULL);
377 translate_key("C-g", &config_keyboard_reset_state,
378 &config_keyboard_reset_keycode);
380 parse_register(i, "keyboard", parse_keyboard, NULL);
382 config_mouse_threshold = 3;
383 config_mouse_dclicktime = 200;
385 parse_register(i, "mouse", parse_mouse, NULL);
387 config_resist_win = 10;
388 config_resist_edge = 20;
390 parse_register(i, "resistance", parse_resistance, NULL);
392 config_menu_files = NULL;
394 parse_register(i, "menu", parse_menu, NULL);
397 void config_shutdown()
401 g_free(config_theme);
403 g_free(config_title_layout);
405 for (it = config_desktops_names; it; it = g_slist_next(it))
407 g_slist_free(config_desktops_names);
409 for (it = config_menu_files; it; it = g_slist_next(it))
411 g_slist_free(config_menu_files);