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
;
33 gchar
*config_title_layout
;
35 int config_desktops_num
;
36 GSList
*config_desktops_names
;
38 gboolean config_redraw_resize
;
40 ObStackingLayer config_dock_layer
;
41 gboolean config_dock_floating
;
42 ObDirection config_dock_pos
;
45 ObOrientation config_dock_orient
;
46 gboolean config_dock_hide
;
47 guint config_dock_hide_timeout
;
49 guint config_keyboard_reset_keycode
;
50 guint config_keyboard_reset_state
;
52 gint config_mouse_threshold
;
53 gint config_mouse_dclicktime
;
55 GSList
*config_menu_files
;
57 gint config_resist_win
;
58 gint config_resist_edge
;
63 <action name="ChangeDesktop">
70 static void parse_key(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
78 if ((n
= parse_find_node("chainQuitKey", node
))) {
79 key
= parse_string(doc
, n
);
80 translate_key(key
, &config_keyboard_reset_state
,
81 &config_keyboard_reset_keycode
);
85 n
= parse_find_node("keybind", node
);
87 if (parse_attr_string("key", n
, &key
)) {
88 keylist
= g_list_append(keylist
, key
);
90 parse_key(i
, doc
, n
->children
, keylist
);
92 it
= g_list_last(keylist
);
94 keylist
= g_list_delete_link(keylist
, it
);
96 n
= parse_find_node("keybind", n
->next
);
99 nact
= parse_find_node("action", node
);
101 if ((action
= action_parse(i
, doc
, nact
,
102 OB_USER_ACTION_KEYBOARD_KEY
)))
103 keyboard_bind(keylist
, action
);
104 nact
= parse_find_node("action", nact
->next
);
109 static void parse_keyboard(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
112 keyboard_unbind_all();
114 parse_key(i
, doc
, node
->children
, NULL
);
119 <context name="Titlebar">
120 <mousebind button="Left" action="Press">
121 <action name="Raise"></action>
127 static void parse_mouse(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
130 xmlNodePtr n
, nbut
, nact
;
139 node
= node
->children
;
141 if ((n
= parse_find_node("dragThreshold", node
)))
142 config_mouse_threshold
= parse_int(doc
, n
);
143 if ((n
= parse_find_node("doubleClickTime", node
)))
144 config_mouse_dclicktime
= parse_int(doc
, n
);
146 n
= parse_find_node("context", node
);
148 if (!parse_attr_string("name", n
, &contextstr
))
150 nbut
= parse_find_node("mousebind", n
->children
);
152 if (!parse_attr_string("button", nbut
, &buttonstr
))
154 if (parse_attr_contains("press", nbut
, "action")) {
155 uact
= OB_USER_ACTION_MOUSE_PRESS
;
156 mact
= OB_MOUSE_ACTION_PRESS
;
157 } else if (parse_attr_contains("release", nbut
, "action")) {
158 uact
= OB_USER_ACTION_MOUSE_RELEASE
;
159 mact
= OB_MOUSE_ACTION_RELEASE
;
160 } else if (parse_attr_contains("click", nbut
, "action")) {
161 uact
= OB_USER_ACTION_MOUSE_CLICK
;
162 mact
= OB_MOUSE_ACTION_CLICK
;
163 } else if (parse_attr_contains("doubleclick", nbut
,"action")) {
164 uact
= OB_USER_ACTION_MOUSE_DOUBLE_CLICK
;
165 mact
= OB_MOUSE_ACTION_DOUBLE_CLICK
;
166 } else if (parse_attr_contains("drag", nbut
, "action")) {
167 uact
= OB_USER_ACTION_MOUSE_MOTION
;
168 mact
= OB_MOUSE_ACTION_MOTION
;
171 nact
= parse_find_node("action", nbut
->children
);
173 if ((action
= action_parse(i
, doc
, nact
, uact
)))
174 mouse_bind(buttonstr
, contextstr
, mact
, action
);
175 nact
= parse_find_node("action", nact
->next
);
179 nbut
= parse_find_node("mousebind", nbut
->next
);
183 n
= parse_find_node("context", n
->next
);
187 static void parse_focus(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
192 node
= node
->children
;
194 if ((n
= parse_find_node("focusNew", node
)))
195 config_focus_new
= parse_bool(doc
, n
);
196 if ((n
= parse_find_node("followMouse", node
)))
197 config_focus_follow
= parse_bool(doc
, n
);
198 if ((n
= parse_find_node("focusDelay", node
)))
199 config_focus_delay
= parse_int(doc
, n
) * 1000;
202 static void parse_theme(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
207 node
= node
->children
;
209 if ((n
= parse_find_node("name", node
))) {
212 g_free(config_theme
);
213 c
= parse_string(doc
, n
);
214 config_theme
= parse_expand_tilde(c
);
217 if ((n
= parse_find_node("titleLayout", node
))) {
218 g_free(config_title_layout
);
219 config_title_layout
= parse_string(doc
, n
);
223 static void parse_desktops(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
228 node
= node
->children
;
230 if ((n
= parse_find_node("number", node
)))
231 config_desktops_num
= parse_int(doc
, n
);
232 if ((n
= parse_find_node("names", node
))) {
236 for (it
= config_desktops_names
; it
; it
= it
->next
)
238 g_slist_free(config_desktops_names
);
239 config_desktops_names
= NULL
;
241 nname
= parse_find_node("name", n
->children
);
243 config_desktops_names
= g_slist_append(config_desktops_names
,
244 parse_string(doc
, nname
));
245 nname
= parse_find_node("name", nname
->next
);
250 static void parse_resize(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
255 node
= node
->children
;
257 if ((n
= parse_find_node("drawContents", node
)))
258 config_redraw_resize
= parse_bool(doc
, n
);
261 static void parse_dock(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
, void *d
)
265 node
= node
->children
;
267 if ((n
= parse_find_node("position", node
))) {
268 if (parse_contains("TopLeft", doc
, n
))
269 config_dock_floating
= FALSE
,
270 config_dock_pos
= OB_DIRECTION_NORTHWEST
;
271 else if (parse_contains("Top", doc
, n
))
272 config_dock_floating
= FALSE
,
273 config_dock_pos
= OB_DIRECTION_NORTH
;
274 else if (parse_contains("TopRight", doc
, n
))
275 config_dock_floating
= FALSE
,
276 config_dock_pos
= OB_DIRECTION_NORTHEAST
;
277 else if (parse_contains("Right", doc
, n
))
278 config_dock_floating
= FALSE
,
279 config_dock_pos
= OB_DIRECTION_EAST
;
280 else if (parse_contains("BottomRight", doc
, n
))
281 config_dock_floating
= FALSE
,
282 config_dock_pos
= OB_DIRECTION_SOUTHEAST
;
283 else if (parse_contains("Bottom", doc
, n
))
284 config_dock_floating
= FALSE
,
285 config_dock_pos
= OB_DIRECTION_SOUTH
;
286 else if (parse_contains("BottomLeft", doc
, n
))
287 config_dock_floating
= FALSE
,
288 config_dock_pos
= OB_DIRECTION_SOUTHWEST
;
289 else if (parse_contains("Left", doc
, n
))
290 config_dock_floating
= FALSE
,
291 config_dock_pos
= OB_DIRECTION_WEST
;
292 else if (parse_contains("Floating", doc
, n
))
293 config_dock_floating
= TRUE
;
295 if (config_dock_floating
) {
296 if ((n
= parse_find_node("floatingX", node
)))
297 config_dock_x
= parse_int(doc
, n
);
298 if ((n
= parse_find_node("floatingY", node
)))
299 config_dock_y
= parse_int(doc
, n
);
301 if ((n
= parse_find_node("stacking", node
))) {
302 if (parse_contains("top", doc
, n
))
303 config_dock_layer
= OB_STACKING_LAYER_TOP
;
304 else if (parse_contains("normal", doc
, n
))
305 config_dock_layer
= OB_STACKING_LAYER_NORMAL
;
306 else if (parse_contains("bottom", doc
, n
))
307 config_dock_layer
= OB_STACKING_LAYER_BELOW
;
309 if ((n
= parse_find_node("direction", node
))) {
310 if (parse_contains("horizontal", doc
, n
))
311 config_dock_orient
= OB_ORIENTATION_HORZ
;
312 else if (parse_contains("vertical", doc
, n
))
313 config_dock_orient
= OB_ORIENTATION_VERT
;
315 if ((n
= parse_find_node("autoHide", node
)))
316 config_dock_hide
= parse_bool(doc
, n
);
317 if ((n
= parse_find_node("hideTimeout", node
)))
318 config_dock_hide_timeout
= parse_int(doc
, n
) * 1000;
321 static void parse_menu(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
, void *d
)
323 for (node
= node
->children
; node
; node
= node
->next
) {
324 if (!xmlStrcasecmp(node
->name
, (const xmlChar
*) "file")) {
327 c
= parse_string(doc
, node
);
328 config_menu_files
= g_slist_append(config_menu_files
,
329 parse_expand_tilde(c
));
335 static void parse_resistance(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
340 node
= node
->children
;
341 if ((n
= parse_find_node("strength", node
)))
342 config_resist_win
= parse_int(doc
, n
);
343 if ((n
= parse_find_node("screen_edge_strength", node
)))
344 config_resist_edge
= parse_int(doc
, n
);
350 const gchar
*actname
;
353 static void bind_default_keyboard()
356 ObDefKeyBind binds
[] = {
357 { "A-Tab", "NextWindow" },
358 { "S-A-Tab", "PreviousWindow" },
359 { "C-A-Right", "DesktopRight" },
360 { "C-A-Left", "DesktopLeft" },
361 { "C-A-Up", "DesktopUp" },
362 { "C-A-Down", "DesktopDown" },
363 { "S-A-Right", "SendToDesktopRight" },
364 { "S-A-Left", "SendToDesktopLeft" },
365 { "S-A-Up", "SendToDesktopUp" },
366 { "S-A-Down", "SendToDesktopDown" },
367 { "A-F10", "MaximizeFull" },
368 { "A-F5", "UnmaximizeFull" },
369 { "A-F12", "ToggleShade" },
372 { "A-F8", "Resize" },
373 { "A-F9", "Iconify" },
377 for (it
= binds
; it
->key
; ++it
) {
378 GList
*l
= g_list_append(NULL
, g_strdup(it
->key
));
379 keyboard_bind(l
, action_from_string(it
->actname
,
380 OB_USER_ACTION_KEYBOARD_KEY
));
387 const gchar
*context
;
389 const gchar
*actname
;
392 static void bind_default_mouse()
395 ObDefMouseBind binds
[] = {
396 { "Up", "Desktop", OB_MOUSE_ACTION_PRESS
, "DesktopNext" },
397 { "Down", "Desktop", OB_MOUSE_ACTION_PRESS
, "DesktopPrevious" },
398 { "A-Up", "Desktop", OB_MOUSE_ACTION_PRESS
, "DesktopNext" },
399 { "A-Down", "Desktop", OB_MOUSE_ACTION_PRESS
, "DesktopPrevious" },
400 { "A-Up", "Frame", OB_MOUSE_ACTION_PRESS
, "DesktopNext" },
401 { "A-Down", "Frame", OB_MOUSE_ACTION_PRESS
, "DesktopPrevious" },
402 { "A-Up", "MoveResize", OB_MOUSE_ACTION_PRESS
, "DesktopNext" },
403 { "Down", "MoveResize", OB_MOUSE_ACTION_PRESS
, "DesktopPrevious" },
404 { "Left", "Client", OB_MOUSE_ACTION_PRESS
, "Focus" },
405 { "Middle", "Client", OB_MOUSE_ACTION_PRESS
, "Focus" },
406 { "Right", "Client", OB_MOUSE_ACTION_PRESS
, "Focus" },
407 { "Left", "Desktop", OB_MOUSE_ACTION_PRESS
, "Focus" },
408 { "Middle", "Desktop", OB_MOUSE_ACTION_PRESS
, "Focus" },
409 { "Right", "Desktop", OB_MOUSE_ACTION_PRESS
, "Focus" },
410 { "Left", "Titlebar", OB_MOUSE_ACTION_PRESS
, "Focus" },
411 { "Left", "Handle", OB_MOUSE_ACTION_PRESS
, "Focus" },
412 { "Left", "BLCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
413 { "Left", "BRCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
414 { "Left", "TLCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
415 { "Left", "TRCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
416 { "Left", "Close", OB_MOUSE_ACTION_PRESS
, "Focus" },
417 { "Left", "Maximize", OB_MOUSE_ACTION_PRESS
, "Focus" },
418 { "Left", "Iconify", OB_MOUSE_ACTION_PRESS
, "Focus" },
419 { "Left", "Icon", OB_MOUSE_ACTION_PRESS
, "Focus" },
420 { "Left", "AllDesktops", OB_MOUSE_ACTION_PRESS
, "Focus" },
421 { "Left", "Shade", OB_MOUSE_ACTION_PRESS
, "Focus" },
422 { "Left", "Client", OB_MOUSE_ACTION_CLICK
, "Raise" },
423 { "Left", "Titlebar", OB_MOUSE_ACTION_CLICK
, "Raise" },
424 { "Middle", "Titlebar", OB_MOUSE_ACTION_CLICK
, "Lower" },
425 { "Left", "Handle", OB_MOUSE_ACTION_CLICK
, "Raise" },
426 { "Left", "BLCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
427 { "Left", "BRCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
428 { "Left", "TLCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
429 { "Left", "TRCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
430 { "Left", "Close", OB_MOUSE_ACTION_CLICK
, "Raise" },
431 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK
, "Raise" },
432 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK
, "Raise" },
433 { "Left", "Icon", OB_MOUSE_ACTION_CLICK
, "Raise" },
434 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK
, "Raise" },
435 { "Left", "Shade", OB_MOUSE_ACTION_CLICK
, "Raise" },
436 { "Left", "Close", OB_MOUSE_ACTION_CLICK
, "Close" },
437 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK
, "ToggleMaximizeFull" },
438 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK
, "Iconify" },
439 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK
, "ToggleOmnipresent" },
440 { "Left", "Shade", OB_MOUSE_ACTION_CLICK
, "ToggleShade" },
441 { "Left", "TLCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
442 { "Left", "TRCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
443 { "Left", "BLCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
444 { "Left", "BRCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
445 { "Left", "Titlebar", OB_MOUSE_ACTION_MOTION
, "Move" },
446 { "A-Left", "Frame", OB_MOUSE_ACTION_MOTION
, "Move" },
447 { "A-Middle", "Frame", OB_MOUSE_ACTION_MOTION
, "Resize" },
448 { NULL
, NULL
, 0, NULL
}
451 for (it
= binds
; it
->button
; ++it
) {
454 case OB_MOUSE_ACTION_PRESS
:
455 uact
= OB_USER_ACTION_MOUSE_PRESS
; break;
456 case OB_MOUSE_ACTION_RELEASE
:
457 uact
= OB_USER_ACTION_MOUSE_RELEASE
; break;
458 case OB_MOUSE_ACTION_CLICK
:
459 uact
= OB_USER_ACTION_MOUSE_CLICK
; break;
460 case OB_MOUSE_ACTION_DOUBLE_CLICK
:
461 uact
= OB_USER_ACTION_MOUSE_DOUBLE_CLICK
; break;
462 case OB_MOUSE_ACTION_MOTION
:
463 uact
= OB_USER_ACTION_MOUSE_MOTION
; break;
464 case OB_NUM_MOUSE_ACTIONS
:
465 g_assert_not_reached();
467 mouse_bind(it
->button
, it
->context
, it
->mact
,
468 action_from_string(it
->actname
, uact
));
472 void config_startup(ObParseInst
*i
)
474 config_focus_new
= TRUE
;
475 config_focus_follow
= FALSE
;
476 config_focus_delay
= 0;
478 parse_register(i
, "focus", parse_focus
, NULL
);
482 config_title_layout
= g_strdup("NLIMC");
484 parse_register(i
, "theme", parse_theme
, NULL
);
486 config_desktops_num
= 4;
487 config_desktops_names
= NULL
;
489 parse_register(i
, "desktops", parse_desktops
, NULL
);
491 config_redraw_resize
= TRUE
;
493 parse_register(i
, "resize", parse_resize
, NULL
);
495 config_dock_layer
= OB_STACKING_LAYER_TOP
;
496 config_dock_pos
= OB_DIRECTION_NORTHEAST
;
497 config_dock_floating
= FALSE
;
500 config_dock_orient
= OB_ORIENTATION_VERT
;
501 config_dock_hide
= FALSE
;
502 config_dock_hide_timeout
= 300;
504 parse_register(i
, "dock", parse_dock
, NULL
);
506 translate_key("C-g", &config_keyboard_reset_state
,
507 &config_keyboard_reset_keycode
);
509 bind_default_keyboard();
511 parse_register(i
, "keyboard", parse_keyboard
, NULL
);
513 config_mouse_threshold
= 3;
514 config_mouse_dclicktime
= 200;
516 bind_default_mouse();
518 parse_register(i
, "mouse", parse_mouse
, NULL
);
520 config_resist_win
= 10;
521 config_resist_edge
= 20;
523 parse_register(i
, "resistance", parse_resistance
, NULL
);
525 config_menu_files
= NULL
;
527 parse_register(i
, "menu", parse_menu
, NULL
);
530 void config_shutdown()
534 g_free(config_theme
);
536 g_free(config_title_layout
);
538 for (it
= config_desktops_names
; it
; it
= g_slist_next(it
))
540 g_slist_free(config_desktops_names
);
542 for (it
= config_menu_files
; it
; it
= g_slist_next(it
))
544 g_slist_free(config_menu_files
);