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
;
39 gchar
*config_title_layout
;
41 gint config_desktops_num
;
42 GSList
*config_desktops_names
;
43 gint config_screen_firstdesk
;
45 gboolean config_resize_redraw
;
46 gboolean config_resize_four_corners
;
47 gint config_resize_popup_show
;
48 gint config_resize_popup_pos
;
50 ObStackingLayer config_dock_layer
;
51 gboolean config_dock_floating
;
52 gboolean config_dock_nostrut
;
53 ObDirection config_dock_pos
;
56 ObOrientation config_dock_orient
;
57 gboolean config_dock_hide
;
58 guint config_dock_hide_delay
;
59 guint config_dock_app_move_button
;
60 guint config_dock_app_move_modifiers
;
62 guint config_keyboard_reset_keycode
;
63 guint config_keyboard_reset_state
;
65 gint config_mouse_threshold
;
66 gint config_mouse_dclicktime
;
68 gboolean config_menu_warppointer
;
69 gboolean config_menu_xorstyle
;
70 guint config_menu_hide_delay
;
71 gboolean config_menu_client_list_icons
;
73 GSList
*config_menu_files
;
75 gint config_resist_win
;
76 gint config_resist_edge
;
78 gboolean config_resist_layers_below
;
83 <action name="ChangeDesktop">
90 static void parse_key(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
98 if ((n
= parse_find_node("chainQuitKey", node
))) {
99 key
= parse_string(doc
, n
);
100 translate_key(key
, &config_keyboard_reset_state
,
101 &config_keyboard_reset_keycode
);
105 n
= parse_find_node("keybind", node
);
107 if (parse_attr_string("key", n
, &key
)) {
108 keylist
= g_list_append(keylist
, key
);
110 parse_key(i
, doc
, n
->children
, keylist
);
112 it
= g_list_last(keylist
);
114 keylist
= g_list_delete_link(keylist
, it
);
116 n
= parse_find_node("keybind", n
->next
);
119 nact
= parse_find_node("action", node
);
121 if ((action
= action_parse(i
, doc
, nact
,
122 OB_USER_ACTION_KEYBOARD_KEY
)))
123 keyboard_bind(keylist
, action
);
124 nact
= parse_find_node("action", nact
->next
);
129 static void parse_keyboard(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
132 keyboard_unbind_all();
134 parse_key(i
, doc
, node
->children
, NULL
);
139 <context name="Titlebar">
140 <mousebind button="Left" action="Press">
141 <action name="Raise"></action>
147 static void parse_mouse(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
150 xmlNodePtr n
, nbut
, nact
;
159 node
= node
->children
;
161 if ((n
= parse_find_node("dragThreshold", node
)))
162 config_mouse_threshold
= parse_int(doc
, n
);
163 if ((n
= parse_find_node("doubleClickTime", node
)))
164 config_mouse_dclicktime
= parse_int(doc
, n
);
166 n
= parse_find_node("context", node
);
168 if (!parse_attr_string("name", n
, &contextstr
))
170 nbut
= parse_find_node("mousebind", n
->children
);
172 if (!parse_attr_string("button", nbut
, &buttonstr
))
174 if (parse_attr_contains("press", nbut
, "action")) {
175 uact
= OB_USER_ACTION_MOUSE_PRESS
;
176 mact
= OB_MOUSE_ACTION_PRESS
;
177 } else if (parse_attr_contains("release", nbut
, "action")) {
178 uact
= OB_USER_ACTION_MOUSE_RELEASE
;
179 mact
= OB_MOUSE_ACTION_RELEASE
;
180 } else if (parse_attr_contains("click", nbut
, "action")) {
181 uact
= OB_USER_ACTION_MOUSE_CLICK
;
182 mact
= OB_MOUSE_ACTION_CLICK
;
183 } else if (parse_attr_contains("doubleclick", nbut
,"action")) {
184 uact
= OB_USER_ACTION_MOUSE_DOUBLE_CLICK
;
185 mact
= OB_MOUSE_ACTION_DOUBLE_CLICK
;
186 } else if (parse_attr_contains("drag", nbut
, "action")) {
187 uact
= OB_USER_ACTION_MOUSE_MOTION
;
188 mact
= OB_MOUSE_ACTION_MOTION
;
191 nact
= parse_find_node("action", nbut
->children
);
193 if ((action
= action_parse(i
, doc
, nact
, uact
)))
194 mouse_bind(buttonstr
, contextstr
, mact
, action
);
195 nact
= parse_find_node("action", nact
->next
);
199 nbut
= parse_find_node("mousebind", nbut
->next
);
203 n
= parse_find_node("context", n
->next
);
207 static void parse_focus(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
212 node
= node
->children
;
214 if ((n
= parse_find_node("focusNew", node
)))
215 config_focus_new
= parse_bool(doc
, n
);
216 if ((n
= parse_find_node("followMouse", node
)))
217 config_focus_follow
= parse_bool(doc
, n
);
218 if ((n
= parse_find_node("focusDelay", node
)))
219 config_focus_delay
= parse_int(doc
, n
) * 1000;
220 if ((n
= parse_find_node("raiseOnFocus", node
)))
221 config_focus_raise
= parse_bool(doc
, n
);
222 if ((n
= parse_find_node("focusLast", node
)))
223 config_focus_last
= parse_bool(doc
, n
);
226 static void parse_placement(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
231 node
= node
->children
;
233 if ((n
= parse_find_node("policy", node
)))
234 if (parse_contains("UnderMouse", doc
, n
))
235 config_place_policy
= OB_PLACE_POLICY_MOUSE
;
238 static void parse_theme(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
243 node
= node
->children
;
245 if ((n
= parse_find_node("name", node
))) {
248 g_free(config_theme
);
249 c
= parse_string(doc
, n
);
250 config_theme
= parse_expand_tilde(c
);
253 if ((n
= parse_find_node("titleLayout", node
))) {
254 g_free(config_title_layout
);
255 config_title_layout
= parse_string(doc
, n
);
257 if ((n
= parse_find_node("keepBorder", node
)))
258 config_theme_keepborder
= parse_bool(doc
, n
);
261 static void parse_desktops(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
266 node
= node
->children
;
268 if ((n
= parse_find_node("number", node
))) {
269 gint d
= parse_int(doc
, n
);
271 config_desktops_num
= d
;
273 if ((n
= parse_find_node("firstdesk", node
))) {
274 gint d
= parse_int(doc
, n
);
276 config_screen_firstdesk
= d
;
278 if ((n
= parse_find_node("names", node
))) {
282 for (it
= config_desktops_names
; it
; it
= it
->next
)
284 g_slist_free(config_desktops_names
);
285 config_desktops_names
= NULL
;
287 nname
= parse_find_node("name", n
->children
);
289 config_desktops_names
= g_slist_append(config_desktops_names
,
290 parse_string(doc
, nname
));
291 nname
= parse_find_node("name", nname
->next
);
296 static void parse_resize(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
301 node
= node
->children
;
303 if ((n
= parse_find_node("drawContents", node
)))
304 config_resize_redraw
= parse_bool(doc
, n
);
305 if ((n
= parse_find_node("fourCorner", node
)))
306 config_resize_four_corners
= parse_bool(doc
, n
);
307 if ((n
= parse_find_node("popupShow", node
))) {
308 config_resize_popup_show
= parse_int(doc
, n
);
309 if (parse_contains("Always", doc
, n
))
310 config_resize_popup_show
= 2;
311 else if (parse_contains("Never", doc
, n
))
312 config_resize_popup_show
= 0;
313 else if (parse_contains("Nonpixel", doc
, n
))
314 config_resize_popup_show
= 1;
316 if ((n
= parse_find_node("popupPosition", node
))) {
317 config_resize_popup_pos
= parse_int(doc
, n
);
318 if (parse_contains("Top", doc
, n
))
319 config_resize_popup_pos
= 1;
320 else if (parse_contains("Center", doc
, n
))
321 config_resize_popup_pos
= 0;
325 static void parse_dock(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
330 node
= node
->children
;
332 if ((n
= parse_find_node("position", node
))) {
333 if (parse_contains("TopLeft", doc
, n
))
334 config_dock_floating
= FALSE
,
335 config_dock_pos
= OB_DIRECTION_NORTHWEST
;
336 else if (parse_contains("Top", doc
, n
))
337 config_dock_floating
= FALSE
,
338 config_dock_pos
= OB_DIRECTION_NORTH
;
339 else if (parse_contains("TopRight", doc
, n
))
340 config_dock_floating
= FALSE
,
341 config_dock_pos
= OB_DIRECTION_NORTHEAST
;
342 else if (parse_contains("Right", doc
, n
))
343 config_dock_floating
= FALSE
,
344 config_dock_pos
= OB_DIRECTION_EAST
;
345 else if (parse_contains("BottomRight", doc
, n
))
346 config_dock_floating
= FALSE
,
347 config_dock_pos
= OB_DIRECTION_SOUTHEAST
;
348 else if (parse_contains("Bottom", doc
, n
))
349 config_dock_floating
= FALSE
,
350 config_dock_pos
= OB_DIRECTION_SOUTH
;
351 else if (parse_contains("BottomLeft", doc
, n
))
352 config_dock_floating
= FALSE
,
353 config_dock_pos
= OB_DIRECTION_SOUTHWEST
;
354 else if (parse_contains("Left", doc
, n
))
355 config_dock_floating
= FALSE
,
356 config_dock_pos
= OB_DIRECTION_WEST
;
357 else if (parse_contains("Floating", doc
, n
))
358 config_dock_floating
= TRUE
;
360 if (config_dock_floating
) {
361 if ((n
= parse_find_node("floatingX", node
)))
362 config_dock_x
= parse_int(doc
, n
);
363 if ((n
= parse_find_node("floatingY", node
)))
364 config_dock_y
= parse_int(doc
, n
);
366 if ((n
= parse_find_node("noStrut", node
)))
367 config_dock_nostrut
= parse_bool(doc
, n
);
369 if ((n
= parse_find_node("stacking", node
))) {
370 if (parse_contains("top", doc
, n
))
371 config_dock_layer
= OB_STACKING_LAYER_ABOVE
;
372 else if (parse_contains("normal", doc
, n
))
373 config_dock_layer
= OB_STACKING_LAYER_NORMAL
;
374 else if (parse_contains("bottom", doc
, n
))
375 config_dock_layer
= OB_STACKING_LAYER_BELOW
;
377 if ((n
= parse_find_node("direction", node
))) {
378 if (parse_contains("horizontal", doc
, n
))
379 config_dock_orient
= OB_ORIENTATION_HORZ
;
380 else if (parse_contains("vertical", doc
, n
))
381 config_dock_orient
= OB_ORIENTATION_VERT
;
383 if ((n
= parse_find_node("autoHide", node
)))
384 config_dock_hide
= parse_bool(doc
, n
);
385 if ((n
= parse_find_node("hideDelay", node
)))
386 config_dock_hide_delay
= parse_int(doc
, n
) * 1000;
387 if ((n
= parse_find_node("moveButton", node
))) {
388 gchar
*str
= parse_string(doc
, n
);
390 if (translate_button(str
, &s
, &b
)) {
391 config_dock_app_move_button
= b
;
392 config_dock_app_move_modifiers
= s
;
394 g_warning("invalid button '%s'", str
);
400 static void parse_menu(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
404 for (node
= node
->children
; node
; node
= node
->next
) {
405 if (!xmlStrcasecmp(node
->name
, (const xmlChar
*) "file")) {
408 c
= parse_string(doc
, node
);
409 config_menu_files
= g_slist_append(config_menu_files
,
410 parse_expand_tilde(c
));
413 if ((n
= parse_find_node("warpPointer", node
)))
414 config_menu_warppointer
= parse_bool(doc
, n
);
415 if ((n
= parse_find_node("xorStyle", node
)))
416 config_menu_xorstyle
= parse_bool(doc
, n
);
417 if ((n
= parse_find_node("hideDelay", node
)))
418 config_menu_hide_delay
= parse_int(doc
, n
);
419 if ((n
= parse_find_node("desktopMenuIcons", node
)))
420 config_menu_client_list_icons
= parse_bool(doc
, n
);
424 static void parse_resistance(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
429 node
= node
->children
;
430 if ((n
= parse_find_node("strength", node
)))
431 config_resist_win
= parse_int(doc
, n
);
432 if ((n
= parse_find_node("screen_edge_strength", node
)))
433 config_resist_edge
= parse_int(doc
, n
);
434 if ((n
= parse_find_node("edges_hit_layers_below", node
)))
435 config_resist_layers_below
= parse_bool(doc
, n
);
441 const gchar
*actname
;
444 static void bind_default_keyboard()
447 ObDefKeyBind binds
[] = {
448 { "A-Tab", "NextWindow" },
449 { "S-A-Tab", "PreviousWindow" },
454 for (it
= binds
; it
->key
; ++it
) {
455 GList
*l
= g_list_append(NULL
, g_strdup(it
->key
));
456 keyboard_bind(l
, action_from_string(it
->actname
,
457 OB_USER_ACTION_KEYBOARD_KEY
));
464 const gchar
*context
;
465 const ObMouseAction mact
;
466 const gchar
*actname
;
469 static void bind_default_mouse()
472 ObDefMouseBind binds
[] = {
473 { "Left", "Client", OB_MOUSE_ACTION_PRESS
, "Focus" },
474 { "Middle", "Client", OB_MOUSE_ACTION_PRESS
, "Focus" },
475 { "Right", "Client", OB_MOUSE_ACTION_PRESS
, "Focus" },
476 { "Left", "Desktop", OB_MOUSE_ACTION_PRESS
, "Focus" },
477 { "Middle", "Desktop", OB_MOUSE_ACTION_PRESS
, "Focus" },
478 { "Right", "Desktop", OB_MOUSE_ACTION_PRESS
, "Focus" },
479 { "Left", "Titlebar", OB_MOUSE_ACTION_PRESS
, "Focus" },
480 { "Left", "Handle", OB_MOUSE_ACTION_PRESS
, "Focus" },
481 { "Left", "BLCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
482 { "Left", "BRCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
483 { "Left", "TLCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
484 { "Left", "TRCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
485 { "Left", "Close", OB_MOUSE_ACTION_PRESS
, "Focus" },
486 { "Left", "Maximize", OB_MOUSE_ACTION_PRESS
, "Focus" },
487 { "Left", "Iconify", OB_MOUSE_ACTION_PRESS
, "Focus" },
488 { "Left", "Icon", OB_MOUSE_ACTION_PRESS
, "Focus" },
489 { "Left", "AllDesktops", OB_MOUSE_ACTION_PRESS
, "Focus" },
490 { "Left", "Shade", OB_MOUSE_ACTION_PRESS
, "Focus" },
491 { "Left", "Client", OB_MOUSE_ACTION_CLICK
, "Raise" },
492 { "Left", "Titlebar", OB_MOUSE_ACTION_CLICK
, "Raise" },
493 { "Middle", "Titlebar", OB_MOUSE_ACTION_CLICK
, "Lower" },
494 { "Left", "Handle", OB_MOUSE_ACTION_CLICK
, "Raise" },
495 { "Left", "BLCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
496 { "Left", "BRCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
497 { "Left", "TLCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
498 { "Left", "TRCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
499 { "Left", "Close", OB_MOUSE_ACTION_CLICK
, "Raise" },
500 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK
, "Raise" },
501 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK
, "Raise" },
502 { "Left", "Icon", OB_MOUSE_ACTION_CLICK
, "Raise" },
503 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK
, "Raise" },
504 { "Left", "Shade", OB_MOUSE_ACTION_CLICK
, "Raise" },
505 { "Left", "Close", OB_MOUSE_ACTION_CLICK
, "Close" },
506 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK
, "ToggleMaximizeFull" },
507 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK
, "Iconify" },
508 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK
, "ToggleOmnipresent" },
509 { "Left", "Shade", OB_MOUSE_ACTION_CLICK
, "ToggleShade" },
510 { "Left", "TLCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
511 { "Left", "TRCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
512 { "Left", "BLCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
513 { "Left", "BRCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
514 { "Left", "Titlebar", OB_MOUSE_ACTION_MOTION
, "Move" },
515 { "A-Left", "Frame", OB_MOUSE_ACTION_MOTION
, "Move" },
516 { "A-Middle", "Frame", OB_MOUSE_ACTION_MOTION
, "Resize" },
517 { NULL
, NULL
, 0, NULL
}
520 for (it
= binds
; it
->button
; ++it
) {
523 case OB_MOUSE_ACTION_PRESS
:
524 uact
= OB_USER_ACTION_MOUSE_PRESS
; break;
525 case OB_MOUSE_ACTION_RELEASE
:
526 uact
= OB_USER_ACTION_MOUSE_RELEASE
; break;
527 case OB_MOUSE_ACTION_CLICK
:
528 uact
= OB_USER_ACTION_MOUSE_CLICK
; break;
529 case OB_MOUSE_ACTION_DOUBLE_CLICK
:
530 uact
= OB_USER_ACTION_MOUSE_DOUBLE_CLICK
; break;
531 case OB_MOUSE_ACTION_MOTION
:
532 uact
= OB_USER_ACTION_MOUSE_MOTION
; break;
533 case OB_NUM_MOUSE_ACTIONS
:
534 g_assert_not_reached();
536 mouse_bind(it
->button
, it
->context
, it
->mact
,
537 action_from_string(it
->actname
, uact
));
541 void config_startup(ObParseInst
*i
)
543 config_focus_new
= TRUE
;
544 config_focus_follow
= FALSE
;
545 config_focus_delay
= 0;
546 config_focus_raise
= FALSE
;
547 config_focus_last
= FALSE
;
549 parse_register(i
, "focus", parse_focus
, NULL
);
551 config_place_policy
= OB_PLACE_POLICY_SMART
;
553 parse_register(i
, "placement", parse_placement
, NULL
);
557 config_title_layout
= g_strdup("NLIMC");
558 config_theme_keepborder
= TRUE
;
560 parse_register(i
, "theme", parse_theme
, NULL
);
562 config_desktops_num
= 4;
563 config_screen_firstdesk
= 1;
564 config_desktops_names
= NULL
;
566 parse_register(i
, "desktops", parse_desktops
, NULL
);
568 config_resize_redraw
= TRUE
;
569 config_resize_four_corners
= FALSE
;
570 config_resize_popup_show
= 1; /* nonpixel increments */
571 config_resize_popup_pos
= 0; /* center of client */
573 parse_register(i
, "resize", parse_resize
, NULL
);
575 config_dock_layer
= OB_STACKING_LAYER_ABOVE
;
576 config_dock_pos
= OB_DIRECTION_NORTHEAST
;
577 config_dock_floating
= FALSE
;
578 config_dock_nostrut
= FALSE
;
581 config_dock_orient
= OB_ORIENTATION_VERT
;
582 config_dock_hide
= FALSE
;
583 config_dock_hide_delay
= 300;
584 config_dock_app_move_button
= 2; /* middle */
585 config_dock_app_move_modifiers
= 0;
587 parse_register(i
, "dock", parse_dock
, NULL
);
589 translate_key("C-g", &config_keyboard_reset_state
,
590 &config_keyboard_reset_keycode
);
592 bind_default_keyboard();
594 parse_register(i
, "keyboard", parse_keyboard
, NULL
);
596 config_mouse_threshold
= 3;
597 config_mouse_dclicktime
= 200;
599 bind_default_mouse();
601 parse_register(i
, "mouse", parse_mouse
, NULL
);
603 config_resist_win
= 10;
604 config_resist_edge
= 20;
605 config_resist_layers_below
= FALSE
;
607 parse_register(i
, "resistance", parse_resistance
, NULL
);
609 config_menu_warppointer
= TRUE
;
610 config_menu_xorstyle
= TRUE
;
611 config_menu_hide_delay
= 250;
612 config_menu_client_list_icons
= TRUE
;
613 config_menu_files
= NULL
;
615 parse_register(i
, "menu", parse_menu
, NULL
);
618 void config_shutdown()
622 g_free(config_theme
);
624 g_free(config_title_layout
);
626 for (it
= config_desktops_names
; it
; it
= g_slist_next(it
))
628 g_slist_free(config_desktops_names
);
630 for (it
= config_menu_files
; it
; it
= g_slist_next(it
))
632 g_slist_free(config_menu_files
);