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
;
32 ObPlacePolicy config_place_policy
;
36 gchar
*config_title_layout
;
38 int config_desktops_num
;
39 GSList
*config_desktops_names
;
41 gboolean config_redraw_resize
;
43 ObStackingLayer config_dock_layer
;
44 gboolean config_dock_floating
;
45 ObDirection config_dock_pos
;
48 ObOrientation config_dock_orient
;
49 gboolean config_dock_hide
;
50 guint config_dock_hide_delay
;
51 guint config_dock_app_move_button
;
52 guint config_dock_app_move_modifiers
;
54 guint config_keyboard_reset_keycode
;
55 guint config_keyboard_reset_state
;
57 gint config_mouse_threshold
;
58 gint config_mouse_dclicktime
;
60 GSList
*config_menu_files
;
62 gint config_resist_win
;
63 gint config_resist_edge
;
68 <action name="ChangeDesktop">
75 static void parse_key(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
83 if ((n
= parse_find_node("chainQuitKey", node
))) {
84 key
= parse_string(doc
, n
);
85 translate_key(key
, &config_keyboard_reset_state
,
86 &config_keyboard_reset_keycode
);
90 n
= parse_find_node("keybind", node
);
92 if (parse_attr_string("key", n
, &key
)) {
93 keylist
= g_list_append(keylist
, key
);
95 parse_key(i
, doc
, n
->children
, keylist
);
97 it
= g_list_last(keylist
);
99 keylist
= g_list_delete_link(keylist
, it
);
101 n
= parse_find_node("keybind", n
->next
);
104 nact
= parse_find_node("action", node
);
106 if ((action
= action_parse(i
, doc
, nact
,
107 OB_USER_ACTION_KEYBOARD_KEY
)))
108 keyboard_bind(keylist
, action
);
109 nact
= parse_find_node("action", nact
->next
);
114 static void parse_keyboard(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
117 keyboard_unbind_all();
119 parse_key(i
, doc
, node
->children
, NULL
);
124 <context name="Titlebar">
125 <mousebind button="Left" action="Press">
126 <action name="Raise"></action>
132 static void parse_mouse(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
135 xmlNodePtr n
, nbut
, nact
;
144 node
= node
->children
;
146 if ((n
= parse_find_node("dragThreshold", node
)))
147 config_mouse_threshold
= parse_int(doc
, n
);
148 if ((n
= parse_find_node("doubleClickTime", node
)))
149 config_mouse_dclicktime
= parse_int(doc
, n
);
151 n
= parse_find_node("context", node
);
153 if (!parse_attr_string("name", n
, &contextstr
))
155 nbut
= parse_find_node("mousebind", n
->children
);
157 if (!parse_attr_string("button", nbut
, &buttonstr
))
159 if (parse_attr_contains("press", nbut
, "action")) {
160 uact
= OB_USER_ACTION_MOUSE_PRESS
;
161 mact
= OB_MOUSE_ACTION_PRESS
;
162 } else if (parse_attr_contains("release", nbut
, "action")) {
163 uact
= OB_USER_ACTION_MOUSE_RELEASE
;
164 mact
= OB_MOUSE_ACTION_RELEASE
;
165 } else if (parse_attr_contains("click", nbut
, "action")) {
166 uact
= OB_USER_ACTION_MOUSE_CLICK
;
167 mact
= OB_MOUSE_ACTION_CLICK
;
168 } else if (parse_attr_contains("doubleclick", nbut
,"action")) {
169 uact
= OB_USER_ACTION_MOUSE_DOUBLE_CLICK
;
170 mact
= OB_MOUSE_ACTION_DOUBLE_CLICK
;
171 } else if (parse_attr_contains("drag", nbut
, "action")) {
172 uact
= OB_USER_ACTION_MOUSE_MOTION
;
173 mact
= OB_MOUSE_ACTION_MOTION
;
176 nact
= parse_find_node("action", nbut
->children
);
178 if ((action
= action_parse(i
, doc
, nact
, uact
)))
179 mouse_bind(buttonstr
, contextstr
, mact
, action
);
180 nact
= parse_find_node("action", nact
->next
);
184 nbut
= parse_find_node("mousebind", nbut
->next
);
188 n
= parse_find_node("context", n
->next
);
192 static void parse_focus(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
197 node
= node
->children
;
199 if ((n
= parse_find_node("focusNew", node
)))
200 config_focus_new
= parse_bool(doc
, n
);
201 if ((n
= parse_find_node("followMouse", node
)))
202 config_focus_follow
= parse_bool(doc
, n
);
203 if ((n
= parse_find_node("focusDelay", node
)))
204 config_focus_delay
= parse_int(doc
, n
) * 1000;
205 if ((n
= parse_find_node("raiseOnFocus", node
)))
206 config_focus_raise
= parse_bool(doc
, n
);
209 static void parse_placement(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
214 node
= node
->children
;
216 if ((n
= parse_find_node("policy", node
)))
217 if (parse_contains("UnderMouse", doc
, n
))
218 config_place_policy
= OB_PLACE_POLICY_MOUSE
;
221 static void parse_theme(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
226 node
= node
->children
;
228 if ((n
= parse_find_node("name", node
))) {
231 g_free(config_theme
);
232 c
= parse_string(doc
, n
);
233 config_theme
= parse_expand_tilde(c
);
236 if ((n
= parse_find_node("titleLayout", node
))) {
237 g_free(config_title_layout
);
238 config_title_layout
= parse_string(doc
, n
);
242 static void parse_desktops(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
247 node
= node
->children
;
249 if ((n
= parse_find_node("number", node
))) {
250 guint d
= parse_int(doc
, n
);
252 config_desktops_num
= d
;
254 if ((n
= parse_find_node("names", node
))) {
258 for (it
= config_desktops_names
; it
; it
= it
->next
)
260 g_slist_free(config_desktops_names
);
261 config_desktops_names
= NULL
;
263 nname
= parse_find_node("name", n
->children
);
265 config_desktops_names
= g_slist_append(config_desktops_names
,
266 parse_string(doc
, nname
));
267 nname
= parse_find_node("name", nname
->next
);
272 static void parse_resize(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
277 node
= node
->children
;
279 if ((n
= parse_find_node("drawContents", node
)))
280 config_redraw_resize
= parse_bool(doc
, n
);
283 static void parse_dock(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
, void *d
)
287 node
= node
->children
;
289 if ((n
= parse_find_node("position", node
))) {
290 if (parse_contains("TopLeft", doc
, n
))
291 config_dock_floating
= FALSE
,
292 config_dock_pos
= OB_DIRECTION_NORTHWEST
;
293 else if (parse_contains("Top", doc
, n
))
294 config_dock_floating
= FALSE
,
295 config_dock_pos
= OB_DIRECTION_NORTH
;
296 else if (parse_contains("TopRight", doc
, n
))
297 config_dock_floating
= FALSE
,
298 config_dock_pos
= OB_DIRECTION_NORTHEAST
;
299 else if (parse_contains("Right", doc
, n
))
300 config_dock_floating
= FALSE
,
301 config_dock_pos
= OB_DIRECTION_EAST
;
302 else if (parse_contains("BottomRight", doc
, n
))
303 config_dock_floating
= FALSE
,
304 config_dock_pos
= OB_DIRECTION_SOUTHEAST
;
305 else if (parse_contains("Bottom", doc
, n
))
306 config_dock_floating
= FALSE
,
307 config_dock_pos
= OB_DIRECTION_SOUTH
;
308 else if (parse_contains("BottomLeft", doc
, n
))
309 config_dock_floating
= FALSE
,
310 config_dock_pos
= OB_DIRECTION_SOUTHWEST
;
311 else if (parse_contains("Left", doc
, n
))
312 config_dock_floating
= FALSE
,
313 config_dock_pos
= OB_DIRECTION_WEST
;
314 else if (parse_contains("Floating", doc
, n
))
315 config_dock_floating
= TRUE
;
317 if (config_dock_floating
) {
318 if ((n
= parse_find_node("floatingX", node
)))
319 config_dock_x
= parse_int(doc
, n
);
320 if ((n
= parse_find_node("floatingY", node
)))
321 config_dock_y
= parse_int(doc
, n
);
323 if ((n
= parse_find_node("stacking", node
))) {
324 if (parse_contains("top", doc
, n
))
325 config_dock_layer
= OB_STACKING_LAYER_TOP
;
326 else if (parse_contains("normal", doc
, n
))
327 config_dock_layer
= OB_STACKING_LAYER_NORMAL
;
328 else if (parse_contains("bottom", doc
, n
))
329 config_dock_layer
= OB_STACKING_LAYER_BELOW
;
331 if ((n
= parse_find_node("direction", node
))) {
332 if (parse_contains("horizontal", doc
, n
))
333 config_dock_orient
= OB_ORIENTATION_HORZ
;
334 else if (parse_contains("vertical", doc
, n
))
335 config_dock_orient
= OB_ORIENTATION_VERT
;
337 if ((n
= parse_find_node("autoHide", node
)))
338 config_dock_hide
= parse_bool(doc
, n
);
339 if ((n
= parse_find_node("hideDelay", node
)))
340 config_dock_hide_delay
= parse_int(doc
, n
) * 1000;
341 if ((n
= parse_find_node("moveButton", node
))) {
342 gchar
*str
= parse_string(doc
, n
);
344 if (translate_button(str
, &s
, &b
)) {
345 config_dock_app_move_button
= b
;
346 config_dock_app_move_modifiers
= s
;
348 g_warning("invalid button '%s'", str
);
354 static void parse_menu(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
, void *d
)
356 for (node
= node
->children
; node
; node
= node
->next
) {
357 if (!xmlStrcasecmp(node
->name
, (const xmlChar
*) "file")) {
360 c
= parse_string(doc
, node
);
361 config_menu_files
= g_slist_append(config_menu_files
,
362 parse_expand_tilde(c
));
368 static void parse_resistance(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
373 node
= node
->children
;
374 if ((n
= parse_find_node("strength", node
)))
375 config_resist_win
= parse_int(doc
, n
);
376 if ((n
= parse_find_node("screen_edge_strength", node
)))
377 config_resist_edge
= parse_int(doc
, n
);
383 const gchar
*actname
;
386 static void bind_default_keyboard()
389 ObDefKeyBind binds
[] = {
390 { "A-Tab", "NextWindow" },
391 { "S-A-Tab", "PreviousWindow" },
396 for (it
= binds
; it
->key
; ++it
) {
397 GList
*l
= g_list_append(NULL
, g_strdup(it
->key
));
398 keyboard_bind(l
, action_from_string(it
->actname
,
399 OB_USER_ACTION_KEYBOARD_KEY
));
406 const gchar
*context
;
407 const ObMouseAction mact
;
408 const gchar
*actname
;
411 static void bind_default_mouse()
414 ObDefMouseBind binds
[] = {
415 { "Left", "Client", OB_MOUSE_ACTION_PRESS
, "Focus" },
416 { "Middle", "Client", OB_MOUSE_ACTION_PRESS
, "Focus" },
417 { "Right", "Client", OB_MOUSE_ACTION_PRESS
, "Focus" },
418 { "Left", "Desktop", OB_MOUSE_ACTION_PRESS
, "Focus" },
419 { "Middle", "Desktop", OB_MOUSE_ACTION_PRESS
, "Focus" },
420 { "Right", "Desktop", OB_MOUSE_ACTION_PRESS
, "Focus" },
421 { "Left", "Titlebar", OB_MOUSE_ACTION_PRESS
, "Focus" },
422 { "Left", "Handle", OB_MOUSE_ACTION_PRESS
, "Focus" },
423 { "Left", "BLCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
424 { "Left", "BRCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
425 { "Left", "TLCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
426 { "Left", "TRCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
427 { "Left", "Close", OB_MOUSE_ACTION_PRESS
, "Focus" },
428 { "Left", "Maximize", OB_MOUSE_ACTION_PRESS
, "Focus" },
429 { "Left", "Iconify", OB_MOUSE_ACTION_PRESS
, "Focus" },
430 { "Left", "Icon", OB_MOUSE_ACTION_PRESS
, "Focus" },
431 { "Left", "AllDesktops", OB_MOUSE_ACTION_PRESS
, "Focus" },
432 { "Left", "Shade", OB_MOUSE_ACTION_PRESS
, "Focus" },
433 { "Left", "Client", OB_MOUSE_ACTION_CLICK
, "Raise" },
434 { "Left", "Titlebar", OB_MOUSE_ACTION_CLICK
, "Raise" },
435 { "Middle", "Titlebar", OB_MOUSE_ACTION_CLICK
, "Lower" },
436 { "Left", "Handle", OB_MOUSE_ACTION_CLICK
, "Raise" },
437 { "Left", "BLCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
438 { "Left", "BRCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
439 { "Left", "TLCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
440 { "Left", "TRCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
441 { "Left", "Close", OB_MOUSE_ACTION_CLICK
, "Raise" },
442 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK
, "Raise" },
443 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK
, "Raise" },
444 { "Left", "Icon", OB_MOUSE_ACTION_CLICK
, "Raise" },
445 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK
, "Raise" },
446 { "Left", "Shade", OB_MOUSE_ACTION_CLICK
, "Raise" },
447 { "Left", "Close", OB_MOUSE_ACTION_CLICK
, "Close" },
448 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK
, "ToggleMaximizeFull" },
449 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK
, "Iconify" },
450 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK
, "ToggleOmnipresent" },
451 { "Left", "Shade", OB_MOUSE_ACTION_CLICK
, "ToggleShade" },
452 { "Left", "TLCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
453 { "Left", "TRCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
454 { "Left", "BLCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
455 { "Left", "BRCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
456 { "Left", "Titlebar", OB_MOUSE_ACTION_MOTION
, "Move" },
457 { "A-Left", "Frame", OB_MOUSE_ACTION_MOTION
, "Move" },
458 { "A-Middle", "Frame", OB_MOUSE_ACTION_MOTION
, "Resize" },
459 { NULL
, NULL
, 0, NULL
}
462 for (it
= binds
; it
->button
; ++it
) {
465 case OB_MOUSE_ACTION_PRESS
:
466 uact
= OB_USER_ACTION_MOUSE_PRESS
; break;
467 case OB_MOUSE_ACTION_RELEASE
:
468 uact
= OB_USER_ACTION_MOUSE_RELEASE
; break;
469 case OB_MOUSE_ACTION_CLICK
:
470 uact
= OB_USER_ACTION_MOUSE_CLICK
; break;
471 case OB_MOUSE_ACTION_DOUBLE_CLICK
:
472 uact
= OB_USER_ACTION_MOUSE_DOUBLE_CLICK
; break;
473 case OB_MOUSE_ACTION_MOTION
:
474 uact
= OB_USER_ACTION_MOUSE_MOTION
; break;
475 case OB_NUM_MOUSE_ACTIONS
:
476 g_assert_not_reached();
478 mouse_bind(it
->button
, it
->context
, it
->mact
,
479 action_from_string(it
->actname
, uact
));
483 void config_startup(ObParseInst
*i
)
485 config_focus_new
= TRUE
;
486 config_focus_follow
= FALSE
;
487 config_focus_delay
= 0;
488 config_focus_raise
= FALSE
;
490 parse_register(i
, "focus", parse_focus
, NULL
);
492 config_place_policy
= OB_PLACE_POLICY_SMART
;
494 parse_register(i
, "placement", parse_placement
, NULL
);
498 config_title_layout
= g_strdup("NLIMC");
500 parse_register(i
, "theme", parse_theme
, NULL
);
502 config_desktops_num
= 4;
503 config_desktops_names
= NULL
;
505 parse_register(i
, "desktops", parse_desktops
, NULL
);
507 config_redraw_resize
= TRUE
;
509 parse_register(i
, "resize", parse_resize
, NULL
);
511 config_dock_layer
= OB_STACKING_LAYER_TOP
;
512 config_dock_pos
= OB_DIRECTION_NORTHEAST
;
513 config_dock_floating
= FALSE
;
516 config_dock_orient
= OB_ORIENTATION_VERT
;
517 config_dock_hide
= FALSE
;
518 config_dock_hide_delay
= 300;
519 config_dock_app_move_button
= 2; /* middle */
520 config_dock_app_move_modifiers
= 0;
522 parse_register(i
, "dock", parse_dock
, NULL
);
524 translate_key("C-g", &config_keyboard_reset_state
,
525 &config_keyboard_reset_keycode
);
527 bind_default_keyboard();
529 parse_register(i
, "keyboard", parse_keyboard
, NULL
);
531 config_mouse_threshold
= 3;
532 config_mouse_dclicktime
= 200;
534 bind_default_mouse();
536 parse_register(i
, "mouse", parse_mouse
, NULL
);
538 config_resist_win
= 10;
539 config_resist_edge
= 20;
541 parse_register(i
, "resistance", parse_resistance
, NULL
);
543 config_menu_files
= NULL
;
545 parse_register(i
, "menu", parse_menu
, NULL
);
548 void config_shutdown()
552 g_free(config_theme
);
554 g_free(config_title_layout
);
556 for (it
= config_desktops_names
; it
; it
= g_slist_next(it
))
558 g_slist_free(config_desktops_names
);
560 for (it
= config_menu_files
; it
; it
= g_slist_next(it
))
562 g_slist_free(config_menu_files
);