diff -Nru unity-gtk-module-0.0.0+14.04.20140328/debian/changelog unity-gtk-module-0.0.0+14.04.20140403/debian/changelog --- unity-gtk-module-0.0.0+14.04.20140328/debian/changelog 2014-04-03 17:18:13.000000000 +0000 +++ unity-gtk-module-0.0.0+14.04.20140403/debian/changelog 2014-04-03 17:18:14.000000000 +0000 @@ -1,3 +1,11 @@ +unity-gtk-module (0.0.0+14.04.20140403-0ubuntu1) trusty; urgency=low + + [ William Hua ] + * Forward original accelerator text for Eclipse, Inkscape, Emacs. (LP: + #1208019) + + -- Ubuntu daily release Thu, 03 Apr 2014 17:12:49 +0000 + unity-gtk-module (0.0.0+14.04.20140328-0ubuntu1) trusty; urgency=low [ CI bot ] diff -Nru unity-gtk-module-0.0.0+14.04.20140328/lib/unity-gtk-menu-item.c unity-gtk-module-0.0.0+14.04.20140403/lib/unity-gtk-menu-item.c --- unity-gtk-module-0.0.0+14.04.20140328/lib/unity-gtk-menu-item.c 2014-03-28 10:54:24.000000000 +0000 +++ unity-gtk-module-0.0.0+14.04.20140403/lib/unity-gtk-menu-item.c 2014-04-03 17:12:41.000000000 +0000 @@ -57,7 +57,7 @@ } } -static GtkLabel * +GtkLabel * gtk_menu_item_get_nth_label (GtkMenuItem *menu_item, guint index) { @@ -368,6 +368,23 @@ } static void +unity_gtk_menu_item_handle_accel_closures_changed (GtkWidget *widget, + gpointer user_data) +{ + UnityGtkMenuItem *item; + UnityGtkMenuShell *parent_shell; + + g_return_if_fail (UNITY_GTK_IS_MENU_ITEM (user_data)); + + item = UNITY_GTK_MENU_ITEM (user_data); + parent_shell = item->parent_shell; + + g_return_if_fail (parent_shell != NULL); + + unity_gtk_menu_shell_handle_item_notify (parent_shell, item, "accel-path"); +} + +static void unity_gtk_menu_item_set_menu_item (UnityGtkMenuItem *item, GtkMenuItem *menu_item) { @@ -410,6 +427,8 @@ if (label != NULL) g_signal_connect (label, "notify", G_CALLBACK (unity_gtk_menu_item_handle_label_notify), item); + g_signal_connect (menu_item, "accel-closures-changed", G_CALLBACK (unity_gtk_menu_item_handle_accel_closures_changed), item); + /* LP: #1208019 */ if (gtk_menu_item_get_submenu (menu_item) != NULL) g_signal_emit_by_name (gtk_menu_item_get_submenu (menu_item), "show"); diff -Nru unity-gtk-module-0.0.0+14.04.20140328/lib/unity-gtk-menu-item-private.h unity-gtk-module-0.0.0+14.04.20140403/lib/unity-gtk-menu-item-private.h --- unity-gtk-module-0.0.0+14.04.20140328/lib/unity-gtk-menu-item-private.h 2014-03-28 10:54:08.000000000 +0000 +++ unity-gtk-module-0.0.0+14.04.20140403/lib/unity-gtk-menu-item-private.h 2014-04-03 17:12:41.000000000 +0000 @@ -89,6 +89,9 @@ void unity_gtk_menu_item_print (UnityGtkMenuItem *item, guint indent) G_GNUC_INTERNAL; +GtkLabel * gtk_menu_item_get_nth_label (GtkMenuItem *menu_item, + guint index) G_GNUC_INTERNAL; + const gchar * gtk_menu_item_get_nth_label_label (GtkMenuItem *menu_item, guint index) G_GNUC_INTERNAL; diff -Nru unity-gtk-module-0.0.0+14.04.20140328/lib/unity-gtk-menu-section.c unity-gtk-module-0.0.0+14.04.20140403/lib/unity-gtk-menu-section.c --- unity-gtk-module-0.0.0+14.04.20140328/lib/unity-gtk-menu-section.c 2014-03-28 10:54:08.000000000 +0000 +++ unity-gtk-module-0.0.0+14.04.20140403/lib/unity-gtk-menu-section.c 2014-04-03 17:12:41.000000000 +0000 @@ -23,6 +23,10 @@ #define G_MENU_ATTRIBUTE_ACCEL "accel" #endif +#ifndef G_MENU_ATTRIBUTE_ACCEL_TEXT +#define G_MENU_ATTRIBUTE_ACCEL_TEXT "x-canonical-accel" +#endif + G_DEFINE_TYPE (UnityGtkMenuSection, unity_gtk_menu_section, G_TYPE_MENU_MODEL); @@ -35,6 +39,14 @@ return GPOINTER_TO_INT (a) - GPOINTER_TO_INT (b); } +static gboolean +g_closure_equal (GtkAccelKey *key, + GClosure *closure, + gpointer data) +{ + return closure == data; +} + static void unity_gtk_menu_section_set_parent_shell (UnityGtkMenuSection *section, UnityGtkMenuShell *parent_shell) @@ -166,10 +178,49 @@ } if (accel_name == NULL) - accel_name = g_strdup (gtk_menu_item_get_nth_label_label (item->menu_item, 1)); + { + GList *closures = gtk_widget_list_accel_closures (GTK_WIDGET (item->menu_item)); + GList *iter; + + for (iter = closures; iter != NULL && accel_name == NULL; iter = g_list_next (iter)) + { + GClosure *closure = iter->data; + GtkAccelGroup *accel_group = gtk_accel_group_from_accel_closure (closure); + + if (accel_group != NULL) + { + GtkAccelKey *accel_key = gtk_accel_group_find (accel_group, g_closure_equal, closure); + + if (accel_key != NULL) + accel_name = gtk_accelerator_name (accel_key->accel_key, accel_key->accel_mods); + } + } + + g_list_free (closures); + } if (accel_name != NULL) g_hash_table_insert (*attributes, G_MENU_ATTRIBUTE_ACCEL, g_variant_ref_sink (g_variant_new_string (accel_name))); + else + { +#if GTK_MAJOR_VERSION == 2 + /* LP: #1208019 */ + GtkLabel *accel_label = gtk_menu_item_get_nth_label (item->menu_item, 0); + + if (GTK_IS_ACCEL_LABEL (accel_label)) + { + /* Eclipse uses private API. */ + if (GTK_ACCEL_LABEL (accel_label)->accel_string != NULL) + accel_name = g_strdup (GTK_ACCEL_LABEL (accel_label)->accel_string); + } +#endif + + if (accel_name == NULL) + accel_name = g_strdup (gtk_menu_item_get_nth_label_label (item->menu_item, 1)); + + if (accel_name != NULL) + g_hash_table_insert (*attributes, G_MENU_ATTRIBUTE_ACCEL_TEXT, g_variant_ref_sink (g_variant_new_string (accel_name))); + } g_free (accel_name); }