From cf92396e054454e69918933b510efa212b326863 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Fri, 5 Aug 2011 20:36:51 -0400 Subject: [PATCH] Rename obt_xml_find_node() to obt_xml_find_sibling(). Add obt_xml_tree_get_node() and xml_tree_delete_node() --- obt/xml.c | 82 ++++++++++++++++++- obt/xml.h | 32 +++++++- openbox/config.c | 180 ++++++++++++++++++++--------------------- openbox/config_value.c | 20 ++--- openbox/config_value.h | 2 +- openbox/menu.c | 4 +- openbox/session.c | 64 +++++++-------- 7 files changed, 247 insertions(+), 137 deletions(-) diff --git a/obt/xml.c b/obt/xml.c index fde3b76d..a8a3a4ae 100644 --- a/obt/xml.c +++ b/obt/xml.c @@ -117,6 +117,19 @@ void obt_xml_unregister(ObtXmlInst *i, const gchar *tag) g_hash_table_remove(i->callbacks, tag); } +void obt_xml_new_file(ObtXmlInst *i, + const gchar *root_node) +{ + xmlNodePtr old; + + g_assert(i->doc == NULL); /* another doc isn't open already? */ + + i->doc = xmlNewDoc((xmlChar*)"1.0"); + i->root = xmlNewDocRawNode(i->doc, NULL, (xmlChar*)root_node, NULL); + old = xmlDocSetRootElement(i->doc, i->root); + if (old) xmlFreeNode(old); +} + static gboolean load_file(ObtXmlInst *i, const gchar *domain, const gchar *filename, @@ -366,7 +379,7 @@ gboolean obt_xml_node_contains(xmlNodePtr node, const gchar *val) return r; } -xmlNodePtr obt_xml_find_node(xmlNodePtr node, const gchar *tag) +xmlNodePtr obt_xml_find_sibling(xmlNodePtr node, const gchar *tag) { while (node) { if (!xmlStrcmp(node->name, (const xmlChar*) tag)) @@ -439,3 +452,70 @@ gboolean obt_xml_attr_contains(xmlNodePtr node, const gchar *name, xmlFree(c); return r; } + +xmlNodePtr obt_xml_path_get_node(xmlNodePtr subtree, const gchar *path, + const gchar *default_value) +{ + xmlNodePtr n, c; + gchar **nodes; + gchar **it, **next; + + g_return_val_if_fail(subtree != NULL, NULL); + + n = subtree; + + nodes = g_strsplit(path, "/", 0); + for (it = nodes; *it; it = next) { + gchar **attrs; + gboolean ok = FALSE; + + attrs = g_strsplit(*it, ":", 0); + next = it + 1; + + /* match attributes */ + c = obt_xml_find_sibling(n->children, attrs[0]); + while (c && !ok) { + gint i; + + ok = TRUE; + for (i = 1; attrs[i]; ++i) { + gchar **eq = g_strsplit(attrs[i], "=", 2); + if (eq[1] && !obt_xml_attr_contains(c, eq[0], eq[1])) + ok = FALSE; + g_strfreev(eq); + } + if (!ok) + c = obt_xml_find_sibling(c->next, attrs[0]); + } + + if (!c) { + gint i; + + c = xmlNewTextChild(n, NULL, (xmlChar*)attrs[0], + *next ? NULL : (xmlChar*)default_value); + + for (i = 1; attrs[i]; ++i) { + gchar **eq = g_strsplit(attrs[i], "=", 2); + if (eq[1]) + xmlNewProp(c, (xmlChar*)eq[0], (xmlChar*)eq[1]); + g_strfreev(eq); + } + } + n = c; + + g_strfreev(attrs); + } + + g_strfreev(nodes); + + return n; +} + +void obt_xml_path_delete_node(xmlNodePtr subtree, const gchar *path) +{ + xmlNodePtr n; + + n = obt_xml_path_get_node(subtree, path, NULL); + xmlUnlinkNode(n); + xmlFreeNode(n); +} diff --git a/obt/xml.h b/obt/xml.h index 3884f36b..7390b938 100644 --- a/obt/xml.h +++ b/obt/xml.h @@ -32,6 +32,9 @@ ObtXmlInst* obt_xml_instance_new(void); void obt_xml_instance_ref(ObtXmlInst *inst); void obt_xml_instance_unref(ObtXmlInst *inst); +void obt_xml_new_file(ObtXmlInst *inst, + const gchar *root_node); + gboolean obt_xml_load_file(ObtXmlInst *inst, const gchar *path, const gchar *root_node); @@ -69,7 +72,7 @@ void obt_xml_tree_from_root(ObtXmlInst *i); /* helpers */ -xmlNodePtr obt_xml_find_node (xmlNodePtr node, const gchar *name); +xmlNodePtr obt_xml_find_sibling(xmlNodePtr node, const gchar *name); gboolean obt_xml_node_contains (xmlNodePtr node, const gchar *val); gchar *obt_xml_node_string (xmlNodePtr node); @@ -85,6 +88,33 @@ gboolean obt_xml_attr_int (xmlNodePtr node, const gchar *name, gboolean obt_xml_attr_bool (xmlNodePtr node, const gchar *name, gboolean *value); +/* path based operations */ + +/*! Returns the node in the given @subtree, at the given @path. If the node is + not found, it is created, along with any parents. + + The path has a structure follows. + - - specifies a child of the current position in the subtree + - :foo=bar - specifies an attribute and its value. this can be appended to + a or to another attribute + - / - specifies to move one level deeper in the tree + + An example: + - theme/font:place=ActiveWindow/size refers to the size node at this + position: + - + + @subtree The root of the search. + @path A string specifying the search path. + @default_value If the node is not found, it is created with this value + contained within. +*/ +xmlNodePtr obt_xml_path_get_node(xmlNodePtr subtree, const gchar *path, + const gchar *default_value); +/*! Removes a specified node from the tree. */ +void obt_xml_path_delete_node(xmlNodePtr subtree, const gchar *path); + + G_END_DECLS #endif diff --git a/openbox/config.c b/openbox/config.c index d1a2be85..5c1de12c 100644 --- a/openbox/config.c +++ b/openbox/config.c @@ -215,7 +215,7 @@ void config_parse_gravity_coord(xmlNodePtr node, GravityCoord *c) */ static void parse_per_app_settings(xmlNodePtr node, gpointer d) { - xmlNodePtr app = obt_xml_find_node(node->children, "application"); + xmlNodePtr app = obt_xml_find_sibling(node->children, "application"); gchar *name = NULL, *class = NULL, *role = NULL, *title = NULL, *type_str = NULL; gboolean name_set, class_set, type_set, role_set, title_set; @@ -272,29 +272,29 @@ static void parse_per_app_settings(xmlNodePtr node, gpointer d) if (type_set) settings->type = type; - if ((n = obt_xml_find_node(app->children, "decor"))) + if ((n = obt_xml_find_sibling(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 ((n = obt_xml_find_sibling(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 ((n = obt_xml_find_sibling(app->children, "position"))) { + if ((c = obt_xml_find_sibling(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 (x_pos_given && (c = obt_xml_find_sibling(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 ((c = obt_xml_find_sibling(n->children, "monitor"))) if (!obt_xml_node_contains(c, "default")) { gchar *s = obt_xml_node_string(c); if (!g_ascii_strcasecmp(s, "mouse")) @@ -314,11 +314,11 @@ static void parse_per_app_settings(xmlNodePtr node, gpointer d) obt_xml_attr_bool(n, "force", &settings->pos_force); } - if ((n = obt_xml_find_node(app->children, "focus"))) + if ((n = obt_xml_find_sibling(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 ((n = obt_xml_find_sibling(app->children, "desktop"))) { if (!obt_xml_node_contains(n, "default")) { gchar *s = obt_xml_node_string(n); if (!g_ascii_strcasecmp(s, "all")) @@ -332,7 +332,7 @@ static void parse_per_app_settings(xmlNodePtr node, gpointer d) } } - if ((n = obt_xml_find_node(app->children, "layer"))) + if ((n = obt_xml_find_sibling(app->children, "layer"))) if (!obt_xml_node_contains(n, "default")) { gchar *s = obt_xml_node_string(n); if (!g_ascii_strcasecmp(s, "above")) @@ -344,23 +344,23 @@ static void parse_per_app_settings(xmlNodePtr node, gpointer d) g_free(s); } - if ((n = obt_xml_find_node(app->children, "iconic"))) + if ((n = obt_xml_find_sibling(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 ((n = obt_xml_find_sibling(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 ((n = obt_xml_find_sibling(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 ((n = obt_xml_find_sibling(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 ((n = obt_xml_find_sibling(app->children, "maximized"))) if (!obt_xml_node_contains(n, "default")) { gchar *s = obt_xml_node_string(n); if (!g_ascii_strcasecmp(s, "horizontal")) { @@ -385,7 +385,7 @@ static void parse_per_app_settings(xmlNodePtr node, gpointer d) name = class = role = title = type_str = NULL; } - app = obt_xml_find_node(app->next, "application"); + app = obt_xml_find_sibling(app->next, "application"); } } @@ -414,13 +414,13 @@ static void parse_key(xmlNodePtr node, GList *keylist) for (key = keys; *key; ++key) { keylist = g_list_append(keylist, *key); - if ((n = obt_xml_find_node(node->children, "keybind"))) { + if ((n = obt_xml_find_sibling(node->children, "keybind"))) { while (n) { parse_key(n, keylist); - n = obt_xml_find_node(n->next, "keybind"); + n = obt_xml_find_sibling(n->next, "keybind"); } } - else if ((n = obt_xml_find_node(node->children, "action"))) { + else if ((n = obt_xml_find_sibling(node->children, "action"))) { while (n) { ObActionParser *p; ObActionList *actions; @@ -436,7 +436,7 @@ static void parse_key(xmlNodePtr node, GList *keylist) keyboard_bind(keylist, actions); action_list_unref(actions); - n = obt_xml_find_node(n->next, "action"); + n = obt_xml_find_sibling(n->next, "action"); } } @@ -457,17 +457,17 @@ static void parse_keyboard(xmlNodePtr node, gpointer d) keyboard_unbind_all(); - if ((n = obt_xml_find_node(node->children, "chainQuitKey"))) { + if ((n = obt_xml_find_sibling(node->children, "chainQuitKey"))) { key = obt_xml_node_string(n); translate_key(key, &config_keyboard_reset_state, &config_keyboard_reset_keycode); g_free(key); } - if ((n = obt_xml_find_node(node->children, "keybind"))) + if ((n = obt_xml_find_sibling(node->children, "keybind"))) while (n) { parse_key(n, NULL); - n = obt_xml_find_node(n->next, "keybind"); + n = obt_xml_find_sibling(n->next, "keybind"); } } @@ -492,21 +492,21 @@ static void parse_mouse(xmlNodePtr node, gpointer d) node = node->children; - if ((n = obt_xml_find_node(node, "dragThreshold"))) + if ((n = obt_xml_find_sibling(node, "dragThreshold"))) config_mouse_threshold = obt_xml_node_int(n); - if ((n = obt_xml_find_node(node, "doubleClickTime"))) + if ((n = obt_xml_find_sibling(node, "doubleClickTime"))) config_mouse_dclicktime = obt_xml_node_int(n); - if ((n = obt_xml_find_node(node, "screenEdgeWarpTime"))) { + if ((n = obt_xml_find_sibling(node, "screenEdgeWarpTime"))) { config_mouse_screenedgetime = obt_xml_node_int(n); /* minimum value of 25 for this property, when it is 1 and you hit the edge it basically never stops */ if (config_mouse_screenedgetime && config_mouse_screenedgetime < 25) config_mouse_screenedgetime = 25; } - if ((n = obt_xml_find_node(node, "screenEdgeWarpMouse"))) + if ((n = obt_xml_find_sibling(node, "screenEdgeWarpMouse"))) config_mouse_screenedgewarp = obt_xml_node_bool(n); - n = obt_xml_find_node(node, "context"); + n = obt_xml_find_sibling(node, "context"); while (n) { gchar *modcxstr; ObFrameContext cx; @@ -527,7 +527,7 @@ static void parse_mouse(xmlNodePtr node, gpointer d) continue; } - nbut = obt_xml_find_node(n->children, "mousebind"); + nbut = obt_xml_find_sibling(n->children, "mousebind"); while (nbut) { if (!obt_xml_attr_string(nbut, "button", &buttonstr)) goto next_nbut; @@ -544,7 +544,7 @@ static void parse_mouse(xmlNodePtr node, gpointer d) else goto next_nbut; - nact = obt_xml_find_node(nbut->children, "action"); + nact = obt_xml_find_sibling(nbut->children, "action"); while (nact) { ObActionList *actions; ObActionParser *p; @@ -554,20 +554,20 @@ static void parse_mouse(xmlNodePtr node, gpointer d) p = action_parser_new(); if ((actions = action_parser_read_string(p, (gchar*)c))) mouse_bind(buttonstr, cx, mact, actions); - nact = obt_xml_find_node(nact->next, "action"); + nact = obt_xml_find_sibling(nact->next, "action"); action_list_unref(actions); xmlFree(c); action_parser_unref(p); } g_free(buttonstr); next_nbut: - nbut = obt_xml_find_node(nbut->next, "mousebind"); + nbut = obt_xml_find_sibling(nbut->next, "mousebind"); } } g_free(modcxstr); g_free(cxstr); next_n: - n = obt_xml_find_node(n->next, "context"); + n = obt_xml_find_sibling(n->next, "context"); } } @@ -577,19 +577,19 @@ static void parse_focus(xmlNodePtr node, gpointer d) node = node->children; - if ((n = obt_xml_find_node(node, "focusNew"))) + if ((n = obt_xml_find_sibling(node, "focusNew"))) config_focus_new = obt_xml_node_bool(n); - if ((n = obt_xml_find_node(node, "followMouse"))) + if ((n = obt_xml_find_sibling(node, "followMouse"))) config_focus_follow = obt_xml_node_bool(n); - if ((n = obt_xml_find_node(node, "focusDelay"))) + if ((n = obt_xml_find_sibling(node, "focusDelay"))) config_focus_delay = obt_xml_node_int(n); - if ((n = obt_xml_find_node(node, "raiseOnFocus"))) + if ((n = obt_xml_find_sibling(node, "raiseOnFocus"))) config_focus_raise = obt_xml_node_bool(n); - if ((n = obt_xml_find_node(node, "focusLast"))) + if ((n = obt_xml_find_sibling(node, "focusLast"))) config_focus_last = obt_xml_node_bool(n); - if ((n = obt_xml_find_node(node, "underMouse"))) + if ((n = obt_xml_find_sibling(node, "underMouse"))) config_focus_under_mouse = obt_xml_node_bool(n); - if ((n = obt_xml_find_node(node, "unfocusOnLeave"))) + if ((n = obt_xml_find_sibling(node, "unfocusOnLeave"))) config_unfocus_leave = obt_xml_node_bool(n); } @@ -599,12 +599,12 @@ static void parse_placement(xmlNodePtr node, gpointer d) node = node->children; - if ((n = obt_xml_find_node(node, "policy"))) + if ((n = obt_xml_find_sibling(node, "policy"))) if (obt_xml_node_contains(n, "UnderMouse")) config_place_policy = OB_PLACE_POLICY_MOUSE; - if ((n = obt_xml_find_node(node, "center"))) + if ((n = obt_xml_find_sibling(node, "center"))) config_place_center = obt_xml_node_bool(n); - if ((n = obt_xml_find_node(node, "monitor"))) { + if ((n = obt_xml_find_sibling(node, "monitor"))) { if (obt_xml_node_contains(n, "active")) config_place_monitor = OB_PLACE_MONITOR_ACTIVE; else if (obt_xml_node_contains(n, "mouse")) @@ -612,7 +612,7 @@ static void parse_placement(xmlNodePtr node, gpointer d) else if (obt_xml_node_contains(n, "any")) config_place_monitor = OB_PLACE_MONITOR_ANY; } - if ((n = obt_xml_find_node(node, "primaryMonitor"))) { + if ((n = obt_xml_find_sibling(node, "primaryMonitor"))) { config_primary_monitor_index = obt_xml_node_int(n); if (!config_primary_monitor_index) { if (obt_xml_node_contains(n, "mouse")) @@ -627,13 +627,13 @@ static void parse_margins(xmlNodePtr node, gpointer d) node = node->children; - if ((n = obt_xml_find_node(node, "top"))) + if ((n = obt_xml_find_sibling(node, "top"))) config_margins.top = MAX(0, obt_xml_node_int(n)); - if ((n = obt_xml_find_node(node, "left"))) + if ((n = obt_xml_find_sibling(node, "left"))) config_margins.left = MAX(0, obt_xml_node_int(n)); - if ((n = obt_xml_find_node(node, "right"))) + if ((n = obt_xml_find_sibling(node, "right"))) config_margins.right = MAX(0, obt_xml_node_int(n)); - if ((n = obt_xml_find_node(node, "bottom"))) + if ((n = obt_xml_find_sibling(node, "bottom"))) config_margins.bottom = MAX(0, obt_xml_node_int(n)); } @@ -643,7 +643,7 @@ static void parse_theme(xmlNodePtr node, gpointer d) node = node->children; - if ((n = obt_xml_find_node(node, "name"))) { + if ((n = obt_xml_find_sibling(node, "name"))) { gchar *c; g_free(config_theme); @@ -651,7 +651,7 @@ static void parse_theme(xmlNodePtr node, gpointer d) config_theme = obt_paths_expand_tilde(c); g_free(c); } - if ((n = obt_xml_find_node(node, "titleLayout"))) { + if ((n = obt_xml_find_sibling(node, "titleLayout"))) { gchar *c, *d; g_free(config_title_layout); @@ -662,11 +662,11 @@ static void parse_theme(xmlNodePtr node, gpointer d) for (d = c+1; *d != '\0'; ++d) if (*c == *d) *d = ' '; } - if ((n = obt_xml_find_node(node, "keepBorder"))) + if ((n = obt_xml_find_sibling(node, "keepBorder"))) config_theme_keepborder = obt_xml_node_bool(n); - if ((n = obt_xml_find_node(node, "animateIconify"))) + if ((n = obt_xml_find_sibling(node, "animateIconify"))) config_animate_iconify = obt_xml_node_bool(n); - if ((n = obt_xml_find_node(node, "windowListIconSize"))) { + if ((n = obt_xml_find_sibling(node, "windowListIconSize"))) { config_theme_window_list_icon_size = obt_xml_node_int(n); if (config_theme_window_list_icon_size < 16) config_theme_window_list_icon_size = 16; @@ -674,7 +674,7 @@ static void parse_theme(xmlNodePtr node, gpointer d) config_theme_window_list_icon_size = 96; } - n = obt_xml_find_node(node, "font"); + n = obt_xml_find_sibling(node, "font"); while (n) { xmlNodePtr fnode; RrFont **font; @@ -700,21 +700,21 @@ static void parse_theme(xmlNodePtr node, gpointer d) else goto next_font; - if ((fnode = obt_xml_find_node(n->children, "name"))) { + if ((fnode = obt_xml_find_sibling(n->children, "name"))) { g_free(name); name = obt_xml_node_string(fnode); } - if ((fnode = obt_xml_find_node(n->children, "size"))) { + if ((fnode = obt_xml_find_sibling(n->children, "size"))) { int s = obt_xml_node_int(fnode); if (s > 0) size = s; } - if ((fnode = obt_xml_find_node(n->children, "weight"))) { + if ((fnode = obt_xml_find_sibling(n->children, "weight"))) { gchar *w = obt_xml_node_string(fnode); if (!g_ascii_strcasecmp(w, "Bold")) weight = RR_FONTWEIGHT_BOLD; g_free(w); } - if ((fnode = obt_xml_find_node(n->children, "slant"))) { + if ((fnode = obt_xml_find_sibling(n->children, "slant"))) { gchar *s = obt_xml_node_string(fnode); if (!g_ascii_strcasecmp(s, "Italic")) slant = RR_FONTSLANT_ITALIC; @@ -726,7 +726,7 @@ static void parse_theme(xmlNodePtr node, gpointer d) *font = RrFontOpen(ob_rr_inst, name, size, weight, slant); g_free(name); next_font: - n = obt_xml_find_node(n->next, "font"); + n = obt_xml_find_sibling(n->next, "font"); } } @@ -736,17 +736,17 @@ static void parse_desktops(xmlNodePtr node, gpointer d) node = node->children; - if ((n = obt_xml_find_node(node, "number"))) { + if ((n = obt_xml_find_sibling(node, "number"))) { gint d = obt_xml_node_int(n); if (d > 0) config_desktops_num = (unsigned) d; } - if ((n = obt_xml_find_node(node, "firstdesk"))) { + if ((n = obt_xml_find_sibling(node, "firstdesk"))) { gint d = obt_xml_node_int(n); if (d > 0) config_screen_firstdesk = (unsigned) d; } - if ((n = obt_xml_find_node(node, "names"))) { + if ((n = obt_xml_find_sibling(node, "names"))) { GSList *it; xmlNodePtr nname; @@ -755,15 +755,15 @@ static void parse_desktops(xmlNodePtr node, gpointer d) g_slist_free(config_desktops_names); config_desktops_names = NULL; - nname = obt_xml_find_node(n->children, "name"); + nname = obt_xml_find_sibling(n->children, "name"); while (nname) { config_desktops_names = g_slist_append(config_desktops_names, obt_xml_node_string(nname)); - nname = obt_xml_find_node(nname->next, "name"); + nname = obt_xml_find_sibling(nname->next, "name"); } } - if ((n = obt_xml_find_node(node, "popupTime"))) + if ((n = obt_xml_find_sibling(node, "popupTime"))) config_desktop_popup_time = obt_xml_node_int(n); } @@ -773,9 +773,9 @@ static void parse_resize(xmlNodePtr node, gpointer d) node = node->children; - if ((n = obt_xml_find_node(node, "drawContents"))) + if ((n = obt_xml_find_sibling(node, "drawContents"))) config_resize_redraw = obt_xml_node_bool(n); - if ((n = obt_xml_find_node(node, "popupShow"))) { + if ((n = obt_xml_find_sibling(node, "popupShow"))) { config_resize_popup_show = obt_xml_node_int(n); if (obt_xml_node_contains(n, "Always")) config_resize_popup_show = 2; @@ -784,7 +784,7 @@ static void parse_resize(xmlNodePtr node, gpointer d) else if (obt_xml_node_contains(n, "Nonpixel")) config_resize_popup_show = 1; } - if ((n = obt_xml_find_node(node, "popupPosition"))) { + if ((n = obt_xml_find_sibling(node, "popupPosition"))) { if (obt_xml_node_contains(n, "Top")) config_resize_popup_pos = OB_RESIZE_POS_TOP; else if (obt_xml_node_contains(n, "Center")) @@ -792,13 +792,13 @@ static void parse_resize(xmlNodePtr node, gpointer d) else if (obt_xml_node_contains(n, "Fixed")) { config_resize_popup_pos = OB_RESIZE_POS_FIXED; - if ((n = obt_xml_find_node(node, "popupFixedPosition"))) { + if ((n = obt_xml_find_sibling(node, "popupFixedPosition"))) { xmlNodePtr n2; - if ((n2 = obt_xml_find_node(n->children, "x"))) + if ((n2 = obt_xml_find_sibling(n->children, "x"))) config_parse_gravity_coord(n2, &config_resize_popup_fixed.x); - if ((n2 = obt_xml_find_node(n->children, "y"))) + if ((n2 = obt_xml_find_sibling(n->children, "y"))) config_parse_gravity_coord(n2, &config_resize_popup_fixed.y); @@ -817,7 +817,7 @@ static void parse_dock(xmlNodePtr node, gpointer d) node = node->children; - if ((n = obt_xml_find_node(node, "position"))) { + if ((n = obt_xml_find_sibling(node, "position"))) { if (obt_xml_node_contains(n, "TopLeft")) config_dock_floating = FALSE, config_dock_pos = OB_DIRECTION_NORTHWEST; @@ -846,15 +846,15 @@ static void parse_dock(xmlNodePtr node, gpointer d) config_dock_floating = TRUE; } if (config_dock_floating) { - if ((n = obt_xml_find_node(node, "floatingX"))) + if ((n = obt_xml_find_sibling(node, "floatingX"))) config_dock_x = obt_xml_node_int(n); - if ((n = obt_xml_find_node(node, "floatingY"))) + if ((n = obt_xml_find_sibling(node, "floatingY"))) config_dock_y = obt_xml_node_int(n); } else { - if ((n = obt_xml_find_node(node, "noStrut"))) + if ((n = obt_xml_find_sibling(node, "noStrut"))) config_dock_nostrut = obt_xml_node_bool(n); } - if ((n = obt_xml_find_node(node, "stacking"))) { + if ((n = obt_xml_find_sibling(node, "stacking"))) { if (obt_xml_node_contains(n, "normal")) config_dock_layer = OB_STACKING_LAYER_NORMAL; else if (obt_xml_node_contains(n, "below")) @@ -862,19 +862,19 @@ static void parse_dock(xmlNodePtr node, gpointer d) else if (obt_xml_node_contains(n, "above")) config_dock_layer = OB_STACKING_LAYER_ABOVE; } - if ((n = obt_xml_find_node(node, "direction"))) { + if ((n = obt_xml_find_sibling(node, "direction"))) { if (obt_xml_node_contains(n, "horizontal")) config_dock_orient = OB_ORIENTATION_HORZ; else if (obt_xml_node_contains(n, "vertical")) config_dock_orient = OB_ORIENTATION_VERT; } - if ((n = obt_xml_find_node(node, "autoHide"))) + if ((n = obt_xml_find_sibling(node, "autoHide"))) config_dock_hide = obt_xml_node_bool(n); - if ((n = obt_xml_find_node(node, "hideDelay"))) + if ((n = obt_xml_find_sibling(node, "hideDelay"))) config_dock_hide_delay = obt_xml_node_int(n); - if ((n = obt_xml_find_node(node, "showDelay"))) + if ((n = obt_xml_find_sibling(node, "showDelay"))) config_dock_show_delay = obt_xml_node_int(n); - if ((n = obt_xml_find_node(node, "moveButton"))) { + if ((n = obt_xml_find_sibling(node, "moveButton"))) { gchar *str = obt_xml_node_string(n); guint b, s; if (translate_button(str, &s, &b)) { @@ -892,17 +892,17 @@ static void parse_menu(xmlNodePtr node, gpointer d) xmlNodePtr n; node = node->children; - if ((n = obt_xml_find_node(node, "hideDelay"))) + if ((n = obt_xml_find_sibling(node, "hideDelay"))) config_menu_hide_delay = obt_xml_node_int(n); - if ((n = obt_xml_find_node(node, "middle"))) + if ((n = obt_xml_find_sibling(node, "middle"))) config_menu_middle = obt_xml_node_bool(n); - if ((n = obt_xml_find_node(node, "submenuShowDelay"))) + if ((n = obt_xml_find_sibling(node, "submenuShowDelay"))) config_submenu_show_delay = obt_xml_node_int(n); - if ((n = obt_xml_find_node(node, "submenuHideDelay"))) + if ((n = obt_xml_find_sibling(node, "submenuHideDelay"))) config_submenu_hide_delay = obt_xml_node_int(n); - if ((n = obt_xml_find_node(node, "manageDesktops"))) + if ((n = obt_xml_find_sibling(node, "manageDesktops"))) config_menu_manage_desktops = obt_xml_node_bool(n); - if ((n = obt_xml_find_node(node, "showIcons"))) { + if ((n = obt_xml_find_sibling(node, "showIcons"))) { config_menu_show_icons = obt_xml_node_bool(n); #ifndef USE_IMLIB2 if (config_menu_show_icons) @@ -910,7 +910,7 @@ static void parse_menu(xmlNodePtr node, gpointer d) #endif } - while ((node = obt_xml_find_node(node, "file"))) { + while ((node = obt_xml_find_sibling(node, "file"))) { gchar *c = obt_xml_node_string(node); config_menu_files = g_slist_append(config_menu_files, obt_paths_expand_tilde(c)); @@ -924,9 +924,9 @@ static void parse_resistance(xmlNodePtr node, gpointer d) xmlNodePtr n; node = node->children; - if ((n = obt_xml_find_node(node, "strength"))) + if ((n = obt_xml_find_sibling(node, "strength"))) config_resist_win = obt_xml_node_int(n); - if ((n = obt_xml_find_node(node, "screen_edge_strength"))) + if ((n = obt_xml_find_sibling(node, "screen_edge_strength"))) config_resist_edge = obt_xml_node_int(n); } diff --git a/openbox/config_value.c b/openbox/config_value.c index 4d74e3cd..0aa73599 100644 --- a/openbox/config_value.c +++ b/openbox/config_value.c @@ -87,40 +87,40 @@ gboolean config_value_is_action_list(const ObConfigValue *v) void config_value_copy_ptr(ObConfigValue *v, ObConfigValueDataType type, - ObConfigValueDataPtr *p, + ObConfigValueDataPtr p, const ObConfigValueEnum e[]) { switch (type) { case OB_CONFIG_VALUE_STRING: - *p->string = config_value_string(v); + *p.string = config_value_string(v); break; case OB_CONFIG_VALUE_BOOLEAN: - *p->boolean = config_value_bool(v); + *p.boolean = config_value_bool(v); break; case OB_CONFIG_VALUE_INTEGER: - *p->integer = config_value_int(v); + *p.integer = config_value_int(v); break; case OB_CONFIG_VALUE_ENUM: - *p->enumeration = config_value_enum(v, e); + *p.enumeration = config_value_enum(v, e); break; case OB_CONFIG_VALUE_FRACTION: { gint n, d; config_value_fraction(v, &n, &d); - p->fraction->numer = n; - p->fraction->denom = d; + p.fraction->numer = n; + p.fraction->denom = d; break; } case OB_CONFIG_VALUE_GRAVITY_COORD: { GravityCoord c; config_value_gravity_coord(v, &c); - *p->coord = c; + *p.coord = c; break; } case OB_CONFIG_VALUE_LIST: - *p->list = config_value_list(v); + *p.list = config_value_list(v); break; case OB_CONFIG_VALUE_ACTIONLIST: - *p->actions = config_value_action_list(v); + *p.actions = config_value_action_list(v); break; case NUM_OB_CONFIG_VALUE_TYPES: default: diff --git a/openbox/config_value.h b/openbox/config_value.h index f2f92265..5b756340 100644 --- a/openbox/config_value.h +++ b/openbox/config_value.h @@ -84,7 +84,7 @@ gboolean config_value_is_action_list(const ObConfigValue *v); pointing to. */ void config_value_copy_ptr(ObConfigValue *v, ObConfigValueDataType type, - ObConfigValueDataPtr *p, + ObConfigValueDataPtr p, const ObConfigValueEnum e[]); /* These ones are valid on a string value */ diff --git a/openbox/menu.c b/openbox/menu.c index 1ab876ed..39a42b7b 100644 --- a/openbox/menu.c +++ b/openbox/menu.c @@ -290,7 +290,7 @@ static void parse_menu_item(xmlNodePtr node, gpointer data) ObActionList *acts = NULL; ObActionParser *p; - c = obt_xml_find_node(node->children, "action"); + c = obt_xml_find_sibling(node->children, "action"); p = action_parser_new(); while (c) { ObActionList *al; @@ -300,7 +300,7 @@ static void parse_menu_item(xmlNodePtr node, gpointer data) xmlFree(cc); acts = action_list_concat(acts, al); - c = obt_xml_find_node(c->next, "action"); + c = obt_xml_find_sibling(c->next, "action"); } e = menu_add_normal(state->parent, -1, label, acts, TRUE); action_list_unref(acts); diff --git a/openbox/session.c b/openbox/session.c index d6c6f767..6595c2a8 100644 --- a/openbox/session.c +++ b/openbox/session.c @@ -697,28 +697,28 @@ static void session_load_file(const gchar *path) } node = obt_xml_root(i); - if ((n = obt_xml_find_node(node->children, "desktop"))) + if ((n = obt_xml_find_sibling(node->children, "desktop"))) session_desktop = obt_xml_node_int(n); - if ((n = obt_xml_find_node(node->children, "numdesktops"))) + if ((n = obt_xml_find_sibling(node->children, "numdesktops"))) session_num_desktops = obt_xml_node_int(n); - if ((n = obt_xml_find_node(node->children, "desktoplayout"))) { + if ((n = obt_xml_find_sibling(node->children, "desktoplayout"))) { /* make sure they are all there for it to be valid */ - if ((m = obt_xml_find_node(n->children, "orientation"))) + if ((m = obt_xml_find_sibling(n->children, "orientation"))) session_desktop_layout.orientation = obt_xml_node_int(m); - if (m && (m = obt_xml_find_node(n->children, "startcorner"))) + if (m && (m = obt_xml_find_sibling(n->children, "startcorner"))) session_desktop_layout.start_corner = obt_xml_node_int(m); - if (m && (m = obt_xml_find_node(n->children, "columns"))) + if (m && (m = obt_xml_find_sibling(n->children, "columns"))) session_desktop_layout.columns = obt_xml_node_int(m); - if (m && (m = obt_xml_find_node(n->children, "rows"))) + if (m && (m = obt_xml_find_sibling(n->children, "rows"))) session_desktop_layout.rows = obt_xml_node_int(m); session_desktop_layout_present = m != NULL; } - if ((n = obt_xml_find_node(node->children, "desktopnames"))) { - for (m = obt_xml_find_node(n->children, "name"); m; - m = obt_xml_find_node(m->next, "name")) + if ((n = obt_xml_find_sibling(node->children, "desktopnames"))) { + for (m = obt_xml_find_sibling(n->children, "name"); m; + m = obt_xml_find_sibling(m->next, "name")) { session_desktop_names = g_slist_append(session_desktop_names, obt_xml_node_string(m)); @@ -726,8 +726,8 @@ static void session_load_file(const gchar *path) } ob_debug_type(OB_DEBUG_SM, "loading windows"); - for (node = obt_xml_find_node(node->children, "window"); node != NULL; - node = obt_xml_find_node(node->next, "window")) + for (node = obt_xml_find_sibling(node->children, "window"); node != NULL; + node = obt_xml_find_sibling(node->next, "window")) { ObSessionState *state; @@ -736,56 +736,56 @@ static void session_load_file(const gchar *path) if (!obt_xml_attr_string(node, "id", &state->id)) if (!obt_xml_attr_string(node, "command", &state->command)) goto session_load_bail; - if (!(n = obt_xml_find_node(node->children, "name"))) + if (!(n = obt_xml_find_sibling(node->children, "name"))) goto session_load_bail; state->name = obt_xml_node_string(n); - if (!(n = obt_xml_find_node(node->children, "class"))) + if (!(n = obt_xml_find_sibling(node->children, "class"))) goto session_load_bail; state->class = obt_xml_node_string(n); - if (!(n = obt_xml_find_node(node->children, "role"))) + if (!(n = obt_xml_find_sibling(node->children, "role"))) goto session_load_bail; state->role = obt_xml_node_string(n); - if (!(n = obt_xml_find_node(node->children, "windowtype"))) + if (!(n = obt_xml_find_sibling(node->children, "windowtype"))) goto session_load_bail; state->type = obt_xml_node_int(n); - if (!(n = obt_xml_find_node(node->children, "desktop"))) + if (!(n = obt_xml_find_sibling(node->children, "desktop"))) goto session_load_bail; state->desktop = obt_xml_node_int(n); - if (!(n = obt_xml_find_node(node->children, "x"))) + if (!(n = obt_xml_find_sibling(node->children, "x"))) goto session_load_bail; state->x = obt_xml_node_int(n); - if (!(n = obt_xml_find_node(node->children, "y"))) + if (!(n = obt_xml_find_sibling(node->children, "y"))) goto session_load_bail; state->y = obt_xml_node_int(n); - if (!(n = obt_xml_find_node(node->children, "width"))) + if (!(n = obt_xml_find_sibling(node->children, "width"))) goto session_load_bail; state->w = obt_xml_node_int(n); - if (!(n = obt_xml_find_node(node->children, "height"))) + if (!(n = obt_xml_find_sibling(node->children, "height"))) goto session_load_bail; state->h = obt_xml_node_int(n); state->shaded = - obt_xml_find_node(node->children, "shaded") != NULL; + obt_xml_find_sibling(node->children, "shaded") != NULL; state->iconic = - obt_xml_find_node(node->children, "iconic") != NULL; + obt_xml_find_sibling(node->children, "iconic") != NULL; state->skip_pager = - obt_xml_find_node(node->children, "skip_pager") != NULL; + obt_xml_find_sibling(node->children, "skip_pager") != NULL; state->skip_taskbar = - obt_xml_find_node(node->children, "skip_taskbar") != NULL; + obt_xml_find_sibling(node->children, "skip_taskbar") != NULL; state->fullscreen = - obt_xml_find_node(node->children, "fullscreen") != NULL; + obt_xml_find_sibling(node->children, "fullscreen") != NULL; state->above = - obt_xml_find_node(node->children, "above") != NULL; + obt_xml_find_sibling(node->children, "above") != NULL; state->below = - obt_xml_find_node(node->children, "below") != NULL; + obt_xml_find_sibling(node->children, "below") != NULL; state->max_horz = - obt_xml_find_node(node->children, "max_horz") != NULL; + obt_xml_find_sibling(node->children, "max_horz") != NULL; state->max_vert = - obt_xml_find_node(node->children, "max_vert") != NULL; + obt_xml_find_sibling(node->children, "max_vert") != NULL; state->undecorated = - obt_xml_find_node(node->children, "undecorated") != NULL; + obt_xml_find_sibling(node->children, "undecorated") != NULL; state->focused = - obt_xml_find_node(node->children, "focused") != NULL; + obt_xml_find_sibling(node->children, "focused") != NULL; /* save this. they are in the file in stacking order, so preserve that order here */ -- 2.34.1