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;
38 gchar *config_title_layout;
40 gint config_desktops_num;
41 GSList *config_desktops_names;
42 gint config_screen_firstdesk;
44 gboolean config_resize_redraw;
45 gint config_resize_popup_show;
46 gint config_resize_popup_pos;
48 ObStackingLayer config_dock_layer;
49 gboolean config_dock_floating;
50 ObDirection config_dock_pos;
53 ObOrientation config_dock_orient;
54 gboolean config_dock_hide;
55 guint config_dock_hide_delay;
56 guint config_dock_app_move_button;
57 guint config_dock_app_move_modifiers;
59 guint config_keyboard_reset_keycode;
60 guint config_keyboard_reset_state;
62 gint config_mouse_threshold;
63 gint config_mouse_dclicktime;
65 gboolean config_menu_warppointer;
66 gboolean config_menu_xorstyle;
67 gboolean config_menu_hilightfirst;
68 guint config_menu_hide_delay;
70 GSList *config_menu_files;
72 gint config_resist_win;
73 gint config_resist_edge;
78 <action name="ChangeDesktop">
85 static void parse_key(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
93 if ((n = parse_find_node("chainQuitKey", node))) {
94 key = parse_string(doc, n);
95 translate_key(key, &config_keyboard_reset_state,
96 &config_keyboard_reset_keycode);
100 n = parse_find_node("keybind", node);
102 if (parse_attr_string("key", n, &key)) {
103 keylist = g_list_append(keylist, key);
105 parse_key(i, doc, n->children, keylist);
107 it = g_list_last(keylist);
109 keylist = g_list_delete_link(keylist, it);
111 n = parse_find_node("keybind", n->next);
114 nact = parse_find_node("action", node);
116 if ((action = action_parse(i, doc, nact,
117 OB_USER_ACTION_KEYBOARD_KEY)))
118 keyboard_bind(keylist, action);
119 nact = parse_find_node("action", nact->next);
124 static void parse_keyboard(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
127 keyboard_unbind_all();
129 parse_key(i, doc, node->children, NULL);
134 <context name="Titlebar">
135 <mousebind button="Left" action="Press">
136 <action name="Raise"></action>
142 static void parse_mouse(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
145 xmlNodePtr n, nbut, nact;
154 node = node->children;
156 if ((n = parse_find_node("dragThreshold", node)))
157 config_mouse_threshold = parse_int(doc, n);
158 if ((n = parse_find_node("doubleClickTime", node)))
159 config_mouse_dclicktime = parse_int(doc, n);
161 n = parse_find_node("context", node);
163 if (!parse_attr_string("name", n, &contextstr))
165 nbut = parse_find_node("mousebind", n->children);
167 if (!parse_attr_string("button", nbut, &buttonstr))
169 if (parse_attr_contains("press", nbut, "action")) {
170 uact = OB_USER_ACTION_MOUSE_PRESS;
171 mact = OB_MOUSE_ACTION_PRESS;
172 } else if (parse_attr_contains("release", nbut, "action")) {
173 uact = OB_USER_ACTION_MOUSE_RELEASE;
174 mact = OB_MOUSE_ACTION_RELEASE;
175 } else if (parse_attr_contains("click", nbut, "action")) {
176 uact = OB_USER_ACTION_MOUSE_CLICK;
177 mact = OB_MOUSE_ACTION_CLICK;
178 } else if (parse_attr_contains("doubleclick", nbut,"action")) {
179 uact = OB_USER_ACTION_MOUSE_DOUBLE_CLICK;
180 mact = OB_MOUSE_ACTION_DOUBLE_CLICK;
181 } else if (parse_attr_contains("drag", nbut, "action")) {
182 uact = OB_USER_ACTION_MOUSE_MOTION;
183 mact = OB_MOUSE_ACTION_MOTION;
186 nact = parse_find_node("action", nbut->children);
188 if ((action = action_parse(i, doc, nact, uact)))
189 mouse_bind(buttonstr, contextstr, mact, action);
190 nact = parse_find_node("action", nact->next);
194 nbut = parse_find_node("mousebind", nbut->next);
198 n = parse_find_node("context", n->next);
202 static void parse_focus(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
207 node = node->children;
209 if ((n = parse_find_node("focusNew", node)))
210 config_focus_new = parse_bool(doc, n);
211 if ((n = parse_find_node("followMouse", node)))
212 config_focus_follow = parse_bool(doc, n);
213 if ((n = parse_find_node("focusDelay", node)))
214 config_focus_delay = parse_int(doc, n) * 1000;
215 if ((n = parse_find_node("raiseOnFocus", node)))
216 config_focus_raise = parse_bool(doc, n);
217 if ((n = parse_find_node("focusLast", node)))
218 config_focus_last = parse_bool(doc, n);
221 static void parse_placement(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
226 node = node->children;
228 if ((n = parse_find_node("policy", node)))
229 if (parse_contains("UnderMouse", doc, n))
230 config_place_policy = OB_PLACE_POLICY_MOUSE;
233 static void parse_theme(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
238 node = node->children;
240 if ((n = parse_find_node("name", node))) {
243 g_free(config_theme);
244 c = parse_string(doc, n);
245 config_theme = parse_expand_tilde(c);
248 if ((n = parse_find_node("titleLayout", node))) {
249 g_free(config_title_layout);
250 config_title_layout = parse_string(doc, n);
254 static void parse_desktops(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
259 node = node->children;
261 if ((n = parse_find_node("number", node))) {
262 gint d = parse_int(doc, n);
264 config_desktops_num = d;
266 if ((n = parse_find_node("firstdesk", node))) {
267 gint d = parse_int(doc, n);
269 config_screen_firstdesk = d;
271 if ((n = parse_find_node("names", node))) {
275 for (it = config_desktops_names; it; it = it->next)
277 g_slist_free(config_desktops_names);
278 config_desktops_names = NULL;
280 nname = parse_find_node("name", n->children);
282 config_desktops_names = g_slist_append(config_desktops_names,
283 parse_string(doc, nname));
284 nname = parse_find_node("name", nname->next);
289 static void parse_resize(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
294 node = node->children;
296 if ((n = parse_find_node("drawContents", node)))
297 config_resize_redraw = parse_bool(doc, n);
298 if ((n = parse_find_node("popupShow", node))) {
299 config_resize_popup_show = parse_int(doc, n);
300 if (parse_contains("Always", doc, n))
301 config_resize_popup_show = 2;
302 else if (parse_contains("Never", doc, n))
303 config_resize_popup_show = 0;
304 else if (parse_contains("Nonpixel", doc, n))
305 config_resize_popup_show = 1;
307 if ((n = parse_find_node("popupPosition", node))) {
308 config_resize_popup_pos = parse_int(doc, n);
309 if (parse_contains("Top", doc, n))
310 config_resize_popup_pos = 1;
311 else if (parse_contains("Center", doc, n))
312 config_resize_popup_pos = 0;
316 static void parse_dock(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
321 node = node->children;
323 if ((n = parse_find_node("position", node))) {
324 if (parse_contains("TopLeft", doc, n))
325 config_dock_floating = FALSE,
326 config_dock_pos = OB_DIRECTION_NORTHWEST;
327 else if (parse_contains("Top", doc, n))
328 config_dock_floating = FALSE,
329 config_dock_pos = OB_DIRECTION_NORTH;
330 else if (parse_contains("TopRight", doc, n))
331 config_dock_floating = FALSE,
332 config_dock_pos = OB_DIRECTION_NORTHEAST;
333 else if (parse_contains("Right", doc, n))
334 config_dock_floating = FALSE,
335 config_dock_pos = OB_DIRECTION_EAST;
336 else if (parse_contains("BottomRight", doc, n))
337 config_dock_floating = FALSE,
338 config_dock_pos = OB_DIRECTION_SOUTHEAST;
339 else if (parse_contains("Bottom", doc, n))
340 config_dock_floating = FALSE,
341 config_dock_pos = OB_DIRECTION_SOUTH;
342 else if (parse_contains("BottomLeft", doc, n))
343 config_dock_floating = FALSE,
344 config_dock_pos = OB_DIRECTION_SOUTHWEST;
345 else if (parse_contains("Left", doc, n))
346 config_dock_floating = FALSE,
347 config_dock_pos = OB_DIRECTION_WEST;
348 else if (parse_contains("Floating", doc, n))
349 config_dock_floating = TRUE;
351 if (config_dock_floating) {
352 if ((n = parse_find_node("floatingX", node)))
353 config_dock_x = parse_int(doc, n);
354 if ((n = parse_find_node("floatingY", node)))
355 config_dock_y = parse_int(doc, n);
357 if ((n = parse_find_node("stacking", node))) {
358 if (parse_contains("top", doc, n))
359 config_dock_layer = OB_STACKING_LAYER_DOCK_ABOVE;
360 else if (parse_contains("normal", doc, n))
361 config_dock_layer = OB_STACKING_LAYER_DOCK_NORMAL;
362 else if (parse_contains("bottom", doc, n))
363 config_dock_layer = OB_STACKING_LAYER_DOCK_BELOW;
365 if ((n = parse_find_node("direction", node))) {
366 if (parse_contains("horizontal", doc, n))
367 config_dock_orient = OB_ORIENTATION_HORZ;
368 else if (parse_contains("vertical", doc, n))
369 config_dock_orient = OB_ORIENTATION_VERT;
371 if ((n = parse_find_node("autoHide", node)))
372 config_dock_hide = parse_bool(doc, n);
373 if ((n = parse_find_node("hideDelay", node)))
374 config_dock_hide_delay = parse_int(doc, n) * 1000;
375 if ((n = parse_find_node("moveButton", node))) {
376 gchar *str = parse_string(doc, n);
378 if (translate_button(str, &s, &b)) {
379 config_dock_app_move_button = b;
380 config_dock_app_move_modifiers = s;
382 g_warning("invalid button '%s'", str);
388 static void parse_menu(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
392 for (node = node->children; node; node = node->next) {
393 if (!xmlStrcasecmp(node->name, (const xmlChar*) "file")) {
396 c = parse_string(doc, node);
397 config_menu_files = g_slist_append(config_menu_files,
398 parse_expand_tilde(c));
401 if ((n = parse_find_node("warpPointer", node)))
402 config_menu_warppointer = parse_bool(doc, n);
403 if ((n = parse_find_node("xorStyle", node)))
404 config_menu_xorstyle = parse_bool(doc, n);
405 if ((n = parse_find_node("hilightFirst", node)))
406 config_menu_hilightfirst = parse_bool(doc, n);
407 if ((n = parse_find_node("hideDelay", node)))
408 config_menu_hide_delay = parse_int(doc, n);
412 static void parse_resistance(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
417 node = node->children;
418 if ((n = parse_find_node("strength", node)))
419 config_resist_win = parse_int(doc, n);
420 if ((n = parse_find_node("screen_edge_strength", node)))
421 config_resist_edge = parse_int(doc, n);
427 const gchar *actname;
430 static void bind_default_keyboard()
433 ObDefKeyBind binds[] = {
434 { "A-Tab", "NextWindow" },
435 { "S-A-Tab", "PreviousWindow" },
440 for (it = binds; it->key; ++it) {
441 GList *l = g_list_append(NULL, g_strdup(it->key));
442 keyboard_bind(l, action_from_string(it->actname,
443 OB_USER_ACTION_KEYBOARD_KEY));
450 const gchar *context;
451 const ObMouseAction mact;
452 const gchar *actname;
455 static void bind_default_mouse()
458 ObDefMouseBind binds[] = {
459 { "Left", "Client", OB_MOUSE_ACTION_PRESS, "Focus" },
460 { "Middle", "Client", OB_MOUSE_ACTION_PRESS, "Focus" },
461 { "Right", "Client", OB_MOUSE_ACTION_PRESS, "Focus" },
462 { "Left", "Desktop", OB_MOUSE_ACTION_PRESS, "Focus" },
463 { "Middle", "Desktop", OB_MOUSE_ACTION_PRESS, "Focus" },
464 { "Right", "Desktop", OB_MOUSE_ACTION_PRESS, "Focus" },
465 { "Left", "Titlebar", OB_MOUSE_ACTION_PRESS, "Focus" },
466 { "Left", "Handle", OB_MOUSE_ACTION_PRESS, "Focus" },
467 { "Left", "BLCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
468 { "Left", "BRCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
469 { "Left", "TLCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
470 { "Left", "TRCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
471 { "Left", "Close", OB_MOUSE_ACTION_PRESS, "Focus" },
472 { "Left", "Maximize", OB_MOUSE_ACTION_PRESS, "Focus" },
473 { "Left", "Iconify", OB_MOUSE_ACTION_PRESS, "Focus" },
474 { "Left", "Icon", OB_MOUSE_ACTION_PRESS, "Focus" },
475 { "Left", "AllDesktops", OB_MOUSE_ACTION_PRESS, "Focus" },
476 { "Left", "Shade", OB_MOUSE_ACTION_PRESS, "Focus" },
477 { "Left", "Client", OB_MOUSE_ACTION_CLICK, "Raise" },
478 { "Left", "Titlebar", OB_MOUSE_ACTION_CLICK, "Raise" },
479 { "Middle", "Titlebar", OB_MOUSE_ACTION_CLICK, "Lower" },
480 { "Left", "Handle", OB_MOUSE_ACTION_CLICK, "Raise" },
481 { "Left", "BLCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
482 { "Left", "BRCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
483 { "Left", "TLCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
484 { "Left", "TRCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
485 { "Left", "Close", OB_MOUSE_ACTION_CLICK, "Raise" },
486 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK, "Raise" },
487 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK, "Raise" },
488 { "Left", "Icon", OB_MOUSE_ACTION_CLICK, "Raise" },
489 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK, "Raise" },
490 { "Left", "Shade", OB_MOUSE_ACTION_CLICK, "Raise" },
491 { "Left", "Close", OB_MOUSE_ACTION_CLICK, "Close" },
492 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK, "ToggleMaximizeFull" },
493 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK, "Iconify" },
494 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK, "ToggleOmnipresent" },
495 { "Left", "Shade", OB_MOUSE_ACTION_CLICK, "ToggleShade" },
496 { "Left", "TLCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
497 { "Left", "TRCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
498 { "Left", "BLCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
499 { "Left", "BRCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
500 { "Left", "Titlebar", OB_MOUSE_ACTION_MOTION, "Move" },
501 { "A-Left", "Frame", OB_MOUSE_ACTION_MOTION, "Move" },
502 { "A-Middle", "Frame", OB_MOUSE_ACTION_MOTION, "Resize" },
503 { NULL, NULL, 0, NULL }
506 for (it = binds; it->button; ++it) {
509 case OB_MOUSE_ACTION_PRESS:
510 uact = OB_USER_ACTION_MOUSE_PRESS; break;
511 case OB_MOUSE_ACTION_RELEASE:
512 uact = OB_USER_ACTION_MOUSE_RELEASE; break;
513 case OB_MOUSE_ACTION_CLICK:
514 uact = OB_USER_ACTION_MOUSE_CLICK; break;
515 case OB_MOUSE_ACTION_DOUBLE_CLICK:
516 uact = OB_USER_ACTION_MOUSE_DOUBLE_CLICK; break;
517 case OB_MOUSE_ACTION_MOTION:
518 uact = OB_USER_ACTION_MOUSE_MOTION; break;
519 case OB_NUM_MOUSE_ACTIONS:
520 g_assert_not_reached();
522 mouse_bind(it->button, it->context, it->mact,
523 action_from_string(it->actname, uact));
527 void config_startup(ObParseInst *i)
529 config_focus_new = TRUE;
530 config_focus_follow = FALSE;
531 config_focus_delay = 0;
532 config_focus_raise = FALSE;
533 config_focus_last = FALSE;
535 parse_register(i, "focus", parse_focus, NULL);
537 config_place_policy = OB_PLACE_POLICY_SMART;
539 parse_register(i, "placement", parse_placement, NULL);
543 config_title_layout = g_strdup("NLIMC");
545 parse_register(i, "theme", parse_theme, NULL);
547 config_desktops_num = 4;
548 config_screen_firstdesk = 1;
549 config_desktops_names = NULL;
551 parse_register(i, "desktops", parse_desktops, NULL);
553 config_resize_redraw = TRUE;
554 config_resize_popup_show = 1; /* nonpixel increments */
555 config_resize_popup_pos = 0; /* center of client */
557 parse_register(i, "resize", parse_resize, NULL);
559 config_dock_layer = OB_STACKING_LAYER_DOCK_ABOVE;
560 config_dock_pos = OB_DIRECTION_NORTHEAST;
561 config_dock_floating = FALSE;
564 config_dock_orient = OB_ORIENTATION_VERT;
565 config_dock_hide = FALSE;
566 config_dock_hide_delay = 300;
567 config_dock_app_move_button = 2; /* middle */
568 config_dock_app_move_modifiers = 0;
570 parse_register(i, "dock", parse_dock, NULL);
572 translate_key("C-g", &config_keyboard_reset_state,
573 &config_keyboard_reset_keycode);
575 bind_default_keyboard();
577 parse_register(i, "keyboard", parse_keyboard, NULL);
579 config_mouse_threshold = 3;
580 config_mouse_dclicktime = 200;
582 bind_default_mouse();
584 parse_register(i, "mouse", parse_mouse, NULL);
586 config_resist_win = 10;
587 config_resist_edge = 20;
589 parse_register(i, "resistance", parse_resistance, NULL);
591 config_menu_warppointer = TRUE;
592 config_menu_xorstyle = FALSE;
593 config_menu_hilightfirst = TRUE;
594 config_menu_hide_delay = 250;
595 config_menu_files = NULL;
597 parse_register(i, "menu", parse_menu, NULL);
600 void config_shutdown()
604 g_free(config_theme);
606 g_free(config_title_layout);
608 for (it = config_desktops_names; it; it = g_slist_next(it))
610 g_slist_free(config_desktops_names);
612 for (it = config_menu_files; it; it = g_slist_next(it))
614 g_slist_free(config_menu_files);