From 64ed9ef0bf0799ea025f60c3ef1f0a9c2350cdbd Mon Sep 17 00:00:00 2001 From: Albert Astals Date: Thu, 25 Oct 2012 15:23:22 +0200 Subject: Do not reuse menu items if their type is different The gtk side does not know how to convert from a separator to a standard item, and even if it'd knew it does not make much sense to reuse them since if the types are different you can expect there's little to reuse --- libdbusmenu-glib/client.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index 237697c..4ec9d3b 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -2160,8 +2160,29 @@ parse_layout_xml(DbusmenuClient * client, GVariant * layout, DbusmenuMenuitem * for (childsearch = oldchildren; childsearch != NULL; childsearch = g_list_next(childsearch)) { DbusmenuMenuitem * cs_mi = DBUSMENU_MENUITEM(childsearch->data); if (childid == dbusmenu_menuitem_get_id(cs_mi)) { - oldchildren = g_list_remove(oldchildren, cs_mi); - childmi = cs_mi; + GVariantIter iter; + gchar * prop; + GVariant * value; + GVariant * child_props; + GVariant * new_type = NULL; + GVariant * old_type = NULL; + + child_props = g_variant_get_child_value(child, 1); + g_variant_iter_init(&iter, child_props); + while (g_variant_iter_loop(&iter, "{sv}", &prop, &value)) { + if (g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_TYPE) == 0) { + new_type = value; + break; + } + } + g_variant_unref(child_props); + + old_type = dbusmenu_menuitem_property_get_variant(cs_mi, DBUSMENU_MENUITEM_PROP_TYPE); + if ((old_type == new_type) || (old_type != NULL && new_type != NULL && g_strcmp0(g_variant_get_string (old_type, NULL), g_variant_get_string (new_type, NULL)) == 0)) { + // Only recycle the menu item if it's of the same type + oldchildren = g_list_remove(oldchildren, cs_mi); + childmi = cs_mi; + } break; } } -- cgit v1.2.3 From c2eb33badf85c0b4550605a1c45d7040304c29bb Mon Sep 17 00:00:00 2001 From: Albert Astals Date: Thu, 25 Oct 2012 17:13:35 +0200 Subject: Use g_variant_compare --- libdbusmenu-glib/client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index 4ec9d3b..de3b2e8 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -2178,7 +2178,7 @@ parse_layout_xml(DbusmenuClient * client, GVariant * layout, DbusmenuMenuitem * g_variant_unref(child_props); old_type = dbusmenu_menuitem_property_get_variant(cs_mi, DBUSMENU_MENUITEM_PROP_TYPE); - if ((old_type == new_type) || (old_type != NULL && new_type != NULL && g_strcmp0(g_variant_get_string (old_type, NULL), g_variant_get_string (new_type, NULL)) == 0)) { + if ((old_type == new_type) || (old_type != NULL && new_type != NULL && g_variant_compare(old_type, new_type) == 0)) { // Only recycle the menu item if it's of the same type oldchildren = g_list_remove(oldchildren, cs_mi); childmi = cs_mi; -- cgit v1.2.3 From fa83f46a8bebb0788f2d92b633c0aabcbcc1db09 Mon Sep 17 00:00:00 2001 From: Albert Astals Date: Thu, 25 Oct 2012 17:19:23 +0200 Subject: null type means standard type --- libdbusmenu-glib/client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index de3b2e8..4bb3217 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -2178,7 +2178,7 @@ parse_layout_xml(DbusmenuClient * client, GVariant * layout, DbusmenuMenuitem * g_variant_unref(child_props); old_type = dbusmenu_menuitem_property_get_variant(cs_mi, DBUSMENU_MENUITEM_PROP_TYPE); - if ((old_type == new_type) || (old_type != NULL && new_type != NULL && g_variant_compare(old_type, new_type) == 0)) { + if ((old_type == NULL && new_type == NULL) || (old_type != NULL && new_type != NULL && g_variant_compare(old_type, new_type) == 0)) { // Only recycle the menu item if it's of the same type oldchildren = g_list_remove(oldchildren, cs_mi); childmi = cs_mi; -- cgit v1.2.3