1 /* -*- indent-tabs-mode: nil; tab-width: 4; c-basic-offset: 4; -*-
3 config.c for the Openbox window manager
4 Copyright (c) 2006 Mikael Magnusson
5 Copyright (c) 2003-2007 Dana 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"
29 #include "obt/paths.h"
31 gboolean config_focus_new
;
32 gboolean config_focus_follow
;
33 guint config_focus_delay
;
34 gboolean config_focus_raise
;
35 gboolean config_focus_last
;
36 gboolean config_focus_under_mouse
;
37 gboolean config_unfocus_leave
;
39 ObPlacePolicy config_place_policy
;
40 gboolean config_place_center
;
41 ObPlaceMonitor config_place_monitor
;
43 guint config_primary_monitor_index
;
44 ObPlaceMonitor config_primary_monitor
;
46 StrutPartial config_margins
;
49 gboolean config_theme_keepborder
;
50 guint config_theme_window_list_icon_size
;
52 gchar
*config_title_layout
;
54 gboolean config_animate_iconify
;
56 RrFont
*config_font_activewindow
;
57 RrFont
*config_font_inactivewindow
;
58 RrFont
*config_font_menuitem
;
59 RrFont
*config_font_menutitle
;
60 RrFont
*config_font_activeosd
;
61 RrFont
*config_font_inactiveosd
;
63 guint config_desktops_num
;
64 GSList
*config_desktops_names
;
65 guint config_screen_firstdesk
;
66 guint config_desktop_popup_time
;
68 gboolean config_resize_redraw
;
69 gint config_resize_popup_show
;
70 ObResizePopupPos config_resize_popup_pos
;
71 GravityPoint config_resize_popup_fixed
;
73 ObStackingLayer config_dock_layer
;
74 gboolean config_dock_floating
;
75 gboolean config_dock_nostrut
;
76 ObDirection config_dock_pos
;
79 ObOrientation config_dock_orient
;
80 gboolean config_dock_hide
;
81 guint config_dock_hide_delay
;
82 guint config_dock_show_delay
;
83 guint config_dock_app_move_button
;
84 guint config_dock_app_move_modifiers
;
86 guint config_keyboard_reset_keycode
;
87 guint config_keyboard_reset_state
;
89 gint config_mouse_threshold
;
90 gint config_mouse_dclicktime
;
91 gint config_mouse_screenedgetime
;
92 gboolean config_mouse_screenedgewarp
;
94 guint config_menu_hide_delay
;
95 gboolean config_menu_middle
;
96 guint config_submenu_show_delay
;
97 guint config_submenu_hide_delay
;
98 gboolean config_menu_manage_desktops
;
99 gboolean config_menu_show_icons
;
101 GSList
*config_menu_files
;
103 gint config_resist_win
;
104 gint config_resist_edge
;
106 GSList
*config_per_app_settings
;
108 ObAppSettings
* config_create_app_settings(void)
110 ObAppSettings
*settings
= g_slice_new0(ObAppSettings
);
112 settings
->decor
= -1;
113 settings
->shade
= -1;
114 settings
->monitor
= -1;
115 settings
->focus
= -1;
116 settings
->desktop
= 0;
117 settings
->layer
= -2;
118 settings
->iconic
= -1;
119 settings
->skip_pager
= -1;
120 settings
->skip_taskbar
= -1;
121 settings
->fullscreen
= -1;
122 settings
->max_horz
= -1;
123 settings
->max_vert
= -1;
127 #define copy_if(setting, default) \
128 if (src->setting != default) dst->setting = src->setting
129 void config_app_settings_copy_non_defaults(const ObAppSettings
*src
,
132 g_assert(src
!= NULL
);
133 g_assert(dst
!= NULL
);
135 copy_if(type
, (ObClientType
)-1);
138 copy_if(monitor
, -1);
143 copy_if(skip_pager
, -1);
144 copy_if(skip_taskbar
, -1);
145 copy_if(fullscreen
, -1);
146 copy_if(max_horz
, -1);
147 copy_if(max_vert
, -1);
149 if (src
->pos_given
) {
150 dst
->pos_given
= TRUE
;
151 dst
->pos_force
= src
->pos_force
;
152 dst
->position
= src
->position
;
153 /* monitor is copied above */
157 static void config_parse_gravity_coord(xmlNodePtr node
, GravityCoord
*c
)
159 gchar
*s
= obt_xml_node_string(node
);
160 if (!g_ascii_strcasecmp(s
, "center"))
165 if (s
[0] == '-' || s
[0] == '+')
175 <application name="aterm">
178 <application name="Rhythmbox">
185 .. there is a lot more settings available
190 /* Manages settings for individual applications.
191 Some notes: monitor is the screen number in a multi monitor
192 (Xinerama) setup (starting from 0) or mouse, meaning the
193 monitor the pointer is on. Default: mouse.
194 Layer can be three values, above (Always on top), below
195 (Always on bottom) and everything else (normal behaviour).
196 Positions can be an integer value or center, which will
197 center the window in the specified axis. Position is within
198 the monitor, so <position><x>center</x></position><monitor>2</monitor>
199 will center the window on the second monitor.
201 static void parse_per_app_settings(xmlNodePtr node
, gpointer d
)
203 xmlNodePtr app
= obt_xml_find_node(node
->children
, "application");
204 gchar
*name
= NULL
, *class = NULL
, *role
= NULL
, *title
= NULL
,
206 gboolean name_set
, class_set
, type_set
, role_set
, title_set
;
208 gboolean x_pos_given
;
213 class_set
= obt_xml_attr_string(app
, "class", &class);
214 name_set
= obt_xml_attr_string(app
, "name", &name
);
215 type_set
= obt_xml_attr_string(app
, "type", &type_str
);
216 role_set
= obt_xml_attr_string(app
, "role", &role
);
217 title_set
= obt_xml_attr_string(app
, "title", &title
);
219 /* validate the type tho */
221 if (!g_ascii_strcasecmp(type_str
, "normal"))
222 type
= OB_CLIENT_TYPE_NORMAL
;
223 else if (!g_ascii_strcasecmp(type_str
, "dialog"))
224 type
= OB_CLIENT_TYPE_DIALOG
;
225 else if (!g_ascii_strcasecmp(type_str
, "splash"))
226 type
= OB_CLIENT_TYPE_SPLASH
;
227 else if (!g_ascii_strcasecmp(type_str
, "utility"))
228 type
= OB_CLIENT_TYPE_UTILITY
;
229 else if (!g_ascii_strcasecmp(type_str
, "menu"))
230 type
= OB_CLIENT_TYPE_MENU
;
231 else if (!g_ascii_strcasecmp(type_str
, "toolbar"))
232 type
= OB_CLIENT_TYPE_TOOLBAR
;
233 else if (!g_ascii_strcasecmp(type_str
, "dock"))
234 type
= OB_CLIENT_TYPE_DOCK
;
235 else if (!g_ascii_strcasecmp(type_str
, "desktop"))
236 type
= OB_CLIENT_TYPE_DESKTOP
;
238 type_set
= FALSE
; /* not valid! */
241 if (class_set
|| name_set
|| role_set
|| title_set
|| type_set
) {
243 ObAppSettings
*settings
= config_create_app_settings();
246 settings
->name
= g_pattern_spec_new(name
);
249 settings
->class = g_pattern_spec_new(class);
252 settings
->role
= g_pattern_spec_new(role
);
255 settings
->title
= g_pattern_spec_new(title
);
258 settings
->type
= type
;
260 if ((n
= obt_xml_find_node(app
->children
, "decor")))
261 if (!obt_xml_node_contains(n
, "default"))
262 settings
->decor
= obt_xml_node_bool(n
);
264 if ((n
= obt_xml_find_node(app
->children
, "shade")))
265 if (!obt_xml_node_contains(n
, "default"))
266 settings
->shade
= obt_xml_node_bool(n
);
268 if ((n
= obt_xml_find_node(app
->children
, "position"))) {
269 if ((c
= obt_xml_find_node(n
->children
, "x")))
270 if (!obt_xml_node_contains(c
, "default")) {
271 config_parse_gravity_coord(c
, &settings
->position
.x
);
275 if (x_pos_given
&& (c
= obt_xml_find_node(n
->children
, "y")))
276 if (!obt_xml_node_contains(c
, "default")) {
277 config_parse_gravity_coord(c
, &settings
->position
.y
);
278 settings
->pos_given
= TRUE
;
281 if (settings
->pos_given
&&
282 (c
= obt_xml_find_node(n
->children
, "monitor")))
283 if (!obt_xml_node_contains(c
, "default")) {
284 gchar
*s
= obt_xml_node_string(c
);
285 if (!g_ascii_strcasecmp(s
, "mouse"))
286 settings
->monitor
= 0;
288 settings
->monitor
= obt_xml_node_int(c
);
292 obt_xml_attr_bool(n
, "force", &settings
->pos_force
);
295 if ((n
= obt_xml_find_node(app
->children
, "focus")))
296 if (!obt_xml_node_contains(n
, "default"))
297 settings
->focus
= obt_xml_node_bool(n
);
299 if ((n
= obt_xml_find_node(app
->children
, "desktop"))) {
300 if (!obt_xml_node_contains(n
, "default")) {
301 gchar
*s
= obt_xml_node_string(n
);
302 if (!g_ascii_strcasecmp(s
, "all"))
303 settings
->desktop
= DESKTOP_ALL
;
305 gint i
= obt_xml_node_int(n
);
307 settings
->desktop
= i
;
313 if ((n
= obt_xml_find_node(app
->children
, "layer")))
314 if (!obt_xml_node_contains(n
, "default")) {
315 gchar
*s
= obt_xml_node_string(n
);
316 if (!g_ascii_strcasecmp(s
, "above"))
318 else if (!g_ascii_strcasecmp(s
, "below"))
319 settings
->layer
= -1;
325 if ((n
= obt_xml_find_node(app
->children
, "iconic")))
326 if (!obt_xml_node_contains(n
, "default"))
327 settings
->iconic
= obt_xml_node_bool(n
);
329 if ((n
= obt_xml_find_node(app
->children
, "skip_pager")))
330 if (!obt_xml_node_contains(n
, "default"))
331 settings
->skip_pager
= obt_xml_node_bool(n
);
333 if ((n
= obt_xml_find_node(app
->children
, "skip_taskbar")))
334 if (!obt_xml_node_contains(n
, "default"))
335 settings
->skip_taskbar
= obt_xml_node_bool(n
);
337 if ((n
= obt_xml_find_node(app
->children
, "fullscreen")))
338 if (!obt_xml_node_contains(n
, "default"))
339 settings
->fullscreen
= obt_xml_node_bool(n
);
341 if ((n
= obt_xml_find_node(app
->children
, "maximized")))
342 if (!obt_xml_node_contains(n
, "default")) {
343 gchar
*s
= obt_xml_node_string(n
);
344 if (!g_ascii_strcasecmp(s
, "horizontal")) {
345 settings
->max_horz
= TRUE
;
346 settings
->max_vert
= FALSE
;
347 } else if (!g_ascii_strcasecmp(s
, "vertical")) {
348 settings
->max_horz
= FALSE
;
349 settings
->max_vert
= TRUE
;
351 settings
->max_horz
= settings
->max_vert
=
352 obt_xml_node_bool(n
);
356 config_per_app_settings
= g_slist_append(config_per_app_settings
,
357 (gpointer
) settings
);
362 name
= class = role
= title
= NULL
;
365 app
= obt_xml_find_node(app
->next
, "application");
372 <action name="ChangeDesktop">
379 static void parse_key(xmlNodePtr node
, GList
*keylist
)
383 gboolean is_chroot
= FALSE
;
385 if (!obt_xml_attr_string(node
, "key", &key
))
388 obt_xml_attr_bool(node
, "chroot", &is_chroot
);
390 keylist
= g_list_append(keylist
, key
);
392 if ((n
= obt_xml_find_node(node
->children
, "keybind"))) {
394 parse_key(n
, keylist
);
395 n
= obt_xml_find_node(n
->next
, "keybind");
398 else if ((n
= obt_xml_find_node(node
->children
, "action"))) {
400 ObActionsAct
*action
;
402 action
= actions_parse(n
);
404 keyboard_bind(keylist
, action
);
405 n
= obt_xml_find_node(n
->next
, "action");
410 keyboard_chroot(keylist
);
413 keylist
= g_list_delete_link(keylist
, g_list_last(keylist
));
416 static void parse_keyboard(xmlNodePtr node
, gpointer d
)
421 keyboard_unbind_all();
423 if ((n
= obt_xml_find_node(node
->children
, "chainQuitKey"))) {
424 key
= obt_xml_node_string(n
);
425 translate_key(key
, &config_keyboard_reset_state
,
426 &config_keyboard_reset_keycode
);
430 if ((n
= obt_xml_find_node(node
->children
, "keybind")))
433 n
= obt_xml_find_node(n
->next
, "keybind");
439 <context name="Titlebar">
440 <mousebind button="Left" action="Press">
441 <action name="Raise"></action>
447 static void parse_mouse(xmlNodePtr node
, gpointer d
)
449 xmlNodePtr n
, nbut
, nact
;
456 node
= node
->children
;
458 if ((n
= obt_xml_find_node(node
, "dragThreshold")))
459 config_mouse_threshold
= obt_xml_node_int(n
);
460 if ((n
= obt_xml_find_node(node
, "doubleClickTime")))
461 config_mouse_dclicktime
= obt_xml_node_int(n
);
462 if ((n
= obt_xml_find_node(node
, "screenEdgeWarpTime"))) {
463 config_mouse_screenedgetime
= obt_xml_node_int(n
);
464 /* minimum value of 25 for this property, when it is 1 and you hit the
465 edge it basically never stops */
466 if (config_mouse_screenedgetime
&& config_mouse_screenedgetime
< 25)
467 config_mouse_screenedgetime
= 25;
469 if ((n
= obt_xml_find_node(node
, "screenEdgeWarpMouse")))
470 config_mouse_screenedgewarp
= obt_xml_node_bool(n
);
472 n
= obt_xml_find_node(node
, "context");
474 if (!obt_xml_attr_string(n
, "name", &contextstr
))
476 nbut
= obt_xml_find_node(n
->children
, "mousebind");
478 if (!obt_xml_attr_string(nbut
, "button", &buttonstr
))
480 if (obt_xml_attr_contains(nbut
, "action", "press")) {
481 mact
= OB_MOUSE_ACTION_PRESS
;
482 } else if (obt_xml_attr_contains(nbut
, "action", "release")) {
483 mact
= OB_MOUSE_ACTION_RELEASE
;
484 } else if (obt_xml_attr_contains(nbut
, "action", "click")) {
485 mact
= OB_MOUSE_ACTION_CLICK
;
486 } else if (obt_xml_attr_contains(nbut
, "action","doubleclick")) {
487 mact
= OB_MOUSE_ACTION_DOUBLE_CLICK
;
488 } else if (obt_xml_attr_contains(nbut
, "action", "drag")) {
489 mact
= OB_MOUSE_ACTION_MOTION
;
492 nact
= obt_xml_find_node(nbut
->children
, "action");
494 ObActionsAct
*action
;
496 if ((action
= actions_parse(nact
)))
497 mouse_bind(buttonstr
, contextstr
, mact
, action
);
498 nact
= obt_xml_find_node(nact
->next
, "action");
502 nbut
= obt_xml_find_node(nbut
->next
, "mousebind");
506 n
= obt_xml_find_node(n
->next
, "context");
510 static void parse_focus(xmlNodePtr node
, gpointer d
)
514 node
= node
->children
;
516 if ((n
= obt_xml_find_node(node
, "focusNew")))
517 config_focus_new
= obt_xml_node_bool(n
);
518 if ((n
= obt_xml_find_node(node
, "followMouse")))
519 config_focus_follow
= obt_xml_node_bool(n
);
520 if ((n
= obt_xml_find_node(node
, "focusDelay")))
521 config_focus_delay
= obt_xml_node_int(n
);
522 if ((n
= obt_xml_find_node(node
, "raiseOnFocus")))
523 config_focus_raise
= obt_xml_node_bool(n
);
524 if ((n
= obt_xml_find_node(node
, "focusLast")))
525 config_focus_last
= obt_xml_node_bool(n
);
526 if ((n
= obt_xml_find_node(node
, "underMouse")))
527 config_focus_under_mouse
= obt_xml_node_bool(n
);
528 if ((n
= obt_xml_find_node(node
, "unfocusOnLeave")))
529 config_unfocus_leave
= obt_xml_node_bool(n
);
532 static void parse_placement(xmlNodePtr node
, gpointer d
)
536 node
= node
->children
;
538 if ((n
= obt_xml_find_node(node
, "policy")))
539 if (obt_xml_node_contains(n
, "UnderMouse"))
540 config_place_policy
= OB_PLACE_POLICY_MOUSE
;
541 if ((n
= obt_xml_find_node(node
, "center")))
542 config_place_center
= obt_xml_node_bool(n
);
543 if ((n
= obt_xml_find_node(node
, "monitor"))) {
544 if (obt_xml_node_contains(n
, "active"))
545 config_place_monitor
= OB_PLACE_MONITOR_ACTIVE
;
546 else if (obt_xml_node_contains(n
, "mouse"))
547 config_place_monitor
= OB_PLACE_MONITOR_MOUSE
;
549 if ((n
= obt_xml_find_node(node
, "primaryMonitor"))) {
550 config_primary_monitor_index
= obt_xml_node_int(n
);
551 if (!config_primary_monitor_index
) {
552 if (obt_xml_node_contains(n
, "mouse"))
553 config_primary_monitor
= OB_PLACE_MONITOR_MOUSE
;
558 static void parse_margins(xmlNodePtr node
, gpointer d
)
562 node
= node
->children
;
564 if ((n
= obt_xml_find_node(node
, "top")))
565 config_margins
.top
= MAX(0, obt_xml_node_int(n
));
566 if ((n
= obt_xml_find_node(node
, "left")))
567 config_margins
.left
= MAX(0, obt_xml_node_int(n
));
568 if ((n
= obt_xml_find_node(node
, "right")))
569 config_margins
.right
= MAX(0, obt_xml_node_int(n
));
570 if ((n
= obt_xml_find_node(node
, "bottom")))
571 config_margins
.bottom
= MAX(0, obt_xml_node_int(n
));
574 static void parse_theme(xmlNodePtr node
, gpointer d
)
578 node
= node
->children
;
580 if ((n
= obt_xml_find_node(node
, "name"))) {
583 g_free(config_theme
);
584 c
= obt_xml_node_string(n
);
585 config_theme
= obt_paths_expand_tilde(c
);
588 if ((n
= obt_xml_find_node(node
, "titleLayout"))) {
591 g_free(config_title_layout
);
592 config_title_layout
= obt_xml_node_string(n
);
594 /* replace duplicates with spaces */
595 for (c
= config_title_layout
; *c
!= '\0'; ++c
)
596 for (d
= c
+1; *d
!= '\0'; ++d
)
597 if (*c
== *d
) *d
= ' ';
599 if ((n
= obt_xml_find_node(node
, "keepBorder")))
600 config_theme_keepborder
= obt_xml_node_bool(n
);
601 if ((n
= obt_xml_find_node(node
, "animateIconify")))
602 config_animate_iconify
= obt_xml_node_bool(n
);
603 if ((n
= obt_xml_find_node(node
, "windowListIconSize"))) {
604 config_theme_window_list_icon_size
= obt_xml_node_int(n
);
605 if (config_theme_window_list_icon_size
< 16)
606 config_theme_window_list_icon_size
= 16;
607 else if (config_theme_window_list_icon_size
> 96)
608 config_theme_window_list_icon_size
= 96;
611 n
= obt_xml_find_node(node
, "font");
615 gchar
*name
= g_strdup(RrDefaultFontFamily
);
616 gint size
= RrDefaultFontSize
;
617 RrFontWeight weight
= RrDefaultFontWeight
;
618 RrFontSlant slant
= RrDefaultFontSlant
;
620 if (obt_xml_attr_contains(n
, "place", "ActiveWindow"))
621 font
= &config_font_activewindow
;
622 else if (obt_xml_attr_contains(n
, "place", "InactiveWindow"))
623 font
= &config_font_inactivewindow
;
624 else if (obt_xml_attr_contains(n
, "place", "MenuHeader"))
625 font
= &config_font_menutitle
;
626 else if (obt_xml_attr_contains(n
, "place", "MenuItem"))
627 font
= &config_font_menuitem
;
628 else if (obt_xml_attr_contains(n
, "place", "ActiveOnScreenDisplay"))
629 font
= &config_font_activeosd
;
630 else if (obt_xml_attr_contains(n
, "place", "OnScreenDisplay"))
631 font
= &config_font_activeosd
;
632 else if (obt_xml_attr_contains(n
, "place","InactiveOnScreenDisplay"))
633 font
= &config_font_inactiveosd
;
637 if ((fnode
= obt_xml_find_node(n
->children
, "name"))) {
639 name
= obt_xml_node_string(fnode
);
641 if ((fnode
= obt_xml_find_node(n
->children
, "size"))) {
642 int s
= obt_xml_node_int(fnode
);
645 if ((fnode
= obt_xml_find_node(n
->children
, "weight"))) {
646 gchar
*w
= obt_xml_node_string(fnode
);
647 if (!g_ascii_strcasecmp(w
, "Bold"))
648 weight
= RR_FONTWEIGHT_BOLD
;
651 if ((fnode
= obt_xml_find_node(n
->children
, "slant"))) {
652 gchar
*s
= obt_xml_node_string(fnode
);
653 if (!g_ascii_strcasecmp(s
, "Italic"))
654 slant
= RR_FONTSLANT_ITALIC
;
655 if (!g_ascii_strcasecmp(s
, "Oblique"))
656 slant
= RR_FONTSLANT_OBLIQUE
;
660 *font
= RrFontOpen(ob_rr_inst
, name
, size
, weight
, slant
);
663 n
= obt_xml_find_node(n
->next
, "font");
667 static void parse_desktops(xmlNodePtr node
, gpointer d
)
671 node
= node
->children
;
673 if ((n
= obt_xml_find_node(node
, "number"))) {
674 gint d
= obt_xml_node_int(n
);
676 config_desktops_num
= (unsigned) d
;
678 if ((n
= obt_xml_find_node(node
, "firstdesk"))) {
679 gint d
= obt_xml_node_int(n
);
681 config_screen_firstdesk
= (unsigned) d
;
683 if ((n
= obt_xml_find_node(node
, "names"))) {
687 for (it
= config_desktops_names
; it
; it
= it
->next
)
689 g_slist_free(config_desktops_names
);
690 config_desktops_names
= NULL
;
692 nname
= obt_xml_find_node(n
->children
, "name");
694 config_desktops_names
=
695 g_slist_append(config_desktops_names
,
696 obt_xml_node_string(nname
));
697 nname
= obt_xml_find_node(nname
->next
, "name");
700 if ((n
= obt_xml_find_node(node
, "popupTime")))
701 config_desktop_popup_time
= obt_xml_node_int(n
);
704 static void parse_resize(xmlNodePtr node
, gpointer d
)
708 node
= node
->children
;
710 if ((n
= obt_xml_find_node(node
, "drawContents")))
711 config_resize_redraw
= obt_xml_node_bool(n
);
712 if ((n
= obt_xml_find_node(node
, "popupShow"))) {
713 config_resize_popup_show
= obt_xml_node_int(n
);
714 if (obt_xml_node_contains(n
, "Always"))
715 config_resize_popup_show
= 2;
716 else if (obt_xml_node_contains(n
, "Never"))
717 config_resize_popup_show
= 0;
718 else if (obt_xml_node_contains(n
, "Nonpixel"))
719 config_resize_popup_show
= 1;
721 if ((n
= obt_xml_find_node(node
, "popupPosition"))) {
722 if (obt_xml_node_contains(n
, "Top"))
723 config_resize_popup_pos
= OB_RESIZE_POS_TOP
;
724 else if (obt_xml_node_contains(n
, "Center"))
725 config_resize_popup_pos
= OB_RESIZE_POS_CENTER
;
726 else if (obt_xml_node_contains(n
, "Fixed")) {
727 config_resize_popup_pos
= OB_RESIZE_POS_FIXED
;
729 if ((n
= obt_xml_find_node(node
, "popupFixedPosition"))) {
732 if ((n2
= obt_xml_find_node(n
->children
, "x")))
733 config_parse_gravity_coord(n2
,
734 &config_resize_popup_fixed
.x
);
735 if ((n2
= obt_xml_find_node(n
->children
, "y")))
736 config_parse_gravity_coord(n2
,
737 &config_resize_popup_fixed
.y
);
739 config_resize_popup_fixed
.x
.pos
=
740 MAX(config_resize_popup_fixed
.x
.pos
, 0);
741 config_resize_popup_fixed
.y
.pos
=
742 MAX(config_resize_popup_fixed
.y
.pos
, 0);
748 static void parse_dock(xmlNodePtr node
, gpointer d
)
752 node
= node
->children
;
754 if ((n
= obt_xml_find_node(node
, "position"))) {
755 if (obt_xml_node_contains(n
, "TopLeft"))
756 config_dock_floating
= FALSE
,
757 config_dock_pos
= OB_DIRECTION_NORTHWEST
;
758 else if (obt_xml_node_contains(n
, "Top"))
759 config_dock_floating
= FALSE
,
760 config_dock_pos
= OB_DIRECTION_NORTH
;
761 else if (obt_xml_node_contains(n
, "TopRight"))
762 config_dock_floating
= FALSE
,
763 config_dock_pos
= OB_DIRECTION_NORTHEAST
;
764 else if (obt_xml_node_contains(n
, "Right"))
765 config_dock_floating
= FALSE
,
766 config_dock_pos
= OB_DIRECTION_EAST
;
767 else if (obt_xml_node_contains(n
, "BottomRight"))
768 config_dock_floating
= FALSE
,
769 config_dock_pos
= OB_DIRECTION_SOUTHEAST
;
770 else if (obt_xml_node_contains(n
, "Bottom"))
771 config_dock_floating
= FALSE
,
772 config_dock_pos
= OB_DIRECTION_SOUTH
;
773 else if (obt_xml_node_contains(n
, "BottomLeft"))
774 config_dock_floating
= FALSE
,
775 config_dock_pos
= OB_DIRECTION_SOUTHWEST
;
776 else if (obt_xml_node_contains(n
, "Left"))
777 config_dock_floating
= FALSE
,
778 config_dock_pos
= OB_DIRECTION_WEST
;
779 else if (obt_xml_node_contains(n
, "Floating"))
780 config_dock_floating
= TRUE
;
782 if (config_dock_floating
) {
783 if ((n
= obt_xml_find_node(node
, "floatingX")))
784 config_dock_x
= obt_xml_node_int(n
);
785 if ((n
= obt_xml_find_node(node
, "floatingY")))
786 config_dock_y
= obt_xml_node_int(n
);
788 if ((n
= obt_xml_find_node(node
, "noStrut")))
789 config_dock_nostrut
= obt_xml_node_bool(n
);
791 if ((n
= obt_xml_find_node(node
, "stacking"))) {
792 if (obt_xml_node_contains(n
, "normal"))
793 config_dock_layer
= OB_STACKING_LAYER_NORMAL
;
794 else if (obt_xml_node_contains(n
, "below"))
795 config_dock_layer
= OB_STACKING_LAYER_BELOW
;
796 else if (obt_xml_node_contains(n
, "above"))
797 config_dock_layer
= OB_STACKING_LAYER_ABOVE
;
799 if ((n
= obt_xml_find_node(node
, "direction"))) {
800 if (obt_xml_node_contains(n
, "horizontal"))
801 config_dock_orient
= OB_ORIENTATION_HORZ
;
802 else if (obt_xml_node_contains(n
, "vertical"))
803 config_dock_orient
= OB_ORIENTATION_VERT
;
805 if ((n
= obt_xml_find_node(node
, "autoHide")))
806 config_dock_hide
= obt_xml_node_bool(n
);
807 if ((n
= obt_xml_find_node(node
, "hideDelay")))
808 config_dock_hide_delay
= obt_xml_node_int(n
);
809 if ((n
= obt_xml_find_node(node
, "showDelay")))
810 config_dock_show_delay
= obt_xml_node_int(n
);
811 if ((n
= obt_xml_find_node(node
, "moveButton"))) {
812 gchar
*str
= obt_xml_node_string(n
);
814 if (translate_button(str
, &s
, &b
)) {
815 config_dock_app_move_button
= b
;
816 config_dock_app_move_modifiers
= s
;
818 g_message(_("Invalid button \"%s\" specified in config file"), str
);
824 static void parse_menu(xmlNodePtr node
, gpointer d
)
827 node
= node
->children
;
829 if ((n
= obt_xml_find_node(node
, "hideDelay")))
830 config_menu_hide_delay
= obt_xml_node_int(n
);
831 if ((n
= obt_xml_find_node(node
, "middle")))
832 config_menu_middle
= obt_xml_node_bool(n
);
833 if ((n
= obt_xml_find_node(node
, "submenuShowDelay")))
834 config_submenu_show_delay
= obt_xml_node_int(n
);
835 if ((n
= obt_xml_find_node(node
, "submenuHideDelay")))
836 config_submenu_hide_delay
= obt_xml_node_int(n
);
837 if ((n
= obt_xml_find_node(node
, "manageDesktops")))
838 config_menu_manage_desktops
= obt_xml_node_bool(n
);
839 if ((n
= obt_xml_find_node(node
, "showIcons"))) {
840 config_menu_show_icons
= obt_xml_node_bool(n
);
842 if (config_menu_show_icons
)
843 g_message(_("Openbox was compiled without Imlib2 image loading support. Icons in menus will not be loaded."));
847 while ((node
= obt_xml_find_node(node
, "file"))) {
848 gchar
*c
= obt_xml_node_string(node
);
849 config_menu_files
= g_slist_append(config_menu_files
,
850 obt_paths_expand_tilde(c
));
856 static void parse_resistance(xmlNodePtr node
, gpointer d
)
860 node
= node
->children
;
861 if ((n
= obt_xml_find_node(node
, "strength")))
862 config_resist_win
= obt_xml_node_int(n
);
863 if ((n
= obt_xml_find_node(node
, "screen_edge_strength")))
864 config_resist_edge
= obt_xml_node_int(n
);
870 const gchar
*actname
;
873 static void bind_default_keyboard(void)
876 ObDefKeyBind binds
[] = {
877 { "A-Tab", "NextWindow" },
878 { "S-A-Tab", "PreviousWindow" },
882 for (it
= binds
; it
->key
; ++it
) {
883 GList
*l
= g_list_append(NULL
, g_strdup(it
->key
));
884 keyboard_bind(l
, actions_parse_string(it
->actname
));
891 const gchar
*context
;
892 const ObMouseAction mact
;
893 const gchar
*actname
;
896 static void bind_default_mouse(void)
899 ObDefMouseBind binds
[] = {
900 { "Left", "Client", OB_MOUSE_ACTION_PRESS
, "Focus" },
901 { "Middle", "Client", OB_MOUSE_ACTION_PRESS
, "Focus" },
902 { "Right", "Client", OB_MOUSE_ACTION_PRESS
, "Focus" },
903 { "Left", "Desktop", OB_MOUSE_ACTION_PRESS
, "Focus" },
904 { "Middle", "Desktop", OB_MOUSE_ACTION_PRESS
, "Focus" },
905 { "Right", "Desktop", OB_MOUSE_ACTION_PRESS
, "Focus" },
906 { "Left", "Titlebar", OB_MOUSE_ACTION_PRESS
, "Focus" },
907 { "Left", "Bottom", OB_MOUSE_ACTION_PRESS
, "Focus" },
908 { "Left", "BLCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
909 { "Left", "BRCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
910 { "Left", "TLCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
911 { "Left", "TRCorner", OB_MOUSE_ACTION_PRESS
, "Focus" },
912 { "Left", "Close", OB_MOUSE_ACTION_PRESS
, "Focus" },
913 { "Left", "Maximize", OB_MOUSE_ACTION_PRESS
, "Focus" },
914 { "Left", "Iconify", OB_MOUSE_ACTION_PRESS
, "Focus" },
915 { "Left", "Icon", OB_MOUSE_ACTION_PRESS
, "Focus" },
916 { "Left", "AllDesktops", OB_MOUSE_ACTION_PRESS
, "Focus" },
917 { "Left", "Shade", OB_MOUSE_ACTION_PRESS
, "Focus" },
918 { "Left", "Client", OB_MOUSE_ACTION_CLICK
, "Raise" },
919 { "Left", "Titlebar", OB_MOUSE_ACTION_CLICK
, "Raise" },
920 { "Middle", "Titlebar", OB_MOUSE_ACTION_CLICK
, "Lower" },
921 { "Left", "BLCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
922 { "Left", "BRCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
923 { "Left", "TLCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
924 { "Left", "TRCorner", OB_MOUSE_ACTION_CLICK
, "Raise" },
925 { "Left", "Close", OB_MOUSE_ACTION_CLICK
, "Raise" },
926 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK
, "Raise" },
927 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK
, "Raise" },
928 { "Left", "Icon", OB_MOUSE_ACTION_CLICK
, "Raise" },
929 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK
, "Raise" },
930 { "Left", "Shade", OB_MOUSE_ACTION_CLICK
, "Raise" },
931 { "Left", "Close", OB_MOUSE_ACTION_CLICK
, "Close" },
932 { "Left", "Maximize", OB_MOUSE_ACTION_CLICK
, "ToggleMaximize" },
933 { "Left", "Iconify", OB_MOUSE_ACTION_CLICK
, "Iconify" },
934 { "Left", "AllDesktops", OB_MOUSE_ACTION_CLICK
, "ToggleOmnipresent" },
935 { "Left", "Shade", OB_MOUSE_ACTION_CLICK
, "ToggleShade" },
936 { "Left", "TLCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
937 { "Left", "TRCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
938 { "Left", "BLCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
939 { "Left", "BRCorner", OB_MOUSE_ACTION_MOTION
, "Resize" },
940 { "Left", "Top", OB_MOUSE_ACTION_MOTION
, "Resize" },
941 { "Left", "Bottom", OB_MOUSE_ACTION_MOTION
, "Resize" },
942 { "Left", "Left", OB_MOUSE_ACTION_MOTION
, "Resize" },
943 { "Left", "Right", OB_MOUSE_ACTION_MOTION
, "Resize" },
944 { "Left", "Titlebar", OB_MOUSE_ACTION_MOTION
, "Move" },
945 { "A-Left", "Frame", OB_MOUSE_ACTION_MOTION
, "Move" },
946 { "A-Middle", "Frame", OB_MOUSE_ACTION_MOTION
, "Resize" },
947 { NULL
, NULL
, 0, NULL
}
950 for (it
= binds
; it
->button
; ++it
)
951 mouse_bind(it
->button
, it
->context
, it
->mact
,
952 actions_parse_string(it
->actname
));
955 void config_startup(ObtXmlInst
*i
)
957 config_focus_new
= TRUE
;
958 config_focus_follow
= FALSE
;
959 config_focus_delay
= 0;
960 config_focus_raise
= FALSE
;
961 config_focus_last
= TRUE
;
962 config_focus_under_mouse
= FALSE
;
963 config_unfocus_leave
= FALSE
;
965 obt_xml_register(i
, "focus", parse_focus
, NULL
);
967 config_place_policy
= OB_PLACE_POLICY_SMART
;
968 config_place_center
= TRUE
;
969 config_place_monitor
= OB_PLACE_MONITOR_ANY
;
971 config_primary_monitor_index
= 1;
972 config_primary_monitor
= OB_PLACE_MONITOR_ACTIVE
;
974 obt_xml_register(i
, "placement", parse_placement
, NULL
);
976 STRUT_PARTIAL_SET(config_margins
, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
978 obt_xml_register(i
, "margins", parse_margins
, NULL
);
982 config_animate_iconify
= TRUE
;
983 config_title_layout
= g_strdup("NLIMC");
984 config_theme_keepborder
= TRUE
;
985 config_theme_window_list_icon_size
= 36;
987 config_font_activewindow
= NULL
;
988 config_font_inactivewindow
= NULL
;
989 config_font_menuitem
= NULL
;
990 config_font_menutitle
= NULL
;
991 config_font_activeosd
= NULL
;
992 config_font_inactiveosd
= NULL
;
994 obt_xml_register(i
, "theme", parse_theme
, NULL
);
996 config_desktops_num
= 4;
997 config_screen_firstdesk
= 1;
998 config_desktops_names
= NULL
;
999 config_desktop_popup_time
= 875;
1001 obt_xml_register(i
, "desktops", parse_desktops
, NULL
);
1003 config_resize_redraw
= TRUE
;
1004 config_resize_popup_show
= 1; /* nonpixel increments */
1005 config_resize_popup_pos
= OB_RESIZE_POS_CENTER
;
1006 GRAVITY_COORD_SET(config_resize_popup_fixed
.x
, 0, FALSE
, FALSE
);
1007 GRAVITY_COORD_SET(config_resize_popup_fixed
.y
, 0, FALSE
, FALSE
);
1009 obt_xml_register(i
, "resize", parse_resize
, NULL
);
1011 config_dock_layer
= OB_STACKING_LAYER_ABOVE
;
1012 config_dock_pos
= OB_DIRECTION_NORTHEAST
;
1013 config_dock_floating
= FALSE
;
1014 config_dock_nostrut
= FALSE
;
1017 config_dock_orient
= OB_ORIENTATION_VERT
;
1018 config_dock_hide
= FALSE
;
1019 config_dock_hide_delay
= 300;
1020 config_dock_show_delay
= 300;
1021 config_dock_app_move_button
= 2; /* middle */
1022 config_dock_app_move_modifiers
= 0;
1024 obt_xml_register(i
, "dock", parse_dock
, NULL
);
1026 translate_key("C-g", &config_keyboard_reset_state
,
1027 &config_keyboard_reset_keycode
);
1029 bind_default_keyboard();
1031 obt_xml_register(i
, "keyboard", parse_keyboard
, NULL
);
1033 config_mouse_threshold
= 8;
1034 config_mouse_dclicktime
= 200;
1035 config_mouse_screenedgetime
= 400;
1036 config_mouse_screenedgewarp
= FALSE
;
1038 bind_default_mouse();
1040 obt_xml_register(i
, "mouse", parse_mouse
, NULL
);
1042 config_resist_win
= 10;
1043 config_resist_edge
= 20;
1045 obt_xml_register(i
, "resistance", parse_resistance
, NULL
);
1047 config_menu_hide_delay
= 250;
1048 config_menu_middle
= FALSE
;
1049 config_submenu_show_delay
= 100;
1050 config_submenu_hide_delay
= 400;
1051 config_menu_manage_desktops
= TRUE
;
1052 config_menu_files
= NULL
;
1053 config_menu_show_icons
= TRUE
;
1055 obt_xml_register(i
, "menu", parse_menu
, NULL
);
1057 config_per_app_settings
= NULL
;
1059 obt_xml_register(i
, "applications", parse_per_app_settings
, NULL
);
1062 void config_shutdown(void)
1066 g_free(config_theme
);
1068 g_free(config_title_layout
);
1070 RrFontClose(config_font_activewindow
);
1071 RrFontClose(config_font_inactivewindow
);
1072 RrFontClose(config_font_menuitem
);
1073 RrFontClose(config_font_menutitle
);
1074 RrFontClose(config_font_activeosd
);
1075 RrFontClose(config_font_inactiveosd
);
1077 for (it
= config_desktops_names
; it
; it
= g_slist_next(it
))
1079 g_slist_free(config_desktops_names
);
1081 for (it
= config_menu_files
; it
; it
= g_slist_next(it
))
1083 g_slist_free(config_menu_files
);
1085 for (it
= config_per_app_settings
; it
; it
= g_slist_next(it
)) {
1086 ObAppSettings
*itd
= (ObAppSettings
*)it
->data
;
1087 if (itd
->name
) g_pattern_spec_free(itd
->name
);
1088 if (itd
->role
) g_pattern_spec_free(itd
->role
);
1089 if (itd
->title
) g_pattern_spec_free(itd
->title
);
1090 if (itd
->class) g_pattern_spec_free(itd
->class);
1091 g_slice_free(ObAppSettings
, it
->data
);
1093 g_slist_free(config_per_app_settings
);