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
;
38 gchar
*config_title_layout
;
40 gint config_desktops_num
;
41 GSList
*config_desktops_names
;
42 gint config_screen_firstdesk
;
44 gboolean config_resize_redraw
;
45 gint config_resize_popup_show
;
46 gint config_resize_popup_pos
;
48 ObStackingLayer config_dock_layer
;
49 gboolean config_dock_floating
;
50 ObDirection config_dock_pos
;
53 ObOrientation config_dock_orient
;
54 gboolean config_dock_hide
;
55 guint config_dock_hide_delay
;
56 guint config_dock_app_move_button
;
57 guint config_dock_app_move_modifiers
;
59 guint config_keyboard_reset_keycode
;
60 guint config_keyboard_reset_state
;
62 gint config_mouse_threshold
;
63 gint config_mouse_dclicktime
;
65 gboolean config_menu_warppointer
;
66 gboolean config_menu_xorstyle
;
67 gboolean config_menu_hilightfirst
;
68 guint config_menu_hide_delay
;
70 GSList
*config_menu_files
;
72 gint config_resist_win
;
73 gint config_resist_edge
;
78 <action name="ChangeDesktop">
85 static void parse_key(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
93 if ((n
= parse_find_node("chainQuitKey", node
))) {
94 key
= parse_string(doc
, n
);
95 translate_key(key
, &config_keyboard_reset_state
,
96 &config_keyboard_reset_keycode
);
100 n
= parse_find_node("keybind", node
);
102 if (parse_attr_string("key", n
, &key
)) {
103 keylist
= g_list_append(keylist
, key
);
105 parse_key(i
, doc
, n
->children
, keylist
);
107 it
= g_list_last(keylist
);
109 keylist
= g_list_delete_link(keylist
, it
);
111 n
= parse_find_node("keybind", n
->next
);
114 nact
= parse_find_node("action", node
);
116 if ((action
= action_parse(i
, doc
, nact
,
117 OB_USER_ACTION_KEYBOARD_KEY
)))
118 keyboard_bind(keylist
, action
);
119 nact
= parse_find_node("action", nact
->next
);
124 static void parse_keyboard(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
127 keyboard_unbind_all();
129 parse_key(i
, doc
, node
->children
, NULL
);
134 <context name="Titlebar">
135 <mousebind button="Left" action="Press">
136 <action name="Raise"></action>
142 static void parse_mouse(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
145 xmlNodePtr n
, nbut
, nact
;
154 node
= node
->children
;
156 if ((n
= parse_find_node("dragThreshold", node
)))
157 config_mouse_threshold
= parse_int(doc
, n
);
158 if ((n
= parse_find_node("doubleClickTime", node
)))
159 config_mouse_dclicktime
= parse_int(doc
, n
);
161 n
= parse_find_node("context", node
);
163 if (!parse_attr_string("name", n
, &contextstr
))
165 nbut
= parse_find_node("mousebind", n
->children
);
167 if (!parse_attr_string("button", nbut
, &buttonstr
))
169 if (parse_attr_contains("press", nbut
, "action")) {
170 uact
= OB_USER_ACTION_MOUSE_PRESS
;
171 mact
= OB_MOUSE_ACTION_PRESS
;
172 } else if (parse_attr_contains("release", nbut
, "action")) {
173 uact
= OB_USER_ACTION_MOUSE_RELEASE
;
174 mact
= OB_MOUSE_ACTION_RELEASE
;
175 } else if (parse_attr_contains("click", nbut
, "action")) {
176 uact
= OB_USER_ACTION_MOUSE_CLICK
;
177 mact
= OB_MOUSE_ACTION_CLICK
;
178 } else if (parse_attr_contains("doubleclick", nbut
,"action")) {
179 uact
= OB_USER_ACTION_MOUSE_DOUBLE_CLICK
;
180 mact
= OB_MOUSE_ACTION_DOUBLE_CLICK
;
181 } else if (parse_attr_contains("drag", nbut
, "action")) {
182 uact
= OB_USER_ACTION_MOUSE_MOTION
;
183 mact
= OB_MOUSE_ACTION_MOTION
;
186 nact
= parse_find_node("action", nbut
->children
);
188 if ((action
= action_parse(i
, doc
, nact
, uact
)))
189 mouse_bind(buttonstr
, contextstr
, mact
, action
);
190 nact
= parse_find_node("action", nact
->next
);
194 nbut
= parse_find_node("mousebind", nbut
->next
);
198 n
= parse_find_node("context", n
->next
);
202 static void parse_focus(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
207 node
= node
->children
;
209 if ((n
= parse_find_node("focusNew", node
)))
210 config_focus_new
= parse_bool(doc
, n
);
211 if ((n
= parse_find_node("followMouse", node
)))
212 config_focus_follow
= parse_bool(doc
, n
);
213 if ((n
= parse_find_node("focusDelay", node
)))
214 config_focus_delay
= parse_int(doc
, n
) * 1000;
215 if ((n
= parse_find_node("raiseOnFocus", node
)))
216 config_focus_raise
= parse_bool(doc
, n
);
217 if ((n
= parse_find_node("focusLast", node
)))
218 config_focus_last
= parse_bool(doc
, n
);
221 static void parse_placement(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
226 node
= node
->children
;
228 if ((n
= parse_find_node("policy", node
)))
229 if (parse_contains("UnderMouse", doc
, n
))
230 config_place_policy
= OB_PLACE_POLICY_MOUSE
;
233 static void parse_theme(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
238 node
= node
->children
;
240 if ((n
= parse_find_node("name", node
))) {
243 g_free(config_theme
);
244 c
= parse_string(doc
, n
);
245 config_theme
= parse_expand_tilde(c
);
248 if ((n
= parse_find_node("titleLayout", node
))) {
249 g_free(config_title_layout
);
250 config_title_layout
= parse_string(doc
, n
);
254 static void parse_desktops(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
259 node
= node
->children
;
261 if ((n
= parse_find_node("number", node
))) {
262 gint d
= parse_int(doc
, n
);
264 config_desktops_num
= d
;
266 if ((n
= parse_find_node("firstdesk", node
))) {
267 gint d
= parse_int(doc
, n
);
269 config_screen_firstdesk
= d
;
271 if ((n
= parse_find_node("names", node
))) {
275 for (it
= config_desktops_names
; it
; it
= it
->next
)
277 g_slist_free(config_desktops_names
);
278 config_desktops_names
= NULL
;
280 nname
= parse_find_node("name", n
->children
);
282 config_desktops_names
= g_slist_append(config_desktops_names
,
283 parse_string(doc
, nname
));
284 nname
= parse_find_node("name", nname
->next
);
289 static void parse_resize(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
294 node
= node
->children
;
296 if ((n
= parse_find_node("drawContents", node
)))
297 config_resize_redraw
= parse_bool(doc
, n
);
298 if ((n
= parse_find_node("popupShow", node
))) {
299 if (parse_contains("Always", doc
, n
))
300 config_resize_popup_show
= 2;
301 else if (parse_contains("Never", doc
, n
))
302 config_resize_popup_show
= 0;
303 else if (parse_contains("Nonpixel", doc
, n
))
304 config_resize_popup_show
= 1;
306 if ((n
= parse_find_node("popupPosition", node
))) {
307 if (parse_contains("Top", doc
, n
))
308 config_resize_popup_pos
= 1;
309 else if (parse_contains("Center", doc
, n
))
310 config_resize_popup_pos
= 0;
314 static void parse_dock(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
319 node
= node
->children
;
321 if ((n
= parse_find_node("position", node
))) {
322 if (parse_contains("TopLeft", doc
, n
))
323 config_dock_floating
= FALSE
,
324 config_dock_pos
= OB_DIRECTION_NORTHWEST
;
325 else if (parse_contains("Top", doc
, n
))
326 config_dock_floating
= FALSE
,
327 config_dock_pos
= OB_DIRECTION_NORTH
;
328 else if (parse_contains("TopRight", doc
, n
))
329 config_dock_floating
= FALSE
,
330 config_dock_pos
= OB_DIRECTION_NORTHEAST
;
331 else if (parse_contains("Right", doc
, n
))
332 config_dock_floating
= FALSE
,
333 config_dock_pos
= OB_DIRECTION_EAST
;
334 else if (parse_contains("BottomRight", doc
, n
))
335 config_dock_floating
= FALSE
,
336 config_dock_pos
= OB_DIRECTION_SOUTHEAST
;
337 else if (parse_contains("Bottom", doc
, n
))
338 config_dock_floating
= FALSE
,
339 config_dock_pos
= OB_DIRECTION_SOUTH
;
340 else if (parse_contains("BottomLeft", doc
, n
))
341 config_dock_floating
= FALSE
,
342 config_dock_pos
= OB_DIRECTION_SOUTHWEST
;
343 else if (parse_contains("Left", doc
, n
))
344 config_dock_floating
= FALSE
,
345 config_dock_pos
= OB_DIRECTION_WEST
;
346 else if (parse_contains("Floating", doc
, n
))
347 config_dock_floating
= TRUE
;
349 if (config_dock_floating
) {
350 if ((n
= parse_find_node("floatingX", node
)))
351 config_dock_x
= parse_int(doc
, n
);
352 if ((n
= parse_find_node("floatingY", node
)))
353 config_dock_y
= parse_int(doc
, n
);
355 if ((n
= parse_find_node("stacking", node
))) {
356 if (parse_contains("top", doc
, n
))
357 config_dock_layer
= OB_STACKING_LAYER_DOCK_ABOVE
;
358 else if (parse_contains("normal", doc
, n
))
359 config_dock_layer
= OB_STACKING_LAYER_DOCK_NORMAL
;
360 else if (parse_contains("bottom", doc
, n
))
361 config_dock_layer
= OB_STACKING_LAYER_DOCK_BELOW
;
363 if ((n
= parse_find_node("direction", node
))) {
364 if (parse_contains("horizontal", doc
, n
))
365 config_dock_orient
= OB_ORIENTATION_HORZ
;
366 else if (parse_contains("vertical", doc
, n
))
367 config_dock_orient
= OB_ORIENTATION_VERT
;
369 if ((n
= parse_find_node("autoHide", node
)))
370 config_dock_hide
= parse_bool(doc
, n
);
371 if ((n
= parse_find_node("hideDelay", node
)))
372 config_dock_hide_delay
= parse_int(doc
, n
) * 1000;
373 if ((n
= parse_find_node("moveButton", node
))) {
374 gchar
*str
= parse_string(doc
, n
);
376 if (translate_button(str
, &s
, &b
)) {
377 config_dock_app_move_button
= b
;
378 config_dock_app_move_modifiers
= s
;
380 g_warning("invalid button '%s'", str
);
386 static void parse_menu(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
390 for (node
= node
->children
; node
; node
= node
->next
) {
391 if (!xmlStrcasecmp(node
->name
, (const xmlChar
*) "file")) {
394 c
= parse_string(doc
, node
);
395 config_menu_files
= g_slist_append(config_menu_files
,
396 parse_expand_tilde(c
));
399 if ((n
= parse_find_node("warpPointer", node
)))
400 config_menu_warppointer
= parse_bool(doc
, n
);
401 if ((n
= parse_find_node("xorStyle", node
)))
402 config_menu_xorstyle
= parse_bool(doc
, n
);
403 if ((n
= parse_find_node("hilightFirst", node
)))
404 config_menu_hilightfirst
= parse_bool(doc
, n
);
405 if ((n
= parse_find_node("hideDelay", node
)))
406 config_menu_hide_delay
= parse_int(doc
, n
);
410 static void parse_resistance(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
415 node
= node
->children
;
416 if ((n
= parse_find_node("strength", node
)))
417 config_resist_win
= parse_int(doc
, n
);
418 if ((n
= parse_find_node("screen_edge_strength", node
)))
419 config_resist_edge
= parse_int(doc
, n
);
425 const gchar
*actname
;
428 static void bind_default_keyboard()
431 ObDefKeyBind binds
[] = {
432 { "A-Tab", "NextWindow" },
433 { "S-A-Tab", "PreviousWindow" },
438 for (it
= binds
; it
->key
; ++it
) {
439 GList
*l
= g_list_append(NULL
, g_strdup(it
->key
));
440 keyboard_bind(l
, action_from_string(it
->actname
,
441 OB_USER_ACTION_KEYBOARD_KEY
));
448 const gchar
*context
;
449 const ObMouseAction mact
;
450 const gchar
*actname
;
453 static void bind_default_mouse()
456 ObDefMouseBind binds
[] = {
457 { "Left", "Client", OB_MOUSE_ACTION_PRESS
, "Focus" },
458 { "Middle", "Client", OB_MOUSE_ACTION_PRESS
, "Focus" },
459 { "Right", "Client", OB_MOUSE_ACTION_PRESS
, "Focus" },
460 { "Left", "Desktop", OB_MOUSE_ACTION_PRESS
, "Focus" },
461 { "Middle", "Desktop", OB_MOUSE_ACTION_PRESS
, "Focus" },
462 { "Right", "Desktop", OB_MOUSE_ACTION_PRESS
, "Focus" },
463 { "Left", "Titlebar", OB_MOUSE_ACTION_PRESS
, "Focus" },
464 { "Left", "Handle", OB_MOUSE_ACTION_PRESS
, "Focus" },
465 { "Left", "BLCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
466 { "Left", "BRCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
467 { "Left", "TLCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
468 { "Left", "TRCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
469 { "Left", "Close", OB_MOUSE_ACTION_PRESS
, "Focus" },
470 { "Left", "Maximize", OB_MOUSE_ACTION_PRESS
, "Focus" },
471 { "Left", "Iconify", OB_MOUSE_ACTION_PRESS
, "Focus" },
472 { "Left", "Icon", OB_MOUSE_ACTION_PRESS
, "Focus" },
473 { "Left", "AllDesktops", OB_MOUSE_ACTION_PRESS
, "Focus" },
474 { "Left", "Shade", OB_MOUSE_ACTION_PRESS
, "Focus" },
475 { "Left", "Client", OB_MOUSE_ACTION_CLICK
, "Raise" },
476 { "Left", "Titlebar", OB_MOUSE_ACTION_CLICK
, "Raise" },
477 { "Middle", "Titlebar", OB_MOUSE_ACTION_CLICK
, "Lower" },
478 { "Left", "Handle", OB_MOUSE_ACTION_CLICK
, "Raise" },
479 { "Left", "BLCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
480 { "Left", "BRCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
481 { "Left", "TLCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
482 { "Left", "TRCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
483 { "Left", "Close", OB_MOUSE_ACTION_CLICK
, "Raise" },
484 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK
, "Raise" },
485 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK
, "Raise" },
486 { "Left", "Icon", OB_MOUSE_ACTION_CLICK
, "Raise" },
487 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK
, "Raise" },
488 { "Left", "Shade", OB_MOUSE_ACTION_CLICK
, "Raise" },
489 { "Left", "Close", OB_MOUSE_ACTION_CLICK
, "Close" },
490 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK
, "ToggleMaximizeFull" },
491 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK
, "Iconify" },
492 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK
, "ToggleOmnipresent" },
493 { "Left", "Shade", OB_MOUSE_ACTION_CLICK
, "ToggleShade" },
494 { "Left", "TLCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
495 { "Left", "TRCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
496 { "Left", "BLCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
497 { "Left", "BRCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
498 { "Left", "Titlebar", OB_MOUSE_ACTION_MOTION
, "Move" },
499 { "A-Left", "Frame", OB_MOUSE_ACTION_MOTION
, "Move" },
500 { "A-Middle", "Frame", OB_MOUSE_ACTION_MOTION
, "Resize" },
501 { NULL
, NULL
, 0, NULL
}
504 for (it
= binds
; it
->button
; ++it
) {
507 case OB_MOUSE_ACTION_PRESS
:
508 uact
= OB_USER_ACTION_MOUSE_PRESS
; break;
509 case OB_MOUSE_ACTION_RELEASE
:
510 uact
= OB_USER_ACTION_MOUSE_RELEASE
; break;
511 case OB_MOUSE_ACTION_CLICK
:
512 uact
= OB_USER_ACTION_MOUSE_CLICK
; break;
513 case OB_MOUSE_ACTION_DOUBLE_CLICK
:
514 uact
= OB_USER_ACTION_MOUSE_DOUBLE_CLICK
; break;
515 case OB_MOUSE_ACTION_MOTION
:
516 uact
= OB_USER_ACTION_MOUSE_MOTION
; break;
517 case OB_NUM_MOUSE_ACTIONS
:
518 g_assert_not_reached();
520 mouse_bind(it
->button
, it
->context
, it
->mact
,
521 action_from_string(it
->actname
, uact
));
525 void config_startup(ObParseInst
*i
)
527 config_focus_new
= TRUE
;
528 config_focus_follow
= FALSE
;
529 config_focus_delay
= 0;
530 config_focus_raise
= FALSE
;
531 config_focus_last
= FALSE
;
533 parse_register(i
, "focus", parse_focus
, NULL
);
535 config_place_policy
= OB_PLACE_POLICY_SMART
;
537 parse_register(i
, "placement", parse_placement
, NULL
);
541 config_title_layout
= g_strdup("NLIMC");
543 parse_register(i
, "theme", parse_theme
, NULL
);
545 config_desktops_num
= 4;
546 config_screen_firstdesk
= 1;
547 config_desktops_names
= NULL
;
549 parse_register(i
, "desktops", parse_desktops
, NULL
);
551 config_resize_redraw
= TRUE
;
552 config_resize_popup_show
= 1; /* nonpixel increments */
553 config_resize_popup_pos
= 0; /* center of client */
555 parse_register(i
, "resize", parse_resize
, NULL
);
557 config_dock_layer
= OB_STACKING_LAYER_DOCK_ABOVE
;
558 config_dock_pos
= OB_DIRECTION_NORTHEAST
;
559 config_dock_floating
= FALSE
;
562 config_dock_orient
= OB_ORIENTATION_VERT
;
563 config_dock_hide
= FALSE
;
564 config_dock_hide_delay
= 300;
565 config_dock_app_move_button
= 2; /* middle */
566 config_dock_app_move_modifiers
= 0;
568 parse_register(i
, "dock", parse_dock
, NULL
);
570 translate_key("C-g", &config_keyboard_reset_state
,
571 &config_keyboard_reset_keycode
);
573 bind_default_keyboard();
575 parse_register(i
, "keyboard", parse_keyboard
, NULL
);
577 config_mouse_threshold
= 3;
578 config_mouse_dclicktime
= 200;
580 bind_default_mouse();
582 parse_register(i
, "mouse", parse_mouse
, NULL
);
584 config_resist_win
= 10;
585 config_resist_edge
= 20;
587 parse_register(i
, "resistance", parse_resistance
, NULL
);
589 config_menu_warppointer
= TRUE
;
590 config_menu_xorstyle
= FALSE
;
591 config_menu_hilightfirst
= TRUE
;
592 config_menu_hide_delay
= 250;
593 config_menu_files
= NULL
;
595 parse_register(i
, "menu", parse_menu
, NULL
);
598 void config_shutdown()
602 g_free(config_theme
);
604 g_free(config_title_layout
);
606 for (it
= config_desktops_names
; it
; it
= g_slist_next(it
))
608 g_slist_free(config_desktops_names
);
610 for (it
= config_menu_files
; it
; it
= g_slist_next(it
))
612 g_slist_free(config_menu_files
);