summaryrefslogtreecommitdiff
path: root/gdk/gdkkeys.c
diff options
context:
space:
mode:
authorMichael Natterer <mitch@lanedo.com>2011-09-27 09:50:34 +0200
committerMichael Natterer <mitch@gimp.org>2011-09-27 09:56:25 +0200
commit4a7a67339a3c8a7c523b32b36a7fc2ea5abfb8f8 (patch)
tree954b9cee7be7c1d578d524b3d4bac05f7d921411 /gdk/gdkkeys.c
parent04009aa3329486cc60634865b597195babbec774 (diff)
downloadgtk+-4a7a67339a3c8a7c523b32b36a7fc2ea5abfb8f8.tar.gz
Bug 659602 - Provide an abstraction for the platform's use of modifier keys
Add enum GdkModifierIntent which identifies use cases for modifier masks and GdkKeyMap::get_modifier_mask(). Add a default implementation which returns what is currently hardcoded all over GTK+, and an implementation in the quartz backend. Also add gtk_widget_get_modifier_mask() which simplifies things by doing widget->display->keymap->get_modifier_mask().
Diffstat (limited to 'gdk/gdkkeys.c')
-rw-r--r--gdk/gdkkeys.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/gdk/gdkkeys.c b/gdk/gdkkeys.c
index f52de39e04..d2b7b61f6e 100644
--- a/gdk/gdkkeys.c
+++ b/gdk/gdkkeys.c
@@ -108,6 +108,11 @@ enum {
LAST_SIGNAL
};
+
+static GdkModifierType gdk_keymap_real_get_modifier_mask (GdkKeymap *keymap,
+ GdkModifierIntent intent);
+
+
static guint signals[LAST_SIGNAL] = { 0 };
G_DEFINE_TYPE (GdkKeymap, gdk_keymap, G_TYPE_OBJECT)
@@ -117,6 +122,8 @@ gdk_keymap_class_init (GdkKeymapClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ klass->get_modifier_mask = gdk_keymap_real_get_modifier_mask;
+
/**
* GdkKeymap::direction-changed:
* @keymap: the object on which the signal is emitted
@@ -605,6 +612,61 @@ gdk_keymap_map_virtual_modifiers (GdkKeymap *keymap,
return GDK_KEYMAP_GET_CLASS(keymap)->map_virtual_modifiers (keymap, state);
}
+static GdkModifierType
+gdk_keymap_real_get_modifier_mask (GdkKeymap *keymap,
+ GdkModifierIntent intent)
+{
+ switch (intent)
+ {
+ case GDK_MODIFIER_INTENT_PRIMARY_ACCELERATOR:
+ return GDK_CONTROL_MASK;
+
+ case GDK_MODIFIER_INTENT_CONTEXT_MENU:
+ return 0;
+
+ case GDK_MODIFIER_INTENT_EXTEND_SELECTION:
+ return GDK_SHIFT_MASK;
+
+ case GDK_MODIFIER_INTENT_MODIFY_SELECTION:
+ return GDK_CONTROL_MASK;
+
+ case GDK_MODIFIER_INTENT_NO_TEXT_INPUT:
+ return GDK_MOD1_MASK | GDK_CONTROL_MASK;
+
+ default:
+ g_return_val_if_reached (0);
+ }
+}
+
+/**
+ * gdk_keymap_get_modifier_mask:
+ * @keymap: a #GdkKeymap
+ * @intent: the use case for the modifier mask
+ *
+ * Returns the modifier mask the @keymap's windowing system backend
+ * uses for a particular purpose.
+ *
+ * Note that this function always returns real hardware modifiers, not
+ * virtual ones (e.g. it will return #GDK_MOD1_MASK rather than
+ * #GDK_META_MASK if the backend maps MOD1 to META), so there are use
+ * cases where the return value of this function has to be transformed
+ * by gdk_keymap_add_virtual_modifiers() in order to contain the
+ * expected result.
+ *
+ * Returns: the modifier mask used for @intent.
+ *
+ * Since: 3.4
+ **/
+GdkModifierType
+gdk_keymap_get_modifier_mask (GdkKeymap *keymap,
+ GdkModifierIntent intent)
+{
+ g_return_val_if_fail (GDK_IS_KEYMAP (keymap), 0);
+
+ return GDK_KEYMAP_GET_CLASS (keymap)->get_modifier_mask (keymap, intent);
+}
+
+
/**
* gdk_keyval_name:
* @keyval: a key value