1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 config.c for the Openbox window manager
4 Copyright (c) 2004 Mikael Magnusson
5 Copyright (c) 2003 Ben Jansens
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 See the COPYING file for a copy of the GNU General Public License.
24 #include "translate.h"
25 #include "parser/parse.h"
28 gboolean config_focus_new;
29 gboolean config_focus_follow;
30 guint config_focus_delay;
31 gboolean config_focus_raise;
32 gboolean config_focus_last;
34 ObPlacePolicy config_place_policy;
37 gboolean config_theme_keepborder;
38 gboolean config_theme_hidedisabled;
40 gchar *config_title_layout;
42 gint config_desktops_num;
43 GSList *config_desktops_names;
44 gint config_screen_firstdesk;
46 gboolean config_resize_redraw;
47 gboolean config_resize_four_corners;
48 gint config_resize_popup_show;
49 gint config_resize_popup_pos;
51 ObStackingLayer config_dock_layer;
52 gboolean config_dock_floating;
53 gboolean config_dock_nostrut;
54 ObDirection config_dock_pos;
57 ObOrientation config_dock_orient;
58 gboolean config_dock_hide;
59 guint config_dock_hide_delay;
60 guint config_dock_show_delay;
61 guint config_dock_app_move_button;
62 guint config_dock_app_move_modifiers;
64 guint config_keyboard_reset_keycode;
65 guint config_keyboard_reset_state;
67 gint config_mouse_threshold;
68 gint config_mouse_dclicktime;
70 gboolean config_menu_warppointer;
71 gboolean config_menu_xorstyle;
72 guint config_menu_hide_delay;
73 guint config_submenu_show_delay;
74 gboolean config_menu_client_list_icons;
76 GSList *config_menu_files;
78 gint config_resist_win;
79 gint config_resist_edge;
81 gboolean config_resist_layers_below;
86 <action name="ChangeDesktop">
93 static void parse_key(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
101 if ((n = parse_find_node("chainQuitKey", node))) {
102 key = parse_string(doc, n);
103 translate_key(key, &config_keyboard_reset_state,
104 &config_keyboard_reset_keycode);
108 n = parse_find_node("keybind", node);
110 if (parse_attr_string("key", n, &key)) {
111 keylist = g_list_append(keylist, key);
113 parse_key(i, doc, n->children, keylist);
115 it = g_list_last(keylist);
117 keylist = g_list_delete_link(keylist, it);
119 n = parse_find_node("keybind", n->next);
122 nact = parse_find_node("action", node);
124 if ((action = action_parse(i, doc, nact,
125 OB_USER_ACTION_KEYBOARD_KEY)))
126 keyboard_bind(keylist, action);
127 nact = parse_find_node("action", nact->next);
132 static void parse_keyboard(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
135 keyboard_unbind_all();
137 parse_key(i, doc, node->children, NULL);
142 <context name="Titlebar">
143 <mousebind button="Left" action="Press">
144 <action name="Raise"></action>
150 static void parse_mouse(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
153 xmlNodePtr n, nbut, nact;
162 node = node->children;
164 if ((n = parse_find_node("dragThreshold", node)))
165 config_mouse_threshold = parse_int(doc, n);
166 if ((n = parse_find_node("doubleClickTime", node)))
167 config_mouse_dclicktime = parse_int(doc, n);
169 n = parse_find_node("context", node);
171 if (!parse_attr_string("name", n, &contextstr))
173 nbut = parse_find_node("mousebind", n->children);
175 if (!parse_attr_string("button", nbut, &buttonstr))
177 if (parse_attr_contains("press", nbut, "action")) {
178 uact = OB_USER_ACTION_MOUSE_PRESS;
179 mact = OB_MOUSE_ACTION_PRESS;
180 } else if (parse_attr_contains("release", nbut, "action")) {
181 uact = OB_USER_ACTION_MOUSE_RELEASE;
182 mact = OB_MOUSE_ACTION_RELEASE;
183 } else if (parse_attr_contains("click", nbut, "action")) {
184 uact = OB_USER_ACTION_MOUSE_CLICK;
185 mact = OB_MOUSE_ACTION_CLICK;
186 } else if (parse_attr_contains("doubleclick", nbut,"action")) {
187 uact = OB_USER_ACTION_MOUSE_DOUBLE_CLICK;
188 mact = OB_MOUSE_ACTION_DOUBLE_CLICK;
189 } else if (parse_attr_contains("drag", nbut, "action")) {
190 uact = OB_USER_ACTION_MOUSE_MOTION;
191 mact = OB_MOUSE_ACTION_MOTION;
194 nact = parse_find_node("action", nbut->children);
196 if ((action = action_parse(i, doc, nact, uact)))
197 mouse_bind(buttonstr, contextstr, mact, action);
198 nact = parse_find_node("action", nact->next);
202 nbut = parse_find_node("mousebind", nbut->next);
206 n = parse_find_node("context", n->next);
210 static void parse_focus(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
215 node = node->children;
217 if ((n = parse_find_node("focusNew", node)))
218 config_focus_new = parse_bool(doc, n);
219 if ((n = parse_find_node("followMouse", node)))
220 config_focus_follow = parse_bool(doc, n);
221 if ((n = parse_find_node("focusDelay", node)))
222 config_focus_delay = parse_int(doc, n) * 1000;
223 if ((n = parse_find_node("raiseOnFocus", node)))
224 config_focus_raise = parse_bool(doc, n);
225 if ((n = parse_find_node("focusLast", node)))
226 config_focus_last = parse_bool(doc, n);
229 static void parse_placement(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
234 node = node->children;
236 if ((n = parse_find_node("policy", node)))
237 if (parse_contains("UnderMouse", doc, n))
238 config_place_policy = OB_PLACE_POLICY_MOUSE;
241 static void parse_theme(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
246 node = node->children;
248 if ((n = parse_find_node("name", node))) {
251 g_free(config_theme);
252 c = parse_string(doc, n);
253 config_theme = parse_expand_tilde(c);
256 if ((n = parse_find_node("titleLayout", node))) {
257 g_free(config_title_layout);
258 config_title_layout = parse_string(doc, n);
260 if ((n = parse_find_node("keepBorder", node)))
261 config_theme_keepborder = parse_bool(doc, n);
262 if ((n = parse_find_node("hideDisabled", node)))
263 config_theme_hidedisabled = parse_bool(doc, n);
266 static void parse_desktops(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
271 node = node->children;
273 if ((n = parse_find_node("number", node))) {
274 gint d = parse_int(doc, n);
276 config_desktops_num = d;
278 if ((n = parse_find_node("firstdesk", node))) {
279 gint d = parse_int(doc, n);
281 config_screen_firstdesk = d;
283 if ((n = parse_find_node("names", node))) {
287 for (it = config_desktops_names; it; it = it->next)
289 g_slist_free(config_desktops_names);
290 config_desktops_names = NULL;
292 nname = parse_find_node("name", n->children);
294 config_desktops_names = g_slist_append(config_desktops_names,
295 parse_string(doc, nname));
296 nname = parse_find_node("name", nname->next);
301 static void parse_resize(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
306 node = node->children;
308 if ((n = parse_find_node("drawContents", node)))
309 config_resize_redraw = parse_bool(doc, n);
310 if ((n = parse_find_node("fourCorner", node)))
311 config_resize_four_corners = parse_bool(doc, n);
312 if ((n = parse_find_node("popupShow", node))) {
313 config_resize_popup_show = parse_int(doc, n);
314 if (parse_contains("Always", doc, n))
315 config_resize_popup_show = 2;
316 else if (parse_contains("Never", doc, n))
317 config_resize_popup_show = 0;
318 else if (parse_contains("Nonpixel", doc, n))
319 config_resize_popup_show = 1;
321 if ((n = parse_find_node("popupPosition", node))) {
322 config_resize_popup_pos = parse_int(doc, n);
323 if (parse_contains("Top", doc, n))
324 config_resize_popup_pos = 1;
325 else if (parse_contains("Center", doc, n))
326 config_resize_popup_pos = 0;
330 static void parse_dock(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
335 node = node->children;
337 if ((n = parse_find_node("position", node))) {
338 if (parse_contains("TopLeft", doc, n))
339 config_dock_floating = FALSE,
340 config_dock_pos = OB_DIRECTION_NORTHWEST;
341 else if (parse_contains("Top", doc, n))
342 config_dock_floating = FALSE,
343 config_dock_pos = OB_DIRECTION_NORTH;
344 else if (parse_contains("TopRight", doc, n))
345 config_dock_floating = FALSE,
346 config_dock_pos = OB_DIRECTION_NORTHEAST;
347 else if (parse_contains("Right", doc, n))
348 config_dock_floating = FALSE,
349 config_dock_pos = OB_DIRECTION_EAST;
350 else if (parse_contains("BottomRight", doc, n))
351 config_dock_floating = FALSE,
352 config_dock_pos = OB_DIRECTION_SOUTHEAST;
353 else if (parse_contains("Bottom", doc, n))
354 config_dock_floating = FALSE,
355 config_dock_pos = OB_DIRECTION_SOUTH;
356 else if (parse_contains("BottomLeft", doc, n))
357 config_dock_floating = FALSE,
358 config_dock_pos = OB_DIRECTION_SOUTHWEST;
359 else if (parse_contains("Left", doc, n))
360 config_dock_floating = FALSE,
361 config_dock_pos = OB_DIRECTION_WEST;
362 else if (parse_contains("Floating", doc, n))
363 config_dock_floating = TRUE;
365 if (config_dock_floating) {
366 if ((n = parse_find_node("floatingX", node)))
367 config_dock_x = parse_int(doc, n);
368 if ((n = parse_find_node("floatingY", node)))
369 config_dock_y = parse_int(doc, n);
371 if ((n = parse_find_node("noStrut", node)))
372 config_dock_nostrut = parse_bool(doc, n);
374 if ((n = parse_find_node("stacking", node))) {
375 if (parse_contains("top", doc, n))
376 config_dock_layer = OB_STACKING_LAYER_ABOVE;
377 else if (parse_contains("normal", doc, n))
378 config_dock_layer = OB_STACKING_LAYER_NORMAL;
379 else if (parse_contains("bottom", doc, n))
380 config_dock_layer = OB_STACKING_LAYER_BELOW;
382 if ((n = parse_find_node("direction", node))) {
383 if (parse_contains("horizontal", doc, n))
384 config_dock_orient = OB_ORIENTATION_HORZ;
385 else if (parse_contains("vertical", doc, n))
386 config_dock_orient = OB_ORIENTATION_VERT;
388 if ((n = parse_find_node("autoHide", node)))
389 config_dock_hide = parse_bool(doc, n);
390 if ((n = parse_find_node("hideDelay", node)))
391 config_dock_hide_delay = parse_int(doc, n) * 1000;
392 if ((n = parse_find_node("showDelay", node)))
393 config_dock_show_delay = parse_int(doc, n) * 1000;
394 if ((n = parse_find_node("moveButton", node))) {
395 gchar *str = parse_string(doc, n);
397 if (translate_button(str, &s, &b)) {
398 config_dock_app_move_button = b;
399 config_dock_app_move_modifiers = s;
401 g_warning("invalid button '%s'", str);
407 static void parse_menu(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
411 for (node = node->children; node; node = node->next) {
412 if (!xmlStrcasecmp(node->name, (const xmlChar*) "file")) {
415 c = parse_string(doc, node);
416 config_menu_files = g_slist_append(config_menu_files,
417 parse_expand_tilde(c));
420 if ((n = parse_find_node("warpPointer", node)))
421 config_menu_warppointer = parse_bool(doc, n);
422 if ((n = parse_find_node("xorStyle", node)))
423 config_menu_xorstyle = parse_bool(doc, n);
424 if ((n = parse_find_node("hideDelay", node)))
425 config_menu_hide_delay = parse_int(doc, n);
426 if ((n = parse_find_node("submenuShowDelay", node)))
427 config_submenu_show_delay = parse_int(doc, n);
428 if ((n = parse_find_node("desktopMenuIcons", node)))
429 config_menu_client_list_icons = parse_bool(doc, n);
433 static void parse_resistance(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
438 node = node->children;
439 if ((n = parse_find_node("strength", node)))
440 config_resist_win = parse_int(doc, n);
441 if ((n = parse_find_node("screen_edge_strength", node)))
442 config_resist_edge = parse_int(doc, n);
443 if ((n = parse_find_node("edges_hit_layers_below", node)))
444 config_resist_layers_below = parse_bool(doc, n);
450 const gchar *actname;
453 static void bind_default_keyboard()
456 ObDefKeyBind binds[] = {
457 { "A-Tab", "NextWindow" },
458 { "S-A-Tab", "PreviousWindow" },
463 for (it = binds; it->key; ++it) {
464 GList *l = g_list_append(NULL, g_strdup(it->key));
465 keyboard_bind(l, action_from_string(it->actname,
466 OB_USER_ACTION_KEYBOARD_KEY));
473 const gchar *context;
474 const ObMouseAction mact;
475 const gchar *actname;
478 static void bind_default_mouse()
481 ObDefMouseBind binds[] = {
482 { "Left", "Client", OB_MOUSE_ACTION_PRESS, "Focus" },
483 { "Middle", "Client", OB_MOUSE_ACTION_PRESS, "Focus" },
484 { "Right", "Client", OB_MOUSE_ACTION_PRESS, "Focus" },
485 { "Left", "Desktop", OB_MOUSE_ACTION_PRESS, "Focus" },
486 { "Middle", "Desktop", OB_MOUSE_ACTION_PRESS, "Focus" },
487 { "Right", "Desktop", OB_MOUSE_ACTION_PRESS, "Focus" },
488 { "Left", "Titlebar", OB_MOUSE_ACTION_PRESS, "Focus" },
489 { "Left", "Handle", OB_MOUSE_ACTION_PRESS, "Focus" },
490 { "Left", "BLCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
491 { "Left", "BRCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
492 { "Left", "TLCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
493 { "Left", "TRCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
494 { "Left", "Close", OB_MOUSE_ACTION_PRESS, "Focus" },
495 { "Left", "Maximize", OB_MOUSE_ACTION_PRESS, "Focus" },
496 { "Left", "Iconify", OB_MOUSE_ACTION_PRESS, "Focus" },
497 { "Left", "Icon", OB_MOUSE_ACTION_PRESS, "Focus" },
498 { "Left", "AllDesktops", OB_MOUSE_ACTION_PRESS, "Focus" },
499 { "Left", "Shade", OB_MOUSE_ACTION_PRESS, "Focus" },
500 { "Left", "Client", OB_MOUSE_ACTION_CLICK, "Raise" },
501 { "Left", "Titlebar", OB_MOUSE_ACTION_CLICK, "Raise" },
502 { "Middle", "Titlebar", OB_MOUSE_ACTION_CLICK, "Lower" },
503 { "Left", "Handle", OB_MOUSE_ACTION_CLICK, "Raise" },
504 { "Left", "BLCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
505 { "Left", "BRCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
506 { "Left", "TLCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
507 { "Left", "TRCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
508 { "Left", "Close", OB_MOUSE_ACTION_CLICK, "Raise" },
509 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK, "Raise" },
510 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK, "Raise" },
511 { "Left", "Icon", OB_MOUSE_ACTION_CLICK, "Raise" },
512 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK, "Raise" },
513 { "Left", "Shade", OB_MOUSE_ACTION_CLICK, "Raise" },
514 { "Left", "Close", OB_MOUSE_ACTION_CLICK, "Close" },
515 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK, "ToggleMaximizeFull" },
516 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK, "Iconify" },
517 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK, "ToggleOmnipresent" },
518 { "Left", "Shade", OB_MOUSE_ACTION_CLICK, "ToggleShade" },
519 { "Left", "TLCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
520 { "Left", "TRCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
521 { "Left", "BLCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
522 { "Left", "BRCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
523 { "Left", "Titlebar", OB_MOUSE_ACTION_MOTION, "Move" },
524 { "A-Left", "Frame", OB_MOUSE_ACTION_MOTION, "Move" },
525 { "A-Middle", "Frame", OB_MOUSE_ACTION_MOTION, "Resize" },
526 { NULL, NULL, 0, NULL }
529 for (it = binds; it->button; ++it) {
532 case OB_MOUSE_ACTION_PRESS:
533 uact = OB_USER_ACTION_MOUSE_PRESS; break;
534 case OB_MOUSE_ACTION_RELEASE:
535 uact = OB_USER_ACTION_MOUSE_RELEASE; break;
536 case OB_MOUSE_ACTION_CLICK:
537 uact = OB_USER_ACTION_MOUSE_CLICK; break;
538 case OB_MOUSE_ACTION_DOUBLE_CLICK:
539 uact = OB_USER_ACTION_MOUSE_DOUBLE_CLICK; break;
540 case OB_MOUSE_ACTION_MOTION:
541 uact = OB_USER_ACTION_MOUSE_MOTION; break;
542 case OB_NUM_MOUSE_ACTIONS:
543 g_assert_not_reached();
545 mouse_bind(it->button, it->context, it->mact,
546 action_from_string(it->actname, uact));
550 void config_startup(ObParseInst *i)
552 config_focus_new = TRUE;
553 config_focus_follow = FALSE;
554 config_focus_delay = 0;
555 config_focus_raise = FALSE;
556 config_focus_last = FALSE;
558 parse_register(i, "focus", parse_focus, NULL);
560 config_place_policy = OB_PLACE_POLICY_SMART;
562 parse_register(i, "placement", parse_placement, NULL);
566 config_title_layout = g_strdup("NLIMC");
567 config_theme_keepborder = TRUE;
568 config_theme_hidedisabled = FALSE;
570 parse_register(i, "theme", parse_theme, NULL);
572 config_desktops_num = 4;
573 config_screen_firstdesk = 1;
574 config_desktops_names = NULL;
576 parse_register(i, "desktops", parse_desktops, NULL);
578 config_resize_redraw = TRUE;
579 config_resize_four_corners = FALSE;
580 config_resize_popup_show = 1; /* nonpixel increments */
581 config_resize_popup_pos = 0; /* center of client */
583 parse_register(i, "resize", parse_resize, NULL);
585 config_dock_layer = OB_STACKING_LAYER_ABOVE;
586 config_dock_pos = OB_DIRECTION_NORTHEAST;
587 config_dock_floating = FALSE;
588 config_dock_nostrut = FALSE;
591 config_dock_orient = OB_ORIENTATION_VERT;
592 config_dock_hide = FALSE;
593 config_dock_hide_delay = 300;
594 config_dock_show_delay = 300;
595 config_dock_app_move_button = 2; /* middle */
596 config_dock_app_move_modifiers = 0;
598 parse_register(i, "dock", parse_dock, NULL);
600 translate_key("C-g", &config_keyboard_reset_state,
601 &config_keyboard_reset_keycode);
603 bind_default_keyboard();
605 parse_register(i, "keyboard", parse_keyboard, NULL);
607 config_mouse_threshold = 3;
608 config_mouse_dclicktime = 200;
610 bind_default_mouse();
612 parse_register(i, "mouse", parse_mouse, NULL);
614 config_resist_win = 10;
615 config_resist_edge = 20;
616 config_resist_layers_below = FALSE;
618 parse_register(i, "resistance", parse_resistance, NULL);
620 config_menu_warppointer = TRUE;
621 config_menu_xorstyle = TRUE;
622 config_menu_hide_delay = 250;
623 config_submenu_show_delay = 0;
624 config_menu_client_list_icons = TRUE;
625 config_menu_files = NULL;
627 parse_register(i, "menu", parse_menu, NULL);
630 void config_shutdown()
634 g_free(config_theme);
636 g_free(config_title_layout);
638 for (it = config_desktops_names; it; it = g_slist_next(it))
640 g_slist_free(config_desktops_names);
642 for (it = config_menu_files; it; it = g_slist_next(it))
644 g_slist_free(config_menu_files);