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 gboolean config_menu_client_list_icons;
75 GSList *config_menu_files;
77 gint config_resist_win;
78 gint config_resist_edge;
80 gboolean config_resist_layers_below;
85 <action name="ChangeDesktop">
92 static void parse_key(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
100 if ((n = parse_find_node("chainQuitKey", node))) {
101 key = parse_string(doc, n);
102 translate_key(key, &config_keyboard_reset_state,
103 &config_keyboard_reset_keycode);
107 n = parse_find_node("keybind", node);
109 if (parse_attr_string("key", n, &key)) {
110 keylist = g_list_append(keylist, key);
112 parse_key(i, doc, n->children, keylist);
114 it = g_list_last(keylist);
116 keylist = g_list_delete_link(keylist, it);
118 n = parse_find_node("keybind", n->next);
121 nact = parse_find_node("action", node);
123 if ((action = action_parse(i, doc, nact,
124 OB_USER_ACTION_KEYBOARD_KEY)))
125 keyboard_bind(keylist, action);
126 nact = parse_find_node("action", nact->next);
131 static void parse_keyboard(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
134 keyboard_unbind_all();
136 parse_key(i, doc, node->children, NULL);
141 <context name="Titlebar">
142 <mousebind button="Left" action="Press">
143 <action name="Raise"></action>
149 static void parse_mouse(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
152 xmlNodePtr n, nbut, nact;
161 node = node->children;
163 if ((n = parse_find_node("dragThreshold", node)))
164 config_mouse_threshold = parse_int(doc, n);
165 if ((n = parse_find_node("doubleClickTime", node)))
166 config_mouse_dclicktime = parse_int(doc, n);
168 n = parse_find_node("context", node);
170 if (!parse_attr_string("name", n, &contextstr))
172 nbut = parse_find_node("mousebind", n->children);
174 if (!parse_attr_string("button", nbut, &buttonstr))
176 if (parse_attr_contains("press", nbut, "action")) {
177 uact = OB_USER_ACTION_MOUSE_PRESS;
178 mact = OB_MOUSE_ACTION_PRESS;
179 } else if (parse_attr_contains("release", nbut, "action")) {
180 uact = OB_USER_ACTION_MOUSE_RELEASE;
181 mact = OB_MOUSE_ACTION_RELEASE;
182 } else if (parse_attr_contains("click", nbut, "action")) {
183 uact = OB_USER_ACTION_MOUSE_CLICK;
184 mact = OB_MOUSE_ACTION_CLICK;
185 } else if (parse_attr_contains("doubleclick", nbut,"action")) {
186 uact = OB_USER_ACTION_MOUSE_DOUBLE_CLICK;
187 mact = OB_MOUSE_ACTION_DOUBLE_CLICK;
188 } else if (parse_attr_contains("drag", nbut, "action")) {
189 uact = OB_USER_ACTION_MOUSE_MOTION;
190 mact = OB_MOUSE_ACTION_MOTION;
193 nact = parse_find_node("action", nbut->children);
195 if ((action = action_parse(i, doc, nact, uact)))
196 mouse_bind(buttonstr, contextstr, mact, action);
197 nact = parse_find_node("action", nact->next);
201 nbut = parse_find_node("mousebind", nbut->next);
205 n = parse_find_node("context", n->next);
209 static void parse_focus(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
214 node = node->children;
216 if ((n = parse_find_node("focusNew", node)))
217 config_focus_new = parse_bool(doc, n);
218 if ((n = parse_find_node("followMouse", node)))
219 config_focus_follow = parse_bool(doc, n);
220 if ((n = parse_find_node("focusDelay", node)))
221 config_focus_delay = parse_int(doc, n) * 1000;
222 if ((n = parse_find_node("raiseOnFocus", node)))
223 config_focus_raise = parse_bool(doc, n);
224 if ((n = parse_find_node("focusLast", node)))
225 config_focus_last = parse_bool(doc, n);
228 static void parse_placement(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
233 node = node->children;
235 if ((n = parse_find_node("policy", node)))
236 if (parse_contains("UnderMouse", doc, n))
237 config_place_policy = OB_PLACE_POLICY_MOUSE;
240 static void parse_theme(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
245 node = node->children;
247 if ((n = parse_find_node("name", node))) {
250 g_free(config_theme);
251 c = parse_string(doc, n);
252 config_theme = parse_expand_tilde(c);
255 if ((n = parse_find_node("titleLayout", node))) {
256 g_free(config_title_layout);
257 config_title_layout = parse_string(doc, n);
259 if ((n = parse_find_node("keepBorder", node)))
260 config_theme_keepborder = parse_bool(doc, n);
261 if ((n = parse_find_node("hideDisabled", node)))
262 config_theme_hidedisabled = parse_bool(doc, n);
265 static void parse_desktops(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
270 node = node->children;
272 if ((n = parse_find_node("number", node))) {
273 gint d = parse_int(doc, n);
275 config_desktops_num = d;
277 if ((n = parse_find_node("firstdesk", node))) {
278 gint d = parse_int(doc, n);
280 config_screen_firstdesk = d;
282 if ((n = parse_find_node("names", node))) {
286 for (it = config_desktops_names; it; it = it->next)
288 g_slist_free(config_desktops_names);
289 config_desktops_names = NULL;
291 nname = parse_find_node("name", n->children);
293 config_desktops_names = g_slist_append(config_desktops_names,
294 parse_string(doc, nname));
295 nname = parse_find_node("name", nname->next);
300 static void parse_resize(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
305 node = node->children;
307 if ((n = parse_find_node("drawContents", node)))
308 config_resize_redraw = parse_bool(doc, n);
309 if ((n = parse_find_node("fourCorner", node)))
310 config_resize_four_corners = parse_bool(doc, n);
311 if ((n = parse_find_node("popupShow", node))) {
312 config_resize_popup_show = parse_int(doc, n);
313 if (parse_contains("Always", doc, n))
314 config_resize_popup_show = 2;
315 else if (parse_contains("Never", doc, n))
316 config_resize_popup_show = 0;
317 else if (parse_contains("Nonpixel", doc, n))
318 config_resize_popup_show = 1;
320 if ((n = parse_find_node("popupPosition", node))) {
321 config_resize_popup_pos = parse_int(doc, n);
322 if (parse_contains("Top", doc, n))
323 config_resize_popup_pos = 1;
324 else if (parse_contains("Center", doc, n))
325 config_resize_popup_pos = 0;
329 static void parse_dock(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
334 node = node->children;
336 if ((n = parse_find_node("position", node))) {
337 if (parse_contains("TopLeft", doc, n))
338 config_dock_floating = FALSE,
339 config_dock_pos = OB_DIRECTION_NORTHWEST;
340 else if (parse_contains("Top", doc, n))
341 config_dock_floating = FALSE,
342 config_dock_pos = OB_DIRECTION_NORTH;
343 else if (parse_contains("TopRight", doc, n))
344 config_dock_floating = FALSE,
345 config_dock_pos = OB_DIRECTION_NORTHEAST;
346 else if (parse_contains("Right", doc, n))
347 config_dock_floating = FALSE,
348 config_dock_pos = OB_DIRECTION_EAST;
349 else if (parse_contains("BottomRight", doc, n))
350 config_dock_floating = FALSE,
351 config_dock_pos = OB_DIRECTION_SOUTHEAST;
352 else if (parse_contains("Bottom", doc, n))
353 config_dock_floating = FALSE,
354 config_dock_pos = OB_DIRECTION_SOUTH;
355 else if (parse_contains("BottomLeft", doc, n))
356 config_dock_floating = FALSE,
357 config_dock_pos = OB_DIRECTION_SOUTHWEST;
358 else if (parse_contains("Left", doc, n))
359 config_dock_floating = FALSE,
360 config_dock_pos = OB_DIRECTION_WEST;
361 else if (parse_contains("Floating", doc, n))
362 config_dock_floating = TRUE;
364 if (config_dock_floating) {
365 if ((n = parse_find_node("floatingX", node)))
366 config_dock_x = parse_int(doc, n);
367 if ((n = parse_find_node("floatingY", node)))
368 config_dock_y = parse_int(doc, n);
370 if ((n = parse_find_node("noStrut", node)))
371 config_dock_nostrut = parse_bool(doc, n);
373 if ((n = parse_find_node("stacking", node))) {
374 if (parse_contains("top", doc, n))
375 config_dock_layer = OB_STACKING_LAYER_ABOVE;
376 else if (parse_contains("normal", doc, n))
377 config_dock_layer = OB_STACKING_LAYER_NORMAL;
378 else if (parse_contains("bottom", doc, n))
379 config_dock_layer = OB_STACKING_LAYER_BELOW;
381 if ((n = parse_find_node("direction", node))) {
382 if (parse_contains("horizontal", doc, n))
383 config_dock_orient = OB_ORIENTATION_HORZ;
384 else if (parse_contains("vertical", doc, n))
385 config_dock_orient = OB_ORIENTATION_VERT;
387 if ((n = parse_find_node("autoHide", node)))
388 config_dock_hide = parse_bool(doc, n);
389 if ((n = parse_find_node("hideDelay", node)))
390 config_dock_hide_delay = parse_int(doc, n) * 1000;
391 if ((n = parse_find_node("showDelay", node)))
392 config_dock_show_delay = parse_int(doc, n) * 1000;
393 if ((n = parse_find_node("moveButton", node))) {
394 gchar *str = parse_string(doc, n);
396 if (translate_button(str, &s, &b)) {
397 config_dock_app_move_button = b;
398 config_dock_app_move_modifiers = s;
400 g_warning("invalid button '%s'", str);
406 static void parse_menu(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
410 for (node = node->children; node; node = node->next) {
411 if (!xmlStrcasecmp(node->name, (const xmlChar*) "file")) {
414 c = parse_string(doc, node);
415 config_menu_files = g_slist_append(config_menu_files,
416 parse_expand_tilde(c));
419 if ((n = parse_find_node("warpPointer", node)))
420 config_menu_warppointer = parse_bool(doc, n);
421 if ((n = parse_find_node("xorStyle", node)))
422 config_menu_xorstyle = parse_bool(doc, n);
423 if ((n = parse_find_node("hideDelay", node)))
424 config_menu_hide_delay = parse_int(doc, n);
425 if ((n = parse_find_node("desktopMenuIcons", node)))
426 config_menu_client_list_icons = parse_bool(doc, n);
430 static void parse_resistance(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
435 node = node->children;
436 if ((n = parse_find_node("strength", node)))
437 config_resist_win = parse_int(doc, n);
438 if ((n = parse_find_node("screen_edge_strength", node)))
439 config_resist_edge = parse_int(doc, n);
440 if ((n = parse_find_node("edges_hit_layers_below", node)))
441 config_resist_layers_below = parse_bool(doc, n);
447 const gchar *actname;
450 static void bind_default_keyboard()
453 ObDefKeyBind binds[] = {
454 { "A-Tab", "NextWindow" },
455 { "S-A-Tab", "PreviousWindow" },
460 for (it = binds; it->key; ++it) {
461 GList *l = g_list_append(NULL, g_strdup(it->key));
462 keyboard_bind(l, action_from_string(it->actname,
463 OB_USER_ACTION_KEYBOARD_KEY));
470 const gchar *context;
471 const ObMouseAction mact;
472 const gchar *actname;
475 static void bind_default_mouse()
478 ObDefMouseBind binds[] = {
479 { "Left", "Client", OB_MOUSE_ACTION_PRESS, "Focus" },
480 { "Middle", "Client", OB_MOUSE_ACTION_PRESS, "Focus" },
481 { "Right", "Client", OB_MOUSE_ACTION_PRESS, "Focus" },
482 { "Left", "Desktop", OB_MOUSE_ACTION_PRESS, "Focus" },
483 { "Middle", "Desktop", OB_MOUSE_ACTION_PRESS, "Focus" },
484 { "Right", "Desktop", OB_MOUSE_ACTION_PRESS, "Focus" },
485 { "Left", "Titlebar", OB_MOUSE_ACTION_PRESS, "Focus" },
486 { "Left", "Handle", OB_MOUSE_ACTION_PRESS, "Focus" },
487 { "Left", "BLCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
488 { "Left", "BRCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
489 { "Left", "TLCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
490 { "Left", "TRCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
491 { "Left", "Close", OB_MOUSE_ACTION_PRESS, "Focus" },
492 { "Left", "Maximize", OB_MOUSE_ACTION_PRESS, "Focus" },
493 { "Left", "Iconify", OB_MOUSE_ACTION_PRESS, "Focus" },
494 { "Left", "Icon", OB_MOUSE_ACTION_PRESS, "Focus" },
495 { "Left", "AllDesktops", OB_MOUSE_ACTION_PRESS, "Focus" },
496 { "Left", "Shade", OB_MOUSE_ACTION_PRESS, "Focus" },
497 { "Left", "Client", OB_MOUSE_ACTION_CLICK, "Raise" },
498 { "Left", "Titlebar", OB_MOUSE_ACTION_CLICK, "Raise" },
499 { "Middle", "Titlebar", OB_MOUSE_ACTION_CLICK, "Lower" },
500 { "Left", "Handle", OB_MOUSE_ACTION_CLICK, "Raise" },
501 { "Left", "BLCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
502 { "Left", "BRCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
503 { "Left", "TLCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
504 { "Left", "TRCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
505 { "Left", "Close", OB_MOUSE_ACTION_CLICK, "Raise" },
506 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK, "Raise" },
507 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK, "Raise" },
508 { "Left", "Icon", OB_MOUSE_ACTION_CLICK, "Raise" },
509 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK, "Raise" },
510 { "Left", "Shade", OB_MOUSE_ACTION_CLICK, "Raise" },
511 { "Left", "Close", OB_MOUSE_ACTION_CLICK, "Close" },
512 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK, "ToggleMaximizeFull" },
513 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK, "Iconify" },
514 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK, "ToggleOmnipresent" },
515 { "Left", "Shade", OB_MOUSE_ACTION_CLICK, "ToggleShade" },
516 { "Left", "TLCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
517 { "Left", "TRCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
518 { "Left", "BLCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
519 { "Left", "BRCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
520 { "Left", "Titlebar", OB_MOUSE_ACTION_MOTION, "Move" },
521 { "A-Left", "Frame", OB_MOUSE_ACTION_MOTION, "Move" },
522 { "A-Middle", "Frame", OB_MOUSE_ACTION_MOTION, "Resize" },
523 { NULL, NULL, 0, NULL }
526 for (it = binds; it->button; ++it) {
529 case OB_MOUSE_ACTION_PRESS:
530 uact = OB_USER_ACTION_MOUSE_PRESS; break;
531 case OB_MOUSE_ACTION_RELEASE:
532 uact = OB_USER_ACTION_MOUSE_RELEASE; break;
533 case OB_MOUSE_ACTION_CLICK:
534 uact = OB_USER_ACTION_MOUSE_CLICK; break;
535 case OB_MOUSE_ACTION_DOUBLE_CLICK:
536 uact = OB_USER_ACTION_MOUSE_DOUBLE_CLICK; break;
537 case OB_MOUSE_ACTION_MOTION:
538 uact = OB_USER_ACTION_MOUSE_MOTION; break;
539 case OB_NUM_MOUSE_ACTIONS:
540 g_assert_not_reached();
542 mouse_bind(it->button, it->context, it->mact,
543 action_from_string(it->actname, uact));
547 void config_startup(ObParseInst *i)
549 config_focus_new = TRUE;
550 config_focus_follow = FALSE;
551 config_focus_delay = 0;
552 config_focus_raise = FALSE;
553 config_focus_last = FALSE;
555 parse_register(i, "focus", parse_focus, NULL);
557 config_place_policy = OB_PLACE_POLICY_SMART;
559 parse_register(i, "placement", parse_placement, NULL);
563 config_title_layout = g_strdup("NLIMC");
564 config_theme_keepborder = TRUE;
565 config_theme_hidedisabled = FALSE;
567 parse_register(i, "theme", parse_theme, NULL);
569 config_desktops_num = 4;
570 config_screen_firstdesk = 1;
571 config_desktops_names = NULL;
573 parse_register(i, "desktops", parse_desktops, NULL);
575 config_resize_redraw = TRUE;
576 config_resize_four_corners = FALSE;
577 config_resize_popup_show = 1; /* nonpixel increments */
578 config_resize_popup_pos = 0; /* center of client */
580 parse_register(i, "resize", parse_resize, NULL);
582 config_dock_layer = OB_STACKING_LAYER_ABOVE;
583 config_dock_pos = OB_DIRECTION_NORTHEAST;
584 config_dock_floating = FALSE;
585 config_dock_nostrut = FALSE;
588 config_dock_orient = OB_ORIENTATION_VERT;
589 config_dock_hide = FALSE;
590 config_dock_hide_delay = 300;
591 config_dock_show_delay = 300;
592 config_dock_app_move_button = 2; /* middle */
593 config_dock_app_move_modifiers = 0;
595 parse_register(i, "dock", parse_dock, NULL);
597 translate_key("C-g", &config_keyboard_reset_state,
598 &config_keyboard_reset_keycode);
600 bind_default_keyboard();
602 parse_register(i, "keyboard", parse_keyboard, NULL);
604 config_mouse_threshold = 3;
605 config_mouse_dclicktime = 200;
607 bind_default_mouse();
609 parse_register(i, "mouse", parse_mouse, NULL);
611 config_resist_win = 10;
612 config_resist_edge = 20;
613 config_resist_layers_below = FALSE;
615 parse_register(i, "resistance", parse_resistance, NULL);
617 config_menu_warppointer = TRUE;
618 config_menu_xorstyle = TRUE;
619 config_menu_hide_delay = 250;
620 config_menu_client_list_icons = TRUE;
621 config_menu_files = NULL;
623 parse_register(i, "menu", parse_menu, NULL);
626 void config_shutdown()
630 g_free(config_theme);
632 g_free(config_title_layout);
634 for (it = config_desktops_names; it; it = g_slist_next(it))
636 g_slist_free(config_desktops_names);
638 for (it = config_menu_files; it; it = g_slist_next(it))
640 g_slist_free(config_menu_files);