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_resize_redraw
;
44 gint config_resize_popup_show
;
46 ObStackingLayer config_dock_layer
;
47 gboolean config_dock_floating
;
48 ObDirection config_dock_pos
;
51 ObOrientation config_dock_orient
;
52 gboolean config_dock_hide
;
53 guint config_dock_hide_delay
;
54 guint config_dock_app_move_button
;
55 guint config_dock_app_move_modifiers
;
57 guint config_keyboard_reset_keycode
;
58 guint config_keyboard_reset_state
;
60 gint config_mouse_threshold
;
61 gint config_mouse_dclicktime
;
63 gboolean config_menu_warppointer
;
64 gboolean config_menu_xorstyle
;
65 gboolean config_menu_hilightfirst
;
66 guint config_menu_hide_delay
;
68 GSList
*config_menu_files
;
70 gint config_resist_win
;
71 gint config_resist_edge
;
76 <action name="ChangeDesktop">
83 static void parse_key(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
91 if ((n
= parse_find_node("chainQuitKey", node
))) {
92 key
= parse_string(doc
, n
);
93 translate_key(key
, &config_keyboard_reset_state
,
94 &config_keyboard_reset_keycode
);
98 n
= parse_find_node("keybind", node
);
100 if (parse_attr_string("key", n
, &key
)) {
101 keylist
= g_list_append(keylist
, key
);
103 parse_key(i
, doc
, n
->children
, keylist
);
105 it
= g_list_last(keylist
);
107 keylist
= g_list_delete_link(keylist
, it
);
109 n
= parse_find_node("keybind", n
->next
);
112 nact
= parse_find_node("action", node
);
114 if ((action
= action_parse(i
, doc
, nact
,
115 OB_USER_ACTION_KEYBOARD_KEY
)))
116 keyboard_bind(keylist
, action
);
117 nact
= parse_find_node("action", nact
->next
);
122 static void parse_keyboard(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
125 keyboard_unbind_all();
127 parse_key(i
, doc
, node
->children
, NULL
);
132 <context name="Titlebar">
133 <mousebind button="Left" action="Press">
134 <action name="Raise"></action>
140 static void parse_mouse(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
143 xmlNodePtr n
, nbut
, nact
;
152 node
= node
->children
;
154 if ((n
= parse_find_node("dragThreshold", node
)))
155 config_mouse_threshold
= parse_int(doc
, n
);
156 if ((n
= parse_find_node("doubleClickTime", node
)))
157 config_mouse_dclicktime
= parse_int(doc
, n
);
159 n
= parse_find_node("context", node
);
161 if (!parse_attr_string("name", n
, &contextstr
))
163 nbut
= parse_find_node("mousebind", n
->children
);
165 if (!parse_attr_string("button", nbut
, &buttonstr
))
167 if (parse_attr_contains("press", nbut
, "action")) {
168 uact
= OB_USER_ACTION_MOUSE_PRESS
;
169 mact
= OB_MOUSE_ACTION_PRESS
;
170 } else if (parse_attr_contains("release", nbut
, "action")) {
171 uact
= OB_USER_ACTION_MOUSE_RELEASE
;
172 mact
= OB_MOUSE_ACTION_RELEASE
;
173 } else if (parse_attr_contains("click", nbut
, "action")) {
174 uact
= OB_USER_ACTION_MOUSE_CLICK
;
175 mact
= OB_MOUSE_ACTION_CLICK
;
176 } else if (parse_attr_contains("doubleclick", nbut
,"action")) {
177 uact
= OB_USER_ACTION_MOUSE_DOUBLE_CLICK
;
178 mact
= OB_MOUSE_ACTION_DOUBLE_CLICK
;
179 } else if (parse_attr_contains("drag", nbut
, "action")) {
180 uact
= OB_USER_ACTION_MOUSE_MOTION
;
181 mact
= OB_MOUSE_ACTION_MOTION
;
184 nact
= parse_find_node("action", nbut
->children
);
186 if ((action
= action_parse(i
, doc
, nact
, uact
)))
187 mouse_bind(buttonstr
, contextstr
, mact
, action
);
188 nact
= parse_find_node("action", nact
->next
);
192 nbut
= parse_find_node("mousebind", nbut
->next
);
196 n
= parse_find_node("context", n
->next
);
200 static void parse_focus(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
205 node
= node
->children
;
207 if ((n
= parse_find_node("focusNew", node
)))
208 config_focus_new
= parse_bool(doc
, n
);
209 if ((n
= parse_find_node("followMouse", node
)))
210 config_focus_follow
= parse_bool(doc
, n
);
211 if ((n
= parse_find_node("focusDelay", node
)))
212 config_focus_delay
= parse_int(doc
, n
) * 1000;
213 if ((n
= parse_find_node("raiseOnFocus", node
)))
214 config_focus_raise
= parse_bool(doc
, n
);
215 if ((n
= parse_find_node("focusLast", node
)))
216 config_focus_last
= parse_bool(doc
, n
);
219 static void parse_placement(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
224 node
= node
->children
;
226 if ((n
= parse_find_node("policy", node
)))
227 if (parse_contains("UnderMouse", doc
, n
))
228 config_place_policy
= OB_PLACE_POLICY_MOUSE
;
231 static void parse_theme(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
236 node
= node
->children
;
238 if ((n
= parse_find_node("name", node
))) {
241 g_free(config_theme
);
242 c
= parse_string(doc
, n
);
243 config_theme
= parse_expand_tilde(c
);
246 if ((n
= parse_find_node("titleLayout", node
))) {
247 g_free(config_title_layout
);
248 config_title_layout
= parse_string(doc
, n
);
252 static void parse_desktops(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
257 node
= node
->children
;
259 if ((n
= parse_find_node("number", node
))) {
260 gint d
= parse_int(doc
, n
);
262 config_desktops_num
= d
;
264 if ((n
= parse_find_node("firstdesk", node
))) {
265 gint d
= parse_int(doc
, n
);
267 config_screen_firstdesk
= d
;
269 if ((n
= parse_find_node("names", node
))) {
273 for (it
= config_desktops_names
; it
; it
= it
->next
)
275 g_slist_free(config_desktops_names
);
276 config_desktops_names
= NULL
;
278 nname
= parse_find_node("name", n
->children
);
280 config_desktops_names
= g_slist_append(config_desktops_names
,
281 parse_string(doc
, nname
));
282 nname
= parse_find_node("name", nname
->next
);
287 static void parse_resize(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
292 node
= node
->children
;
294 if ((n
= parse_find_node("drawContents", node
)))
295 config_resize_redraw
= parse_bool(doc
, n
);
296 if ((n
= parse_find_node("popupShow", node
))) {
297 if (parse_contains("Always", doc
, n
))
298 config_resize_popup_show
= 2;
299 else if (parse_contains("Never", doc
, n
))
300 config_resize_popup_show
= 0;
301 else if (parse_contains("Nonpixel", doc
, n
))
302 config_resize_popup_show
= 1;
306 static void parse_dock(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
311 node
= node
->children
;
313 if ((n
= parse_find_node("position", node
))) {
314 if (parse_contains("TopLeft", doc
, n
))
315 config_dock_floating
= FALSE
,
316 config_dock_pos
= OB_DIRECTION_NORTHWEST
;
317 else if (parse_contains("Top", doc
, n
))
318 config_dock_floating
= FALSE
,
319 config_dock_pos
= OB_DIRECTION_NORTH
;
320 else if (parse_contains("TopRight", doc
, n
))
321 config_dock_floating
= FALSE
,
322 config_dock_pos
= OB_DIRECTION_NORTHEAST
;
323 else if (parse_contains("Right", doc
, n
))
324 config_dock_floating
= FALSE
,
325 config_dock_pos
= OB_DIRECTION_EAST
;
326 else if (parse_contains("BottomRight", doc
, n
))
327 config_dock_floating
= FALSE
,
328 config_dock_pos
= OB_DIRECTION_SOUTHEAST
;
329 else if (parse_contains("Bottom", doc
, n
))
330 config_dock_floating
= FALSE
,
331 config_dock_pos
= OB_DIRECTION_SOUTH
;
332 else if (parse_contains("BottomLeft", doc
, n
))
333 config_dock_floating
= FALSE
,
334 config_dock_pos
= OB_DIRECTION_SOUTHWEST
;
335 else if (parse_contains("Left", doc
, n
))
336 config_dock_floating
= FALSE
,
337 config_dock_pos
= OB_DIRECTION_WEST
;
338 else if (parse_contains("Floating", doc
, n
))
339 config_dock_floating
= TRUE
;
341 if (config_dock_floating
) {
342 if ((n
= parse_find_node("floatingX", node
)))
343 config_dock_x
= parse_int(doc
, n
);
344 if ((n
= parse_find_node("floatingY", node
)))
345 config_dock_y
= parse_int(doc
, n
);
347 if ((n
= parse_find_node("stacking", node
))) {
348 if (parse_contains("top", doc
, n
))
349 config_dock_layer
= OB_STACKING_LAYER_DOCK_ABOVE
;
350 else if (parse_contains("normal", doc
, n
))
351 config_dock_layer
= OB_STACKING_LAYER_DOCK_NORMAL
;
352 else if (parse_contains("bottom", doc
, n
))
353 config_dock_layer
= OB_STACKING_LAYER_DOCK_BELOW
;
355 if ((n
= parse_find_node("direction", node
))) {
356 if (parse_contains("horizontal", doc
, n
))
357 config_dock_orient
= OB_ORIENTATION_HORZ
;
358 else if (parse_contains("vertical", doc
, n
))
359 config_dock_orient
= OB_ORIENTATION_VERT
;
361 if ((n
= parse_find_node("autoHide", node
)))
362 config_dock_hide
= parse_bool(doc
, n
);
363 if ((n
= parse_find_node("hideDelay", node
)))
364 config_dock_hide_delay
= parse_int(doc
, n
) * 1000;
365 if ((n
= parse_find_node("moveButton", node
))) {
366 gchar
*str
= parse_string(doc
, n
);
368 if (translate_button(str
, &s
, &b
)) {
369 config_dock_app_move_button
= b
;
370 config_dock_app_move_modifiers
= s
;
372 g_warning("invalid button '%s'", str
);
378 static void parse_menu(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
381 for (node
= node
->children
; node
; node
= node
->next
) {
382 if (!xmlStrcasecmp(node
->name
, (const xmlChar
*) "file")) {
385 c
= parse_string(doc
, node
);
386 config_menu_files
= g_slist_append(config_menu_files
,
387 parse_expand_tilde(c
));
390 if ((n
= parse_find_node("warpPointer", node
)))
391 config_menu_warppointer
= parse_bool(doc
, n
);
392 if ((n
= parse_find_node("xorStyle", node
)))
393 config_menu_xorstyle
= parse_bool(doc
, n
);
394 if ((n
= parse_find_node("hilightFirst", node
)))
395 config_menu_hilightfirst
= parse_bool(doc
, n
);
396 if ((n
= parse_find_node("hideDelay", node
)))
397 config_menu_hide_delay
= parse_int(doc
, n
);
401 static void parse_resistance(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
406 node
= node
->children
;
407 if ((n
= parse_find_node("strength", node
)))
408 config_resist_win
= parse_int(doc
, n
);
409 if ((n
= parse_find_node("screen_edge_strength", node
)))
410 config_resist_edge
= parse_int(doc
, n
);
416 const gchar
*actname
;
419 static void bind_default_keyboard()
422 ObDefKeyBind binds
[] = {
423 { "A-Tab", "NextWindow" },
424 { "S-A-Tab", "PreviousWindow" },
429 for (it
= binds
; it
->key
; ++it
) {
430 GList
*l
= g_list_append(NULL
, g_strdup(it
->key
));
431 keyboard_bind(l
, action_from_string(it
->actname
,
432 OB_USER_ACTION_KEYBOARD_KEY
));
439 const gchar
*context
;
440 const ObMouseAction mact
;
441 const gchar
*actname
;
444 static void bind_default_mouse()
447 ObDefMouseBind binds
[] = {
448 { "Left", "Client", OB_MOUSE_ACTION_PRESS
, "Focus" },
449 { "Middle", "Client", OB_MOUSE_ACTION_PRESS
, "Focus" },
450 { "Right", "Client", OB_MOUSE_ACTION_PRESS
, "Focus" },
451 { "Left", "Desktop", OB_MOUSE_ACTION_PRESS
, "Focus" },
452 { "Middle", "Desktop", OB_MOUSE_ACTION_PRESS
, "Focus" },
453 { "Right", "Desktop", OB_MOUSE_ACTION_PRESS
, "Focus" },
454 { "Left", "Titlebar", OB_MOUSE_ACTION_PRESS
, "Focus" },
455 { "Left", "Handle", OB_MOUSE_ACTION_PRESS
, "Focus" },
456 { "Left", "BLCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
457 { "Left", "BRCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
458 { "Left", "TLCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
459 { "Left", "TRCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
460 { "Left", "Close", OB_MOUSE_ACTION_PRESS
, "Focus" },
461 { "Left", "Maximize", OB_MOUSE_ACTION_PRESS
, "Focus" },
462 { "Left", "Iconify", OB_MOUSE_ACTION_PRESS
, "Focus" },
463 { "Left", "Icon", OB_MOUSE_ACTION_PRESS
, "Focus" },
464 { "Left", "AllDesktops", OB_MOUSE_ACTION_PRESS
, "Focus" },
465 { "Left", "Shade", OB_MOUSE_ACTION_PRESS
, "Focus" },
466 { "Left", "Client", OB_MOUSE_ACTION_CLICK
, "Raise" },
467 { "Left", "Titlebar", OB_MOUSE_ACTION_CLICK
, "Raise" },
468 { "Middle", "Titlebar", OB_MOUSE_ACTION_CLICK
, "Lower" },
469 { "Left", "Handle", OB_MOUSE_ACTION_CLICK
, "Raise" },
470 { "Left", "BLCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
471 { "Left", "BRCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
472 { "Left", "TLCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
473 { "Left", "TRCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
474 { "Left", "Close", OB_MOUSE_ACTION_CLICK
, "Raise" },
475 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK
, "Raise" },
476 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK
, "Raise" },
477 { "Left", "Icon", OB_MOUSE_ACTION_CLICK
, "Raise" },
478 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK
, "Raise" },
479 { "Left", "Shade", OB_MOUSE_ACTION_CLICK
, "Raise" },
480 { "Left", "Close", OB_MOUSE_ACTION_CLICK
, "Close" },
481 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK
, "ToggleMaximizeFull" },
482 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK
, "Iconify" },
483 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK
, "ToggleOmnipresent" },
484 { "Left", "Shade", OB_MOUSE_ACTION_CLICK
, "ToggleShade" },
485 { "Left", "TLCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
486 { "Left", "TRCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
487 { "Left", "BLCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
488 { "Left", "BRCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
489 { "Left", "Titlebar", OB_MOUSE_ACTION_MOTION
, "Move" },
490 { "A-Left", "Frame", OB_MOUSE_ACTION_MOTION
, "Move" },
491 { "A-Middle", "Frame", OB_MOUSE_ACTION_MOTION
, "Resize" },
492 { NULL
, NULL
, 0, NULL
}
495 for (it
= binds
; it
->button
; ++it
) {
498 case OB_MOUSE_ACTION_PRESS
:
499 uact
= OB_USER_ACTION_MOUSE_PRESS
; break;
500 case OB_MOUSE_ACTION_RELEASE
:
501 uact
= OB_USER_ACTION_MOUSE_RELEASE
; break;
502 case OB_MOUSE_ACTION_CLICK
:
503 uact
= OB_USER_ACTION_MOUSE_CLICK
; break;
504 case OB_MOUSE_ACTION_DOUBLE_CLICK
:
505 uact
= OB_USER_ACTION_MOUSE_DOUBLE_CLICK
; break;
506 case OB_MOUSE_ACTION_MOTION
:
507 uact
= OB_USER_ACTION_MOUSE_MOTION
; break;
508 case OB_NUM_MOUSE_ACTIONS
:
509 g_assert_not_reached();
511 mouse_bind(it
->button
, it
->context
, it
->mact
,
512 action_from_string(it
->actname
, uact
));
516 void config_startup(ObParseInst
*i
)
518 config_focus_new
= TRUE
;
519 config_focus_follow
= FALSE
;
520 config_focus_delay
= 0;
521 config_focus_raise
= FALSE
;
522 config_focus_last
= FALSE
;
524 parse_register(i
, "focus", parse_focus
, NULL
);
526 config_place_policy
= OB_PLACE_POLICY_SMART
;
528 parse_register(i
, "placement", parse_placement
, NULL
);
532 config_title_layout
= g_strdup("NLIMC");
534 parse_register(i
, "theme", parse_theme
, NULL
);
536 config_desktops_num
= 4;
537 config_screen_firstdesk
= 1;
538 config_desktops_names
= NULL
;
540 parse_register(i
, "desktops", parse_desktops
, NULL
);
542 config_resize_redraw
= TRUE
;
543 config_resize_popup_show
= 1;
545 parse_register(i
, "resize", parse_resize
, NULL
);
547 config_dock_layer
= OB_STACKING_LAYER_DOCK_ABOVE
;
548 config_dock_pos
= OB_DIRECTION_NORTHEAST
;
549 config_dock_floating
= FALSE
;
552 config_dock_orient
= OB_ORIENTATION_VERT
;
553 config_dock_hide
= FALSE
;
554 config_dock_hide_delay
= 300;
555 config_dock_app_move_button
= 2; /* middle */
556 config_dock_app_move_modifiers
= 0;
558 parse_register(i
, "dock", parse_dock
, NULL
);
560 translate_key("C-g", &config_keyboard_reset_state
,
561 &config_keyboard_reset_keycode
);
563 bind_default_keyboard();
565 parse_register(i
, "keyboard", parse_keyboard
, NULL
);
567 config_mouse_threshold
= 3;
568 config_mouse_dclicktime
= 200;
570 bind_default_mouse();
572 parse_register(i
, "mouse", parse_mouse
, NULL
);
574 config_resist_win
= 10;
575 config_resist_edge
= 20;
577 parse_register(i
, "resistance", parse_resistance
, NULL
);
579 config_menu_warppointer
= TRUE
;
580 config_menu_xorstyle
= TRUE
;
581 config_menu_hilightfirst
= TRUE
;
582 config_menu_hide_delay
= 250;
583 config_menu_files
= NULL
;
585 parse_register(i
, "menu", parse_menu
, NULL
);
588 void config_shutdown()
592 g_free(config_theme
);
594 g_free(config_title_layout
);
596 for (it
= config_desktops_names
; it
; it
= g_slist_next(it
))
598 g_slist_free(config_desktops_names
);
600 for (it
= config_menu_files
; it
; it
= g_slist_next(it
))
602 g_slist_free(config_menu_files
);