diff --git a/gtk/gtkaccelgroup.c b/gtk/gtkaccelgroup.c index 7631ece85a..b134aa1a72 100644 --- a/gtk/gtkaccelgroup.c +++ b/gtk/gtkaccelgroup.c @@ -35,7 +35,7 @@ #include "gtkintl.h" #include "gtkmainprivate.h" #include "gtkmarshalers.h" - +#include "gtkprivate.h" /** * SECTION:gtkaccelgroup @@ -1152,6 +1152,20 @@ is_hyper (const gchar *string) (string[6] == '>')); } +static inline gboolean +is_primary (const gchar *string) +{ + return ((string[0] == '<') && + (string[1] == 'p' || string[1] == 'P') && + (string[2] == 'r' || string[2] == 'R') && + (string[3] == 'i' || string[3] == 'I') && + (string[4] == 'm' || string[4] == 'M') && + (string[5] == 'a' || string[5] == 'A') && + (string[6] == 'r' || string[6] == 'R') && + (string[7] == 'y' || string[7] == 'Y') && + (string[8] == '>')); +} + /** * gtk_accelerator_parse: * @accelerator: string representing an accelerator @@ -1201,6 +1215,12 @@ gtk_accelerator_parse (const gchar *accelerator, len -= 9; mods |= GDK_RELEASE_MASK; } + else if (len >= 9 && is_primary (accelerator)) + { + accelerator += 9; + len -= 9; + mods |= GTK_DEFAULT_ACCEL_MOD_MASK; + } else if (len >= 9 && is_control (accelerator)) { accelerator += 9; @@ -1314,6 +1334,7 @@ gtk_accelerator_name (guint accelerator_key, GdkModifierType accelerator_mods) { static const gchar text_release[] = ""; + static const gchar text_primary[] = ""; static const gchar text_shift[] = ""; static const gchar text_control[] = ""; static const gchar text_mod1[] = ""; @@ -1324,6 +1345,7 @@ gtk_accelerator_name (guint accelerator_key, static const gchar text_meta[] = ""; static const gchar text_super[] = ""; static const gchar text_hyper[] = ""; + GdkModifierType saved_mods; guint l; gchar *keyval_name; gchar *accelerator; @@ -1334,9 +1356,15 @@ gtk_accelerator_name (guint accelerator_key, if (!keyval_name) keyval_name = ""; + saved_mods = accelerator_mods; l = 0; if (accelerator_mods & GDK_RELEASE_MASK) l += sizeof (text_release) - 1; + if (accelerator_mods & GTK_DEFAULT_ACCEL_MOD_MASK) + { + l += sizeof (text_primary) - 1; + accelerator_mods &= ~GTK_DEFAULT_ACCEL_MOD_MASK; /* consume the default accel */ + } if (accelerator_mods & GDK_SHIFT_MASK) l += sizeof (text_shift) - 1; if (accelerator_mods & GDK_CONTROL_MASK) @@ -1361,6 +1389,7 @@ gtk_accelerator_name (guint accelerator_key, accelerator = g_new (gchar, l + 1); + accelerator_mods = saved_mods; l = 0; accelerator[l] = 0; if (accelerator_mods & GDK_RELEASE_MASK) @@ -1368,6 +1397,12 @@ gtk_accelerator_name (guint accelerator_key, strcpy (accelerator + l, text_release); l += sizeof (text_release) - 1; } + if (accelerator_mods & GTK_DEFAULT_ACCEL_MOD_MASK) + { + strcpy (accelerator + l, text_primary); + l += sizeof (text_primary) - 1; + accelerator_mods &= ~GTK_DEFAULT_ACCEL_MOD_MASK; /* consume the default accel */ + } if (accelerator_mods & GDK_SHIFT_MASK) { strcpy (accelerator + l, text_shift);