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_delay
;
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 guint d
= parse_int(doc
, n
);
233 config_desktops_num
= d
;
235 if ((n
= parse_find_node("names", node
))) {
239 for (it
= config_desktops_names
; it
; it
= it
->next
)
241 g_slist_free(config_desktops_names
);
242 config_desktops_names
= NULL
;
244 nname
= parse_find_node("name", n
->children
);
246 config_desktops_names
= g_slist_append(config_desktops_names
,
247 parse_string(doc
, nname
));
248 nname
= parse_find_node("name", nname
->next
);
253 static void parse_resize(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
258 node
= node
->children
;
260 if ((n
= parse_find_node("drawContents", node
)))
261 config_redraw_resize
= parse_bool(doc
, n
);
264 static void parse_dock(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
, void *d
)
268 node
= node
->children
;
270 if ((n
= parse_find_node("position", node
))) {
271 if (parse_contains("TopLeft", doc
, n
))
272 config_dock_floating
= FALSE
,
273 config_dock_pos
= OB_DIRECTION_NORTHWEST
;
274 else if (parse_contains("Top", doc
, n
))
275 config_dock_floating
= FALSE
,
276 config_dock_pos
= OB_DIRECTION_NORTH
;
277 else if (parse_contains("TopRight", doc
, n
))
278 config_dock_floating
= FALSE
,
279 config_dock_pos
= OB_DIRECTION_NORTHEAST
;
280 else if (parse_contains("Right", doc
, n
))
281 config_dock_floating
= FALSE
,
282 config_dock_pos
= OB_DIRECTION_EAST
;
283 else if (parse_contains("BottomRight", doc
, n
))
284 config_dock_floating
= FALSE
,
285 config_dock_pos
= OB_DIRECTION_SOUTHEAST
;
286 else if (parse_contains("Bottom", doc
, n
))
287 config_dock_floating
= FALSE
,
288 config_dock_pos
= OB_DIRECTION_SOUTH
;
289 else if (parse_contains("BottomLeft", doc
, n
))
290 config_dock_floating
= FALSE
,
291 config_dock_pos
= OB_DIRECTION_SOUTHWEST
;
292 else if (parse_contains("Left", doc
, n
))
293 config_dock_floating
= FALSE
,
294 config_dock_pos
= OB_DIRECTION_WEST
;
295 else if (parse_contains("Floating", doc
, n
))
296 config_dock_floating
= TRUE
;
298 if (config_dock_floating
) {
299 if ((n
= parse_find_node("floatingX", node
)))
300 config_dock_x
= parse_int(doc
, n
);
301 if ((n
= parse_find_node("floatingY", node
)))
302 config_dock_y
= parse_int(doc
, n
);
304 if ((n
= parse_find_node("stacking", node
))) {
305 if (parse_contains("top", doc
, n
))
306 config_dock_layer
= OB_STACKING_LAYER_TOP
;
307 else if (parse_contains("normal", doc
, n
))
308 config_dock_layer
= OB_STACKING_LAYER_NORMAL
;
309 else if (parse_contains("bottom", doc
, n
))
310 config_dock_layer
= OB_STACKING_LAYER_BELOW
;
312 if ((n
= parse_find_node("direction", node
))) {
313 if (parse_contains("horizontal", doc
, n
))
314 config_dock_orient
= OB_ORIENTATION_HORZ
;
315 else if (parse_contains("vertical", doc
, n
))
316 config_dock_orient
= OB_ORIENTATION_VERT
;
318 if ((n
= parse_find_node("autoHide", node
)))
319 config_dock_hide
= parse_bool(doc
, n
);
320 if ((n
= parse_find_node("hideDelay", node
)))
321 config_dock_hide_delay
= parse_int(doc
, n
) * 1000;
324 static void parse_menu(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
, void *d
)
326 for (node
= node
->children
; node
; node
= node
->next
) {
327 if (!xmlStrcasecmp(node
->name
, (const xmlChar
*) "file")) {
330 c
= parse_string(doc
, node
);
331 config_menu_files
= g_slist_append(config_menu_files
,
332 parse_expand_tilde(c
));
338 static void parse_resistance(ObParseInst
*i
, xmlDocPtr doc
, xmlNodePtr node
,
343 node
= node
->children
;
344 if ((n
= parse_find_node("strength", node
)))
345 config_resist_win
= parse_int(doc
, n
);
346 if ((n
= parse_find_node("screen_edge_strength", node
)))
347 config_resist_edge
= parse_int(doc
, n
);
353 const gchar
*actname
;
356 static void bind_default_keyboard()
359 ObDefKeyBind binds
[] = {
360 { "A-Tab", "NextWindow" },
361 { "S-A-Tab", "PreviousWindow" },
362 { "C-A-Right", "DesktopRight" },
363 { "C-A-Left", "DesktopLeft" },
364 { "C-A-Up", "DesktopUp" },
365 { "C-A-Down", "DesktopDown" },
366 { "S-A-Right", "SendToDesktopRight" },
367 { "S-A-Left", "SendToDesktopLeft" },
368 { "S-A-Up", "SendToDesktopUp" },
369 { "S-A-Down", "SendToDesktopDown" },
370 { "A-F10", "MaximizeFull" },
371 { "A-F5", "UnmaximizeFull" },
372 { "A-F12", "ToggleShade" },
375 { "A-F8", "Resize" },
376 { "A-F9", "Iconify" },
380 for (it
= binds
; it
->key
; ++it
) {
381 GList
*l
= g_list_append(NULL
, g_strdup(it
->key
));
382 keyboard_bind(l
, action_from_string(it
->actname
,
383 OB_USER_ACTION_KEYBOARD_KEY
));
390 const gchar
*context
;
391 const ObMouseAction mact
;
392 const gchar
*actname
;
395 static void bind_default_mouse()
398 ObDefMouseBind binds
[] = {
399 { "Up", "Desktop", OB_MOUSE_ACTION_PRESS
, "DesktopNext" },
400 { "Down", "Desktop", OB_MOUSE_ACTION_PRESS
, "DesktopPrevious" },
401 { "A-Up", "Desktop", OB_MOUSE_ACTION_PRESS
, "DesktopNext" },
402 { "A-Down", "Desktop", OB_MOUSE_ACTION_PRESS
, "DesktopPrevious" },
403 { "A-Up", "Frame", OB_MOUSE_ACTION_PRESS
, "DesktopNext" },
404 { "A-Down", "Frame", OB_MOUSE_ACTION_PRESS
, "DesktopPrevious" },
405 { "A-Up", "MoveResize", OB_MOUSE_ACTION_PRESS
, "DesktopNext" },
406 { "Down", "MoveResize", OB_MOUSE_ACTION_PRESS
, "DesktopPrevious" },
407 { "Left", "Client", OB_MOUSE_ACTION_PRESS
, "Focus" },
408 { "Middle", "Client", OB_MOUSE_ACTION_PRESS
, "Focus" },
409 { "Right", "Client", OB_MOUSE_ACTION_PRESS
, "Focus" },
410 { "Left", "Desktop", OB_MOUSE_ACTION_PRESS
, "Focus" },
411 { "Middle", "Desktop", OB_MOUSE_ACTION_PRESS
, "Focus" },
412 { "Right", "Desktop", OB_MOUSE_ACTION_PRESS
, "Focus" },
413 { "Left", "Titlebar", OB_MOUSE_ACTION_PRESS
, "Focus" },
414 { "Left", "Handle", OB_MOUSE_ACTION_PRESS
, "Focus" },
415 { "Left", "BLCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
416 { "Left", "BRCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
417 { "Left", "TLCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
418 { "Left", "TRCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
419 { "Left", "Close", OB_MOUSE_ACTION_PRESS
, "Focus" },
420 { "Left", "Maximize", OB_MOUSE_ACTION_PRESS
, "Focus" },
421 { "Left", "Iconify", OB_MOUSE_ACTION_PRESS
, "Focus" },
422 { "Left", "Icon", OB_MOUSE_ACTION_PRESS
, "Focus" },
423 { "Left", "AllDesktops", OB_MOUSE_ACTION_PRESS
, "Focus" },
424 { "Left", "Shade", OB_MOUSE_ACTION_PRESS
, "Focus" },
425 { "Left", "Client", OB_MOUSE_ACTION_CLICK
, "Raise" },
426 { "Left", "Titlebar", OB_MOUSE_ACTION_CLICK
, "Raise" },
427 { "Middle", "Titlebar", OB_MOUSE_ACTION_CLICK
, "Lower" },
428 { "Left", "Handle", OB_MOUSE_ACTION_CLICK
, "Raise" },
429 { "Left", "BLCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
430 { "Left", "BRCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
431 { "Left", "TLCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
432 { "Left", "TRCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
433 { "Left", "Close", OB_MOUSE_ACTION_CLICK
, "Raise" },
434 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK
, "Raise" },
435 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK
, "Raise" },
436 { "Left", "Icon", OB_MOUSE_ACTION_CLICK
, "Raise" },
437 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK
, "Raise" },
438 { "Left", "Shade", OB_MOUSE_ACTION_CLICK
, "Raise" },
439 { "Left", "Close", OB_MOUSE_ACTION_CLICK
, "Close" },
440 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK
, "ToggleMaximizeFull" },
441 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK
, "Iconify" },
442 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK
, "ToggleOmnipresent" },
443 { "Left", "Shade", OB_MOUSE_ACTION_CLICK
, "ToggleShade" },
444 { "Left", "TLCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
445 { "Left", "TRCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
446 { "Left", "BLCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
447 { "Left", "BRCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
448 { "Left", "Titlebar", OB_MOUSE_ACTION_MOTION
, "Move" },
449 { "A-Left", "Frame", OB_MOUSE_ACTION_MOTION
, "Move" },
450 { "A-Middle", "Frame", OB_MOUSE_ACTION_MOTION
, "Resize" },
451 { NULL
, NULL
, 0, NULL
}
454 for (it
= binds
; it
->button
; ++it
) {
457 case OB_MOUSE_ACTION_PRESS
:
458 uact
= OB_USER_ACTION_MOUSE_PRESS
; break;
459 case OB_MOUSE_ACTION_RELEASE
:
460 uact
= OB_USER_ACTION_MOUSE_RELEASE
; break;
461 case OB_MOUSE_ACTION_CLICK
:
462 uact
= OB_USER_ACTION_MOUSE_CLICK
; break;
463 case OB_MOUSE_ACTION_DOUBLE_CLICK
:
464 uact
= OB_USER_ACTION_MOUSE_DOUBLE_CLICK
; break;
465 case OB_MOUSE_ACTION_MOTION
:
466 uact
= OB_USER_ACTION_MOUSE_MOTION
; break;
467 case OB_NUM_MOUSE_ACTIONS
:
468 g_assert_not_reached();
470 mouse_bind(it
->button
, it
->context
, it
->mact
,
471 action_from_string(it
->actname
, uact
));
475 void config_startup(ObParseInst
*i
)
477 config_focus_new
= TRUE
;
478 config_focus_follow
= FALSE
;
479 config_focus_delay
= 0;
481 parse_register(i
, "focus", parse_focus
, NULL
);
485 config_title_layout
= g_strdup("NLIMC");
487 parse_register(i
, "theme", parse_theme
, NULL
);
489 config_desktops_num
= 4;
490 config_desktops_names
= NULL
;
492 parse_register(i
, "desktops", parse_desktops
, NULL
);
494 config_redraw_resize
= TRUE
;
496 parse_register(i
, "resize", parse_resize
, NULL
);
498 config_dock_layer
= OB_STACKING_LAYER_TOP
;
499 config_dock_pos
= OB_DIRECTION_NORTHEAST
;
500 config_dock_floating
= FALSE
;
503 config_dock_orient
= OB_ORIENTATION_VERT
;
504 config_dock_hide
= FALSE
;
505 config_dock_hide_delay
= 300;
507 parse_register(i
, "dock", parse_dock
, NULL
);
509 translate_key("C-g", &config_keyboard_reset_state
,
510 &config_keyboard_reset_keycode
);
512 bind_default_keyboard();
514 parse_register(i
, "keyboard", parse_keyboard
, NULL
);
516 config_mouse_threshold
= 3;
517 config_mouse_dclicktime
= 200;
519 bind_default_mouse();
521 parse_register(i
, "mouse", parse_mouse
, NULL
);
523 config_resist_win
= 10;
524 config_resist_edge
= 20;
526 parse_register(i
, "resistance", parse_resistance
, NULL
);
528 config_menu_files
= NULL
;
530 parse_register(i
, "menu", parse_menu
, NULL
);
533 void config_shutdown()
537 g_free(config_theme
);
539 g_free(config_title_layout
);
541 for (it
= config_desktops_names
; it
; it
= g_slist_next(it
))
543 g_slist_free(config_desktops_names
);
545 for (it
= config_menu_files
; it
; it
= g_slist_next(it
))
547 g_slist_free(config_menu_files
);