From 8ec651ef62779668b4919e94a32cd6c7868b7609 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 8 Jun 2010 17:36:57 -0500 Subject: Dummy functions to get and set the shortcut --- libdbusmenu-gtk/menuitem.c | 34 ++++++++++++++++++++++++++++++++++ libdbusmenu-gtk/menuitem.h | 3 +++ 2 files changed, 37 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 23ff311..8b026e6 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -128,3 +128,37 @@ dbusmenu_menuitem_property_get_image (DbusmenuMenuitem * menuitem, const gchar * return icon; } +/** + dbusmenu_menuitem_property_set_shortcut: + @menuitem: The #DbusmenuMenuitem to set the shortcut on + @shortcut: String describing the shortcut + + This function takes a GTK shortcut string as defined in + #gtk_accellerator_parse and turns that into the information + required to send it over DBusmenu. + + Return value: Whether it was successful at setting the property. +*/ +gboolean +dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, const gchar * shortcut) +{ + + return FALSE; +} + +/** + dbusmenu_menuitem_property_get_shortcut: + @menuitem: The #DbusmenuMenuitem to get the shortcut off + + This function gets a GTK shortcut string as defined in + #gtk_accellerator_parse from the data that is transferred + over DBusmenu. + + Return value: Either the string or #NULL if there is none. +*/ +gchar * +dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem) +{ + + return NULL; +} diff --git a/libdbusmenu-gtk/menuitem.h b/libdbusmenu-gtk/menuitem.h index ff458de..aacab42 100644 --- a/libdbusmenu-gtk/menuitem.h +++ b/libdbusmenu-gtk/menuitem.h @@ -36,4 +36,7 @@ License version 3 and version 2.1 along with this program. If not, see gboolean dbusmenu_menuitem_property_set_image (DbusmenuMenuitem * menuitem, const gchar * property, const GdkPixbuf * data); GdkPixbuf * dbusmenu_menuitem_property_get_image (DbusmenuMenuitem * menuitem, const gchar * property); +gboolean dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, const gchar * shortcut); +gchar * dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem); + #endif -- cgit v1.2.3 From 9c4988079766e6c5398852b8b7f78188b6aee369 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 9 Jun 2010 16:52:24 -0500 Subject: Fleshing out building the shortcut array. --- libdbusmenu-gtk/menuitem.c | 48 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 8b026e6..1ae4817 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -27,6 +27,8 @@ License version 3 and version 2.1 along with this program. If not, see */ #include "menuitem.h" +#include +#include /** dbusmenu_menuitem_property_set_image: @@ -134,7 +136,7 @@ dbusmenu_menuitem_property_get_image (DbusmenuMenuitem * menuitem, const gchar * @shortcut: String describing the shortcut This function takes a GTK shortcut string as defined in - #gtk_accellerator_parse and turns that into the information + #gtk_accelerator_parse and turns that into the information required to send it over DBusmenu. Return value: Whether it was successful at setting the property. @@ -142,8 +144,47 @@ dbusmenu_menuitem_property_get_image (DbusmenuMenuitem * menuitem, const gchar * gboolean dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, const gchar * shortcut) { + g_return_val_if_fail(DBUSMENU_IS_MENUITEM(menuitem), FALSE); + g_return_val_if_fail(shortcut != NULL, FALSE); + + guint key = 0; + GdkModifierType modifier = 0; + + gtk_accelerator_parse(shortcut, &key, &modifier); - return FALSE; + if (key == 0) { + g_warning("Unable to parse shortcut string '%s'", shortcut); + return FALSE; + } + + GPtrArray * array = g_ptr_array_new(); + + if (modifier & GDK_CONTROL_MASK) { + g_ptr_array_add(array, g_strdup(DBUSMENU_MENUITEM_SHORTCUT_CONTROL)); + } + if (modifier & GDK_MOD1_MASK) { + g_ptr_array_add(array, g_strdup(DBUSMENU_MENUITEM_SHORTCUT_ALT)); + } + if (modifier & GDK_SHIFT_MASK) { + g_ptr_array_add(array, g_strdup(DBUSMENU_MENUITEM_SHORTCUT_SHIFT)); + } + if (modifier & GDK_SUPER_MASK) { + g_ptr_array_add(array, g_strdup(DBUSMENU_MENUITEM_SHORTCUT_SUPER)); + } + + gint len = g_utf8_strlen(shortcut, -1); + g_ptr_array_add(array, g_strdup(shortcut + len - 1)); + + GPtrArray * wrapper = g_ptr_array_new(); + g_ptr_array_add(wrapper, array); + + GValue value = {0}; + g_value_init(&value, G_TYPE_BOXED); + g_value_set_boxed(&value, wrapper); + + dbusmenu_menuitem_property_set_value(menuitem, DBUSMENU_MENUITEM_PROP_SHORTCUT, &value); + + return TRUE; } /** @@ -151,7 +192,7 @@ dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, const gcha @menuitem: The #DbusmenuMenuitem to get the shortcut off This function gets a GTK shortcut string as defined in - #gtk_accellerator_parse from the data that is transferred + #gtk_accelerator_parse from the data that is transferred over DBusmenu. Return value: Either the string or #NULL if there is none. @@ -159,6 +200,7 @@ dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, const gcha gchar * dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem) { + g_return_val_if_fail(DBUSMENU_IS_MENUITEM(menuitem), FALSE); return NULL; } -- cgit v1.2.3 From 2c464b6b4c16d4dc32090706ecfc7c198d68c84e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 9 Jun 2010 20:39:21 -0500 Subject: Switching things around to expose the key and modifier more as it's more useful. --- libdbusmenu-gtk/menuitem.c | 30 ++++++++++++++++++------------ libdbusmenu-gtk/menuitem.h | 6 ++++-- 2 files changed, 22 insertions(+), 14 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 1ae4817..0f09483 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -142,7 +142,7 @@ dbusmenu_menuitem_property_get_image (DbusmenuMenuitem * menuitem, const gchar * Return value: Whether it was successful at setting the property. */ gboolean -dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, const gchar * shortcut) +dbusmenu_menuitem_property_set_shortcut_string (DbusmenuMenuitem * menuitem, const gchar * shortcut) { g_return_val_if_fail(DBUSMENU_IS_MENUITEM(menuitem), FALSE); g_return_val_if_fail(shortcut != NULL, FALSE); @@ -157,6 +157,14 @@ dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, const gcha return FALSE; } + return dbusmenu_menuitem_property_set_shortcut(menuitem, key, modifier); +} + +gboolean +dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, guint key, GdkModifierType modifier) +{ + g_return_val_if_fail(DBUSMENU_IS_MENUITEM(menuitem), FALSE); + GPtrArray * array = g_ptr_array_new(); if (modifier & GDK_CONTROL_MASK) { @@ -172,8 +180,7 @@ dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, const gcha g_ptr_array_add(array, g_strdup(DBUSMENU_MENUITEM_SHORTCUT_SUPER)); } - gint len = g_utf8_strlen(shortcut, -1); - g_ptr_array_add(array, g_strdup(shortcut + len - 1)); + g_ptr_array_add(array, g_strdup(gdk_keyval_name(key))); GPtrArray * wrapper = g_ptr_array_new(); g_ptr_array_add(wrapper, array); @@ -190,17 +197,16 @@ dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, const gcha /** dbusmenu_menuitem_property_get_shortcut: @menuitem: The #DbusmenuMenuitem to get the shortcut off + @key: Location to put the key value + @modifier: Location to put the modifier mask - This function gets a GTK shortcut string as defined in - #gtk_accelerator_parse from the data that is transferred - over DBusmenu. - - Return value: Either the string or #NULL if there is none. + This function gets a GTK shortcut as a key and a mask + for use to set the accelerators. */ -gchar * -dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem) +void +dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * key, GdkModifierType * modifier) { - g_return_val_if_fail(DBUSMENU_IS_MENUITEM(menuitem), FALSE); + g_return_if_fail(DBUSMENU_IS_MENUITEM(menuitem)); - return NULL; + return; } diff --git a/libdbusmenu-gtk/menuitem.h b/libdbusmenu-gtk/menuitem.h index aacab42..ba01549 100644 --- a/libdbusmenu-gtk/menuitem.h +++ b/libdbusmenu-gtk/menuitem.h @@ -32,11 +32,13 @@ License version 3 and version 2.1 along with this program. If not, see #include #include #include +#include gboolean dbusmenu_menuitem_property_set_image (DbusmenuMenuitem * menuitem, const gchar * property, const GdkPixbuf * data); GdkPixbuf * dbusmenu_menuitem_property_get_image (DbusmenuMenuitem * menuitem, const gchar * property); -gboolean dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, const gchar * shortcut); -gchar * dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem); +gboolean dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, guint key, GdkModifierType modifier); +gboolean dbusmenu_menuitem_property_set_shortcut_string (DbusmenuMenuitem * menuitem, const gchar * shortcut); +void dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * key, GdkModifierType * modifiers); #endif -- cgit v1.2.3 From 77958c0a4c45138e5f731e6f11cdee5a8bc3f8a8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 14 Jun 2010 10:58:21 -0500 Subject: Adding in a prototype for stealing the shortcut off of a menuitem. --- libdbusmenu-gtk/menuitem.c | 7 +++++++ libdbusmenu-gtk/menuitem.h | 2 ++ 2 files changed, 9 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 0f09483..74cb635 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -194,6 +194,13 @@ dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, guint key, return TRUE; } +gboolean +dbusmenu_menuitem_property_set_shortcut_menuitem (DbusmenuMenuitem * menuitem, const GtkMenuItem * gmi) +{ + + return FALSE; +} + /** dbusmenu_menuitem_property_get_shortcut: @menuitem: The #DbusmenuMenuitem to get the shortcut off diff --git a/libdbusmenu-gtk/menuitem.h b/libdbusmenu-gtk/menuitem.h index ba01549..6960f76 100644 --- a/libdbusmenu-gtk/menuitem.h +++ b/libdbusmenu-gtk/menuitem.h @@ -33,12 +33,14 @@ License version 3 and version 2.1 along with this program. If not, see #include #include #include +#include gboolean dbusmenu_menuitem_property_set_image (DbusmenuMenuitem * menuitem, const gchar * property, const GdkPixbuf * data); GdkPixbuf * dbusmenu_menuitem_property_get_image (DbusmenuMenuitem * menuitem, const gchar * property); gboolean dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, guint key, GdkModifierType modifier); gboolean dbusmenu_menuitem_property_set_shortcut_string (DbusmenuMenuitem * menuitem, const gchar * shortcut); +gboolean dbusmenu_menuitem_property_set_shortcut_menuitem (DbusmenuMenuitem * menuitem, const GtkMenuItem * gmi); void dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * key, GdkModifierType * modifiers); #endif -- cgit v1.2.3 From 50dcdae3889fef7da43c6618b35b70847ba59d72 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 14 Jun 2010 11:05:34 -0500 Subject: Comment fixes --- libdbusmenu-gtk/menuitem.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 74cb635..6f5c6b3 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -131,7 +131,7 @@ dbusmenu_menuitem_property_get_image (DbusmenuMenuitem * menuitem, const gchar * } /** - dbusmenu_menuitem_property_set_shortcut: + dbusmenu_menuitem_property_set_shortcut_string: @menuitem: The #DbusmenuMenuitem to set the shortcut on @shortcut: String describing the shortcut @@ -160,6 +160,17 @@ dbusmenu_menuitem_property_set_shortcut_string (DbusmenuMenuitem * menuitem, con return dbusmenu_menuitem_property_set_shortcut(menuitem, key, modifier); } +/** + dbusmenu_menuitem_property_set_shortcut: + @menuitem: The #DbusmenuMenuitem to set the shortcut on + @key: The keycode of the key to send + @modifier: A bitmask of modifiers used to activate the item + + Takes the modifer described by @key and @modifier and places that into + the format sending across Dbus for shortcuts. + + Return value: Whether it was successful at setting the property. +*/ gboolean dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, guint key, GdkModifierType modifier) { @@ -194,6 +205,17 @@ dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, guint key, return TRUE; } +/** + dbusmenu_menuitem_property_set_shortcut_menuitem: + @menuitem: The #DbusmenuMenuitem to set the shortcut on + @gmi: A menu item to steal the shortcut off of + + Takes the shortcut that is installed on a menu item and calls + #dbusmenu_menuitem_property_set_shortcut with it. It also sets + up listeners to watch it change. + + Return value: Whether it was successful at setting the property. +*/ gboolean dbusmenu_menuitem_property_set_shortcut_menuitem (DbusmenuMenuitem * menuitem, const GtkMenuItem * gmi) { -- cgit v1.2.3 From 7fc24062ed7fea97fec2a3cd873dcc68edc9c488 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 14 Jun 2010 12:12:35 -0500 Subject: Fleshing out getting the accelerator from the menuitem. --- libdbusmenu-gtk/menuitem.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 6f5c6b3..dfd83b0 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -205,6 +205,14 @@ dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, guint key, return TRUE; } +/* Look at the closures in an accel group and find + the one that matches the one we've been passed */ +static gboolean +find_closure (GtkAccelKey * key, GClosure * closure, gpointer user_data) +{ + return closure == user_data; +} + /** dbusmenu_menuitem_property_set_shortcut_menuitem: @menuitem: The #DbusmenuMenuitem to set the shortcut on @@ -219,8 +227,32 @@ dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, guint key, gboolean dbusmenu_menuitem_property_set_shortcut_menuitem (DbusmenuMenuitem * menuitem, const GtkMenuItem * gmi) { + g_return_val_if_fail(DBUSMENU_IS_MENUITEM(menuitem), FALSE); + g_return_val_if_fail(GTK_IS_MENU_ITEM(gmi), FALSE); + + GClosure * closure = NULL; + GList * clist; + + clist = gtk_widget_list_accel_closures(GTK_WIDGET(gmi)); + if (clist == NULL) { + g_warning("Menuitem does not have any closures."); + return FALSE; + } + + closure = (GClosure *)clist->data; + g_list_free(clist); + + GtkAccelGroup * group = gtk_accel_group_from_accel_closure(closure); + + /* Seriously, if this returns NULL something is seriously + wrong in GTK. */ + g_return_val_if_fail(group != NULL, FALSE); + + GtkAccelKey * key = gtk_accel_group_find(group, find_closure, closure); + /* Again, not much we can do except complain loudly. */ + g_return_val_if_fail(key != NULL, FALSE); - return FALSE; + return dbusmenu_menuitem_property_set_shortcut(menuitem, key->accel_key, key->accel_mods); } /** -- cgit v1.2.3 From b0099f8f5ce53544a225033274ffd692e9edf4e6 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 14 Jun 2010 12:44:03 -0500 Subject: Checking the validity of the key combo. --- libdbusmenu-gtk/menuitem.c | 1 + 1 file changed, 1 insertion(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index dfd83b0..ea1b77f 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -175,6 +175,7 @@ gboolean dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, guint key, GdkModifierType modifier) { g_return_val_if_fail(DBUSMENU_IS_MENUITEM(menuitem), FALSE); + g_return_val_if_fail(gtk_accelerator_valid(key, modifier), FALSE); GPtrArray * array = g_ptr_array_new(); -- cgit v1.2.3 From 4ead60b99de627e29d0aae213c622ba10ef72069 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 14 Jun 2010 14:20:52 -0500 Subject: initing the value array properly --- libdbusmenu-gtk/menuitem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index ea1b77f..a4818ca 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -198,7 +198,7 @@ dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, guint key, g_ptr_array_add(wrapper, array); GValue value = {0}; - g_value_init(&value, G_TYPE_BOXED); + g_value_init(&value, G_TYPE_PTR_ARRAY); g_value_set_boxed(&value, wrapper); dbusmenu_menuitem_property_set_value(menuitem, DBUSMENU_MENUITEM_PROP_SHORTCUT, &value); -- cgit v1.2.3 From 16b5a01c2cb8c4d8ce6216f984c4a06f6aa14c3a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 14 Jun 2010 14:50:16 -0500 Subject: Fleshing out getting the shortcut --- libdbusmenu-gtk/menuitem.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index a4818ca..f56e9e5 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -268,7 +268,58 @@ dbusmenu_menuitem_property_set_shortcut_menuitem (DbusmenuMenuitem * menuitem, c void dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * key, GdkModifierType * modifier) { + *key = 0; + *modifier = 0; + g_return_if_fail(DBUSMENU_IS_MENUITEM(menuitem)); + const GValue * wrapper = dbusmenu_menuitem_property_get_value(menuitem, DBUSMENU_MENUITEM_PROP_SHORTCUT); + if (wrapper == NULL) { + return; + } + + g_return_if_fail(G_VALUE_HOLDS_BOXED(wrapper)); + + GPtrArray * wrapperarray = (GPtrArray *)g_value_get_boxed(wrapper); + if (wrapperarray->len == 0) { + return; + } + + if (wrapperarray->len != 1) { + g_warning("Shortcut is more than one entry. Which we don't currently support. Taking the first."); + } + + GPtrArray * entryarray = g_ptr_array_index(wrapperarray, 0); + if (entryarray->len == 0) { + /* Seems a little odd, but really, we're saying that it isn't a + shortcut, so I'm comfortable with exiting silently. */ + return; + } + + /* Parse through modifiers */ + int i; + for (i = 0; i < entryarray->len - 1; i++) { + if (g_strcmp0(g_ptr_array_index(entryarray, i), DBUSMENU_MENUITEM_SHORTCUT_CONTROL) == 0) { + *modifier |= GDK_CONTROL_MASK; + continue; + } + if (g_strcmp0(g_ptr_array_index(entryarray, i), DBUSMENU_MENUITEM_SHORTCUT_ALT) == 0) { + *modifier |= GDK_MOD1_MASK; + continue; + } + if (g_strcmp0(g_ptr_array_index(entryarray, i), DBUSMENU_MENUITEM_SHORTCUT_SHIFT) == 0) { + *modifier |= GDK_SHIFT_MASK; + continue; + } + if (g_strcmp0(g_ptr_array_index(entryarray, i), DBUSMENU_MENUITEM_SHORTCUT_SUPER) == 0) { + *modifier |= GDK_SUPER_MASK; + continue; + } + } + + GdkModifierType tempmod; + + gtk_accelerator_parse(g_ptr_array_index(entryarray, entryarray->len - 1), key, &tempmod); + return; } -- cgit v1.2.3 From 2525166d72f421e045b21910aa7df2523135d1c9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 14 Jun 2010 15:23:05 -0500 Subject: Switching to an accel label --- libdbusmenu-gtk/genericmenuitem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/genericmenuitem.c b/libdbusmenu-gtk/genericmenuitem.c index 8f40d93..1000c68 100644 --- a/libdbusmenu-gtk/genericmenuitem.c +++ b/libdbusmenu-gtk/genericmenuitem.c @@ -191,7 +191,7 @@ set_label (GtkMenuItem * menu_item, const gchar * label) update the one that we already have. */ if (labelw == NULL) { /* Build it */ - labelw = GTK_LABEL(gtk_label_new(label)); + labelw = GTK_LABEL(gtk_accel_label_new(label)); gtk_label_set_use_underline(GTK_LABEL(labelw), TRUE); gtk_misc_set_alignment(GTK_MISC(labelw), 0.0, 0.5); gtk_widget_show(GTK_WIDGET(labelw)); -- cgit v1.2.3 From b2be41cd5085e821f5557303592c11a064eef104 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 14 Jun 2010 16:10:54 -0500 Subject: Add two functions for setting and getting the accelerator group. --- libdbusmenu-gtk/client.c | 34 ++++++++++++++++++++++++++++++++++ libdbusmenu-gtk/client.h | 3 +++ 2 files changed, 37 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 3bd0af6..64f6a6d 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -99,6 +99,40 @@ dbusmenu_gtkclient_finalize (GObject *object) return; } +/** + dbusmenu_gtkclient_set_accel_group: + @client: To set the group on + @agroup: The new acceleration group + + Sets the acceleration group for the menu items with accelerators + on this client. +*/ +void +dbusmenu_gtkclient_set_accel_group (DbusmenuGtkClient * client, GtkAccelGroup * agroup) +{ + g_return_if_fail(DBUSMENU_IS_GTKCLIENT(client)); + g_return_if_fail(GTK_IS_ACCEL_GROUP(agroup)); + + return; +} + +/** + dbusmenu_gtkclient_get_accel_group: + @client: Client to query for an accelerator group + + Gets the accel group for this client. + + Return value: Either a valid group or #NULL on error or + none set. +*/ +GtkAccelGroup * +dbusmenu_gtkclient_get_accel_group (DbusmenuGtkClient * client) +{ + g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), NULL); + + return NULL; +} + /* Internal Functions */ static const gchar * data_menuitem = "dbusmenugtk-data-gtkmenuitem"; diff --git a/libdbusmenu-gtk/client.h b/libdbusmenu-gtk/client.h index 7672bf7..a7c96ee 100644 --- a/libdbusmenu-gtk/client.h +++ b/libdbusmenu-gtk/client.h @@ -79,6 +79,9 @@ DbusmenuGtkClient * dbusmenu_gtkclient_new (gchar * dbus_name, gchar * dbus_obje GtkMenuItem * dbusmenu_gtkclient_menuitem_get (DbusmenuGtkClient * client, DbusmenuMenuitem * item); GtkMenu * dbusmenu_gtkclient_menuitem_get_submenu (DbusmenuGtkClient * client, DbusmenuMenuitem * item); +void dbusmenu_gtkclient_set_accel_group (DbusmenuGtkClient * client, GtkAccelGroup * agroup); +GtkAccelGroup * dbusmenu_gtkclient_get_accel_group (DbusmenuGtkClient * client); + void dbusmenu_gtkclient_newitem_base (DbusmenuGtkClient * client, DbusmenuMenuitem * item, GtkMenuItem * gmi, DbusmenuMenuitem * parent); /** -- cgit v1.2.3 From b426c6e47fbfa4c701a264c765a47b7fba820e8c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 14 Jun 2010 16:15:30 -0500 Subject: Adding a private area on to the client. --- libdbusmenu-gtk/client.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 64f6a6d..09e7b4e 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -36,6 +36,15 @@ License version 3 and version 2.1 along with this program. If not, see #include "menuitem.h" #include "genericmenuitem.h" +/* Private */ +typedef struct _DbusmenuGtkClientPrivate DbusmenuGtkClientPrivate; +struct _DbusmenuGtkClientPrivate { + GtkAccelGroup * agroup; +}; + +#define DBUSMENU_GTKCLIENT_GET_PRIVATE(o) \ +(G_TYPE_INSTANCE_GET_PRIVATE ((o), DBUSMENU_GTKCLIENT_TYPE, DbusmenuGtkClientPrivate)) + /* Prototypes */ static void dbusmenu_gtkclient_class_init (DbusmenuGtkClientClass *klass); static void dbusmenu_gtkclient_init (DbusmenuGtkClient *self); @@ -62,6 +71,8 @@ dbusmenu_gtkclient_class_init (DbusmenuGtkClientClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); + g_type_class_add_private (klass, sizeof (DbusmenuGtkClientPrivate)); + object_class->dispose = dbusmenu_gtkclient_dispose; object_class->finalize = dbusmenu_gtkclient_finalize; @@ -73,6 +84,10 @@ dbusmenu_gtkclient_class_init (DbusmenuGtkClientClass *klass) static void dbusmenu_gtkclient_init (DbusmenuGtkClient *self) { + DbusmenuGtkClientPrivate * priv = DBUSMENU_GTKCLIENT_GET_PRIVATE(self); + + priv->agroup = NULL; + dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(self), DBUSMENU_CLIENT_TYPES_DEFAULT, new_item_normal); dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(self), DBUSMENU_CLIENT_TYPES_SEPARATOR, new_item_seperator); @@ -85,6 +100,12 @@ dbusmenu_gtkclient_init (DbusmenuGtkClient *self) static void dbusmenu_gtkclient_dispose (GObject *object) { + DbusmenuGtkClientPrivate * priv = DBUSMENU_GTKCLIENT_GET_PRIVATE(object); + + if (priv->agroup != NULL) { + g_object_unref(priv->agroup); + priv->agroup = NULL; + } G_OBJECT_CLASS (dbusmenu_gtkclient_parent_class)->dispose (object); return; -- cgit v1.2.3 From a27e07f2173dea07625df51466563b1caeddb385 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 14 Jun 2010 17:04:37 -0500 Subject: Fleshing out setting and getting the accel group --- libdbusmenu-gtk/client.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 09e7b4e..ca0b668 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -120,6 +120,48 @@ dbusmenu_gtkclient_finalize (GObject *object) return; } +static void +swap_agroup (DbusmenuMenuitem * mi, gpointer userdata) { + gpointer * array = (gpointer *)userdata; + DbusmenuGtkClient * client = (DbusmenuGtkClient *)array[0]; + GtkAccelGroup * old_agroup = (GtkAccelGroup *)array[1]; + GtkAccelGroup * new_agroup = (GtkAccelGroup *)array[2]; + + /* If we don't have a shortcut we don't care */ + if (!dbusmenu_menuitem_property_exist(mi, DBUSMENU_MENUITEM_PROP_SHORTCUT)) { + return; + } + + guint key = 0; + GdkModifierType modifiers = 0; + + dbusmenu_menuitem_property_get_shortcut(mi, &key, &modifiers); + + if (key == 0) { + return; + } + + GtkMenuItem * gmi = dbusmenu_gtkclient_menuitem_get(client, mi); + if (gmi == NULL) { + return; + } + + if (old_agroup != NULL) { + gtk_widget_remove_accelerator(GTK_WIDGET(gmi), old_agroup, key, modifiers); + } + + if (new_agroup != NULL) { + gtk_widget_add_accelerator(GTK_WIDGET(gmi), + "activate", + new_agroup, + key, + modifiers, + GTK_ACCEL_VISIBLE); + } + + return; +} + /** dbusmenu_gtkclient_set_accel_group: @client: To set the group on @@ -134,6 +176,23 @@ dbusmenu_gtkclient_set_accel_group (DbusmenuGtkClient * client, GtkAccelGroup * g_return_if_fail(DBUSMENU_IS_GTKCLIENT(client)); g_return_if_fail(GTK_IS_ACCEL_GROUP(agroup)); + DbusmenuGtkClientPrivate * priv = DBUSMENU_GTKCLIENT_GET_PRIVATE(client); + + DbusmenuMenuitem * root = dbusmenu_client_get_root(DBUSMENU_CLIENT(client)); + if (root != NULL) { + gpointer data[3]; + data[0] = client; + data[1] = priv->agroup; + data[2] = agroup; + + dbusmenu_menuitem_foreach(root, swap_agroup, data); + } + + if (priv->agroup != NULL) { + g_object_unref(priv->agroup); + priv->agroup = NULL; + } + return; } @@ -151,7 +210,9 @@ dbusmenu_gtkclient_get_accel_group (DbusmenuGtkClient * client) { g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), NULL); - return NULL; + DbusmenuGtkClientPrivate * priv = DBUSMENU_GTKCLIENT_GET_PRIVATE(client); + + return priv->agroup; } /* Internal Functions */ -- cgit v1.2.3 From be82ae8c060f84b28d4e4c6fb0c4b11062112984 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 14 Jun 2010 17:09:02 -0500 Subject: Restructuring to use a structure to get cleaner type checking. --- libdbusmenu-gtk/client.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index ca0b668..f5d683c 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -120,12 +120,19 @@ dbusmenu_gtkclient_finalize (GObject *object) return; } +/* Structure for passing data to swap_agroup */ +typedef struct _swap_agroup_t swap_agroup_t; +struct _swap_agroup_t { + DbusmenuGtkClient * client; + GtkAccelGroup * old_agroup; + GtkAccelGroup * new_agroup; +}; + +/* Looks at the old version of the accelerator group and + the new one and makes the state proper. */ static void swap_agroup (DbusmenuMenuitem * mi, gpointer userdata) { - gpointer * array = (gpointer *)userdata; - DbusmenuGtkClient * client = (DbusmenuGtkClient *)array[0]; - GtkAccelGroup * old_agroup = (GtkAccelGroup *)array[1]; - GtkAccelGroup * new_agroup = (GtkAccelGroup *)array[2]; + swap_agroup_t * data = (swap_agroup_t *)userdata; /* If we don't have a shortcut we don't care */ if (!dbusmenu_menuitem_property_exist(mi, DBUSMENU_MENUITEM_PROP_SHORTCUT)) { @@ -141,19 +148,19 @@ swap_agroup (DbusmenuMenuitem * mi, gpointer userdata) { return; } - GtkMenuItem * gmi = dbusmenu_gtkclient_menuitem_get(client, mi); + GtkMenuItem * gmi = dbusmenu_gtkclient_menuitem_get(data->client, mi); if (gmi == NULL) { return; } - if (old_agroup != NULL) { - gtk_widget_remove_accelerator(GTK_WIDGET(gmi), old_agroup, key, modifiers); + if (data->old_agroup != NULL) { + gtk_widget_remove_accelerator(GTK_WIDGET(gmi), data->old_agroup, key, modifiers); } - if (new_agroup != NULL) { + if (data->new_agroup != NULL) { gtk_widget_add_accelerator(GTK_WIDGET(gmi), "activate", - new_agroup, + data->new_agroup, key, modifiers, GTK_ACCEL_VISIBLE); @@ -180,12 +187,12 @@ dbusmenu_gtkclient_set_accel_group (DbusmenuGtkClient * client, GtkAccelGroup * DbusmenuMenuitem * root = dbusmenu_client_get_root(DBUSMENU_CLIENT(client)); if (root != NULL) { - gpointer data[3]; - data[0] = client; - data[1] = priv->agroup; - data[2] = agroup; + swap_agroup_t data; + data.client = client; + data.old_agroup = priv->agroup; + data.new_agroup = agroup; - dbusmenu_menuitem_foreach(root, swap_agroup, data); + dbusmenu_menuitem_foreach(root, swap_agroup, &data); } if (priv->agroup != NULL) { @@ -193,6 +200,8 @@ dbusmenu_gtkclient_set_accel_group (DbusmenuGtkClient * client, GtkAccelGroup * priv->agroup = NULL; } + priv->agroup = agroup; + return; } -- cgit v1.2.3 From 1338ccff53e35cafae1500eb5414514c57af15bf Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 14 Jun 2010 19:59:13 -0500 Subject: Adding a function to refresh the shortcut of a menuitem. --- libdbusmenu-gtk/client.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index f5d683c..625c4ba 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -169,6 +169,24 @@ swap_agroup (DbusmenuMenuitem * mi, gpointer userdata) { return; } +/* Refresh the shortcut for an entry */ +static void +refresh_shortcut (DbusmenuGtkClient * client, DbusmenuMenuitem * mi) +{ + g_return_if_fail(DBUSMENU_IS_GTKCLIENT(client)); + g_return_if_fail(DBUSMENU_IS_MENUITEM(mi)); + + DbusmenuGtkClientPrivate * priv = DBUSMENU_GTKCLIENT_GET_PRIVATE(client); + + swap_agroup_t data; + data.client = client; + data.old_agroup = priv->agroup; + data.new_agroup = priv->agroup; + + return swap_agroup(mi, &data); +} + + /** dbusmenu_gtkclient_set_accel_group: @client: To set the group on -- cgit v1.2.3 From 85d700350d533fc1989aa7cb6cfe9e973b4db552 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 14 Jun 2010 20:05:19 -0500 Subject: Connecting up the refresh cycles to property changes and creation. --- libdbusmenu-gtk/client.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 625c4ba..ab7f16c 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -368,6 +368,17 @@ menu_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * value, GtkMen return; } +/* Special handler for the shortcut changing as we need to have the + client for that one to get the accel group. */ +static void +menu_shortcut_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * value, DbusmenuGtkClient * client) +{ + if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_SHORTCUT)) { + refresh_shortcut(client, mi); + } + return; +} + /* Call back that happens when the DbusmenuMenuitem is destroyed. We're making sure to clean up everything else down the pipe. */ @@ -434,6 +445,7 @@ dbusmenu_gtkclient_newitem_base (DbusmenuGtkClient * client, DbusmenuMenuitem * /* DbusmenuMenuitem signals */ g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(menu_prop_change_cb), gmi); + g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(menu_shortcut_change_cb), client); g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_CHILD_REMOVED, G_CALLBACK(delete_child), client); g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_CHILD_MOVED, G_CALLBACK(move_child), client); @@ -448,6 +460,7 @@ dbusmenu_gtkclient_newitem_base (DbusmenuGtkClient * client, DbusmenuMenuitem * process_sensitive(item, gmi, dbusmenu_menuitem_property_get_value(item, DBUSMENU_MENUITEM_PROP_ENABLED)); process_toggle_type(item, gmi, dbusmenu_menuitem_property_get_value(item, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE)); process_toggle_state(item, gmi, dbusmenu_menuitem_property_get_value(item, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE)); + refresh_shortcut(client, item); /* Oh, we're a child, let's deal with that */ if (parent != NULL) { -- cgit v1.2.3 From a7940079b8a074529ea504efe3e9a033197ea057 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 14 Jun 2010 21:24:29 -0500 Subject: Switching to a value array from a ptrarray --- libdbusmenu-gtk/menuitem.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index f56e9e5..9a374b0 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -160,6 +160,17 @@ dbusmenu_menuitem_property_set_shortcut_string (DbusmenuMenuitem * menuitem, con return dbusmenu_menuitem_property_set_shortcut(menuitem, key, modifier); } +/* Append strings to an g_value_array */ +static void +_g_value_array_append_string (GValueArray * array, const gchar * string) +{ + GValue value = {0}; + g_value_init(&value, G_TYPE_STRING); + g_value_set_string(&value, string); + g_value_array_append(array, &value); + return; +} + /** dbusmenu_menuitem_property_set_shortcut: @menuitem: The #DbusmenuMenuitem to set the shortcut on @@ -177,28 +188,31 @@ dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, guint key, g_return_val_if_fail(DBUSMENU_IS_MENUITEM(menuitem), FALSE); g_return_val_if_fail(gtk_accelerator_valid(key, modifier), FALSE); - GPtrArray * array = g_ptr_array_new(); + GValueArray * array = g_value_array_new(4); /* Four seems like the max we'd need, plus it's still small */ if (modifier & GDK_CONTROL_MASK) { - g_ptr_array_add(array, g_strdup(DBUSMENU_MENUITEM_SHORTCUT_CONTROL)); + _g_value_array_append_string(array, DBUSMENU_MENUITEM_SHORTCUT_CONTROL); } if (modifier & GDK_MOD1_MASK) { - g_ptr_array_add(array, g_strdup(DBUSMENU_MENUITEM_SHORTCUT_ALT)); + _g_value_array_append_string(array, DBUSMENU_MENUITEM_SHORTCUT_ALT); } if (modifier & GDK_SHIFT_MASK) { - g_ptr_array_add(array, g_strdup(DBUSMENU_MENUITEM_SHORTCUT_SHIFT)); + _g_value_array_append_string(array, DBUSMENU_MENUITEM_SHORTCUT_SHIFT); } if (modifier & GDK_SUPER_MASK) { - g_ptr_array_add(array, g_strdup(DBUSMENU_MENUITEM_SHORTCUT_SUPER)); + _g_value_array_append_string(array, DBUSMENU_MENUITEM_SHORTCUT_SUPER); } - g_ptr_array_add(array, g_strdup(gdk_keyval_name(key))); + _g_value_array_append_string(array, gdk_keyval_name(key)); - GPtrArray * wrapper = g_ptr_array_new(); - g_ptr_array_add(wrapper, array); + GValueArray * wrapper = g_value_array_new(1); + GValue wrap_val = {0}; + g_value_init(&wrap_val, G_TYPE_VALUE_ARRAY); + g_value_set_boxed(&wrap_val, array); + g_value_array_append(wrapper, &wrap_val); GValue value = {0}; - g_value_init(&value, G_TYPE_PTR_ARRAY); + g_value_init(&value, G_TYPE_VALUE_ARRAY); g_value_set_boxed(&value, wrapper); dbusmenu_menuitem_property_set_value(menuitem, DBUSMENU_MENUITEM_PROP_SHORTCUT, &value); -- cgit v1.2.3 From b31f6418f37bc35dc59162d5878eacb5002e3402 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 14 Jun 2010 22:01:56 -0500 Subject: Block the case where the label is being init'd to NULL --- libdbusmenu-gtk/genericmenuitem.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/genericmenuitem.c b/libdbusmenu-gtk/genericmenuitem.c index 1000c68..7239864 100644 --- a/libdbusmenu-gtk/genericmenuitem.c +++ b/libdbusmenu-gtk/genericmenuitem.c @@ -158,6 +158,8 @@ get_hpadding (GtkWidget * widget) static void set_label (GtkMenuItem * menu_item, const gchar * label) { + if (label == NULL) return; + GtkWidget * child = gtk_bin_get_child(GTK_BIN(menu_item)); GtkLabel * labelw = NULL; gboolean suppress_update = FALSE; -- cgit v1.2.3 From 2a1ad77c4b91f35b69e42a79b48b2f0cc0f01bfb Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 14 Jun 2010 23:48:51 -0500 Subject: Switching get over to a GValueArray too! --- libdbusmenu-gtk/menuitem.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 9a374b0..a448f88 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -292,19 +292,18 @@ dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * ke return; } - g_return_if_fail(G_VALUE_HOLDS_BOXED(wrapper)); - - GPtrArray * wrapperarray = (GPtrArray *)g_value_get_boxed(wrapper); - if (wrapperarray->len == 0) { + GValueArray * wrapperarray = (GValueArray *)g_value_get_boxed(wrapper); + if (wrapperarray->n_values == 0) { return; } - if (wrapperarray->len != 1) { + if (wrapperarray->n_values != 1) { g_warning("Shortcut is more than one entry. Which we don't currently support. Taking the first."); } - GPtrArray * entryarray = g_ptr_array_index(wrapperarray, 0); - if (entryarray->len == 0) { + GValue * ventryarray = g_value_array_get_nth(wrapperarray, 0); + GValueArray * entryarray = (GValueArray *)g_value_get_boxed(ventryarray); + if (entryarray->n_values == 0) { /* Seems a little odd, but really, we're saying that it isn't a shortcut, so I'm comfortable with exiting silently. */ return; @@ -312,20 +311,20 @@ dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * ke /* Parse through modifiers */ int i; - for (i = 0; i < entryarray->len - 1; i++) { - if (g_strcmp0(g_ptr_array_index(entryarray, i), DBUSMENU_MENUITEM_SHORTCUT_CONTROL) == 0) { + for (i = 0; i < entryarray->n_values - 1; i++) { + if (g_strcmp0(g_value_get_string(g_value_array_get_nth(entryarray, i)), DBUSMENU_MENUITEM_SHORTCUT_CONTROL) == 0) { *modifier |= GDK_CONTROL_MASK; continue; } - if (g_strcmp0(g_ptr_array_index(entryarray, i), DBUSMENU_MENUITEM_SHORTCUT_ALT) == 0) { + if (g_strcmp0(g_value_get_string(g_value_array_get_nth(entryarray, i)), DBUSMENU_MENUITEM_SHORTCUT_ALT) == 0) { *modifier |= GDK_MOD1_MASK; continue; } - if (g_strcmp0(g_ptr_array_index(entryarray, i), DBUSMENU_MENUITEM_SHORTCUT_SHIFT) == 0) { + if (g_strcmp0(g_value_get_string(g_value_array_get_nth(entryarray, i)), DBUSMENU_MENUITEM_SHORTCUT_SHIFT) == 0) { *modifier |= GDK_SHIFT_MASK; continue; } - if (g_strcmp0(g_ptr_array_index(entryarray, i), DBUSMENU_MENUITEM_SHORTCUT_SUPER) == 0) { + if (g_strcmp0(g_value_get_string(g_value_array_get_nth(entryarray, i)), DBUSMENU_MENUITEM_SHORTCUT_SUPER) == 0) { *modifier |= GDK_SUPER_MASK; continue; } @@ -333,7 +332,7 @@ dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * ke GdkModifierType tempmod; - gtk_accelerator_parse(g_ptr_array_index(entryarray, entryarray->len - 1), key, &tempmod); + gtk_accelerator_parse(g_value_get_string(g_value_array_get_nth(entryarray, entryarray->n_values - 1)), key, &tempmod); return; } -- cgit v1.2.3 From 97513daeb03ba302613de3ebbfcf356bc75fa611 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 15 Jun 2010 13:49:05 -0500 Subject: Switch to using the accel map with paths --- libdbusmenu-gtk/client.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index ab7f16c..a9c6657 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -153,17 +153,20 @@ swap_agroup (DbusmenuMenuitem * mi, gpointer userdata) { return; } - if (data->old_agroup != NULL) { - gtk_widget_remove_accelerator(GTK_WIDGET(gmi), data->old_agroup, key, modifiers); + const gchar * accel_path = gtk_menu_item_get_accel_path(gmi); + + if (accel_path != NULL) { + gtk_accel_map_change_entry(accel_path, key, modifiers, TRUE /* replace */); + } else { + gchar * accel_path = g_strdup_printf("/Generated/%d", dbusmenu_menuitem_get_id(mi)); + gtk_accel_map_add_entry(accel_path, key, modifiers); + gtk_menu_item_set_accel_path(gmi, accel_path); + g_free(accel_path); } - if (data->new_agroup != NULL) { - gtk_widget_add_accelerator(GTK_WIDGET(gmi), - "activate", - data->new_agroup, - key, - modifiers, - GTK_ACCEL_VISIBLE); + GtkMenu * submenu = dbusmenu_gtkclient_menuitem_get_submenu(data->client, mi); + if (submenu != NULL) { + gtk_menu_set_accel_group(submenu, data->new_agroup); } return; -- cgit v1.2.3 From d0bbb5a0985adccf54cf857d4b0f17a8ba803cd2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 15 Jun 2010 13:50:52 -0500 Subject: Setting the accel widget for the accel label. --- libdbusmenu-gtk/genericmenuitem.c | 1 + 1 file changed, 1 insertion(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/genericmenuitem.c b/libdbusmenu-gtk/genericmenuitem.c index 7239864..30b072f 100644 --- a/libdbusmenu-gtk/genericmenuitem.c +++ b/libdbusmenu-gtk/genericmenuitem.c @@ -196,6 +196,7 @@ set_label (GtkMenuItem * menu_item, const gchar * label) labelw = GTK_LABEL(gtk_accel_label_new(label)); gtk_label_set_use_underline(GTK_LABEL(labelw), TRUE); gtk_misc_set_alignment(GTK_MISC(labelw), 0.0, 0.5); + gtk_accel_label_set_accel_widget(GTK_ACCEL_LABEL(labelw), GTK_WIDGET(menu_item)); gtk_widget_show(GTK_WIDGET(labelw)); /* Check to see if it needs to be in the bin for this -- cgit v1.2.3 From 81f4b7c5e21a23e97bdd267567b40cdbe0d528b7 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 15 Jun 2010 14:10:22 -0500 Subject: Making the path more unique and using the lower level path set function. --- libdbusmenu-gtk/client.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index a9c6657..c7d1140 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -158,9 +158,9 @@ swap_agroup (DbusmenuMenuitem * mi, gpointer userdata) { if (accel_path != NULL) { gtk_accel_map_change_entry(accel_path, key, modifiers, TRUE /* replace */); } else { - gchar * accel_path = g_strdup_printf("/Generated/%d", dbusmenu_menuitem_get_id(mi)); + gchar * accel_path = g_strdup_printf("/Generated/%X/%d", GPOINTER_TO_UINT(data->client), dbusmenu_menuitem_get_id(mi)); gtk_accel_map_add_entry(accel_path, key, modifiers); - gtk_menu_item_set_accel_path(gmi, accel_path); + gtk_widget_set_accel_path(GTK_WIDGET(gmi), accel_path, data->new_agroup); g_free(accel_path); } -- cgit v1.2.3 From 71817a1eed1c49d358d7cb1c093321ddc91fb258 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 15 Jun 2010 14:47:29 -0500 Subject: Adding a debug message --- libdbusmenu-gtk/client.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index c7d1140..d45360a 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -143,6 +143,8 @@ swap_agroup (DbusmenuMenuitem * mi, gpointer userdata) { GdkModifierType modifiers = 0; dbusmenu_menuitem_property_get_shortcut(mi, &key, &modifiers); + + g_debug("Setting shortcut on '%s': %d %X", dbusmenu_menuitem_property_get(mi, DBUSMENU_MENUITEM_PROP_LABEL), key, modifiers); if (key == 0) { return; -- cgit v1.2.3 From ce0a5c849081e8d6f54a28f771dce0136a4e4b93 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Sat, 19 Jun 2010 09:32:56 -0400 Subject: support gtk3 version of libdbusmenu-gtk --- configure.ac | 10 ++++++++ libdbusmenu-gtk/Makefile.am | 47 ++++++++++++++++++++++++++++++++----- libdbusmenu-gtk/dbusmenu-gtk3.pc.in | 14 +++++++++++ libdbusmenu-gtk/menu.c | 4 ++-- 4 files changed, 67 insertions(+), 8 deletions(-) create mode 100644 libdbusmenu-gtk/dbusmenu-gtk3.pc.in (limited to 'libdbusmenu-gtk') diff --git a/configure.ac b/configure.ac index 938fe84..ff8dc78 100644 --- a/configure.ac +++ b/configure.ac @@ -48,6 +48,7 @@ AC_SUBST(DBUSMENUGLIB_LIBS) ########################### GTK_REQUIRED_VERSION=2.16 +GTK3_REQUIRED_VERSION=2.90 PKG_CHECK_MODULES(DBUSMENUGTK, gtk+-2.0 >= $GTK_REQUIRED_VERSION glib-2.0 >= $GLIB_REQUIRED_VERSION @@ -57,6 +58,14 @@ PKG_CHECK_MODULES(DBUSMENUGTK, gtk+-2.0 >= $GTK_REQUIRED_VERSION AC_SUBST(DBUSMENUGTK_CFLAGS) AC_SUBST(DBUSMENUGTK_LIBS) +PKG_CHECK_MODULES(DBUSMENUGTK3, gtk+-3.0 >= $GTK3_REQUIRED_VERSION + glib-2.0 >= $GLIB_REQUIRED_VERSION + dbus-glib-1 >= $DBUS_REQUIRED_VERSION + libxml-2.0 >= $XML_REQUIRED_VERSION) + +AC_SUBST(DBUSMENUGTK3_CFLAGS) +AC_SUBST(DBUSMENUGTK3_LIBS) + ########################### # Dependencies - Testing ########################### @@ -123,6 +132,7 @@ libdbusmenu-glib/Makefile libdbusmenu-glib/dbusmenu-glib.pc libdbusmenu-gtk/Makefile libdbusmenu-gtk/dbusmenu-gtk.pc +libdbusmenu-gtk/dbusmenu-gtk3.pc tools/Makefile tools/testapp/Makefile tests/Makefile diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index 2be63b7..4f38b63 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -2,17 +2,21 @@ CLEANFILES = EXTRA_DIST = \ - dbusmenu-gtk.pc.in + dbusmenu-gtk.pc.in \ + dbusmenu-gtk3.pc.in lib_LTLIBRARIES = \ - libdbusmenu-gtk.la + libdbusmenu-gtk.la \ + libdbusmenu-gtk3.la libdbusmenu_gtkincludedir=$(includedir)/libdbusmenu-0.1/libdbusmenu-gtk/ +libdbusmenu_gtk3includedir=$(includedir)/libdbusmenu3-0.1/libdbusmenu-gtk/ libdbusmenu_gtkinclude_HEADERS = \ client.h \ menu.h \ menuitem.h +libdbusmenu_gtk3include_HEADERS = $(libdbusmenu_gtkinclude_HEADERS) libdbusmenu_gtk_la_SOURCES = \ client.h \ @@ -23,20 +27,27 @@ libdbusmenu_gtk_la_SOURCES = \ menu.c \ menuitem.h \ menuitem.c +libdbusmenu_gtk3_la_SOURCES = $(libdbusmenu_gtk_la_SOURCES) libdbusmenu_gtk_la_LDFLAGS = \ -version-info $(LIBDBUSMENU_CURRENT):$(LIBDBUSMENU_REVISION):$(LIBDBUSMENU_AGE) \ -no-undefined \ -export-symbols-regex "^[^_].*" +libdbusmenu_gtk3_la_LDFLAGS = $(libdbusmenu_gtk_la_LDFLAGS) libdbusmenu_gtk_la_CFLAGS = \ $(DBUSMENUGTK_CFLAGS) -I$(top_srcdir) -Wall -Werror -DG_DISABLE_DEPRECATED -DG_LOG_DOMAIN="\"LIBDBUSMENU-GTK\"" +libdbusmenu_gtk3_la_CFLAGS = \ + $(DBUSMENUGTK3_CFLAGS) -I$(top_srcdir) -Wall -Werror -DG_DISABLE_DEPRECATED -DG_LOG_DOMAIN="\"LIBDBUSMENU-GTK\"" libdbusmenu_gtk_la_LIBADD = \ ../libdbusmenu-glib/libdbusmenu-glib.la \ $(DBUSMENUGTK_LIBS) +libdbusmenu_gtk3_la_LIBADD = \ + ../libdbusmenu-glib/libdbusmenu-glib.la \ + $(DBUSMENUGTK3_LIBS) -pkgconfig_DATA = dbusmenu-gtk.pc +pkgconfig_DATA = dbusmenu-gtk.pc dbusmenu-gtk3.pc pkgconfigdir = $(libdir)/pkgconfig ######################### @@ -64,7 +75,16 @@ DbusmenuGtk_0_2_gir_CFLAGS = $(DBUSMENUGTK_CFLAGS) -I$(top_srcdir) DbusmenuGtk_0_2_gir_LIBS = libdbusmenu-gtk.la DbusmenuGtk_0_2_gir_FILES = $(addprefix $(srcdir)/, $(introspection_sources)) -INTROSPECTION_GIRS += DbusmenuGtk-0.2.gir +DbusmenuGtk3-0.2.gir: libdbusmenu-gtk3.la +DbusmenuGtk3_0_2_gir_INCLUDES = \ + GObject-2.0 \ + Gtk-3.0 \ + Dbusmenu-Glib-0.2 +DbusmenuGtk3_0_2_gir_CFLAGS = $(DBUSMENUGTK3_CFLAGS) -I$(top_srcdir) +DbusmenuGtk3_0_2_gir_LIBS = libdbusmenu-gtk3.la +DbusmenuGtk3_0_2_gir_FILES = $(addprefix $(srcdir)/, $(introspection_sources)) + +INTROSPECTION_GIRS += DbusmenuGtk-0.2.gir DbusmenuGtk3-0.2.gir girdir = $(datadir)/gir-1.0 gir_DATA = $(INTROSPECTION_GIRS) @@ -83,7 +103,7 @@ endif if HAVE_INTROSPECTION vapidir = $(datadir)/vala/vapi -vapi_DATA = DbusmenuGtk-0.2.vapi +vapi_DATA = DbusmenuGtk-0.2.vapi DbusmenuGtk3-0.2.vapi DbusmenuGtk-0.2.vapi: DbusmenuGtk-0.2.tmp.gir Makefile.am $(VALA_API_GEN) --library=DbusmenuGtk-0.2 \ @@ -94,13 +114,28 @@ DbusmenuGtk-0.2.vapi: DbusmenuGtk-0.2.tmp.gir Makefile.am --vapidir=$(top_builddir)/libdbusmenu-glib \ $< +DbusmenuGtk3-0.2.vapi: DbusmenuGtk3-0.2.tmp.gir Makefile.am + $(VALA_API_GEN) --library=DbusmenuGtk3-0.2 \ + --pkg gdk-pixbuf-3.0 \ + --pkg gtk+-3.0 \ + --pkg atk \ + --pkg Dbusmenu-Glib-0.2 \ + --vapidir=$(top_builddir)/libdbusmenu-glib \ + $< + DbusmenuGtk-0.2.tmp.gir: DbusmenuGtk-0.2.gir $(SED) \ -e "s|GdkPixbuf.Pixbuf|Gdk.Pixbuf|g" \ -e "s|Atk.ImplementorIface|Atk.Implementor|g" \ $< > $@ -CLEANFILES += $(vapi_DATA) DbusmenuGtk-0.2.tmp.gir +DbusmenuGtk3-0.2.tmp.gir: DbusmenuGtk3-0.2.gir + $(SED) \ + -e "s|GdkPixbuf.Pixbuf|Gdk.Pixbuf|g" \ + -e "s|Atk.ImplementorIface|Atk.Implementor|g" \ + $< > $@ + +CLEANFILES += $(vapi_DATA) DbusmenuGtk-0.2.tmp.gir DbusmenuGtk3-0.2.tmp.gir endif diff --git a/libdbusmenu-gtk/dbusmenu-gtk3.pc.in b/libdbusmenu-gtk/dbusmenu-gtk3.pc.in new file mode 100644 index 0000000..e2c4cc3 --- /dev/null +++ b/libdbusmenu-gtk/dbusmenu-gtk3.pc.in @@ -0,0 +1,14 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +bindir=@bindir@ +includedir=@includedir@ + +Cflags: -I${includedir}/libdbusmenu-3.1 +Requires: dbus-glib-1 dbusmenu-glib +Libs: -L${libdir} -ldbusmenu-gtk3 + +Name: libdbusmenu-gtk3 +Description: libdbusmenu-gtk3. +Version: @VERSION@ + diff --git a/libdbusmenu-gtk/menu.c b/libdbusmenu-gtk/menu.c index 4fa546b..3e6f2dd 100644 --- a/libdbusmenu-gtk/menu.c +++ b/libdbusmenu-gtk/menu.c @@ -237,7 +237,7 @@ root_child_added (DbusmenuMenuitem * root, DbusmenuMenuitem * child, guint posit GtkMenuItem * mi = dbusmenu_gtkclient_menuitem_get(priv->client, child); if (mi != NULL) { GtkWidget * item = GTK_WIDGET(mi); - gtk_menu_insert(GTK_MENU(menu), item, dbusmenu_menuitem_get_position_realized(child, root)); + gtk_menu_shell_insert(GTK_MENU_SHELL(menu), item, dbusmenu_menuitem_get_position_realized(child, root)); #ifdef MASSIVEDEBUGGING menu_pos_t menu_pos; menu_pos.mi = mi; @@ -299,7 +299,7 @@ child_realized (DbusmenuMenuitem * child, gpointer userdata) GtkWidget * child_widget = GTK_WIDGET(dbusmenu_gtkclient_menuitem_get(priv->client, child)); if (child_widget != NULL) { - gtk_menu_append(menu, child_widget); + gtk_menu_shell_append(GTK_MENU_SHELL(menu), child_widget); gtk_menu_reorder_child(GTK_MENU(menu), child_widget, dbusmenu_menuitem_get_position_realized(child, dbusmenu_client_get_root(DBUSMENU_CLIENT(priv->client)))); } else { g_warning("Child is realized, but doesn't have a GTK Widget!"); -- cgit v1.2.3 From cfdd33a19758224cb835efa705a410d3d4d0db91 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Mon, 21 Jun 2010 14:37:18 -0500 Subject: Add the accelerators. --- libdbusmenu-gtk/client.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index d45360a..91bc816 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -130,13 +130,13 @@ struct _swap_agroup_t { /* Looks at the old version of the accelerator group and the new one and makes the state proper. */ -static void -swap_agroup (DbusmenuMenuitem * mi, gpointer userdata) { - swap_agroup_t * data = (swap_agroup_t *)userdata; +static gboolean +do_swap_agroup (DbusmenuMenuitem * mi, gpointer userdata) { + swap_agroup_t * data = (swap_agroup_t *)userdata; /* If we don't have a shortcut we don't care */ if (!dbusmenu_menuitem_property_exist(mi, DBUSMENU_MENUITEM_PROP_SHORTCUT)) { - return; + return FALSE; } guint key = 0; @@ -145,14 +145,14 @@ swap_agroup (DbusmenuMenuitem * mi, gpointer userdata) { dbusmenu_menuitem_property_get_shortcut(mi, &key, &modifiers); g_debug("Setting shortcut on '%s': %d %X", dbusmenu_menuitem_property_get(mi, DBUSMENU_MENUITEM_PROP_LABEL), key, modifiers); - + if (key == 0) { - return; + return FALSE; } GtkMenuItem * gmi = dbusmenu_gtkclient_menuitem_get(data->client, mi); if (gmi == NULL) { - return; + return FALSE; } const gchar * accel_path = gtk_menu_item_get_accel_path(gmi); @@ -161,6 +161,7 @@ swap_agroup (DbusmenuMenuitem * mi, gpointer userdata) { gtk_accel_map_change_entry(accel_path, key, modifiers, TRUE /* replace */); } else { gchar * accel_path = g_strdup_printf("/Generated/%X/%d", GPOINTER_TO_UINT(data->client), dbusmenu_menuitem_get_id(mi)); + gtk_accel_map_add_entry(accel_path, key, modifiers); gtk_widget_set_accel_path(GTK_WIDGET(gmi), accel_path, data->new_agroup); g_free(accel_path); @@ -171,7 +172,14 @@ swap_agroup (DbusmenuMenuitem * mi, gpointer userdata) { gtk_menu_set_accel_group(submenu, data->new_agroup); } - return; + return TRUE; +} + +static void +swap_agroup (DbusmenuMenuitem *mi, gpointer userdata) { + do_swap_agroup (mi, userdata); + + return; /* See what I did here, Ted? :) */ } /* Refresh the shortcut for an entry */ @@ -188,7 +196,17 @@ refresh_shortcut (DbusmenuGtkClient * client, DbusmenuMenuitem * mi) data.old_agroup = priv->agroup; data.new_agroup = priv->agroup; - return swap_agroup(mi, &data); + if (do_swap_agroup(mi, &data)) { + guint key; + GdkModifierType mod; + GtkMenuItem *gmi = dbusmenu_gtkclient_menuitem_get (client, mi); + + dbusmenu_menuitem_property_get_shortcut (mi, &key, &mod); + + gtk_widget_add_accelerator (GTK_WIDGET (gmi), "activate", priv->agroup, key, mod, GTK_ACCEL_VISIBLE); + } + + return; } -- cgit v1.2.3 From 2872698e6eb9bfab4d56f5d98fd8f9494738a398 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Tue, 22 Jun 2010 11:03:42 -0500 Subject: Fix setting shortcuts from GtkMenuItem --- libdbusmenu-gtk/menuitem.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index a448f88..57cd258 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -246,19 +246,20 @@ dbusmenu_menuitem_property_set_shortcut_menuitem (DbusmenuMenuitem * menuitem, c g_return_val_if_fail(GTK_IS_MENU_ITEM(gmi), FALSE); GClosure * closure = NULL; - GList * clist; + GtkWidget *label = GTK_BIN (gmi)->child; - clist = gtk_widget_list_accel_closures(GTK_WIDGET(gmi)); - if (clist == NULL) { - g_warning("Menuitem does not have any closures."); - return FALSE; - } + if (GTK_IS_ACCEL_LABEL (label)) + { + g_object_get (label, + "accel-closure", &closure, + NULL); + } - closure = (GClosure *)clist->data; - g_list_free(clist); + if (closure == NULL) + return FALSE; GtkAccelGroup * group = gtk_accel_group_from_accel_closure(closure); - + /* Seriously, if this returns NULL something is seriously wrong in GTK. */ g_return_val_if_fail(group != NULL, FALSE); @@ -267,6 +268,9 @@ dbusmenu_menuitem_property_set_shortcut_menuitem (DbusmenuMenuitem * menuitem, c /* Again, not much we can do except complain loudly. */ g_return_val_if_fail(key != NULL, FALSE); + if (!gtk_accelerator_valid (key->accel_key, key->accel_mods)) + return FALSE; + return dbusmenu_menuitem_property_set_shortcut(menuitem, key->accel_key, key->accel_mods); } -- cgit v1.2.3 From 49ce6868ccba0928a401e15fe11689ebab711471 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 22 Jun 2010 14:07:28 -0500 Subject: Putting in several GValue checks to ensure we're getting what we thing we're getting. --- libdbusmenu-gtk/menuitem.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 57cd258..a250431 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -295,6 +295,9 @@ dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * ke if (wrapper == NULL) { return; } + if (!G_VALUE_HOLDS_BOXED(wrapper)) { + return; + } GValueArray * wrapperarray = (GValueArray *)g_value_get_boxed(wrapper); if (wrapperarray->n_values == 0) { @@ -306,6 +309,10 @@ dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * ke } GValue * ventryarray = g_value_array_get_nth(wrapperarray, 0); + if (!G_VALUE_HOLDS_BOXED(ventryarray)) { + return; + } + GValueArray * entryarray = (GValueArray *)g_value_get_boxed(ventryarray); if (entryarray->n_values == 0) { /* Seems a little odd, but really, we're saying that it isn't a @@ -316,6 +323,10 @@ dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * ke /* Parse through modifiers */ int i; for (i = 0; i < entryarray->n_values - 1; i++) { + if (!G_VALUE_HOLDS_STRING(g_value_array_get_nth(entryarray, i))) { + continue; + } + if (g_strcmp0(g_value_get_string(g_value_array_get_nth(entryarray, i)), DBUSMENU_MENUITEM_SHORTCUT_CONTROL) == 0) { *modifier |= GDK_CONTROL_MASK; continue; -- cgit v1.2.3 From d9922623de540c7d670c67a96a83722dd6674f31 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 22 Jun 2010 14:15:14 -0500 Subject: Refactoring to make things more clear --- libdbusmenu-gtk/menuitem.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index a250431..a201558 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -323,23 +323,25 @@ dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * ke /* Parse through modifiers */ int i; for (i = 0; i < entryarray->n_values - 1; i++) { - if (!G_VALUE_HOLDS_STRING(g_value_array_get_nth(entryarray, i))) { + GValue * value = g_value_array_get_nth(entryarray, i); + + if (!G_VALUE_HOLDS_STRING(value)) { continue; } - if (g_strcmp0(g_value_get_string(g_value_array_get_nth(entryarray, i)), DBUSMENU_MENUITEM_SHORTCUT_CONTROL) == 0) { + if (g_strcmp0(g_value_get_string(value), DBUSMENU_MENUITEM_SHORTCUT_CONTROL) == 0) { *modifier |= GDK_CONTROL_MASK; continue; } - if (g_strcmp0(g_value_get_string(g_value_array_get_nth(entryarray, i)), DBUSMENU_MENUITEM_SHORTCUT_ALT) == 0) { + if (g_strcmp0(g_value_get_string(value), DBUSMENU_MENUITEM_SHORTCUT_ALT) == 0) { *modifier |= GDK_MOD1_MASK; continue; } - if (g_strcmp0(g_value_get_string(g_value_array_get_nth(entryarray, i)), DBUSMENU_MENUITEM_SHORTCUT_SHIFT) == 0) { + if (g_strcmp0(g_value_get_string(value), DBUSMENU_MENUITEM_SHORTCUT_SHIFT) == 0) { *modifier |= GDK_SHIFT_MASK; continue; } - if (g_strcmp0(g_value_get_string(g_value_array_get_nth(entryarray, i)), DBUSMENU_MENUITEM_SHORTCUT_SUPER) == 0) { + if (g_strcmp0(g_value_get_string(value), DBUSMENU_MENUITEM_SHORTCUT_SUPER) == 0) { *modifier |= GDK_SUPER_MASK; continue; } -- cgit v1.2.3 From a3e3bf18795873dcb8cafbaac758dc93448f49bf Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 22 Jun 2010 14:19:40 -0500 Subject: Checking the final value as well. --- libdbusmenu-gtk/menuitem.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index a201558..e1e1e30 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -349,7 +349,13 @@ dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * ke GdkModifierType tempmod; - gtk_accelerator_parse(g_value_get_string(g_value_array_get_nth(entryarray, entryarray->n_values - 1)), key, &tempmod); + GValue * accelval = g_value_array_get_nth(entryarray, entryarray->n_values - 1); + if (!G_VALUE_HOLDS_STRING(accelval)) { + *modifier = 0; + return; + } + + gtk_accelerator_parse(g_value_get_string(accelval), key, &tempmod); return; } -- cgit v1.2.3 From 2412ce9b02272a0928157b91a15d67b8f1b805a5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 22 Jun 2010 14:37:24 -0500 Subject: Not checking just for boxed, looking inside a bit. --- libdbusmenu-gtk/menuitem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index e1e1e30..0eb0758 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -295,7 +295,7 @@ dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * ke if (wrapper == NULL) { return; } - if (!G_VALUE_HOLDS_BOXED(wrapper)) { + if (!G_VALUE_HOLDS(wrapper, G_TYPE_VALUE_ARRAY)) { return; } @@ -309,7 +309,7 @@ dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * ke } GValue * ventryarray = g_value_array_get_nth(wrapperarray, 0); - if (!G_VALUE_HOLDS_BOXED(ventryarray)) { + if (!G_VALUE_HOLDS(ventryarray, G_TYPE_VALUE_ARRAY)) { return; } -- cgit v1.2.3 From 5c0f9d84925fc1221f20b8356810c015dbad962c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 22 Jun 2010 14:45:03 -0500 Subject: A couple of warning messages. --- libdbusmenu-gtk/menuitem.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 0eb0758..a7aa9d2 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -296,6 +296,7 @@ dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * ke return; } if (!G_VALUE_HOLDS(wrapper, G_TYPE_VALUE_ARRAY)) { + g_warning("Unexpected shortcut structure. Wrapper is: %s", G_VALUE_TYPE_NAME(wrapper)); return; } @@ -310,6 +311,7 @@ dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * ke GValue * ventryarray = g_value_array_get_nth(wrapperarray, 0); if (!G_VALUE_HOLDS(ventryarray, G_TYPE_VALUE_ARRAY)) { + g_warning("Unexpected shortcut structure. Value array is: %s", G_VALUE_TYPE_NAME(ventryarray)); return; } -- cgit v1.2.3 From 2a90535dae3ef2d97ff02c2c6325615de0f6ca09 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 22 Jun 2010 16:29:08 -0500 Subject: Cleaning up usage of get_shortcut to only print/set if it sets a key --- libdbusmenu-gtk/client.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 91bc816..c73c90f 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -144,12 +144,12 @@ do_swap_agroup (DbusmenuMenuitem * mi, gpointer userdata) { dbusmenu_menuitem_property_get_shortcut(mi, &key, &modifiers); - g_debug("Setting shortcut on '%s': %d %X", dbusmenu_menuitem_property_get(mi, DBUSMENU_MENUITEM_PROP_LABEL), key, modifiers); - if (key == 0) { return FALSE; } + g_debug("Setting shortcut on '%s': %d %X", dbusmenu_menuitem_property_get(mi, DBUSMENU_MENUITEM_PROP_LABEL), key, modifiers); + GtkMenuItem * gmi = dbusmenu_gtkclient_menuitem_get(data->client, mi); if (gmi == NULL) { return FALSE; @@ -197,16 +197,18 @@ refresh_shortcut (DbusmenuGtkClient * client, DbusmenuMenuitem * mi) data.new_agroup = priv->agroup; if (do_swap_agroup(mi, &data)) { - guint key; - GdkModifierType mod; - GtkMenuItem *gmi = dbusmenu_gtkclient_menuitem_get (client, mi); + guint key = 0; + GdkModifierType mod = 0; + GtkMenuItem *gmi = dbusmenu_gtkclient_menuitem_get (client, mi); - dbusmenu_menuitem_property_get_shortcut (mi, &key, &mod); + dbusmenu_menuitem_property_get_shortcut (mi, &key, &mod); - gtk_widget_add_accelerator (GTK_WIDGET (gmi), "activate", priv->agroup, key, mod, GTK_ACCEL_VISIBLE); - } + if (key != 0) { + gtk_widget_add_accelerator (GTK_WIDGET (gmi), "activate", priv->agroup, key, mod, GTK_ACCEL_VISIBLE); + } + } - return; + return; } -- cgit v1.2.3 From 0ace7ce970cdffdca66ab7d19c152269f358b730 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 22 Jun 2010 16:37:10 -0500 Subject: Switching around the get function to be GPtrArray-GStrV --- libdbusmenu-gtk/menuitem.c | 43 +++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 26 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index a7aa9d2..5d41934 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -295,28 +295,28 @@ dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * ke if (wrapper == NULL) { return; } - if (!G_VALUE_HOLDS(wrapper, G_TYPE_VALUE_ARRAY)) { + if (!G_VALUE_HOLDS(wrapper, G_TYPE_PTR_ARRAY)) { g_warning("Unexpected shortcut structure. Wrapper is: %s", G_VALUE_TYPE_NAME(wrapper)); return; } - GValueArray * wrapperarray = (GValueArray *)g_value_get_boxed(wrapper); - if (wrapperarray->n_values == 0) { + GPtrArray * wrapperarray = (GPtrArray *)g_value_get_boxed(wrapper); + if (wrapperarray->len == 0) { return; } - if (wrapperarray->n_values != 1) { + if (wrapperarray->len != 1) { g_warning("Shortcut is more than one entry. Which we don't currently support. Taking the first."); } - GValue * ventryarray = g_value_array_get_nth(wrapperarray, 0); - if (!G_VALUE_HOLDS(ventryarray, G_TYPE_VALUE_ARRAY)) { + GValue * ventryarray = g_ptr_array_index(wrapperarray, 0); + if (!G_VALUE_HOLDS(ventryarray, G_TYPE_STRV)) { g_warning("Unexpected shortcut structure. Value array is: %s", G_VALUE_TYPE_NAME(ventryarray)); return; } - GValueArray * entryarray = (GValueArray *)g_value_get_boxed(ventryarray); - if (entryarray->n_values == 0) { + gchar ** entryarray = (gchar **)g_value_get_boxed(ventryarray); + if (entryarray == NULL || entryarray[0] == NULL) { /* Seems a little odd, but really, we're saying that it isn't a shortcut, so I'm comfortable with exiting silently. */ return; @@ -324,40 +324,31 @@ dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * ke /* Parse through modifiers */ int i; - for (i = 0; i < entryarray->n_values - 1; i++) { - GValue * value = g_value_array_get_nth(entryarray, i); + for (i = 0; entryarray[i + 1] != NULL; i++) { + gchar * value = entryarray[i]; - if (!G_VALUE_HOLDS_STRING(value)) { - continue; - } - - if (g_strcmp0(g_value_get_string(value), DBUSMENU_MENUITEM_SHORTCUT_CONTROL) == 0) { + if (g_strcmp0(value, DBUSMENU_MENUITEM_SHORTCUT_CONTROL) == 0) { *modifier |= GDK_CONTROL_MASK; continue; } - if (g_strcmp0(g_value_get_string(value), DBUSMENU_MENUITEM_SHORTCUT_ALT) == 0) { + if (g_strcmp0(value, DBUSMENU_MENUITEM_SHORTCUT_ALT) == 0) { *modifier |= GDK_MOD1_MASK; continue; } - if (g_strcmp0(g_value_get_string(value), DBUSMENU_MENUITEM_SHORTCUT_SHIFT) == 0) { + if (g_strcmp0(value, DBUSMENU_MENUITEM_SHORTCUT_SHIFT) == 0) { *modifier |= GDK_SHIFT_MASK; continue; } - if (g_strcmp0(g_value_get_string(value), DBUSMENU_MENUITEM_SHORTCUT_SUPER) == 0) { + if (g_strcmp0(value, DBUSMENU_MENUITEM_SHORTCUT_SUPER) == 0) { *modifier |= GDK_SUPER_MASK; continue; } } GdkModifierType tempmod; - - GValue * accelval = g_value_array_get_nth(entryarray, entryarray->n_values - 1); - if (!G_VALUE_HOLDS_STRING(accelval)) { - *modifier = 0; - return; - } - - gtk_accelerator_parse(g_value_get_string(accelval), key, &tempmod); + gchar * accelval = entryarray[i]; + gtk_accelerator_parse(accelval, key, &tempmod); return; } + -- cgit v1.2.3 From c94eb1cfe25551c528409fdcb9d56446a915ed0f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 22 Jun 2010 16:50:42 -0500 Subject: Lowering our protection a little, but hopefully this'll make it happy. --- libdbusmenu-gtk/menuitem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 5d41934..44e78e1 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -295,7 +295,7 @@ dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * ke if (wrapper == NULL) { return; } - if (!G_VALUE_HOLDS(wrapper, G_TYPE_PTR_ARRAY)) { + if (!G_VALUE_HOLDS(wrapper, G_TYPE_BOXED)) { g_warning("Unexpected shortcut structure. Wrapper is: %s", G_VALUE_TYPE_NAME(wrapper)); return; } @@ -310,7 +310,7 @@ dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * ke } GValue * ventryarray = g_ptr_array_index(wrapperarray, 0); - if (!G_VALUE_HOLDS(ventryarray, G_TYPE_STRV)) { + if (!G_VALUE_HOLDS(ventryarray, G_TYPE_BOXED)) { g_warning("Unexpected shortcut structure. Value array is: %s", G_VALUE_TYPE_NAME(ventryarray)); return; } -- cgit v1.2.3 From f071a21b449e8ac1d34b593dc788929e175d987f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 23 Jun 2010 09:07:27 -0500 Subject: Building us some custom types. --- libdbusmenu-gtk/menuitem.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 44e78e1..532f478 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -29,6 +29,7 @@ License version 3 and version 2.1 along with this program. If not, see #include "menuitem.h" #include #include +#include /** dbusmenu_menuitem_property_set_image: @@ -274,6 +275,27 @@ dbusmenu_menuitem_property_set_shortcut_menuitem (DbusmenuMenuitem * menuitem, c return dbusmenu_menuitem_property_set_shortcut(menuitem, key->accel_key, key->accel_mods); } +static const gchar * wrapper_type_name = "wrapper-type"; +static const gchar * string_array_type_name = "string-array-type"; + +static GType wrapper_type = 0; +static GType string_array_type = 0; + +/* Works with dbus to get types for the collections that we're using. + Should be pretty quick if we've done this once already. */ +static void +setup_collections (void) { + if (string_array_type == 0) { + dbus_g_type_get_collection(string_array_type_name, G_TYPE_STRING); + } + + if (wrapper_type == 0) { + dbus_g_type_get_collection(wrapper_type_name, string_array_type); + } + + return; +} + /** dbusmenu_menuitem_property_get_shortcut: @menuitem: The #DbusmenuMenuitem to get the shortcut off @@ -290,6 +312,7 @@ dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * ke *modifier = 0; g_return_if_fail(DBUSMENU_IS_MENUITEM(menuitem)); + setup_collections(); const GValue * wrapper = dbusmenu_menuitem_property_get_value(menuitem, DBUSMENU_MENUITEM_PROP_SHORTCUT); if (wrapper == NULL) { -- cgit v1.2.3 From 63fc1985fdf9ef74830ec27d7ad8c1bb03c54f0c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 23 Jun 2010 09:10:10 -0500 Subject: Using our complex types to start looking at things. --- libdbusmenu-gtk/menuitem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 532f478..9154592 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -318,7 +318,7 @@ dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * ke if (wrapper == NULL) { return; } - if (!G_VALUE_HOLDS(wrapper, G_TYPE_BOXED)) { + if (!G_VALUE_HOLDS(wrapper, wrapper_type)) { g_warning("Unexpected shortcut structure. Wrapper is: %s", G_VALUE_TYPE_NAME(wrapper)); return; } @@ -333,7 +333,7 @@ dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * ke } GValue * ventryarray = g_ptr_array_index(wrapperarray, 0); - if (!G_VALUE_HOLDS(ventryarray, G_TYPE_BOXED)) { + if (!G_VALUE_HOLDS(ventryarray, string_array_type)) { g_warning("Unexpected shortcut structure. Value array is: %s", G_VALUE_TYPE_NAME(ventryarray)); return; } -- cgit v1.2.3 From 51815a2cd05dd18d649113f2fc76247d7fdf00d1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 23 Jun 2010 09:36:57 -0500 Subject: Eh, that's not a rat hole that I want to go down. Realized I'd have to build the types with their vtables to go that way. We'll try using the others. --- libdbusmenu-gtk/menuitem.c | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 9154592..8874ebe 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -275,27 +275,6 @@ dbusmenu_menuitem_property_set_shortcut_menuitem (DbusmenuMenuitem * menuitem, c return dbusmenu_menuitem_property_set_shortcut(menuitem, key->accel_key, key->accel_mods); } -static const gchar * wrapper_type_name = "wrapper-type"; -static const gchar * string_array_type_name = "string-array-type"; - -static GType wrapper_type = 0; -static GType string_array_type = 0; - -/* Works with dbus to get types for the collections that we're using. - Should be pretty quick if we've done this once already. */ -static void -setup_collections (void) { - if (string_array_type == 0) { - dbus_g_type_get_collection(string_array_type_name, G_TYPE_STRING); - } - - if (wrapper_type == 0) { - dbus_g_type_get_collection(wrapper_type_name, string_array_type); - } - - return; -} - /** dbusmenu_menuitem_property_get_shortcut: @menuitem: The #DbusmenuMenuitem to get the shortcut off @@ -312,13 +291,12 @@ dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * ke *modifier = 0; g_return_if_fail(DBUSMENU_IS_MENUITEM(menuitem)); - setup_collections(); const GValue * wrapper = dbusmenu_menuitem_property_get_value(menuitem, DBUSMENU_MENUITEM_PROP_SHORTCUT); if (wrapper == NULL) { return; } - if (!G_VALUE_HOLDS(wrapper, wrapper_type)) { + if (!G_VALUE_HOLDS(wrapper, G_TYPE_BOXED)) { g_warning("Unexpected shortcut structure. Wrapper is: %s", G_VALUE_TYPE_NAME(wrapper)); return; } @@ -333,7 +311,7 @@ dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * ke } GValue * ventryarray = g_ptr_array_index(wrapperarray, 0); - if (!G_VALUE_HOLDS(ventryarray, string_array_type)) { + if (!G_VALUE_HOLDS(ventryarray, G_TYPE_BOXED)) { g_warning("Unexpected shortcut structure. Value array is: %s", G_VALUE_TYPE_NAME(ventryarray)); return; } -- cgit v1.2.3 From 4c05e67b833cdd4467eab0a740367536ebfb2c33 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 23 Jun 2010 10:17:44 -0500 Subject: Reworking to use collection iterators. --- libdbusmenu-gtk/menuitem.c | 117 ++++++++++++++++++++++++++------------------- 1 file changed, 69 insertions(+), 48 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 8874ebe..fa94c1e 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -275,6 +275,69 @@ dbusmenu_menuitem_property_set_shortcut_menuitem (DbusmenuMenuitem * menuitem, c return dbusmenu_menuitem_property_set_shortcut(menuitem, key->accel_key, key->accel_mods); } +typedef struct _iter_data_t iter_data_t; +struct _iter_data_t { + guint * key; + GdkModifierType * modifier; + const gchar * last_string; +}; + +static void +_string_iterator (const GValue * value, gpointer user_data) +{ + iter_data_t * iter_data = (iter_data_t *)user_data; + + if (!G_VALUE_HOLDS_STRING(value)) { + return; + } + + const gchar * string = g_value_get_string(value); + iter_data->last_string = string; + + if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_CONTROL) == 0) { + *iter_data->modifier |= GDK_CONTROL_MASK; + return; + } + if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_ALT) == 0) { + *iter_data->modifier |= GDK_MOD1_MASK; + return; + } + if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_SHIFT) == 0) { + *iter_data->modifier |= GDK_SHIFT_MASK; + return; + } + if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_SUPER) == 0) { + *iter_data->modifier |= GDK_SUPER_MASK; + return; + } + + return; +} + +static void +_wrapper_iterator (const GValue * value, gpointer user_data) +{ + iter_data_t * iter_data = (iter_data_t *)user_data; + + if (*iter_data->key != 0) { + g_warning("Shortcut is more than one entry. Which we don't currently support. Taking the first."); + return; + } + + if (!dbus_g_type_is_collection(G_VALUE_TYPE(value))) { + g_warning("Unexpected shortcut structure. Value array is: %s", G_VALUE_TYPE_NAME(value)); + } + + dbus_g_type_collection_value_iterate(value, _string_iterator, iter_data); + + if (iter_data->last_string != NULL) { + GdkModifierType tempmod; + gtk_accelerator_parse(iter_data->last_string, iter_data->key, &tempmod); + } + + return; +} + /** dbusmenu_menuitem_property_get_shortcut: @menuitem: The #DbusmenuMenuitem to get the shortcut off @@ -296,59 +359,17 @@ dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * ke if (wrapper == NULL) { return; } - if (!G_VALUE_HOLDS(wrapper, G_TYPE_BOXED)) { + if (!dbus_g_type_is_collection(G_VALUE_TYPE(wrapper))) { g_warning("Unexpected shortcut structure. Wrapper is: %s", G_VALUE_TYPE_NAME(wrapper)); return; } - GPtrArray * wrapperarray = (GPtrArray *)g_value_get_boxed(wrapper); - if (wrapperarray->len == 0) { - return; - } - - if (wrapperarray->len != 1) { - g_warning("Shortcut is more than one entry. Which we don't currently support. Taking the first."); - } - - GValue * ventryarray = g_ptr_array_index(wrapperarray, 0); - if (!G_VALUE_HOLDS(ventryarray, G_TYPE_BOXED)) { - g_warning("Unexpected shortcut structure. Value array is: %s", G_VALUE_TYPE_NAME(ventryarray)); - return; - } - - gchar ** entryarray = (gchar **)g_value_get_boxed(ventryarray); - if (entryarray == NULL || entryarray[0] == NULL) { - /* Seems a little odd, but really, we're saying that it isn't a - shortcut, so I'm comfortable with exiting silently. */ - return; - } - - /* Parse through modifiers */ - int i; - for (i = 0; entryarray[i + 1] != NULL; i++) { - gchar * value = entryarray[i]; - - if (g_strcmp0(value, DBUSMENU_MENUITEM_SHORTCUT_CONTROL) == 0) { - *modifier |= GDK_CONTROL_MASK; - continue; - } - if (g_strcmp0(value, DBUSMENU_MENUITEM_SHORTCUT_ALT) == 0) { - *modifier |= GDK_MOD1_MASK; - continue; - } - if (g_strcmp0(value, DBUSMENU_MENUITEM_SHORTCUT_SHIFT) == 0) { - *modifier |= GDK_SHIFT_MASK; - continue; - } - if (g_strcmp0(value, DBUSMENU_MENUITEM_SHORTCUT_SUPER) == 0) { - *modifier |= GDK_SUPER_MASK; - continue; - } - } + iter_data_t iter_data; + iter_data.key = key; + iter_data.modifier = modifier; + iter_data.last_string = NULL; - GdkModifierType tempmod; - gchar * accelval = entryarray[i]; - gtk_accelerator_parse(accelval, key, &tempmod); + dbus_g_type_collection_value_iterate(wrapper, _wrapper_iterator, &iter_data); return; } -- cgit v1.2.3 From 0591156dc8defd6a816634448d3ab9aa68f92882 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 23 Jun 2010 10:48:43 -0500 Subject: Apparently not a collection internally. --- libdbusmenu-gtk/menuitem.c | 66 +++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 36 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index fa94c1e..56dd192 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -279,60 +279,55 @@ typedef struct _iter_data_t iter_data_t; struct _iter_data_t { guint * key; GdkModifierType * modifier; - const gchar * last_string; }; static void -_string_iterator (const GValue * value, gpointer user_data) +_wrapper_iterator (const GValue * value, gpointer user_data) { iter_data_t * iter_data = (iter_data_t *)user_data; - if (!G_VALUE_HOLDS_STRING(value)) { + if (*iter_data->key != 0) { + g_warning("Shortcut is more than one entry. Which we don't currently support. Taking the first."); return; } - const gchar * string = g_value_get_string(value); - iter_data->last_string = string; - - if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_CONTROL) == 0) { - *iter_data->modifier |= GDK_CONTROL_MASK; - return; - } - if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_ALT) == 0) { - *iter_data->modifier |= GDK_MOD1_MASK; - return; - } - if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_SHIFT) == 0) { - *iter_data->modifier |= GDK_SHIFT_MASK; + if (!G_VALUE_HOLDS(value, G_TYPE_STRV)) { + g_warning("Unexpected shortcut structure. Value array is: %s", G_VALUE_TYPE_NAME(value)); return; } - if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_SUPER) == 0) { - *iter_data->modifier |= GDK_SUPER_MASK; + + gchar ** stringarray = (gchar **)g_value_get_boxed(value); + if (stringarray == NULL) { return; } - return; -} + const gchar * last_string = NULL; + int i; -static void -_wrapper_iterator (const GValue * value, gpointer user_data) -{ - iter_data_t * iter_data = (iter_data_t *)user_data; - - if (*iter_data->key != 0) { - g_warning("Shortcut is more than one entry. Which we don't currently support. Taking the first."); - return; - } + for (i = 0; stringarray[i] != NULL; i++) { + last_string = stringarray[i]; - if (!dbus_g_type_is_collection(G_VALUE_TYPE(value))) { - g_warning("Unexpected shortcut structure. Value array is: %s", G_VALUE_TYPE_NAME(value)); + if (g_strcmp0(last_string, DBUSMENU_MENUITEM_SHORTCUT_CONTROL) == 0) { + *iter_data->modifier |= GDK_CONTROL_MASK; + continue; + } + if (g_strcmp0(last_string, DBUSMENU_MENUITEM_SHORTCUT_ALT) == 0) { + *iter_data->modifier |= GDK_MOD1_MASK; + continue; + } + if (g_strcmp0(last_string, DBUSMENU_MENUITEM_SHORTCUT_SHIFT) == 0) { + *iter_data->modifier |= GDK_SHIFT_MASK; + continue; + } + if (g_strcmp0(last_string, DBUSMENU_MENUITEM_SHORTCUT_SUPER) == 0) { + *iter_data->modifier |= GDK_SUPER_MASK; + continue; + } } - dbus_g_type_collection_value_iterate(value, _string_iterator, iter_data); - - if (iter_data->last_string != NULL) { + if (last_string != NULL) { GdkModifierType tempmod; - gtk_accelerator_parse(iter_data->last_string, iter_data->key, &tempmod); + gtk_accelerator_parse(last_string, iter_data->key, &tempmod); } return; @@ -367,7 +362,6 @@ dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * ke iter_data_t iter_data; iter_data.key = key; iter_data.modifier = modifier; - iter_data.last_string = NULL; dbus_g_type_collection_value_iterate(wrapper, _wrapper_iterator, &iter_data); -- cgit v1.2.3 From 5bed312e9e03a4fd0f3ef189205bd3eb3f1a43bf Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 23 Jun 2010 11:15:12 -0500 Subject: Adding comments --- libdbusmenu-gtk/menuitem.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 56dd192..adc01f3 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -275,12 +275,16 @@ dbusmenu_menuitem_property_set_shortcut_menuitem (DbusmenuMenuitem * menuitem, c return dbusmenu_menuitem_property_set_shortcut(menuitem, key->accel_key, key->accel_mods); } +/* A set of typed data for the interator */ typedef struct _iter_data_t iter_data_t; struct _iter_data_t { guint * key; GdkModifierType * modifier; }; +/* Goes through the wrapper items. In reality we only support one + so it checks to see if a key is set first. But, we could possibly, + support more in the future. */ static void _wrapper_iterator (const GValue * value, gpointer user_data) { -- cgit v1.2.3 From 9c28ec10b2481d4374dd83310d9a894dca01d5c1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 23 Jun 2010 14:32:47 -0500 Subject: Start building structures more like the KDE ones. --- libdbusmenu-gtk/menuitem.c | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index adc01f3..811ff1f 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -161,17 +161,6 @@ dbusmenu_menuitem_property_set_shortcut_string (DbusmenuMenuitem * menuitem, con return dbusmenu_menuitem_property_set_shortcut(menuitem, key, modifier); } -/* Append strings to an g_value_array */ -static void -_g_value_array_append_string (GValueArray * array, const gchar * string) -{ - GValue value = {0}; - g_value_init(&value, G_TYPE_STRING); - g_value_set_string(&value, string); - g_value_array_append(array, &value); - return; -} - /** dbusmenu_menuitem_property_set_shortcut: @menuitem: The #DbusmenuMenuitem to set the shortcut on @@ -189,31 +178,37 @@ dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, guint key, g_return_val_if_fail(DBUSMENU_IS_MENUITEM(menuitem), FALSE); g_return_val_if_fail(gtk_accelerator_valid(key, modifier), FALSE); - GValueArray * array = g_value_array_new(4); /* Four seems like the max we'd need, plus it's still small */ + GArray * array = g_array_sized_new(TRUE, TRUE, sizeof(gchar *), 4); /* Four seems like the max we'd need, plus it's still small */ + + const gchar * control_val = DBUSMENU_MENUITEM_SHORTCUT_CONTROL; + const gchar * alt_val = DBUSMENU_MENUITEM_SHORTCUT_ALT; + const gchar * shift_val = DBUSMENU_MENUITEM_SHORTCUT_SHIFT; + const gchar * super_val = DBUSMENU_MENUITEM_SHORTCUT_SUPER; if (modifier & GDK_CONTROL_MASK) { - _g_value_array_append_string(array, DBUSMENU_MENUITEM_SHORTCUT_CONTROL); + g_array_append_val(array, control_val); } if (modifier & GDK_MOD1_MASK) { - _g_value_array_append_string(array, DBUSMENU_MENUITEM_SHORTCUT_ALT); + g_array_append_val(array, alt_val); } if (modifier & GDK_SHIFT_MASK) { - _g_value_array_append_string(array, DBUSMENU_MENUITEM_SHORTCUT_SHIFT); + g_array_append_val(array, shift_val); } if (modifier & GDK_SUPER_MASK) { - _g_value_array_append_string(array, DBUSMENU_MENUITEM_SHORTCUT_SUPER); + g_array_append_val(array, super_val); } - _g_value_array_append_string(array, gdk_keyval_name(key)); + const gchar * keyname = gdk_keyval_name(key); + g_array_append_val(array, keyname); - GValueArray * wrapper = g_value_array_new(1); + GPtrArray * wrapper = g_ptr_array_new(); GValue wrap_val = {0}; - g_value_init(&wrap_val, G_TYPE_VALUE_ARRAY); - g_value_set_boxed(&wrap_val, array); - g_value_array_append(wrapper, &wrap_val); + g_value_init(&wrap_val, G_TYPE_STRV); + g_value_set_boxed(&wrap_val, array->data); + g_ptr_array_add(wrapper, &wrap_val); GValue value = {0}; - g_value_init(&value, G_TYPE_VALUE_ARRAY); + g_value_init(&value, G_TYPE_PTR_ARRAY); g_value_set_boxed(&value, wrapper); dbusmenu_menuitem_property_set_value(menuitem, DBUSMENU_MENUITEM_PROP_SHORTCUT, &value); -- cgit v1.2.3 From df4949bb3ea62b531bf2a38cc2f37a1f9ead4991 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 23 Jun 2010 14:41:30 -0500 Subject: The joy of specialized collections. --- libdbusmenu-gtk/menuitem.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 811ff1f..3a0f117 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -201,15 +201,22 @@ dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, guint key, const gchar * keyname = gdk_keyval_name(key); g_array_append_val(array, keyname); - GPtrArray * wrapper = g_ptr_array_new(); - GValue wrap_val = {0}; - g_value_init(&wrap_val, G_TYPE_STRV); - g_value_set_boxed(&wrap_val, array->data); - g_ptr_array_add(wrapper, &wrap_val); - - GValue value = {0}; - g_value_init(&value, G_TYPE_PTR_ARRAY); - g_value_set_boxed(&value, wrapper); + GType type = dbus_g_type_get_collection("GPtrArray", G_TYPE_STRV); + GPtrArray * wrapper = (GPtrArray *)dbus_g_type_specialized_construct(type); + + GValue value = {0,}; + g_value_init(&value, type); + g_value_take_boxed(&value, wrapper); + + DBusGTypeSpecializedAppendContext ctx; + dbus_g_type_specialized_init_append(&value, &ctx); + + GValue strval = {0,}; + g_value_init(&strval, G_TYPE_STRV); + g_value_take_boxed(&strval, array->data); + + dbus_g_type_specialized_collection_append(&ctx, &strval); + dbus_g_type_specialized_collection_end_append(&ctx); dbusmenu_menuitem_property_set_value(menuitem, DBUSMENU_MENUITEM_PROP_SHORTCUT, &value); -- cgit v1.2.3 From 85a801e7f19b862fd21c0286899d3b87bebcac83 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 23 Jun 2010 14:50:26 -0500 Subject: Freeing the array wrapper --- libdbusmenu-gtk/menuitem.c | 1 + 1 file changed, 1 insertion(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 3a0f117..9924546 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -214,6 +214,7 @@ dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, guint key, GValue strval = {0,}; g_value_init(&strval, G_TYPE_STRV); g_value_take_boxed(&strval, array->data); + g_array_free(array, FALSE); dbus_g_type_specialized_collection_append(&ctx, &strval); dbus_g_type_specialized_collection_end_append(&ctx); -- cgit v1.2.3 From aa58b4c6b6460a8f9e49953447994b479b9f1705 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 29 Jun 2010 18:12:08 -0500 Subject: Block separators from getting new submenus --- libdbusmenu-gtk/client.c | 1 + 1 file changed, 1 insertion(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index c73c90f..a46aef3 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -503,6 +503,7 @@ new_child (DbusmenuMenuitem * mi, DbusmenuMenuitem * child, guint position, Dbus #endif if (dbusmenu_menuitem_get_root(mi)) { return; } + if (g_strcmp0(dbusmenu_menuitem_property_get(mi, DBUSMENU_MENUITEM_PROP_TYPE), DBUSMENU_CLIENT_TYPES_SEPARATOR) == 0) { return; } gpointer ann_menu = g_object_get_data(G_OBJECT(mi), data_menu); GtkMenu * menu = GTK_MENU(ann_menu); -- cgit v1.2.3 From 72440f055a39e9a80feff00515f7ae8b49237278 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 2 Jul 2010 10:35:23 -0500 Subject: Only tell when we're doing massive debugging. --- libdbusmenu-gtk/client.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index a46aef3..b406697 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -148,7 +148,9 @@ do_swap_agroup (DbusmenuMenuitem * mi, gpointer userdata) { return FALSE; } + #ifdef MASSIVEDEBUGGING g_debug("Setting shortcut on '%s': %d %X", dbusmenu_menuitem_property_get(mi, DBUSMENU_MENUITEM_PROP_LABEL), key, modifiers); + #endif GtkMenuItem * gmi = dbusmenu_gtkclient_menuitem_get(data->client, mi); if (gmi == NULL) { -- cgit v1.2.3 From eff1ffd59b4ca9ccfe11146559e070e8f4cf1f06 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 7 Jul 2010 11:46:37 -0500 Subject: Ratcheting down the warning level of not finding a group. --- libdbusmenu-gtk/menuitem.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 9924546..5846aa7 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -264,9 +264,10 @@ dbusmenu_menuitem_property_set_shortcut_menuitem (DbusmenuMenuitem * menuitem, c GtkAccelGroup * group = gtk_accel_group_from_accel_closure(closure); - /* Seriously, if this returns NULL something is seriously - wrong in GTK. */ - g_return_val_if_fail(group != NULL, FALSE); + /* Apparently this is more common than I thought. */ + if (group == NULL) { + return FALSE; + } GtkAccelKey * key = gtk_accel_group_find(group, find_closure, closure); /* Again, not much we can do except complain loudly. */ -- cgit v1.2.3 From fd7ffaa78b2c75db0b8138903d7272ed15641ce1 Mon Sep 17 00:00:00 2001 From: Aurelien Gateau Date: Thu, 22 Jul 2010 10:44:33 +0200 Subject: Fix menu order in submenus --- libdbusmenu-gtk/client.c | 4 +- tests/Makefile.am | 47 ++++++++++++- tests/test-gtk-reorder-server.c | 19 ++++-- tests/test-gtk-submenu-client.c | 143 ++++++++++++++++++++++++++++++++++++++++ tests/test-gtk-submenu-server.c | 86 ++++++++++++++++++++++++ 5 files changed, 289 insertions(+), 10 deletions(-) create mode 100644 tests/test-gtk-submenu-client.c create mode 100644 tests/test-gtk-submenu-server.c (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index b406697..b5b509f 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -491,7 +491,7 @@ dbusmenu_gtkclient_newitem_base (DbusmenuGtkClient * client, DbusmenuMenuitem * /* Oh, we're a child, let's deal with that */ if (parent != NULL) { - new_child(parent, item, dbusmenu_menuitem_get_position_realized(item, parent), DBUSMENU_GTKCLIENT(client)); + new_child(parent, item, dbusmenu_menuitem_get_position(item, parent), DBUSMENU_GTKCLIENT(client)); } return; @@ -519,7 +519,7 @@ new_child (DbusmenuMenuitem * mi, DbusmenuMenuitem * child, guint position, Dbus } GtkMenuItem * childmi = dbusmenu_gtkclient_menuitem_get(gtkclient, child); - gtk_menu_shell_insert(GTK_MENU_SHELL(menu), GTK_WIDGET(childmi), dbusmenu_menuitem_get_position_realized(child, mi)); + gtk_menu_shell_insert(GTK_MENU_SHELL(menu), GTK_WIDGET(childmi), position); gtk_widget_show(GTK_WIDGET(menu)); return; diff --git a/tests/Makefile.am b/tests/Makefile.am index 63857a2..9f621cb 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -14,7 +14,8 @@ TESTS = \ test-gtk-objects-test \ test-gtk-label \ test-gtk-shortcut \ - test-gtk-reorder + test-gtk-reorder \ + test-gtk-submenu check_PROGRAMS = \ glib-server-nomenu \ @@ -36,7 +37,9 @@ check_PROGRAMS = \ test-glib-simple-items \ test-gtk-reorder-server \ test-json-client \ - test-json-server + test-json-server \ + test-gtk-submenu-server \ + test-gtk-submenu-client XVFB_RUN=". $(srcdir)/run-xvfb.sh" @@ -453,6 +456,46 @@ test_gtk_reorder_server_LDADD = \ $(DBUSMENUGTK_LIBS) \ $(DBUSMENUTESTS_LIBS) +######################### +# Test GTK Submenu +######################### + +test-gtk-submenu: test-gtk-submenu-client test-gtk-submenu-server Makefile.am + @echo "#!/bin/bash" > $@ + @echo $(XVFB_RUN) >> $@ + @echo $(DBUS_RUNNER) --task ./test-gtk-submenu-client --task-name Client --task ./test-gtk-submenu-server --task-name Server --ignore-return >> $@ + @chmod +x $@ + +test_gtk_submenu_server_SOURCES = \ + test-gtk-submenu-server.c + +test_gtk_submenu_server_CFLAGS = \ + -I $(srcdir)/.. \ + $(DBUSMENUGTK_CFLAGS) \ + $(DBUSMENUTESTS_CFLAGS) \ + $(DBUSMENUGLIB_CFLAGS) -Wall -Werror + +test_gtk_submenu_server_LDADD = \ + ../libdbusmenu-glib/libdbusmenu-glib.la \ + ../libdbusmenu-gtk/libdbusmenu-gtk.la \ + $(DBUSMENUGTK_LIBS) \ + $(DBUSMENUTESTS_LIBS) + +test_gtk_submenu_client_SOURCES = \ + test-gtk-submenu-client.c + +test_gtk_submenu_client_CFLAGS = \ + -I $(srcdir)/.. \ + $(DBUSMENUGTK_CFLAGS) \ + $(DBUSMENUTESTS_CFLAGS) \ + $(DBUSMENUGLIB_CFLAGS) -Wall -Werror + +test_gtk_submenu_client_LDADD = \ + ../libdbusmenu-glib/libdbusmenu-glib.la \ + ../libdbusmenu-gtk/libdbusmenu-gtk.la \ + $(DBUSMENUGTK_LIBS) \ + $(DBUSMENUTESTS_LIBS) + ######################### # Test Mago ######################### diff --git a/tests/test-gtk-reorder-server.c b/tests/test-gtk-reorder-server.c index eee9bb8..a3fadb1 100644 --- a/tests/test-gtk-reorder-server.c +++ b/tests/test-gtk-reorder-server.c @@ -41,17 +41,18 @@ guint ordering [NUMBER_TESTS][NUMBER_ENTRIES] = { }; gchar * names [NUMBER_ENTRIES] = { - "One", "Two", "Three", "Four", "Five" + "0", "1", "2", "3", "4" }; DbusmenuMenuitem * entries[NUMBER_ENTRIES] = {0}; DbusmenuMenuitem * root = NULL; - +DbusmenuMenuitem * parent = NULL; gint test = 0; static DbusmenuServer * server = NULL; static GMainLoop * mainloop = NULL; +#if 0 static gboolean timer_func (gpointer data) { @@ -65,13 +66,14 @@ timer_func (gpointer data) int i; for (i = 0; i < NUMBER_ENTRIES; i++) { g_debug("Putting entry '%d' at position '%d'", i, ordering[test][i]); - dbusmenu_menuitem_child_reorder(root, entries[i], ordering[test][i]); + dbusmenu_menuitem_child_reorder(parent, entries[i], ordering[test][i]); dbusmenu_menuitem_property_set(entries[i], "label", names[ordering[test][i]]); } test++; return TRUE; } +#endif int main (int argc, char ** argv) @@ -101,13 +103,18 @@ main (int argc, char ** argv) dbusmenu_server_set_root(server, root); int i; + parent = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set(parent, "label", "Parent"); + dbusmenu_menuitem_child_append(root, parent); + for (i = 0; i < NUMBER_ENTRIES; i++) { entries[i] = dbusmenu_menuitem_new(); - dbusmenu_menuitem_child_append(root, entries[i]); + dbusmenu_menuitem_property_set(entries[i], "label", names[ordering[test][i]]); + dbusmenu_menuitem_child_append(parent, entries[i]); } - timer_func(NULL); - g_timeout_add_seconds(5, timer_func, NULL); + //timer_func(NULL); + //g_timeout_add_seconds(5, timer_func, NULL); mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); diff --git a/tests/test-gtk-submenu-client.c b/tests/test-gtk-submenu-client.c new file mode 100644 index 0000000..2e1ef7a --- /dev/null +++ b/tests/test-gtk-submenu-client.c @@ -0,0 +1,143 @@ +/* +A test for libdbusmenu to ensure its quality. + +Copyright 2009 Canonical Ltd. + +Authors: + Ted Gould + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + +#include +#include + +static GMainLoop * mainloop = NULL; +static gboolean passed = TRUE; + +static gboolean check_menu_content(GtkMenu * menu, char ** content) +{ + GList * child = gtk_container_get_children(GTK_CONTAINER(menu)); + char ** expected = content; + for (; child != NULL; child = g_list_next(child), ++expected) { + if (*expected == NULL) { + g_warning("Too many gtk items"); + return FALSE; + } + const char * label = gtk_menu_item_get_label(GTK_MENU_ITEM(child->data)); + if (g_strcmp0(label, *expected) != 0) { + g_warning("Expected '%s', got '%s'", *expected, label); + return FALSE; + } + } + if (*expected != NULL) { + g_warning("Not enough gtk items"); + return FALSE; + } + return TRUE; +} + +static void +abort_test(const char * message) +{ + if (message) { + g_warning("%s", message); + } + passed = FALSE; + g_main_loop_quit(mainloop); +} + +static gboolean +timer_func (gpointer data) +{ + static char * root_content[] = { "Folder 1", "Folder 2", NULL }; + static char * folder1_content[] = { "1.1", "1.2", "1.3", NULL }; + static char * folder2_content[] = { "2.1", "2.2", "2.3", NULL }; + + GtkMenuItem * root_item = GTK_MENU_ITEM(data); + GtkMenu * menu = GTK_MENU(gtk_menu_item_get_submenu(root_item)); + + /* Root */ + if (!check_menu_content(menu, root_content)) { + abort_test("Checking root content failed"); + return FALSE; + } + + /* Folder 1 */ + GList * child = gtk_container_get_children(GTK_CONTAINER(menu)); + GtkMenuItem * item = GTK_MENU_ITEM(child->data); + GtkMenu * folder_menu = GTK_MENU(gtk_menu_item_get_submenu(item)); + if (!folder_menu) { + abort_test("Folder 1 has no menu"); + return FALSE; + } + + if (!check_menu_content(folder_menu, folder1_content)) { + abort_test("Checking folder1 content failed"); + return FALSE; + } + + /* Folder 2 */ + child = g_list_next(child); + item = GTK_MENU_ITEM(child->data); + folder_menu = GTK_MENU(gtk_menu_item_get_submenu(item)); + if (!folder_menu) { + abort_test("Folder 2 has no menu"); + return FALSE; + } + + if (!check_menu_content(folder_menu, folder2_content)) { + abort_test("Checking folder2 content failed"); + return FALSE; + } + + passed = TRUE; + g_main_loop_quit(mainloop); + return FALSE; +} + +int +main (int argc, char ** argv) +{ + gtk_init(&argc, &argv); + + g_debug("Client Initialized. Waiting."); + /* Make sure the server starts up and all that */ + g_usleep(500000); + + g_debug("Building Window"); + GtkWidget * window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + GtkWidget * menubar = gtk_menu_bar_new(); + GtkWidget * menuitem = gtk_menu_item_new_with_label("Test"); + gtk_menu_item_set_submenu(GTK_MENU_ITEM(menuitem), GTK_WIDGET(dbusmenu_gtkmenu_new ("glib.label.test", "/org/test"))); + gtk_widget_show(menuitem); + gtk_menu_bar_append(menubar, menuitem); + gtk_widget_show(menubar); + gtk_container_add(GTK_CONTAINER(window), menubar); + gtk_window_set_title(GTK_WINDOW(window), "libdbusmenu-gtk test"); + gtk_widget_show(window); + + g_timeout_add_seconds(1, timer_func, menuitem); + + g_debug("Entering Mainloop"); + mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + if (passed) { + g_debug("Quiting"); + return 0; + } else { + g_debug("Quiting as we're a failure"); + return 1; + } +} diff --git a/tests/test-gtk-submenu-server.c b/tests/test-gtk-submenu-server.c new file mode 100644 index 0000000..ed9cf79 --- /dev/null +++ b/tests/test-gtk-submenu-server.c @@ -0,0 +1,86 @@ +/* +A test for libdbusmenu to ensure its quality. + +Copyright 2009 Canonical Ltd. + +Authors: + Ted Gould + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License version 3, as published +by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR +PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see . +*/ + +#include + +#include +#include +#include +#include + +#include +#include + +DbusmenuMenuitem * +add_item(DbusmenuMenuitem * parent, const char * label) +{ + DbusmenuMenuitem * item = dbusmenu_menuitem_new(); + dbusmenu_menuitem_property_set(item, "label", label); + dbusmenu_menuitem_child_append(parent, item); + return item; +} + +int +main (int argc, char ** argv) +{ + GError * error = NULL; + + g_type_init(); + + DBusGConnection * connection = dbus_g_bus_get(DBUS_BUS_SESSION, NULL); + g_debug("DBus ID: %s", dbus_connection_get_server_id(dbus_g_connection_get_connection(dbus_g_bus_get(DBUS_BUS_SESSION, NULL)))); + + DBusGProxy * bus_proxy = dbus_g_proxy_new_for_name(connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); + guint nameret = 0; + + if (!org_freedesktop_DBus_request_name(bus_proxy, "glib.label.test", 0, &nameret, &error)) { + g_error("Unable to call to request name"); + return 1; + } + + if (nameret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { + g_error("Unable to get name"); + return 1; + } + + DbusmenuServer * server = dbusmenu_server_new("/org/test"); + DbusmenuMenuitem * root = dbusmenu_menuitem_new(); + dbusmenu_server_set_root(server, root); + + DbusmenuMenuitem * item; + item = add_item(root, "Folder 1"); + add_item(item, "1.1"); + add_item(item, "1.2"); + add_item(item, "1.3"); + + item = add_item(root, "Folder 2"); + add_item(item, "2.1"); + add_item(item, "2.2"); + add_item(item, "2.3"); + + GMainLoop * mainloop = g_main_loop_new(NULL, FALSE); + g_main_loop_run(mainloop); + + g_debug("Quiting"); + + return 0; +} + -- cgit v1.2.3 From 939c18d85dde7bdd5340c853c1f334b809fc65d1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 17 Aug 2010 20:53:13 -0500 Subject: Connected into the item activate signal --- libdbusmenu-gtk/client.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index b5b509f..e7761fb 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -54,6 +54,7 @@ static void new_menuitem (DbusmenuClient * client, DbusmenuMenuitem * mi, gpoint static void new_child (DbusmenuMenuitem * mi, DbusmenuMenuitem * child, guint position, DbusmenuGtkClient * gtkclient); static void delete_child (DbusmenuMenuitem * mi, DbusmenuMenuitem * child, DbusmenuGtkClient * gtkclient); static void move_child (DbusmenuMenuitem * mi, DbusmenuMenuitem * child, guint new, guint old, DbusmenuGtkClient * gtkclient); +static void item_activate (DbusmenuClient * client, DbusmenuMenuitem * mi, guint timestamp, gpointer userdata); static gboolean new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); static gboolean new_item_seperator (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); @@ -91,7 +92,9 @@ dbusmenu_gtkclient_init (DbusmenuGtkClient *self) dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(self), DBUSMENU_CLIENT_TYPES_DEFAULT, new_item_normal); dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(self), DBUSMENU_CLIENT_TYPES_SEPARATOR, new_item_seperator); + /* TODO: I think these can be handled in the class... */ g_signal_connect(G_OBJECT(self), DBUSMENU_CLIENT_SIGNAL_NEW_MENUITEM, G_CALLBACK(new_menuitem), NULL); + g_signal_connect(G_OBJECT(self), DBUSMENU_CLIENT_SIGNAL_ITEM_ACTIVATE, G_CALLBACK(item_activate), NULL); return; } @@ -431,6 +434,15 @@ new_menuitem (DbusmenuClient * client, DbusmenuMenuitem * mi, gpointer userdata) return; } +/* Signaled when we should show a menuitem at request of the application + that it is in. */ +static void +item_activate (DbusmenuClient * client, DbusmenuMenuitem * mi, guint timestamp, gpointer userdata) +{ + + return; +} + #ifdef MASSIVEDEBUGGING static void destroy_gmi (GtkMenuItem * gmi, DbusmenuMenuitem * mi) -- cgit v1.2.3 From 607107ea135b2579c30a9efff08c626538892045 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 18 Aug 2010 09:14:35 -0500 Subject: Activate the mnemonic when requested by the server --- libdbusmenu-gtk/client.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index e7761fb..da81544 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -439,6 +439,22 @@ new_menuitem (DbusmenuClient * client, DbusmenuMenuitem * mi, gpointer userdata) static void item_activate (DbusmenuClient * client, DbusmenuMenuitem * mi, guint timestamp, gpointer userdata) { + gpointer pmenu = g_object_get_data(G_OBJECT(mi), data_menu); + if (pmenu == NULL) { + g_warning("Activated menu item doesn't have a menu? ID: %d", dbusmenu_menuitem_get_id(mi)); + return; + } + + GtkWidget * parent = gtk_widget_get_parent(GTK_WIDGET(pmenu)); + if (parent == NULL) { + g_warning("Activated menu item's menu doesn't have a parent? ID: %d", dbusmenu_menuitem_get_id(mi)); + return; + } + + if (!gtk_widget_mnemonic_activate(parent, FALSE)) { + g_warning("Unable to activate item: %d", dbusmenu_menuitem_get_id(mi)); + return; + } return; } -- cgit v1.2.3 From 8b9843002a14e8954404f4991db2a9a54988c06b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 20 Aug 2010 16:39:12 -0500 Subject: Making it so that items show. --- libdbusmenu-gtk/client.c | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index da81544..4938601 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -434,27 +434,52 @@ new_menuitem (DbusmenuClient * client, DbusmenuMenuitem * mi, gpointer userdata) return; } +/* Goes through the tree of items and ensure's that all the items + above us are also displayed. */ +static void +activate_helper (GtkWidget * item) +{ + GtkWidget * parent = gtk_widget_get_parent(item); + + if (parent != NULL && GTK_IS_MENU_SHELL(parent)) { + GtkWidget * attach = NULL; + + if (GTK_IS_MENU(parent)) { + attach = gtk_menu_get_attach_widget(GTK_MENU(parent)); + } + + if (attach != NULL) { + activate_helper(attach); + } + + gtk_menu_shell_select_item(GTK_MENU_SHELL(parent), item); + } + + return; +} + /* Signaled when we should show a menuitem at request of the application that it is in. */ static void item_activate (DbusmenuClient * client, DbusmenuMenuitem * mi, guint timestamp, gpointer userdata) { - gpointer pmenu = g_object_get_data(G_OBJECT(mi), data_menu); - if (pmenu == NULL) { + gpointer pitem = g_object_get_data(G_OBJECT(mi), data_menuitem); + if (pitem == NULL) { g_warning("Activated menu item doesn't have a menu? ID: %d", dbusmenu_menuitem_get_id(mi)); return; } - GtkWidget * parent = gtk_widget_get_parent(GTK_WIDGET(pmenu)); - if (parent == NULL) { - g_warning("Activated menu item's menu doesn't have a parent? ID: %d", dbusmenu_menuitem_get_id(mi)); + gpointer pmenu = g_object_get_data(G_OBJECT(mi), data_menu); + if (pmenu == NULL) { + g_warning("Activated menu item doesn't have a menu? ID: %d", dbusmenu_menuitem_get_id(mi)); return; } - if (!gtk_widget_mnemonic_activate(parent, FALSE)) { - g_warning("Unable to activate item: %d", dbusmenu_menuitem_get_id(mi)); - return; - } + GtkWidget * item = GTK_WIDGET(pitem); + + activate_helper(item); + + gtk_menu_shell_select_first(GTK_MENU_SHELL(pmenu), FALSE); return; } -- cgit v1.2.3 From 49ff3029a6cc08287e39371f079dc2109a896901 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 20 Aug 2010 16:47:06 -0500 Subject: Restructuring so that we pass the menu --- libdbusmenu-gtk/client.c | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 4938601..44f95fe 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -437,22 +437,25 @@ new_menuitem (DbusmenuClient * client, DbusmenuMenuitem * mi, gpointer userdata) /* Goes through the tree of items and ensure's that all the items above us are also displayed. */ static void -activate_helper (GtkWidget * item) +activate_helper (GtkMenuShell * shell) { - GtkWidget * parent = gtk_widget_get_parent(item); + if (shell == NULL) { + return; + } - if (parent != NULL && GTK_IS_MENU_SHELL(parent)) { - GtkWidget * attach = NULL; - - if (GTK_IS_MENU(parent)) { - attach = gtk_menu_get_attach_widget(GTK_MENU(parent)); - } + if (GTK_IS_MENU(shell)) { + GtkWidget * attach = gtk_menu_get_attach_widget(GTK_MENU(shell)); if (attach != NULL) { - activate_helper(attach); - } + GtkWidget * parent = gtk_widget_get_parent(GTK_WIDGET(attach)); - gtk_menu_shell_select_item(GTK_MENU_SHELL(parent), item); + if (parent != NULL) { + if (GTK_IS_MENU(parent)) { + activate_helper(GTK_MENU_SHELL(parent)); + } + gtk_menu_shell_select_item(GTK_MENU_SHELL(parent), attach); + } + } } return; @@ -463,22 +466,13 @@ activate_helper (GtkWidget * item) static void item_activate (DbusmenuClient * client, DbusmenuMenuitem * mi, guint timestamp, gpointer userdata) { - gpointer pitem = g_object_get_data(G_OBJECT(mi), data_menuitem); - if (pitem == NULL) { - g_warning("Activated menu item doesn't have a menu? ID: %d", dbusmenu_menuitem_get_id(mi)); - return; - } - gpointer pmenu = g_object_get_data(G_OBJECT(mi), data_menu); if (pmenu == NULL) { g_warning("Activated menu item doesn't have a menu? ID: %d", dbusmenu_menuitem_get_id(mi)); return; } - GtkWidget * item = GTK_WIDGET(pitem); - - activate_helper(item); - + activate_helper(GTK_MENU_SHELL(pmenu)); gtk_menu_shell_select_first(GTK_MENU_SHELL(pmenu), FALSE); return; -- cgit v1.2.3 From cbb0f2c5ae4381b2627fcfb9fe7a57d80460ec44 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Mon, 30 Aug 2010 16:13:06 -0400 Subject: Grab your junk. --- libdbusmenu-gtk/client.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 44f95fe..72f5b0b 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -447,18 +447,26 @@ activate_helper (GtkMenuShell * shell) GtkWidget * attach = gtk_menu_get_attach_widget(GTK_MENU(shell)); if (attach != NULL) { - GtkWidget * parent = gtk_widget_get_parent(GTK_WIDGET(attach)); + GtkWidget * parent = gtk_widget_get_parent(attach); + GtkWidget *toplevel = gtk_widget_get_toplevel (attach); if (parent != NULL) { if (GTK_IS_MENU(parent)) { activate_helper(GTK_MENU_SHELL(parent)); } + + if (!GTK_MENU_SHELL (parent)->active) { + gtk_grab_add (parent); + GTK_MENU_SHELL (parent)->have_grab = TRUE; + GTK_MENU_SHELL (parent)->active = TRUE; + } + gtk_menu_shell_select_item(GTK_MENU_SHELL(parent), attach); } } } - return; + return; } /* Signaled when we should show a menuitem at request of the application -- cgit v1.2.3 From 46cf6414f55a027f0eaf3b85701479fb5fe12441 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 24 Sep 2010 14:38:24 -0500 Subject: Making sure to reference the accel group --- libdbusmenu-gtk/client.c | 1 + 1 file changed, 1 insertion(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 6970d59..0f8592c 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -249,6 +249,7 @@ dbusmenu_gtkclient_set_accel_group (DbusmenuGtkClient * client, GtkAccelGroup * } priv->agroup = agroup; + g_object_ref(priv->agroup); return; } -- cgit v1.2.3 From 682fd63278c0306437d43c827d7873403d3575af Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 6 Oct 2010 10:13:09 -0400 Subject: instead of always building gtk2 and gtk3, add a --with-gtk= flag to configure to specify which to build with --- configure.ac | 45 +++++++++++------- libdbusmenu-gtk/Makefile.am | 91 +++++++++++++++++-------------------- libdbusmenu-gtk/dbusmenu-gtk3.pc.in | 2 +- libdbusmenu-gtk/genericmenuitem.c | 40 +++++++++++----- tools/testapp/Makefile.am | 8 +++- 5 files changed, 105 insertions(+), 81 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/configure.ac b/configure.ac index ff8dc78..a525612 100644 --- a/configure.ac +++ b/configure.ac @@ -48,23 +48,33 @@ AC_SUBST(DBUSMENUGLIB_LIBS) ########################### GTK_REQUIRED_VERSION=2.16 -GTK3_REQUIRED_VERSION=2.90 - -PKG_CHECK_MODULES(DBUSMENUGTK, gtk+-2.0 >= $GTK_REQUIRED_VERSION - glib-2.0 >= $GLIB_REQUIRED_VERSION - dbus-glib-1 >= $DBUS_REQUIRED_VERSION - libxml-2.0 >= $XML_REQUIRED_VERSION) - -AC_SUBST(DBUSMENUGTK_CFLAGS) -AC_SUBST(DBUSMENUGTK_LIBS) - -PKG_CHECK_MODULES(DBUSMENUGTK3, gtk+-3.0 >= $GTK3_REQUIRED_VERSION - glib-2.0 >= $GLIB_REQUIRED_VERSION - dbus-glib-1 >= $DBUS_REQUIRED_VERSION - libxml-2.0 >= $XML_REQUIRED_VERSION) - -AC_SUBST(DBUSMENUGTK3_CFLAGS) -AC_SUBST(DBUSMENUGTK3_LIBS) +GTK3_REQUIRED_VERSION=2.91 + +AC_ARG_WITH([gtk], + [AS_HELP_STRING([--with-gtk], + [Which version of gtk to use @<:@default=2@:>@])], + [], + [with_gtk=2]) +AS_IF([test "x$with_gtk" = x3], + [PKG_CHECK_MODULES(DBUSMENUGTK, gtk+-3.0 >= $GTK3_REQUIRED_VERSION + glib-2.0 >= $GLIB_REQUIRED_VERSION + dbus-glib-1 >= $DBUS_REQUIRED_VERSION + libxml-2.0 >= $XML_REQUIRED_VERSION) + AC_SUBST(DBUSMENUGTK_CFLAGS) + AC_SUBST(DBUSMENUGTK_LIBS) + AC_DEFINE(HAVE_GTK3, 1, [whether gtk3 is available]) + ], + [test "x$with_gtk" = x2], + [PKG_CHECK_MODULES(DBUSMENUGTK, gtk+-2.0 >= $GTK_REQUIRED_VERSION + glib-2.0 >= $GLIB_REQUIRED_VERSION + dbus-glib-1 >= $DBUS_REQUIRED_VERSION + libxml-2.0 >= $XML_REQUIRED_VERSION) + AC_SUBST(DBUSMENUGTK_CFLAGS) + AC_SUBST(DBUSMENUGTK_LIBS) + ], + [AC_MSG_FAILURE([Value for --with-gtk was neither 2 nor 3])] +) +AM_CONDITIONAL(USE_GTK3, [test "x$with_gtk" = x3]) ########################### # Dependencies - Testing @@ -155,5 +165,6 @@ libdbusmenu Configuration: Prefix: $prefix Massive Debugging: $with_massivedebugging + GTK+ Version: $with_gtk ]) diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index 4f38b63..cfa4230 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -1,22 +1,27 @@ CLEANFILES = -EXTRA_DIST = \ - dbusmenu-gtk.pc.in \ - dbusmenu-gtk3.pc.in +if USE_GTK3 +VER=3 +GTKGIR=Gtk-3.0 +GTKVALA=gtk+-3.0 +lib_LTLIBRARIES = libdbusmenu-gtk3.la +else +VER= +GTKGIR=Gtk-2.0 +GTKVALA=gtk+-2.0 +lib_LTLIBRARIES = libdbusmenu-gtk.la +endif -lib_LTLIBRARIES = \ - libdbusmenu-gtk.la \ - libdbusmenu-gtk3.la +EXTRA_DIST = \ + dbusmenu-gtk$(VER).pc.in -libdbusmenu_gtkincludedir=$(includedir)/libdbusmenu-0.1/libdbusmenu-gtk/ -libdbusmenu_gtk3includedir=$(includedir)/libdbusmenu3-0.1/libdbusmenu-gtk/ +libdbusmenu_gtkincludedir=$(includedir)/libdbusmenu-0.1/libdbusmenu-gtk$(VER)/ libdbusmenu_gtkinclude_HEADERS = \ client.h \ menu.h \ menuitem.h -libdbusmenu_gtk3include_HEADERS = $(libdbusmenu_gtkinclude_HEADERS) libdbusmenu_gtk_la_SOURCES = \ client.h \ @@ -27,27 +32,31 @@ libdbusmenu_gtk_la_SOURCES = \ menu.c \ menuitem.h \ menuitem.c -libdbusmenu_gtk3_la_SOURCES = $(libdbusmenu_gtk_la_SOURCES) libdbusmenu_gtk_la_LDFLAGS = \ -version-info $(LIBDBUSMENU_CURRENT):$(LIBDBUSMENU_REVISION):$(LIBDBUSMENU_AGE) \ -no-undefined \ -export-symbols-regex "^[^_].*" -libdbusmenu_gtk3_la_LDFLAGS = $(libdbusmenu_gtk_la_LDFLAGS) libdbusmenu_gtk_la_CFLAGS = \ $(DBUSMENUGTK_CFLAGS) -I$(top_srcdir) -Wall -Werror -DG_DISABLE_DEPRECATED -DG_LOG_DOMAIN="\"LIBDBUSMENU-GTK\"" -libdbusmenu_gtk3_la_CFLAGS = \ - $(DBUSMENUGTK3_CFLAGS) -I$(top_srcdir) -Wall -Werror -DG_DISABLE_DEPRECATED -DG_LOG_DOMAIN="\"LIBDBUSMENU-GTK\"" libdbusmenu_gtk_la_LIBADD = \ ../libdbusmenu-glib/libdbusmenu-glib.la \ $(DBUSMENUGTK_LIBS) -libdbusmenu_gtk3_la_LIBADD = \ - ../libdbusmenu-glib/libdbusmenu-glib.la \ - $(DBUSMENUGTK3_LIBS) -pkgconfig_DATA = dbusmenu-gtk.pc dbusmenu-gtk3.pc +# We duplicate these here because Automake won't let us use $(VER) on the left hand side. +# Since we carefully use $(VER) in the right hand side above, we can assign the same values. +# Only one version of the library is every compiled at the same time, so it is safe to reuse +# the right hand sides like this. +libdbusmenu_gtk3includedir = $(libdbusmenu_gtkincludedir) +libdbusmenu_gtk3include_HEADERS = $(libdbusmenu_gtkinclude_HEADERS) +libdbusmenu_gtk3_la_SOURCES = $(libdbusmenu_gtk_la_SOURCES) +libdbusmenu_gtk3_la_LDFLAGS = $(libdbusmenu_gtk_la_LDFLAGS) +libdbusmenu_gtk3_la_CFLAGS = $(libdbusmenu_gtk_la_CFLAGS) +libdbusmenu_gtk3_la_LIBADD = $(libdbusmenu_gtk_la_LIBADD) + +pkgconfig_DATA = dbusmenu-gtk$(VER).pc pkgconfigdir = $(libdir)/pkgconfig ######################### @@ -66,25 +75,22 @@ if HAVE_INTROSPECTION introspection_sources = $(libdbusmenu_gtkinclude_HEADERS) -DbusmenuGtk-0.2.gir: libdbusmenu-gtk.la +DbusmenuGtk$(VER)-0.2.gir: libdbusmenu-gtk$(VER).la DbusmenuGtk_0_2_gir_INCLUDES = \ GObject-2.0 \ - Gtk-2.0 \ + $(GTKGIR) \ Dbusmenu-Glib-0.2 DbusmenuGtk_0_2_gir_CFLAGS = $(DBUSMENUGTK_CFLAGS) -I$(top_srcdir) -DbusmenuGtk_0_2_gir_LIBS = libdbusmenu-gtk.la +DbusmenuGtk_0_2_gir_LIBS = libdbusmenu-gtk$(VER).la DbusmenuGtk_0_2_gir_FILES = $(addprefix $(srcdir)/, $(introspection_sources)) -DbusmenuGtk3-0.2.gir: libdbusmenu-gtk3.la -DbusmenuGtk3_0_2_gir_INCLUDES = \ - GObject-2.0 \ - Gtk-3.0 \ - Dbusmenu-Glib-0.2 -DbusmenuGtk3_0_2_gir_CFLAGS = $(DBUSMENUGTK3_CFLAGS) -I$(top_srcdir) -DbusmenuGtk3_0_2_gir_LIBS = libdbusmenu-gtk3.la -DbusmenuGtk3_0_2_gir_FILES = $(addprefix $(srcdir)/, $(introspection_sources)) +# We duplicate these for the same reason as libdbusmenu_gtk3includedir above +DbusmenuGtk3_0_2_gir_INCLUDES = $(DbusmenuGtk_0_2_gir_INCLUDES) +DbusmenuGtk3_0_2_gir_CFLAGS = $(DbusmenuGtk_0_2_gir_CFLAGS) +DbusmenuGtk3_0_2_gir_LIBS = $(DbusmenuGtk_0_2_gir_LIBS) +DbusmenuGtk3_0_2_gir_FILES = $(DbusmenuGtk_0_2_gir_FILES) -INTROSPECTION_GIRS += DbusmenuGtk-0.2.gir DbusmenuGtk3-0.2.gir +INTROSPECTION_GIRS += DbusmenuGtk$(VER)-0.2.gir girdir = $(datadir)/gir-1.0 gir_DATA = $(INTROSPECTION_GIRS) @@ -103,39 +109,24 @@ endif if HAVE_INTROSPECTION vapidir = $(datadir)/vala/vapi -vapi_DATA = DbusmenuGtk-0.2.vapi DbusmenuGtk3-0.2.vapi +vapi_DATA = DbusmenuGtk$(VER)-0.2.vapi -DbusmenuGtk-0.2.vapi: DbusmenuGtk-0.2.tmp.gir Makefile.am - $(VALA_API_GEN) --library=DbusmenuGtk-0.2 \ +DbusmenuGtk$(VER)-0.2.vapi: DbusmenuGtk$(VER)-0.2.tmp.gir Makefile.am + $(VALA_API_GEN) --library=DbusmenuGtk$(VER)-0.2 \ --pkg gdk-pixbuf-2.0 \ - --pkg gtk+-2.0 \ - --pkg atk \ - --pkg Dbusmenu-Glib-0.2 \ - --vapidir=$(top_builddir)/libdbusmenu-glib \ - $< - -DbusmenuGtk3-0.2.vapi: DbusmenuGtk3-0.2.tmp.gir Makefile.am - $(VALA_API_GEN) --library=DbusmenuGtk3-0.2 \ - --pkg gdk-pixbuf-3.0 \ - --pkg gtk+-3.0 \ + --pkg $(GTKVALA) \ --pkg atk \ --pkg Dbusmenu-Glib-0.2 \ --vapidir=$(top_builddir)/libdbusmenu-glib \ $< -DbusmenuGtk-0.2.tmp.gir: DbusmenuGtk-0.2.gir - $(SED) \ - -e "s|GdkPixbuf.Pixbuf|Gdk.Pixbuf|g" \ - -e "s|Atk.ImplementorIface|Atk.Implementor|g" \ - $< > $@ - -DbusmenuGtk3-0.2.tmp.gir: DbusmenuGtk3-0.2.gir +DbusmenuGtk$(VER)-0.2.tmp.gir: DbusmenuGtk$(VER)-0.2.gir $(SED) \ -e "s|GdkPixbuf.Pixbuf|Gdk.Pixbuf|g" \ -e "s|Atk.ImplementorIface|Atk.Implementor|g" \ $< > $@ -CLEANFILES += $(vapi_DATA) DbusmenuGtk-0.2.tmp.gir DbusmenuGtk3-0.2.tmp.gir +CLEANFILES += $(vapi_DATA) DbusmenuGtk$(VER)-0.2.tmp.gir endif diff --git a/libdbusmenu-gtk/dbusmenu-gtk3.pc.in b/libdbusmenu-gtk/dbusmenu-gtk3.pc.in index e2c4cc3..1a3410e 100644 --- a/libdbusmenu-gtk/dbusmenu-gtk3.pc.in +++ b/libdbusmenu-gtk/dbusmenu-gtk3.pc.in @@ -4,7 +4,7 @@ libdir=@libdir@ bindir=@bindir@ includedir=@includedir@ -Cflags: -I${includedir}/libdbusmenu-3.1 +Cflags: -I${includedir}/libdbusmenu-0.1 Requires: dbus-glib-1 dbusmenu-glib Libs: -L${libdir} -ldbusmenu-gtk3 diff --git a/libdbusmenu-gtk/genericmenuitem.c b/libdbusmenu-gtk/genericmenuitem.c index 8f40d93..b357d82 100644 --- a/libdbusmenu-gtk/genericmenuitem.c +++ b/libdbusmenu-gtk/genericmenuitem.c @@ -51,7 +51,6 @@ static void genericmenuitem_class_init (GenericmenuitemClass *klass); static void genericmenuitem_init (Genericmenuitem *self); static void genericmenuitem_dispose (GObject *object); static void genericmenuitem_finalize (GObject *object); -static void draw_indicator (GtkCheckMenuItem *check_menu_item, GdkRectangle *area); static void set_label (GtkMenuItem * menu_item, const gchar * label); static const gchar * get_label (GtkMenuItem * menu_item); static void activate (GtkMenuItem * menu_item); @@ -59,8 +58,13 @@ static void activate (GtkMenuItem * menu_item); /* GObject stuff */ G_DEFINE_TYPE (Genericmenuitem, genericmenuitem, GTK_TYPE_CHECK_MENU_ITEM); -/* Globals */ +#if HAVE_GTK3 +static void draw_indicator (GtkCheckMenuItem *check_menu_item, cairo_t *cr); +static void (*parent_draw_indicator) (GtkCheckMenuItem *check_menu_item, cairo_t *cr) = NULL; +#else +static void draw_indicator (GtkCheckMenuItem *check_menu_item, GdkRectangle *area); static void (*parent_draw_indicator) (GtkCheckMenuItem *check_menu_item, GdkRectangle *area) = NULL; +#endif /* Initializing all of the classes. Most notably we're disabling the drawing of the check early. */ @@ -121,6 +125,17 @@ genericmenuitem_finalize (GObject *object) /* Checks to see if we should be drawing a little box at all. If we should be, let's do that, otherwise we're going suppress the box drawing. */ +#if HAVE_GTK3 +static void +draw_indicator (GtkCheckMenuItem *check_menu_item, cairo_t *cr) +{ + Genericmenuitem * self = GENERICMENUITEM(check_menu_item); + if (self->priv->check_type != GENERICMENUITEM_CHECK_TYPE_NONE) { + parent_draw_indicator(check_menu_item, cr); + } + return; +} +#else static void draw_indicator (GtkCheckMenuItem *check_menu_item, GdkRectangle *area) { @@ -130,6 +145,7 @@ draw_indicator (GtkCheckMenuItem *check_menu_item, GdkRectangle *area) } return; } +#endif /* A small helper to look through the widgets in the box and find the one that is the label. */ @@ -320,32 +336,32 @@ genericmenuitem_set_state (Genericmenuitem * item, GenericmenuitemState state) GtkCheckMenuItem * check = GTK_CHECK_MENU_ITEM(item); - gboolean old_active = check->active; - gboolean old_inconsist = check->inconsistent; + gboolean old_active = gtk_check_menu_item_get_active (check); + gboolean old_inconsist = gtk_check_menu_item_get_inconsistent (check); switch (item->priv->state) { case GENERICMENUITEM_STATE_UNCHECKED: - check->active = FALSE; - check->inconsistent = FALSE; + gtk_check_menu_item_set_active (check, FALSE); + gtk_check_menu_item_set_inconsistent (check, FALSE); break; case GENERICMENUITEM_STATE_CHECKED: - check->active = TRUE; - check->inconsistent = FALSE; + gtk_check_menu_item_set_active (check, TRUE); + gtk_check_menu_item_set_inconsistent (check, FALSE); break; case GENERICMENUITEM_STATE_INDETERMINATE: - check->active = TRUE; - check->inconsistent = TRUE; + gtk_check_menu_item_set_active (check, TRUE); + gtk_check_menu_item_set_inconsistent (check, TRUE); break; default: g_warning("Generic Menuitem invalid check state: %d", state); return; } - if (old_active != check->active) { + if (old_active != gtk_check_menu_item_get_active (check)) { g_object_notify(G_OBJECT(item), "active"); } - if (old_inconsist != check->inconsistent) { + if (old_inconsist != gtk_check_menu_item_get_inconsistent (check)) { g_object_notify(G_OBJECT(item), "inconsistent"); } diff --git a/tools/testapp/Makefile.am b/tools/testapp/Makefile.am index a8b42dd..39de532 100644 --- a/tools/testapp/Makefile.am +++ b/tools/testapp/Makefile.am @@ -1,4 +1,10 @@ +if USE_GTK3 +VER=3 +else +VER= +endif + libexec_PROGRAMS = dbusmenu-testapp dbusmenu_testapp_SOURCES = \ @@ -12,6 +18,6 @@ dbusmenu_testapp_CFLAGS = \ dbusmenu_testapp_LDADD = \ $(builddir)/../../libdbusmenu-glib/libdbusmenu-glib.la \ - $(builddir)/../../libdbusmenu-gtk/libdbusmenu-gtk.la \ + $(builddir)/../../libdbusmenu-gtk/libdbusmenu-gtk$(VER).la \ $(DBUSMENUGTK_LIBS) \ $(DBUSMENUTESTS_LIBS) -- cgit v1.2.3 From 650d606580a1cf5842470ecf9dd97b166eed55d4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 Oct 2010 16:07:22 -0500 Subject: Going to 6 privates like others --- libdbusmenu-gtk/client.h | 6 +++++- libdbusmenu-gtk/menu.h | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.h b/libdbusmenu-gtk/client.h index a7c96ee..2793faf 100644 --- a/libdbusmenu-gtk/client.h +++ b/libdbusmenu-gtk/client.h @@ -50,6 +50,8 @@ G_BEGIN_DECLS @reserved2: Reserved for future use. @reserved3: Reserved for future use. @reserved4: Reserved for future use. + @reserved5: Reserved for future use. + @reserved6: Reserved for future use. */ typedef struct _DbusmenuGtkClientClass DbusmenuGtkClientClass; struct _DbusmenuGtkClientClass { @@ -58,11 +60,13 @@ struct _DbusmenuGtkClientClass { /* Signals */ void (*root_changed) (DbusmenuMenuitem * newroot); - /* Reserved */ + /*< Private >*/ void (*reserved1) (void); void (*reserved2) (void); void (*reserved3) (void); void (*reserved4) (void); + void (*reserved5) (void); + void (*reserved6) (void); }; /** diff --git a/libdbusmenu-gtk/menu.h b/libdbusmenu-gtk/menu.h index 5147d30..0601d0a 100644 --- a/libdbusmenu-gtk/menu.h +++ b/libdbusmenu-gtk/menu.h @@ -49,16 +49,20 @@ G_BEGIN_DECLS @reserved2: Reserved for future use. @reserved3: Reserved for future use. @reserved4: Reserved for future use. + @reserved5: Reserved for future use. + @reserved6: Reserved for future use. */ typedef struct _DbusmenuGtkMenuClass DbusmenuGtkMenuClass; struct _DbusmenuGtkMenuClass { GtkMenuClass parent_class; - /* Reserved */ + /*< Private >*/ void (*reserved1) (void); void (*reserved2) (void); void (*reserved3) (void); void (*reserved4) (void); + void (*reserved5) (void); + void (*reserved6) (void); }; /** -- cgit v1.2.3 From 176f561e6959611b96e4c1525958fce757a6fb46 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 Oct 2010 16:16:55 -0500 Subject: Private pointers in instance structs --- libdbusmenu-gtk/client.c | 1 - libdbusmenu-gtk/client.h | 5 +++++ libdbusmenu-gtk/menu.c | 1 - libdbusmenu-gtk/menu.h | 5 +++++ 4 files changed, 10 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 6970d59..7de93e1 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -37,7 +37,6 @@ License version 3 and version 2.1 along with this program. If not, see #include "genericmenuitem.h" /* Private */ -typedef struct _DbusmenuGtkClientPrivate DbusmenuGtkClientPrivate; struct _DbusmenuGtkClientPrivate { GtkAccelGroup * agroup; }; diff --git a/libdbusmenu-gtk/client.h b/libdbusmenu-gtk/client.h index 2793faf..c986a5d 100644 --- a/libdbusmenu-gtk/client.h +++ b/libdbusmenu-gtk/client.h @@ -43,6 +43,8 @@ G_BEGIN_DECLS #define DBUSMENU_GTKCLIENT_SIGNAL_ROOT_CHANGED DBUSMENU_CLIENT_SIGNAL_ROOT_CHANGED +typedef struct _DbusmenuGtkClientPrivate DbusmenuGtkClientPrivate; + /** DbusmenuGtkClientClass: @parent_class: #GtkMenuClass @@ -76,6 +78,9 @@ struct _DbusmenuGtkClientClass { typedef struct _DbusmenuGtkClient DbusmenuGtkClient; struct _DbusmenuGtkClient { DbusmenuClient parent; + + /*< Private >*/ + DbusmenuGtkClientPrivate * priv; }; GType dbusmenu_gtkclient_get_type (void); diff --git a/libdbusmenu-gtk/menu.c b/libdbusmenu-gtk/menu.c index 4fa546b..14dcb89 100644 --- a/libdbusmenu-gtk/menu.c +++ b/libdbusmenu-gtk/menu.c @@ -44,7 +44,6 @@ enum { }; /* Private */ -typedef struct _DbusmenuGtkMenuPrivate DbusmenuGtkMenuPrivate; struct _DbusmenuGtkMenuPrivate { DbusmenuGtkClient * client; diff --git a/libdbusmenu-gtk/menu.h b/libdbusmenu-gtk/menu.h index 0601d0a..896e466 100644 --- a/libdbusmenu-gtk/menu.h +++ b/libdbusmenu-gtk/menu.h @@ -42,6 +42,8 @@ G_BEGIN_DECLS #define DBUSMENU_IS_GTKMENU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DBUSMENU_GTKMENU_TYPE)) #define DBUSMENU_GTKMENU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DBUSMENU_GTKMENU_TYPE, DbusmenuGtkMenuClass)) +typedef struct _DbusmenuGtkMenuPrivate DbusmenuGtkMenuPrivate; + /** DbusmenuGtkMenuClass: @parent_class: #GtkMenuClass @@ -72,6 +74,9 @@ struct _DbusmenuGtkMenuClass { typedef struct _DbusmenuGtkMenu DbusmenuGtkMenu; struct _DbusmenuGtkMenu { GtkMenu parent; + + /*< Private >*/ + DbusmenuGtkMenuPrivate * priv; }; GType dbusmenu_gtkmenu_get_type (void); -- cgit v1.2.3 From f8d472db4415096f7a5e99e14aa3b1af290d2098 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 12 Oct 2010 16:29:26 -0500 Subject: Switching to using the pointer in the instance --- libdbusmenu-gtk/client.c | 5 +++-- libdbusmenu-gtk/menu.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 7de93e1..487971f 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -41,8 +41,7 @@ struct _DbusmenuGtkClientPrivate { GtkAccelGroup * agroup; }; -#define DBUSMENU_GTKCLIENT_GET_PRIVATE(o) \ -(G_TYPE_INSTANCE_GET_PRIVATE ((o), DBUSMENU_GTKCLIENT_TYPE, DbusmenuGtkClientPrivate)) +#define DBUSMENU_GTKCLIENT_GET_PRIVATE(o) (DBUSMENU_GTKCLIENT(o)->priv) /* Prototypes */ static void dbusmenu_gtkclient_class_init (DbusmenuGtkClientClass *klass); @@ -84,6 +83,8 @@ dbusmenu_gtkclient_class_init (DbusmenuGtkClientClass *klass) static void dbusmenu_gtkclient_init (DbusmenuGtkClient *self) { + self->priv = G_TYPE_INSTANCE_GET_PRIVATE ((self), DBUSMENU_GTKCLIENT_TYPE, DbusmenuGtkClientPrivate); + DbusmenuGtkClientPrivate * priv = DBUSMENU_GTKCLIENT_GET_PRIVATE(self); priv->agroup = NULL; diff --git a/libdbusmenu-gtk/menu.c b/libdbusmenu-gtk/menu.c index 14dcb89..ace8e8a 100644 --- a/libdbusmenu-gtk/menu.c +++ b/libdbusmenu-gtk/menu.c @@ -51,8 +51,7 @@ struct _DbusmenuGtkMenuPrivate { gchar * dbus_name; }; -#define DBUSMENU_GTKMENU_GET_PRIVATE(o) \ -(G_TYPE_INSTANCE_GET_PRIVATE ((o), DBUSMENU_GTKMENU_TYPE, DbusmenuGtkMenuPrivate)) +#define DBUSMENU_GTKMENU_GET_PRIVATE(o) (DBUSMENU_GTKMENU(o)->priv) /* Prototypes */ static void dbusmenu_gtkmenu_class_init (DbusmenuGtkMenuClass *klass); @@ -109,6 +108,8 @@ menu_focus_cb(DbusmenuGtkMenu * menu, gpointer userdata) static void dbusmenu_gtkmenu_init (DbusmenuGtkMenu *self) { + self->priv = G_TYPE_INSTANCE_GET_PRIVATE ((self), DBUSMENU_GTKMENU_TYPE, DbusmenuGtkMenuPrivate); + DbusmenuGtkMenuPrivate * priv = DBUSMENU_GTKMENU_GET_PRIVATE(self); priv->client = NULL; -- cgit v1.2.3 From 7ba22007311d5ed891a8dbb29e76873c74ea4ea6 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 13 Oct 2010 08:42:42 -0400 Subject: ship both .pc files in EXTRA_DIST --- libdbusmenu-gtk/Makefile.am | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index cfa4230..b30cac9 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -14,7 +14,8 @@ lib_LTLIBRARIES = libdbusmenu-gtk.la endif EXTRA_DIST = \ - dbusmenu-gtk$(VER).pc.in + dbusmenu-gtk.pc.in \ + dbusmenu-gtk3.pc.in libdbusmenu_gtkincludedir=$(includedir)/libdbusmenu-0.1/libdbusmenu-gtk$(VER)/ -- cgit v1.2.3 From 726e8b11f2938a229b5ff75979031aafdbacf60d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 16 Nov 2010 16:27:53 -0600 Subject: Redoing the handling of shortcuts to use GVariants rather than GValues --- libdbusmenu-gtk/menuitem.c | 128 +++++++++++++++------------------------------ 1 file changed, 41 insertions(+), 87 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 5846aa7..9c1cfd2 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -29,7 +29,6 @@ License version 3 and version 2.1 along with this program. If not, see #include "menuitem.h" #include #include -#include /** dbusmenu_menuitem_property_set_image: @@ -201,25 +200,16 @@ dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, guint key, const gchar * keyname = gdk_keyval_name(key); g_array_append_val(array, keyname); - GType type = dbus_g_type_get_collection("GPtrArray", G_TYPE_STRV); - GPtrArray * wrapper = (GPtrArray *)dbus_g_type_specialized_construct(type); + GVariant * inside = g_variant_new("as", array->data); + GVariantBuilder builder; + g_variant_builder_init(&builder, G_VARIANT_TYPE("av")); + g_variant_builder_add_value(&builder, inside); + GVariant * outsidevariant = g_variant_builder_end(&builder); - GValue value = {0,}; - g_value_init(&value, type); - g_value_take_boxed(&value, wrapper); + dbusmenu_menuitem_property_set_variant(menuitem, DBUSMENU_MENUITEM_PROP_SHORTCUT, outsidevariant); - DBusGTypeSpecializedAppendContext ctx; - dbus_g_type_specialized_init_append(&value, &ctx); - - GValue strval = {0,}; - g_value_init(&strval, G_TYPE_STRV); - g_value_take_boxed(&strval, array->data); - g_array_free(array, FALSE); - - dbus_g_type_specialized_collection_append(&ctx, &strval); - dbus_g_type_specialized_collection_end_append(&ctx); - - dbusmenu_menuitem_property_set_value(menuitem, DBUSMENU_MENUITEM_PROP_SHORTCUT, &value); + g_variant_unref(outsidevariant); + g_variant_unref(inside); return TRUE; } @@ -279,68 +269,6 @@ dbusmenu_menuitem_property_set_shortcut_menuitem (DbusmenuMenuitem * menuitem, c return dbusmenu_menuitem_property_set_shortcut(menuitem, key->accel_key, key->accel_mods); } -/* A set of typed data for the interator */ -typedef struct _iter_data_t iter_data_t; -struct _iter_data_t { - guint * key; - GdkModifierType * modifier; -}; - -/* Goes through the wrapper items. In reality we only support one - so it checks to see if a key is set first. But, we could possibly, - support more in the future. */ -static void -_wrapper_iterator (const GValue * value, gpointer user_data) -{ - iter_data_t * iter_data = (iter_data_t *)user_data; - - if (*iter_data->key != 0) { - g_warning("Shortcut is more than one entry. Which we don't currently support. Taking the first."); - return; - } - - if (!G_VALUE_HOLDS(value, G_TYPE_STRV)) { - g_warning("Unexpected shortcut structure. Value array is: %s", G_VALUE_TYPE_NAME(value)); - return; - } - - gchar ** stringarray = (gchar **)g_value_get_boxed(value); - if (stringarray == NULL) { - return; - } - - const gchar * last_string = NULL; - int i; - - for (i = 0; stringarray[i] != NULL; i++) { - last_string = stringarray[i]; - - if (g_strcmp0(last_string, DBUSMENU_MENUITEM_SHORTCUT_CONTROL) == 0) { - *iter_data->modifier |= GDK_CONTROL_MASK; - continue; - } - if (g_strcmp0(last_string, DBUSMENU_MENUITEM_SHORTCUT_ALT) == 0) { - *iter_data->modifier |= GDK_MOD1_MASK; - continue; - } - if (g_strcmp0(last_string, DBUSMENU_MENUITEM_SHORTCUT_SHIFT) == 0) { - *iter_data->modifier |= GDK_SHIFT_MASK; - continue; - } - if (g_strcmp0(last_string, DBUSMENU_MENUITEM_SHORTCUT_SUPER) == 0) { - *iter_data->modifier |= GDK_SUPER_MASK; - continue; - } - } - - if (last_string != NULL) { - GdkModifierType tempmod; - gtk_accelerator_parse(last_string, iter_data->key, &tempmod); - } - - return; -} - /** dbusmenu_menuitem_property_get_shortcut: @menuitem: The #DbusmenuMenuitem to get the shortcut off @@ -358,20 +286,46 @@ dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * ke g_return_if_fail(DBUSMENU_IS_MENUITEM(menuitem)); - const GValue * wrapper = dbusmenu_menuitem_property_get_value(menuitem, DBUSMENU_MENUITEM_PROP_SHORTCUT); + GVariant * wrapper = dbusmenu_menuitem_property_get_variant(menuitem, DBUSMENU_MENUITEM_PROP_SHORTCUT); if (wrapper == NULL) { return; } - if (!dbus_g_type_is_collection(G_VALUE_TYPE(wrapper))) { - g_warning("Unexpected shortcut structure. Wrapper is: %s", G_VALUE_TYPE_NAME(wrapper)); + + if (g_variant_n_children(wrapper) != 1) { + g_warning("Unable to parse shortcut, too many keys"); + g_variant_unref(wrapper); return; } - iter_data_t iter_data; - iter_data.key = key; - iter_data.modifier = modifier; + GVariantIter outsideiter; + GVariant * inside; + g_variant_iter_init(&outsideiter, wrapper); + + while(g_variant_iter_next(&outsideiter, "v", &inside)) { + GVariantIter insideiter; + g_variant_iter_init(&insideiter, inside); + gchar * string; + + while(g_variant_iter_next(&insideiter, "s", &string)) { + if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_CONTROL) == 0) { + *modifier |= GDK_CONTROL_MASK; + } else if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_ALT) == 0) { + *modifier |= GDK_MOD1_MASK; + } else if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_SHIFT) == 0) { + *modifier |= GDK_SHIFT_MASK; + } else if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_SUPER) == 0) { + *modifier |= GDK_SUPER_MASK; + } else { + GdkModifierType tempmod; + gtk_accelerator_parse(string, key, &tempmod); + } + + g_free(string); + } - dbus_g_type_collection_value_iterate(wrapper, _wrapper_iterator, &iter_data); + g_variant_unref(inside); + } + g_variant_unref(wrapper); return; } -- cgit v1.2.3 From 153a249f1029171cfcf40cf34ccc5157ba791c20 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 17 Nov 2010 20:37:01 -0600 Subject: Switching everything to start using variants... even ahead of GLib --- libdbusmenu-gtk/client.c | 71 ++++++++++++++++----------------------- libdbusmenu-gtk/genericmenuitem.c | 2 ++ 2 files changed, 31 insertions(+), 42 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 487971f..9dd18df 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -57,9 +57,9 @@ static void item_activate (DbusmenuClient * client, DbusmenuMenuitem * mi, guint static gboolean new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); static gboolean new_item_seperator (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); -static void process_visible (DbusmenuMenuitem * mi, GtkMenuItem * gmi, const GValue * value); -static void process_sensitive (DbusmenuMenuitem * mi, GtkMenuItem * gmi, const GValue * value); -static void image_property_handle (DbusmenuMenuitem * item, const gchar * property, const GValue * invalue, gpointer userdata); +static void process_visible (DbusmenuMenuitem * mi, GtkMenuItem * gmi, GVariant * value); +static void process_sensitive (DbusmenuMenuitem * mi, GtkMenuItem * gmi, GVariant * value); +static void image_property_handle (DbusmenuMenuitem * item, const gchar * property, GVariant * invalue, gpointer userdata); /* GObject Stuff */ G_DEFINE_TYPE (DbusmenuGtkClient, dbusmenu_gtkclient, DBUSMENU_TYPE_CLIENT); @@ -283,10 +283,8 @@ static gboolean menu_pressed_cb (GtkMenuItem * gmi, DbusmenuMenuitem * mi) { if (gtk_menu_item_get_submenu(gmi) == NULL) { - GValue value = {0}; - g_value_init(&value, G_TYPE_INT); - g_value_set_int(&value, 0); - dbusmenu_menuitem_handle_event(mi, "clicked", &value, gtk_get_current_event_time()); + GVariant * variant = g_variant_new("i", 0); + dbusmenu_menuitem_handle_event(mi, "clicked", variant, gtk_get_current_event_time()); } else { /* TODO: We need to stop the display of the submenu until this callback returns. */ @@ -297,7 +295,7 @@ menu_pressed_cb (GtkMenuItem * gmi, DbusmenuMenuitem * mi) /* Process the visible property */ static void -process_visible (DbusmenuMenuitem * mi, GtkMenuItem * gmi, const GValue * value) +process_visible (DbusmenuMenuitem * mi, GtkMenuItem * gmi, GVariant * value) { gboolean val = TRUE; if (value != NULL) { @@ -314,7 +312,7 @@ process_visible (DbusmenuMenuitem * mi, GtkMenuItem * gmi, const GValue * value) /* Process the sensitive property */ static void -process_sensitive (DbusmenuMenuitem * mi, GtkMenuItem * gmi, const GValue * value) +process_sensitive (DbusmenuMenuitem * mi, GtkMenuItem * gmi, GVariant * value) { gboolean val = TRUE; if (value != NULL) { @@ -326,26 +324,21 @@ process_sensitive (DbusmenuMenuitem * mi, GtkMenuItem * gmi, const GValue * valu /* Process the sensitive property */ static void -process_toggle_type (DbusmenuMenuitem * mi, GtkMenuItem * gmi, const GValue * value) +process_toggle_type (DbusmenuMenuitem * mi, GtkMenuItem * gmi, GVariant * variant) { if (!IS_GENERICMENUITEM(gmi)) return; - if (value == NULL) return; + if (variant == NULL) return; GenericmenuitemCheckType type = GENERICMENUITEM_CHECK_TYPE_NONE; - GValue strvalue = {0}; - g_value_init(&strvalue, G_TYPE_STRING); - - if (value != NULL && g_value_transform(value, &strvalue)) { - const gchar * strval = g_value_get_string(&strvalue); + if (variant != NULL) { + const gchar * strval = g_variant_get_string(variant, NULL); if (!g_strcmp0(strval, DBUSMENU_MENUITEM_TOGGLE_CHECK)) { type = GENERICMENUITEM_CHECK_TYPE_CHECKBOX; } else if (!g_strcmp0(strval, DBUSMENU_MENUITEM_TOGGLE_RADIO)) { type = GENERICMENUITEM_CHECK_TYPE_RADIO; } - - g_value_unset(&strvalue); } genericmenuitem_set_check_type(GENERICMENUITEM(gmi), type); @@ -355,17 +348,14 @@ process_toggle_type (DbusmenuMenuitem * mi, GtkMenuItem * gmi, const GValue * va /* Process the sensitive property */ static void -process_toggle_state (DbusmenuMenuitem * mi, GtkMenuItem * gmi, const GValue * value) +process_toggle_state (DbusmenuMenuitem * mi, GtkMenuItem * gmi, GVariant * variant) { if (!IS_GENERICMENUITEM(gmi)) return; GenericmenuitemState state = GENERICMENUITEM_STATE_UNCHECKED; - GValue intvalue = {0}; - g_value_init(&intvalue, G_TYPE_INT); - - if (value != NULL && g_value_transform(value, &intvalue)) { - int val = g_value_get_int(&intvalue); + if (variant != NULL) { + int val = g_variant_get_int32(variant); if (val == DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED) { state = GENERICMENUITEM_STATE_CHECKED; @@ -381,18 +371,18 @@ process_toggle_state (DbusmenuMenuitem * mi, GtkMenuItem * gmi, const GValue * v /* Whenever we have a property change on a DbusmenuMenuitem we need to be responsive to that. */ static void -menu_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * value, GtkMenuItem * gmi) +menu_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant * variant, GtkMenuItem * gmi) { if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_LABEL)) { - gtk_menu_item_set_label(gmi, g_value_get_string(value)); + gtk_menu_item_set_label(gmi, g_variant_get_string(variant, NULL)); } else if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_VISIBLE)) { - process_visible(mi, gmi, value); + process_visible(mi, gmi, variant); } else if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_ENABLED)) { - process_sensitive(mi, gmi, value); + process_sensitive(mi, gmi, variant); } else if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE)) { - process_toggle_type(mi, gmi, value); + process_toggle_type(mi, gmi, variant); } else if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE)) { - process_toggle_state(mi, gmi, value); + process_toggle_state(mi, gmi, variant); } return; @@ -401,7 +391,7 @@ menu_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * value, GtkMen /* Special handler for the shortcut changing as we need to have the client for that one to get the accel group. */ static void -menu_shortcut_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * value, DbusmenuGtkClient * client) +menu_shortcut_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant * value, DbusmenuGtkClient * client) { if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_SHORTCUT)) { refresh_shortcut(client, mi); @@ -537,10 +527,10 @@ dbusmenu_gtkclient_newitem_base (DbusmenuGtkClient * client, DbusmenuMenuitem * g_object_weak_ref(G_OBJECT(item), destoryed_dbusmenuitem_cb, gmi); /* Check our set of props to see if any are set already */ - process_visible(item, gmi, dbusmenu_menuitem_property_get_value(item, DBUSMENU_MENUITEM_PROP_VISIBLE)); - process_sensitive(item, gmi, dbusmenu_menuitem_property_get_value(item, DBUSMENU_MENUITEM_PROP_ENABLED)); - process_toggle_type(item, gmi, dbusmenu_menuitem_property_get_value(item, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE)); - process_toggle_state(item, gmi, dbusmenu_menuitem_property_get_value(item, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE)); + process_visible(item, gmi, dbusmenu_menuitem_property_get_variant(item, DBUSMENU_MENUITEM_PROP_VISIBLE)); + process_sensitive(item, gmi, dbusmenu_menuitem_property_get_variant(item, DBUSMENU_MENUITEM_PROP_ENABLED)); + process_toggle_type(item, gmi, dbusmenu_menuitem_property_get_variant(item, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE)); + process_toggle_state(item, gmi, dbusmenu_menuitem_property_get_variant(item, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE)); refresh_shortcut(client, item); /* Oh, we're a child, let's deal with that */ @@ -705,11 +695,11 @@ new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusmenu image_property_handle(newitem, DBUSMENU_MENUITEM_PROP_ICON_NAME, - dbusmenu_menuitem_property_get_value(newitem, DBUSMENU_MENUITEM_PROP_ICON_NAME), + dbusmenu_menuitem_property_get_variant(newitem, DBUSMENU_MENUITEM_PROP_ICON_NAME), client); image_property_handle(newitem, DBUSMENU_MENUITEM_PROP_ICON_DATA, - dbusmenu_menuitem_property_get_value(newitem, DBUSMENU_MENUITEM_PROP_ICON_DATA), + dbusmenu_menuitem_property_get_variant(newitem, DBUSMENU_MENUITEM_PROP_ICON_DATA), client); g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, @@ -743,7 +733,7 @@ new_item_seperator (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusm /* This handler looks at property changes for items that are image menu items. */ static void -image_property_handle (DbusmenuMenuitem * item, const gchar * property, const GValue * invalue, gpointer userdata) +image_property_handle (DbusmenuMenuitem * item, const gchar * property, GVariant * variant, gpointer userdata) { /* We're only looking at these two properties here */ if (g_strcmp0(property, DBUSMENU_MENUITEM_PROP_ICON_NAME) != 0 && @@ -752,11 +742,8 @@ image_property_handle (DbusmenuMenuitem * item, const gchar * property, const GV } const gchar * value = NULL; + value = g_variant_get_string(variant, NULL); - if (invalue != NULL && G_VALUE_TYPE(invalue) == G_TYPE_STRING) { - value = g_value_get_string(invalue); - } - if (value == NULL || value[0] == '\0') { /* This means that we're unsetting a value. */ /* Try to use the other one */ diff --git a/libdbusmenu-gtk/genericmenuitem.c b/libdbusmenu-gtk/genericmenuitem.c index 30b072f..cb76964 100644 --- a/libdbusmenu-gtk/genericmenuitem.c +++ b/libdbusmenu-gtk/genericmenuitem.c @@ -298,6 +298,8 @@ genericmenuitem_set_check_type (Genericmenuitem * item, GenericmenuitemCheckType return; } + g_value_unset(&value); + gtk_widget_queue_draw(GTK_WIDGET(item)); return; -- cgit v1.2.3 From a7a7326946d7dd13c0ef5027d460662dfd04b1e7 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Tue, 23 Nov 2010 15:53:10 -0500 Subject: Set more scanner flags to get the namespace right --- libdbusmenu-glib/Makefile.am | 12 +++++++++--- libdbusmenu-gtk/Makefile.am | 14 ++++++++++---- 2 files changed, 19 insertions(+), 7 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-glib/Makefile.am b/libdbusmenu-glib/Makefile.am index 0a6513f..3d031dd 100644 --- a/libdbusmenu-glib/Makefile.am +++ b/libdbusmenu-glib/Makefile.am @@ -114,9 +114,13 @@ menuitem-marshal.c: $(srcdir)/menuitem-marshal.list -include $(INTROSPECTION_MAKEFILE) INTROSPECTION_GIRS = -INTROSPECTION_SCANNER_ARGS = \ - --add-include-path=$(srcdir) \ - $(addprefix --c-include=libdbusmenu-glib/, $(introspection_sources)) +INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) \ + --add-include-path=$(srcdir) \ + $(addprefix --c-include=libdbusmenu-glib/, $(introspection_sources)) \ + --symbol-prefix=dbusmenu \ + --identifier-prefix=Dbusmenu \ + --pkg-export=dbusmenu-glib + INTROSPECTION_COMPILER_ARGS = --includedir=$(builddir) if HAVE_INTROSPECTION @@ -131,6 +135,8 @@ Dbusmenu_Glib_0_2_gir_LIBS = libdbusmenu-glib.la Dbusmenu_Glib_0_2_gir_FILES = $(addprefix $(srcdir)/, $(introspection_sources)) Dbusmenu_Glib_0_2_gir_NAMESPACE = Dbusmenu Dbusmenu_Glib_0_2_gir_VERSION = Glib-0.2 +Dbusmenu_Glib_0_2_gir_PACKAGES = dbusmenu-glib +Dbusmenu_Glib_0_2_gir_SCANNER_FLAGS = $(INTROSPECTION_SCANNER_ARGS) INTROSPECTION_GIRS += Dbusmenu-Glib-0.2.gir diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index b30cac9..bb3890e 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -66,10 +66,12 @@ pkgconfigdir = $(libdir)/pkgconfig -include $(INTROSPECTION_MAKEFILE) INTROSPECTION_GIRS = -INTROSPECTION_SCANNER_ARGS = \ - --add-include-path=$(srcdir) \ +INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) \ --add-include-path=$(top_builddir)/libdbusmenu-glib \ - $(addprefix --c-include=libdbusmenu-gtk/, $(introspection_sources)) + $(addprefix --c-include=libdbusmenu-gtk/, $(introspection_sources)) \ + --symbol-prefix=dbusmenu \ + --identifier-prefix=DbusmenuGtk \ + --pkg-export=dbusmenu-gtk$(VER) INTROSPECTION_COMPILER_ARGS = --includedir=$(builddir) --includedir=$(top_builddir)/libdbusmenu-glib if HAVE_INTROSPECTION @@ -80,16 +82,20 @@ DbusmenuGtk$(VER)-0.2.gir: libdbusmenu-gtk$(VER).la DbusmenuGtk_0_2_gir_INCLUDES = \ GObject-2.0 \ $(GTKGIR) \ - Dbusmenu-Glib-0.2 + Dbusmenu-Glib-0.2 DbusmenuGtk_0_2_gir_CFLAGS = $(DBUSMENUGTK_CFLAGS) -I$(top_srcdir) DbusmenuGtk_0_2_gir_LIBS = libdbusmenu-gtk$(VER).la DbusmenuGtk_0_2_gir_FILES = $(addprefix $(srcdir)/, $(introspection_sources)) +DbusmenuGtk_0_2_gir_NAMESPACE = DbusmenuGtk$(VER) +DbusmenuGtk_0_2_gir_SCANNERFLAGS = $(INTROSPECTION_SCANNER_ARGS) # We duplicate these for the same reason as libdbusmenu_gtk3includedir above DbusmenuGtk3_0_2_gir_INCLUDES = $(DbusmenuGtk_0_2_gir_INCLUDES) DbusmenuGtk3_0_2_gir_CFLAGS = $(DbusmenuGtk_0_2_gir_CFLAGS) DbusmenuGtk3_0_2_gir_LIBS = $(DbusmenuGtk_0_2_gir_LIBS) DbusmenuGtk3_0_2_gir_FILES = $(DbusmenuGtk_0_2_gir_FILES) +DbusmenuGtk3_0_2_gir_NAMESPACE = $(DbusmenuGtk_0_2_gir_NAMESPACE) +DbusmenuGtk3_0_2_gir_SCANNERFLAGS = $(DbusmenuGtk_0_2_gir_SCANNERFLAGS) INTROSPECTION_GIRS += DbusmenuGtk$(VER)-0.2.gir -- cgit v1.2.3 From d9d3f22c4240b7b1479299167e8ce184fd0c5f3a Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Tue, 23 Nov 2010 16:06:30 -0500 Subject: Cleaned up the scanner flags some --- libdbusmenu-glib/Makefile.am | 3 +-- libdbusmenu-gtk/Makefile.am | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-glib/Makefile.am b/libdbusmenu-glib/Makefile.am index 3d031dd..adf4607 100644 --- a/libdbusmenu-glib/Makefile.am +++ b/libdbusmenu-glib/Makefile.am @@ -118,8 +118,7 @@ INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) \ --add-include-path=$(srcdir) \ $(addprefix --c-include=libdbusmenu-glib/, $(introspection_sources)) \ --symbol-prefix=dbusmenu \ - --identifier-prefix=Dbusmenu \ - --pkg-export=dbusmenu-glib + --identifier-prefix=Dbusmenu INTROSPECTION_COMPILER_ARGS = --includedir=$(builddir) diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index bb3890e..e539aa6 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -70,8 +70,7 @@ INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) \ --add-include-path=$(top_builddir)/libdbusmenu-glib \ $(addprefix --c-include=libdbusmenu-gtk/, $(introspection_sources)) \ --symbol-prefix=dbusmenu \ - --identifier-prefix=DbusmenuGtk \ - --pkg-export=dbusmenu-gtk$(VER) + --identifier-prefix=DbusmenuGtk INTROSPECTION_COMPILER_ARGS = --includedir=$(builddir) --includedir=$(top_builddir)/libdbusmenu-glib if HAVE_INTROSPECTION @@ -88,6 +87,7 @@ DbusmenuGtk_0_2_gir_LIBS = libdbusmenu-gtk$(VER).la DbusmenuGtk_0_2_gir_FILES = $(addprefix $(srcdir)/, $(introspection_sources)) DbusmenuGtk_0_2_gir_NAMESPACE = DbusmenuGtk$(VER) DbusmenuGtk_0_2_gir_SCANNERFLAGS = $(INTROSPECTION_SCANNER_ARGS) +DbusmenuGtk_0_2_gir_PACKAGES = dbusmenu-gtk$(VER) # We duplicate these for the same reason as libdbusmenu_gtk3includedir above DbusmenuGtk3_0_2_gir_INCLUDES = $(DbusmenuGtk_0_2_gir_INCLUDES) @@ -96,6 +96,7 @@ DbusmenuGtk3_0_2_gir_LIBS = $(DbusmenuGtk_0_2_gir_LIBS) DbusmenuGtk3_0_2_gir_FILES = $(DbusmenuGtk_0_2_gir_FILES) DbusmenuGtk3_0_2_gir_NAMESPACE = $(DbusmenuGtk_0_2_gir_NAMESPACE) DbusmenuGtk3_0_2_gir_SCANNERFLAGS = $(DbusmenuGtk_0_2_gir_SCANNERFLAGS) +DbusmenuGtk3_0_2_gir_PACKAGES = $(DbusmenuGtk_0_2_gir_PACKAGES) INTROSPECTION_GIRS += DbusmenuGtk$(VER)-0.2.gir -- cgit v1.2.3 From 02be403c32b2228b33d3cb122750889f165419d1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 23 Nov 2010 17:00:14 -0600 Subject: Fixing up variant usage --- libdbusmenu-gtk/menuitem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 9c1cfd2..64913be 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -200,9 +200,9 @@ dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, guint key, const gchar * keyname = gdk_keyval_name(key); g_array_append_val(array, keyname); - GVariant * inside = g_variant_new("as", array->data); + GVariant * inside = g_variant_new_strv((const gchar * const *)array->data, -1); GVariantBuilder builder; - g_variant_builder_init(&builder, G_VARIANT_TYPE("av")); + g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY); g_variant_builder_add_value(&builder, inside); GVariant * outsidevariant = g_variant_builder_end(&builder); -- cgit v1.2.3 From 938856dbb01aa4e583ce637a0cd34846f8a940fd Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 29 Nov 2010 12:32:35 -0600 Subject: Switching shortcut parsing code to more directly use the variant iterator --- libdbusmenu-gtk/menuitem.c | 45 +++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 26 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 64913be..872142b 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -297,35 +297,28 @@ dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * ke return; } - GVariantIter outsideiter; - GVariant * inside; - g_variant_iter_init(&outsideiter, wrapper); - - while(g_variant_iter_next(&outsideiter, "v", &inside)) { - GVariantIter insideiter; - g_variant_iter_init(&insideiter, inside); - gchar * string; - - while(g_variant_iter_next(&insideiter, "s", &string)) { - if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_CONTROL) == 0) { - *modifier |= GDK_CONTROL_MASK; - } else if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_ALT) == 0) { - *modifier |= GDK_MOD1_MASK; - } else if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_SHIFT) == 0) { - *modifier |= GDK_SHIFT_MASK; - } else if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_SUPER) == 0) { - *modifier |= GDK_SUPER_MASK; - } else { - GdkModifierType tempmod; - gtk_accelerator_parse(string, key, &tempmod); - } - - g_free(string); + g_debug("Data: %s", g_variant_print(wrapper, TRUE)); + + GVariantIter iter; + g_variant_iter_init(&iter, g_variant_get_child_value(wrapper, 0)); + gchar * string; + + while(g_variant_iter_next(&iter, "s", &string)) { + if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_CONTROL) == 0) { + *modifier |= GDK_CONTROL_MASK; + } else if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_ALT) == 0) { + *modifier |= GDK_MOD1_MASK; + } else if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_SHIFT) == 0) { + *modifier |= GDK_SHIFT_MASK; + } else if (g_strcmp0(string, DBUSMENU_MENUITEM_SHORTCUT_SUPER) == 0) { + *modifier |= GDK_SUPER_MASK; + } else { + GdkModifierType tempmod; + gtk_accelerator_parse(string, key, &tempmod); } - g_variant_unref(inside); + g_free(string); } - g_variant_unref(wrapper); return; } -- cgit v1.2.3 From 611103533121afca614b2e531c5e113a1a6122f4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 29 Nov 2010 14:21:03 -0600 Subject: Protect against NULL variants to remove warnings --- libdbusmenu-gtk/client.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 9dd18df..77935c5 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -374,7 +374,7 @@ static void menu_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant * variant, GtkMenuItem * gmi) { if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_LABEL)) { - gtk_menu_item_set_label(gmi, g_variant_get_string(variant, NULL)); + gtk_menu_item_set_label(gmi, variant == NULL ? NULL : g_variant_get_string(variant, NULL)); } else if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_VISIBLE)) { process_visible(mi, gmi, variant); } else if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_ENABLED)) { @@ -742,7 +742,9 @@ image_property_handle (DbusmenuMenuitem * item, const gchar * property, GVariant } const gchar * value = NULL; - value = g_variant_get_string(variant, NULL); + if (variant != NULL) { + value = g_variant_get_string(variant, NULL); + } if (value == NULL || value[0] == '\0') { /* This means that we're unsetting a value. */ -- cgit v1.2.3 From e3097b569710d3cb8466f229571dc632decd1671 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 29 Nov 2010 15:38:21 -0600 Subject: Switching to use the builder all the way for the strings instead of the GArray --- libdbusmenu-gtk/menuitem.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 872142b..1b8cab1 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -177,31 +177,26 @@ dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, guint key, g_return_val_if_fail(DBUSMENU_IS_MENUITEM(menuitem), FALSE); g_return_val_if_fail(gtk_accelerator_valid(key, modifier), FALSE); - GArray * array = g_array_sized_new(TRUE, TRUE, sizeof(gchar *), 4); /* Four seems like the max we'd need, plus it's still small */ - - const gchar * control_val = DBUSMENU_MENUITEM_SHORTCUT_CONTROL; - const gchar * alt_val = DBUSMENU_MENUITEM_SHORTCUT_ALT; - const gchar * shift_val = DBUSMENU_MENUITEM_SHORTCUT_SHIFT; - const gchar * super_val = DBUSMENU_MENUITEM_SHORTCUT_SUPER; + GVariantBuilder builder; + g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY); if (modifier & GDK_CONTROL_MASK) { - g_array_append_val(array, control_val); + g_variant_builder_add(&builder, "s", DBUSMENU_MENUITEM_SHORTCUT_CONTROL); } if (modifier & GDK_MOD1_MASK) { - g_array_append_val(array, alt_val); + g_variant_builder_add(&builder, "s", DBUSMENU_MENUITEM_SHORTCUT_ALT); } if (modifier & GDK_SHIFT_MASK) { - g_array_append_val(array, shift_val); + g_variant_builder_add(&builder, "s", DBUSMENU_MENUITEM_SHORTCUT_SHIFT); } if (modifier & GDK_SUPER_MASK) { - g_array_append_val(array, super_val); + g_variant_builder_add(&builder, "s", DBUSMENU_MENUITEM_SHORTCUT_SUPER); } const gchar * keyname = gdk_keyval_name(key); - g_array_append_val(array, keyname); + g_variant_builder_add(&builder, "s", keyname); - GVariant * inside = g_variant_new_strv((const gchar * const *)array->data, -1); - GVariantBuilder builder; + GVariant * inside = g_variant_builder_end(&builder); g_variant_builder_init(&builder, G_VARIANT_TYPE_ARRAY); g_variant_builder_add_value(&builder, inside); GVariant * outsidevariant = g_variant_builder_end(&builder); -- cgit v1.2.3 From 675693fe90c242c4dc9d54d7d3ed34be49d931cc Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 29 Nov 2010 15:50:38 -0600 Subject: Ah, oops, we shouldn't unref these variants as they're kept in the hashtable, we have them as floating. --- libdbusmenu-gtk/menuitem.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 1b8cab1..2251efc 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -201,12 +201,7 @@ dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, guint key, g_variant_builder_add_value(&builder, inside); GVariant * outsidevariant = g_variant_builder_end(&builder); - dbusmenu_menuitem_property_set_variant(menuitem, DBUSMENU_MENUITEM_PROP_SHORTCUT, outsidevariant); - - g_variant_unref(outsidevariant); - g_variant_unref(inside); - - return TRUE; + return dbusmenu_menuitem_property_set_variant(menuitem, DBUSMENU_MENUITEM_PROP_SHORTCUT, outsidevariant); } /* Look at the closures in an accel group and find -- cgit v1.2.3 From 9231081151c71846010c1be75277a4cc0afc29e3 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 29 Nov 2010 15:51:57 -0600 Subject: oops, forgot a debug message --- libdbusmenu-gtk/menuitem.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 2251efc..e27e6ff 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -287,8 +287,6 @@ dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * ke return; } - g_debug("Data: %s", g_variant_print(wrapper, TRUE)); - GVariantIter iter; g_variant_iter_init(&iter, g_variant_get_child_value(wrapper, 0)); gchar * string; -- cgit v1.2.3 From 0ac0a85f42be1aa1c93cfc42a0b4d455f594ba2c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 1 Dec 2010 15:53:09 -0600 Subject: Changing API to 0.4 --- libdbusmenu-gtk/Makefile.am | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index 2be63b7..3a65b03 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -7,7 +7,7 @@ EXTRA_DIST = \ lib_LTLIBRARIES = \ libdbusmenu-gtk.la -libdbusmenu_gtkincludedir=$(includedir)/libdbusmenu-0.1/libdbusmenu-gtk/ +libdbusmenu_gtkincludedir=$(includedir)/libdbusmenu-0.4/libdbusmenu-gtk/ libdbusmenu_gtkinclude_HEADERS = \ client.h \ @@ -55,16 +55,16 @@ if HAVE_INTROSPECTION introspection_sources = $(libdbusmenu_gtkinclude_HEADERS) -DbusmenuGtk-0.2.gir: libdbusmenu-gtk.la -DbusmenuGtk_0_2_gir_INCLUDES = \ +DbusmenuGtk-0.4.gir: libdbusmenu-gtk.la +DbusmenuGtk_0_4_gir_INCLUDES = \ GObject-2.0 \ Gtk-2.0 \ - Dbusmenu-Glib-0.2 -DbusmenuGtk_0_2_gir_CFLAGS = $(DBUSMENUGTK_CFLAGS) -I$(top_srcdir) -DbusmenuGtk_0_2_gir_LIBS = libdbusmenu-gtk.la -DbusmenuGtk_0_2_gir_FILES = $(addprefix $(srcdir)/, $(introspection_sources)) + Dbusmenu-Glib-0.4 +DbusmenuGtk_0_4_gir_CFLAGS = $(DBUSMENUGTK_CFLAGS) -I$(top_srcdir) +DbusmenuGtk_0_4_gir_LIBS = libdbusmenu-gtk.la +DbusmenuGtk_0_4_gir_FILES = $(addprefix $(srcdir)/, $(introspection_sources)) -INTROSPECTION_GIRS += DbusmenuGtk-0.2.gir +INTROSPECTION_GIRS += DbusmenuGtk-0.4.gir girdir = $(datadir)/gir-1.0 gir_DATA = $(INTROSPECTION_GIRS) @@ -83,24 +83,24 @@ endif if HAVE_INTROSPECTION vapidir = $(datadir)/vala/vapi -vapi_DATA = DbusmenuGtk-0.2.vapi +vapi_DATA = DbusmenuGtk-0.4.vapi -DbusmenuGtk-0.2.vapi: DbusmenuGtk-0.2.tmp.gir Makefile.am - $(VALA_API_GEN) --library=DbusmenuGtk-0.2 \ +DbusmenuGtk-0.4.vapi: DbusmenuGtk-0.4.tmp.gir Makefile.am + $(VALA_API_GEN) --library=DbusmenuGtk-0.4 \ --pkg gdk-pixbuf-2.0 \ --pkg gtk+-2.0 \ --pkg atk \ - --pkg Dbusmenu-Glib-0.2 \ + --pkg Dbusmenu-Glib-0.4 \ --vapidir=$(top_builddir)/libdbusmenu-glib \ $< -DbusmenuGtk-0.2.tmp.gir: DbusmenuGtk-0.2.gir +DbusmenuGtk-0.4.tmp.gir: DbusmenuGtk-0.4.gir $(SED) \ -e "s|GdkPixbuf.Pixbuf|Gdk.Pixbuf|g" \ -e "s|Atk.ImplementorIface|Atk.Implementor|g" \ $< > $@ -CLEANFILES += $(vapi_DATA) DbusmenuGtk-0.2.tmp.gir +CLEANFILES += $(vapi_DATA) DbusmenuGtk-0.4.tmp.gir endif -- cgit v1.2.3 From 2a3d4ac52d20ea99e77b44749aaccb07a135fe25 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 1 Dec 2010 20:42:13 -0600 Subject: Changing the include directory to be the correct changed one. --- libdbusmenu-gtk/dbusmenu-gtk.pc.in | 2 +- libdbusmenu-gtk/dbusmenu-gtk3.pc.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/dbusmenu-gtk.pc.in b/libdbusmenu-gtk/dbusmenu-gtk.pc.in index df4cb36..f35c621 100644 --- a/libdbusmenu-gtk/dbusmenu-gtk.pc.in +++ b/libdbusmenu-gtk/dbusmenu-gtk.pc.in @@ -4,7 +4,7 @@ libdir=@libdir@ bindir=@bindir@ includedir=@includedir@ -Cflags: -I${includedir}/libdbusmenu-0.1 +Cflags: -I${includedir}/libdbusmenu-0.4 Requires: dbus-glib-1 dbusmenu-glib Libs: -L${libdir} -ldbusmenu-gtk diff --git a/libdbusmenu-gtk/dbusmenu-gtk3.pc.in b/libdbusmenu-gtk/dbusmenu-gtk3.pc.in index 1a3410e..033c390 100644 --- a/libdbusmenu-gtk/dbusmenu-gtk3.pc.in +++ b/libdbusmenu-gtk/dbusmenu-gtk3.pc.in @@ -4,7 +4,7 @@ libdir=@libdir@ bindir=@bindir@ includedir=@includedir@ -Cflags: -I${includedir}/libdbusmenu-0.1 +Cflags: -I${includedir}/libdbusmenu-0.4 Requires: dbus-glib-1 dbusmenu-glib Libs: -L${libdir} -ldbusmenu-gtk3 -- cgit v1.2.3 From 7c45578e1fbaa08088d4f2d43bc3533e6b9112e1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 1 Dec 2010 20:46:40 -0600 Subject: Moving the pc files to be parallel installable. --- configure.ac | 6 +++--- libdbusmenu-glib/Makefile.am | 4 ++-- libdbusmenu-glib/dbusmenu-glib-0.4.pc.in | 14 ++++++++++++++ libdbusmenu-glib/dbusmenu-glib.pc.in | 14 -------------- libdbusmenu-gtk/Makefile.am | 6 +++--- libdbusmenu-gtk/dbusmenu-gtk-0.4.pc.in | 14 ++++++++++++++ libdbusmenu-gtk/dbusmenu-gtk.pc.in | 14 -------------- libdbusmenu-gtk/dbusmenu-gtk3-0.4.pc.in | 14 ++++++++++++++ libdbusmenu-gtk/dbusmenu-gtk3.pc.in | 14 -------------- 9 files changed, 50 insertions(+), 50 deletions(-) create mode 100644 libdbusmenu-glib/dbusmenu-glib-0.4.pc.in delete mode 100644 libdbusmenu-glib/dbusmenu-glib.pc.in create mode 100644 libdbusmenu-gtk/dbusmenu-gtk-0.4.pc.in delete mode 100644 libdbusmenu-gtk/dbusmenu-gtk.pc.in create mode 100644 libdbusmenu-gtk/dbusmenu-gtk3-0.4.pc.in delete mode 100644 libdbusmenu-gtk/dbusmenu-gtk3.pc.in (limited to 'libdbusmenu-gtk') diff --git a/configure.ac b/configure.ac index bbc1aad..80519e8 100644 --- a/configure.ac +++ b/configure.ac @@ -159,10 +159,10 @@ AC_OUTPUT([ Makefile po/Makefile.in libdbusmenu-glib/Makefile -libdbusmenu-glib/dbusmenu-glib.pc +libdbusmenu-glib/dbusmenu-glib-0.4.pc libdbusmenu-gtk/Makefile -libdbusmenu-gtk/dbusmenu-gtk.pc -libdbusmenu-gtk/dbusmenu-gtk3.pc +libdbusmenu-gtk/dbusmenu-gtk-0.4.pc +libdbusmenu-gtk/dbusmenu-gtk3-0.4.pc tools/Makefile tools/testapp/Makefile tests/Makefile diff --git a/libdbusmenu-glib/Makefile.am b/libdbusmenu-glib/Makefile.am index 6db7e5d..e5a99a2 100644 --- a/libdbusmenu-glib/Makefile.am +++ b/libdbusmenu-glib/Makefile.am @@ -3,7 +3,7 @@ CLEANFILES = EXTRA_DIST = \ clean-namespaces.xslt \ - dbusmenu-glib.pc.in \ + dbusmenu-glib-0.4.pc.in \ dbus-menu.xml \ client-marshal.list \ menuitem-marshal.list \ @@ -52,7 +52,7 @@ libdbusmenu_glib_la_CFLAGS = \ libdbusmenu_glib_la_LIBADD = \ $(DBUSMENUGLIB_LIBS) -pkgconfig_DATA = dbusmenu-glib.pc +pkgconfig_DATA = dbusmenu-glib-0.4.pc pkgconfigdir = $(libdir)/pkgconfig %.xml.h: %.xml diff --git a/libdbusmenu-glib/dbusmenu-glib-0.4.pc.in b/libdbusmenu-glib/dbusmenu-glib-0.4.pc.in new file mode 100644 index 0000000..3f31664 --- /dev/null +++ b/libdbusmenu-glib/dbusmenu-glib-0.4.pc.in @@ -0,0 +1,14 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +bindir=@bindir@ +includedir=@includedir@ + +Cflags: -I${includedir}/libdbusmenu-0.4 +Requires: dbus-glib-1 +Libs: -L${libdir} -ldbusmenu-glib + +Name: libdbusmenu-glib +Description: libdbusmenu-glib. +Version: @VERSION@ + diff --git a/libdbusmenu-glib/dbusmenu-glib.pc.in b/libdbusmenu-glib/dbusmenu-glib.pc.in deleted file mode 100644 index 3f31664..0000000 --- a/libdbusmenu-glib/dbusmenu-glib.pc.in +++ /dev/null @@ -1,14 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -bindir=@bindir@ -includedir=@includedir@ - -Cflags: -I${includedir}/libdbusmenu-0.4 -Requires: dbus-glib-1 -Libs: -L${libdir} -ldbusmenu-glib - -Name: libdbusmenu-glib -Description: libdbusmenu-glib. -Version: @VERSION@ - diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index e512c4d..7eb725a 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -14,8 +14,8 @@ lib_LTLIBRARIES = libdbusmenu-gtk.la endif EXTRA_DIST = \ - dbusmenu-gtk.pc.in \ - dbusmenu-gtk3.pc.in + dbusmenu-gtk-0.4.pc.in \ + dbusmenu-gtk3-0.4.pc.in libdbusmenu_gtkincludedir=$(includedir)/libdbusmenu-0.4/libdbusmenu-gtk$(VER)/ @@ -57,7 +57,7 @@ libdbusmenu_gtk3_la_LDFLAGS = $(libdbusmenu_gtk_la_LDFLAGS) libdbusmenu_gtk3_la_CFLAGS = $(libdbusmenu_gtk_la_CFLAGS) libdbusmenu_gtk3_la_LIBADD = $(libdbusmenu_gtk_la_LIBADD) -pkgconfig_DATA = dbusmenu-gtk$(VER).pc +pkgconfig_DATA = dbusmenu-gtk$(VER)-0.4.pc pkgconfigdir = $(libdir)/pkgconfig ######################### diff --git a/libdbusmenu-gtk/dbusmenu-gtk-0.4.pc.in b/libdbusmenu-gtk/dbusmenu-gtk-0.4.pc.in new file mode 100644 index 0000000..f35c621 --- /dev/null +++ b/libdbusmenu-gtk/dbusmenu-gtk-0.4.pc.in @@ -0,0 +1,14 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +bindir=@bindir@ +includedir=@includedir@ + +Cflags: -I${includedir}/libdbusmenu-0.4 +Requires: dbus-glib-1 dbusmenu-glib +Libs: -L${libdir} -ldbusmenu-gtk + +Name: libdbusmenu-gtk +Description: libdbusmenu-gtk. +Version: @VERSION@ + diff --git a/libdbusmenu-gtk/dbusmenu-gtk.pc.in b/libdbusmenu-gtk/dbusmenu-gtk.pc.in deleted file mode 100644 index f35c621..0000000 --- a/libdbusmenu-gtk/dbusmenu-gtk.pc.in +++ /dev/null @@ -1,14 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -bindir=@bindir@ -includedir=@includedir@ - -Cflags: -I${includedir}/libdbusmenu-0.4 -Requires: dbus-glib-1 dbusmenu-glib -Libs: -L${libdir} -ldbusmenu-gtk - -Name: libdbusmenu-gtk -Description: libdbusmenu-gtk. -Version: @VERSION@ - diff --git a/libdbusmenu-gtk/dbusmenu-gtk3-0.4.pc.in b/libdbusmenu-gtk/dbusmenu-gtk3-0.4.pc.in new file mode 100644 index 0000000..033c390 --- /dev/null +++ b/libdbusmenu-gtk/dbusmenu-gtk3-0.4.pc.in @@ -0,0 +1,14 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +bindir=@bindir@ +includedir=@includedir@ + +Cflags: -I${includedir}/libdbusmenu-0.4 +Requires: dbus-glib-1 dbusmenu-glib +Libs: -L${libdir} -ldbusmenu-gtk3 + +Name: libdbusmenu-gtk3 +Description: libdbusmenu-gtk3. +Version: @VERSION@ + diff --git a/libdbusmenu-gtk/dbusmenu-gtk3.pc.in b/libdbusmenu-gtk/dbusmenu-gtk3.pc.in deleted file mode 100644 index 033c390..0000000 --- a/libdbusmenu-gtk/dbusmenu-gtk3.pc.in +++ /dev/null @@ -1,14 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -bindir=@bindir@ -includedir=@includedir@ - -Cflags: -I${includedir}/libdbusmenu-0.4 -Requires: dbus-glib-1 dbusmenu-glib -Libs: -L${libdir} -ldbusmenu-gtk3 - -Name: libdbusmenu-gtk3 -Description: libdbusmenu-gtk3. -Version: @VERSION@ - -- cgit v1.2.3 From 9dba82584abf181777b7bed4cca8202cf6652ff6 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 2 Dec 2010 13:52:54 -0600 Subject: Removing a GValue to use the direct functions --- libdbusmenu-gtk/genericmenuitem.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/genericmenuitem.c b/libdbusmenu-gtk/genericmenuitem.c index 990ca82..61881ef 100644 --- a/libdbusmenu-gtk/genericmenuitem.c +++ b/libdbusmenu-gtk/genericmenuitem.c @@ -291,7 +291,6 @@ genericmenuitem_set_check_type (Genericmenuitem * item, GenericmenuitemCheckType } item->priv->check_type = check_type; - GValue value = {0}; switch (item->priv->check_type) { case GENERICMENUITEM_CHECK_TYPE_NONE: @@ -300,22 +299,16 @@ genericmenuitem_set_check_type (Genericmenuitem * item, GenericmenuitemCheckType check on the item. */ break; case GENERICMENUITEM_CHECK_TYPE_CHECKBOX: - g_value_init(&value, G_TYPE_BOOLEAN); - g_value_set_boolean(&value, FALSE); - g_object_set_property(G_OBJECT(item), "draw-as-radio", &value); + gtk_check_menu_item_set_draw_as_radio(GTK_CHECK_MENU_ITEM(item), FALSE); break; case GENERICMENUITEM_CHECK_TYPE_RADIO: - g_value_init(&value, G_TYPE_BOOLEAN); - g_value_set_boolean(&value, TRUE); - g_object_set_property(G_OBJECT(item), "draw-as-radio", &value); + gtk_check_menu_item_set_draw_as_radio(GTK_CHECK_MENU_ITEM(item), TRUE); break; default: g_warning("Generic Menuitem invalid check type: %d", check_type); return; } - g_value_unset(&value); - gtk_widget_queue_draw(GTK_WIDGET(item)); return; -- cgit v1.2.3 From 5f1c15b654a09bf8d5ad04b8d8ff046cdf7068fa Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 6 Dec 2010 10:50:24 -0600 Subject: Add a check for GIR version less that 10 --- configure.ac | 6 ++++++ libdbusmenu-glib/Makefile.am | 7 +++++++ libdbusmenu-gtk/Makefile.am | 8 ++++++++ 3 files changed, 21 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/configure.ac b/configure.ac index 4a7bc86..a285ad9 100644 --- a/configure.ac +++ b/configure.ac @@ -116,6 +116,12 @@ AC_SUBST(DBUSMENUTESTS_LIBS) GOBJECT_INTROSPECTION_CHECK([0.6.7]) +PKG_CHECK_EXISTS([gobject-introspection-1.0 >= 0.10], + introspection_ten=yes, + introspection_ten=no) + +AM_CONDITIONAL(INTROSPECTION_TEN, [test "x$introspection_ten" = "xyes"]) + ########################### # Vala API Generation ########################### diff --git a/libdbusmenu-glib/Makefile.am b/libdbusmenu-glib/Makefile.am index adf4607..d33bc9b 100644 --- a/libdbusmenu-glib/Makefile.am +++ b/libdbusmenu-glib/Makefile.am @@ -114,11 +114,18 @@ menuitem-marshal.c: $(srcdir)/menuitem-marshal.list -include $(INTROSPECTION_MAKEFILE) INTROSPECTION_GIRS = + +if INTROSPECTION_TEN INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) \ --add-include-path=$(srcdir) \ $(addprefix --c-include=libdbusmenu-glib/, $(introspection_sources)) \ --symbol-prefix=dbusmenu \ --identifier-prefix=Dbusmenu +else +INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) \ + --add-include-path=$(srcdir) \ + $(addprefix --c-include=libdbusmenu-glib/, $(introspection_sources)) +endif INTROSPECTION_COMPILER_ARGS = --includedir=$(builddir) diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index e539aa6..19765d5 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -66,11 +66,19 @@ pkgconfigdir = $(libdir)/pkgconfig -include $(INTROSPECTION_MAKEFILE) INTROSPECTION_GIRS = + +if INTROSPECTION_TEN INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) \ --add-include-path=$(top_builddir)/libdbusmenu-glib \ $(addprefix --c-include=libdbusmenu-gtk/, $(introspection_sources)) \ --symbol-prefix=dbusmenu \ --identifier-prefix=DbusmenuGtk +else +INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) \ + --add-include-path=$(top_builddir)/libdbusmenu-glib \ + $(addprefix --c-include=libdbusmenu-gtk/, $(introspection_sources)) +endif + INTROSPECTION_COMPILER_ARGS = --includedir=$(builddir) --includedir=$(top_builddir)/libdbusmenu-glib if HAVE_INTROSPECTION -- cgit v1.2.3 From 1a73825600508b5d7f027641b05a682a8ac81f5e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 8 Dec 2010 09:27:48 -0600 Subject: Fixing the requires in the pc files --- libdbusmenu-glib/dbusmenu-glib-0.4.pc.in | 2 +- libdbusmenu-gtk/dbusmenu-gtk-0.4.pc.in | 2 +- libdbusmenu-gtk/dbusmenu-gtk3-0.4.pc.in | 2 +- tests/dbusmenu-jsonloader-0.4.pc.in | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-glib/dbusmenu-glib-0.4.pc.in b/libdbusmenu-glib/dbusmenu-glib-0.4.pc.in index 3f31664..31a1eac 100644 --- a/libdbusmenu-glib/dbusmenu-glib-0.4.pc.in +++ b/libdbusmenu-glib/dbusmenu-glib-0.4.pc.in @@ -5,7 +5,7 @@ bindir=@bindir@ includedir=@includedir@ Cflags: -I${includedir}/libdbusmenu-0.4 -Requires: dbus-glib-1 +Requires: Libs: -L${libdir} -ldbusmenu-glib Name: libdbusmenu-glib diff --git a/libdbusmenu-gtk/dbusmenu-gtk-0.4.pc.in b/libdbusmenu-gtk/dbusmenu-gtk-0.4.pc.in index f35c621..8784556 100644 --- a/libdbusmenu-gtk/dbusmenu-gtk-0.4.pc.in +++ b/libdbusmenu-gtk/dbusmenu-gtk-0.4.pc.in @@ -5,7 +5,7 @@ bindir=@bindir@ includedir=@includedir@ Cflags: -I${includedir}/libdbusmenu-0.4 -Requires: dbus-glib-1 dbusmenu-glib +Requires: dbusmenu-glib-0.4 Libs: -L${libdir} -ldbusmenu-gtk Name: libdbusmenu-gtk diff --git a/libdbusmenu-gtk/dbusmenu-gtk3-0.4.pc.in b/libdbusmenu-gtk/dbusmenu-gtk3-0.4.pc.in index 033c390..804b13e 100644 --- a/libdbusmenu-gtk/dbusmenu-gtk3-0.4.pc.in +++ b/libdbusmenu-gtk/dbusmenu-gtk3-0.4.pc.in @@ -5,7 +5,7 @@ bindir=@bindir@ includedir=@includedir@ Cflags: -I${includedir}/libdbusmenu-0.4 -Requires: dbus-glib-1 dbusmenu-glib +Requires: dbusmenu-glib-0.4 Libs: -L${libdir} -ldbusmenu-gtk3 Name: libdbusmenu-gtk3 diff --git a/tests/dbusmenu-jsonloader-0.4.pc.in b/tests/dbusmenu-jsonloader-0.4.pc.in index d042132..62bfeb2 100644 --- a/tests/dbusmenu-jsonloader-0.4.pc.in +++ b/tests/dbusmenu-jsonloader-0.4.pc.in @@ -5,7 +5,7 @@ bindir=@bindir@ includedir=@includedir@ Cflags: -I${includedir}/libdbusmenu-0.1 -Requires: dbus-glib-1,dbusmenu-glib,json-glib-1.0 +Requires: dbusmenu-glib-0.4 json-glib-1.0 Libs: -L${libdir} -ldbusmenu-jsonloader Name: libdbusmenu-jsonloader -- cgit v1.2.3 From 1574d58e111bd80cbeb770ab3f603dca88a90341 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 9 Dec 2010 16:36:48 -0600 Subject: Switching away from using set_activate as that doesn't actually set the value, it just signals, but we're sucking up that signal already so we need to manually create it if we need it, which is the only way to set the active property. Goofy. --- libdbusmenu-gtk/genericmenuitem.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/genericmenuitem.c b/libdbusmenu-gtk/genericmenuitem.c index d507487..d3023ad 100644 --- a/libdbusmenu-gtk/genericmenuitem.c +++ b/libdbusmenu-gtk/genericmenuitem.c @@ -65,6 +65,7 @@ static void (*parent_draw_indicator) (GtkCheckMenuItem *check_menu_item, cairo_t static void draw_indicator (GtkCheckMenuItem *check_menu_item, GdkRectangle *area); static void (*parent_draw_indicator) (GtkCheckMenuItem *check_menu_item, GdkRectangle *area) = NULL; #endif +static void (*parent_menuitem_activate) (GtkMenuItem * mi) = NULL; /* Initializing all of the classes. Most notably we're disabling the drawing of the check early. */ @@ -86,6 +87,7 @@ genericmenuitem_class_init (GenericmenuitemClass *klass) GtkMenuItemClass * menuitem_class = GTK_MENU_ITEM_CLASS (klass); menuitem_class->set_label = set_label; menuitem_class->get_label = get_label; + parent_menuitem_activate = menuitem_class->activate; menuitem_class->activate = activate; return; @@ -338,21 +340,19 @@ genericmenuitem_set_state (Genericmenuitem * item, GenericmenuitemState state) item->priv->state = state; GtkCheckMenuItem * check = GTK_CHECK_MENU_ITEM(item); - - gboolean old_active = gtk_check_menu_item_get_active (check); - gboolean old_inconsist = gtk_check_menu_item_get_inconsistent (check); + gboolean goal_active = FALSE; switch (item->priv->state) { case GENERICMENUITEM_STATE_UNCHECKED: - gtk_check_menu_item_set_active (check, FALSE); + goal_active = FALSE; gtk_check_menu_item_set_inconsistent (check, FALSE); break; case GENERICMENUITEM_STATE_CHECKED: - gtk_check_menu_item_set_active (check, TRUE); + goal_active = TRUE; gtk_check_menu_item_set_inconsistent (check, FALSE); break; case GENERICMENUITEM_STATE_INDETERMINATE: - gtk_check_menu_item_set_active (check, TRUE); + goal_active = TRUE; gtk_check_menu_item_set_inconsistent (check, TRUE); break; default: @@ -360,16 +360,12 @@ genericmenuitem_set_state (Genericmenuitem * item, GenericmenuitemState state) return; } - if (old_active != gtk_check_menu_item_get_active (check)) { - g_object_notify(G_OBJECT(item), "active"); - } - - if (old_inconsist != gtk_check_menu_item_get_inconsistent (check)) { - g_object_notify(G_OBJECT(item), "inconsistent"); + if (goal_active != gtk_check_menu_item_get_active(check)) { + if (parent_menuitem_activate != NULL) { + parent_menuitem_activate(GTK_MENU_ITEM(check)); + } } - gtk_widget_queue_draw(GTK_WIDGET(item)); - return; } -- cgit v1.2.3 From 9ca2114ba780c0d7976e66fbc6e4ae750a7522c4 Mon Sep 17 00:00:00 2001 From: Chris Coulson Date: Mon, 13 Dec 2010 13:40:01 +0000 Subject: Bracked public libdbusmenu-gtk/menuitem.h header with G_{BEGIN/END}_DECLS, so it can be used from C++ consumers --- libdbusmenu-gtk/menuitem.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.h b/libdbusmenu-gtk/menuitem.h index 6960f76..a2b6652 100644 --- a/libdbusmenu-gtk/menuitem.h +++ b/libdbusmenu-gtk/menuitem.h @@ -35,6 +35,8 @@ License version 3 and version 2.1 along with this program. If not, see #include #include +G_BEGIN_DECLS + gboolean dbusmenu_menuitem_property_set_image (DbusmenuMenuitem * menuitem, const gchar * property, const GdkPixbuf * data); GdkPixbuf * dbusmenu_menuitem_property_get_image (DbusmenuMenuitem * menuitem, const gchar * property); @@ -43,4 +45,6 @@ gboolean dbusmenu_menuitem_property_set_shortcut_string (DbusmenuMenuitem * menu gboolean dbusmenu_menuitem_property_set_shortcut_menuitem (DbusmenuMenuitem * menuitem, const GtkMenuItem * gmi); void dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * key, GdkModifierType * modifiers); +G_END_DECLS + #endif -- cgit v1.2.3 From 86337748c5683bc8f5f953e9baa85fe485d8ff26 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 13 Jan 2011 09:57:37 -0600 Subject: Fixing packages names for the gir scanner --- libdbusmenu-glib/Makefile.am | 2 +- libdbusmenu-gtk/Makefile.am | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-glib/Makefile.am b/libdbusmenu-glib/Makefile.am index e45f700..4a65ac0 100644 --- a/libdbusmenu-glib/Makefile.am +++ b/libdbusmenu-glib/Makefile.am @@ -143,7 +143,7 @@ Dbusmenu_Glib_0_4_gir_LIBS = libdbusmenu-glib.la Dbusmenu_Glib_0_4_gir_FILES = $(addprefix $(srcdir)/, $(introspection_sources)) Dbusmenu_Glib_0_4_gir_NAMESPACE = Dbusmenu Dbusmenu_Glib_0_4_gir_VERSION = Glib-0.4 -Dbusmenu_Glib_0_4_gir_PACKAGES = dbusmenu-glib +Dbusmenu_Glib_0_4_gir_PACKAGES = dbusmenu-glib-0.4 Dbusmenu_Glib_0_4_gir_SCANNER_FLAGS = $(INTROSPECTION_SCANNER_ARGS) INTROSPECTION_GIRS += Dbusmenu-Glib-0.4.gir diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index ac2eee9..1957820 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -95,7 +95,7 @@ DbusmenuGtk_0_4_gir_LIBS = libdbusmenu-gtk$(VER).la DbusmenuGtk_0_4_gir_FILES = $(addprefix $(srcdir)/, $(introspection_sources)) DbusmenuGtk_0_4_gir_NAMESPACE = DbusmenuGtk$(VER) DbusmenuGtk_0_4_gir_SCANNERFLAGS = $(INTROSPECTION_SCANNER_ARGS) -DbusmenuGtk_0_4_gir_PACKAGES = dbusmenu-gtk$(VER) +DbusmenuGtk_0_4_gir_PACKAGES = dbusmenu-gtk$(VER)-0.4 # We duplicate these for the same reason as libdbusmenu_gtk3includedir above DbusmenuGtk3_0_4_gir_INCLUDES = $(DbusmenuGtk_0_4_gir_INCLUDES) -- cgit v1.2.3 From 66cfbe695f21345bb0cf84824f4b2d9183067a25 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Tue, 18 Jan 2011 10:02:47 -0500 Subject: Use EXPORT_PACKAGES instead of PACKAGES to prevent circular build depends --- libdbusmenu-glib/Makefile.am | 2 +- libdbusmenu-gtk/Makefile.am | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-glib/Makefile.am b/libdbusmenu-glib/Makefile.am index a1247a3..f502fb3 100644 --- a/libdbusmenu-glib/Makefile.am +++ b/libdbusmenu-glib/Makefile.am @@ -143,7 +143,7 @@ Dbusmenu_Glib_0_4_gir_LIBS = libdbusmenu-glib.la Dbusmenu_Glib_0_4_gir_FILES = $(addprefix $(srcdir)/, $(introspection_sources)) Dbusmenu_Glib_0_4_gir_NAMESPACE = Dbusmenu Dbusmenu_Glib_0_4_gir_VERSION = Glib-0.4 -Dbusmenu_Glib_0_4_gir_PACKAGES = dbusmenu-glib-0.4 +Dbusmenu_Glib_0_4_gir_EXPORT_PACKAGES = dbusmenu-glib-0.4 Dbusmenu_Glib_0_4_gir_SCANNER_FLAGS = $(INTROSPECTION_SCANNER_ARGS) INTROSPECTION_GIRS += Dbusmenu-Glib-0.4.gir diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index 1957820..0b939c0 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -95,7 +95,7 @@ DbusmenuGtk_0_4_gir_LIBS = libdbusmenu-gtk$(VER).la DbusmenuGtk_0_4_gir_FILES = $(addprefix $(srcdir)/, $(introspection_sources)) DbusmenuGtk_0_4_gir_NAMESPACE = DbusmenuGtk$(VER) DbusmenuGtk_0_4_gir_SCANNERFLAGS = $(INTROSPECTION_SCANNER_ARGS) -DbusmenuGtk_0_4_gir_PACKAGES = dbusmenu-gtk$(VER)-0.4 +DbusmenuGtk_0_4_gir_EXPORT_PACKAGES = dbusmenu-gtk$(VER)-0.4 # We duplicate these for the same reason as libdbusmenu_gtk3includedir above DbusmenuGtk3_0_4_gir_INCLUDES = $(DbusmenuGtk_0_4_gir_INCLUDES) @@ -104,7 +104,7 @@ DbusmenuGtk3_0_4_gir_LIBS = $(DbusmenuGtk_0_4_gir_LIBS) DbusmenuGtk3_0_4_gir_FILES = $(DbusmenuGtk_0_4_gir_FILES) DbusmenuGtk3_0_4_gir_NAMESPACE = $(DbusmenuGtk_0_4_gir_NAMESPACE) DbusmenuGtk3_0_4_gir_SCANNERFLAGS = $(DbusmenuGtk_0_4_gir_SCANNERFLAGS) -DbusmenuGtk3_0_4_gir_PACKAGES = $(DbusmenuGtk_0_4_gir_PACKAGES) +DbusmenuGtk3_0_4_gir_EXPORT_PACKAGES = $(DbusmenuGtk_0_4_gir_EXPORT_PACKAGES) INTROSPECTION_GIRS += DbusmenuGtk$(VER)-0.4.gir -- cgit v1.2.3 From cedc4584f11e6fa90ae73db5ecc3019868a6323e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 Jan 2011 15:59:36 -0600 Subject: Set the use-fallback property to TRUE on all our Images --- libdbusmenu-gtk/client.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index b01156f..18a2cdd 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -789,6 +789,7 @@ image_property_handle (DbusmenuMenuitem * item, const gchar * property, GVariant gtkimage = NULL; } else if (g_strcmp0(iconname, DBUSMENU_MENUITEM_ICON_NAME_BLANK) == 0) { gtkimage = gtk_image_new(); + g_object_set(G_OBJECT(gtkimage), "use-fallback", TRUE, NULL); } else { /* Look to see if we want to have an icon with the 'ltr' or 'rtl' depending on what we're doing. */ @@ -807,6 +808,7 @@ image_property_handle (DbusmenuMenuitem * item, const gchar * property, GVariant can just convert it to this name. */ if (gtkimage == NULL) { gtkimage = gtk_image_new_from_icon_name(finaliconname, GTK_ICON_SIZE_MENU); + g_object_set(G_OBJECT(gtkimage), "use-fallback", TRUE, NULL); } else { gtk_image_set_from_icon_name(GTK_IMAGE(gtkimage), finaliconname, GTK_ICON_SIZE_MENU); } -- cgit v1.2.3 From e319b07fba9a47a15aae9ef7c85da464b75874ff Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 Jan 2011 16:02:48 -0600 Subject: Steal the serializable menuitem from IDO --- libdbusmenu-gtk/serializablemenuitem.c | 99 ++++++++++++++++++++++++++++++++++ libdbusmenu-gtk/serializablemenuitem.h | 58 ++++++++++++++++++++ 2 files changed, 157 insertions(+) create mode 100644 libdbusmenu-gtk/serializablemenuitem.c create mode 100644 libdbusmenu-gtk/serializablemenuitem.h (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c new file mode 100644 index 0000000..2c166d8 --- /dev/null +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -0,0 +1,99 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "idoserializablemenuitem.h" + +struct _IdoSerializableMenuItemPrivate { + int dummy; +}; + +#define IDO_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(o) \ +(G_TYPE_INSTANCE_GET_PRIVATE ((o), IDO_TYPE_SERIALIZABLE_MENU_ITEM, IdoSerializableMenuItemPrivate)) + +static void ido_serializable_menu_item_class_init (IdoSerializableMenuItemClass *klass); +static void ido_serializable_menu_item_init (IdoSerializableMenuItem *self); +static void ido_serializable_menu_item_dispose (GObject *object); +static void ido_serializable_menu_item_finalize (GObject *object); + +G_DEFINE_TYPE (IdoSerializableMenuItem, ido_serializable_menu_item, GTK_TYPE_MENU_ITEM); + +static void +ido_serializable_menu_item_class_init (IdoSerializableMenuItemClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + g_type_class_add_private (klass, sizeof (IdoSerializableMenuItemPrivate)); + + object_class->dispose = ido_serializable_menu_item_dispose; + object_class->finalize = ido_serializable_menu_item_finalize; + + return; +} + +static void +ido_serializable_menu_item_init (IdoSerializableMenuItem *self) +{ + self->priv = IDO_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(self); + + self->priv->dummy = 5; + + return; +} + +static void +ido_serializable_menu_item_dispose (GObject *object) +{ + + + G_OBJECT_CLASS (ido_serializable_menu_item_parent_class)->dispose (object); + return; +} + +static void +ido_serializable_menu_item_finalize (GObject *object) +{ + + + + G_OBJECT_CLASS (ido_serializable_menu_item_parent_class)->finalize (object); + return; +} + +DbusmenuMenuitem * +ido_serializable_menu_item_get_dbusmenu_menuitem (IdoSerializableMenuItem * smi) +{ + g_return_val_if_fail(IDO_IS_SERIALIZABLE_MENU_ITEM(smi), NULL); + + IdoSerializableMenuItemClass * klass = IDO_SERIALIZABLE_MENU_ITEM_GET_CLASS(smi); + if (klass->get_dbusmenu_menuitem != NULL) { + return klass->get_dbusmenu_menuitem(smi); + } + + return NULL; +} + +void +ido_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type) +{ + g_return_if_fail(g_type_is_a(item_type, IDO_TYPE_SERIALIZABLE_MENU_ITEM)); + + gpointer type_class = g_type_class_ref(item_type); + g_return_if_fail(type_class != NULL); + + IdoSerializableMenuItemClass * class = IDO_SERIALIZABLE_MENU_ITEM_CLASS(type_class); + + if (class->get_type_string == NULL) { + g_type_class_unref(type_class); + g_error("No 'get_type_string' in subclass of IdoSerializableMenuItem"); + return; + } + + /* Register type */ + + + /* Register defaults */ + + + return; +} diff --git a/libdbusmenu-gtk/serializablemenuitem.h b/libdbusmenu-gtk/serializablemenuitem.h new file mode 100644 index 0000000..48fdb49 --- /dev/null +++ b/libdbusmenu-gtk/serializablemenuitem.h @@ -0,0 +1,58 @@ +#ifndef __IDO_SERIALIZABLE_MENU_ITEM_H__ +#define __IDO_SERIALIZABLE_MENU_ITEM_H__ + +#include +#include +#include +#include +#include + +G_BEGIN_DECLS + +#define IDO_TYPE_SERIALIZABLE_MENU_ITEM (ido_serializable_menu_item_get_type ()) +#define IDO_SERIALIZABLE_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IDO_TYPE_SERIALIZABLE_MENU_ITEM, IdoSerializableMenuItem)) +#define IDO_SERIALIZABLE_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IDO_TYPE_SERIALIZABLE_MENU_ITEM, IdoSerializableMenuItemClass)) +#define IDO_IS_SERIALIZABLE_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IDO_TYPE_SERIALIZABLE_MENU_ITEM)) +#define IDO_IS_SERIALIZABLE_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IDO_TYPE_SERIALIZABLE_MENU_ITEM)) +#define IDO_SERIALIZABLE_MENU_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IDO_TYPE_SERIALIZABLE_MENU_ITEM, IdoSerializableMenuItemClass)) + +typedef struct _IdoSerializableMenuItem IdoSerializableMenuItem; +typedef struct _IdoSerializableMenuItemClass IdoSerializableMenuItemClass; +typedef struct _IdoSerializableMenuItemPrivate IdoSerializableMenuItemPrivate; + +struct _IdoSerializableMenuItemClass { + GtkMenuItemClass parent_class; + + /* Subclassable functions */ + const gchar * (*get_type_string) (void); + GHashTable * (*get_default_properties) (void); + + DbusmenuMenuitem * (*get_dbusmenu_menuitem) (IdoSerializableMenuItem * smi); + + /* Signals */ + + + + /* Empty Space */ + void (*_ido_serializable_menu_item_reserved1) (void); + void (*_ido_serializable_menu_item_reserved2) (void); + void (*_ido_serializable_menu_item_reserved3) (void); + void (*_ido_serializable_menu_item_reserved4) (void); + void (*_ido_serializable_menu_item_reserved5) (void); + void (*_ido_serializable_menu_item_reserved6) (void); +}; + +struct _IdoSerializableMenuItem { + GtkMenuItem parent; + + IdoSerializableMenuItemPrivate * priv; +}; + +GType ido_serializable_menu_item_get_type (void); + +DbusmenuMenuitem * ido_serializable_menu_item_get_dbusmenu_menuitem (IdoSerializableMenuItem * smi); +void ido_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type); + +G_END_DECLS + +#endif -- cgit v1.2.3 From d43d544702665d2653f7dbb9c73493733ff2fae6 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 Jan 2011 16:27:12 -0600 Subject: Adding the files to the build --- libdbusmenu-gtk/Makefile.am | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index 0b939c0..a424d4a 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -22,7 +22,8 @@ libdbusmenu_gtkincludedir=$(includedir)/libdbusmenu-0.4/libdbusmenu-gtk$(VER)/ libdbusmenu_gtkinclude_HEADERS = \ client.h \ menu.h \ - menuitem.h + menuitem.h \ + serializablemenuitem.h libdbusmenu_gtk_la_SOURCES = \ client.h \ @@ -32,7 +33,9 @@ libdbusmenu_gtk_la_SOURCES = \ menu.h \ menu.c \ menuitem.h \ - menuitem.c + menuitem.c \ + serializablemenuitem.h \ + serializablemenuitem.c libdbusmenu_gtk_la_LDFLAGS = \ -version-info $(LIBDBUSMENU_CURRENT):$(LIBDBUSMENU_REVISION):$(LIBDBUSMENU_AGE) \ -- cgit v1.2.3 From 8122074a5e67cf69f147a8b10b31c1fefaf64486 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 Jan 2011 16:32:02 -0600 Subject: Changing namespace from IDO to DBusMenu GTK --- libdbusmenu-gtk/serializablemenuitem.c | 52 +++++++++++++++++----------------- libdbusmenu-gtk/serializablemenuitem.h | 48 +++++++++++++++---------------- 2 files changed, 50 insertions(+), 50 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 2c166d8..c9eb416 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -2,39 +2,39 @@ #include "config.h" #endif -#include "idoserializablemenuitem.h" +#include "serializablemenuitem.h" -struct _IdoSerializableMenuItemPrivate { +struct _DbusmenuGtkSerializableMenuItemPrivate { int dummy; }; -#define IDO_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(o) \ -(G_TYPE_INSTANCE_GET_PRIVATE ((o), IDO_TYPE_SERIALIZABLE_MENU_ITEM, IdoSerializableMenuItemPrivate)) +#define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(o) \ +(G_TYPE_INSTANCE_GET_PRIVATE ((o), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM, DbusmenuGtkSerializableMenuItemPrivate)) -static void ido_serializable_menu_item_class_init (IdoSerializableMenuItemClass *klass); -static void ido_serializable_menu_item_init (IdoSerializableMenuItem *self); -static void ido_serializable_menu_item_dispose (GObject *object); -static void ido_serializable_menu_item_finalize (GObject *object); +static void dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializableMenuItemClass *klass); +static void dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self); +static void dbusmenu_gtk_serializable_menu_item_dispose (GObject *object); +static void dbusmenu_gtk_serializable_menu_item_finalize (GObject *object); -G_DEFINE_TYPE (IdoSerializableMenuItem, ido_serializable_menu_item, GTK_TYPE_MENU_ITEM); +G_DEFINE_TYPE (DbusmenuGtkSerializableMenuItem, dbusmenu_gtk_serializable_menu_item, GTK_TYPE_MENU_ITEM); static void -ido_serializable_menu_item_class_init (IdoSerializableMenuItemClass *klass) +dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializableMenuItemClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - g_type_class_add_private (klass, sizeof (IdoSerializableMenuItemPrivate)); + g_type_class_add_private (klass, sizeof (DbusmenuGtkSerializableMenuItemPrivate)); - object_class->dispose = ido_serializable_menu_item_dispose; - object_class->finalize = ido_serializable_menu_item_finalize; + object_class->dispose = dbusmenu_gtk_serializable_menu_item_dispose; + object_class->finalize = dbusmenu_gtk_serializable_menu_item_finalize; return; } static void -ido_serializable_menu_item_init (IdoSerializableMenuItem *self) +dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self) { - self->priv = IDO_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(self); + self->priv = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(self); self->priv->dummy = 5; @@ -42,30 +42,30 @@ ido_serializable_menu_item_init (IdoSerializableMenuItem *self) } static void -ido_serializable_menu_item_dispose (GObject *object) +dbusmenu_gtk_serializable_menu_item_dispose (GObject *object) { - G_OBJECT_CLASS (ido_serializable_menu_item_parent_class)->dispose (object); + G_OBJECT_CLASS (dbusmenu_gtk_serializable_menu_item_parent_class)->dispose (object); return; } static void -ido_serializable_menu_item_finalize (GObject *object) +dbusmenu_gtk_serializable_menu_item_finalize (GObject *object) { - G_OBJECT_CLASS (ido_serializable_menu_item_parent_class)->finalize (object); + G_OBJECT_CLASS (dbusmenu_gtk_serializable_menu_item_parent_class)->finalize (object); return; } DbusmenuMenuitem * -ido_serializable_menu_item_get_dbusmenu_menuitem (IdoSerializableMenuItem * smi) +dbusmenu_gtk_serializable_menu_item_get_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi) { - g_return_val_if_fail(IDO_IS_SERIALIZABLE_MENU_ITEM(smi), NULL); + g_return_val_if_fail(DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM(smi), NULL); - IdoSerializableMenuItemClass * klass = IDO_SERIALIZABLE_MENU_ITEM_GET_CLASS(smi); + DbusmenuGtkSerializableMenuItemClass * klass = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_CLASS(smi); if (klass->get_dbusmenu_menuitem != NULL) { return klass->get_dbusmenu_menuitem(smi); } @@ -74,18 +74,18 @@ ido_serializable_menu_item_get_dbusmenu_menuitem (IdoSerializableMenuItem * smi) } void -ido_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type) +dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type) { - g_return_if_fail(g_type_is_a(item_type, IDO_TYPE_SERIALIZABLE_MENU_ITEM)); + g_return_if_fail(g_type_is_a(item_type, DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM)); gpointer type_class = g_type_class_ref(item_type); g_return_if_fail(type_class != NULL); - IdoSerializableMenuItemClass * class = IDO_SERIALIZABLE_MENU_ITEM_CLASS(type_class); + DbusmenuGtkSerializableMenuItemClass * class = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_CLASS(type_class); if (class->get_type_string == NULL) { g_type_class_unref(type_class); - g_error("No 'get_type_string' in subclass of IdoSerializableMenuItem"); + g_error("No 'get_type_string' in subclass of DbusmenuGtkSerializableMenuItem"); return; } diff --git a/libdbusmenu-gtk/serializablemenuitem.h b/libdbusmenu-gtk/serializablemenuitem.h index 48fdb49..e99d329 100644 --- a/libdbusmenu-gtk/serializablemenuitem.h +++ b/libdbusmenu-gtk/serializablemenuitem.h @@ -1,5 +1,5 @@ -#ifndef __IDO_SERIALIZABLE_MENU_ITEM_H__ -#define __IDO_SERIALIZABLE_MENU_ITEM_H__ +#ifndef __DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_H__ +#define __DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_H__ #include #include @@ -9,49 +9,49 @@ G_BEGIN_DECLS -#define IDO_TYPE_SERIALIZABLE_MENU_ITEM (ido_serializable_menu_item_get_type ()) -#define IDO_SERIALIZABLE_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IDO_TYPE_SERIALIZABLE_MENU_ITEM, IdoSerializableMenuItem)) -#define IDO_SERIALIZABLE_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IDO_TYPE_SERIALIZABLE_MENU_ITEM, IdoSerializableMenuItemClass)) -#define IDO_IS_SERIALIZABLE_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IDO_TYPE_SERIALIZABLE_MENU_ITEM)) -#define IDO_IS_SERIALIZABLE_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IDO_TYPE_SERIALIZABLE_MENU_ITEM)) -#define IDO_SERIALIZABLE_MENU_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IDO_TYPE_SERIALIZABLE_MENU_ITEM, IdoSerializableMenuItemClass)) +#define DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM (dbusmenu_gtk_serializable_menu_item_get_type ()) +#define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM, DbusmenuGtkSerializableMenuItem)) +#define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM, DbusmenuGtkSerializableMenuItemClass)) +#define DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM)) +#define DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM)) +#define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM, DbusmenuGtkSerializableMenuItemClass)) -typedef struct _IdoSerializableMenuItem IdoSerializableMenuItem; -typedef struct _IdoSerializableMenuItemClass IdoSerializableMenuItemClass; -typedef struct _IdoSerializableMenuItemPrivate IdoSerializableMenuItemPrivate; +typedef struct _DbusmenuGtkSerializableMenuItem DbusmenuGtkSerializableMenuItem; +typedef struct _DbusmenuGtkSerializableMenuItemClass DbusmenuGtkSerializableMenuItemClass; +typedef struct _DbusmenuGtkSerializableMenuItemPrivate DbusmenuGtkSerializableMenuItemPrivate; -struct _IdoSerializableMenuItemClass { +struct _DbusmenuGtkSerializableMenuItemClass { GtkMenuItemClass parent_class; /* Subclassable functions */ const gchar * (*get_type_string) (void); GHashTable * (*get_default_properties) (void); - DbusmenuMenuitem * (*get_dbusmenu_menuitem) (IdoSerializableMenuItem * smi); + DbusmenuMenuitem * (*get_dbusmenu_menuitem) (DbusmenuGtkSerializableMenuItem * smi); /* Signals */ /* Empty Space */ - void (*_ido_serializable_menu_item_reserved1) (void); - void (*_ido_serializable_menu_item_reserved2) (void); - void (*_ido_serializable_menu_item_reserved3) (void); - void (*_ido_serializable_menu_item_reserved4) (void); - void (*_ido_serializable_menu_item_reserved5) (void); - void (*_ido_serializable_menu_item_reserved6) (void); + void (*_dbusmenu_gtk_serializable_menu_item_reserved1) (void); + void (*_dbusmenu_gtk_serializable_menu_item_reserved2) (void); + void (*_dbusmenu_gtk_serializable_menu_item_reserved3) (void); + void (*_dbusmenu_gtk_serializable_menu_item_reserved4) (void); + void (*_dbusmenu_gtk_serializable_menu_item_reserved5) (void); + void (*_dbusmenu_gtk_serializable_menu_item_reserved6) (void); }; -struct _IdoSerializableMenuItem { +struct _DbusmenuGtkSerializableMenuItem { GtkMenuItem parent; - IdoSerializableMenuItemPrivate * priv; + DbusmenuGtkSerializableMenuItemPrivate * priv; }; -GType ido_serializable_menu_item_get_type (void); +GType dbusmenu_gtk_serializable_menu_item_get_type (void); -DbusmenuMenuitem * ido_serializable_menu_item_get_dbusmenu_menuitem (IdoSerializableMenuItem * smi); -void ido_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type); +DbusmenuMenuitem * dbusmenu_gtk_serializable_menu_item_get_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi); +void dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type); G_END_DECLS -- cgit v1.2.3 From 6ec53854067f149492c18d35d680c2dad01d0a41 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 Jan 2011 16:45:44 -0600 Subject: Setting up the type handler, need more API --- libdbusmenu-gtk/serializablemenuitem.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index c9eb416..4d23635 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -73,6 +73,14 @@ dbusmenu_gtk_serializable_menu_item_get_dbusmenu_menuitem (DbusmenuGtkSerializab return NULL; } +/* Handle the type with this item. */ +static gboolean +type_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) +{ + + return TRUE; +} + void dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type) { @@ -90,10 +98,10 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, } /* Register type */ - + dbusmenu_client_add_type_handler(client, class->get_type_string(), type_handler); /* need type */ /* Register defaults */ - + /* TODO: Need API on another branch */ return; } -- cgit v1.2.3 From 3d8ec9ae0b07cbe287aaeda633621ac8c81b5925 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 Jan 2011 16:59:57 -0600 Subject: Fixing callback prototypes --- libdbusmenu-gtk/client.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index b01156f..af7768a 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -54,8 +54,8 @@ static void delete_child (DbusmenuMenuitem * mi, DbusmenuMenuitem * child, Dbusm static void move_child (DbusmenuMenuitem * mi, DbusmenuMenuitem * child, guint new, guint old, DbusmenuGtkClient * gtkclient); static void item_activate (DbusmenuClient * client, DbusmenuMenuitem * mi, guint timestamp, gpointer userdata); -static gboolean new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); -static gboolean new_item_seperator (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); +static gboolean new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data); +static gboolean new_item_seperator (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data); static void process_visible (DbusmenuMenuitem * mi, GtkMenuItem * gmi, GVariant * value); static void process_sensitive (DbusmenuMenuitem * mi, GtkMenuItem * gmi, GVariant * value); @@ -684,7 +684,7 @@ dbusmenu_gtkclient_menuitem_get_submenu (DbusmenuGtkClient * client, DbusmenuMen /* The base type handler that builds a plain ol' GtkMenuItem to represent, well, the GtkMenuItem */ static gboolean -new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) +new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data) { g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); @@ -719,7 +719,7 @@ new_item_normal (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusmenu /* Type handler for the seperators where it builds a GtkSeparator to act as the GtkMenuItem */ static gboolean -new_item_seperator (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) +new_item_seperator (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data) { g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); -- cgit v1.2.3 From 61fd5050b6319de6b948cdb0cd36e1b985d7b2a8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 Jan 2011 17:02:00 -0600 Subject: Setup to the use the full type handler --- libdbusmenu-glib/client.h | 2 +- libdbusmenu-gtk/serializablemenuitem.c | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-glib/client.h b/libdbusmenu-glib/client.h index 323e142..f371792 100644 --- a/libdbusmenu-glib/client.h +++ b/libdbusmenu-glib/client.h @@ -111,7 +111,7 @@ struct _DbusmenuClient { }; typedef gboolean (*DbusmenuClientTypeHandler) (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data); -typedef gboolean (*DbusmenuClientTypeDestroyHandler) (DbusmenuClient * client, const gchar * type, gpointer user_data); +typedef void (*DbusmenuClientTypeDestroyHandler) (DbusmenuClient * client, const gchar * type, gpointer user_data); GType dbusmenu_client_get_type (void); DbusmenuClient * dbusmenu_client_new (const gchar * name, diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 4d23635..42d79b2 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -75,12 +75,20 @@ dbusmenu_gtk_serializable_menu_item_get_dbusmenu_menuitem (DbusmenuGtkSerializab /* Handle the type with this item. */ static gboolean -type_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) +type_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data) { return TRUE; } +/* Destruction is inevitable */ +static void +type_destroy_handler (DbusmenuClient * client, const gchar * type, gpointer user_data) +{ + + return; +} + void dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type) { @@ -98,7 +106,7 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, } /* Register type */ - dbusmenu_client_add_type_handler(client, class->get_type_string(), type_handler); /* need type */ + dbusmenu_client_add_type_handler_full(client, class->get_type_string(), type_handler, NULL, type_destroy_handler); /* need type */ /* Register defaults */ /* TODO: Need API on another branch */ -- cgit v1.2.3 From 5d6f408aad06b27f8d29b52df9bd8d76155eabe4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 Jan 2011 17:05:31 -0600 Subject: Build a type handler structure to handle the class struct --- libdbusmenu-gtk/serializablemenuitem.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 42d79b2..16b3910 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -73,6 +73,12 @@ dbusmenu_gtk_serializable_menu_item_get_dbusmenu_menuitem (DbusmenuGtkSerializab return NULL; } +typedef struct _type_handler_t type_handler_t; +struct _type_handler_t { + DbusmenuGtkSerializableMenuItemClass * class; + GType type; +}; + /* Handle the type with this item. */ static gboolean type_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data) @@ -85,7 +91,10 @@ type_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuCli static void type_destroy_handler (DbusmenuClient * client, const gchar * type, gpointer user_data) { - + g_return_if_fail(user_data != NULL); + type_handler_t * th = (type_handler_t *)user_data; + g_type_class_unref(th->class); + g_free(user_data); return; } @@ -106,7 +115,10 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, } /* Register type */ - dbusmenu_client_add_type_handler_full(client, class->get_type_string(), type_handler, NULL, type_destroy_handler); /* need type */ + type_handler_t * th = g_new0(type_handler_t, 1); + th->class = class; + th->type = item_type; + dbusmenu_client_add_type_handler_full(client, class->get_type_string(), type_handler, th, type_destroy_handler); /* need type */ /* Register defaults */ /* TODO: Need API on another branch */ -- cgit v1.2.3 From 43b377b84c868f652e8ea0db989b985cf20a3304 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 18 Jan 2011 17:06:28 -0600 Subject: Clean up on failure --- libdbusmenu-gtk/serializablemenuitem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 16b3910..1d4703f 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -118,7 +118,9 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, type_handler_t * th = g_new0(type_handler_t, 1); th->class = class; th->type = item_type; - dbusmenu_client_add_type_handler_full(client, class->get_type_string(), type_handler, th, type_destroy_handler); /* need type */ + if (!dbusmenu_client_add_type_handler_full(client, class->get_type_string(), type_handler, th, type_destroy_handler)) { + type_destroy_handler(client, class->get_type_string(), th); + } /* Register defaults */ /* TODO: Need API on another branch */ -- cgit v1.2.3 From 4d6b2a232814fc61e7652199a142d5af39c4f78f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Jan 2011 10:52:33 -0600 Subject: License headers --- libdbusmenu-gtk/serializablemenuitem.c | 28 ++++++++++++++++++++++++++++ libdbusmenu-gtk/serializablemenuitem.h | 28 ++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 1d4703f..e8ad22b 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -1,3 +1,31 @@ +/* +An object to act as a base class for easy GTK widgets that can be +transfered over dbusmenu. + +Copyright 2011 Canonical Ltd. + +Authors: + Ted Gould + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the +Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by +the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see + +*/ + #ifdef HAVE_CONFIG_H #include "config.h" #endif diff --git a/libdbusmenu-gtk/serializablemenuitem.h b/libdbusmenu-gtk/serializablemenuitem.h index e99d329..bb67192 100644 --- a/libdbusmenu-gtk/serializablemenuitem.h +++ b/libdbusmenu-gtk/serializablemenuitem.h @@ -1,3 +1,31 @@ +/* +An object to act as a base class for easy GTK widgets that can be +transfered over dbusmenu. + +Copyright 2011 Canonical Ltd. + +Authors: + Ted Gould + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the +Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by +the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see + +*/ + #ifndef __DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_H__ #define __DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_H__ -- cgit v1.2.3 From c0990d9fa4889042ae255ed1358c0686d5dec241 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Jan 2011 16:50:34 -0600 Subject: Filling out the type handler --- libdbusmenu-gtk/serializablemenuitem.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index e8ad22b..de7bb04 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -30,6 +30,7 @@ License version 3 and version 2.1 along with this program. If not, see #include "config.h" #endif +#include "client.h" #include "serializablemenuitem.h" struct _DbusmenuGtkSerializableMenuItemPrivate { @@ -111,6 +112,13 @@ struct _type_handler_t { static gboolean type_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client, gpointer user_data) { + type_handler_t * th = (type_handler_t *)user_data; + + DbusmenuGtkSerializableMenuItem * smi = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM(g_object_new(th->type, NULL)); + g_return_val_if_fail(smi != NULL, FALSE); + + dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem(smi, newitem); + dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, GTK_MENU_ITEM(smi), parent); return TRUE; } -- cgit v1.2.3 From 5dc7f70d50ba5cf9cdc86693e7b759f567fb862c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 19 Jan 2011 17:00:50 -0600 Subject: Adding a function to tell the menu item about where it's properties are coming from. --- libdbusmenu-gtk/serializablemenuitem.c | 7 +++++++ libdbusmenu-gtk/serializablemenuitem.h | 1 + 2 files changed, 8 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index de7bb04..74e0bec 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -163,3 +163,10 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, return; } + +void +dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi, DbusmenuMenuitem * mi) +{ + + return; +} diff --git a/libdbusmenu-gtk/serializablemenuitem.h b/libdbusmenu-gtk/serializablemenuitem.h index bb67192..487b08b 100644 --- a/libdbusmenu-gtk/serializablemenuitem.h +++ b/libdbusmenu-gtk/serializablemenuitem.h @@ -80,6 +80,7 @@ GType dbusmenu_gtk_serializable_menu_item_get_type (void); DbusmenuMenuitem * dbusmenu_gtk_serializable_menu_item_get_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi); void dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type); +void dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi, DbusmenuMenuitem * mi); G_END_DECLS -- cgit v1.2.3 From 58677931dde065b11f7010ad1443c6d4d1b20d7d Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Wed, 19 Jan 2011 22:50:25 -0500 Subject: added --warn-all to scanner flags so the build log will warn us about missing annotations --- libdbusmenu-glib/Makefile.am | 2 ++ libdbusmenu-gtk/Makefile.am | 2 ++ 2 files changed, 4 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-glib/Makefile.am b/libdbusmenu-glib/Makefile.am index f502fb3..8ab36f7 100644 --- a/libdbusmenu-glib/Makefile.am +++ b/libdbusmenu-glib/Makefile.am @@ -119,12 +119,14 @@ INTROSPECTION_GIRS = if INTROSPECTION_TEN INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) \ + --warn-all \ --add-include-path=$(srcdir) \ $(addprefix --c-include=libdbusmenu-glib/, $(introspection_sources)) \ --symbol-prefix=dbusmenu \ --identifier-prefix=Dbusmenu else INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) \ + --warn-all \ --add-include-path=$(srcdir) \ $(addprefix --c-include=libdbusmenu-glib/, $(introspection_sources)) endif diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index 0b939c0..b8e1170 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -69,12 +69,14 @@ INTROSPECTION_GIRS = if INTROSPECTION_TEN INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) \ + --warn-all \ --add-include-path=$(top_builddir)/libdbusmenu-glib \ $(addprefix --c-include=libdbusmenu-gtk/, $(introspection_sources)) \ --symbol-prefix=dbusmenu \ --identifier-prefix=DbusmenuGtk else INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) \ + --warn-all \ --add-include-path=$(top_builddir)/libdbusmenu-glib \ $(addprefix --c-include=libdbusmenu-gtk/, $(introspection_sources)) endif -- cgit v1.2.3 From abe1a8b281bf08217367666fbac41eb812708d33 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Jan 2011 19:56:14 -0600 Subject: Switching the name to build so that we realize what's going on there. --- libdbusmenu-gtk/serializablemenuitem.c | 6 +++--- libdbusmenu-gtk/serializablemenuitem.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 74e0bec..32be773 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -90,13 +90,13 @@ dbusmenu_gtk_serializable_menu_item_finalize (GObject *object) } DbusmenuMenuitem * -dbusmenu_gtk_serializable_menu_item_get_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi) +dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi) { g_return_val_if_fail(DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM(smi), NULL); DbusmenuGtkSerializableMenuItemClass * klass = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_CLASS(smi); - if (klass->get_dbusmenu_menuitem != NULL) { - return klass->get_dbusmenu_menuitem(smi); + if (klass->build_dbusmenu_menuitem != NULL) { + return klass->build_dbusmenu_menuitem(smi); } return NULL; diff --git a/libdbusmenu-gtk/serializablemenuitem.h b/libdbusmenu-gtk/serializablemenuitem.h index 487b08b..30e1157 100644 --- a/libdbusmenu-gtk/serializablemenuitem.h +++ b/libdbusmenu-gtk/serializablemenuitem.h @@ -55,7 +55,7 @@ struct _DbusmenuGtkSerializableMenuItemClass { const gchar * (*get_type_string) (void); GHashTable * (*get_default_properties) (void); - DbusmenuMenuitem * (*get_dbusmenu_menuitem) (DbusmenuGtkSerializableMenuItem * smi); + DbusmenuMenuitem * (*build_dbusmenu_menuitem) (DbusmenuGtkSerializableMenuItem * smi); /* Signals */ @@ -78,7 +78,7 @@ struct _DbusmenuGtkSerializableMenuItem { GType dbusmenu_gtk_serializable_menu_item_get_type (void); -DbusmenuMenuitem * dbusmenu_gtk_serializable_menu_item_get_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi); +DbusmenuMenuitem * dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi); void dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type); void dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi, DbusmenuMenuitem * mi); -- cgit v1.2.3 From aea42d14c645517cc32611ab0e8580223948aad3 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 20 Jan 2011 20:09:39 -0600 Subject: Installing a property for the menuitem in the super-class --- libdbusmenu-gtk/serializablemenuitem.c | 23 +++++++++++++++++++++-- libdbusmenu-gtk/serializablemenuitem.h | 2 ++ 2 files changed, 23 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 32be773..5089af0 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -34,7 +34,13 @@ License version 3 and version 2.1 along with this program. If not, see #include "serializablemenuitem.h" struct _DbusmenuGtkSerializableMenuItemPrivate { - int dummy; + DbusmenuMenuitem * mi; +}; + +/* Properties */ +enum { + PROP_0, + PROP_MENUITEM }; #define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(o) \ @@ -57,6 +63,12 @@ dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializableMenuItemC object_class->dispose = dbusmenu_gtk_serializable_menu_item_dispose; object_class->finalize = dbusmenu_gtk_serializable_menu_item_finalize; + g_object_class_install_property (object_class, PROP_MENUITEM, + g_param_spec_object(DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_PROP_MENUITEM, "DBusmenu Menuitem attached to item", + "A menuitem who's properties are being watched and where changes should be watched for updates. It is the responsibility of subclasses to set up the signal handlers for those property changes.", + DBUSMENU_TYPE_MENUITEM, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + return; } @@ -65,7 +77,7 @@ dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self) { self->priv = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(self); - self->priv->dummy = 5; + self->priv->mi = NULL; return; } @@ -73,6 +85,13 @@ dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self) static void dbusmenu_gtk_serializable_menu_item_dispose (GObject *object) { + DbusmenuGtkSerializableMenuItem * smi = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM(object); + g_return_if_fail(smi != NULL); + + if (smi->priv->mi != NULL) { + g_object_unref(G_OBJECT(smi->priv->mi)); + smi->priv->mi = NULL; + } G_OBJECT_CLASS (dbusmenu_gtk_serializable_menu_item_parent_class)->dispose (object); diff --git a/libdbusmenu-gtk/serializablemenuitem.h b/libdbusmenu-gtk/serializablemenuitem.h index 30e1157..0dc92e0 100644 --- a/libdbusmenu-gtk/serializablemenuitem.h +++ b/libdbusmenu-gtk/serializablemenuitem.h @@ -44,6 +44,8 @@ G_BEGIN_DECLS #define DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM)) #define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM, DbusmenuGtkSerializableMenuItemClass)) +#define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_PROP_MENUITEM "dbusmenu-menuitem" + typedef struct _DbusmenuGtkSerializableMenuItem DbusmenuGtkSerializableMenuItem; typedef struct _DbusmenuGtkSerializableMenuItemClass DbusmenuGtkSerializableMenuItemClass; typedef struct _DbusmenuGtkSerializableMenuItemPrivate DbusmenuGtkSerializableMenuItemPrivate; -- cgit v1.2.3 From 1a4efa01c312cf8c54d7d158385b5208f1cdb841 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Jan 2011 10:35:55 -0600 Subject: Add a single include for dbusmenu-gtk --- libdbusmenu-gtk/Makefile.am | 1 + libdbusmenu-gtk/dbusmenu-gtk.h | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 libdbusmenu-gtk/dbusmenu-gtk.h (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index b8e1170..e5df6b1 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -20,6 +20,7 @@ EXTRA_DIST = \ libdbusmenu_gtkincludedir=$(includedir)/libdbusmenu-0.4/libdbusmenu-gtk$(VER)/ libdbusmenu_gtkinclude_HEADERS = \ + dbusmenu-gtk.h \ client.h \ menu.h \ menuitem.h diff --git a/libdbusmenu-gtk/dbusmenu-gtk.h b/libdbusmenu-gtk/dbusmenu-gtk.h new file mode 100644 index 0000000..de63c61 --- /dev/null +++ b/libdbusmenu-gtk/dbusmenu-gtk.h @@ -0,0 +1,40 @@ +/* +A library to communicate a menu object set accross DBus and +track updates and maintain consistency. + +Copyright 2011 Canonical Ltd. + +Authors: + Ted Gould + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the +Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by +the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see + +*/ + +#ifndef __DBUSMENU_GTK_H__ +#define __DBUSMENU_GTK_H__ + +/* Start with the glib stuff */ +#include + +/* Now get the GTK stuff */ +#include +#include +#include + +#endif /* __DBUSMENU_GLIB_H__ */ -- cgit v1.2.3 From 0ea5e726b97d9080b4300d007f002da247dbf0b2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Jan 2011 11:59:06 -0600 Subject: Add serializable menuitem to the single include --- libdbusmenu-gtk/dbusmenu-gtk.h | 1 + 1 file changed, 1 insertion(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/dbusmenu-gtk.h b/libdbusmenu-gtk/dbusmenu-gtk.h index de63c61..f2fe5be 100644 --- a/libdbusmenu-gtk/dbusmenu-gtk.h +++ b/libdbusmenu-gtk/dbusmenu-gtk.h @@ -36,5 +36,6 @@ License version 3 and version 2.1 along with this program. If not, see #include #include #include +#include #endif /* __DBUSMENU_GLIB_H__ */ -- cgit v1.2.3 From ffce14168e30c5b34d24ee7ee5199a61bb4a30f3 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Jan 2011 12:02:57 -0600 Subject: Add some documentation of the class and object structures. --- libdbusmenu-gtk/serializablemenuitem.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.h b/libdbusmenu-gtk/serializablemenuitem.h index 0dc92e0..aae2f96 100644 --- a/libdbusmenu-gtk/serializablemenuitem.h +++ b/libdbusmenu-gtk/serializablemenuitem.h @@ -50,6 +50,19 @@ typedef struct _DbusmenuGtkSerializableMenuItem DbusmenuGtkSerializableMe typedef struct _DbusmenuGtkSerializableMenuItemClass DbusmenuGtkSerializableMenuItemClass; typedef struct _DbusmenuGtkSerializableMenuItemPrivate DbusmenuGtkSerializableMenuItemPrivate; +/** + DbusmenuGtkSerializableMenuItemClass: + @parent_class: Inherit from GtkMenuItem + @get_type_string: Static function to get a string describing this type + @get_default_properties: Return a hashtable of defaults for the menu item type + @build_dbusmenu_menuitem: Build a menuitem that can be sent over dbus + @_dbusmenu_gtk_serializable_menu_item_reserved1: Reserved for future use. + @_dbusmenu_gtk_serializable_menu_item_reserved2: Reserved for future use. + @_dbusmenu_gtk_serializable_menu_item_reserved3: Reserved for future use. + @_dbusmenu_gtk_serializable_menu_item_reserved4: Reserved for future use. + @_dbusmenu_gtk_serializable_menu_item_reserved5: Reserved for future use. + @_dbusmenu_gtk_serializable_menu_item_reserved6: Reserved for future use. +*/ struct _DbusmenuGtkSerializableMenuItemClass { GtkMenuItemClass parent_class; @@ -64,6 +77,7 @@ struct _DbusmenuGtkSerializableMenuItemClass { /* Empty Space */ + /*< Private >*/ void (*_dbusmenu_gtk_serializable_menu_item_reserved1) (void); void (*_dbusmenu_gtk_serializable_menu_item_reserved2) (void); void (*_dbusmenu_gtk_serializable_menu_item_reserved3) (void); @@ -72,6 +86,11 @@ struct _DbusmenuGtkSerializableMenuItemClass { void (*_dbusmenu_gtk_serializable_menu_item_reserved6) (void); }; +/** + DbusmenuGtkSerializableMenuItem: + @parent: Inherit from GtkMenuItem + @priv: Blind structure of private variables +*/ struct _DbusmenuGtkSerializableMenuItem { GtkMenuItem parent; -- cgit v1.2.3 From efd5c63d09eed1230bb0bb822f3040f55d30638d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Jan 2011 16:01:20 -0600 Subject: More documentation --- libdbusmenu-gtk/serializablemenuitem.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 5089af0..01b20b2 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -33,6 +33,10 @@ License version 3 and version 2.1 along with this program. If not, see #include "client.h" #include "serializablemenuitem.h" +/** + DbusmenuGtkSerializableMenuItemPrivate: + @mi: Menuitem to watch the property changes from +*/ struct _DbusmenuGtkSerializableMenuItemPrivate { DbusmenuMenuitem * mi; }; @@ -43,16 +47,20 @@ enum { PROP_MENUITEM }; +/* Private macro, only used in object init */ #define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), DBUSMENU_TYPE_GTK_SERIALIZABLE_MENU_ITEM, DbusmenuGtkSerializableMenuItemPrivate)) +/* Function prototypes */ static void dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializableMenuItemClass *klass); static void dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self); static void dbusmenu_gtk_serializable_menu_item_dispose (GObject *object); static void dbusmenu_gtk_serializable_menu_item_finalize (GObject *object); +/* GObject boiler plate */ G_DEFINE_TYPE (DbusmenuGtkSerializableMenuItem, dbusmenu_gtk_serializable_menu_item, GTK_TYPE_MENU_ITEM); +/* Initialize the stuff in the class structure */ static void dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializableMenuItemClass *klass) { @@ -72,6 +80,7 @@ dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializableMenuItemC return; } +/* Initialize the object structures and private structure */ static void dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self) { @@ -82,6 +91,7 @@ dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self) return; } +/* Free all references to objects */ static void dbusmenu_gtk_serializable_menu_item_dispose (GObject *object) { @@ -98,6 +108,7 @@ dbusmenu_gtk_serializable_menu_item_dispose (GObject *object) return; } +/* Free memory */ static void dbusmenu_gtk_serializable_menu_item_finalize (GObject *object) { @@ -121,6 +132,7 @@ dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem (DbusmenuGtkSerializ return NULL; } +/* Callback to the generic type handler */ typedef struct _type_handler_t type_handler_t; struct _type_handler_t { DbusmenuGtkSerializableMenuItemClass * class; -- cgit v1.2.3 From 91544bb4a5ae2bc6eea3e930da6c7ebbb32216d0 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Jan 2011 16:37:44 -0600 Subject: gtk-doc documentation for public API functions --- libdbusmenu-gtk/serializablemenuitem.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 01b20b2..06dfa59 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -119,6 +119,19 @@ dbusmenu_gtk_serializable_menu_item_finalize (GObject *object) return; } +/** + dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem: + @smi: #DbusmenuGtkSerializableMenuItem to build a #DbusmenuMenuitem mirroring + + This function is for menu items that are instanciated from + GTK and have their properites set using GTK functions. This + builds a #DbusmenuMenuitem that then has the properties that + should be sent over the bus to create a new item of this + type on the other side. + + Return value: A #DbusmenuMenuitem who's values will be set by + this object. +*/ DbusmenuMenuitem * dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi) { @@ -165,6 +178,16 @@ type_destroy_handler (DbusmenuClient * client, const gchar * type, gpointer user return; } +/** + dbusmenu_gtk_serializable_menu_item_register_to_client: + @client: #DbusmenuClient that we should register a type at. + @item_type: The #GType of a class that is a subclass of #DbusmenuGtkSerializableMenuItem + + Registers a generic handler for dealing with all subclasses of + #DbusmenuGtkSerializableMenuItem. This handler responds to the callback, + creates a new object and attaches it to the appropriate #DbusmenuMenuitem + object. +*/ void dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type) { @@ -195,6 +218,17 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, return; } +/** + dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem: + @smi: #DbusmenuGtkSerializableMenuItem to set the @DbusmenuGtkSerializableMenuItem::dbusmenu-menuitem of + @mi: Menuitem to get the properties from + + This function is used on the server side to signal to the object + that it should get its' property change events from @mi instead + of expecting calls to its' API. A call to this function sets the + property and subclasses should listen to the notify signal to + pick up this property being set. +*/ void dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi, DbusmenuMenuitem * mi) { -- cgit v1.2.3 From 97083dc0b396d91c68fe9f439024cc048333e87b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Jan 2011 16:43:44 -0600 Subject: Adding in set and get property functions. --- libdbusmenu-gtk/serializablemenuitem.c | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 06dfa59..99bc585 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -56,6 +56,14 @@ static void dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializa static void dbusmenu_gtk_serializable_menu_item_init (DbusmenuGtkSerializableMenuItem *self); static void dbusmenu_gtk_serializable_menu_item_dispose (GObject *object); static void dbusmenu_gtk_serializable_menu_item_finalize (GObject *object); +static void set_property (GObject * obj, + guint id, + const GValue * value, + GParamSpec * pspec); +static void get_property (GObject * obj, + guint id, + GValue * value, + GParamSpec * pspec); /* GObject boiler plate */ G_DEFINE_TYPE (DbusmenuGtkSerializableMenuItem, dbusmenu_gtk_serializable_menu_item, GTK_TYPE_MENU_ITEM); @@ -70,6 +78,8 @@ dbusmenu_gtk_serializable_menu_item_class_init (DbusmenuGtkSerializableMenuItemC object_class->dispose = dbusmenu_gtk_serializable_menu_item_dispose; object_class->finalize = dbusmenu_gtk_serializable_menu_item_finalize; + object_class->set_property = set_property; + object_class->get_property = get_property; g_object_class_install_property (object_class, PROP_MENUITEM, g_param_spec_object(DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_PROP_MENUITEM, "DBusmenu Menuitem attached to item", @@ -119,6 +129,42 @@ dbusmenu_gtk_serializable_menu_item_finalize (GObject *object) return; } +/* Set an object property */ +static void +set_property (GObject * obj, guint id, const GValue * value, GParamSpec * pspec) +{ + DbusmenuGtkSerializableMenuItem * smi = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM(obj); + + switch (id) { + case PROP_MENUITEM: + smi->priv->mi = g_value_get_object(value); + break; + default: + g_return_if_reached(); + break; + } + + return; +} + +/* Get an object property */ +static void +get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) +{ + DbusmenuGtkSerializableMenuItem * smi = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM(obj); + + switch (id) { + case PROP_MENUITEM: + g_value_set_object(value, smi->priv->mi); + break; + default: + g_return_if_reached(); + break; + } + + return; +} + /** dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem: @smi: #DbusmenuGtkSerializableMenuItem to build a #DbusmenuMenuitem mirroring -- cgit v1.2.3 From 555f085168fac50cf55c910c746363f8ce268823 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Jan 2011 16:46:27 -0600 Subject: Fleshing out setting the property --- libdbusmenu-gtk/serializablemenuitem.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 99bc585..6bc3695 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -278,6 +278,11 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, void dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi, DbusmenuMenuitem * mi) { + g_return_if_fail(DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM(smi)); + g_return_if_fail(mi != NULL); + + smi->priv->mi = mi; + g_object_notify(G_OBJECT(smi), DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_PROP_MENUITEM); return; } -- cgit v1.2.3 From 539290124d737754b20dd69e6d3033175ca37e12 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Jan 2011 16:48:41 -0600 Subject: Ensuring our double include protectors make g-ir-scanner happy. --- libdbusmenu-gtk/menuitem.h | 4 ++-- libdbusmenu-gtk/serializablemenuitem.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.h b/libdbusmenu-gtk/menuitem.h index a2b6652..4fc42f9 100644 --- a/libdbusmenu-gtk/menuitem.h +++ b/libdbusmenu-gtk/menuitem.h @@ -26,8 +26,8 @@ License version 3 and version 2.1 along with this program. If not, see */ -#ifndef __DBUSMENU_GTKMENUITEM_H__ -#define __DBUSMENU_GTKMENUITEM_H__ 1 +#ifndef DBUSMENU_GTK_MENUITEM_H__ +#define DBUSMENU_GTK_MENUITEM_H__ 1 #include #include diff --git a/libdbusmenu-gtk/serializablemenuitem.h b/libdbusmenu-gtk/serializablemenuitem.h index aae2f96..1ca3ef8 100644 --- a/libdbusmenu-gtk/serializablemenuitem.h +++ b/libdbusmenu-gtk/serializablemenuitem.h @@ -26,8 +26,8 @@ License version 3 and version 2.1 along with this program. If not, see */ -#ifndef __DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_H__ -#define __DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_H__ +#ifndef DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_H__ +#define DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM_H__ 1 #include #include -- cgit v1.2.3 From edef8613dd3e78e5d11a2754e6175dd8e55ff87e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 21 Jan 2011 16:59:35 -0600 Subject: Adding a transfer annotation --- libdbusmenu-gtk/serializablemenuitem.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index 6bc3695..f67434e 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -175,8 +175,8 @@ get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) should be sent over the bus to create a new item of this type on the other side. - Return value: A #DbusmenuMenuitem who's values will be set by - this object. + Return value: (transfer full) A #DbusmenuMenuitem who's values will be + set by this object. */ DbusmenuMenuitem * dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi) -- cgit v1.2.3 From c644e10c9da09e443a00422df00a6ba9df7a7e83 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 23 Jan 2011 12:45:05 -0600 Subject: Adding the base files for the parser --- .bzrignore | 1 + libdbusmenu-gtk/Makefile.am | 7 +++++-- libdbusmenu-gtk/parser.c | 9 +++++++++ libdbusmenu-gtk/parser.h | 6 ++++++ 4 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 libdbusmenu-gtk/parser.c create mode 100644 libdbusmenu-gtk/parser.h (limited to 'libdbusmenu-gtk') diff --git a/.bzrignore b/.bzrignore index 44c6edb..e0fd93e 100644 --- a/.bzrignore +++ b/.bzrignore @@ -220,3 +220,4 @@ libdbusmenu-gtk/DbusmenuGtk-0.4.typelib libdbusmenu-gtk/DbusmenuGtk-0.4.vapi libdbusmenu-gtk/dbusmenu-gtk-0.4.pc libdbusmenu-gtk/dbusmenu-gtk3-0.4.pc +libdbusmenu-gtk/libdbusmenu_gtk_la-parser.lo diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index e5df6b1..201a631 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -23,7 +23,8 @@ libdbusmenu_gtkinclude_HEADERS = \ dbusmenu-gtk.h \ client.h \ menu.h \ - menuitem.h + menuitem.h \ + parser.h libdbusmenu_gtk_la_SOURCES = \ client.h \ @@ -33,7 +34,9 @@ libdbusmenu_gtk_la_SOURCES = \ menu.h \ menu.c \ menuitem.h \ - menuitem.c + menuitem.c \ + parser.h \ + parser.c libdbusmenu_gtk_la_LDFLAGS = \ -version-info $(LIBDBUSMENU_CURRENT):$(LIBDBUSMENU_REVISION):$(LIBDBUSMENU_AGE) \ diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c new file mode 100644 index 0000000..98b3f7d --- /dev/null +++ b/libdbusmenu-gtk/parser.c @@ -0,0 +1,9 @@ + +#include "parser.h" + +DbusmenuMenuitem * +dbusmenu_gtk_parse_menu_structure (GtkMenuItem * mi) +{ + + return NULL; +} diff --git a/libdbusmenu-gtk/parser.h b/libdbusmenu-gtk/parser.h new file mode 100644 index 0000000..222d9f4 --- /dev/null +++ b/libdbusmenu-gtk/parser.h @@ -0,0 +1,6 @@ + +#include +#include + +DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkMenuItem * mi); + -- cgit v1.2.3 From b39a625defde44aa345253237d4f186abedf7196 Mon Sep 17 00:00:00 2001 From: Cody Russell Date: Sun, 23 Jan 2011 13:05:28 -0600 Subject: Taking the menu parsing code from appmenu-gtk --- libdbusmenu-gtk/parser.c | 426 ++++++++++++++++++++++++++++++++++++++++++++++- libdbusmenu-gtk/parser.h | 2 +- 2 files changed, 426 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 98b3f7d..8fd0d12 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -1,9 +1,433 @@ #include "parser.h" +#include "menuitem.h" + +static void accel_changed (GtkWidget *widget, gpointer data); +static gboolean update_stock_item (DbusmenuMenuitem *menuitem, GtkWidget *widget); +static void checkbox_toggled (GtkWidget *widget, DbusmenuMenuitem *mi); +static void update_icon_name (DbusmenuMenuitem *menuitem, GtkWidget *widget); +static GtkWidget * find_menu_label (GtkWidget *widget); +static void label_notify_cb (GtkWidget *widget, GParamSpec *pspec, gpointer data); +static void action_notify_cb (GtkAction *action, GParamSpec *pspec, gpointer data); +static void item_activated (DbusmenuMenuitem *item, guint timestamp, gpointer user_data); +static gboolean item_about_to_show (DbusmenuMenuitem *item, gpointer user_data); +static void widget_notify_cb (GtkWidget *widget, GParamSpec *pspec, gpointer data); +static gboolean should_show_image (GtkImage *image); DbusmenuMenuitem * -dbusmenu_gtk_parse_menu_structure (GtkMenuItem * mi) +dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) { + DbusmenuMenuitem *mi = dbusmenu_menuitem_new (); + + if (GTK_IS_MENU_ITEM (widget)) + { + gboolean visible = FALSE; + gboolean sensitive = FALSE; + if (GTK_IS_SEPARATOR_MENU_ITEM (widget)) + { + dbusmenu_menuitem_property_set (mi, + "type", + "separator"); + + visible = gtk_widget_get_visible (widget); + sensitive = gtk_widget_get_sensitive (widget); + } + else + { + gboolean label_set = FALSE; + + g_signal_connect (widget, + "accel-closures-changed", + G_CALLBACK (accel_changed), + mi); + + if (GTK_IS_CHECK_MENU_ITEM (widget)) + { + dbusmenu_menuitem_property_set (mi, + DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, + gtk_check_menu_item_get_draw_as_radio (GTK_CHECK_MENU_ITEM (widget)) ? DBUSMENU_MENUITEM_TOGGLE_RADIO : DBUSMENU_MENUITEM_TOGGLE_CHECK); + + dbusmenu_menuitem_property_set_int (mi, + DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, + gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (widget)) ? DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED : DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED); + + g_signal_connect (widget, + "activate", + G_CALLBACK (checkbox_toggled), + mi); + } + + if (GTK_IS_IMAGE_MENU_ITEM (widget)) + { + GtkWidget *image; + GtkImageType image_type; + + image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (widget)); + + if (GTK_IS_IMAGE (image)) + { + image_type = gtk_image_get_storage_type (GTK_IMAGE (image)); + + if (image_type == GTK_IMAGE_STOCK) + { + label_set = update_stock_item (mi, image); + } + else if (image_type == GTK_IMAGE_ICON_NAME) + { + update_icon_name (mi, image); + } + else if (image_type == GTK_IMAGE_PIXBUF) + { + dbusmenu_menuitem_property_set_image (mi, + DBUSMENU_MENUITEM_PROP_ICON_DATA, + gtk_image_get_pixbuf (GTK_IMAGE (image))); + } + } + } + + GtkWidget *label = find_menu_label (widget); + + dbusmenu_menuitem_property_set (mi, + "label", + label ? gtk_label_get_text (GTK_LABEL (label)) : NULL); + + if (label) + { + // Sometimes, an app will directly find and modify the label + // (like empathy), so watch the label especially for that. + g_signal_connect (G_OBJECT (label), + "notify", + G_CALLBACK (label_notify_cb), + mi); + } + + if (GTK_IS_ACTIVATABLE (widget)) + { + GtkActivatable *activatable = GTK_ACTIVATABLE (widget); + + if (gtk_activatable_get_use_action_appearance (activatable)) + { + GtkAction *action = gtk_activatable_get_related_action (activatable); + + if (action) + { + visible = gtk_action_is_visible (action); + sensitive = gtk_action_is_sensitive (action); + + g_signal_connect_object (action, "notify", + G_CALLBACK (action_notify_cb), + mi, + G_CONNECT_AFTER); + } + } + } + + if (!g_object_get_data (G_OBJECT (widget), "gtk-empty-menu-item") && !GTK_IS_TEAROFF_MENU_ITEM (widget)) + { + visible = gtk_widget_get_visible (widget); + sensitive = gtk_widget_get_sensitive (widget); + } + + dbusmenu_menuitem_property_set_shortcut_menuitem (mi, GTK_MENU_ITEM (widget)); + + g_signal_connect (G_OBJECT (mi), + DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, + G_CALLBACK (item_activated), + widget); + + g_signal_connect (G_OBJECT (mi), + DBUSMENU_MENUITEM_SIGNAL_ABOUT_TO_SHOW, + G_CALLBACK (item_about_to_show), + widget); + } + + dbusmenu_menuitem_property_set_bool (mi, + DBUSMENU_MENUITEM_PROP_VISIBLE, + visible); + + dbusmenu_menuitem_property_set_bool (mi, + DBUSMENU_MENUITEM_PROP_ENABLED, + sensitive); + + g_signal_connect (widget, + "notify", + G_CALLBACK (widget_notify_cb), + mi); + } + + return mi; return NULL; } + +static void +accel_changed (GtkWidget *widget, + gpointer data) +{ + DbusmenuMenuitem *mi = (DbusmenuMenuitem *)data; + dbusmenu_menuitem_property_set_shortcut_menuitem (mi, GTK_MENU_ITEM (widget)); +} + +static gboolean +update_stock_item (DbusmenuMenuitem *menuitem, + GtkWidget *widget) +{ + GtkStockItem stock; + GtkImage *image; + + g_return_val_if_fail (GTK_IS_IMAGE (widget), FALSE); + + image = GTK_IMAGE (widget); + + if (gtk_image_get_storage_type (image) != GTK_IMAGE_STOCK) + return FALSE; + + gtk_stock_lookup (image->data.stock.stock_id, &stock); + + if (should_show_image (image)) + dbusmenu_menuitem_property_set (menuitem, + DBUSMENU_MENUITEM_PROP_ICON_NAME, + image->data.stock.stock_id); + else + dbusmenu_menuitem_property_remove (menuitem, + DBUSMENU_MENUITEM_PROP_ICON_NAME); + + const gchar *label = dbusmenu_menuitem_property_get (menuitem, + DBUSMENU_MENUITEM_PROP_LABEL); + + if (stock.label != NULL && label != NULL) + { + dbusmenu_menuitem_property_set (menuitem, + DBUSMENU_MENUITEM_PROP_LABEL, + stock.label); + + return TRUE; + } + + return FALSE; +} + +static void +checkbox_toggled (GtkWidget *widget, DbusmenuMenuitem *mi) +{ + dbusmenu_menuitem_property_set_int (mi, + DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, + gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (widget)) ? DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED : DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED); +} + +static void +update_icon_name (DbusmenuMenuitem *menuitem, + GtkWidget *widget) +{ + GtkImage *image; + + g_return_if_fail (GTK_IS_IMAGE (widget)); + + image = GTK_IMAGE (widget); + + if (gtk_image_get_storage_type (image) != GTK_IMAGE_ICON_NAME) + return; + + if (should_show_image (image)) + dbusmenu_menuitem_property_set (menuitem, + DBUSMENU_MENUITEM_PROP_ICON_NAME, + image->data.name.icon_name); + else + dbusmenu_menuitem_property_remove (menuitem, + DBUSMENU_MENUITEM_PROP_ICON_NAME); +} + +static GtkWidget * +find_menu_label (GtkWidget *widget) +{ + GtkWidget *label = NULL; + + if (GTK_IS_LABEL (widget)) + return widget; + + if (GTK_IS_CONTAINER (widget)) + { + GList *children; + GList *l; + + children = gtk_container_get_children (GTK_CONTAINER (widget)); + + for (l = children; l; l = l->next) + { + label = find_menu_label (l->data); + + if (label) + break; + } + + g_list_free (children); + } + + return label; +} + +static void +label_notify_cb (GtkWidget *widget, + GParamSpec *pspec, + gpointer data) +{ + DbusmenuMenuitem *child = (DbusmenuMenuitem *)data; + + if (pspec->name == g_intern_static_string ("label")) + { + dbusmenu_menuitem_property_set (child, + DBUSMENU_MENUITEM_PROP_LABEL, + gtk_label_get_text (GTK_LABEL (widget))); + } +} + +static void +action_notify_cb (GtkAction *action, + GParamSpec *pspec, + gpointer data) +{ + DbusmenuMenuitem *mi = (DbusmenuMenuitem *)data; + + if (pspec->name == g_intern_static_string ("sensitive")) + { + dbusmenu_menuitem_property_set_bool (mi, + DBUSMENU_MENUITEM_PROP_ENABLED, + gtk_action_is_sensitive (action)); + } + else if (pspec->name == g_intern_static_string ("visible")) + { + dbusmenu_menuitem_property_set_bool (mi, + DBUSMENU_MENUITEM_PROP_VISIBLE, + gtk_action_is_visible (action)); + } + else if (pspec->name == g_intern_static_string ("active")) + { + dbusmenu_menuitem_property_set_bool (mi, + DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, + gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))); + } + else if (pspec->name == g_intern_static_string ("label")) + { + dbusmenu_menuitem_property_set (mi, + DBUSMENU_MENUITEM_PROP_LABEL, + gtk_action_get_label (action)); + } +} + +static void +item_activated (DbusmenuMenuitem *item, guint timestamp, gpointer user_data) +{ + GtkWidget *child; + + if (user_data != NULL) + { + child = (GtkWidget *)user_data; + + if (GTK_IS_MENU_ITEM (child)) + { + gtk_menu_item_activate (GTK_MENU_ITEM (child)); + } + } +} + +static gboolean +item_about_to_show (DbusmenuMenuitem *item, gpointer user_data) +{ + GtkWidget *child; + + if (user_data != NULL) + { + child = (GtkWidget *)user_data; + + if (GTK_IS_MENU_ITEM (child)) + { + // Only called for items with submens. So we activate it here in + // case the program dynamically creates menus (like empathy does) + gtk_menu_item_activate (GTK_MENU_ITEM (child)); + } + } + + return TRUE; +} + +static void +widget_notify_cb (GtkWidget *widget, + GParamSpec *pspec, + gpointer data) +{ + DbusmenuMenuitem *child = (DbusmenuMenuitem *)data; + + if (pspec->name == g_intern_static_string ("sensitive")) + { + dbusmenu_menuitem_property_set_bool (child, + DBUSMENU_MENUITEM_PROP_ENABLED, + gtk_widget_get_sensitive (widget)); + } + else if (pspec->name == g_intern_static_string ("label")) + { + dbusmenu_menuitem_property_set (child, + DBUSMENU_MENUITEM_PROP_LABEL, + gtk_menu_item_get_label (GTK_MENU_ITEM (widget))); + } + else if (pspec->name == g_intern_static_string ("visible")) + { + dbusmenu_menuitem_property_set_bool (child, + DBUSMENU_MENUITEM_PROP_VISIBLE, + gtk_widget_get_visible (widget)); + } + else if (pspec->name == g_intern_static_string ("stock")) + { + update_stock_item (child, widget); + } + else if (pspec->name == g_intern_static_string ("icon-name")) + { + update_icon_name (child, widget); + } + else if (pspec->name == g_intern_static_string ("parent")) + { + /* + * We probably should have added a 'remove' method to the + * UbuntuMenuProxy early on, but it's late in the cycle now. + */ + if (gtk_widget_get_parent (widget) == NULL) + { + g_signal_handlers_disconnect_by_func (widget, + G_CALLBACK (widget_notify_cb), + child); + + DbusmenuMenuitem *parent = g_object_get_data (G_OBJECT (child), "dbusmenu-parent"); + + if (DBUSMENU_IS_MENUITEM (parent) && DBUSMENU_IS_MENUITEM (child)) + { + dbusmenu_menuitem_child_delete (parent, child); + } + } + } +} + +static gboolean +should_show_image (GtkImage *image) +{ + GtkWidget *item; + + item = gtk_widget_get_ancestor (GTK_WIDGET (image), + GTK_TYPE_IMAGE_MENU_ITEM); + + if (item) + { + GtkSettings *settings; + gboolean gtk_menu_images; + + settings = gtk_widget_get_settings (item); + + g_object_get (settings, "gtk-menu-images", >k_menu_images, NULL); + + if (gtk_menu_images) + return TRUE; + + return gtk_image_menu_item_get_always_show_image (GTK_IMAGE_MENU_ITEM (item)); + } + + return FALSE; +} + diff --git a/libdbusmenu-gtk/parser.h b/libdbusmenu-gtk/parser.h index 222d9f4..3cffb9c 100644 --- a/libdbusmenu-gtk/parser.h +++ b/libdbusmenu-gtk/parser.h @@ -2,5 +2,5 @@ #include #include -DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkMenuItem * mi); +DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkWidget * widget); -- cgit v1.2.3 From 708ccab44c2c88b43ad35048dc0aee81023e61f9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 23 Jan 2011 13:11:46 -0600 Subject: Reformating prototypes because it makes the code run faster. --- libdbusmenu-gtk/parser.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 8fd0d12..f0c22be 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -2,17 +2,30 @@ #include "parser.h" #include "menuitem.h" -static void accel_changed (GtkWidget *widget, gpointer data); -static gboolean update_stock_item (DbusmenuMenuitem *menuitem, GtkWidget *widget); -static void checkbox_toggled (GtkWidget *widget, DbusmenuMenuitem *mi); -static void update_icon_name (DbusmenuMenuitem *menuitem, GtkWidget *widget); -static GtkWidget * find_menu_label (GtkWidget *widget); -static void label_notify_cb (GtkWidget *widget, GParamSpec *pspec, gpointer data); -static void action_notify_cb (GtkAction *action, GParamSpec *pspec, gpointer data); -static void item_activated (DbusmenuMenuitem *item, guint timestamp, gpointer user_data); -static gboolean item_about_to_show (DbusmenuMenuitem *item, gpointer user_data); -static void widget_notify_cb (GtkWidget *widget, GParamSpec *pspec, gpointer data); -static gboolean should_show_image (GtkImage *image); +static void accel_changed (GtkWidget * widget, + gpointer data); +static gboolean update_stock_item (DbusmenuMenuitem * menuitem, + GtkWidget * widget); +static void checkbox_toggled (GtkWidget * widget, + DbusmenuMenuitem * mi); +static void update_icon_name (DbusmenuMenuitem * menuitem, + GtkWidget * widget); +static GtkWidget * find_menu_label (GtkWidget * widget); +static void label_notify_cb (GtkWidget * widget, + GParamSpec * pspec, + gpointer data); +static void action_notify_cb (GtkAction * action, + GParamSpec * pspec, + gpointer data); +static void item_activated (DbusmenuMenuitem * item, + guint timestamp, + gpointer user_data); +static gboolean item_about_to_show (DbusmenuMenuitem * item, + gpointer user_data); +static void widget_notify_cb (GtkWidget * widget, + GParamSpec * pspec, + gpointer data); +static gboolean should_show_image (GtkImage * image); DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) -- cgit v1.2.3 From 401bc7c326c518ad01c1edd38155d89d9e35fd49 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 23 Jan 2011 13:16:20 -0600 Subject: Adding copyright headers --- libdbusmenu-gtk/parser.c | 27 +++++++++++++++++++++++++++ libdbusmenu-gtk/parser.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index f0c22be..cba6b42 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -1,3 +1,30 @@ +/* +Parse to take a set of GTK Menus and turn them into something that can +be sent over the wire. + +Copyright 2011 Canonical Ltd. + +Authors: + Numerous (check Bazaar) + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the +Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by +the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see + +*/ #include "parser.h" #include "menuitem.h" diff --git a/libdbusmenu-gtk/parser.h b/libdbusmenu-gtk/parser.h index 3cffb9c..a40d709 100644 --- a/libdbusmenu-gtk/parser.h +++ b/libdbusmenu-gtk/parser.h @@ -1,6 +1,37 @@ +/* +Parse to take a set of GTK Menus and turn them into something that can +be sent over the wire. + +Copyright 2011 Canonical Ltd. + +Authors: + Ted Gould + +This program is free software: you can redistribute it and/or modify it +under the terms of either or both of the following licenses: + +1) the GNU Lesser General Public License version 3, as published by the +Free Software Foundation; and/or +2) the GNU Lesser General Public License version 2.1, as published by +the Free Software Foundation. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranties of +MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR +PURPOSE. See the applicable version of the GNU Lesser General Public +License for more details. + +You should have received a copy of both the GNU Lesser General Public +License version 3 and version 2.1 along with this program. If not, see + +*/ + +#ifndef DBUSMENU_GTK_PARSER_H__ +#define DBUSMENU_GTK_PARSER_H__ #include #include DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkWidget * widget); +#endif /* DBUSMENU_GTK_PARSER_H__ */ -- cgit v1.2.3 From 32a7eb938893bcc1bc5644aa95c63041e9d4db01 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 23 Jan 2011 15:09:51 -0600 Subject: Needed to go up a level to get recursion code. --- libdbusmenu-gtk/parser.c | 158 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index cba6b42..08613ac 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -29,6 +29,14 @@ License version 3 and version 2.1 along with this program. If not, see #include "parser.h" #include "menuitem.h" +typedef struct _RecurseContext +{ + gint count; + DbusmenuMenuitem *stack[30]; +} RecurseContext; + +static void parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse); +static DbusmenuMenuitem * construct_dbusmenu_for_widget (GtkWidget * widget); static void accel_changed (GtkWidget * widget, gpointer data); static gboolean update_stock_item (DbusmenuMenuitem * menuitem, @@ -56,6 +64,156 @@ static gboolean should_show_image (GtkImage * image); DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) +{ + RecurseContext recurse = {0}; + recurse.count = -1; + + parse_menu_structure_helper(widget, &recurse); + + if (recurse.stack[0] != NULL && DBUSMENU_IS_MENUITEM(recurse.stack[0])) { + return recurse.stack[0]; + } + + return NULL; +} + +static void +parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) +{ + if (GTK_IS_CONTAINER (widget)) + { + gboolean increment = GTK_IS_MENU_BAR (widget) || GTK_IS_MENU_ITEM (widget); + + if (increment) + recurse->count++; + + /* Okay, this is a little janky and all.. but some applications update some + * menuitem properties such as sensitivity on the activate callback. This + * seems a little weird, but it's not our place to judge when all this code + * is so crazy. So we're going to get ever crazier and activate all the + * menus that are directly below the menubar and force the applications to + * update their sensitivity. The menus won't actually popup in the app + * window due to our gtk+ patches. + * + * Note that this will not force menuitems in submenus to be updated as well. + */ + if (recurse->count == 0 && GTK_IS_MENU_BAR (widget)) + { + GList *children = gtk_container_get_children (GTK_CONTAINER (widget)); + + for (; children != NULL; children = children->next) + { + gtk_menu_shell_activate_item (GTK_MENU_SHELL (widget), + children->data, + TRUE); + } + + g_list_free (children); + } + + if (recurse->count > -1 && increment) + { + DbusmenuMenuitem *dmi = NULL; //g_hash_table_lookup (recurse->context->lookup, widget); + if (dmi != NULL) + { + if (increment) + recurse->count--; + + return; + } + else + { + recurse->stack[recurse->count] = construct_dbusmenu_for_widget (widget); + //g_hash_table_insert (recurse->context->lookup, widget, recurse->stack[recurse->count]); + } + + if (!gtk_widget_get_visible (widget)) + { + /*g_signal_connect (G_OBJECT (widget), + "notify", + G_CALLBACK (menuitem_notify_cb), + recurse->context); */ + } + + if (GTK_IS_TEAROFF_MENU_ITEM (widget)) + { + dbusmenu_menuitem_property_set_bool (recurse->stack[recurse->count], + DBUSMENU_MENUITEM_PROP_VISIBLE, + FALSE); + } + + if (recurse->count > 0) + { + GList *children = NULL; + GList *peek = NULL; + + if (recurse->stack[recurse->count - 1]) + { + children = dbusmenu_menuitem_get_children (recurse->stack[recurse->count - 1]); + + if (children) + { + peek = g_list_find (children, recurse->stack[recurse->count]); + } + + if (!peek) + { + /* Should we set a weak ref on the parent? */ + g_object_set_data (G_OBJECT (recurse->stack[recurse->count]), + "dbusmenu-parent", + recurse->stack[recurse->count - 1]); + dbusmenu_menuitem_child_append (recurse->stack[recurse->count - 1], + recurse->stack[recurse->count]); + } + } + else + { + DbusmenuMenuitem *item = NULL; /* g_hash_table_lookup (recurse->context->lookup, + gtk_widget_get_parent (widget)); */ + + if (item) + { + children = dbusmenu_menuitem_get_children (item); + + if (children) + { + peek = g_list_find (children, recurse->stack[recurse->count]); + } + + if (!peek) + { + g_object_set_data (G_OBJECT (recurse->stack[recurse->count]), + "dbusmenu-parent", + recurse->stack[recurse->count - 1]); + + dbusmenu_menuitem_child_append (item, recurse->stack[recurse->count]); + } + } + } + } + } + + gtk_container_foreach (GTK_CONTAINER (widget), + (GtkCallback)parse_menu_structure_helper, + recurse); + + if (GTK_IS_MENU_ITEM (widget)) + { + GtkWidget *menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget)); + + if (menu != NULL) + { + parse_menu_structure_helper (menu, recurse); + } + } + + if (increment) + recurse->count--; + } +} + +static DbusmenuMenuitem * +construct_dbusmenu_for_widget (GtkWidget * widget) { DbusmenuMenuitem *mi = dbusmenu_menuitem_new (); -- cgit v1.2.3 From 65b9cda89a5bef2c541f5ed2624e6e199f136435 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 23 Jan 2011 15:40:26 -0600 Subject: Trying to put back in the visibility notifier to force the rebuild, but I'm not quite sure how to do that yet. --- libdbusmenu-gtk/parser.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 08613ac..9d0f9b4 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -31,6 +31,7 @@ License version 3 and version 2.1 along with this program. If not, see typedef struct _RecurseContext { + GtkWidget * toplevel; gint count; DbusmenuMenuitem *stack[30]; } RecurseContext; @@ -61,12 +62,17 @@ static void widget_notify_cb (GtkWidget * widget, GParamSpec * pspec, gpointer data); static gboolean should_show_image (GtkImage * image); +static void menuitem_notify_cb (GtkWidget * widget, + GParamSpec * pspec, + gpointer data); DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) { RecurseContext recurse = {0}; + recurse.count = -1; + recurse.toplevel = gtk_widget_get_toplevel(widget); parse_menu_structure_helper(widget, &recurse); @@ -129,10 +135,10 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) if (!gtk_widget_get_visible (widget)) { - /*g_signal_connect (G_OBJECT (widget), - "notify", + g_signal_connect (G_OBJECT (widget), + "notify::visible", G_CALLBACK (menuitem_notify_cb), - recurse->context); */ + recurse->toplevel); } if (GTK_IS_TEAROFF_MENU_ITEM (widget)) @@ -358,6 +364,27 @@ construct_dbusmenu_for_widget (GtkWidget * widget) return NULL; } +static void +menuitem_notify_cb (GtkWidget *widget, + GParamSpec *pspec, + gpointer data) +{ + if (pspec->name == g_intern_static_string ("visible")) + { + GtkWidget * new_toplevel = gtk_widget_get_toplevel (widget); + GtkWidget * old_toplevel = GTK_WIDGET(data); + + if (new_toplevel == old_toplevel) { + /* TODO: Figure this out -> rebuild (context->bridge, window); */ + } + + /* We only care about this once, so let's disconnect now. */ + g_signal_handlers_disconnect_by_func (widget, + G_CALLBACK (menuitem_notify_cb), + data); + } +} + static void accel_changed (GtkWidget *widget, gpointer data) -- cgit v1.2.3 From a439aeb8fd08d9858055bbb2ae1326a1335600d1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 23 Jan 2011 15:53:27 -0600 Subject: Reimplementing the cache based on object data with signals to cleanup --- libdbusmenu-gtk/parser.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 9d0f9b4..f1c46ba 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -29,6 +29,8 @@ License version 3 and version 2.1 along with this program. If not, see #include "parser.h" #include "menuitem.h" +#define CACHED_MENUITEM "dbusmenu-gtk-parser-cached-item" + typedef struct _RecurseContext { GtkWidget * toplevel; @@ -83,6 +85,20 @@ dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) return NULL; } +static void +dbusmenu_cache_freed (gpointer data, GObject * obj) +{ + g_object_set_data(G_OBJECT(data), CACHED_MENUITEM, NULL); + return; +} + +static void +object_cache_freed (gpointer data) +{ + g_object_weak_unref(G_OBJECT(data), dbusmenu_cache_freed, data); + return; +} + static void parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) { @@ -119,7 +135,10 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) if (recurse->count > -1 && increment) { - DbusmenuMenuitem *dmi = NULL; //g_hash_table_lookup (recurse->context->lookup, widget); + gpointer pmi = g_object_get_data(G_OBJECT(widget), CACHED_MENUITEM); + DbusmenuMenuitem *dmi = NULL; + if (pmi != NULL) dmi = DBUSMENU_MENUITEM(pmi); + if (dmi != NULL) { if (increment) @@ -130,7 +149,8 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) else { recurse->stack[recurse->count] = construct_dbusmenu_for_widget (widget); - //g_hash_table_insert (recurse->context->lookup, widget, recurse->stack[recurse->count]); + g_object_set_data_full(G_OBJECT(widget), CACHED_MENUITEM, recurse->stack[recurse->count], object_cache_freed); + g_object_weak_ref(G_OBJECT(recurse->stack[recurse->count]), dbusmenu_cache_freed, widget); } if (!gtk_widget_get_visible (widget)) -- cgit v1.2.3 From fc096ca12b152461dfddbfdf74720b98691448ce Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Sun, 23 Jan 2011 16:08:39 -0600 Subject: Stop using the data field in gtk image for GTK3 --- libdbusmenu-gtk/parser.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index f1c46ba..cfce42a 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -427,12 +427,15 @@ update_stock_item (DbusmenuMenuitem *menuitem, if (gtk_image_get_storage_type (image) != GTK_IMAGE_STOCK) return FALSE; - gtk_stock_lookup (image->data.stock.stock_id, &stock); + gchar * stock_id = NULL; + gtk_image_get_stock(image, &stock_id, NULL); + + gtk_stock_lookup (stock_id, &stock); if (should_show_image (image)) dbusmenu_menuitem_property_set (menuitem, DBUSMENU_MENUITEM_PROP_ICON_NAME, - image->data.stock.stock_id); + stock_id); else dbusmenu_menuitem_property_remove (menuitem, DBUSMENU_MENUITEM_PROP_ICON_NAME); @@ -473,13 +476,16 @@ update_icon_name (DbusmenuMenuitem *menuitem, if (gtk_image_get_storage_type (image) != GTK_IMAGE_ICON_NAME) return; - if (should_show_image (image)) + if (should_show_image (image)) { + const gchar * icon_name = NULL; + gtk_image_get_icon_name(image, &icon_name, NULL); dbusmenu_menuitem_property_set (menuitem, DBUSMENU_MENUITEM_PROP_ICON_NAME, - image->data.name.icon_name); - else + icon_name); + } else { dbusmenu_menuitem_property_remove (menuitem, DBUSMENU_MENUITEM_PROP_ICON_NAME); + } } static GtkWidget * -- cgit v1.2.3 From 25ab785826d59d8ca7860b0d0bc39d6187a3a1ed Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 24 Jan 2011 14:56:07 -0600 Subject: Fixing referencing warnings on destruction. --- libdbusmenu-gtk/parser.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index cfce42a..52bd8a8 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -88,7 +88,9 @@ dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) static void dbusmenu_cache_freed (gpointer data, GObject * obj) { - g_object_set_data(G_OBJECT(data), CACHED_MENUITEM, NULL); + /* If the dbusmenu item is killed we don't need to remove + the weak ref as well. */ + g_object_steal_data(G_OBJECT(data), CACHED_MENUITEM); return; } -- cgit v1.2.3 From 32def89e3191d994a43d222c1e81c746922b688d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 25 Jan 2011 11:50:46 -0600 Subject: Moving one up the stack so GtkMenu works as well --- libdbusmenu-gtk/parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 52bd8a8..d26f8fb 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -106,7 +106,7 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) { if (GTK_IS_CONTAINER (widget)) { - gboolean increment = GTK_IS_MENU_BAR (widget) || GTK_IS_MENU_ITEM (widget); + gboolean increment = GTK_IS_MENU_SHELL (widget) || GTK_IS_MENU_ITEM (widget); if (increment) recurse->count++; -- cgit v1.2.3 From 275bd0eec2e28b708ff6cda14531f63a8aa16e8e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 25 Jan 2011 16:51:31 -0600 Subject: Looking for the serializable menu item and using it's build function if it is one. --- libdbusmenu-gtk/parser.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index d26f8fb..6d95f10 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -28,6 +28,7 @@ License version 3 and version 2.1 along with this program. If not, see #include "parser.h" #include "menuitem.h" +#include "serializablemenuitem.h" #define CACHED_MENUITEM "dbusmenu-gtk-parser-cached-item" @@ -240,13 +241,23 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) } } +/* Turn a widget into a dbusmenu item depending on the type of GTK + object that it is. */ static DbusmenuMenuitem * construct_dbusmenu_for_widget (GtkWidget * widget) { - DbusmenuMenuitem *mi = dbusmenu_menuitem_new (); - + /* If it's a subclass of our serializable menu item then we can + use its own build function */ + if (DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM(widget)) { + DbusmenuGtkSerializableMenuItem * smi = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM(widget); + return dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem(smi); + } + + /* If it's a standard GTK Menu Item we need to do some of our own work */ if (GTK_IS_MENU_ITEM (widget)) { + DbusmenuMenuitem *mi = dbusmenu_menuitem_new (); + gboolean visible = FALSE; gboolean sensitive = FALSE; if (GTK_IS_SEPARATOR_MENU_ITEM (widget)) @@ -379,11 +390,12 @@ construct_dbusmenu_for_widget (GtkWidget * widget) "notify", G_CALLBACK (widget_notify_cb), mi); + return mi; } - return mi; - - return NULL; + /* If it's none of those we're going to just create a + generic menuitem as a place holder for it. */ + return dbusmenu_menuitem_new(); } static void -- cgit v1.2.3 From d5a160e04dfd351cefb70ac5f6955cb2913e2ad5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 25 Jan 2011 17:04:23 -0600 Subject: Adding a little helper to reduce the number of warnings if the property is missing. --- libdbusmenu-gtk/client.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 18a2cdd..ff2b3a7 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -42,6 +42,7 @@ struct _DbusmenuGtkClientPrivate { }; #define DBUSMENU_GTKCLIENT_GET_PRIVATE(o) (DBUSMENU_GTKCLIENT(o)->priv) +#define USE_FALLBACK_PROP "use-fallback" /* Prototypes */ static void dbusmenu_gtkclient_class_init (DbusmenuGtkClientClass *klass); @@ -737,6 +738,28 @@ new_item_seperator (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, Dbusm return TRUE; } +/* A little helper so we don't generate a bunch of warnings + about being able to set use-fallback */ +static void +set_use_fallback (GtkWidget * widget) +{ + static gboolean checked = FALSE; + static gboolean available = FALSE; + + if (!checked) { + available = (g_object_class_find_property(G_OBJECT_CLASS(GTK_IMAGE_GET_CLASS(widget)), USE_FALLBACK_PROP) != NULL); + if (!available) { + g_warning("The '" USE_FALLBACK_PROP "' is not available on GtkImage so icons may not show correctly."); + } + } + + if (available) { + g_object_set(G_OBJECT(widget), USE_FALLBACK_PROP, TRUE, NULL); + } + + return; +} + /* This handler looks at property changes for items that are image menu items. */ static void @@ -789,7 +812,7 @@ image_property_handle (DbusmenuMenuitem * item, const gchar * property, GVariant gtkimage = NULL; } else if (g_strcmp0(iconname, DBUSMENU_MENUITEM_ICON_NAME_BLANK) == 0) { gtkimage = gtk_image_new(); - g_object_set(G_OBJECT(gtkimage), "use-fallback", TRUE, NULL); + set_use_fallback(gtkimage); } else { /* Look to see if we want to have an icon with the 'ltr' or 'rtl' depending on what we're doing. */ @@ -808,7 +831,7 @@ image_property_handle (DbusmenuMenuitem * item, const gchar * property, GVariant can just convert it to this name. */ if (gtkimage == NULL) { gtkimage = gtk_image_new_from_icon_name(finaliconname, GTK_ICON_SIZE_MENU); - g_object_set(G_OBJECT(gtkimage), "use-fallback", TRUE, NULL); + set_use_fallback(gtkimage); } else { gtk_image_set_from_icon_name(GTK_IMAGE(gtkimage), finaliconname, GTK_ICON_SIZE_MENU); } -- cgit v1.2.3 From 1039a4dd88243938e8871c307c20841c375b78d2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 26 Jan 2011 15:11:16 -0600 Subject: Adding comments and a check to ensure the item is valid. --- libdbusmenu-gtk/parser.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index d26f8fb..1936d2d 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -85,6 +85,8 @@ dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) return NULL; } +/* Called when the dbusmenu item that we're keeping around + is finalized */ static void dbusmenu_cache_freed (gpointer data, GObject * obj) { @@ -94,9 +96,12 @@ dbusmenu_cache_freed (gpointer data, GObject * obj) return; } +/* Called if we replace the cache on the object with a new + dbusmenu menuitem */ static void object_cache_freed (gpointer data) { + if (!G_IS_OBJECT(data)) return; g_object_weak_unref(G_OBJECT(data), dbusmenu_cache_freed, data); return; } -- cgit v1.2.3 From 81032fae461250e5e73aaa49896fd92dd58ad674 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 26 Jan 2011 16:09:41 -0600 Subject: Factoring out the stack and just tracking the parent as that's all we were using it for really. --- libdbusmenu-gtk/parser.c | 236 ++++++++++++++++++++--------------------------- 1 file changed, 99 insertions(+), 137 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 1936d2d..5f0ef48 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -34,8 +34,7 @@ License version 3 and version 2.1 along with this program. If not, see typedef struct _RecurseContext { GtkWidget * toplevel; - gint count; - DbusmenuMenuitem *stack[30]; + DbusmenuMenuitem * parent; } RecurseContext; static void parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse); @@ -68,21 +67,17 @@ static void menuitem_notify_cb (GtkWidget * widget, GParamSpec * pspec, gpointer data); + DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) { RecurseContext recurse = {0}; - recurse.count = -1; recurse.toplevel = gtk_widget_get_toplevel(widget); parse_menu_structure_helper(widget, &recurse); - if (recurse.stack[0] != NULL && DBUSMENU_IS_MENUITEM(recurse.stack[0])) { - return recurse.stack[0]; - } - - return NULL; + return recurse.parent; } /* Called when the dbusmenu item that we're keeping around @@ -93,6 +88,7 @@ dbusmenu_cache_freed (gpointer data, GObject * obj) /* If the dbusmenu item is killed we don't need to remove the weak ref as well. */ g_object_steal_data(G_OBJECT(data), CACHED_MENUITEM); + g_signal_handlers_disconnect_by_func(data, G_CALLBACK(widget_notify_cb), obj); return; } @@ -109,140 +105,106 @@ object_cache_freed (gpointer data) static void parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) { - if (GTK_IS_CONTAINER (widget)) - { - gboolean increment = GTK_IS_MENU_SHELL (widget) || GTK_IS_MENU_ITEM (widget); - - if (increment) - recurse->count++; - - /* Okay, this is a little janky and all.. but some applications update some - * menuitem properties such as sensitivity on the activate callback. This - * seems a little weird, but it's not our place to judge when all this code - * is so crazy. So we're going to get ever crazier and activate all the - * menus that are directly below the menubar and force the applications to - * update their sensitivity. The menus won't actually popup in the app - * window due to our gtk+ patches. - * - * Note that this will not force menuitems in submenus to be updated as well. - */ - if (recurse->count == 0 && GTK_IS_MENU_BAR (widget)) - { - GList *children = gtk_container_get_children (GTK_CONTAINER (widget)); - - for (; children != NULL; children = children->next) - { - gtk_menu_shell_activate_item (GTK_MENU_SHELL (widget), - children->data, - TRUE); - } - - g_list_free (children); - } - - if (recurse->count > -1 && increment) - { - gpointer pmi = g_object_get_data(G_OBJECT(widget), CACHED_MENUITEM); - DbusmenuMenuitem *dmi = NULL; - if (pmi != NULL) dmi = DBUSMENU_MENUITEM(pmi); - if (dmi != NULL) - { - if (increment) - recurse->count--; - - return; - } - else - { - recurse->stack[recurse->count] = construct_dbusmenu_for_widget (widget); - g_object_set_data_full(G_OBJECT(widget), CACHED_MENUITEM, recurse->stack[recurse->count], object_cache_freed); - g_object_weak_ref(G_OBJECT(recurse->stack[recurse->count]), dbusmenu_cache_freed, widget); + /* If this is a shell, then let's handle the items in it. */ + if (GTK_IS_MENU_SHELL (widget)) { + /* Okay, this is a little janky and all.. but some applications update some + * menuitem properties such as sensitivity on the activate callback. This + * seems a little weird, but it's not our place to judge when all this code + * is so crazy. So we're going to get ever crazier and activate all the + * menus that are directly below the menubar and force the applications to + * update their sensitivity. The menus won't actually popup in the app + * window due to our gtk+ patches. + * + * Note that this will not force menuitems in submenus to be updated as well. + */ + GList *children = gtk_container_get_children (GTK_CONTAINER (widget)); + + for (; children != NULL; children = children->next) { + gtk_menu_shell_activate_item (GTK_MENU_SHELL (widget), + children->data, + TRUE); + } + + g_list_free (children); + + if (recurse->parent == NULL) { + recurse->parent = dbusmenu_menuitem_new(); + } + + gtk_container_foreach (GTK_CONTAINER (widget), + (GtkCallback)parse_menu_structure_helper, + recurse); + return; + } + + if (GTK_IS_MENU_ITEM(widget)) { + DbusmenuMenuitem * thisitem = NULL; + + /* Check to see if we're cached already */ + gpointer pmi = g_object_get_data(G_OBJECT(widget), CACHED_MENUITEM); + if (pmi != NULL) { + thisitem = DBUSMENU_MENUITEM(pmi); + g_object_ref(G_OBJECT(thisitem)); + } + + /* We don't have one, so we'll need to build it */ + if (thisitem == NULL) { + thisitem = construct_dbusmenu_for_widget (widget); + g_object_set_data_full(G_OBJECT(widget), CACHED_MENUITEM, thisitem, object_cache_freed); + g_object_weak_ref(G_OBJECT(thisitem), dbusmenu_cache_freed, widget); + + if (!gtk_widget_get_visible (widget)) { + g_signal_connect (G_OBJECT (widget), + "notify::visible", + G_CALLBACK (menuitem_notify_cb), + recurse->toplevel); } - if (!gtk_widget_get_visible (widget)) - { - g_signal_connect (G_OBJECT (widget), - "notify::visible", - G_CALLBACK (menuitem_notify_cb), - recurse->toplevel); + if (GTK_IS_TEAROFF_MENU_ITEM (widget)) { + dbusmenu_menuitem_property_set_bool (thisitem, + DBUSMENU_MENUITEM_PROP_VISIBLE, + FALSE); } + } + + /* Check to see if we're in our parents list of children, if we have + a parent. */ + if (recurse->parent != NULL) { + GList * children = dbusmenu_menuitem_get_children (recurse->parent); + GList * peek = NULL; + + if (children != NULL) { + peek = g_list_find (children, thisitem); + } + + /* Oops, let's tell our parents about us */ + if (peek == NULL) { + /* TODO: Should we set a weak ref on the parent? */ + g_object_set_data (G_OBJECT (thisitem), + "dbusmenu-parent", + recurse->parent); + dbusmenu_menuitem_child_append (recurse->parent, + thisitem); + } + } + + GtkWidget *menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget)); + if (menu != NULL) { + DbusmenuMenuitem * parent_save = recurse->parent; + recurse->parent = thisitem; + parse_menu_structure_helper (menu, recurse); + recurse->parent = parent_save; + } + + if (recurse->parent == NULL) { + recurse->parent = thisitem; + } else { + g_object_unref(thisitem); + } + } - if (GTK_IS_TEAROFF_MENU_ITEM (widget)) - { - dbusmenu_menuitem_property_set_bool (recurse->stack[recurse->count], - DBUSMENU_MENUITEM_PROP_VISIBLE, - FALSE); - } - - if (recurse->count > 0) - { - GList *children = NULL; - GList *peek = NULL; - - if (recurse->stack[recurse->count - 1]) - { - children = dbusmenu_menuitem_get_children (recurse->stack[recurse->count - 1]); - - if (children) - { - peek = g_list_find (children, recurse->stack[recurse->count]); - } - - if (!peek) - { - /* Should we set a weak ref on the parent? */ - g_object_set_data (G_OBJECT (recurse->stack[recurse->count]), - "dbusmenu-parent", - recurse->stack[recurse->count - 1]); - dbusmenu_menuitem_child_append (recurse->stack[recurse->count - 1], - recurse->stack[recurse->count]); - } - } - else - { - DbusmenuMenuitem *item = NULL; /* g_hash_table_lookup (recurse->context->lookup, - gtk_widget_get_parent (widget)); */ - - if (item) - { - children = dbusmenu_menuitem_get_children (item); - - if (children) - { - peek = g_list_find (children, recurse->stack[recurse->count]); - } - - if (!peek) - { - g_object_set_data (G_OBJECT (recurse->stack[recurse->count]), - "dbusmenu-parent", - recurse->stack[recurse->count - 1]); - - dbusmenu_menuitem_child_append (item, recurse->stack[recurse->count]); - } - } - } - } - } - - gtk_container_foreach (GTK_CONTAINER (widget), - (GtkCallback)parse_menu_structure_helper, - recurse); - - if (GTK_IS_MENU_ITEM (widget)) - { - GtkWidget *menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget)); - - if (menu != NULL) - { - parse_menu_structure_helper (menu, recurse); - } - } - - if (increment) - recurse->count--; - } + return; } static DbusmenuMenuitem * -- cgit v1.2.3 From fe464dc002ed3e2e713f64145e689f66ad51f275 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 26 Jan 2011 16:13:56 -0600 Subject: Fix to the type of toggle-state to int --- libdbusmenu-gtk/parser.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 5f0ef48..b1e7e01 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -522,9 +522,9 @@ action_notify_cb (GtkAction *action, } else if (pspec->name == g_intern_static_string ("active")) { - dbusmenu_menuitem_property_set_bool (mi, - DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, - gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))); + dbusmenu_menuitem_property_set_int (mi, + DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, + gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)) ? DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED : DBUSMENU_MENUITEM_TOGGLE_STATE_UNCHECKED); } else if (pspec->name == g_intern_static_string ("label")) { -- cgit v1.2.3 From e5078ed1027e8c466d081183eeee6888b10ef510 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 26 Jan 2011 16:27:50 -0600 Subject: No really, read the comment and make sure that only happens on the highest level --- libdbusmenu-gtk/parser.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index b1e7e01..27ac926 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -118,15 +118,17 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) * * Note that this will not force menuitems in submenus to be updated as well. */ - GList *children = gtk_container_get_children (GTK_CONTAINER (widget)); + if (recurse->parent == NULL) { + GList *children = gtk_container_get_children (GTK_CONTAINER (widget)); - for (; children != NULL; children = children->next) { - gtk_menu_shell_activate_item (GTK_MENU_SHELL (widget), - children->data, - TRUE); - } + for (; children != NULL; children = children->next) { + gtk_menu_shell_activate_item (GTK_MENU_SHELL (widget), + children->data, + TRUE); + } - g_list_free (children); + g_list_free (children); + } if (recurse->parent == NULL) { recurse->parent = dbusmenu_menuitem_new(); -- cgit v1.2.3 From c6da3667cae61d1606eb66e6b7be01c2cbf9cbff Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 26 Jan 2011 16:53:54 -0600 Subject: Only activating on menu bars. --- libdbusmenu-gtk/parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 27ac926..5dea9de 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -118,7 +118,7 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) * * Note that this will not force menuitems in submenus to be updated as well. */ - if (recurse->parent == NULL) { + if (recurse->parent == NULL && GTK_IS_MENU_BAR(widget)) { GList *children = gtk_container_get_children (GTK_CONTAINER (widget)); for (; children != NULL; children = children->next) { -- cgit v1.2.3 From 1555d242f4e0214dd39dbd56e5cc6ddcf426e19b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 26 Jan 2011 22:42:30 -0600 Subject: Actually setting the 'checked' value --- libdbusmenu-gtk/client.c | 1 + 1 file changed, 1 insertion(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index ff2b3a7..00b2b90 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -751,6 +751,7 @@ set_use_fallback (GtkWidget * widget) if (!available) { g_warning("The '" USE_FALLBACK_PROP "' is not available on GtkImage so icons may not show correctly."); } + checked = TRUE; } if (available) { -- cgit v1.2.3 From 7e55758aa584a9e4080411cbd663d1fa30725a57 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 27 Jan 2011 08:48:37 -0600 Subject: Adding documentation of the public API. --- libdbusmenu-gtk/parser.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 5dea9de..8537a07 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -67,7 +67,17 @@ static void menuitem_notify_cb (GtkWidget * widget, GParamSpec * pspec, gpointer data); +/** + dbusmenu_gtk_parse_menu_structure: + @widget: A #GtkMenuItem or #GtkMenuShell to turn into a #DbusmenuMenuitem + Goes through the GTK structures and turns them into the appropraite + Dbusmenu structures along with setting up all the relationships + between the objects. It also stores the dbusmenu items as a cache + on the GTK items so that they'll be reused if necissary. + + Return value: A dbusmenu item representing the menu structure +*/ DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) { -- cgit v1.2.3 From 321935e1678923454a97bcb41f9ddc6714e4ac88 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 27 Jan 2011 08:50:24 -0600 Subject: Adding an early check on the type of widget coming into the function. --- libdbusmenu-gtk/parser.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 8537a07..ead653a 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -81,6 +81,8 @@ static void menuitem_notify_cb (GtkWidget * widget, DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) { + g_return_val_if_fail(GTK_IS_MENU_ITEM(widget) || GTK_IS_MENU_SHELL(widget), NULL); + RecurseContext recurse = {0}; recurse.toplevel = gtk_widget_get_toplevel(widget); -- cgit v1.2.3 From 49ecfc8c84d543491031aecbe64037e3fd76d366 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 27 Jan 2011 09:28:44 -0600 Subject: Shortening function names to be more reasonable. --- libdbusmenu-gtk/serializablemenuitem.c | 10 +++++----- libdbusmenu-gtk/serializablemenuitem.h | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index f67434e..cfd864d 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -166,7 +166,7 @@ get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) } /** - dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem: + dbusmenu_gtk_serializable_menu_item_build_menuitem: @smi: #DbusmenuGtkSerializableMenuItem to build a #DbusmenuMenuitem mirroring This function is for menu items that are instanciated from @@ -179,7 +179,7 @@ get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) set by this object. */ DbusmenuMenuitem * -dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi) +dbusmenu_gtk_serializable_menu_item_build_menuitem (DbusmenuGtkSerializableMenuItem * smi) { g_return_val_if_fail(DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM(smi), NULL); @@ -207,7 +207,7 @@ type_handler (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuCli DbusmenuGtkSerializableMenuItem * smi = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM(g_object_new(th->type, NULL)); g_return_val_if_fail(smi != NULL, FALSE); - dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem(smi, newitem); + dbusmenu_gtk_serializable_menu_item_set_menuitem(smi, newitem); dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, GTK_MENU_ITEM(smi), parent); return TRUE; @@ -265,7 +265,7 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, } /** - dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem: + dbusmenu_gtk_serializable_menu_item_set_menuitem: @smi: #DbusmenuGtkSerializableMenuItem to set the @DbusmenuGtkSerializableMenuItem::dbusmenu-menuitem of @mi: Menuitem to get the properties from @@ -276,7 +276,7 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, pick up this property being set. */ void -dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi, DbusmenuMenuitem * mi) +dbusmenu_gtk_serializable_menu_item_set_menuitem (DbusmenuGtkSerializableMenuItem * smi, DbusmenuMenuitem * mi) { g_return_if_fail(DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM(smi)); g_return_if_fail(mi != NULL); diff --git a/libdbusmenu-gtk/serializablemenuitem.h b/libdbusmenu-gtk/serializablemenuitem.h index 1ca3ef8..1d12dd4 100644 --- a/libdbusmenu-gtk/serializablemenuitem.h +++ b/libdbusmenu-gtk/serializablemenuitem.h @@ -99,9 +99,9 @@ struct _DbusmenuGtkSerializableMenuItem { GType dbusmenu_gtk_serializable_menu_item_get_type (void); -DbusmenuMenuitem * dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi); +DbusmenuMenuitem * dbusmenu_gtk_serializable_menu_item_build_menuitem (DbusmenuGtkSerializableMenuItem * smi); void dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type); -void dbusmenu_gtk_serializable_menu_item_set_dbusmenu_menuitem (DbusmenuGtkSerializableMenuItem * smi, DbusmenuMenuitem * mi); +void dbusmenu_gtk_serializable_menu_item_set_menuitem (DbusmenuGtkSerializableMenuItem * smi, DbusmenuMenuitem * mi); G_END_DECLS -- cgit v1.2.3 From 717e9a319cd430428c297d0777b45c64e4d7f5fd Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 27 Jan 2011 09:40:30 -0600 Subject: Adding some naritive text describing the purpose --- libdbusmenu-gtk/serializablemenuitem.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.h b/libdbusmenu-gtk/serializablemenuitem.h index 1d12dd4..db28a24 100644 --- a/libdbusmenu-gtk/serializablemenuitem.h +++ b/libdbusmenu-gtk/serializablemenuitem.h @@ -90,6 +90,13 @@ struct _DbusmenuGtkSerializableMenuItemClass { DbusmenuGtkSerializableMenuItem: @parent: Inherit from GtkMenuItem @priv: Blind structure of private variables + + The Serializable Menuitem provides a way for menu items to be created + that can easily be picked up by the Dbusmenu GTK Parser. This way + you can create custom items, and transport them across dbusmenu to + your menus or the appmenu on the other side of the bus. By providing + these function the parser has enough information to both serialize, and + deserialize on the other side, the menuitem you've so carefully created. */ struct _DbusmenuGtkSerializableMenuItem { GtkMenuItem parent; -- cgit v1.2.3 From 07666d7543bfce7fe925c15d3350519fd711a8f0 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 27 Jan 2011 09:44:11 -0600 Subject: Fix changing prototypes. --- libdbusmenu-gtk/parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 6d95f10..cdbc001 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -250,7 +250,7 @@ construct_dbusmenu_for_widget (GtkWidget * widget) use its own build function */ if (DBUSMENU_IS_GTK_SERIALIZABLE_MENU_ITEM(widget)) { DbusmenuGtkSerializableMenuItem * smi = DBUSMENU_GTK_SERIALIZABLE_MENU_ITEM(widget); - return dbusmenu_gtk_serializable_menu_item_build_dbusmenu_menuitem(smi); + return dbusmenu_gtk_serializable_menu_item_build_menuitem(smi); } /* If it's a standard GTK Menu Item we need to do some of our own work */ -- cgit v1.2.3 From 7be86c5778e58bbe231655ed58b7597ad61f5310 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Fri, 28 Jan 2011 14:35:36 -0500 Subject: notice new submenus --- libdbusmenu-gtk/parser.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 5d71585..5f42ed5 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -649,6 +649,27 @@ widget_notify_cb (GtkWidget *widget, } } } + else if (pspec->name == g_intern_static_string ("submenu")) + { + /* The underlying submenu got swapped out. Let's see what it is now. */ + /* First, delete any children that may exist currently. */ + DbusmenuMenuitem * item = DBUSMENU_MENUITEM(g_object_get_data(G_OBJECT(widget), CACHED_MENUITEM)); + if (item != NULL) + { + GList * children = dbusmenu_menuitem_get_children (item); + while (children != NULL) { + dbusmenu_menuitem_child_delete (item, DBUSMENU_MENUITEM(children->data)); + children = children->next; + } + } + + /* Now parse new submenu. */ + GtkWidget * menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget)); + RecurseContext recurse = {0}; + recurse.toplevel = gtk_widget_get_toplevel(widget); + recurse.parent = item; + parse_menu_structure_helper(menu, &recurse); + } } static gboolean -- cgit v1.2.3 From db2d419d34f98cf8067bc97cda27b8687ce1be6c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 31 Jan 2011 10:01:59 -0600 Subject: Disconnect realized handler when we don't care about the item anymore. --- libdbusmenu-gtk/menu.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menu.c b/libdbusmenu-gtk/menu.c index 9c4f7f8..5231d0f 100644 --- a/libdbusmenu-gtk/menu.c +++ b/libdbusmenu-gtk/menu.c @@ -271,6 +271,10 @@ root_child_delete (DbusmenuMenuitem * root, DbusmenuMenuitem * child, DbusmenuGt #ifdef MASSIVEDEBUGGING g_debug("Root child deleted"); #endif + + /* Remove signal for realized */ + g_signal_handlers_disconnect_by_func(G_OBJECT(child), child_realized, menu); + DbusmenuGtkMenuPrivate * priv = DBUSMENU_GTKMENU_GET_PRIVATE(menu); GtkWidget * item = GTK_WIDGET(dbusmenu_gtkclient_menuitem_get(priv->client, child)); if (item != NULL) { -- cgit v1.2.3 From d9b81a0645e15f03c89cae3466a3928d2b75c4ef Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 31 Jan 2011 10:12:20 -0600 Subject: Keeping the root so that we can remove the signal handlers. --- libdbusmenu-gtk/menu.c | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menu.c b/libdbusmenu-gtk/menu.c index 5231d0f..2a27fe2 100644 --- a/libdbusmenu-gtk/menu.c +++ b/libdbusmenu-gtk/menu.c @@ -46,6 +46,7 @@ enum { /* Private */ struct _DbusmenuGtkMenuPrivate { DbusmenuGtkClient * client; + DbusmenuMenuitem * root; gchar * dbus_object; gchar * dbus_name; @@ -63,6 +64,8 @@ static void get_property (GObject * obj, guint id, GValue * value, GParamSpec * /* Internal */ static void build_client (DbusmenuGtkMenu * self); static void child_realized (DbusmenuMenuitem * child, gpointer userdata); +static void remove_child_signals (gpointer data, gpointer user_data); +static void root_changed (DbusmenuGtkClient * client, DbusmenuMenuitem * newroot, DbusmenuGtkMenu * menu); /* GObject Stuff */ G_DEFINE_TYPE (DbusmenuGtkMenu, dbusmenu_gtkmenu, GTK_TYPE_MENU); @@ -127,6 +130,12 @@ dbusmenu_gtkmenu_dispose (GObject *object) { DbusmenuGtkMenuPrivate * priv = DBUSMENU_GTKMENU_GET_PRIVATE(object); + /* Remove signals from the root */ + if (priv->root != NULL) { + /* This will clear the root */ + root_changed(priv->client, NULL, DBUSMENU_GTKMENU(object)); + } + if (priv->client != NULL) { g_object_unref(G_OBJECT(priv->client)); priv->client = NULL; @@ -273,7 +282,7 @@ root_child_delete (DbusmenuMenuitem * root, DbusmenuMenuitem * child, DbusmenuGt #endif /* Remove signal for realized */ - g_signal_handlers_disconnect_by_func(G_OBJECT(child), child_realized, menu); + remove_child_signals(child, menu); DbusmenuGtkMenuPrivate * priv = DBUSMENU_GTKMENU_GET_PRIVATE(menu); GtkWidget * item = GTK_WIDGET(dbusmenu_gtkclient_menuitem_get(priv->client, child)); @@ -312,15 +321,41 @@ child_realized (DbusmenuMenuitem * child, gpointer userdata) return; } +/* Remove any signals we attached to children -- just realized right now */ +static void +remove_child_signals (gpointer data, gpointer user_data) +{ + g_signal_handlers_disconnect_by_func(G_OBJECT(data), child_realized, user_data); + return; +} + /* When the root menuitem changes we need to resetup things so that we're back in the game. */ static void root_changed (DbusmenuGtkClient * client, DbusmenuMenuitem * newroot, DbusmenuGtkMenu * menu) { + DbusmenuGtkMenuPrivate * priv = DBUSMENU_GTKMENU_GET_PRIVATE(menu); + + /* Clear out our interest in the old root */ + if (priv->root != NULL) { + GList * children = dbusmenu_menuitem_get_children(priv->root); + g_list_foreach(children, remove_child_signals, menu); + + g_signal_handlers_disconnect_by_func(G_OBJECT(priv->root), root_child_added, menu); + g_signal_handlers_disconnect_by_func(G_OBJECT(priv->root), root_child_moved, menu); + g_signal_handlers_disconnect_by_func(G_OBJECT(priv->root), root_child_delete, menu); + + g_object_unref(priv->root); + priv->root = NULL; + } + if (newroot == NULL) { gtk_widget_hide(GTK_WIDGET(menu)); return; } + priv->root = newroot; + g_object_ref(priv->root); + g_signal_connect(G_OBJECT(newroot), DBUSMENU_MENUITEM_SIGNAL_CHILD_ADDED, G_CALLBACK(root_child_added), menu); g_signal_connect(G_OBJECT(newroot), DBUSMENU_MENUITEM_SIGNAL_CHILD_MOVED, G_CALLBACK(root_child_moved), menu); g_signal_connect(G_OBJECT(newroot), DBUSMENU_MENUITEM_SIGNAL_CHILD_REMOVED, G_CALLBACK(root_child_delete), menu); -- cgit v1.2.3 From 591583b6e602b93399fd125da1f658146e5d717d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 31 Jan 2011 11:55:39 -0600 Subject: Switching to take_children() so that we can ensure all the data remains valid --- libdbusmenu-gtk/parser.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 5f42ed5..4941bf4 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -656,11 +656,13 @@ widget_notify_cb (GtkWidget *widget, DbusmenuMenuitem * item = DBUSMENU_MENUITEM(g_object_get_data(G_OBJECT(widget), CACHED_MENUITEM)); if (item != NULL) { - GList * children = dbusmenu_menuitem_get_children (item); - while (children != NULL) { - dbusmenu_menuitem_child_delete (item, DBUSMENU_MENUITEM(children->data)); - children = children->next; + GList * children = dbusmenu_menuitem_take_children (item); + GList * child = children; + while (child != NULL) { + g_object_unref (G_OBJECT(child->data)); + child = child->next; } + g_list_free(children); } /* Now parse new submenu. */ -- cgit v1.2.3 From 74a0afebe8d3c1fa28d969739ea5c718f00e8c0d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 31 Jan 2011 12:08:57 -0600 Subject: Handle the case where we don't have a cached item. Not sure how that'd be, but we shouldn't let it drop. --- libdbusmenu-gtk/parser.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 4941bf4..7e5e7e1 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -666,11 +666,19 @@ widget_notify_cb (GtkWidget *widget, } /* Now parse new submenu. */ - GtkWidget * menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget)); RecurseContext recurse = {0}; recurse.toplevel = gtk_widget_get_toplevel(widget); recurse.parent = item; - parse_menu_structure_helper(menu, &recurse); + + if (item != NULL) { + GtkWidget * menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget)); + parse_menu_structure_helper(menu, &recurse); + } else { + /* Note: it would be really odd that we wouldn't have a cached + item, but we should handle that appropriately. */ + parse_menu_structure_helper(widget, &recurse); + g_object_unref(G_OBJECT(recurse.parent)); + } } } -- cgit v1.2.3 From a3da704b473f3ab75786501a6ec20d7b735fe8d9 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 2 Feb 2011 13:44:53 -0500 Subject: disconnect signals when done with menuitem --- libdbusmenu-gtk/parser.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 7e5e7e1..317dba2 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -102,6 +102,21 @@ dbusmenu_cache_freed (gpointer data, GObject * obj) the weak ref as well. */ g_object_steal_data(G_OBJECT(data), CACHED_MENUITEM); g_signal_handlers_disconnect_by_func(data, G_CALLBACK(widget_notify_cb), obj); + + GtkWidget *widget = GTK_WIDGET(data); + GtkWidget *label = find_menu_label (widget); + if (label != NULL) { + g_signal_handlers_disconnect_by_func(label, G_CALLBACK(label_notify_cb), obj); + } + + if (GTK_IS_ACTIVATABLE (widget)) { + GtkAction *action = gtk_activatable_get_related_action (GTK_ACTIVATABLE (widget)); + + if (action) { + g_signal_handlers_disconnect_by_func(action, G_CALLBACK(action_notify_cb), obj); + } + } + return; } -- cgit v1.2.3 From 51e68e1efe0eff4de283d2a0095357115ae514f4 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Thu, 3 Feb 2011 08:43:56 -0500 Subject: keep track of objects that we set notifies for --- libdbusmenu-gtk/parser.c | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 317dba2..db1d8dd 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -31,6 +31,14 @@ License version 3 and version 2.1 along with this program. If not, see #include "serializablemenuitem.h" #define CACHED_MENUITEM "dbusmenu-gtk-parser-cached-item" +#define PARSER_DATA "dbusmenu-gtk-parser-data" + +typedef struct _ParserData +{ + GtkWidget *label; + GtkAction *action; + GtkWidget *widget; +} ParserData; typedef struct _RecurseContext { @@ -103,18 +111,21 @@ dbusmenu_cache_freed (gpointer data, GObject * obj) g_object_steal_data(G_OBJECT(data), CACHED_MENUITEM); g_signal_handlers_disconnect_by_func(data, G_CALLBACK(widget_notify_cb), obj); - GtkWidget *widget = GTK_WIDGET(data); - GtkWidget *label = find_menu_label (widget); - if (label != NULL) { - g_signal_handlers_disconnect_by_func(label, G_CALLBACK(label_notify_cb), obj); + ParserData *pdata = (ParserData *)g_object_get_data(G_OBJECT(obj), PARSER_DATA); + + if (pdata != NULL && pdata->label != NULL) { + g_signal_handlers_disconnect_by_func(pdata->label, G_CALLBACK(label_notify_cb), obj); + g_object_remove_weak_pointer(G_OBJECT(pdata->label), (gpointer*)&pdata->label); } - if (GTK_IS_ACTIVATABLE (widget)) { - GtkAction *action = gtk_activatable_get_related_action (GTK_ACTIVATABLE (widget)); + if (pdata != NULL && pdata->action != NULL) { + g_signal_handlers_disconnect_by_func(pdata->action, G_CALLBACK(action_notify_cb), obj); + g_object_remove_weak_pointer(G_OBJECT(pdata->action), (gpointer*)&pdata->action); + } - if (action) { - g_signal_handlers_disconnect_by_func(action, G_CALLBACK(action_notify_cb), obj); - } + if (pdata != NULL && pdata->widget != NULL) { + g_signal_handlers_disconnect_by_func(pdata->widget, G_CALLBACK(widget_notify_cb), obj); + g_object_remove_weak_pointer(G_OBJECT(pdata->widget), (gpointer*)&pdata->widget); } return; @@ -125,8 +136,10 @@ dbusmenu_cache_freed (gpointer data, GObject * obj) static void object_cache_freed (gpointer data) { - if (!G_IS_OBJECT(data)) return; - g_object_weak_unref(G_OBJECT(data), dbusmenu_cache_freed, data); + // TODO: make this have access to both data and obj so we can call these + //if (!G_IS_OBJECT(obj)) return; + //g_object_weak_unref(G_OBJECT(obj), dbusmenu_cache_freed, data); + //dbusmenu_cache_freed(data, obj); return; } @@ -254,6 +267,9 @@ construct_dbusmenu_for_widget (GtkWidget * widget) { DbusmenuMenuitem *mi = dbusmenu_menuitem_new (); + ParserData *pdata = g_new0 (ParserData, 1); + g_object_set_data_full (G_OBJECT (mi), PARSER_DATA, pdata, g_free); + gboolean visible = FALSE; gboolean sensitive = FALSE; if (GTK_IS_SEPARATOR_MENU_ITEM (widget)) @@ -328,10 +344,12 @@ construct_dbusmenu_for_widget (GtkWidget * widget) { // Sometimes, an app will directly find and modify the label // (like empathy), so watch the label especially for that. + pdata->label = label; g_signal_connect (G_OBJECT (label), "notify", G_CALLBACK (label_notify_cb), mi); + g_object_add_weak_pointer(G_OBJECT (label), (gpointer*)&pdata->label); } if (GTK_IS_ACTIVATABLE (widget)) @@ -347,10 +365,12 @@ construct_dbusmenu_for_widget (GtkWidget * widget) visible = gtk_action_is_visible (action); sensitive = gtk_action_is_sensitive (action); + pdata->action = action; g_signal_connect_object (action, "notify", G_CALLBACK (action_notify_cb), mi, G_CONNECT_AFTER); + g_object_add_weak_pointer(G_OBJECT (action), (gpointer*)&pdata->action); } } } @@ -382,10 +402,13 @@ construct_dbusmenu_for_widget (GtkWidget * widget) DBUSMENU_MENUITEM_PROP_ENABLED, sensitive); + pdata->widget = widget; g_signal_connect (widget, "notify", G_CALLBACK (widget_notify_cb), mi); + g_object_add_weak_pointer(G_OBJECT (widget), (gpointer*)&pdata->widget); + return mi; } -- cgit v1.2.3 From 4da7e99010b1dbf2a6f28660570e9ad79f538136 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Fri, 4 Feb 2011 14:05:52 -0500 Subject: watch for new menu items being added to existing menu shells --- libdbusmenu-gtk/parser.c | 97 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 85 insertions(+), 12 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index db1d8dd..96418b3 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -38,6 +38,7 @@ typedef struct _ParserData GtkWidget *label; GtkAction *action; GtkWidget *widget; + GtkWidget *shell; } ParserData; typedef struct _RecurseContext @@ -63,6 +64,9 @@ static void label_notify_cb (GtkWidget * widget, static void action_notify_cb (GtkAction * action, GParamSpec * pspec, gpointer data); +static void child_added_cb (GtkContainer * menu, + GtkWidget * widget, + gpointer data); static void item_activated (DbusmenuMenuitem * item, guint timestamp, gpointer user_data); @@ -109,7 +113,6 @@ dbusmenu_cache_freed (gpointer data, GObject * obj) /* If the dbusmenu item is killed we don't need to remove the weak ref as well. */ g_object_steal_data(G_OBJECT(data), CACHED_MENUITEM); - g_signal_handlers_disconnect_by_func(data, G_CALLBACK(widget_notify_cb), obj); ParserData *pdata = (ParserData *)g_object_get_data(G_OBJECT(obj), PARSER_DATA); @@ -128,6 +131,11 @@ dbusmenu_cache_freed (gpointer data, GObject * obj) g_object_remove_weak_pointer(G_OBJECT(pdata->widget), (gpointer*)&pdata->widget); } + if (pdata != NULL && pdata->shell != NULL) { + g_signal_handlers_disconnect_by_func(pdata->shell, G_CALLBACK(child_added_cb), obj); + g_object_remove_weak_pointer(G_OBJECT(pdata->shell), (gpointer*)&pdata->shell); + } + return; } @@ -143,6 +151,45 @@ object_cache_freed (gpointer data) return; } +static gint +get_child_position (GtkWidget * child) +{ + GtkWidget * parent = gtk_widget_get_parent (child); + if (parent == NULL || !GTK_IS_CONTAINER (parent)) + return -1; + + GList * children = gtk_container_get_children (GTK_CONTAINER (parent)); + GList * iter; + gint position = 0; + + for (iter = children; iter != NULL; iter = iter->next) { + if (iter->data == child) + break; + ++position; + } + + g_list_free (children); + + if (iter == NULL) + return -1; + else + return position; +} + +static DbusmenuMenuitem * +new_menuitem (GtkWidget * widget) +{ + DbusmenuMenuitem * item = dbusmenu_menuitem_new(); + + ParserData *pdata = g_new0 (ParserData, 1); + g_object_set_data_full(G_OBJECT(item), PARSER_DATA, pdata, g_free); + + g_object_set_data_full(G_OBJECT(widget), CACHED_MENUITEM, item, object_cache_freed); + g_object_weak_ref(G_OBJECT(item), dbusmenu_cache_freed, widget); + + return item; +} + static void parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) { @@ -161,10 +208,11 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) */ if (recurse->parent == NULL && GTK_IS_MENU_BAR(widget)) { GList *children = gtk_container_get_children (GTK_CONTAINER (widget)); + GList *iter; - for (; children != NULL; children = children->next) { + for (iter = children; iter != NULL; iter = iter->next) { gtk_menu_shell_activate_item (GTK_MENU_SHELL (widget), - children->data, + iter->data, TRUE); } @@ -172,9 +220,18 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) } if (recurse->parent == NULL) { - recurse->parent = dbusmenu_menuitem_new(); + recurse->parent = new_menuitem(widget); } + ParserData *pdata = (ParserData *)g_object_get_data(G_OBJECT(recurse->parent), PARSER_DATA); + + pdata->shell = widget; + g_signal_connect (G_OBJECT (widget), + "child-added", + G_CALLBACK (child_added_cb), + recurse->parent); + g_object_add_weak_pointer(G_OBJECT (widget), (gpointer*)&pdata->shell); + gtk_container_foreach (GTK_CONTAINER (widget), (GtkCallback)parse_menu_structure_helper, recurse); @@ -194,8 +251,6 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) /* We don't have one, so we'll need to build it */ if (thisitem == NULL) { thisitem = construct_dbusmenu_for_widget (widget); - g_object_set_data_full(G_OBJECT(widget), CACHED_MENUITEM, thisitem, object_cache_freed); - g_object_weak_ref(G_OBJECT(thisitem), dbusmenu_cache_freed, widget); if (!gtk_widget_get_visible (widget)) { g_signal_connect (G_OBJECT (widget), @@ -227,8 +282,14 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) g_object_set_data (G_OBJECT (thisitem), "dbusmenu-parent", recurse->parent); - dbusmenu_menuitem_child_append (recurse->parent, - thisitem); + gint pos = get_child_position (widget); + if (pos >= 0) + dbusmenu_menuitem_child_add_position (recurse->parent, + thisitem, + pos); + else + dbusmenu_menuitem_child_append (recurse->parent, + thisitem); } } @@ -265,10 +326,9 @@ construct_dbusmenu_for_widget (GtkWidget * widget) /* If it's a standard GTK Menu Item we need to do some of our own work */ if (GTK_IS_MENU_ITEM (widget)) { - DbusmenuMenuitem *mi = dbusmenu_menuitem_new (); + DbusmenuMenuitem *mi = new_menuitem(widget); - ParserData *pdata = g_new0 (ParserData, 1); - g_object_set_data_full (G_OBJECT (mi), PARSER_DATA, pdata, g_free); + ParserData *pdata = (ParserData *)g_object_get_data(G_OBJECT(mi), PARSER_DATA); gboolean visible = FALSE; gboolean sensitive = FALSE; @@ -414,7 +474,7 @@ construct_dbusmenu_for_widget (GtkWidget * widget) /* If it's none of those we're going to just create a generic menuitem as a place holder for it. */ - return dbusmenu_menuitem_new(); + return new_menuitem(widget); } static void @@ -720,6 +780,19 @@ widget_notify_cb (GtkWidget *widget, } } +/* A child item was added to a menu we're watching. Let's try to integrate it. */ +static void +child_added_cb (GtkContainer *menu, GtkWidget *widget, gpointer data) +{ + DbusmenuMenuitem *menuitem = (DbusmenuMenuitem *)data; + + RecurseContext recurse = {0}; + recurse.toplevel = gtk_widget_get_toplevel(GTK_WIDGET(menu)); + recurse.parent = menuitem; + + parse_menu_structure_helper(widget, &recurse); +} + static gboolean should_show_image (GtkImage *image) { -- cgit v1.2.3 From 0ee9e9fe667565a0f141694447599aac39e2c310 Mon Sep 17 00:00:00 2001 From: Ken VanDine Date: Wed, 9 Feb 2011 12:45:41 -0500 Subject: Fix the name used for the Dbusmenu-Glib-0.4 typelib so it can be properly used with GI. It should be Dbusmenu-0.4 (LP: #713099) --- libdbusmenu-glib/Makefile.am | 26 +++++++++++++------------- libdbusmenu-gtk/Makefile.am | 4 ++-- 2 files changed, 15 insertions(+), 15 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-glib/Makefile.am b/libdbusmenu-glib/Makefile.am index a139f7c..e6877b6 100644 --- a/libdbusmenu-glib/Makefile.am +++ b/libdbusmenu-glib/Makefile.am @@ -138,18 +138,18 @@ if HAVE_INTROSPECTION introspection_sources = $(libdbusmenu_glibinclude_HEADERS) -Dbusmenu_Glib-0.4.gir: libdbusmenu-glib.la -Dbusmenu_Glib_0_4_gir_INCLUDES = \ +Dbusmenu-0.4.gir: libdbusmenu-glib.la +Dbusmenu_0_4_gir_INCLUDES = \ GObject-2.0 -Dbusmenu_Glib_0_4_gir_CFLAGS = $(DBUSMENUGLIB_CFLAGS) -I$(top_srcdir) -Dbusmenu_Glib_0_4_gir_LIBS = libdbusmenu-glib.la -Dbusmenu_Glib_0_4_gir_FILES = $(addprefix $(srcdir)/, $(introspection_sources)) -Dbusmenu_Glib_0_4_gir_NAMESPACE = Dbusmenu -Dbusmenu_Glib_0_4_gir_VERSION = Glib-0.4 -Dbusmenu_Glib_0_4_gir_EXPORT_PACKAGES = dbusmenu-glib-0.4 -Dbusmenu_Glib_0_4_gir_SCANNER_FLAGS = $(INTROSPECTION_SCANNER_ARGS) +Dbusmenu_0_4_gir_CFLAGS = $(DBUSMENUGLIB_CFLAGS) -I$(top_srcdir) +Dbusmenu_0_4_gir_LIBS = libdbusmenu-glib.la +Dbusmenu_0_4_gir_FILES = $(addprefix $(srcdir)/, $(introspection_sources)) +Dbusmenu_0_4_gir_NAMESPACE = Dbusmenu +Dbusmenu_0_4_gir_VERSION = 0.4 +Dbusmenu_0_4_gir_EXPORT_PACKAGES = dbusmenu-glib-0.4 +Dbusmenu_0_4_gir_SCANNER_FLAGS = $(INTROSPECTION_SCANNER_ARGS) -INTROSPECTION_GIRS += Dbusmenu-Glib-0.4.gir +INTROSPECTION_GIRS += Dbusmenu-0.4.gir girdir = $(datadir)/gir-1.0 gir_DATA = $(INTROSPECTION_GIRS) @@ -168,10 +168,10 @@ endif if HAVE_INTROSPECTION vapidir = $(datadir)/vala/vapi -vapi_DATA = Dbusmenu-Glib-0.4.vapi +vapi_DATA = Dbusmenu-0.4.vapi -Dbusmenu-Glib-0.4.vapi: Dbusmenu-Glib-0.4.gir - $(VALA_API_GEN) --library=Dbusmenu-Glib-0.4 $< +Dbusmenu-0.4.vapi: Dbusmenu-0.4.gir + $(VALA_API_GEN) --library=Dbusmenu-0.4 $< CLEANFILES += $(vapi_DATA) diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index f3556e9..f66f1f5 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -98,7 +98,7 @@ DbusmenuGtk$(VER)-0.4.gir: libdbusmenu-gtk$(VER).la DbusmenuGtk_0_4_gir_INCLUDES = \ GObject-2.0 \ $(GTKGIR) \ - Dbusmenu-Glib-0.4 + Dbusmenu-0.4 DbusmenuGtk_0_4_gir_CFLAGS = $(DBUSMENUGTK_CFLAGS) -I$(top_srcdir) DbusmenuGtk_0_4_gir_LIBS = libdbusmenu-gtk$(VER).la DbusmenuGtk_0_4_gir_FILES = $(addprefix $(srcdir)/, $(introspection_sources)) @@ -141,7 +141,7 @@ DbusmenuGtk$(VER)-0.4.vapi: DbusmenuGtk$(VER)-0.4.tmp.gir Makefile.am --pkg gdk-pixbuf-2.0 \ --pkg $(GTKVALA) \ --pkg atk \ - --pkg Dbusmenu-Glib-0.4 \ + --pkg Dbusmenu-0.4 \ --vapidir=$(top_builddir)/libdbusmenu-glib \ $< -- cgit v1.2.3 From e342bd662608d2557bb79d6d6cea5947a58fb09f Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Thu, 10 Feb 2011 18:27:40 -0500 Subject: fix icon usage -- watch more signals, handle gicons, respect always-show-image better --- libdbusmenu-gtk/parser.c | 234 +++++++++++++++++++++++++++++------------------ 1 file changed, 146 insertions(+), 88 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 70cde53..38528d8 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -39,6 +39,7 @@ typedef struct _ParserData GtkAction *action; GtkWidget *widget; GtkWidget *shell; + GtkWidget *image; } ParserData; typedef struct _RecurseContext @@ -51,22 +52,25 @@ static void parse_menu_structure_helper (GtkWidget * widget, RecurseContext * re static DbusmenuMenuitem * construct_dbusmenu_for_widget (GtkWidget * widget); static void accel_changed (GtkWidget * widget, gpointer data); -static gboolean update_stock_item (DbusmenuMenuitem * menuitem, - GtkWidget * widget); static void checkbox_toggled (GtkWidget * widget, DbusmenuMenuitem * mi); -static void update_icon_name (DbusmenuMenuitem * menuitem, - GtkWidget * widget); +static void update_icon (DbusmenuMenuitem * menuitem, + GtkImage * image); static GtkWidget * find_menu_label (GtkWidget * widget); static void label_notify_cb (GtkWidget * widget, GParamSpec * pspec, gpointer data); +static void image_notify_cb (GtkWidget * widget, + GParamSpec * pspec, + gpointer data); static void action_notify_cb (GtkAction * action, GParamSpec * pspec, gpointer data); static void child_added_cb (GtkContainer * menu, GtkWidget * widget, gpointer data); +static void theme_changed_cb (GtkIconTheme * theme, + gpointer data); static void item_activated (DbusmenuMenuitem * item, guint timestamp, gpointer user_data); @@ -136,6 +140,11 @@ dbusmenu_cache_freed (gpointer data, GObject * obj) g_object_remove_weak_pointer(G_OBJECT(pdata->shell), (gpointer*)&pdata->shell); } + if (pdata != NULL && pdata->image != NULL) { + g_signal_handlers_disconnect_by_func(pdata->image, G_CALLBACK(image_notify_cb), obj); + g_object_remove_weak_pointer(G_OBJECT(pdata->image), (gpointer*)&pdata->image); + } + return; } @@ -148,6 +157,9 @@ object_cache_freed (gpointer data) //if (!G_IS_OBJECT(obj)) return; //g_object_weak_unref(G_OBJECT(obj), dbusmenu_cache_freed, data); //dbusmenu_cache_freed(data, obj); + + g_signal_handlers_disconnect_by_func(gtk_icon_theme_get_default(), G_CALLBACK(theme_changed_cb), data); + return; } @@ -347,8 +359,6 @@ construct_dbusmenu_for_widget (GtkWidget * widget) } else { - gboolean label_set = FALSE; - g_signal_connect (widget, "accel-closures-changed", G_CALLBACK (accel_changed), @@ -373,41 +383,37 @@ construct_dbusmenu_for_widget (GtkWidget * widget) if (GTK_IS_IMAGE_MENU_ITEM (widget)) { GtkWidget *image; - GtkImageType image_type; image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (widget)); if (GTK_IS_IMAGE (image)) { - image_type = gtk_image_get_storage_type (GTK_IMAGE (image)); - - if (image_type == GTK_IMAGE_STOCK) - { - label_set = update_stock_item (mi, image); - } - else if (image_type == GTK_IMAGE_ICON_NAME) - { - update_icon_name (mi, image); - } - else if (image_type == GTK_IMAGE_PIXBUF) - { - dbusmenu_menuitem_property_set_image (mi, - DBUSMENU_MENUITEM_PROP_ICON_DATA, - gtk_image_get_pixbuf (GTK_IMAGE (image))); - } + update_icon (mi, GTK_IMAGE (image)); + + /* Watch for theme changes because if gicon changes, we want to send a + different pixbuf. */ + g_signal_connect(G_OBJECT(gtk_icon_theme_get_default()), + "changed", G_CALLBACK(theme_changed_cb), widget); + + pdata->image = image; + g_signal_connect (G_OBJECT (image), + "notify", + G_CALLBACK (image_notify_cb), + mi); + g_object_add_weak_pointer(G_OBJECT (image), (gpointer*)&pdata->image); } } GtkWidget *label = find_menu_label (widget); - dbusmenu_menuitem_property_set (mi, - "label", - label ? gtk_label_get_text (GTK_LABEL (label)) : NULL); - if (label) { // Sometimes, an app will directly find and modify the label // (like empathy), so watch the label especially for that. + dbusmenu_menuitem_property_set (mi, + "label", + gtk_label_get_text (GTK_LABEL (label))); + pdata->label = label; g_signal_connect (G_OBJECT (label), "notify", @@ -510,48 +516,6 @@ accel_changed (GtkWidget *widget, dbusmenu_menuitem_property_set_shortcut_menuitem (mi, GTK_MENU_ITEM (widget)); } -static gboolean -update_stock_item (DbusmenuMenuitem *menuitem, - GtkWidget *widget) -{ - GtkStockItem stock; - GtkImage *image; - - g_return_val_if_fail (GTK_IS_IMAGE (widget), FALSE); - - image = GTK_IMAGE (widget); - - if (gtk_image_get_storage_type (image) != GTK_IMAGE_STOCK) - return FALSE; - - gchar * stock_id = NULL; - gtk_image_get_stock(image, &stock_id, NULL); - - gtk_stock_lookup (stock_id, &stock); - - if (should_show_image (image)) - dbusmenu_menuitem_property_set (menuitem, - DBUSMENU_MENUITEM_PROP_ICON_NAME, - stock_id); - else - dbusmenu_menuitem_property_remove (menuitem, - DBUSMENU_MENUITEM_PROP_ICON_NAME); - - const gchar *label = dbusmenu_menuitem_property_get (menuitem, - DBUSMENU_MENUITEM_PROP_LABEL); - - if (stock.label != NULL && label != NULL) - { - dbusmenu_menuitem_property_set (menuitem, - DBUSMENU_MENUITEM_PROP_LABEL, - stock.label); - - return TRUE; - } - - return FALSE; -} - static void checkbox_toggled (GtkWidget *widget, DbusmenuMenuitem *mi) { @@ -561,27 +525,82 @@ checkbox_toggled (GtkWidget *widget, DbusmenuMenuitem *mi) } static void -update_icon_name (DbusmenuMenuitem *menuitem, - GtkWidget *widget) +update_icon (DbusmenuMenuitem *menuitem, GtkImage *image) { - GtkImage *image; - - g_return_if_fail (GTK_IS_IMAGE (widget)); - - image = GTK_IMAGE (widget); + GdkPixbuf * pixbuf = NULL; + const gchar * icon_name = NULL; + GtkStockItem stock; + GIcon * gicon; + GtkIconInfo * info; + gint width; + + if (image != NULL && should_show_image (image)) { + switch (gtk_image_get_storage_type (image)) { + case GTK_IMAGE_PIXBUF: + pixbuf = g_object_ref (gtk_image_get_pixbuf (image)); + break; + + case GTK_IMAGE_ICON_NAME: + gtk_image_get_icon_name (image, &icon_name, NULL); + break; + + case GTK_IMAGE_STOCK: + gtk_image_get_stock (image, (gchar **) &icon_name, NULL); + if (gtk_stock_lookup (icon_name, &stock)) { + /* Now set label too */ + const gchar * label = NULL; + label = dbusmenu_menuitem_property_get (menuitem, + DBUSMENU_MENUITEM_PROP_LABEL); + if (stock.label != NULL && label != NULL) { + dbusmenu_menuitem_property_set (menuitem, + DBUSMENU_MENUITEM_PROP_LABEL, + stock.label); + } + } + break; + + case GTK_IMAGE_GICON: + /* Load up a pixbuf and send that over. We don't bother differentiating + between icon-name gicons and pixbuf gicons because even when given a + icon-name gicon, there's no easy way to lookup which icon-name among + its set is present and should be used among the icon themes available. + So instead, we render to a pixbuf and watch icon theme changes. */ + gtk_image_get_gicon (image, &gicon, NULL); + gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, NULL); + info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default (), + gicon, width, + GTK_ICON_LOOKUP_FORCE_SIZE); + if (info != NULL) { + pixbuf = gtk_icon_info_load_icon (info, NULL); + gtk_icon_info_free (info); + } + break; - if (gtk_image_get_storage_type (image) != GTK_IMAGE_ICON_NAME) - return; + default: + g_debug ("Could not handle image type %i\n", gtk_image_get_storage_type (image)); + break; + } + } - if (should_show_image (image)) { - const gchar * icon_name = NULL; - gtk_image_get_icon_name(image, &icon_name, NULL); + if (icon_name != NULL) { dbusmenu_menuitem_property_set (menuitem, DBUSMENU_MENUITEM_PROP_ICON_NAME, icon_name); - } else { + } + else if (pixbuf != NULL) { + dbusmenu_menuitem_property_set_image (menuitem, + DBUSMENU_MENUITEM_PROP_ICON_DATA, + pixbuf); + } + else { dbusmenu_menuitem_property_remove (menuitem, DBUSMENU_MENUITEM_PROP_ICON_NAME); + dbusmenu_menuitem_property_remove (menuitem, + DBUSMENU_MENUITEM_PROP_ICON_DATA); + } + + if (pixbuf != NULL) { + g_object_unref (pixbuf); } } @@ -629,6 +648,29 @@ label_notify_cb (GtkWidget *widget, } } +static void +image_notify_cb (GtkWidget *widget, + GParamSpec *pspec, + gpointer data) +{ + DbusmenuMenuitem *mi = (DbusmenuMenuitem *)data; + + if (pspec->name == g_intern_static_string ("file") || + pspec->name == g_intern_static_string ("gicon") || + pspec->name == g_intern_static_string ("icon-name") || + pspec->name == g_intern_static_string ("icon-set") || + pspec->name == g_intern_static_string ("image") || + pspec->name == g_intern_static_string ("mask") || + pspec->name == g_intern_static_string ("pixbuf") || + pspec->name == g_intern_static_string ("pixbuf-animation") || + pspec->name == g_intern_static_string ("pixmap") || + pspec->name == g_intern_static_string ("stock") || + pspec->name == g_intern_static_string ("storage-type")) + { + update_icon (mi, GTK_IMAGE (widget)); + } +} + static void action_notify_cb (GtkAction *action, GParamSpec *pspec, @@ -723,13 +765,12 @@ widget_notify_cb (GtkWidget *widget, DBUSMENU_MENUITEM_PROP_VISIBLE, gtk_widget_get_visible (widget)); } - else if (pspec->name == g_intern_static_string ("stock")) - { - update_stock_item (child, widget); - } - else if (pspec->name == g_intern_static_string ("icon-name")) + else if (pspec->name == g_intern_static_string ("image") || + pspec->name == g_intern_static_string ("always-show-image")) { - update_icon_name (child, widget); + GtkWidget *image; + image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (widget)); + update_icon (child, GTK_IMAGE (image)); } else if (pspec->name == g_intern_static_string ("parent")) { @@ -797,6 +838,23 @@ child_added_cb (GtkContainer *menu, GtkWidget *widget, gpointer data) parse_menu_structure_helper(widget, &recurse); } +static void +theme_changed_cb (GtkIconTheme *theme, gpointer data) +{ + GtkWidget *image; + + image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (data)); + + gpointer pmi = g_object_get_data(G_OBJECT(data), CACHED_MENUITEM); + if (pmi != NULL) { + update_icon(DBUSMENU_MENUITEM(pmi), GTK_IMAGE(image)); + } + + /* Switch signal to new theme */ + g_signal_handlers_disconnect_by_func(theme, G_CALLBACK(theme_changed_cb), data); + g_signal_connect(gtk_icon_theme_get_default(), "changed", G_CALLBACK(theme_changed_cb), data); +} + static gboolean should_show_image (GtkImage *image) { -- cgit v1.2.3 From 98e01df8406f305f8d232cf41e5facaf559afe0f Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Wed, 16 Feb 2011 20:56:38 +0100 Subject: Fix g-ir-scanner file list for gtk Analoguous to r211 for the GTK library. --- libdbusmenu-gtk/Makefile.am | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am index f66f1f5..50a8f2c 100644 --- a/libdbusmenu-gtk/Makefile.am +++ b/libdbusmenu-gtk/Makefile.am @@ -78,21 +78,21 @@ if INTROSPECTION_TEN INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) \ --warn-all \ --add-include-path=$(top_builddir)/libdbusmenu-glib \ - $(addprefix --c-include=libdbusmenu-gtk/, $(introspection_sources)) \ + $(addprefix --c-include=libdbusmenu-gtk/, $(libdbusmenu_gtkinclude_HEADERS)) \ --symbol-prefix=dbusmenu \ --identifier-prefix=DbusmenuGtk else INTROSPECTION_SCANNER_ARGS = --add-include-path=$(srcdir) \ --warn-all \ --add-include-path=$(top_builddir)/libdbusmenu-glib \ - $(addprefix --c-include=libdbusmenu-gtk/, $(introspection_sources)) + $(addprefix --c-include=libdbusmenu-gtk/, $(libdbusmenu_gtkinclude_HEADERS)) endif INTROSPECTION_COMPILER_ARGS = --includedir=$(builddir) --includedir=$(top_builddir)/libdbusmenu-glib if HAVE_INTROSPECTION -introspection_sources = $(libdbusmenu_gtkinclude_HEADERS) +introspection_sources = $(filter-out genericmenuitem.%, $(libdbusmenu_gtkinclude_HEADERS) $(libdbusmenu_gtk_la_SOURCES)) DbusmenuGtk$(VER)-0.4.gir: libdbusmenu-gtk$(VER).la DbusmenuGtk_0_4_gir_INCLUDES = \ -- cgit v1.2.3 From 558fa9265c05452de03ddd9f8543dfdce1b81e7b Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Wed, 16 Feb 2011 21:06:14 +0100 Subject: Fix GI annotations for DbusmenuGtk --- libdbusmenu-gtk/client.c | 110 +++++++++++++++--------------- libdbusmenu-gtk/genericmenuitem.c | 52 +++++++------- libdbusmenu-gtk/menu.c | 34 +++++----- libdbusmenu-gtk/menuitem.c | 120 ++++++++++++++++----------------- libdbusmenu-gtk/menuitem.h | 2 +- libdbusmenu-gtk/parser.c | 20 +++--- libdbusmenu-gtk/serializablemenuitem.c | 62 ++++++++--------- 7 files changed, 200 insertions(+), 200 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 7ab2fe9..4128b02 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -219,13 +219,13 @@ refresh_shortcut (DbusmenuGtkClient * client, DbusmenuMenuitem * mi) /** - dbusmenu_gtkclient_set_accel_group: - @client: To set the group on - @agroup: The new acceleration group - - Sets the acceleration group for the menu items with accelerators - on this client. -*/ + * dbusmenu_gtkclient_set_accel_group: + * @client: To set the group on + * @agroup: The new acceleration group + * + * Sets the acceleration group for the menu items with accelerators + * on this client. + */ void dbusmenu_gtkclient_set_accel_group (DbusmenuGtkClient * client, GtkAccelGroup * agroup) { @@ -256,14 +256,14 @@ dbusmenu_gtkclient_set_accel_group (DbusmenuGtkClient * client, GtkAccelGroup * } /** - dbusmenu_gtkclient_get_accel_group: - @client: Client to query for an accelerator group - - Gets the accel group for this client. - - Return value: Either a valid group or #NULL on error or - none set. -*/ + * dbusmenu_gtkclient_get_accel_group: + * @client: Client to query for an accelerator group + * + * Gets the accel group for this client. + * + * Return value: (transfer none): Either a valid group or #NULL on error or + * none set. + */ GtkAccelGroup * dbusmenu_gtkclient_get_accel_group (DbusmenuGtkClient * client) { @@ -493,21 +493,21 @@ destroy_gmi (GtkMenuItem * gmi, DbusmenuMenuitem * mi) #endif /** - dbusmenu_gtkclient_newitem_base: - @client: The client handling everything on this connection - @item: The #DbusmenuMenuitem to attach the GTK-isms to - @gmi: A #GtkMenuItem representing the GTK world's view of this menuitem - @parent: The parent #DbusmenuMenuitem - - This function provides some of the basic connectivity for being in - the GTK world. Things like visibility and sensitivity of the item are - handled here so that the subclasses don't have to. If you're building - your on GTK menu item you can use this function to apply those basic - attributes so that you don't have to deal with them either. - - This also handles passing the "activate" signal back to the - #DbusmenuMenuitem side of thing. -*/ + * dbusmenu_gtkclient_newitem_base: + * @client: The client handling everything on this connection + * @item: The #DbusmenuMenuitem to attach the GTK-isms to + * @gmi: A #GtkMenuItem representing the GTK world's view of this menuitem + * @parent: The parent #DbusmenuMenuitem + * + * This function provides some of the basic connectivity for being in + * the GTK world. Things like visibility and sensitivity of the item are + * handled here so that the subclasses don't have to. If you're building + * your on GTK menu item you can use this function to apply those basic + * attributes so that you don't have to deal with them either. + * + * This also handles passing the "activate" signal back to the + * #DbusmenuMenuitem side of thing. + */ void dbusmenu_gtkclient_newitem_base (DbusmenuGtkClient * client, DbusmenuMenuitem * item, GtkMenuItem * gmi, DbusmenuMenuitem * parent) { @@ -617,15 +617,15 @@ move_child (DbusmenuMenuitem * mi, DbusmenuMenuitem * child, guint new, guint ol /* Public API */ /** - dbusmenu_gtkclient_new: - @dbus_name: Name of the #DbusmenuServer on DBus - @dbus_name: Name of the object on the #DbusmenuServer - - Creates a new #DbusmenuGtkClient object and creates a #DbusmenuClient - that connects across DBus to a #DbusmenuServer. - - Return value: A new #DbusmenuGtkClient sync'd with a server -*/ + * dbusmenu_gtkclient_new: + * @dbus_name: Name of the #DbusmenuServer on DBus + * @dbus_name: Name of the object on the #DbusmenuServer + * + * Creates a new #DbusmenuGtkClient object and creates a #DbusmenuClient + * that connects across DBus to a #DbusmenuServer. + * + * Return value: A new #DbusmenuGtkClient sync'd with a server + */ DbusmenuGtkClient * dbusmenu_gtkclient_new (gchar * dbus_name, gchar * dbus_object) { @@ -636,15 +636,15 @@ dbusmenu_gtkclient_new (gchar * dbus_name, gchar * dbus_object) } /** - dbusmenu_gtkclient_menuitem_get: - @client: A #DbusmenuGtkClient with the item in it. - @item: #DbusmenuMenuitem to get associated #GtkMenuItem on. - - This grabs the #GtkMenuItem that is associated with the - #DbusmenuMenuitem. - - Return value: The #GtkMenuItem that can be played with. -*/ + * dbusmenu_gtkclient_menuitem_get: + * @client: A #DbusmenuGtkClient with the item in it. + * @item: #DbusmenuMenuitem to get associated #GtkMenuItem on. + * + * This grabs the #GtkMenuItem that is associated with the + * #DbusmenuMenuitem. + * + * Return value: (transfer none): The #GtkMenuItem that can be played with. + */ GtkMenuItem * dbusmenu_gtkclient_menuitem_get (DbusmenuGtkClient * client, DbusmenuMenuitem * item) { @@ -660,13 +660,13 @@ dbusmenu_gtkclient_menuitem_get (DbusmenuGtkClient * client, DbusmenuMenuitem * } /** - dbusmenu_gtkclient_menuitem_get_submenu: - @client: A #DbusmenuGtkClient with the item in it. - @item: #DbusmenuMenuitem to get associated #GtkMenu on. - - This grabs the submenu associated with the menuitem. - - Return value: The #GtkMenu if there is one. + * dbusmenu_gtkclient_menuitem_get_submenu: + * @client: A #DbusmenuGtkClient with the item in it. + * @item: #DbusmenuMenuitem to get associated #GtkMenu on. + * + * This grabs the submenu associated with the menuitem. + * + * Return value: (transfer none): The #GtkMenu if there is one. */ GtkMenu * dbusmenu_gtkclient_menuitem_get_submenu (DbusmenuGtkClient * client, DbusmenuMenuitem * item) diff --git a/libdbusmenu-gtk/genericmenuitem.c b/libdbusmenu-gtk/genericmenuitem.c index 2af70f3..2fd6fba 100644 --- a/libdbusmenu-gtk/genericmenuitem.c +++ b/libdbusmenu-gtk/genericmenuitem.c @@ -278,12 +278,12 @@ activate (GtkMenuItem * menu_item) } /** - genericmenuitem_set_check_type: - @item: #Genericmenuitem to set the type on - @check_type: Which type of check should be displayed - - This function changes the type of the checkmark that - appears in the left hand gutter for the menuitem. + * genericmenuitem_set_check_type: + * @item: #Genericmenuitem to set the type on + * @check_type: Which type of check should be displayed + * + * This function changes the type of the checkmark that + * appears in the left hand gutter for the menuitem. */ void genericmenuitem_set_check_type (Genericmenuitem * item, GenericmenuitemCheckType check_type) @@ -317,14 +317,14 @@ genericmenuitem_set_check_type (Genericmenuitem * item, GenericmenuitemCheckType } /** - genericmenuitem_set_state: - @item: #Genericmenuitem to set the type on - @check_type: What is the state of the check - - Sets the state of the check in the menu item. It does - not require, but isn't really useful if the type of - check that the menuitem is set to #GENERICMENUITEM_CHECK_TYPE_NONE. -*/ + * genericmenuitem_set_state: + * @item: #Genericmenuitem to set the type on + * @check_type: What is the state of the check + * + * Sets the state of the check in the menu item. It does + * not require, but isn't really useful if the type of + * check that the menuitem is set to #GENERICMENUITEM_CHECK_TYPE_NONE. + */ void genericmenuitem_set_state (Genericmenuitem * item, GenericmenuitemState state) { @@ -377,11 +377,11 @@ set_image_helper (GtkWidget * widget, gpointer data) } /** - genericmenuitem_set_image: - @item: A #Genericmenuitem - @image: The image to set as the image of @item - - Sets the image of the menu item. + * genericmenuitem_set_image: + * @item: A #Genericmenuitem + * @image: The image to set as the image of @item + * + * Sets the image of the menu item. */ void genericmenuitem_set_image (Genericmenuitem * menu_item, GtkWidget * image) @@ -439,13 +439,13 @@ genericmenuitem_set_image (Genericmenuitem * menu_item, GtkWidget * image) } /** - genericmenuitem_get_image: - @item: A #Genericmenuitem - - Returns the image if there is one. - - Return value: A pointer to the image of the item or #NULL - if there isn't one. + * genericmenuitem_get_image: + * @item: A #Genericmenuitem + * + * Returns the image if there is one. + * + * Return value: (transfer none): A pointer to the image of the item or #NULL + * if there isn't one. */ GtkWidget * genericmenuitem_get_image (Genericmenuitem * menu_item) diff --git a/libdbusmenu-gtk/menu.c b/libdbusmenu-gtk/menu.c index 2a27fe2..9788ffc 100644 --- a/libdbusmenu-gtk/menu.c +++ b/libdbusmenu-gtk/menu.c @@ -398,15 +398,15 @@ build_client (DbusmenuGtkMenu * self) /* Public API */ /** - dbusmenu_gtkmenu_new: - @dbus_name: Name of the #DbusmenuServer on DBus - @dbus_name: Name of the object on the #DbusmenuServer - - Creates a new #DbusmenuGtkMenu object and creates a #DbusmenuClient - that connects across DBus to a #DbusmenuServer. - - Return value: A new #DbusmenuGtkMenu sync'd with a server -*/ + * dbusmenu_gtkmenu_new: + * @dbus_name: Name of the #DbusmenuServer on DBus + * @dbus_name: Name of the object on the #DbusmenuServer + * + * Creates a new #DbusmenuGtkMenu object and creates a #DbusmenuClient + * that connects across DBus to a #DbusmenuServer. + * + * Return value: A new #DbusmenuGtkMenu sync'd with a server + */ DbusmenuGtkMenu * dbusmenu_gtkmenu_new (gchar * dbus_name, gchar * dbus_object) { @@ -417,14 +417,14 @@ dbusmenu_gtkmenu_new (gchar * dbus_name, gchar * dbus_object) } /** - dbusmenu_gtkmenu_get_client: - @menu: The #DbusmenuGtkMenu to get the client from - - An accessor for the client that this menu is using to - communicate with the server. - - Return value: A valid #DbusmenuGtkClient or NULL on error. -*/ + * dbusmenu_gtkmenu_get_client: + * @menu: The #DbusmenuGtkMenu to get the client from + * + * An accessor for the client that this menu is using to + * communicate with the server. + * + * Return value: (transfer none): A valid #DbusmenuGtkClient or NULL on error. + */ DbusmenuGtkClient * dbusmenu_gtkmenu_get_client (DbusmenuGtkMenu * menu) { diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index fa5eb89..4e92961 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -31,17 +31,17 @@ License version 3 and version 2.1 along with this program. If not, see #include /** - dbusmenu_menuitem_property_set_image: - @menuitem: The #DbusmenuMenuitem to set the property on. - @property: Name of the property to set. - @data: The image to place on the property. - - This function takes the pixbuf that is stored in @data and - turns it into a base64 encoded PNG so that it can be placed - onto a standard #DbusmenuMenuitem property. - - Return value: Whether the function was able to set the property - or not. + * dbusmenu_menuitem_property_set_image: + * @menuitem: The #DbusmenuMenuitem to set the property on. + * @property: Name of the property to set. + * @data: The image to place on the property. + * + * This function takes the pixbuf that is stored in @data and + * turns it into a base64 encoded PNG so that it can be placed + * onto a standard #DbusmenuMenuitem property. + * + * Return value: Whether the function was able to set the property + * or not. */ gboolean dbusmenu_menuitem_property_set_image (DbusmenuMenuitem * menuitem, const gchar * property, const GdkPixbuf * data) @@ -77,17 +77,17 @@ dbusmenu_menuitem_property_set_image (DbusmenuMenuitem * menuitem, const gchar * } /** - dbusmenu_menuitem_property_get_image: - @menuitem: The #DbusmenuMenuite to look for the property on - @property: The name of the property to look for. - - This function looks on the menu item for a property by the - name of @property. If one exists it tries to turn it into - a #GdkPixbuf. It assumes that the property is a base64 encoded - PNG file like the one created by #dbusmenu_menuite_property_set_image. - - Return value: A pixbuf or #NULL to signal error. -*/ + * dbusmenu_menuitem_property_get_image: + * @menuitem: The #DbusmenuMenuite to look for the property on + * @property: The name of the property to look for. + * + * This function looks on the menu item for a property by the + * name of @property. If one exists it tries to turn it into + * a #GdkPixbuf. It assumes that the property is a base64 encoded + * PNG file like the one created by #dbusmenu_menuite_property_set_image. + * + * Return value: (transfer full): A pixbuf or #NULL to signal error. + */ GdkPixbuf * dbusmenu_menuitem_property_get_image (DbusmenuMenuitem * menuitem, const gchar * property) { @@ -131,16 +131,16 @@ dbusmenu_menuitem_property_get_image (DbusmenuMenuitem * menuitem, const gchar * } /** - dbusmenu_menuitem_property_set_shortcut_string: - @menuitem: The #DbusmenuMenuitem to set the shortcut on - @shortcut: String describing the shortcut - - This function takes a GTK shortcut string as defined in - #gtk_accelerator_parse and turns that into the information - required to send it over DBusmenu. - - Return value: Whether it was successful at setting the property. -*/ + * dbusmenu_menuitem_property_set_shortcut_string: + * @menuitem: The #DbusmenuMenuitem to set the shortcut on + * @shortcut: String describing the shortcut + * + * This function takes a GTK shortcut string as defined in + * #gtk_accelerator_parse and turns that into the information + * required to send it over DBusmenu. + * + * Return value: Whether it was successful at setting the property. + */ gboolean dbusmenu_menuitem_property_set_shortcut_string (DbusmenuMenuitem * menuitem, const gchar * shortcut) { @@ -161,16 +161,16 @@ dbusmenu_menuitem_property_set_shortcut_string (DbusmenuMenuitem * menuitem, con } /** - dbusmenu_menuitem_property_set_shortcut: - @menuitem: The #DbusmenuMenuitem to set the shortcut on - @key: The keycode of the key to send - @modifier: A bitmask of modifiers used to activate the item - - Takes the modifer described by @key and @modifier and places that into - the format sending across Dbus for shortcuts. - - Return value: Whether it was successful at setting the property. -*/ + * dbusmenu_menuitem_property_set_shortcut: + * @menuitem: The #DbusmenuMenuitem to set the shortcut on + * @key: The keycode of the key to send + * @modifier: A bitmask of modifiers used to activate the item + * + * Takes the modifer described by @key and @modifier and places that into + * the format sending across Dbus for shortcuts. + * + * Return value: Whether it was successful at setting the property. + */ gboolean dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, guint key, GdkModifierType modifier) { @@ -213,16 +213,16 @@ find_closure (GtkAccelKey * key, GClosure * closure, gpointer user_data) } /** - dbusmenu_menuitem_property_set_shortcut_menuitem: - @menuitem: The #DbusmenuMenuitem to set the shortcut on - @gmi: A menu item to steal the shortcut off of - - Takes the shortcut that is installed on a menu item and calls - #dbusmenu_menuitem_property_set_shortcut with it. It also sets - up listeners to watch it change. - - Return value: Whether it was successful at setting the property. -*/ + * dbusmenu_menuitem_property_set_shortcut_menuitem: + * @menuitem: The #DbusmenuMenuitem to set the shortcut on + * @gmi: A menu item to steal the shortcut off of + * + * Takes the shortcut that is installed on a menu item and calls + * #dbusmenu_menuitem_property_set_shortcut with it. It also sets + * up listeners to watch it change. + * + * Return value: Whether it was successful at setting the property. + */ gboolean dbusmenu_menuitem_property_set_shortcut_menuitem (DbusmenuMenuitem * menuitem, const GtkMenuItem * gmi) { @@ -260,14 +260,14 @@ dbusmenu_menuitem_property_set_shortcut_menuitem (DbusmenuMenuitem * menuitem, c } /** - dbusmenu_menuitem_property_get_shortcut: - @menuitem: The #DbusmenuMenuitem to get the shortcut off - @key: Location to put the key value - @modifier: Location to put the modifier mask - - This function gets a GTK shortcut as a key and a mask - for use to set the accelerators. -*/ + * dbusmenu_menuitem_property_get_shortcut: + * @menuitem: The #DbusmenuMenuitem to get the shortcut off + * @key: (out): Location to put the key value + * @modifier: (out): Location to put the modifier mask + * + * This function gets a GTK shortcut as a key and a mask + * for use to set the accelerators. + */ void dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * key, GdkModifierType * modifier) { diff --git a/libdbusmenu-gtk/menuitem.h b/libdbusmenu-gtk/menuitem.h index 4fc42f9..6f009df 100644 --- a/libdbusmenu-gtk/menuitem.h +++ b/libdbusmenu-gtk/menuitem.h @@ -43,7 +43,7 @@ GdkPixbuf * dbusmenu_menuitem_property_get_image (DbusmenuMenuitem * menuitem, c gboolean dbusmenu_menuitem_property_set_shortcut (DbusmenuMenuitem * menuitem, guint key, GdkModifierType modifier); gboolean dbusmenu_menuitem_property_set_shortcut_string (DbusmenuMenuitem * menuitem, const gchar * shortcut); gboolean dbusmenu_menuitem_property_set_shortcut_menuitem (DbusmenuMenuitem * menuitem, const GtkMenuItem * gmi); -void dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * key, GdkModifierType * modifiers); +void dbusmenu_menuitem_property_get_shortcut (DbusmenuMenuitem * menuitem, guint * key, GdkModifierType * modifier); G_END_DECLS diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 70cde53..d00870a 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -81,16 +81,16 @@ static void menuitem_notify_cb (GtkWidget * widget, gpointer data); /** - dbusmenu_gtk_parse_menu_structure: - @widget: A #GtkMenuItem or #GtkMenuShell to turn into a #DbusmenuMenuitem - - Goes through the GTK structures and turns them into the appropraite - Dbusmenu structures along with setting up all the relationships - between the objects. It also stores the dbusmenu items as a cache - on the GTK items so that they'll be reused if necissary. - - Return value: A dbusmenu item representing the menu structure -*/ + * dbusmenu_gtk_parse_menu_structure: + * @widget: A #GtkMenuItem or #GtkMenuShell to turn into a #DbusmenuMenuitem + * + * Goes through the GTK structures and turns them into the appropraite + * Dbusmenu structures along with setting up all the relationships + * between the objects. It also stores the dbusmenu items as a cache + * on the GTK items so that they'll be reused if necissary. + * + * Return value: (transfer none): A dbusmenu item representing the menu structure + */ DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) { diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index cfd864d..f5dbbf1 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -166,18 +166,18 @@ get_property (GObject * obj, guint id, GValue * value, GParamSpec * pspec) } /** - dbusmenu_gtk_serializable_menu_item_build_menuitem: - @smi: #DbusmenuGtkSerializableMenuItem to build a #DbusmenuMenuitem mirroring - - This function is for menu items that are instanciated from - GTK and have their properites set using GTK functions. This - builds a #DbusmenuMenuitem that then has the properties that - should be sent over the bus to create a new item of this - type on the other side. - - Return value: (transfer full) A #DbusmenuMenuitem who's values will be - set by this object. -*/ + * dbusmenu_gtk_serializable_menu_item_build_menuitem: + * @smi: #DbusmenuGtkSerializableMenuItem to build a #DbusmenuMenuitem mirroring + * + * This function is for menu items that are instanciated from + * GTK and have their properites set using GTK functions. This + * builds a #DbusmenuMenuitem that then has the properties that + * should be sent over the bus to create a new item of this + * type on the other side. + * + * Return value: (transfer full): A #DbusmenuMenuitem who's values will be + * set by this object. + */ DbusmenuMenuitem * dbusmenu_gtk_serializable_menu_item_build_menuitem (DbusmenuGtkSerializableMenuItem * smi) { @@ -225,15 +225,15 @@ type_destroy_handler (DbusmenuClient * client, const gchar * type, gpointer user } /** - dbusmenu_gtk_serializable_menu_item_register_to_client: - @client: #DbusmenuClient that we should register a type at. - @item_type: The #GType of a class that is a subclass of #DbusmenuGtkSerializableMenuItem - - Registers a generic handler for dealing with all subclasses of - #DbusmenuGtkSerializableMenuItem. This handler responds to the callback, - creates a new object and attaches it to the appropriate #DbusmenuMenuitem - object. -*/ + * dbusmenu_gtk_serializable_menu_item_register_to_client: + * @client: #DbusmenuClient that we should register a type at. + * @item_type: The #GType of a class that is a subclass of #DbusmenuGtkSerializableMenuItem + * + * Registers a generic handler for dealing with all subclasses of + * #DbusmenuGtkSerializableMenuItem. This handler responds to the callback, + * creates a new object and attaches it to the appropriate #DbusmenuMenuitem + * object. + */ void dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, GType item_type) { @@ -265,16 +265,16 @@ dbusmenu_gtk_serializable_menu_item_register_to_client (DbusmenuClient * client, } /** - dbusmenu_gtk_serializable_menu_item_set_menuitem: - @smi: #DbusmenuGtkSerializableMenuItem to set the @DbusmenuGtkSerializableMenuItem::dbusmenu-menuitem of - @mi: Menuitem to get the properties from - - This function is used on the server side to signal to the object - that it should get its' property change events from @mi instead - of expecting calls to its' API. A call to this function sets the - property and subclasses should listen to the notify signal to - pick up this property being set. -*/ + * dbusmenu_gtk_serializable_menu_item_set_menuitem: + * @smi: #DbusmenuGtkSerializableMenuItem to set the @DbusmenuGtkSerializableMenuItem::dbusmenu-menuitem of + * @mi: Menuitem to get the properties from + * + * This function is used on the server side to signal to the object + * that it should get its' property change events from @mi instead + * of expecting calls to its' API. A call to this function sets the + * property and subclasses should listen to the notify signal to + * pick up this property being set. + */ void dbusmenu_gtk_serializable_menu_item_set_menuitem (DbusmenuGtkSerializableMenuItem * smi, DbusmenuMenuitem * mi) { -- cgit v1.2.3 From 2ee586c80b9cd334cc98559a9754c3492d01e8b3 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Thu, 17 Feb 2011 07:48:27 -0500 Subject: make sure other icon property is removed when setting one --- libdbusmenu-gtk/parser.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 38528d8..8aa2837 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -586,8 +586,12 @@ update_icon (DbusmenuMenuitem *menuitem, GtkImage *image) dbusmenu_menuitem_property_set (menuitem, DBUSMENU_MENUITEM_PROP_ICON_NAME, icon_name); + dbusmenu_menuitem_property_remove (menuitem, + DBUSMENU_MENUITEM_PROP_ICON_DATA); } else if (pixbuf != NULL) { + dbusmenu_menuitem_property_remove (menuitem, + DBUSMENU_MENUITEM_PROP_ICON_NAME); dbusmenu_menuitem_property_set_image (menuitem, DBUSMENU_MENUITEM_PROP_ICON_DATA, pixbuf); -- cgit v1.2.3 From 3f3db4e1ea5e5b2321a7266edf018bb510fcdfb4 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Mon, 21 Feb 2011 12:43:43 +0100 Subject: fix typo in annotation --- libdbusmenu-gtk/menu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menu.c b/libdbusmenu-gtk/menu.c index 9788ffc..c2720ac 100644 --- a/libdbusmenu-gtk/menu.c +++ b/libdbusmenu-gtk/menu.c @@ -400,7 +400,7 @@ build_client (DbusmenuGtkMenu * self) /** * dbusmenu_gtkmenu_new: * @dbus_name: Name of the #DbusmenuServer on DBus - * @dbus_name: Name of the object on the #DbusmenuServer + * @dbus_object: Name of the object on the #DbusmenuServer * * Creates a new #DbusmenuGtkMenu object and creates a #DbusmenuClient * that connects across DBus to a #DbusmenuServer. -- cgit v1.2.3 From fec6317262d94b29c41fa0632236910b4bd11244 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 21 Feb 2011 09:54:31 -0600 Subject: Fixing transfer from the parser to be full --- libdbusmenu-gtk/parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 180b66e..f516dde 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -93,7 +93,7 @@ static void menuitem_notify_cb (GtkWidget * widget, * between the objects. It also stores the dbusmenu items as a cache * on the GTK items so that they'll be reused if necissary. * - * Return value: (transfer none): A dbusmenu item representing the menu structure + * Return value: (transfer full): A dbusmenu item representing the menu structure */ DbusmenuMenuitem * dbusmenu_gtk_parse_menu_structure (GtkWidget * widget) -- cgit v1.2.3 From f7c526d16a75a6f2dd606cb80093ac2b54f537cb Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 21 Feb 2011 10:04:27 -0600 Subject: Fixing the variable name --- libdbusmenu-gtk/client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 4128b02..50978ff 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -619,7 +619,7 @@ move_child (DbusmenuMenuitem * mi, DbusmenuMenuitem * child, guint new, guint ol /** * dbusmenu_gtkclient_new: * @dbus_name: Name of the #DbusmenuServer on DBus - * @dbus_name: Name of the object on the #DbusmenuServer + * @dbus_object: Name of the object on the #DbusmenuServer * * Creates a new #DbusmenuGtkClient object and creates a #DbusmenuClient * that connects across DBus to a #DbusmenuServer. -- cgit v1.2.3 From d436a1866030bc9720c49c696753afd65b08bf12 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 21 Feb 2011 10:04:44 -0600 Subject: Typo in reference --- libdbusmenu-gtk/menuitem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/menuitem.c b/libdbusmenu-gtk/menuitem.c index 4e92961..508b43f 100644 --- a/libdbusmenu-gtk/menuitem.c +++ b/libdbusmenu-gtk/menuitem.c @@ -78,7 +78,7 @@ dbusmenu_menuitem_property_set_image (DbusmenuMenuitem * menuitem, const gchar * /** * dbusmenu_menuitem_property_get_image: - * @menuitem: The #DbusmenuMenuite to look for the property on + * @menuitem: The #DbusmenuMenuitem to look for the property on * @property: The name of the property to look for. * * This function looks on the menu item for a property by the -- cgit v1.2.3 From 18c5f32b393ada7a3a7507b0a83bbd98f88a1722 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 21 Feb 2011 10:05:04 -0600 Subject: Removing parsing of unneeded comment block --- libdbusmenu-gtk/serializablemenuitem.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/serializablemenuitem.c b/libdbusmenu-gtk/serializablemenuitem.c index f5dbbf1..29f83a8 100644 --- a/libdbusmenu-gtk/serializablemenuitem.c +++ b/libdbusmenu-gtk/serializablemenuitem.c @@ -33,7 +33,7 @@ License version 3 and version 2.1 along with this program. If not, see #include "client.h" #include "serializablemenuitem.h" -/** +/* DbusmenuGtkSerializableMenuItemPrivate: @mi: Menuitem to watch the property changes from */ -- cgit v1.2.3