+gint config_resist_win;
+gint config_resist_edge;
+
+GSList *config_per_app_settings;
+
+ObAppSettings* config_create_app_settings(void)
+{
+ ObAppSettings *settings = g_slice_new0(ObAppSettings);
+ settings->type = -1;
+ settings->decor = -1;
+ settings->shade = -1;
+ settings->monitor_type = OB_PLACE_MONITOR_ANY;
+ settings->monitor = -1;
+ settings->focus = -1;
+ settings->desktop = 0;
+ settings->layer = -2;
+ settings->iconic = -1;
+ settings->skip_pager = -1;
+ settings->skip_taskbar = -1;
+ settings->fullscreen = -1;
+ settings->max_horz = -1;
+ settings->max_vert = -1;
+ settings->opacity = -1;
+ return settings;
+}
+
+#define copy_if(setting, default) \
+ if (src->setting != default) dst->setting = src->setting
+void config_app_settings_copy_non_defaults(const ObAppSettings *src,
+ ObAppSettings *dst)
+{
+ g_assert(src != NULL);
+ g_assert(dst != NULL);
+
+ copy_if(type, (ObClientType)-1);
+ copy_if(decor, -1);
+ copy_if(shade, -1);
+ copy_if(monitor_type, OB_PLACE_MONITOR_ANY);
+ copy_if(monitor, -1);
+ copy_if(focus, -1);
+ copy_if(desktop, 0);
+ copy_if(layer, -2);
+ copy_if(iconic, -1);
+ copy_if(skip_pager, -1);
+ copy_if(skip_taskbar, -1);
+ copy_if(fullscreen, -1);
+ copy_if(max_horz, -1);
+ copy_if(max_vert, -1);
+ copy_if(opacity, -1);
+
+ if (src->pos_given) {
+ dst->pos_given = TRUE;
+ dst->pos_force = src->pos_force;
+ dst->position = src->position;
+ /* monitor is copied above */
+ }
+
+ dst->width_num = src->width_num;
+ dst->width_denom = src->width_denom;
+ dst->height_num = src->height_num;
+ dst->height_denom = src->height_denom;
+}
+
+void config_parse_relative_number(gchar *s, gint *num, gint *denom)
+{
+ *num = strtol(s, &s, 10);
+
+ if (*s == '%') {
+ *denom = 100;
+ } else if (*s == '/') {
+ *denom = atoi(s+1);
+ }
+}
+
+void config_parse_gravity_coord(xmlNodePtr node, GravityCoord *c)
+{
+ gchar *s = obt_xml_node_string(node);
+ if (!g_ascii_strcasecmp(s, "center"))
+ c->center = TRUE;
+ else {
+ gchar *ps = s;
+ if (s[0] == '-')
+ c->opposite = TRUE;
+ if (s[0] == '-' || s[0] == '+')
+ ps++;
+ config_parse_relative_number(ps, &c->pos, &c->denom);
+ }
+ 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>
+*/
+
+static void parse_single_per_app_settings(xmlNodePtr app,
+ ObAppSettings *settings)
+{
+ xmlNodePtr n, c;
+ gboolean x_pos_given = FALSE;
+
+ if ((n = obt_xml_find_node(app->children, "decor")))
+ if (!obt_xml_node_contains(n, "default"))
+ settings->decor = obt_xml_node_bool(n);
+
+ if ((n = obt_xml_find_node(app->children, "shade")))
+ if (!obt_xml_node_contains(n, "default"))
+ settings->shade = obt_xml_node_bool(n);
+
+ if ((n = obt_xml_find_node(app->children, "position"))) {
+ if ((c = obt_xml_find_node(n->children, "x"))) {
+ if (!obt_xml_node_contains(c, "default")) {
+ config_parse_gravity_coord(c, &settings->position.x);
+ x_pos_given = TRUE;
+ }
+ }
+
+ if (x_pos_given && (c = obt_xml_find_node(n->children, "y"))) {
+ if (!obt_xml_node_contains(c, "default")) {
+ config_parse_gravity_coord(c, &settings->position.y);
+ settings->pos_given = TRUE;
+ }
+ }
+
+ /* monitor can be set without setting x or y */
+ if ((c = obt_xml_find_node(n->children, "monitor"))) {
+ if (!obt_xml_node_contains(c, "default")) {
+ gchar *s = obt_xml_node_string(c);
+ if (!g_ascii_strcasecmp(s, "mouse"))
+ settings->monitor_type = OB_PLACE_MONITOR_MOUSE;
+ else if (!g_ascii_strcasecmp(s, "active"))
+ settings->monitor_type = OB_PLACE_MONITOR_ACTIVE;
+ else if (!g_ascii_strcasecmp(s, "primary"))
+ settings->monitor_type = OB_PLACE_MONITOR_PRIMARY;
+ else
+ settings->monitor = obt_xml_node_int(c);
+ g_free(s);
+ }
+ }
+
+ obt_xml_attr_bool(n, "force", &settings->pos_force);
+ }
+
+ if ((n = obt_xml_find_node(app->children, "size"))) {
+ if ((c = obt_xml_find_node(n->children, "width"))) {
+ if (!obt_xml_node_contains(c, "default")) {
+ gchar *s = obt_xml_node_string(c);
+ config_parse_relative_number(s,
+ &settings->width_num,
+ &settings->width_denom);
+ if (settings->width_num <= 0 || settings->width_denom < 0)
+ settings->width_num = settings->width_denom = 0;
+ g_free(s);
+ }
+ }
+
+ if ((c = obt_xml_find_node(n->children, "height"))) {
+ if (!obt_xml_node_contains(c, "default")) {
+ gchar *s = obt_xml_node_string(c);
+ config_parse_relative_number(s,
+ &settings->height_num,
+ &settings->height_denom);
+ if (settings->height_num <= 0 || settings->height_denom < 0)
+ settings->height_num = settings->height_denom = 0;
+ g_free(s);
+ }
+ }
+ }
+
+ if ((n = obt_xml_find_node(app->children, "focus"))) {
+ if (!obt_xml_node_contains(n, "default"))
+ settings->focus = obt_xml_node_bool(n);
+ }
+
+ if ((n = obt_xml_find_node(app->children, "desktop"))) {
+ if (!obt_xml_node_contains(n, "default")) {
+ gchar *s = obt_xml_node_string(n);
+ if (!g_ascii_strcasecmp(s, "all"))
+ settings->desktop = DESKTOP_ALL;
+ else {
+ gint i = obt_xml_node_int(n);
+ if (i > 0)
+ settings->desktop = i;
+ }
+ g_free(s);
+ }
+ }
+
+ if ((n = obt_xml_find_node(app->children, "layer"))) {
+ if (!obt_xml_node_contains(n, "default")) {
+ gchar *s = obt_xml_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_xml_find_node(app->children, "iconic")))
+ if (!obt_xml_node_contains(n, "default"))
+ settings->iconic = obt_xml_node_bool(n);
+
+ if ((n = obt_xml_find_node(app->children, "skip_pager")))
+ if (!obt_xml_node_contains(n, "default"))
+ settings->skip_pager = obt_xml_node_bool(n);
+
+ if ((n = obt_xml_find_node(app->children, "skip_taskbar")))
+ if (!obt_xml_node_contains(n, "default"))
+ settings->skip_taskbar = obt_xml_node_bool(n);
+
+ if ((n = obt_xml_find_node(app->children, "fullscreen")))
+ if (!obt_xml_node_contains(n, "default"))
+ settings->fullscreen = obt_xml_node_bool(n);
+
+ if ((n = obt_xml_find_node(app->children, "maximized"))) {
+ if (!obt_xml_node_contains(n, "default")) {
+ gchar *s = obt_xml_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_xml_node_bool(n);
+ g_free(s);
+ }
+ }
+
+ if ((n = obt_xml_find_node(app->children, "opacity")))
+ if (!obt_xml_node_contains(n, "default"))
+ settings->opacity = obt_xml_node_int(n);
+}
+
+/* Manages settings for individual applications.
+ Some notes: monitor is the screen number in a multi monitor
+ (Xinerama) setup (starting from 0), or mouse: the monitor the pointer
+ is on, active: the active monitor, primary: the primary monitor.
+ 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_xml_find_node(node->children, "application");
+ for (; app; app = obt_xml_find_node(app->next, "application")) {
+ ObAppSettings *settings;
+
+ gboolean name_set, class_set, role_set, title_set,
+ type_set, group_name_set, group_class_set;
+ gchar *name = NULL, *class = NULL, *role = NULL, *title = NULL,
+ *type_str = NULL, *group_name = NULL, *group_class = NULL;
+ ObClientType type;
+
+ class_set = obt_xml_attr_string(app, "class", &class);
+ name_set = obt_xml_attr_string(app, "name", &name);
+ group_class_set = obt_xml_attr_string(app, "groupclass", &group_class);
+ group_name_set = obt_xml_attr_string(app, "groupname", &group_name);
+ type_set = obt_xml_attr_string(app, "type", &type_str);
+ role_set = obt_xml_attr_string(app, "role", &role);
+ title_set = obt_xml_attr_string(app, "title", &title);
+
+ /* validate the type tho */
+ if (type_set) {
+ if (!g_ascii_strcasecmp(type_str, "normal"))
+ type = OB_CLIENT_TYPE_NORMAL;
+ else if (!g_ascii_strcasecmp(type_str, "dialog"))
+ type = OB_CLIENT_TYPE_DIALOG;
+ else if (!g_ascii_strcasecmp(type_str, "splash"))
+ type = OB_CLIENT_TYPE_SPLASH;
+ else if (!g_ascii_strcasecmp(type_str, "utility"))
+ type = OB_CLIENT_TYPE_UTILITY;
+ else if (!g_ascii_strcasecmp(type_str, "menu"))
+ type = OB_CLIENT_TYPE_MENU;
+ else if (!g_ascii_strcasecmp(type_str, "toolbar"))
+ type = OB_CLIENT_TYPE_TOOLBAR;
+ else if (!g_ascii_strcasecmp(type_str, "dock"))
+ type = OB_CLIENT_TYPE_DOCK;
+ else if (!g_ascii_strcasecmp(type_str, "desktop"))
+ type = OB_CLIENT_TYPE_DESKTOP;
+ else
+ type_set = FALSE; /* not valid! */
+ }
+
+ if (!(class_set || name_set || role_set || title_set ||
+ type_set || group_class_set || group_name_set))
+ continue;
+
+ 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 (group_name_set)
+ settings->group_name = g_pattern_spec_new(group_name);
+ if (group_class_set)
+ settings->group_class = g_pattern_spec_new(group_class);
+ if (role_set)
+ settings->role = g_pattern_spec_new(role);
+ if (title_set)
+ settings->title = g_pattern_spec_new(title);
+ if (type_set)
+ settings->type = type;
+
+ g_free(name);
+ g_free(class);
+ g_free(group_name);
+ g_free(group_class);
+ g_free(role);
+ g_free(title);
+ g_free(type_str);
+
+ parse_single_per_app_settings(app, settings);
+ config_per_app_settings = g_slist_append(config_per_app_settings,
+ (gpointer)settings);
+ }
+}