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
;
38 gboolean config_theme_hidedisabled
;
40 gchar
*config_title_layout
;
42 gint config_desktops_num
;
43 GSList
*config_desktops_names
;
44 gint config_screen_firstdesk
;
46 gboolean config_resize_redraw
;
47 gboolean config_resize_four_corners
;
48 gint config_resize_popup_show
;
49 gint config_resize_popup_pos
;
51 ObStackingLayer config_dock_layer
;
52 gboolean config_dock_floating
;
53 gboolean config_dock_nostrut
;
54 ObDirection config_dock_pos
;
57 ObOrientation config_dock_orient
;
58 gboolean config_dock_hide
;
59 guint config_dock_hide_delay
;
60 guint config_dock_app_move_button
;
61 guint config_dock_app_move_modifiers
;
63 guint config_keyboard_reset_keycode
;
64 guint config_keyboard_reset_state
;
66 gint config_mouse_threshold
;
67 gint config_mouse_dclicktime
;
69 gboolean config_menu_warppointer
;
70 gboolean config_menu_xorstyle
;
71 guint config_menu_hide_delay
;
72 gboolean config_menu_client_list_icons
;
74 GSList
*config_menu_files
;
76 gint config_resist_win
;
77 gint config_resist_edge
;
79 gboolean config_resist_layers_below
;
84 <action name="ChangeDesktop">
91 static void parse_key(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
99 if ((n
= parse_find_node("chainQuitKey", node
))) {
100 key
= parse_string(doc
, n
);
101 translate_key(key
, &config_keyboard_reset_state
,
102 &config_keyboard_reset_keycode
);
106 n
= parse_find_node("keybind", node
);
108 if (parse_attr_string("key", n
, &key
)) {
109 keylist
= g_list_append(keylist
, key
);
111 parse_key(i
, doc
, n
->children
, keylist
);
113 it
= g_list_last(keylist
);
115 keylist
= g_list_delete_link(keylist
, it
);
117 n
= parse_find_node("keybind", n
->next
);
120 nact
= parse_find_node("action", node
);
122 if ((action
= action_parse(i
, doc
, nact
,
123 OB_USER_ACTION_KEYBOARD_KEY
)))
124 keyboard_bind(keylist
, action
);
125 nact
= parse_find_node("action", nact
->next
);
130 static void parse_keyboard(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
133 keyboard_unbind_all();
135 parse_key(i
, doc
, node
->children
, NULL
);
140 <context name="Titlebar">
141 <mousebind button="Left" action="Press">
142 <action name="Raise"></action>
148 static void parse_mouse(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
151 xmlNodePtr n
, nbut
, nact
;
160 node
= node
->children
;
162 if ((n
= parse_find_node("dragThreshold", node
)))
163 config_mouse_threshold
= parse_int(doc
, n
);
164 if ((n
= parse_find_node("doubleClickTime", node
)))
165 config_mouse_dclicktime
= parse_int(doc
, n
);
167 n
= parse_find_node("context", node
);
169 if (!parse_attr_string("name", n
, &contextstr
))
171 nbut
= parse_find_node("mousebind", n
->children
);
173 if (!parse_attr_string("button", nbut
, &buttonstr
))
175 if (parse_attr_contains("press", nbut
, "action")) {
176 uact
= OB_USER_ACTION_MOUSE_PRESS
;
177 mact
= OB_MOUSE_ACTION_PRESS
;
178 } else if (parse_attr_contains("release", nbut
, "action")) {
179 uact
= OB_USER_ACTION_MOUSE_RELEASE
;
180 mact
= OB_MOUSE_ACTION_RELEASE
;
181 } else if (parse_attr_contains("click", nbut
, "action")) {
182 uact
= OB_USER_ACTION_MOUSE_CLICK
;
183 mact
= OB_MOUSE_ACTION_CLICK
;
184 } else if (parse_attr_contains("doubleclick", nbut
,"action")) {
185 uact
= OB_USER_ACTION_MOUSE_DOUBLE_CLICK
;
186 mact
= OB_MOUSE_ACTION_DOUBLE_CLICK
;
187 } else if (parse_attr_contains("drag", nbut
, "action")) {
188 uact
= OB_USER_ACTION_MOUSE_MOTION
;
189 mact
= OB_MOUSE_ACTION_MOTION
;
192 nact
= parse_find_node("action", nbut
->children
);
194 if ((action
= action_parse(i
, doc
, nact
, uact
)))
195 mouse_bind(buttonstr
, contextstr
, mact
, action
);
196 nact
= parse_find_node("action", nact
->next
);
200 nbut
= parse_find_node("mousebind", nbut
->next
);
204 n
= parse_find_node("context", n
->next
);
208 static void parse_focus(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
213 node
= node
->children
;
215 if ((n
= parse_find_node("focusNew", node
)))
216 config_focus_new
= parse_bool(doc
, n
);
217 if ((n
= parse_find_node("followMouse", node
)))
218 config_focus_follow
= parse_bool(doc
, n
);
219 if ((n
= parse_find_node("focusDelay", node
)))
220 config_focus_delay
= parse_int(doc
, n
) * 1000;
221 if ((n
= parse_find_node("raiseOnFocus", node
)))
222 config_focus_raise
= parse_bool(doc
, n
);
223 if ((n
= parse_find_node("focusLast", node
)))
224 config_focus_last
= parse_bool(doc
, n
);
227 static void parse_placement(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
232 node
= node
->children
;
234 if ((n
= parse_find_node("policy", node
)))
235 if (parse_contains("UnderMouse", doc
, n
))
236 config_place_policy
= OB_PLACE_POLICY_MOUSE
;
239 static void parse_theme(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
244 node
= node
->children
;
246 if ((n
= parse_find_node("name", node
))) {
249 g_free(config_theme
);
250 c
= parse_string(doc
, n
);
251 config_theme
= parse_expand_tilde(c
);
254 if ((n
= parse_find_node("titleLayout", node
))) {
255 g_free(config_title_layout
);
256 config_title_layout
= parse_string(doc
, n
);
258 if ((n
= parse_find_node("keepBorder", node
)))
259 config_theme_keepborder
= parse_bool(doc
, n
);
260 if ((n
= parse_find_node("hideDisabled", node
)))
261 config_theme_hidedisabled
= parse_bool(doc
, n
);
264 static void parse_desktops(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
269 node
= node
->children
;
271 if ((n
= parse_find_node("number", node
))) {
272 gint d
= parse_int(doc
, n
);
274 config_desktops_num
= d
;
276 if ((n
= parse_find_node("firstdesk", node
))) {
277 gint d
= parse_int(doc
, n
);
279 config_screen_firstdesk
= d
;
281 if ((n
= parse_find_node("names", node
))) {
285 for (it
= config_desktops_names
; it
; it
= it
->next
)
287 g_slist_free(config_desktops_names
);
288 config_desktops_names
= NULL
;
290 nname
= parse_find_node("name", n
->children
);
292 config_desktops_names
= g_slist_append(config_desktops_names
,
293 parse_string(doc
, nname
));
294 nname
= parse_find_node("name", nname
->next
);
299 static void parse_resize(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
304 node
= node
->children
;
306 if ((n
= parse_find_node("drawContents", node
)))
307 config_resize_redraw
= parse_bool(doc
, n
);
308 if ((n
= parse_find_node("fourCorner", node
)))
309 config_resize_four_corners
= parse_bool(doc
, n
);
310 if ((n
= parse_find_node("popupShow", node
))) {
311 config_resize_popup_show
= parse_int(doc
, n
);
312 if (parse_contains("Always", doc
, n
))
313 config_resize_popup_show
= 2;
314 else if (parse_contains("Never", doc
, n
))
315 config_resize_popup_show
= 0;
316 else if (parse_contains("Nonpixel", doc
, n
))
317 config_resize_popup_show
= 1;
319 if ((n
= parse_find_node("popupPosition", node
))) {
320 config_resize_popup_pos
= parse_int(doc
, n
);
321 if (parse_contains("Top", doc
, n
))
322 config_resize_popup_pos
= 1;
323 else if (parse_contains("Center", doc
, n
))
324 config_resize_popup_pos
= 0;
328 static void parse_dock(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
333 node
= node
->children
;
335 if ((n
= parse_find_node("position", node
))) {
336 if (parse_contains("TopLeft", doc
, n
))
337 config_dock_floating
= FALSE
,
338 config_dock_pos
= OB_DIRECTION_NORTHWEST
;
339 else if (parse_contains("Top", doc
, n
))
340 config_dock_floating
= FALSE
,
341 config_dock_pos
= OB_DIRECTION_NORTH
;
342 else if (parse_contains("TopRight", doc
, n
))
343 config_dock_floating
= FALSE
,
344 config_dock_pos
= OB_DIRECTION_NORTHEAST
;
345 else if (parse_contains("Right", doc
, n
))
346 config_dock_floating
= FALSE
,
347 config_dock_pos
= OB_DIRECTION_EAST
;
348 else if (parse_contains("BottomRight", doc
, n
))
349 config_dock_floating
= FALSE
,
350 config_dock_pos
= OB_DIRECTION_SOUTHEAST
;
351 else if (parse_contains("Bottom", doc
, n
))
352 config_dock_floating
= FALSE
,
353 config_dock_pos
= OB_DIRECTION_SOUTH
;
354 else if (parse_contains("BottomLeft", doc
, n
))
355 config_dock_floating
= FALSE
,
356 config_dock_pos
= OB_DIRECTION_SOUTHWEST
;
357 else if (parse_contains("Left", doc
, n
))
358 config_dock_floating
= FALSE
,
359 config_dock_pos
= OB_DIRECTION_WEST
;
360 else if (parse_contains("Floating", doc
, n
))
361 config_dock_floating
= TRUE
;
363 if (config_dock_floating
) {
364 if ((n
= parse_find_node("floatingX", node
)))
365 config_dock_x
= parse_int(doc
, n
);
366 if ((n
= parse_find_node("floatingY", node
)))
367 config_dock_y
= parse_int(doc
, n
);
369 if ((n
= parse_find_node("noStrut", node
)))
370 config_dock_nostrut
= parse_bool(doc
, n
);
372 if ((n
= parse_find_node("stacking", node
))) {
373 if (parse_contains("top", doc
, n
))
374 config_dock_layer
= OB_STACKING_LAYER_ABOVE
;
375 else if (parse_contains("normal", doc
, n
))
376 config_dock_layer
= OB_STACKING_LAYER_NORMAL
;
377 else if (parse_contains("bottom", doc
, n
))
378 config_dock_layer
= OB_STACKING_LAYER_BELOW
;
380 if ((n
= parse_find_node("direction", node
))) {
381 if (parse_contains("horizontal", doc
, n
))
382 config_dock_orient
= OB_ORIENTATION_HORZ
;
383 else if (parse_contains("vertical", doc
, n
))
384 config_dock_orient
= OB_ORIENTATION_VERT
;
386 if ((n
= parse_find_node("autoHide", node
)))
387 config_dock_hide
= parse_bool(doc
, n
);
388 if ((n
= parse_find_node("hideDelay", node
)))
389 config_dock_hide_delay
= parse_int(doc
, n
) * 1000;
390 if ((n
= parse_find_node("moveButton", node
))) {
391 gchar
*str
= parse_string(doc
, n
);
393 if (translate_button(str
, &s
, &b
)) {
394 config_dock_app_move_button
= b
;
395 config_dock_app_move_modifiers
= s
;
397 g_warning("invalid button '%s'", str
);
403 static void parse_menu(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
407 for (node
= node
->children
; node
; node
= node
->next
) {
408 if (!xmlStrcasecmp(node
->name
, (const xmlChar
*) "file")) {
411 c
= parse_string(doc
, node
);
412 config_menu_files
= g_slist_append(config_menu_files
,
413 parse_expand_tilde(c
));
416 if ((n
= parse_find_node("warpPointer", node
)))
417 config_menu_warppointer
= parse_bool(doc
, n
);
418 if ((n
= parse_find_node("xorStyle", node
)))
419 config_menu_xorstyle
= parse_bool(doc
, n
);
420 if ((n
= parse_find_node("hideDelay", node
)))
421 config_menu_hide_delay
= parse_int(doc
, n
);
422 if ((n
= parse_find_node("desktopMenuIcons", node
)))
423 config_menu_client_list_icons
= parse_bool(doc
, n
);
427 static void parse_resistance(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
432 node
= node
->children
;
433 if ((n
= parse_find_node("strength", node
)))
434 config_resist_win
= parse_int(doc
, n
);
435 if ((n
= parse_find_node("screen_edge_strength", node
)))
436 config_resist_edge
= parse_int(doc
, n
);
437 if ((n
= parse_find_node("edges_hit_layers_below", node
)))
438 config_resist_layers_below
= parse_bool(doc
, n
);
444 const gchar
*actname
;
447 static void bind_default_keyboard()
450 ObDefKeyBind binds
[] = {
451 { "A-Tab", "NextWindow" },
452 { "S-A-Tab", "PreviousWindow" },
457 for (it
= binds
; it
->key
; ++it
) {
458 GList
*l
= g_list_append(NULL
, g_strdup(it
->key
));
459 keyboard_bind(l
, action_from_string(it
->actname
,
460 OB_USER_ACTION_KEYBOARD_KEY
));
467 const gchar
*context
;
468 const ObMouseAction mact
;
469 const gchar
*actname
;
472 static void bind_default_mouse()
475 ObDefMouseBind binds
[] = {
476 { "Left", "Client", OB_MOUSE_ACTION_PRESS
, "Focus" },
477 { "Middle", "Client", OB_MOUSE_ACTION_PRESS
, "Focus" },
478 { "Right", "Client", OB_MOUSE_ACTION_PRESS
, "Focus" },
479 { "Left", "Desktop", OB_MOUSE_ACTION_PRESS
, "Focus" },
480 { "Middle", "Desktop", OB_MOUSE_ACTION_PRESS
, "Focus" },
481 { "Right", "Desktop", OB_MOUSE_ACTION_PRESS
, "Focus" },
482 { "Left", "Titlebar", OB_MOUSE_ACTION_PRESS
, "Focus" },
483 { "Left", "Handle", OB_MOUSE_ACTION_PRESS
, "Focus" },
484 { "Left", "BLCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
485 { "Left", "BRCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
486 { "Left", "TLCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
487 { "Left", "TRCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
488 { "Left", "Close", OB_MOUSE_ACTION_PRESS
, "Focus" },
489 { "Left", "Maximize", OB_MOUSE_ACTION_PRESS
, "Focus" },
490 { "Left", "Iconify", OB_MOUSE_ACTION_PRESS
, "Focus" },
491 { "Left", "Icon", OB_MOUSE_ACTION_PRESS
, "Focus" },
492 { "Left", "AllDesktops", OB_MOUSE_ACTION_PRESS
, "Focus" },
493 { "Left", "Shade", OB_MOUSE_ACTION_PRESS
, "Focus" },
494 { "Left", "Client", OB_MOUSE_ACTION_CLICK
, "Raise" },
495 { "Left", "Titlebar", OB_MOUSE_ACTION_CLICK
, "Raise" },
496 { "Middle", "Titlebar", OB_MOUSE_ACTION_CLICK
, "Lower" },
497 { "Left", "Handle", OB_MOUSE_ACTION_CLICK
, "Raise" },
498 { "Left", "BLCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
499 { "Left", "BRCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
500 { "Left", "TLCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
501 { "Left", "TRCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
502 { "Left", "Close", OB_MOUSE_ACTION_CLICK
, "Raise" },
503 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK
, "Raise" },
504 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK
, "Raise" },
505 { "Left", "Icon", OB_MOUSE_ACTION_CLICK
, "Raise" },
506 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK
, "Raise" },
507 { "Left", "Shade", OB_MOUSE_ACTION_CLICK
, "Raise" },
508 { "Left", "Close", OB_MOUSE_ACTION_CLICK
, "Close" },
509 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK
, "ToggleMaximizeFull" },
510 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK
, "Iconify" },
511 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK
, "ToggleOmnipresent" },
512 { "Left", "Shade", OB_MOUSE_ACTION_CLICK
, "ToggleShade" },
513 { "Left", "TLCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
514 { "Left", "TRCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
515 { "Left", "BLCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
516 { "Left", "BRCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
517 { "Left", "Titlebar", OB_MOUSE_ACTION_MOTION
, "Move" },
518 { "A-Left", "Frame", OB_MOUSE_ACTION_MOTION
, "Move" },
519 { "A-Middle", "Frame", OB_MOUSE_ACTION_MOTION
, "Resize" },
520 { NULL
, NULL
, 0, NULL
}
523 for (it
= binds
; it
->button
; ++it
) {
526 case OB_MOUSE_ACTION_PRESS
:
527 uact
= OB_USER_ACTION_MOUSE_PRESS
; break;
528 case OB_MOUSE_ACTION_RELEASE
:
529 uact
= OB_USER_ACTION_MOUSE_RELEASE
; break;
530 case OB_MOUSE_ACTION_CLICK
:
531 uact
= OB_USER_ACTION_MOUSE_CLICK
; break;
532 case OB_MOUSE_ACTION_DOUBLE_CLICK
:
533 uact
= OB_USER_ACTION_MOUSE_DOUBLE_CLICK
; break;
534 case OB_MOUSE_ACTION_MOTION
:
535 uact
= OB_USER_ACTION_MOUSE_MOTION
; break;
536 case OB_NUM_MOUSE_ACTIONS
:
537 g_assert_not_reached();
539 mouse_bind(it
->button
, it
->context
, it
->mact
,
540 action_from_string(it
->actname
, uact
));
544 void config_startup(ObParseInst
*i
)
546 config_focus_new
= TRUE
;
547 config_focus_follow
= FALSE
;
548 config_focus_delay
= 0;
549 config_focus_raise
= FALSE
;
550 config_focus_last
= FALSE
;
552 parse_register(i
, "focus", parse_focus
, NULL
);
554 config_place_policy
= OB_PLACE_POLICY_SMART
;
556 parse_register(i
, "placement", parse_placement
, NULL
);
560 config_title_layout
= g_strdup("NLIMC");
561 config_theme_keepborder
= TRUE
;
562 config_theme_hidedisabled
= FALSE
;
564 parse_register(i
, "theme", parse_theme
, NULL
);
566 config_desktops_num
= 4;
567 config_screen_firstdesk
= 1;
568 config_desktops_names
= NULL
;
570 parse_register(i
, "desktops", parse_desktops
, NULL
);
572 config_resize_redraw
= TRUE
;
573 config_resize_four_corners
= FALSE
;
574 config_resize_popup_show
= 1; /* nonpixel increments */
575 config_resize_popup_pos
= 0; /* center of client */
577 parse_register(i
, "resize", parse_resize
, NULL
);
579 config_dock_layer
= OB_STACKING_LAYER_ABOVE
;
580 config_dock_pos
= OB_DIRECTION_NORTHEAST
;
581 config_dock_floating
= FALSE
;
582 config_dock_nostrut
= FALSE
;
585 config_dock_orient
= OB_ORIENTATION_VERT
;
586 config_dock_hide
= FALSE
;
587 config_dock_hide_delay
= 300;
588 config_dock_app_move_button
= 2; /* middle */
589 config_dock_app_move_modifiers
= 0;
591 parse_register(i
, "dock", parse_dock
, NULL
);
593 translate_key("C-g", &config_keyboard_reset_state
,
594 &config_keyboard_reset_keycode
);
596 bind_default_keyboard();
598 parse_register(i
, "keyboard", parse_keyboard
, NULL
);
600 config_mouse_threshold
= 3;
601 config_mouse_dclicktime
= 200;
603 bind_default_mouse();
605 parse_register(i
, "mouse", parse_mouse
, NULL
);
607 config_resist_win
= 10;
608 config_resist_edge
= 20;
609 config_resist_layers_below
= FALSE
;
611 parse_register(i
, "resistance", parse_resistance
, NULL
);
613 config_menu_warppointer
= TRUE
;
614 config_menu_xorstyle
= TRUE
;
615 config_menu_hide_delay
= 250;
616 config_menu_client_list_icons
= TRUE
;
617 config_menu_files
= NULL
;
619 parse_register(i
, "menu", parse_menu
, NULL
);
622 void config_shutdown()
626 g_free(config_theme
);
628 g_free(config_title_layout
);
630 for (it
= config_desktops_names
; it
; it
= g_slist_next(it
))
632 g_slist_free(config_desktops_names
);
634 for (it
= config_menu_files
; it
; it
= g_slist_next(it
))
636 g_slist_free(config_menu_files
);