+static void config_parse_gravity_coord(xmlNodePtr node, GravityCoord *c)
+{
+ gchar *s = obt_parse_node_string(node);
+ if (!g_ascii_strcasecmp(s, "center"))
+ c->center = TRUE;
+ else {
+ if (s[0] == '-')
+ c->opposite = TRUE;
+ if (s[0] == '-' || s[0] == '+')
+ c->pos = atoi(s+1);
+ else
+ c->pos = atoi(s);
+ }
+ g_free(s);
+}
+
+/*
+ <applications>
+ <application name="aterm">
+ <decor>false</decor>
+ </application>
+ <application name="Rhythmbox">
+ <layer>above</layer>
+ <position>
+ <x>700</x>
+ <y>0</y>
+ <monitor>1</monitor>
+ </position>
+ .. there is a lot more settings available
+ </application>
+ </applications>
+*/
+
+/* Manages settings for individual applications.
+ Some notes: monitor is the screen number in a multi monitor
+ (Xinerama) setup (starting from 0) or mouse, meaning the
+ monitor the pointer is on. Default: mouse.
+ Layer can be three values, above (Always on top), below
+ (Always on bottom) and everything else (normal behaviour).
+ Positions can be an integer value or center, which will
+ center the window in the specified axis. Position is within
+ the monitor, so <position><x>center</x></position><monitor>2</monitor>
+ will center the window on the second monitor.
+*/
+static void parse_per_app_settings(xmlNodePtr node, gpointer d)
+{
+ xmlNodePtr app = obt_parse_find_node(node->children, "application");
+ gchar *name = NULL, *class = NULL, *role = NULL, *type = NULL;
+ gboolean name_set, class_set, type_set;
+ gboolean x_pos_given;
+
+ while (app) {
+ name_set = class_set = type_set = x_pos_given = FALSE;
+
+ class_set = obt_parse_attr_string(app, "class", &class);
+ name_set = obt_parse_attr_string(app, "name", &name);
+ type_set = obt_parse_attr_string(app, "type", &type);
+ if (class_set || name_set) {
+ xmlNodePtr n, c;
+ ObAppSettings *settings = config_create_app_settings();;
+
+ if (name_set)
+ settings->name = g_pattern_spec_new(name);
+
+ if (class_set)
+ settings->class = g_pattern_spec_new(class);
+
+ if (type_set) {
+ if (!g_ascii_strcasecmp(type, "normal"))
+ settings->type = OB_CLIENT_TYPE_NORMAL;
+ else if (!g_ascii_strcasecmp(type, "dialog"))
+ settings->type = OB_CLIENT_TYPE_DIALOG;
+ else if (!g_ascii_strcasecmp(type, "splash"))
+ settings->type = OB_CLIENT_TYPE_SPLASH;
+ else if (!g_ascii_strcasecmp(type, "utility"))
+ settings->type = OB_CLIENT_TYPE_UTILITY;
+ else if (!g_ascii_strcasecmp(type, "menu"))
+ settings->type = OB_CLIENT_TYPE_MENU;
+ else if (!g_ascii_strcasecmp(type, "toolbar"))
+ settings->type = OB_CLIENT_TYPE_TOOLBAR;
+ else if (!g_ascii_strcasecmp(type, "dock"))
+ settings->type = OB_CLIENT_TYPE_DOCK;
+ else if (!g_ascii_strcasecmp(type, "desktop"))
+ settings->type = OB_CLIENT_TYPE_DESKTOP;
+ }
+
+ if (obt_parse_attr_string(app, "role", &role))
+ settings->role = g_pattern_spec_new(role);
+
+ if ((n = obt_parse_find_node(app->children, "decor")))
+ if (!obt_parse_node_contains(n, "default"))
+ settings->decor = obt_parse_node_bool(n);
+
+ if ((n = obt_parse_find_node(app->children, "shade")))
+ if (!obt_parse_node_contains(n, "default"))
+ settings->shade = obt_parse_node_bool(n);
+
+ if ((n = obt_parse_find_node(app->children, "position"))) {
+ if ((c = obt_parse_find_node(n->children, "x")))
+ if (!obt_parse_node_contains(c, "default")) {
+ config_parse_gravity_coord(c, &settings->position.x);
+ x_pos_given = TRUE;
+ }
+
+ if (x_pos_given && (c = obt_parse_find_node(n->children, "y")))
+ if (!obt_parse_node_contains(c, "default")) {
+ config_parse_gravity_coord(c, &settings->position.y);
+ settings->pos_given = TRUE;
+ }
+
+ if (settings->pos_given &&
+ (c = obt_parse_find_node(n->children, "monitor")))
+ if (!obt_parse_node_contains(c, "default")) {
+ gchar *s = obt_parse_node_string(c);
+ if (!g_ascii_strcasecmp(s, "mouse"))
+ settings->monitor = 0;
+ else
+ settings->monitor = obt_parse_node_int(c) + 1;
+ g_free(s);
+ }
+
+ obt_parse_attr_bool(n, "force", &settings->pos_force);
+ }
+
+ if ((n = obt_parse_find_node(app->children, "focus")))
+ if (!obt_parse_node_contains(n, "default"))
+ settings->focus = obt_parse_node_bool(n);
+
+ if ((n = obt_parse_find_node(app->children, "desktop"))) {
+ if (!obt_parse_node_contains(n, "default")) {
+ gchar *s = obt_parse_node_string(n);
+ if (!g_ascii_strcasecmp(s, "all"))
+ settings->desktop = DESKTOP_ALL;
+ else {
+ gint i = obt_parse_node_int(n);
+ if (i > 0)
+ settings->desktop = i;
+ }
+ g_free(s);
+ }
+ }
+
+ if ((n = obt_parse_find_node(app->children, "layer")))
+ if (!obt_parse_node_contains(n, "default")) {
+ gchar *s = obt_parse_node_string(n);
+ if (!g_ascii_strcasecmp(s, "above"))
+ settings->layer = 1;
+ else if (!g_ascii_strcasecmp(s, "below"))
+ settings->layer = -1;
+ else
+ settings->layer = 0;
+ g_free(s);
+ }
+
+ if ((n = obt_parse_find_node(app->children, "iconic")))
+ if (!obt_parse_node_contains(n, "default"))
+ settings->iconic = obt_parse_node_bool(n);
+
+ if ((n = obt_parse_find_node(app->children, "skip_pager")))
+ if (!obt_parse_node_contains(n, "default"))
+ settings->skip_pager = obt_parse_node_bool(n);
+
+ if ((n = obt_parse_find_node(app->children, "skip_taskbar")))
+ if (!obt_parse_node_contains(n, "default"))
+ settings->skip_taskbar = obt_parse_node_bool(n);
+
+ if ((n = obt_parse_find_node(app->children, "fullscreen")))
+ if (!obt_parse_node_contains(n, "default"))
+ settings->fullscreen = obt_parse_node_bool(n);
+
+ if ((n = obt_parse_find_node(app->children, "maximized")))
+ if (!obt_parse_node_contains(n, "default")) {
+ gchar *s = obt_parse_node_string(n);
+ if (!g_ascii_strcasecmp(s, "horizontal")) {
+ settings->max_horz = TRUE;
+ settings->max_vert = FALSE;
+ } else if (!g_ascii_strcasecmp(s, "vertical")) {
+ settings->max_horz = FALSE;
+ settings->max_vert = TRUE;
+ } else
+ settings->max_horz = settings->max_vert =
+ obt_parse_node_bool(n);
+ g_free(s);
+ }
+
+ config_per_app_settings = g_slist_append(config_per_app_settings,
+ (gpointer) settings);
+ g_free(name);
+ g_free(class);
+ g_free(role);
+ name = class = role = NULL;
+ }
+
+ app = obt_parse_find_node(app->next, "application");
+ }
+}
+
+static void parse_hook(xmlNodePtr node, gpointer d)
+{
+ gchar *name;
+ ObHook hook;
+ xmlNodePtr n;
+
+
+ if (!obt_parse_attr_string(node, "name", &name)) {
+ g_message(_("Hook in config file is missing a name"));
+ return;
+ }
+
+ hook = hooks_hook_from_name(name);
+ if (!hook)
+ g_message(_("Unknown hook \"%s\" in config file"), name);
+ else {
+ if ((n = obt_parse_find_node(node->children, "action")))
+ while (n) {
+ ObActionsAct *action;
+
+ action = actions_parse(n);
+ if (action)
+ hooks_add(hook, action);
+ n = obt_parse_find_node(n->next, "action");
+ }
+ }
+
+ g_free(name);
+}
+
+static void parse_hooks(xmlNodePtr node, gpointer d)
+{
+ xmlNodePtr n;
+
+ if ((n = obt_parse_find_node(node->children, "hook")))
+ while (n) {
+ parse_hook(n, NULL);
+ n = obt_parse_find_node(n->next, "hook");
+ }
+}