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;
34 gchar *config_title_layout;
36 int config_desktops_num;
37 GSList *config_desktops_names;
39 gboolean config_redraw_resize;
41 ObStackingLayer config_dock_layer;
42 gboolean config_dock_floating;
43 ObDirection config_dock_pos;
46 ObOrientation config_dock_orient;
47 gboolean config_dock_hide;
48 guint config_dock_hide_delay;
50 guint config_keyboard_reset_keycode;
51 guint config_keyboard_reset_state;
53 gint config_mouse_threshold;
54 gint config_mouse_dclicktime;
56 GSList *config_menu_files;
58 gint config_resist_win;
59 gint config_resist_edge;
64 <action name="ChangeDesktop">
71 static void parse_key(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
79 if ((n = parse_find_node("chainQuitKey", node))) {
80 key = parse_string(doc, n);
81 translate_key(key, &config_keyboard_reset_state,
82 &config_keyboard_reset_keycode);
86 n = parse_find_node("keybind", node);
88 if (parse_attr_string("key", n, &key)) {
89 keylist = g_list_append(keylist, key);
91 parse_key(i, doc, n->children, keylist);
93 it = g_list_last(keylist);
95 keylist = g_list_delete_link(keylist, it);
97 n = parse_find_node("keybind", n->next);
100 nact = parse_find_node("action", node);
102 if ((action = action_parse(i, doc, nact,
103 OB_USER_ACTION_KEYBOARD_KEY)))
104 keyboard_bind(keylist, action);
105 nact = parse_find_node("action", nact->next);
110 static void parse_keyboard(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
113 keyboard_unbind_all();
115 parse_key(i, doc, node->children, NULL);
120 <context name="Titlebar">
121 <mousebind button="Left" action="Press">
122 <action name="Raise"></action>
128 static void parse_mouse(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
131 xmlNodePtr n, nbut, nact;
140 node = node->children;
142 if ((n = parse_find_node("dragThreshold", node)))
143 config_mouse_threshold = parse_int(doc, n);
144 if ((n = parse_find_node("doubleClickTime", node)))
145 config_mouse_dclicktime = parse_int(doc, n);
147 n = parse_find_node("context", node);
149 if (!parse_attr_string("name", n, &contextstr))
151 nbut = parse_find_node("mousebind", n->children);
153 if (!parse_attr_string("button", nbut, &buttonstr))
155 if (parse_attr_contains("press", nbut, "action")) {
156 uact = OB_USER_ACTION_MOUSE_PRESS;
157 mact = OB_MOUSE_ACTION_PRESS;
158 } else if (parse_attr_contains("release", nbut, "action")) {
159 uact = OB_USER_ACTION_MOUSE_RELEASE;
160 mact = OB_MOUSE_ACTION_RELEASE;
161 } else if (parse_attr_contains("click", nbut, "action")) {
162 uact = OB_USER_ACTION_MOUSE_CLICK;
163 mact = OB_MOUSE_ACTION_CLICK;
164 } else if (parse_attr_contains("doubleclick", nbut,"action")) {
165 uact = OB_USER_ACTION_MOUSE_DOUBLE_CLICK;
166 mact = OB_MOUSE_ACTION_DOUBLE_CLICK;
167 } else if (parse_attr_contains("drag", nbut, "action")) {
168 uact = OB_USER_ACTION_MOUSE_MOTION;
169 mact = OB_MOUSE_ACTION_MOTION;
172 nact = parse_find_node("action", nbut->children);
174 if ((action = action_parse(i, doc, nact, uact)))
175 mouse_bind(buttonstr, contextstr, mact, action);
176 nact = parse_find_node("action", nact->next);
180 nbut = parse_find_node("mousebind", nbut->next);
184 n = parse_find_node("context", n->next);
188 static void parse_focus(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
193 node = node->children;
195 if ((n = parse_find_node("focusNew", node)))
196 config_focus_new = parse_bool(doc, n);
197 if ((n = parse_find_node("followMouse", node)))
198 config_focus_follow = parse_bool(doc, n);
199 if ((n = parse_find_node("focusDelay", node)))
200 config_focus_delay = parse_int(doc, n) * 1000;
201 if ((n = parse_find_node("raiseOnFocus", node)))
202 config_focus_raise = parse_bool(doc, n);
205 static void parse_theme(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
210 node = node->children;
212 if ((n = parse_find_node("name", node))) {
215 g_free(config_theme);
216 c = parse_string(doc, n);
217 config_theme = parse_expand_tilde(c);
220 if ((n = parse_find_node("titleLayout", node))) {
221 g_free(config_title_layout);
222 config_title_layout = parse_string(doc, n);
226 static void parse_desktops(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
231 node = node->children;
233 if ((n = parse_find_node("number", node))) {
234 guint d = parse_int(doc, n);
236 config_desktops_num = d;
238 if ((n = parse_find_node("names", node))) {
242 for (it = config_desktops_names; it; it = it->next)
244 g_slist_free(config_desktops_names);
245 config_desktops_names = NULL;
247 nname = parse_find_node("name", n->children);
249 config_desktops_names = g_slist_append(config_desktops_names,
250 parse_string(doc, nname));
251 nname = parse_find_node("name", nname->next);
256 static void parse_resize(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
261 node = node->children;
263 if ((n = parse_find_node("drawContents", node)))
264 config_redraw_resize = parse_bool(doc, n);
267 static void parse_dock(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, void *d)
271 node = node->children;
273 if ((n = parse_find_node("position", node))) {
274 if (parse_contains("TopLeft", doc, n))
275 config_dock_floating = FALSE,
276 config_dock_pos = OB_DIRECTION_NORTHWEST;
277 else if (parse_contains("Top", doc, n))
278 config_dock_floating = FALSE,
279 config_dock_pos = OB_DIRECTION_NORTH;
280 else if (parse_contains("TopRight", doc, n))
281 config_dock_floating = FALSE,
282 config_dock_pos = OB_DIRECTION_NORTHEAST;
283 else if (parse_contains("Right", doc, n))
284 config_dock_floating = FALSE,
285 config_dock_pos = OB_DIRECTION_EAST;
286 else if (parse_contains("BottomRight", doc, n))
287 config_dock_floating = FALSE,
288 config_dock_pos = OB_DIRECTION_SOUTHEAST;
289 else if (parse_contains("Bottom", doc, n))
290 config_dock_floating = FALSE,
291 config_dock_pos = OB_DIRECTION_SOUTH;
292 else if (parse_contains("BottomLeft", doc, n))
293 config_dock_floating = FALSE,
294 config_dock_pos = OB_DIRECTION_SOUTHWEST;
295 else if (parse_contains("Left", doc, n))
296 config_dock_floating = FALSE,
297 config_dock_pos = OB_DIRECTION_WEST;
298 else if (parse_contains("Floating", doc, n))
299 config_dock_floating = TRUE;
301 if (config_dock_floating) {
302 if ((n = parse_find_node("floatingX", node)))
303 config_dock_x = parse_int(doc, n);
304 if ((n = parse_find_node("floatingY", node)))
305 config_dock_y = parse_int(doc, n);
307 if ((n = parse_find_node("stacking", node))) {
308 if (parse_contains("top", doc, n))
309 config_dock_layer = OB_STACKING_LAYER_TOP;
310 else if (parse_contains("normal", doc, n))
311 config_dock_layer = OB_STACKING_LAYER_NORMAL;
312 else if (parse_contains("bottom", doc, n))
313 config_dock_layer = OB_STACKING_LAYER_BELOW;
315 if ((n = parse_find_node("direction", node))) {
316 if (parse_contains("horizontal", doc, n))
317 config_dock_orient = OB_ORIENTATION_HORZ;
318 else if (parse_contains("vertical", doc, n))
319 config_dock_orient = OB_ORIENTATION_VERT;
321 if ((n = parse_find_node("autoHide", node)))
322 config_dock_hide = parse_bool(doc, n);
323 if ((n = parse_find_node("hideDelay", node)))
324 config_dock_hide_delay = parse_int(doc, n) * 1000;
327 static void parse_menu(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node, void *d)
329 for (node = node->children; node; node = node->next) {
330 if (!xmlStrcasecmp(node->name, (const xmlChar*) "file")) {
333 c = parse_string(doc, node);
334 config_menu_files = g_slist_append(config_menu_files,
335 parse_expand_tilde(c));
341 static void parse_resistance(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node,
346 node = node->children;
347 if ((n = parse_find_node("strength", node)))
348 config_resist_win = parse_int(doc, n);
349 if ((n = parse_find_node("screen_edge_strength", node)))
350 config_resist_edge = parse_int(doc, n);
356 const gchar *actname;
359 static void bind_default_keyboard()
362 ObDefKeyBind binds[] = {
363 { "A-Tab", "NextWindow" },
364 { "S-A-Tab", "PreviousWindow" },
365 { "C-A-Right", "DesktopRight" },
366 { "C-A-Left", "DesktopLeft" },
367 { "C-A-Up", "DesktopUp" },
368 { "C-A-Down", "DesktopDown" },
369 { "S-A-Right", "SendToDesktopRight" },
370 { "S-A-Left", "SendToDesktopLeft" },
371 { "S-A-Up", "SendToDesktopUp" },
372 { "S-A-Down", "SendToDesktopDown" },
373 { "A-F10", "MaximizeFull" },
374 { "A-F5", "UnmaximizeFull" },
375 { "A-F12", "ToggleShade" },
378 { "A-F8", "Resize" },
379 { "A-F9", "Iconify" },
383 for (it = binds; it->key; ++it) {
384 GList *l = g_list_append(NULL, g_strdup(it->key));
385 keyboard_bind(l, action_from_string(it->actname,
386 OB_USER_ACTION_KEYBOARD_KEY));
393 const gchar *context;
394 const ObMouseAction mact;
395 const gchar *actname;
398 static void bind_default_mouse()
401 ObDefMouseBind binds[] = {
402 { "Up", "Desktop", OB_MOUSE_ACTION_PRESS, "DesktopNext" },
403 { "Down", "Desktop", OB_MOUSE_ACTION_PRESS, "DesktopPrevious" },
404 { "A-Up", "Desktop", OB_MOUSE_ACTION_PRESS, "DesktopNext" },
405 { "A-Down", "Desktop", OB_MOUSE_ACTION_PRESS, "DesktopPrevious" },
406 { "A-Up", "Frame", OB_MOUSE_ACTION_PRESS, "DesktopNext" },
407 { "A-Down", "Frame", OB_MOUSE_ACTION_PRESS, "DesktopPrevious" },
408 { "A-Up", "MoveResize", OB_MOUSE_ACTION_PRESS, "DesktopNext" },
409 { "Down", "MoveResize", OB_MOUSE_ACTION_PRESS, "DesktopPrevious" },
410 { "Left", "Client", OB_MOUSE_ACTION_PRESS, "Focus" },
411 { "Middle", "Client", OB_MOUSE_ACTION_PRESS, "Focus" },
412 { "Right", "Client", OB_MOUSE_ACTION_PRESS, "Focus" },
413 { "Left", "Desktop", OB_MOUSE_ACTION_PRESS, "Focus" },
414 { "Middle", "Desktop", OB_MOUSE_ACTION_PRESS, "Focus" },
415 { "Right", "Desktop", OB_MOUSE_ACTION_PRESS, "Focus" },
416 { "Left", "Titlebar", OB_MOUSE_ACTION_PRESS, "Focus" },
417 { "Left", "Handle", OB_MOUSE_ACTION_PRESS, "Focus" },
418 { "Left", "BLCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
419 { "Left", "BRCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
420 { "Left", "TLCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
421 { "Left", "TRCorner", OB_MOUSE_ACTION_PRESS, "Focus" },
422 { "Left", "Close", OB_MOUSE_ACTION_PRESS, "Focus" },
423 { "Left", "Maximize", OB_MOUSE_ACTION_PRESS, "Focus" },
424 { "Left", "Iconify", OB_MOUSE_ACTION_PRESS, "Focus" },
425 { "Left", "Icon", OB_MOUSE_ACTION_PRESS, "Focus" },
426 { "Left", "AllDesktops", OB_MOUSE_ACTION_PRESS, "Focus" },
427 { "Left", "Shade", OB_MOUSE_ACTION_PRESS, "Focus" },
428 { "Left", "Client", OB_MOUSE_ACTION_CLICK, "Raise" },
429 { "Left", "Titlebar", OB_MOUSE_ACTION_CLICK, "Raise" },
430 { "Middle", "Titlebar", OB_MOUSE_ACTION_CLICK, "Lower" },
431 { "Left", "Handle", OB_MOUSE_ACTION_CLICK, "Raise" },
432 { "Left", "BLCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
433 { "Left", "BRCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
434 { "Left", "TLCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
435 { "Left", "TRCorner", OB_MOUSE_ACTION_CLICK, "Raise" },
436 { "Left", "Close", OB_MOUSE_ACTION_CLICK, "Raise" },
437 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK, "Raise" },
438 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK, "Raise" },
439 { "Left", "Icon", OB_MOUSE_ACTION_CLICK, "Raise" },
440 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK, "Raise" },
441 { "Left", "Shade", OB_MOUSE_ACTION_CLICK, "Raise" },
442 { "Left", "Close", OB_MOUSE_ACTION_CLICK, "Close" },
443 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK, "ToggleMaximizeFull" },
444 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK, "Iconify" },
445 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK, "ToggleOmnipresent" },
446 { "Left", "Shade", OB_MOUSE_ACTION_CLICK, "ToggleShade" },
447 { "Left", "TLCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
448 { "Left", "TRCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
449 { "Left", "BLCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
450 { "Left", "BRCorner", OB_MOUSE_ACTION_MOTION, "Resize" },
451 { "Left", "Titlebar", OB_MOUSE_ACTION_MOTION, "Move" },
452 { "A-Left", "Frame", OB_MOUSE_ACTION_MOTION, "Move" },
453 { "A-Middle", "Frame", OB_MOUSE_ACTION_MOTION, "Resize" },
454 { NULL, NULL, 0, NULL }
457 for (it = binds; it->button; ++it) {
460 case OB_MOUSE_ACTION_PRESS:
461 uact = OB_USER_ACTION_MOUSE_PRESS; break;
462 case OB_MOUSE_ACTION_RELEASE:
463 uact = OB_USER_ACTION_MOUSE_RELEASE; break;
464 case OB_MOUSE_ACTION_CLICK:
465 uact = OB_USER_ACTION_MOUSE_CLICK; break;
466 case OB_MOUSE_ACTION_DOUBLE_CLICK:
467 uact = OB_USER_ACTION_MOUSE_DOUBLE_CLICK; break;
468 case OB_MOUSE_ACTION_MOTION:
469 uact = OB_USER_ACTION_MOUSE_MOTION; break;
470 case OB_NUM_MOUSE_ACTIONS:
471 g_assert_not_reached();
473 mouse_bind(it->button, it->context, it->mact,
474 action_from_string(it->actname, uact));
478 void config_startup(ObParseInst *i)
480 config_focus_new = TRUE;
481 config_focus_follow = FALSE;
482 config_focus_delay = 0;
483 config_focus_raise = FALSE;
485 parse_register(i, "focus", parse_focus, NULL);
489 config_title_layout = g_strdup("NLIMC");
491 parse_register(i, "theme", parse_theme, NULL);
493 config_desktops_num = 4;
494 config_desktops_names = NULL;
496 parse_register(i, "desktops", parse_desktops, NULL);
498 config_redraw_resize = TRUE;
500 parse_register(i, "resize", parse_resize, NULL);
502 config_dock_layer = OB_STACKING_LAYER_TOP;
503 config_dock_pos = OB_DIRECTION_NORTHEAST;
504 config_dock_floating = FALSE;
507 config_dock_orient = OB_ORIENTATION_VERT;
508 config_dock_hide = FALSE;
509 config_dock_hide_delay = 300;
511 parse_register(i, "dock", parse_dock, NULL);
513 translate_key("C-g", &config_keyboard_reset_state,
514 &config_keyboard_reset_keycode);
516 bind_default_keyboard();
518 parse_register(i, "keyboard", parse_keyboard, NULL);
520 config_mouse_threshold = 3;
521 config_mouse_dclicktime = 200;
523 bind_default_mouse();
525 parse_register(i, "mouse", parse_mouse, NULL);
527 config_resist_win = 10;
528 config_resist_edge = 20;
530 parse_register(i, "resistance", parse_resistance, NULL);
532 config_menu_files = NULL;
534 parse_register(i, "menu", parse_menu, NULL);
537 void config_shutdown()
541 g_free(config_theme);
543 g_free(config_title_layout);
545 for (it = config_desktops_names; it; it = g_slist_next(it))
547 g_slist_free(config_desktops_names);
549 for (it = config_menu_files; it; it = g_slist_next(it))
551 g_slist_free(config_menu_files);