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 gboolean config_focus_raise;
31 gboolean config_focus_last;
33 ObPlacePolicy config_place_policy;
37 gchar *config_title_layout;
39 gint config_desktops_num;
40 GSList *config_desktops_names;
41 gint config_screen_firstdesk;
43 gboolean config_redraw_resize;
45 ObStackingLayer config_dock_layer;
46 gboolean config_dock_floating;
47 ObDirection config_dock_pos;
50 ObOrientation config_dock_orient;
51 gboolean config_dock_hide;
52 guint config_dock_hide_delay;
53 guint config_dock_app_move_button;
54 guint config_dock_app_move_modifiers;
56 guint config_keyboard_reset_keycode;
57 guint config_keyboard_reset_state;
59 gint config_mouse_threshold;
60 gint config_mouse_dclicktime;
62 gboolean config_menu_warppointer;
63 gboolean config_menu_xorstyle;
64 gboolean config_menu_hilightfirst;
65 guint config_menu_hide_delay;
67 GSList *config_menu_files;
69 gint config_resist_win;
70 gint config_resist_edge;
75 <action name="ChangeDesktop">
82 static void parse_key(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
90 if ((n = parse_find_node("chainQuitKey", node))) {
91 key = parse_string(doc, n);
92 translate_key(key, &config_keyboard_reset_state,
93 &config_keyboard_reset_keycode);
97 n = parse_find_node("keybind", node);
99 if (parse_attr_string("key", n, &key)) {
100 keylist = g_list_append(keylist, key);
102 parse_key(i, doc, n->children, keylist);
104 it = g_list_last(keylist);
106 keylist = g_list_delete_link(keylist, it);
108 n = parse_find_node("keybind", n->next);
111 nact = parse_find_node("action", node);
113 if ((action = action_parse(i, doc, nact,
114 OB_USER_ACTION_KEYBOARD_KEY)))
115 keyboard_bind(keylist, action);
116 nact = parse_find_node("action", nact->next);
121 static void parse_keyboard(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
124 keyboard_unbind_all();
126 parse_key(i, doc, node->children, NULL);
131 <context name="Titlebar">
132 <mousebind button="Left" action="Press">
133 <action name="Raise"></action>
139 static void parse_mouse(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
142 xmlNodePtr n, nbut, nact;
151 node = node->children;
153 if ((n = parse_find_node("dragThreshold", node)))
154 config_mouse_threshold = parse_int(doc, n);
155 if ((n = parse_find_node("doubleClickTime", node)))
156 config_mouse_dclicktime = parse_int(doc, n);
158 n = parse_find_node("context", node);
160 if (!parse_attr_string("name", n, &contextstr))
162 nbut = parse_find_node("mousebind", n->children);
164 if (!parse_attr_string("button", nbut, &buttonstr))
166 if (parse_attr_contains("press", nbut, "action")) {
167 uact = OB_USER_ACTION_MOUSE_PRESS;
168 mact = OB_MOUSE_ACTION_PRESS;
169 } else if (parse_attr_contains("release", nbut, "action")) {
170 uact = OB_USER_ACTION_MOUSE_RELEASE;
171 mact = OB_MOUSE_ACTION_RELEASE;
172 } else if (parse_attr_contains("click", nbut, "action")) {
173 uact = OB_USER_ACTION_MOUSE_CLICK;
174 mact = OB_MOUSE_ACTION_CLICK;
175 } else if (parse_attr_contains("doubleclick", nbut,"action")) {
176 uact = OB_USER_ACTION_MOUSE_DOUBLE_CLICK;
177 mact = OB_MOUSE_ACTION_DOUBLE_CLICK;
178 } else if (parse_attr_contains("drag", nbut, "action")) {
179 uact = OB_USER_ACTION_MOUSE_MOTION;
180 mact = OB_MOUSE_ACTION_MOTION;
183 nact = parse_find_node("action", nbut->children);
185 if ((action = action_parse(i, doc, nact, uact)))
186 mouse_bind(buttonstr, contextstr, mact, action);
187 nact = parse_find_node("action", nact->next);
191 nbut = parse_find_node("mousebind", nbut->next);
195 n = parse_find_node("context", n->next);
199 static void parse_focus(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
204 node = node->children;
206 if ((n = parse_find_node("focusNew", node)))
207 config_focus_new = parse_bool(doc, n);
208 if ((n = parse_find_node("followMouse", node)))
209 config_focus_follow = parse_bool(doc, n);
210 if ((n = parse_find_node("focusDelay", node)))
211 config_focus_delay = parse_int(doc, n) * 1000;
212 if ((n = parse_find_node("raiseOnFocus", node)))
213 config_focus_raise = parse_bool(doc, n);
214 if ((n = parse_find_node("focusLast", node)))
215 config_focus_last = parse_bool(doc, n);
218 static void parse_placement(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
223 node = node->children;
225 if ((n = parse_find_node("policy", node)))
226 if (parse_contains("UnderMouse", doc, n))
227 config_place_policy = OB_PLACE_POLICY_MOUSE;
230 static void parse_theme(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
235 node = node->children;
237 if ((n = parse_find_node("name", node))) {
240 g_free(config_theme);
241 c = parse_string(doc, n);
242 config_theme = parse_expand_tilde(c);
245 if ((n = parse_find_node("titleLayout", node))) {
246 g_free(config_title_layout);
247 config_title_layout = parse_string(doc, n);
251 static void parse_desktops(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
256 node = node->children;
258 if ((n = parse_find_node("number", node))) {
259 gint d = parse_int(doc, n);
261 config_desktops_num = d;
263 if ((n = parse_find_node("firstdesk", node))) {
264 gint d = parse_int(doc, n);
266 config_screen_firstdesk = d;
268 if ((n = parse_find_node("names", node))) {
272 for (it = config_desktops_names; it; it = it->next)
274 g_slist_free(config_desktops_names);
275 config_desktops_names = NULL;
277 nname = parse_find_node("name", n->children);
279 config_desktops_names = g_slist_append(config_desktops_names,
280 parse_string(doc, nname));
281 nname = parse_find_node("name", nname->next);
286 static void parse_resize(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
291 node = node->children;
293 if ((n = parse_find_node("drawContents", node)))
294 config_redraw_resize = parse_bool(doc, n);
297 static void parse_dock(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
302 node = node->children;
304 if ((n = parse_find_node("position", node))) {
305 if (parse_contains("TopLeft", doc, n))
306 config_dock_floating = FALSE,
307 config_dock_pos = OB_DIRECTION_NORTHWEST;
308 else if (parse_contains("Top", doc, n))
309 config_dock_floating = FALSE,
310 config_dock_pos = OB_DIRECTION_NORTH;
311 else if (parse_contains("TopRight", doc, n))
312 config_dock_floating = FALSE,
313 config_dock_pos = OB_DIRECTION_NORTHEAST;
314 else if (parse_contains("Right", doc, n))
315 config_dock_floating = FALSE,
316 config_dock_pos = OB_DIRECTION_EAST;
317 else if (parse_contains("BottomRight", doc, n))
318 config_dock_floating = FALSE,
319 config_dock_pos = OB_DIRECTION_SOUTHEAST;
320 else if (parse_contains("Bottom", doc, n))
321 config_dock_floating = FALSE,
322 config_dock_pos = OB_DIRECTION_SOUTH;
323 else if (parse_contains("BottomLeft", doc, n))
324 config_dock_floating = FALSE,
325 config_dock_pos = OB_DIRECTION_SOUTHWEST;
326 else if (parse_contains("Left", doc, n))
327 config_dock_floating = FALSE,
328 config_dock_pos = OB_DIRECTION_WEST;
329 else if (parse_contains("Floating", doc, n))
330 config_dock_floating = TRUE;
332 if (config_dock_floating) {
333 if ((n = parse_find_node("floatingX", node)))
334 config_dock_x = parse_int(doc, n);
335 if ((n = parse_find_node("floatingY", node)))
336 config_dock_y = parse_int(doc, n);
338 if ((n = parse_find_node("stacking", node))) {
339 if (parse_contains("top", doc, n))
340 config_dock_layer = OB_STACKING_LAYER_DOCK_ABOVE;
341 else if (parse_contains("normal", doc, n))
342 config_dock_layer = OB_STACKING_LAYER_DOCK_NORMAL;
343 else if (parse_contains("bottom", doc, n))
344 config_dock_layer = OB_STACKING_LAYER_DOCK_BELOW;
346 if ((n = parse_find_node("direction", node))) {
347 if (parse_contains("horizontal", doc, n))
348 config_dock_orient = OB_ORIENTATION_HORZ;
349 else if (parse_contains("vertical", doc, n))
350 config_dock_orient = OB_ORIENTATION_VERT;
352 if ((n = parse_find_node("autoHide", node)))
353 config_dock_hide = parse_bool(doc, n);
354 if ((n = parse_find_node("hideDelay", node)))
355 config_dock_hide_delay = parse_int(doc, n) * 1000;
356 if ((n = parse_find_node("moveButton", node))) {
357 gchar *str = parse_string(doc, n);
359 if (translate_button(str, &s, &b)) {
360 config_dock_app_move_button = b;
361 config_dock_app_move_modifiers = s;
363 g_warning("invalid button '%s'", str);
369 static void parse_menu(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
372 for (node = node->children; node; node = node->next) {
373 if (!xmlStrcasecmp(node->name, (const xmlChar*) "file")) {
376 c = parse_string(doc, node);
377 config_menu_files = g_slist_append(config_menu_files,
378 parse_expand_tilde(c));
381 if ((n = parse_find_node("warpPointer", node)))
382 config_menu_warppointer = parse_bool(doc, n);
383 if ((n = parse_find_node("xorStyle", node)))
384 config_menu_xorstyle = parse_bool(doc, n);
385 if ((n = parse_find_node("hilightFirst", node)))
386 config_menu_hilightfirst = parse_bool(doc, n);
387 if ((n = parse_find_node("hideDelay", node)))
388 config_menu_hide_delay = parse_int(doc, n);
392 static void parse_resistance(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
397 node = node->children;
398 if ((n = parse_find_node("strength", node)))
399 config_resist_win = parse_int(doc, n);
400 if ((n = parse_find_node("screen_edge_strength", node)))
401 config_resist_edge = parse_int(doc, n);
407 const gchar *actname;
410 static void bind_default_keyboard()
413 ObDefKeyBind binds[] = {
414 { "A-Tab", "NextWindow" },
415 { "S-A-Tab", "PreviousWindow" },
420 for (it = binds; it->key; ++it) {
421 GList *l = g_list_append(NULL, g_strdup(it->key));
422 keyboard_bind(l, action_from_string(it->actname,
423 OB_USER_ACTION_KEYBOARD_KEY));
430 const gchar *context;
431 const ObMouseAction mact;
432 const gchar *actname;
435 static void bind_default_mouse()
438 ObDefMouseBind binds[] = {
439 { "Left", "Client", OB_MOUSE_ACTION_PRESS, "Focus" },
440 { "Middle", "Client", OB_MOUSE_ACTION_PRESS, "Focus" },
441 { "Right", "Client", OB_MOUSE_ACTION_PRESS, "Focus" },
442 { "Left", "Desktop", OB_MOUSE_ACTION_PRESS, "Focus" },
443 { "Middle", "Desktop", OB_MOUSE_ACTION_PRESS, "Focus" },
444 { "Right", "Desktop", OB_MOUSE_ACTION_PRESS, "Focus" },
445 { "Left", "Titlebar", OB_MOUSE_ACTION_PRESS, "Focus" },
446 { "Left", "Handle", OB_MOUSE_ACTION_PRESS, "Focus" },
447 { "Left", "BLCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
448 { "Left", "BRCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
449 { "Left", "TLCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
450 { "Left", "TRCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
451 { "Left", "Close", OB_MOUSE_ACTION_PRESS, "Focus" },
452 { "Left", "Maximize", OB_MOUSE_ACTION_PRESS, "Focus" },
453 { "Left", "Iconify", OB_MOUSE_ACTION_PRESS, "Focus" },
454 { "Left", "Icon", OB_MOUSE_ACTION_PRESS, "Focus" },
455 { "Left", "AllDesktops", OB_MOUSE_ACTION_PRESS, "Focus" },
456 { "Left", "Shade", OB_MOUSE_ACTION_PRESS, "Focus" },
457 { "Left", "Client", OB_MOUSE_ACTION_CLICK, "Raise" },
458 { "Left", "Titlebar", OB_MOUSE_ACTION_CLICK, "Raise" },
459 { "Middle", "Titlebar", OB_MOUSE_ACTION_CLICK, "Lower" },
460 { "Left", "Handle", OB_MOUSE_ACTION_CLICK, "Raise" },
461 { "Left", "BLCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
462 { "Left", "BRCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
463 { "Left", "TLCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
464 { "Left", "TRCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
465 { "Left", "Close", OB_MOUSE_ACTION_CLICK, "Raise" },
466 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK, "Raise" },
467 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK, "Raise" },
468 { "Left", "Icon", OB_MOUSE_ACTION_CLICK, "Raise" },
469 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK, "Raise" },
470 { "Left", "Shade", OB_MOUSE_ACTION_CLICK, "Raise" },
471 { "Left", "Close", OB_MOUSE_ACTION_CLICK, "Close" },
472 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK, "ToggleMaximizeFull" },
473 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK, "Iconify" },
474 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK, "ToggleOmnipresent" },
475 { "Left", "Shade", OB_MOUSE_ACTION_CLICK, "ToggleShade" },
476 { "Left", "TLCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
477 { "Left", "TRCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
478 { "Left", "BLCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
479 { "Left", "BRCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
480 { "Left", "Titlebar", OB_MOUSE_ACTION_MOTION, "Move" },
481 { "A-Left", "Frame", OB_MOUSE_ACTION_MOTION, "Move" },
482 { "A-Middle", "Frame", OB_MOUSE_ACTION_MOTION, "Resize" },
483 { NULL, NULL, 0, NULL }
486 for (it = binds; it->button; ++it) {
489 case OB_MOUSE_ACTION_PRESS:
490 uact = OB_USER_ACTION_MOUSE_PRESS; break;
491 case OB_MOUSE_ACTION_RELEASE:
492 uact = OB_USER_ACTION_MOUSE_RELEASE; break;
493 case OB_MOUSE_ACTION_CLICK:
494 uact = OB_USER_ACTION_MOUSE_CLICK; break;
495 case OB_MOUSE_ACTION_DOUBLE_CLICK:
496 uact = OB_USER_ACTION_MOUSE_DOUBLE_CLICK; break;
497 case OB_MOUSE_ACTION_MOTION:
498 uact = OB_USER_ACTION_MOUSE_MOTION; break;
499 case OB_NUM_MOUSE_ACTIONS:
500 g_assert_not_reached();
502 mouse_bind(it->button, it->context, it->mact,
503 action_from_string(it->actname, uact));
507 void config_startup(ObParseInst *i)
509 config_focus_new = TRUE;
510 config_focus_follow = FALSE;
511 config_focus_delay = 0;
512 config_focus_raise = FALSE;
513 config_focus_last = FALSE;
515 parse_register(i, "focus", parse_focus, NULL);
517 config_place_policy = OB_PLACE_POLICY_SMART;
519 parse_register(i, "placement", parse_placement, NULL);
523 config_title_layout = g_strdup("NLIMC");
525 parse_register(i, "theme", parse_theme, NULL);
527 config_desktops_num = 4;
528 config_screen_firstdesk = 1;
529 config_desktops_names = NULL;
531 parse_register(i, "desktops", parse_desktops, NULL);
533 config_redraw_resize = TRUE;
535 parse_register(i, "resize", parse_resize, NULL);
537 config_dock_layer = OB_STACKING_LAYER_DOCK_ABOVE;
538 config_dock_pos = OB_DIRECTION_NORTHEAST;
539 config_dock_floating = FALSE;
542 config_dock_orient = OB_ORIENTATION_VERT;
543 config_dock_hide = FALSE;
544 config_dock_hide_delay = 300;
545 config_dock_app_move_button = 2; /* middle */
546 config_dock_app_move_modifiers = 0;
548 parse_register(i, "dock", parse_dock, NULL);
550 translate_key("C-g", &config_keyboard_reset_state,
551 &config_keyboard_reset_keycode);
553 bind_default_keyboard();
555 parse_register(i, "keyboard", parse_keyboard, NULL);
557 config_mouse_threshold = 3;
558 config_mouse_dclicktime = 200;
560 bind_default_mouse();
562 parse_register(i, "mouse", parse_mouse, NULL);
564 config_resist_win = 10;
565 config_resist_edge = 20;
567 parse_register(i, "resistance", parse_resistance, NULL);
569 config_menu_warppointer = TRUE;
570 config_menu_xorstyle = TRUE;
571 config_menu_hilightfirst = TRUE;
572 config_menu_hide_delay = 250;
573 config_menu_files = NULL;
575 parse_register(i, "menu", parse_menu, NULL);
578 void config_shutdown()
582 g_free(config_theme);
584 g_free(config_title_layout);
586 for (it = config_desktops_names; it; it = g_slist_next(it))
588 g_slist_free(config_desktops_names);
590 for (it = config_menu_files; it; it = g_slist_next(it))
592 g_slist_free(config_menu_files);