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
;
45 gint config_resize_popup_pos
;
47 ObStackingLayer config_dock_layer
;
48 gboolean config_dock_floating
;
49 ObDirection config_dock_pos
;
52 ObOrientation config_dock_orient
;
53 gboolean config_dock_hide
;
54 guint config_dock_hide_delay
;
55 guint config_dock_app_move_button
;
56 guint config_dock_app_move_modifiers
;
58 guint config_keyboard_reset_keycode
;
59 guint config_keyboard_reset_state
;
61 gint config_mouse_threshold
;
62 gint config_mouse_dclicktime
;
64 gboolean config_menu_warppointer
;
65 gboolean config_menu_xorstyle
;
66 gboolean config_menu_hilightfirst
;
67 guint config_menu_hide_delay
;
69 GSList
*config_menu_files
;
71 gint config_resist_win
;
72 gint config_resist_edge
;
77 <action name="ChangeDesktop">
84 static void parse_key(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
92 if ((n
= parse_find_node("chainQuitKey", node
))) {
93 key
= parse_string(doc
, n
);
94 translate_key(key
, &config_keyboard_reset_state
,
95 &config_keyboard_reset_keycode
);
99 n
= parse_find_node("keybind", node
);
101 if (parse_attr_string("key", n
, &key
)) {
102 keylist
= g_list_append(keylist
, key
);
104 parse_key(i
, doc
, n
->children
, keylist
);
106 it
= g_list_last(keylist
);
108 keylist
= g_list_delete_link(keylist
, it
);
110 n
= parse_find_node("keybind", n
->next
);
113 nact
= parse_find_node("action", node
);
115 if ((action
= action_parse(i
, doc
, nact
,
116 OB_USER_ACTION_KEYBOARD_KEY
)))
117 keyboard_bind(keylist
, action
);
118 nact
= parse_find_node("action", nact
->next
);
123 static void parse_keyboard(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
126 keyboard_unbind_all();
128 parse_key(i
, doc
, node
->children
, NULL
);
133 <context name="Titlebar">
134 <mousebind button="Left" action="Press">
135 <action name="Raise"></action>
141 static void parse_mouse(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
144 xmlNodePtr n
, nbut
, nact
;
153 node
= node
->children
;
155 if ((n
= parse_find_node("dragThreshold", node
)))
156 config_mouse_threshold
= parse_int(doc
, n
);
157 if ((n
= parse_find_node("doubleClickTime", node
)))
158 config_mouse_dclicktime
= parse_int(doc
, n
);
160 n
= parse_find_node("context", node
);
162 if (!parse_attr_string("name", n
, &contextstr
))
164 nbut
= parse_find_node("mousebind", n
->children
);
166 if (!parse_attr_string("button", nbut
, &buttonstr
))
168 if (parse_attr_contains("press", nbut
, "action")) {
169 uact
= OB_USER_ACTION_MOUSE_PRESS
;
170 mact
= OB_MOUSE_ACTION_PRESS
;
171 } else if (parse_attr_contains("release", nbut
, "action")) {
172 uact
= OB_USER_ACTION_MOUSE_RELEASE
;
173 mact
= OB_MOUSE_ACTION_RELEASE
;
174 } else if (parse_attr_contains("click", nbut
, "action")) {
175 uact
= OB_USER_ACTION_MOUSE_CLICK
;
176 mact
= OB_MOUSE_ACTION_CLICK
;
177 } else if (parse_attr_contains("doubleclick", nbut
,"action")) {
178 uact
= OB_USER_ACTION_MOUSE_DOUBLE_CLICK
;
179 mact
= OB_MOUSE_ACTION_DOUBLE_CLICK
;
180 } else if (parse_attr_contains("drag", nbut
, "action")) {
181 uact
= OB_USER_ACTION_MOUSE_MOTION
;
182 mact
= OB_MOUSE_ACTION_MOTION
;
185 nact
= parse_find_node("action", nbut
->children
);
187 if ((action
= action_parse(i
, doc
, nact
, uact
)))
188 mouse_bind(buttonstr
, contextstr
, mact
, action
);
189 nact
= parse_find_node("action", nact
->next
);
193 nbut
= parse_find_node("mousebind", nbut
->next
);
197 n
= parse_find_node("context", n
->next
);
201 static void parse_focus(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
206 node
= node
->children
;
208 if ((n
= parse_find_node("focusNew", node
)))
209 config_focus_new
= parse_bool(doc
, n
);
210 if ((n
= parse_find_node("followMouse", node
)))
211 config_focus_follow
= parse_bool(doc
, n
);
212 if ((n
= parse_find_node("focusDelay", node
)))
213 config_focus_delay
= parse_int(doc
, n
) * 1000;
214 if ((n
= parse_find_node("raiseOnFocus", node
)))
215 config_focus_raise
= parse_bool(doc
, n
);
216 if ((n
= parse_find_node("focusLast", node
)))
217 config_focus_last
= parse_bool(doc
, n
);
220 static void parse_placement(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
225 node
= node
->children
;
227 if ((n
= parse_find_node("policy", node
)))
228 if (parse_contains("UnderMouse", doc
, n
))
229 config_place_policy
= OB_PLACE_POLICY_MOUSE
;
232 static void parse_theme(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
237 node
= node
->children
;
239 if ((n
= parse_find_node("name", node
))) {
242 g_free(config_theme
);
243 c
= parse_string(doc
, n
);
244 config_theme
= parse_expand_tilde(c
);
247 if ((n
= parse_find_node("titleLayout", node
))) {
248 g_free(config_title_layout
);
249 config_title_layout
= parse_string(doc
, n
);
253 static void parse_desktops(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
258 node
= node
->children
;
260 if ((n
= parse_find_node("number", node
))) {
261 gint d
= parse_int(doc
, n
);
263 config_desktops_num
= d
;
265 if ((n
= parse_find_node("firstdesk", node
))) {
266 gint d
= parse_int(doc
, n
);
268 config_screen_firstdesk
= d
;
270 if ((n
= parse_find_node("names", node
))) {
274 for (it
= config_desktops_names
; it
; it
= it
->next
)
276 g_slist_free(config_desktops_names
);
277 config_desktops_names
= NULL
;
279 nname
= parse_find_node("name", n
->children
);
281 config_desktops_names
= g_slist_append(config_desktops_names
,
282 parse_string(doc
, nname
));
283 nname
= parse_find_node("name", nname
->next
);
288 static void parse_resize(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
293 node
= node
->children
;
295 if ((n
= parse_find_node("drawContents", node
)))
296 config_resize_redraw
= parse_bool(doc
, n
);
297 if ((n
= parse_find_node("popupShow", node
))) {
298 if (parse_contains("Always", doc
, n
))
299 config_resize_popup_show
= 2;
300 else if (parse_contains("Never", doc
, n
))
301 config_resize_popup_show
= 0;
302 else if (parse_contains("Nonpixel", doc
, n
))
303 config_resize_popup_show
= 1;
305 if ((n
= parse_find_node("popupPosition", node
))) {
306 if (parse_contains("Top", doc
, n
))
307 config_resize_popup_pos
= 1;
308 else if (parse_contains("Center", doc
, n
))
309 config_resize_popup_pos
= 0;
313 static void parse_dock(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
318 node
= node
->children
;
320 if ((n
= parse_find_node("position", node
))) {
321 if (parse_contains("TopLeft", doc
, n
))
322 config_dock_floating
= FALSE
,
323 config_dock_pos
= OB_DIRECTION_NORTHWEST
;
324 else if (parse_contains("Top", doc
, n
))
325 config_dock_floating
= FALSE
,
326 config_dock_pos
= OB_DIRECTION_NORTH
;
327 else if (parse_contains("TopRight", doc
, n
))
328 config_dock_floating
= FALSE
,
329 config_dock_pos
= OB_DIRECTION_NORTHEAST
;
330 else if (parse_contains("Right", doc
, n
))
331 config_dock_floating
= FALSE
,
332 config_dock_pos
= OB_DIRECTION_EAST
;
333 else if (parse_contains("BottomRight", doc
, n
))
334 config_dock_floating
= FALSE
,
335 config_dock_pos
= OB_DIRECTION_SOUTHEAST
;
336 else if (parse_contains("Bottom", doc
, n
))
337 config_dock_floating
= FALSE
,
338 config_dock_pos
= OB_DIRECTION_SOUTH
;
339 else if (parse_contains("BottomLeft", doc
, n
))
340 config_dock_floating
= FALSE
,
341 config_dock_pos
= OB_DIRECTION_SOUTHWEST
;
342 else if (parse_contains("Left", doc
, n
))
343 config_dock_floating
= FALSE
,
344 config_dock_pos
= OB_DIRECTION_WEST
;
345 else if (parse_contains("Floating", doc
, n
))
346 config_dock_floating
= TRUE
;
348 if (config_dock_floating
) {
349 if ((n
= parse_find_node("floatingX", node
)))
350 config_dock_x
= parse_int(doc
, n
);
351 if ((n
= parse_find_node("floatingY", node
)))
352 config_dock_y
= parse_int(doc
, n
);
354 if ((n
= parse_find_node("stacking", node
))) {
355 if (parse_contains("top", doc
, n
))
356 config_dock_layer
= OB_STACKING_LAYER_DOCK_ABOVE
;
357 else if (parse_contains("normal", doc
, n
))
358 config_dock_layer
= OB_STACKING_LAYER_DOCK_NORMAL
;
359 else if (parse_contains("bottom", doc
, n
))
360 config_dock_layer
= OB_STACKING_LAYER_DOCK_BELOW
;
362 if ((n
= parse_find_node("direction", node
))) {
363 if (parse_contains("horizontal", doc
, n
))
364 config_dock_orient
= OB_ORIENTATION_HORZ
;
365 else if (parse_contains("vertical", doc
, n
))
366 config_dock_orient
= OB_ORIENTATION_VERT
;
368 if ((n
= parse_find_node("autoHide", node
)))
369 config_dock_hide
= parse_bool(doc
, n
);
370 if ((n
= parse_find_node("hideDelay", node
)))
371 config_dock_hide_delay
= parse_int(doc
, n
) * 1000;
372 if ((n
= parse_find_node("moveButton", node
))) {
373 gchar
*str
= parse_string(doc
, n
);
375 if (translate_button(str
, &s
, &b
)) {
376 config_dock_app_move_button
= b
;
377 config_dock_app_move_modifiers
= s
;
379 g_warning("invalid button '%s'", str
);
385 static void parse_menu(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
388 for (node
= node
->children
; node
; node
= node
->next
) {
389 if (!xmlStrcasecmp(node
->name
, (const xmlChar
*) "file")) {
392 c
= parse_string(doc
, node
);
393 config_menu_files
= g_slist_append(config_menu_files
,
394 parse_expand_tilde(c
));
397 if ((n
= parse_find_node("warpPointer", node
)))
398 config_menu_warppointer
= parse_bool(doc
, n
);
399 if ((n
= parse_find_node("xorStyle", node
)))
400 config_menu_xorstyle
= parse_bool(doc
, n
);
401 if ((n
= parse_find_node("hilightFirst", node
)))
402 config_menu_hilightfirst
= parse_bool(doc
, n
);
403 if ((n
= parse_find_node("hideDelay", node
)))
404 config_menu_hide_delay
= parse_int(doc
, n
);
408 static void parse_resistance(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
413 node
= node
->children
;
414 if ((n
= parse_find_node("strength", node
)))
415 config_resist_win
= parse_int(doc
, n
);
416 if ((n
= parse_find_node("screen_edge_strength", node
)))
417 config_resist_edge
= parse_int(doc
, n
);
423 const gchar
*actname
;
426 static void bind_default_keyboard()
429 ObDefKeyBind binds
[] = {
430 { "A-Tab", "NextWindow" },
431 { "S-A-Tab", "PreviousWindow" },
436 for (it
= binds
; it
->key
; ++it
) {
437 GList
*l
= g_list_append(NULL
, g_strdup(it
->key
));
438 keyboard_bind(l
, action_from_string(it
->actname
,
439 OB_USER_ACTION_KEYBOARD_KEY
));
446 const gchar
*context
;
447 const ObMouseAction mact
;
448 const gchar
*actname
;
451 static void bind_default_mouse()
454 ObDefMouseBind binds
[] = {
455 { "Left", "Client", OB_MOUSE_ACTION_PRESS
, "Focus" },
456 { "Middle", "Client", OB_MOUSE_ACTION_PRESS
, "Focus" },
457 { "Right", "Client", OB_MOUSE_ACTION_PRESS
, "Focus" },
458 { "Left", "Desktop", OB_MOUSE_ACTION_PRESS
, "Focus" },
459 { "Middle", "Desktop", OB_MOUSE_ACTION_PRESS
, "Focus" },
460 { "Right", "Desktop", OB_MOUSE_ACTION_PRESS
, "Focus" },
461 { "Left", "Titlebar", OB_MOUSE_ACTION_PRESS
, "Focus" },
462 { "Left", "Handle", OB_MOUSE_ACTION_PRESS
, "Focus" },
463 { "Left", "BLCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
464 { "Left", "BRCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
465 { "Left", "TLCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
466 { "Left", "TRCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
467 { "Left", "Close", OB_MOUSE_ACTION_PRESS
, "Focus" },
468 { "Left", "Maximize", OB_MOUSE_ACTION_PRESS
, "Focus" },
469 { "Left", "Iconify", OB_MOUSE_ACTION_PRESS
, "Focus" },
470 { "Left", "Icon", OB_MOUSE_ACTION_PRESS
, "Focus" },
471 { "Left", "AllDesktops", OB_MOUSE_ACTION_PRESS
, "Focus" },
472 { "Left", "Shade", OB_MOUSE_ACTION_PRESS
, "Focus" },
473 { "Left", "Client", OB_MOUSE_ACTION_CLICK
, "Raise" },
474 { "Left", "Titlebar", OB_MOUSE_ACTION_CLICK
, "Raise" },
475 { "Middle", "Titlebar", OB_MOUSE_ACTION_CLICK
, "Lower" },
476 { "Left", "Handle", OB_MOUSE_ACTION_CLICK
, "Raise" },
477 { "Left", "BLCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
478 { "Left", "BRCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
479 { "Left", "TLCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
480 { "Left", "TRCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
481 { "Left", "Close", OB_MOUSE_ACTION_CLICK
, "Raise" },
482 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK
, "Raise" },
483 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK
, "Raise" },
484 { "Left", "Icon", OB_MOUSE_ACTION_CLICK
, "Raise" },
485 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK
, "Raise" },
486 { "Left", "Shade", OB_MOUSE_ACTION_CLICK
, "Raise" },
487 { "Left", "Close", OB_MOUSE_ACTION_CLICK
, "Close" },
488 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK
, "ToggleMaximizeFull" },
489 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK
, "Iconify" },
490 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK
, "ToggleOmnipresent" },
491 { "Left", "Shade", OB_MOUSE_ACTION_CLICK
, "ToggleShade" },
492 { "Left", "TLCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
493 { "Left", "TRCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
494 { "Left", "BLCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
495 { "Left", "BRCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
496 { "Left", "Titlebar", OB_MOUSE_ACTION_MOTION
, "Move" },
497 { "A-Left", "Frame", OB_MOUSE_ACTION_MOTION
, "Move" },
498 { "A-Middle", "Frame", OB_MOUSE_ACTION_MOTION
, "Resize" },
499 { NULL
, NULL
, 0, NULL
}
502 for (it
= binds
; it
->button
; ++it
) {
505 case OB_MOUSE_ACTION_PRESS
:
506 uact
= OB_USER_ACTION_MOUSE_PRESS
; break;
507 case OB_MOUSE_ACTION_RELEASE
:
508 uact
= OB_USER_ACTION_MOUSE_RELEASE
; break;
509 case OB_MOUSE_ACTION_CLICK
:
510 uact
= OB_USER_ACTION_MOUSE_CLICK
; break;
511 case OB_MOUSE_ACTION_DOUBLE_CLICK
:
512 uact
= OB_USER_ACTION_MOUSE_DOUBLE_CLICK
; break;
513 case OB_MOUSE_ACTION_MOTION
:
514 uact
= OB_USER_ACTION_MOUSE_MOTION
; break;
515 case OB_NUM_MOUSE_ACTIONS
:
516 g_assert_not_reached();
518 mouse_bind(it
->button
, it
->context
, it
->mact
,
519 action_from_string(it
->actname
, uact
));
523 void config_startup(ObParseInst
*i
)
525 config_focus_new
= TRUE
;
526 config_focus_follow
= FALSE
;
527 config_focus_delay
= 0;
528 config_focus_raise
= FALSE
;
529 config_focus_last
= FALSE
;
531 parse_register(i
, "focus", parse_focus
, NULL
);
533 config_place_policy
= OB_PLACE_POLICY_SMART
;
535 parse_register(i
, "placement", parse_placement
, NULL
);
539 config_title_layout
= g_strdup("NLIMC");
541 parse_register(i
, "theme", parse_theme
, NULL
);
543 config_desktops_num
= 4;
544 config_screen_firstdesk
= 1;
545 config_desktops_names
= NULL
;
547 parse_register(i
, "desktops", parse_desktops
, NULL
);
549 config_resize_redraw
= TRUE
;
550 config_resize_popup_show
= 1; /* nonpixel increments */
551 config_resize_popup_pos
= 0; /* center of client */
553 parse_register(i
, "resize", parse_resize
, NULL
);
555 config_dock_layer
= OB_STACKING_LAYER_DOCK_ABOVE
;
556 config_dock_pos
= OB_DIRECTION_NORTHEAST
;
557 config_dock_floating
= FALSE
;
560 config_dock_orient
= OB_ORIENTATION_VERT
;
561 config_dock_hide
= FALSE
;
562 config_dock_hide_delay
= 300;
563 config_dock_app_move_button
= 2; /* middle */
564 config_dock_app_move_modifiers
= 0;
566 parse_register(i
, "dock", parse_dock
, NULL
);
568 translate_key("C-g", &config_keyboard_reset_state
,
569 &config_keyboard_reset_keycode
);
571 bind_default_keyboard();
573 parse_register(i
, "keyboard", parse_keyboard
, NULL
);
575 config_mouse_threshold
= 3;
576 config_mouse_dclicktime
= 200;
578 bind_default_mouse();
580 parse_register(i
, "mouse", parse_mouse
, NULL
);
582 config_resist_win
= 10;
583 config_resist_edge
= 20;
585 parse_register(i
, "resistance", parse_resistance
, NULL
);
587 config_menu_warppointer
= TRUE
;
588 config_menu_xorstyle
= FALSE
;
589 config_menu_hilightfirst
= TRUE
;
590 config_menu_hide_delay
= 250;
591 config_menu_files
= NULL
;
593 parse_register(i
, "menu", parse_menu
, NULL
);
596 void config_shutdown()
600 g_free(config_theme
);
602 g_free(config_title_layout
);
604 for (it
= config_desktops_names
; it
; it
= g_slist_next(it
))
606 g_slist_free(config_desktops_names
);
608 for (it
= config_menu_files
; it
; it
= g_slist_next(it
))
610 g_slist_free(config_menu_files
);