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 gboolean config_focus_last
;
30 guint config_focus_delay
;
31 guint config_focus_raise
;
35 gchar
*config_title_layout
;
37 int config_desktops_num
;
38 GSList
*config_desktops_names
;
40 gboolean config_redraw_resize
;
42 ObStackingLayer config_dock_layer
;
43 gboolean config_dock_floating
;
44 ObDirection config_dock_pos
;
47 ObOrientation config_dock_orient
;
48 gboolean config_dock_hide
;
49 guint config_dock_hide_delay
;
51 guint config_keyboard_reset_keycode
;
52 guint config_keyboard_reset_state
;
54 gint config_mouse_threshold
;
55 gint config_mouse_dclicktime
;
57 GSList
*config_menu_files
;
59 gint config_resist_win
;
60 gint config_resist_edge
;
65 <action name="ChangeDesktop">
72 static void parse_key(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
80 if ((n
= parse_find_node("chainQuitKey", node
))) {
81 key
= parse_string(doc
, n
);
82 translate_key(key
, &config_keyboard_reset_state
,
83 &config_keyboard_reset_keycode
);
87 n
= parse_find_node("keybind", node
);
89 if (parse_attr_string("key", n
, &key
)) {
90 keylist
= g_list_append(keylist
, key
);
92 parse_key(i
, doc
, n
->children
, keylist
);
94 it
= g_list_last(keylist
);
96 keylist
= g_list_delete_link(keylist
, it
);
98 n
= parse_find_node("keybind", n
->next
);
101 nact
= parse_find_node("action", node
);
103 if ((action
= action_parse(i
, doc
, nact
,
104 OB_USER_ACTION_KEYBOARD_KEY
)))
105 keyboard_bind(keylist
, action
);
106 nact
= parse_find_node("action", nact
->next
);
111 static void parse_keyboard(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
114 keyboard_unbind_all();
116 parse_key(i
, doc
, node
->children
, NULL
);
121 <context name="Titlebar">
122 <mousebind button="Left" action="Press">
123 <action name="Raise"></action>
129 static void parse_mouse(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
132 xmlNodePtr n
, nbut
, nact
;
141 node
= node
->children
;
143 if ((n
= parse_find_node("dragThreshold", node
)))
144 config_mouse_threshold
= parse_int(doc
, n
);
145 if ((n
= parse_find_node("doubleClickTime", node
)))
146 config_mouse_dclicktime
= parse_int(doc
, n
);
148 n
= parse_find_node("context", node
);
150 if (!parse_attr_string("name", n
, &contextstr
))
152 nbut
= parse_find_node("mousebind", n
->children
);
154 if (!parse_attr_string("button", nbut
, &buttonstr
))
156 if (parse_attr_contains("press", nbut
, "action")) {
157 uact
= OB_USER_ACTION_MOUSE_PRESS
;
158 mact
= OB_MOUSE_ACTION_PRESS
;
159 } else if (parse_attr_contains("release", nbut
, "action")) {
160 uact
= OB_USER_ACTION_MOUSE_RELEASE
;
161 mact
= OB_MOUSE_ACTION_RELEASE
;
162 } else if (parse_attr_contains("click", nbut
, "action")) {
163 uact
= OB_USER_ACTION_MOUSE_CLICK
;
164 mact
= OB_MOUSE_ACTION_CLICK
;
165 } else if (parse_attr_contains("doubleclick", nbut
,"action")) {
166 uact
= OB_USER_ACTION_MOUSE_DOUBLE_CLICK
;
167 mact
= OB_MOUSE_ACTION_DOUBLE_CLICK
;
168 } else if (parse_attr_contains("drag", nbut
, "action")) {
169 uact
= OB_USER_ACTION_MOUSE_MOTION
;
170 mact
= OB_MOUSE_ACTION_MOTION
;
173 nact
= parse_find_node("action", nbut
->children
);
175 if ((action
= action_parse(i
, doc
, nact
, uact
)))
176 mouse_bind(buttonstr
, contextstr
, mact
, action
);
177 nact
= parse_find_node("action", nact
->next
);
181 nbut
= parse_find_node("mousebind", nbut
->next
);
185 n
= parse_find_node("context", n
->next
);
189 static void parse_focus(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
194 node
= node
->children
;
196 if ((n
= parse_find_node("focusNew", node
)))
197 config_focus_new
= parse_bool(doc
, n
);
198 if ((n
= parse_find_node("followMouse", node
)))
199 config_focus_follow
= parse_bool(doc
, n
);
200 if ((n
= parse_find_node("focusLast", node
)))
201 config_focus_last
= parse_bool(doc
, n
);
202 if ((n
= parse_find_node("focusDelay", node
)))
203 config_focus_delay
= parse_int(doc
, n
) * 1000;
204 if ((n
= parse_find_node("raiseOnFocus", node
)))
205 config_focus_raise
= parse_bool(doc
, n
);
208 static void parse_theme(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
213 node
= node
->children
;
215 if ((n
= parse_find_node("name", node
))) {
218 g_free(config_theme
);
219 c
= parse_string(doc
, n
);
220 config_theme
= parse_expand_tilde(c
);
223 if ((n
= parse_find_node("titleLayout", node
))) {
224 g_free(config_title_layout
);
225 config_title_layout
= parse_string(doc
, n
);
229 static void parse_desktops(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
234 node
= node
->children
;
236 if ((n
= parse_find_node("number", node
))) {
237 guint d
= parse_int(doc
, n
);
239 config_desktops_num
= d
;
241 if ((n
= parse_find_node("names", node
))) {
245 for (it
= config_desktops_names
; it
; it
= it
->next
)
247 g_slist_free(config_desktops_names
);
248 config_desktops_names
= NULL
;
250 nname
= parse_find_node("name", n
->children
);
252 config_desktops_names
= g_slist_append(config_desktops_names
,
253 parse_string(doc
, nname
));
254 nname
= parse_find_node("name", nname
->next
);
259 static void parse_resize(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
264 node
= node
->children
;
266 if ((n
= parse_find_node("drawContents", node
)))
267 config_redraw_resize
= parse_bool(doc
, n
);
270 static void parse_dock(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
, void *d
)
274 node
= node
->children
;
276 if ((n
= parse_find_node("position", node
))) {
277 if (parse_contains("TopLeft", doc
, n
))
278 config_dock_floating
= FALSE
,
279 config_dock_pos
= OB_DIRECTION_NORTHWEST
;
280 else if (parse_contains("Top", doc
, n
))
281 config_dock_floating
= FALSE
,
282 config_dock_pos
= OB_DIRECTION_NORTH
;
283 else if (parse_contains("TopRight", doc
, n
))
284 config_dock_floating
= FALSE
,
285 config_dock_pos
= OB_DIRECTION_NORTHEAST
;
286 else if (parse_contains("Right", doc
, n
))
287 config_dock_floating
= FALSE
,
288 config_dock_pos
= OB_DIRECTION_EAST
;
289 else if (parse_contains("BottomRight", doc
, n
))
290 config_dock_floating
= FALSE
,
291 config_dock_pos
= OB_DIRECTION_SOUTHEAST
;
292 else if (parse_contains("Bottom", doc
, n
))
293 config_dock_floating
= FALSE
,
294 config_dock_pos
= OB_DIRECTION_SOUTH
;
295 else if (parse_contains("BottomLeft", doc
, n
))
296 config_dock_floating
= FALSE
,
297 config_dock_pos
= OB_DIRECTION_SOUTHWEST
;
298 else if (parse_contains("Left", doc
, n
))
299 config_dock_floating
= FALSE
,
300 config_dock_pos
= OB_DIRECTION_WEST
;
301 else if (parse_contains("Floating", doc
, n
))
302 config_dock_floating
= TRUE
;
304 if (config_dock_floating
) {
305 if ((n
= parse_find_node("floatingX", node
)))
306 config_dock_x
= parse_int(doc
, n
);
307 if ((n
= parse_find_node("floatingY", node
)))
308 config_dock_y
= parse_int(doc
, n
);
310 if ((n
= parse_find_node("stacking", node
))) {
311 if (parse_contains("top", doc
, n
))
312 config_dock_layer
= OB_STACKING_LAYER_TOP
;
313 else if (parse_contains("normal", doc
, n
))
314 config_dock_layer
= OB_STACKING_LAYER_NORMAL
;
315 else if (parse_contains("bottom", doc
, n
))
316 config_dock_layer
= OB_STACKING_LAYER_BELOW
;
318 if ((n
= parse_find_node("direction", node
))) {
319 if (parse_contains("horizontal", doc
, n
))
320 config_dock_orient
= OB_ORIENTATION_HORZ
;
321 else if (parse_contains("vertical", doc
, n
))
322 config_dock_orient
= OB_ORIENTATION_VERT
;
324 if ((n
= parse_find_node("autoHide", node
)))
325 config_dock_hide
= parse_bool(doc
, n
);
326 if ((n
= parse_find_node("hideDelay", node
)))
327 config_dock_hide_delay
= parse_int(doc
, n
) * 1000;
330 static void parse_menu(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
, void *d
)
332 for (node
= node
->children
; node
; node
= node
->next
) {
333 if (!xmlStrcasecmp(node
->name
, (const xmlChar
*) "file")) {
336 c
= parse_string(doc
, node
);
337 config_menu_files
= g_slist_append(config_menu_files
,
338 parse_expand_tilde(c
));
344 static void parse_resistance(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
349 node
= node
->children
;
350 if ((n
= parse_find_node("strength", node
)))
351 config_resist_win
= parse_int(doc
, n
);
352 if ((n
= parse_find_node("screen_edge_strength", node
)))
353 config_resist_edge
= parse_int(doc
, n
);
359 const gchar
*actname
;
362 static void bind_default_keyboard()
365 ObDefKeyBind binds
[] = {
366 { "A-Tab", "NextWindow" },
367 { "S-A-Tab", "PreviousWindow" },
372 for (it
= binds
; it
->key
; ++it
) {
373 GList
*l
= g_list_append(NULL
, g_strdup(it
->key
));
374 keyboard_bind(l
, action_from_string(it
->actname
,
375 OB_USER_ACTION_KEYBOARD_KEY
));
382 const gchar
*context
;
383 const ObMouseAction mact
;
384 const gchar
*actname
;
387 static void bind_default_mouse()
390 ObDefMouseBind binds
[] = {
391 { "Left", "Client", OB_MOUSE_ACTION_PRESS
, "Focus" },
392 { "Middle", "Client", OB_MOUSE_ACTION_PRESS
, "Focus" },
393 { "Right", "Client", OB_MOUSE_ACTION_PRESS
, "Focus" },
394 { "Left", "Desktop", OB_MOUSE_ACTION_PRESS
, "Focus" },
395 { "Middle", "Desktop", OB_MOUSE_ACTION_PRESS
, "Focus" },
396 { "Right", "Desktop", OB_MOUSE_ACTION_PRESS
, "Focus" },
397 { "Left", "Titlebar", OB_MOUSE_ACTION_PRESS
, "Focus" },
398 { "Left", "Handle", OB_MOUSE_ACTION_PRESS
, "Focus" },
399 { "Left", "BLCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
400 { "Left", "BRCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
401 { "Left", "TLCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
402 { "Left", "TRCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
403 { "Left", "Close", OB_MOUSE_ACTION_PRESS
, "Focus" },
404 { "Left", "Maximize", OB_MOUSE_ACTION_PRESS
, "Focus" },
405 { "Left", "Iconify", OB_MOUSE_ACTION_PRESS
, "Focus" },
406 { "Left", "Icon", OB_MOUSE_ACTION_PRESS
, "Focus" },
407 { "Left", "AllDesktops", OB_MOUSE_ACTION_PRESS
, "Focus" },
408 { "Left", "Shade", OB_MOUSE_ACTION_PRESS
, "Focus" },
409 { "Left", "Client", OB_MOUSE_ACTION_CLICK
, "Raise" },
410 { "Left", "Titlebar", OB_MOUSE_ACTION_CLICK
, "Raise" },
411 { "Middle", "Titlebar", OB_MOUSE_ACTION_CLICK
, "Lower" },
412 { "Left", "Handle", OB_MOUSE_ACTION_CLICK
, "Raise" },
413 { "Left", "BLCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
414 { "Left", "BRCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
415 { "Left", "TLCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
416 { "Left", "TRCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
417 { "Left", "Close", OB_MOUSE_ACTION_CLICK
, "Raise" },
418 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK
, "Raise" },
419 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK
, "Raise" },
420 { "Left", "Icon", OB_MOUSE_ACTION_CLICK
, "Raise" },
421 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK
, "Raise" },
422 { "Left", "Shade", OB_MOUSE_ACTION_CLICK
, "Raise" },
423 { "Left", "Close", OB_MOUSE_ACTION_CLICK
, "Close" },
424 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK
, "ToggleMaximizeFull" },
425 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK
, "Iconify" },
426 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK
, "ToggleOmnipresent" },
427 { "Left", "Shade", OB_MOUSE_ACTION_CLICK
, "ToggleShade" },
428 { "Left", "TLCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
429 { "Left", "TRCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
430 { "Left", "BLCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
431 { "Left", "BRCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
432 { "Left", "Titlebar", OB_MOUSE_ACTION_MOTION
, "Move" },
433 { "A-Left", "Frame", OB_MOUSE_ACTION_MOTION
, "Move" },
434 { "A-Middle", "Frame", OB_MOUSE_ACTION_MOTION
, "Resize" },
435 { NULL
, NULL
, 0, NULL
}
438 for (it
= binds
; it
->button
; ++it
) {
441 case OB_MOUSE_ACTION_PRESS
:
442 uact
= OB_USER_ACTION_MOUSE_PRESS
; break;
443 case OB_MOUSE_ACTION_RELEASE
:
444 uact
= OB_USER_ACTION_MOUSE_RELEASE
; break;
445 case OB_MOUSE_ACTION_CLICK
:
446 uact
= OB_USER_ACTION_MOUSE_CLICK
; break;
447 case OB_MOUSE_ACTION_DOUBLE_CLICK
:
448 uact
= OB_USER_ACTION_MOUSE_DOUBLE_CLICK
; break;
449 case OB_MOUSE_ACTION_MOTION
:
450 uact
= OB_USER_ACTION_MOUSE_MOTION
; break;
451 case OB_NUM_MOUSE_ACTIONS
:
452 g_assert_not_reached();
454 mouse_bind(it
->button
, it
->context
, it
->mact
,
455 action_from_string(it
->actname
, uact
));
459 void config_startup(ObParseInst
*i
)
461 config_focus_new
= TRUE
;
462 config_focus_follow
= FALSE
;
463 config_focus_last
= TRUE
;
464 config_focus_delay
= 0;
465 config_focus_raise
= FALSE
;
467 parse_register(i
, "focus", parse_focus
, NULL
);
471 config_title_layout
= g_strdup("NLIMC");
473 parse_register(i
, "theme", parse_theme
, NULL
);
475 config_desktops_num
= 4;
476 config_desktops_names
= NULL
;
478 parse_register(i
, "desktops", parse_desktops
, NULL
);
480 config_redraw_resize
= TRUE
;
482 parse_register(i
, "resize", parse_resize
, NULL
);
484 config_dock_layer
= OB_STACKING_LAYER_TOP
;
485 config_dock_pos
= OB_DIRECTION_NORTHEAST
;
486 config_dock_floating
= FALSE
;
489 config_dock_orient
= OB_ORIENTATION_VERT
;
490 config_dock_hide
= FALSE
;
491 config_dock_hide_delay
= 300;
493 parse_register(i
, "dock", parse_dock
, NULL
);
495 translate_key("C-g", &config_keyboard_reset_state
,
496 &config_keyboard_reset_keycode
);
498 bind_default_keyboard();
500 parse_register(i
, "keyboard", parse_keyboard
, NULL
);
502 config_mouse_threshold
= 3;
503 config_mouse_dclicktime
= 200;
505 bind_default_mouse();
507 parse_register(i
, "mouse", parse_mouse
, NULL
);
509 config_resist_win
= 10;
510 config_resist_edge
= 20;
512 parse_register(i
, "resistance", parse_resistance
, NULL
);
514 config_menu_files
= NULL
;
516 parse_register(i
, "menu", parse_menu
, NULL
);
519 void config_shutdown()
523 g_free(config_theme
);
525 g_free(config_title_layout
);
527 for (it
= config_desktops_names
; it
; it
= g_slist_next(it
))
529 g_slist_free(config_desktops_names
);
531 for (it
= config_menu_files
; it
; it
= g_slist_next(it
))
533 g_slist_free(config_menu_files
);