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 int 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 gboolean config_dialog_focus;
61 gboolean config_dialog_desktop;
63 GSList *config_menu_files;
65 gint config_resist_win;
66 gint config_resist_edge;
71 <action name="ChangeDesktop">
78 static void parse_key(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
86 if ((n = parse_find_node("chainQuitKey", node))) {
87 key = parse_string(doc, n);
88 translate_key(key, &config_keyboard_reset_state,
89 &config_keyboard_reset_keycode);
93 n = parse_find_node("keybind", node);
95 if (parse_attr_string("key", n, &key)) {
96 keylist = g_list_append(keylist, key);
98 parse_key(i, doc, n->children, keylist);
100 it = g_list_last(keylist);
102 keylist = g_list_delete_link(keylist, it);
104 n = parse_find_node("keybind", n->next);
107 nact = parse_find_node("action", node);
109 if ((action = action_parse(i, doc, nact,
110 OB_USER_ACTION_KEYBOARD_KEY)))
111 keyboard_bind(keylist, action);
112 nact = parse_find_node("action", nact->next);
117 static void parse_keyboard(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
120 keyboard_unbind_all();
122 parse_key(i, doc, node->children, NULL);
127 <context name="Titlebar">
128 <mousebind button="Left" action="Press">
129 <action name="Raise"></action>
135 static void parse_mouse(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
138 xmlNodePtr n, nbut, nact;
147 node = node->children;
149 if ((n = parse_find_node("dragThreshold", node)))
150 config_mouse_threshold = parse_int(doc, n);
151 if ((n = parse_find_node("doubleClickTime", node)))
152 config_mouse_dclicktime = parse_int(doc, n);
154 n = parse_find_node("context", node);
156 if (!parse_attr_string("name", n, &contextstr))
158 nbut = parse_find_node("mousebind", n->children);
160 if (!parse_attr_string("button", nbut, &buttonstr))
162 if (parse_attr_contains("press", nbut, "action")) {
163 uact = OB_USER_ACTION_MOUSE_PRESS;
164 mact = OB_MOUSE_ACTION_PRESS;
165 } else if (parse_attr_contains("release", nbut, "action")) {
166 uact = OB_USER_ACTION_MOUSE_RELEASE;
167 mact = OB_MOUSE_ACTION_RELEASE;
168 } else if (parse_attr_contains("click", nbut, "action")) {
169 uact = OB_USER_ACTION_MOUSE_CLICK;
170 mact = OB_MOUSE_ACTION_CLICK;
171 } else if (parse_attr_contains("doubleclick", nbut,"action")) {
172 uact = OB_USER_ACTION_MOUSE_DOUBLE_CLICK;
173 mact = OB_MOUSE_ACTION_DOUBLE_CLICK;
174 } else if (parse_attr_contains("drag", nbut, "action")) {
175 uact = OB_USER_ACTION_MOUSE_MOTION;
176 mact = OB_MOUSE_ACTION_MOTION;
179 nact = parse_find_node("action", nbut->children);
181 if ((action = action_parse(i, doc, nact, uact)))
182 mouse_bind(buttonstr, contextstr, mact, action);
183 nact = parse_find_node("action", nact->next);
187 nbut = parse_find_node("mousebind", nbut->next);
191 n = parse_find_node("context", n->next);
195 static void parse_focus(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
200 node = node->children;
202 if ((n = parse_find_node("focusNew", node)))
203 config_focus_new = parse_bool(doc, n);
204 if ((n = parse_find_node("followMouse", node)))
205 config_focus_follow = parse_bool(doc, n);
206 if ((n = parse_find_node("focusDelay", node)))
207 config_focus_delay = parse_int(doc, n) * 1000;
208 if ((n = parse_find_node("raiseOnFocus", node)))
209 config_focus_raise = parse_bool(doc, n);
212 static void parse_placement(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
217 node = node->children;
219 if ((n = parse_find_node("policy", node)))
220 if (parse_contains("UnderMouse", doc, n))
221 config_place_policy = OB_PLACE_POLICY_MOUSE;
224 static void parse_theme(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
229 node = node->children;
231 if ((n = parse_find_node("name", node))) {
234 g_free(config_theme);
235 c = parse_string(doc, n);
236 config_theme = parse_expand_tilde(c);
239 if ((n = parse_find_node("titleLayout", node))) {
240 g_free(config_title_layout);
241 config_title_layout = parse_string(doc, n);
245 static void parse_desktops(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
250 node = node->children;
252 if ((n = parse_find_node("number", node))) {
253 guint d = parse_int(doc, n);
255 config_desktops_num = d;
257 if ((n = parse_find_node("names", node))) {
261 for (it = config_desktops_names; it; it = it->next)
263 g_slist_free(config_desktops_names);
264 config_desktops_names = NULL;
266 nname = parse_find_node("name", n->children);
268 config_desktops_names = g_slist_append(config_desktops_names,
269 parse_string(doc, nname));
270 nname = parse_find_node("name", nname->next);
275 static void parse_resize(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
280 node = node->children;
282 if ((n = parse_find_node("drawContents", node)))
283 config_redraw_resize = parse_bool(doc, n);
286 static void parse_dock(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, void *d)
290 node = node->children;
292 if ((n = parse_find_node("position", node))) {
293 if (parse_contains("TopLeft", doc, n))
294 config_dock_floating = FALSE,
295 config_dock_pos = OB_DIRECTION_NORTHWEST;
296 else if (parse_contains("Top", doc, n))
297 config_dock_floating = FALSE,
298 config_dock_pos = OB_DIRECTION_NORTH;
299 else if (parse_contains("TopRight", doc, n))
300 config_dock_floating = FALSE,
301 config_dock_pos = OB_DIRECTION_NORTHEAST;
302 else if (parse_contains("Right", doc, n))
303 config_dock_floating = FALSE,
304 config_dock_pos = OB_DIRECTION_EAST;
305 else if (parse_contains("BottomRight", doc, n))
306 config_dock_floating = FALSE,
307 config_dock_pos = OB_DIRECTION_SOUTHEAST;
308 else if (parse_contains("Bottom", doc, n))
309 config_dock_floating = FALSE,
310 config_dock_pos = OB_DIRECTION_SOUTH;
311 else if (parse_contains("BottomLeft", doc, n))
312 config_dock_floating = FALSE,
313 config_dock_pos = OB_DIRECTION_SOUTHWEST;
314 else if (parse_contains("Left", doc, n))
315 config_dock_floating = FALSE,
316 config_dock_pos = OB_DIRECTION_WEST;
317 else if (parse_contains("Floating", doc, n))
318 config_dock_floating = TRUE;
320 if (config_dock_floating) {
321 if ((n = parse_find_node("floatingX", node)))
322 config_dock_x = parse_int(doc, n);
323 if ((n = parse_find_node("floatingY", node)))
324 config_dock_y = parse_int(doc, n);
326 if ((n = parse_find_node("stacking", node))) {
327 if (parse_contains("top", doc, n))
328 config_dock_layer = OB_STACKING_LAYER_TOP;
329 else if (parse_contains("normal", doc, n))
330 config_dock_layer = OB_STACKING_LAYER_NORMAL;
331 else if (parse_contains("bottom", doc, n))
332 config_dock_layer = OB_STACKING_LAYER_BELOW;
334 if ((n = parse_find_node("direction", node))) {
335 if (parse_contains("horizontal", doc, n))
336 config_dock_orient = OB_ORIENTATION_HORZ;
337 else if (parse_contains("vertical", doc, n))
338 config_dock_orient = OB_ORIENTATION_VERT;
340 if ((n = parse_find_node("autoHide", node)))
341 config_dock_hide = parse_bool(doc, n);
342 if ((n = parse_find_node("hideDelay", node)))
343 config_dock_hide_delay = parse_int(doc, n) * 1000;
344 if ((n = parse_find_node("moveButton", node))) {
345 gchar *str = parse_string(doc, n);
347 if (translate_button(str, &s, &b)) {
348 config_dock_app_move_button = b;
349 config_dock_app_move_modifiers = s;
351 g_warning("invalid button '%s'", str);
357 static void parse_menu(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, void *d)
359 for (node = node->children; node; node = node->next) {
360 if (!xmlStrcasecmp(node->name, (const xmlChar*) "file")) {
363 c = parse_string(doc, node);
364 config_menu_files = g_slist_append(config_menu_files,
365 parse_expand_tilde(c));
371 static void parse_resistance(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
376 node = node->children;
377 if ((n = parse_find_node("strength", node)))
378 config_resist_win = parse_int(doc, n);
379 if ((n = parse_find_node("screen_edge_strength", node)))
380 config_resist_edge = parse_int(doc, n);
386 const gchar *actname;
389 static void bind_default_keyboard()
392 ObDefKeyBind binds[] = {
393 { "A-Tab", "NextWindow" },
394 { "S-A-Tab", "PreviousWindow" },
399 for (it = binds; it->key; ++it) {
400 GList *l = g_list_append(NULL, g_strdup(it->key));
401 keyboard_bind(l, action_from_string(it->actname,
402 OB_USER_ACTION_KEYBOARD_KEY));
409 const gchar *context;
410 const ObMouseAction mact;
411 const gchar *actname;
414 static void bind_default_mouse()
417 ObDefMouseBind binds[] = {
418 { "Left", "Client", OB_MOUSE_ACTION_PRESS, "Focus" },
419 { "Middle", "Client", OB_MOUSE_ACTION_PRESS, "Focus" },
420 { "Right", "Client", OB_MOUSE_ACTION_PRESS, "Focus" },
421 { "Left", "Desktop", OB_MOUSE_ACTION_PRESS, "Focus" },
422 { "Middle", "Desktop", OB_MOUSE_ACTION_PRESS, "Focus" },
423 { "Right", "Desktop", OB_MOUSE_ACTION_PRESS, "Focus" },
424 { "Left", "Titlebar", OB_MOUSE_ACTION_PRESS, "Focus" },
425 { "Left", "Handle", OB_MOUSE_ACTION_PRESS, "Focus" },
426 { "Left", "BLCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
427 { "Left", "BRCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
428 { "Left", "TLCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
429 { "Left", "TRCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
430 { "Left", "Close", OB_MOUSE_ACTION_PRESS, "Focus" },
431 { "Left", "Maximize", OB_MOUSE_ACTION_PRESS, "Focus" },
432 { "Left", "Iconify", OB_MOUSE_ACTION_PRESS, "Focus" },
433 { "Left", "Icon", OB_MOUSE_ACTION_PRESS, "Focus" },
434 { "Left", "AllDesktops", OB_MOUSE_ACTION_PRESS, "Focus" },
435 { "Left", "Shade", OB_MOUSE_ACTION_PRESS, "Focus" },
436 { "Left", "Client", OB_MOUSE_ACTION_CLICK, "Raise" },
437 { "Left", "Titlebar", OB_MOUSE_ACTION_CLICK, "Raise" },
438 { "Middle", "Titlebar", OB_MOUSE_ACTION_CLICK, "Lower" },
439 { "Left", "Handle", OB_MOUSE_ACTION_CLICK, "Raise" },
440 { "Left", "BLCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
441 { "Left", "BRCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
442 { "Left", "TLCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
443 { "Left", "TRCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
444 { "Left", "Close", OB_MOUSE_ACTION_CLICK, "Raise" },
445 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK, "Raise" },
446 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK, "Raise" },
447 { "Left", "Icon", OB_MOUSE_ACTION_CLICK, "Raise" },
448 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK, "Raise" },
449 { "Left", "Shade", OB_MOUSE_ACTION_CLICK, "Raise" },
450 { "Left", "Close", OB_MOUSE_ACTION_CLICK, "Close" },
451 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK, "ToggleMaximizeFull" },
452 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK, "Iconify" },
453 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK, "ToggleOmnipresent" },
454 { "Left", "Shade", OB_MOUSE_ACTION_CLICK, "ToggleShade" },
455 { "Left", "TLCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
456 { "Left", "TRCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
457 { "Left", "BLCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
458 { "Left", "BRCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
459 { "Left", "Titlebar", OB_MOUSE_ACTION_MOTION, "Move" },
460 { "A-Left", "Frame", OB_MOUSE_ACTION_MOTION, "Move" },
461 { "A-Middle", "Frame", OB_MOUSE_ACTION_MOTION, "Resize" },
462 { NULL, NULL, 0, NULL }
465 for (it = binds; it->button; ++it) {
468 case OB_MOUSE_ACTION_PRESS:
469 uact = OB_USER_ACTION_MOUSE_PRESS; break;
470 case OB_MOUSE_ACTION_RELEASE:
471 uact = OB_USER_ACTION_MOUSE_RELEASE; break;
472 case OB_MOUSE_ACTION_CLICK:
473 uact = OB_USER_ACTION_MOUSE_CLICK; break;
474 case OB_MOUSE_ACTION_DOUBLE_CLICK:
475 uact = OB_USER_ACTION_MOUSE_DOUBLE_CLICK; break;
476 case OB_MOUSE_ACTION_MOTION:
477 uact = OB_USER_ACTION_MOUSE_MOTION; break;
478 case OB_NUM_MOUSE_ACTIONS:
479 g_assert_not_reached();
481 mouse_bind(it->button, it->context, it->mact,
482 action_from_string(it->actname, uact));
486 void config_startup(ObParseInst *i)
488 config_focus_new = TRUE;
489 config_focus_follow = FALSE;
490 config_focus_delay = 0;
491 config_focus_raise = FALSE;
493 parse_register(i, "focus", parse_focus, NULL);
495 config_place_policy = OB_PLACE_POLICY_SMART;
497 parse_register(i, "placement", parse_placement, NULL);
501 config_title_layout = g_strdup("NLIMC");
503 parse_register(i, "theme", parse_theme, NULL);
505 config_desktops_num = 4;
506 config_desktops_names = NULL;
508 parse_register(i, "desktops", parse_desktops, NULL);
510 config_redraw_resize = TRUE;
512 parse_register(i, "resize", parse_resize, NULL);
514 config_dock_layer = OB_STACKING_LAYER_TOP;
515 config_dock_pos = OB_DIRECTION_NORTHEAST;
516 config_dock_floating = FALSE;
519 config_dock_orient = OB_ORIENTATION_VERT;
520 config_dock_hide = FALSE;
521 config_dock_hide_delay = 300;
522 config_dock_app_move_button = 2; /* middle */
523 config_dock_app_move_modifiers = 0;
525 parse_register(i, "dock", parse_dock, NULL);
527 translate_key("C-g", &config_keyboard_reset_state,
528 &config_keyboard_reset_keycode);
530 bind_default_keyboard();
532 parse_register(i, "keyboard", parse_keyboard, NULL);
534 config_mouse_threshold = 3;
535 config_mouse_dclicktime = 200;
537 bind_default_mouse();
539 parse_register(i, "mouse", parse_mouse, NULL);
541 config_resist_win = 10;
542 config_resist_edge = 20;
544 parse_register(i, "resistance", parse_resistance, NULL);
546 config_menu_files = NULL;
548 parse_register(i, "menu", parse_menu, NULL);
551 void config_shutdown()
555 g_free(config_theme);
557 g_free(config_title_layout);
559 for (it = config_desktops_names; it; it = g_slist_next(it))
561 g_slist_free(config_desktops_names);
563 for (it = config_menu_files; it; it = g_slist_next(it))
565 g_slist_free(config_menu_files);