aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2011-02-24 08:34:48 -0600
committerTed Gould <ted@gould.cx>2011-02-24 08:34:48 -0600
commitdc884d4c136e674b96fe44dfd1201da8c7872816 (patch)
treeec4bf109f867b2bfac57e8786426b5678a138fe4
parentb57f5a8ba47155113d8352a6b15bd31209a9199b (diff)
parent9c4d38ce605a99616d83918eb6ee7e200090b06d (diff)
downloadlibdbusmenu-dc884d4c136e674b96fe44dfd1201da8c7872816.tar.gz
libdbusmenu-dc884d4c136e674b96fe44dfd1201da8c7872816.tar.bz2
libdbusmenu-dc884d4c136e674b96fe44dfd1201da8c7872816.zip
Only send property updates if the item has been already requested.
-rw-r--r--libdbusmenu-glib/menuitem-private.h1
-rw-r--r--libdbusmenu-glib/menuitem.c14
-rw-r--r--libdbusmenu-glib/server.c23
3 files changed, 32 insertions, 6 deletions
diff --git a/libdbusmenu-glib/menuitem-private.h b/libdbusmenu-glib/menuitem-private.h
index 89319dc..336769d 100644
--- a/libdbusmenu-glib/menuitem-private.h
+++ b/libdbusmenu-glib/menuitem-private.h
@@ -38,6 +38,7 @@ gboolean dbusmenu_menuitem_realized (DbusmenuMenuitem * mi);
void dbusmenu_menuitem_set_realized (DbusmenuMenuitem * mi);
GVariant * dbusmenu_menuitem_properties_variant (DbusmenuMenuitem * mi, const gchar ** properties);
gboolean dbusmenu_menuitem_property_is_default (DbusmenuMenuitem * mi, const gchar * property);
+gboolean dbusmenu_menuitem_exposed (DbusmenuMenuitem * mi);
G_END_DECLS
diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c
index 78e07df..89b2b91 100644
--- a/libdbusmenu-glib/menuitem.c
+++ b/libdbusmenu-glib/menuitem.c
@@ -61,6 +61,7 @@ struct _DbusmenuMenuitemPrivate
gboolean root;
gboolean realized;
DbusmenuDefaults * defaults;
+ gboolean exposed;
};
/* Signals */
@@ -316,6 +317,7 @@ dbusmenu_menuitem_init (DbusmenuMenuitem *self)
priv->realized = FALSE;
priv->defaults = dbusmenu_defaults_ref_default();
+ priv->exposed = FALSE;
return;
}
@@ -1439,6 +1441,8 @@ GVariant *
dbusmenu_menuitem_build_variant (DbusmenuMenuitem * mi, const gchar ** properties, gint recurse)
{
g_return_val_if_fail(DBUSMENU_IS_MENUITEM(mi), NULL);
+ DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi);
+ priv->exposed = TRUE;
gint id = 0;
if (!dbusmenu_menuitem_get_root(mi)) {
@@ -1621,3 +1625,13 @@ dbusmenu_menuitem_property_is_default (DbusmenuMenuitem * mi, const gchar * prop
g_warn_if_reached();
return FALSE;
}
+
+/* Check to see if this menu item has been sent into the bus yet or
+ not. If no one cares we can give less info */
+gboolean
+dbusmenu_menuitem_exposed (DbusmenuMenuitem * mi)
+{
+ g_return_val_if_fail(DBUSMENU_IS_MENUITEM(mi), FALSE);
+ DbusmenuMenuitemPrivate * priv = DBUSMENU_MENUITEM_GET_PRIVATE(mi);
+ return priv->exposed;
+}
diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c
index 8bad7cf..c3faa6b 100644
--- a/libdbusmenu-glib/server.c
+++ b/libdbusmenu-glib/server.c
@@ -791,7 +791,7 @@ layout_update_signal (DbusmenuServer * server)
typedef struct _prop_idle_item_t prop_idle_item_t;
struct _prop_idle_item_t {
- gint id;
+ DbusmenuMenuitem * mi;
GArray * array;
};
@@ -821,6 +821,7 @@ prop_array_teardown (GArray * prop_array)
}
}
+ g_object_unref(G_OBJECT(iitem->mi));
g_array_free(iitem->array, TRUE);
}
@@ -854,6 +855,12 @@ menuitem_property_idle (gpointer user_data)
for (i = 0; i < priv->prop_array->len; i++) {
prop_idle_item_t * iitem = &g_array_index(priv->prop_array, prop_idle_item_t, i);
+ /* if it's not exposed we're going to block it's properties
+ from getting into the dbus message */
+ if (dbusmenu_menuitem_exposed(iitem->mi) == FALSE) {
+ continue;
+ }
+
GVariantBuilder dictbuilder;
gboolean dictinit = FALSE;
@@ -891,7 +898,7 @@ menuitem_property_idle (gpointer user_data)
GVariantBuilder tuplebuilder;
g_variant_builder_init(&tuplebuilder, G_VARIANT_TYPE_TUPLE);
- g_variant_builder_add_value(&tuplebuilder, g_variant_new_int32(iitem->id));
+ g_variant_builder_add_value(&tuplebuilder, g_variant_new_int32(dbusmenu_menuitem_get_id(iitem->mi)));
g_variant_builder_add_value(&tuplebuilder, g_variant_builder_end(&dictbuilder));
if (!item_init) {
@@ -908,7 +915,7 @@ menuitem_property_idle (gpointer user_data)
GVariantBuilder tuplebuilder;
g_variant_builder_init(&tuplebuilder, G_VARIANT_TYPE_TUPLE);
- g_variant_builder_add_value(&tuplebuilder, g_variant_new_int32(iitem->id));
+ g_variant_builder_add_value(&tuplebuilder, g_variant_new_int32(dbusmenu_menuitem_get_id(iitem->mi)));
g_variant_builder_add_value(&tuplebuilder, g_variant_builder_end(&removedictbuilder));
if (!removeitem_init) {
@@ -921,9 +928,11 @@ menuitem_property_idle (gpointer user_data)
}
GVariant * megadata[2];
+ gboolean gotsomething = FALSE;
if (item_init) {
megadata[0] = g_variant_builder_end(&itembuilder);
+ gotsomething = TRUE;
} else {
GError * error = NULL;
megadata[0] = g_variant_parse(G_VARIANT_TYPE("a(ia{sv})"), "[ ]", NULL, NULL, &error);
@@ -936,6 +945,7 @@ menuitem_property_idle (gpointer user_data)
if (removeitem_init) {
megadata[1] = g_variant_builder_end(&removeitembuilder);
+ gotsomething = TRUE;
} else {
GError * error = NULL;
megadata[1] = g_variant_parse(G_VARIANT_TYPE("a(ia(s))"), "[ ]", NULL, NULL, &error);
@@ -946,7 +956,7 @@ menuitem_property_idle (gpointer user_data)
}
}
- if (priv->dbusobject != NULL && priv->bus != NULL) {
+ if (gotsomething && priv->dbusobject != NULL && priv->bus != NULL) {
g_dbus_connection_emit_signal(priv->bus,
NULL,
priv->dbusobject,
@@ -989,7 +999,7 @@ menuitem_property_changed (DbusmenuMenuitem * mi, gchar * property, GVariant * v
prop_idle_item_t * item = NULL;
for (i = 0; i < priv->prop_array->len; i++) {
prop_idle_item_t * iitem = &g_array_index(priv->prop_array, prop_idle_item_t, i);
- if (iitem->id == item_id) {
+ if (iitem->mi == mi) {
item = iitem;
break;
}
@@ -999,7 +1009,8 @@ menuitem_property_changed (DbusmenuMenuitem * mi, gchar * property, GVariant * v
/* If not, we'll need to build ourselves one */
if (item == NULL) {
prop_idle_item_t myitem;
- myitem.id = item_id;
+ myitem.mi = mi;
+ g_object_ref(G_OBJECT(mi));
myitem.array = g_array_new(FALSE, FALSE, sizeof(prop_idle_prop_t));
g_array_append_val(priv->prop_array, myitem);