Commit 24a42839 authored by Michael Natterer's avatar Michael Natterer Committed by Michael Natterer

gtk: allow to specify accelerators in a platform-independent way

Introduce <Primary> in accelerator strings, which resolves to
GDK_CONTROL_MASK on X11/Win23, and to GDK_META_MASK on quartz.
Also serialize CONTROL/META as <Primary> depending on the platform.
parent 2a8be23d
......@@ -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[] = "<Release>";
static const gchar text_primary[] = "<Primary>";
static const gchar text_shift[] = "<Shift>";
static const gchar text_control[] = "<Control>";
static const gchar text_mod1[] = "<Alt>";
......@@ -1324,6 +1345,7 @@ gtk_accelerator_name (guint accelerator_key,
static const gchar text_meta[] = "<Meta>";
static const gchar text_super[] = "<Super>";
static const gchar text_hyper[] = "<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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment