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 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