1 /* -*- indent-tabs-mode: nil; 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;
30 guint config_focus_raise;
32 ObPlacePolicy config_place_policy;
36 gchar *config_title_layout;
38 gint config_desktops_num;
39 GSList *config_desktops_names;
41 gboolean config_redraw_resize;
43 ObStackingLayer config_dock_layer;
44 gboolean config_dock_floating;
45 ObDirection config_dock_pos;
48 ObOrientation config_dock_orient;
49 gboolean config_dock_hide;
50 guint config_dock_hide_delay;
51 guint config_dock_app_move_button;
52 guint config_dock_app_move_modifiers;
54 guint config_keyboard_reset_keycode;
55 guint config_keyboard_reset_state;
57 gint config_mouse_threshold;
58 gint config_mouse_dclicktime;
60 GSList *config_menu_files;
62 gint config_resist_win;
63 gint config_resist_edge;
68 <action name="ChangeDesktop">
75 static void parse_key(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
83 if ((n = parse_find_node("chainQuitKey", node))) {
84 key = parse_string(doc, n);
85 translate_key(key, &config_keyboard_reset_state,
86 &config_keyboard_reset_keycode);
90 n = parse_find_node("keybind", node);
92 if (parse_attr_string("key", n, &key)) {
93 keylist = g_list_append(keylist, key);
95 parse_key(i, doc, n->children, keylist);
97 it = g_list_last(keylist);
99 keylist = g_list_delete_link(keylist, it);
101 n = parse_find_node("keybind", n->next);
104 nact = parse_find_node("action", node);
106 if ((action = action_parse(i, doc, nact,
107 OB_USER_ACTION_KEYBOARD_KEY)))
108 keyboard_bind(keylist, action);
109 nact = parse_find_node("action", nact->next);
114 static void parse_keyboard(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
117 keyboard_unbind_all();
119 parse_key(i, doc, node->children, NULL);
124 <context name="Titlebar">
125 <mousebind button="Left" action="Press">
126 <action name="Raise"></action>
132 static void parse_mouse(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
135 xmlNodePtr n, nbut, nact;
144 node = node->children;
146 if ((n = parse_find_node("dragThreshold", node)))
147 config_mouse_threshold = parse_int(doc, n);
148 if ((n = parse_find_node("doubleClickTime", node)))
149 config_mouse_dclicktime = parse_int(doc, n);
151 n = parse_find_node("context", node);
153 if (!parse_attr_string("name", n, &contextstr))
155 nbut = parse_find_node("mousebind", n->children);
157 if (!parse_attr_string("button", nbut, &buttonstr))
159 if (parse_attr_contains("press", nbut, "action")) {
160 uact = OB_USER_ACTION_MOUSE_PRESS;
161 mact = OB_MOUSE_ACTION_PRESS;
162 } else if (parse_attr_contains("release", nbut, "action")) {
163 uact = OB_USER_ACTION_MOUSE_RELEASE;
164 mact = OB_MOUSE_ACTION_RELEASE;
165 } else if (parse_attr_contains("click", nbut, "action")) {
166 uact = OB_USER_ACTION_MOUSE_CLICK;
167 mact = OB_MOUSE_ACTION_CLICK;
168 } else if (parse_attr_contains("doubleclick", nbut,"action")) {
169 uact = OB_USER_ACTION_MOUSE_DOUBLE_CLICK;
170 mact = OB_MOUSE_ACTION_DOUBLE_CLICK;
171 } else if (parse_attr_contains("drag", nbut, "action")) {
172 uact = OB_USER_ACTION_MOUSE_MOTION;
173 mact = OB_MOUSE_ACTION_MOTION;
176 nact = parse_find_node("action", nbut->children);
178 if ((action = action_parse(i, doc, nact, uact)))
179 mouse_bind(buttonstr, contextstr, mact, action);
180 nact = parse_find_node("action", nact->next);
184 nbut = parse_find_node("mousebind", nbut->next);
188 n = parse_find_node("context", n->next);
192 static void parse_focus(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
197 node = node->children;
199 if ((n = parse_find_node("focusNew", node)))
200 config_focus_new = parse_bool(doc, n);
201 if ((n = parse_find_node("followMouse", node)))
202 config_focus_follow = parse_bool(doc, n);
203 if ((n = parse_find_node("focusDelay", node)))
204 config_focus_delay = parse_int(doc, n) * 1000;
205 if ((n = parse_find_node("raiseOnFocus", node)))
206 config_focus_raise = parse_bool(doc, n);
209 static void parse_placement(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
214 node = node->children;
216 if ((n = parse_find_node("policy", node)))
217 if (parse_contains("UnderMouse", doc, n))
218 config_place_policy = OB_PLACE_POLICY_MOUSE;
221 static void parse_theme(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
226 node = node->children;
228 if ((n = parse_find_node("name", node))) {
231 g_free(config_theme);
232 c = parse_string(doc, n);
233 config_theme = parse_expand_tilde(c);
236 if ((n = parse_find_node("titleLayout", node))) {
237 g_free(config_title_layout);
238 config_title_layout = parse_string(doc, n);
242 static void parse_desktops(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
247 node = node->children;
249 if ((n = parse_find_node("number", node))) {
250 guint d = parse_int(doc, n);
252 config_desktops_num = d;
254 if ((n = parse_find_node("names", node))) {
258 for (it = config_desktops_names; it; it = it->next)
260 g_slist_free(config_desktops_names);
261 config_desktops_names = NULL;
263 nname = parse_find_node("name", n->children);
265 config_desktops_names = g_slist_append(config_desktops_names,
266 parse_string(doc, nname));
267 nname = parse_find_node("name", nname->next);
272 static void parse_resize(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
277 node = node->children;
279 if ((n = parse_find_node("drawContents", node)))
280 config_redraw_resize = parse_bool(doc, n);
283 static void parse_dock(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
288 node = node->children;
290 if ((n = parse_find_node("position", node))) {
291 if (parse_contains("TopLeft", doc, n))
292 config_dock_floating = FALSE,
293 config_dock_pos = OB_DIRECTION_NORTHWEST;
294 else if (parse_contains("Top", doc, n))
295 config_dock_floating = FALSE,
296 config_dock_pos = OB_DIRECTION_NORTH;
297 else if (parse_contains("TopRight", doc, n))
298 config_dock_floating = FALSE,
299 config_dock_pos = OB_DIRECTION_NORTHEAST;
300 else if (parse_contains("Right", doc, n))
301 config_dock_floating = FALSE,
302 config_dock_pos = OB_DIRECTION_EAST;
303 else if (parse_contains("BottomRight", doc, n))
304 config_dock_floating = FALSE,
305 config_dock_pos = OB_DIRECTION_SOUTHEAST;
306 else if (parse_contains("Bottom", doc, n))
307 config_dock_floating = FALSE,
308 config_dock_pos = OB_DIRECTION_SOUTH;
309 else if (parse_contains("BottomLeft", doc, n))
310 config_dock_floating = FALSE,
311 config_dock_pos = OB_DIRECTION_SOUTHWEST;
312 else if (parse_contains("Left", doc, n))
313 config_dock_floating = FALSE,
314 config_dock_pos = OB_DIRECTION_WEST;
315 else if (parse_contains("Floating", doc, n))
316 config_dock_floating = TRUE;
318 if (config_dock_floating) {
319 if ((n = parse_find_node("floatingX", node)))
320 config_dock_x = parse_int(doc, n);
321 if ((n = parse_find_node("floatingY", node)))
322 config_dock_y = parse_int(doc, n);
324 if ((n = parse_find_node("stacking", node))) {
325 if (parse_contains("top", doc, n))
326 config_dock_layer = OB_STACKING_LAYER_DOCK_ABOVE;
327 else if (parse_contains("normal", doc, n))
328 config_dock_layer = OB_STACKING_LAYER_DOCK_NORMAL;
329 else if (parse_contains("bottom", doc, n))
330 config_dock_layer = OB_STACKING_LAYER_DOCK_BELOW;
332 if ((n = parse_find_node("direction", node))) {
333 if (parse_contains("horizontal", doc, n))
334 config_dock_orient = OB_ORIENTATION_HORZ;
335 else if (parse_contains("vertical", doc, n))
336 config_dock_orient = OB_ORIENTATION_VERT;
338 if ((n = parse_find_node("autoHide", node)))
339 config_dock_hide = parse_bool(doc, n);
340 if ((n = parse_find_node("hideDelay", node)))
341 config_dock_hide_delay = parse_int(doc, n) * 1000;
342 if ((n = parse_find_node("moveButton", node))) {
343 gchar *str = parse_string(doc, n);
345 if (translate_button(str, &s, &b)) {
346 config_dock_app_move_button = b;
347 config_dock_app_move_modifiers = s;
349 g_warning("invalid button '%s'", str);
355 static void parse_menu(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
358 for (node = node->children; node; node = node->next) {
359 if (!xmlStrcasecmp(node->name, (const xmlChar*) "file")) {
362 c = parse_string(doc, node);
363 config_menu_files = g_slist_append(config_menu_files,
364 parse_expand_tilde(c));
370 static void parse_resistance(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
375 node = node->children;
376 if ((n = parse_find_node("strength", node)))
377 config_resist_win = parse_int(doc, n);
378 if ((n = parse_find_node("screen_edge_strength", node)))
379 config_resist_edge = parse_int(doc, n);
385 const gchar *actname;
388 static void bind_default_keyboard()
391 ObDefKeyBind binds[] = {
392 { "A-Tab", "NextWindow" },
393 { "S-A-Tab", "PreviousWindow" },
398 for (it = binds; it->key; ++it) {
399 GList *l = g_list_append(NULL, g_strdup(it->key));
400 keyboard_bind(l, action_from_string(it->actname,
401 OB_USER_ACTION_KEYBOARD_KEY));
408 const gchar *context;
409 const ObMouseAction mact;
410 const gchar *actname;
413 static void bind_default_mouse()
416 ObDefMouseBind binds[] = {
417 { "Left", "Client", OB_MOUSE_ACTION_PRESS, "Focus" },
418 { "Middle", "Client", OB_MOUSE_ACTION_PRESS, "Focus" },
419 { "Right", "Client", OB_MOUSE_ACTION_PRESS, "Focus" },
420 { "Left", "Desktop", OB_MOUSE_ACTION_PRESS, "Focus" },
421 { "Middle", "Desktop", OB_MOUSE_ACTION_PRESS, "Focus" },
422 { "Right", "Desktop", OB_MOUSE_ACTION_PRESS, "Focus" },
423 { "Left", "Titlebar", OB_MOUSE_ACTION_PRESS, "Focus" },
424 { "Left", "Handle", OB_MOUSE_ACTION_PRESS, "Focus" },
425 { "Left", "BLCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
426 { "Left", "BRCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
427 { "Left", "TLCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
428 { "Left", "TRCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
429 { "Left", "Close", OB_MOUSE_ACTION_PRESS, "Focus" },
430 { "Left", "Maximize", OB_MOUSE_ACTION_PRESS, "Focus" },
431 { "Left", "Iconify", OB_MOUSE_ACTION_PRESS, "Focus" },
432 { "Left", "Icon", OB_MOUSE_ACTION_PRESS, "Focus" },
433 { "Left", "AllDesktops", OB_MOUSE_ACTION_PRESS, "Focus" },
434 { "Left", "Shade", OB_MOUSE_ACTION_PRESS, "Focus" },
435 { "Left", "Client", OB_MOUSE_ACTION_CLICK, "Raise" },
436 { "Left", "Titlebar", OB_MOUSE_ACTION_CLICK, "Raise" },
437 { "Middle", "Titlebar", OB_MOUSE_ACTION_CLICK, "Lower" },
438 { "Left", "Handle", OB_MOUSE_ACTION_CLICK, "Raise" },
439 { "Left", "BLCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
440 { "Left", "BRCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
441 { "Left", "TLCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
442 { "Left", "TRCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
443 { "Left", "Close", OB_MOUSE_ACTION_CLICK, "Raise" },
444 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK, "Raise" },
445 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK, "Raise" },
446 { "Left", "Icon", OB_MOUSE_ACTION_CLICK, "Raise" },
447 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK, "Raise" },
448 { "Left", "Shade", OB_MOUSE_ACTION_CLICK, "Raise" },
449 { "Left", "Close", OB_MOUSE_ACTION_CLICK, "Close" },
450 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK, "ToggleMaximizeFull" },
451 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK, "Iconify" },
452 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK, "ToggleOmnipresent" },
453 { "Left", "Shade", OB_MOUSE_ACTION_CLICK, "ToggleShade" },
454 { "Left", "TLCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
455 { "Left", "TRCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
456 { "Left", "BLCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
457 { "Left", "BRCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
458 { "Left", "Titlebar", OB_MOUSE_ACTION_MOTION, "Move" },
459 { "A-Left", "Frame", OB_MOUSE_ACTION_MOTION, "Move" },
460 { "A-Middle", "Frame", OB_MOUSE_ACTION_MOTION, "Resize" },
461 { NULL, NULL, 0, NULL }
464 for (it = binds; it->button; ++it) {
467 case OB_MOUSE_ACTION_PRESS:
468 uact = OB_USER_ACTION_MOUSE_PRESS; break;
469 case OB_MOUSE_ACTION_RELEASE:
470 uact = OB_USER_ACTION_MOUSE_RELEASE; break;
471 case OB_MOUSE_ACTION_CLICK:
472 uact = OB_USER_ACTION_MOUSE_CLICK; break;
473 case OB_MOUSE_ACTION_DOUBLE_CLICK:
474 uact = OB_USER_ACTION_MOUSE_DOUBLE_CLICK; break;
475 case OB_MOUSE_ACTION_MOTION:
476 uact = OB_USER_ACTION_MOUSE_MOTION; break;
477 case OB_NUM_MOUSE_ACTIONS:
478 g_assert_not_reached();
480 mouse_bind(it->button, it->context, it->mact,
481 action_from_string(it->actname, uact));
485 void config_startup(ObParseInst *i)
487 config_focus_new = TRUE;
488 config_focus_follow = FALSE;
489 config_focus_delay = 0;
490 config_focus_raise = FALSE;
492 parse_register(i, "focus", parse_focus, NULL);
494 config_place_policy = OB_PLACE_POLICY_SMART;
496 parse_register(i, "placement", parse_placement, NULL);
500 config_title_layout = g_strdup("NLIMC");
502 parse_register(i, "theme", parse_theme, NULL);
504 config_desktops_num = 4;
505 config_desktops_names = NULL;
507 parse_register(i, "desktops", parse_desktops, NULL);
509 config_redraw_resize = TRUE;
511 parse_register(i, "resize", parse_resize, NULL);
513 config_dock_layer = OB_STACKING_LAYER_DOCK_ABOVE;
514 config_dock_pos = OB_DIRECTION_NORTHEAST;
515 config_dock_floating = FALSE;
518 config_dock_orient = OB_ORIENTATION_VERT;
519 config_dock_hide = FALSE;
520 config_dock_hide_delay = 300;
521 config_dock_app_move_button = 2; /* middle */
522 config_dock_app_move_modifiers = 0;
524 parse_register(i, "dock", parse_dock, NULL);
526 translate_key("C-g", &config_keyboard_reset_state,
527 &config_keyboard_reset_keycode);
529 bind_default_keyboard();
531 parse_register(i, "keyboard", parse_keyboard, NULL);
533 config_mouse_threshold = 3;
534 config_mouse_dclicktime = 200;
536 bind_default_mouse();
538 parse_register(i, "mouse", parse_mouse, NULL);
540 config_resist_win = 10;
541 config_resist_edge = 20;
543 parse_register(i, "resistance", parse_resistance, NULL);
545 config_menu_files = NULL;
547 parse_register(i, "menu", parse_menu, NULL);
550 void config_shutdown()
554 g_free(config_theme);
556 g_free(config_title_layout);
558 for (it = config_desktops_names; it; it = g_slist_next(it))
560 g_slist_free(config_desktops_names);
562 for (it = config_menu_files; it; it = g_slist_next(it))
564 g_slist_free(config_menu_files);