#include "gdkinternals.h"
#include "gdkdisplay-x11.h"
#include "gdkkeysyms.h"
-#include "gdkalias.h"
#ifdef HAVE_XKB
#include <X11/XKBlib.h>
guint sun_keypad : 1;
guint have_direction : 1;
guint caps_lock_state : 1;
+ guint num_lock_state : 1;
guint current_serial;
#ifdef HAVE_XKB
if (!object_type)
{
- static const GTypeInfo object_info =
+ const GTypeInfo object_info =
{
sizeof (GdkKeymapClass),
(GBaseInitFunc) NULL,
keymap->num_lock_mask = 0;
keymap->sun_keypad = FALSE;
keymap->group_switch_mask = 0;
- keymap->lock_keysym = GDK_Caps_Lock;
+ keymap->lock_keysym = GDK_KEY_Caps_Lock;
keymap->have_direction = FALSE;
keymap->current_serial = 0;
keymap_x11->current_serial = display_x11->keymap_serial;
+ if (keymap_x11->num_lock_mask == 0)
+ keymap_x11->num_lock_mask = XkbKeysymToModifiers (KEYMAP_XDISPLAY (GDK_KEYMAP (keymap_x11)), XK_Num_Lock);
+
return keymap_x11->xkb_desc;
}
#endif /* HAVE_XKB */
/* Check both groups */
for (i = 0 ; i < 2 ; i++)
{
- if (get_symbol (syms, keymap_x11, i, 0) == GDK_Tab)
- set_symbol (syms, keymap_x11, i, 1, GDK_ISO_Left_Tab);
+ if (get_symbol (syms, keymap_x11, i, 0) == GDK_KEY_Tab)
+ set_symbol (syms, keymap_x11, i, 1, GDK_KEY_ISO_Left_Tab);
}
/*
keymap_x11->mod_keymap = XGetModifierMapping (xdisplay);
- keymap_x11->lock_keysym = GDK_VoidSymbol;
+ keymap_x11->lock_keysym = GDK_KEY_VoidSymbol;
keymap_x11->group_switch_mask = 0;
keymap_x11->num_lock_mask = 0;
mask = 0;
for (j = 0; j < keymap_x11->keysyms_per_keycode; j++)
{
- if (syms[j] == GDK_Meta_L ||
- syms[j] == GDK_Meta_R)
+ if (syms[j] == GDK_KEY_Meta_L ||
+ syms[j] == GDK_KEY_Meta_R)
mask |= GDK_META_MASK;
- else if (syms[j] == GDK_Hyper_L ||
- syms[j] == GDK_Hyper_R)
+ else if (syms[j] == GDK_KEY_Hyper_L ||
+ syms[j] == GDK_KEY_Hyper_R)
mask |= GDK_HYPER_MASK;
- else if (syms[j] == GDK_Super_L ||
- syms[j] == GDK_Super_R)
+ else if (syms[j] == GDK_KEY_Super_L ||
+ syms[j] == GDK_KEY_Super_R)
mask |= GDK_SUPER_MASK;
}
*/
for (j = 0; j < keymap_x11->keysyms_per_keycode; j++)
{
- if (syms[j] == GDK_Caps_Lock)
- keymap_x11->lock_keysym = GDK_Caps_Lock;
- else if (syms[j] == GDK_Shift_Lock &&
- keymap_x11->lock_keysym == GDK_VoidSymbol)
- keymap_x11->lock_keysym = GDK_Shift_Lock;
+ if (syms[j] == GDK_KEY_Caps_Lock)
+ keymap_x11->lock_keysym = GDK_KEY_Caps_Lock;
+ else if (syms[j] == GDK_KEY_Shift_Lock &&
+ keymap_x11->lock_keysym == GDK_KEY_VoidSymbol)
+ keymap_x11->lock_keysym = GDK_KEY_Shift_Lock;
}
break;
/* Find the Mode_Switch and Num_Lock modifiers. */
for (j = 0; j < keymap_x11->keysyms_per_keycode; j++)
{
- if (syms[j] == GDK_Mode_switch)
+ if (syms[j] == GDK_KEY_Mode_switch)
{
/* This modifier swaps groups */
keymap_x11->group_switch_mask |= mask;
}
- else if (syms[j] == GDK_Num_Lock)
+ else if (syms[j] == GDK_KEY_Num_Lock)
{
/* This modifier is used for Num_Lock */
keymap_x11->num_lock_mask |= mask;
gint locked_mods)
{
gboolean caps_lock_state;
-
+ gboolean num_lock_state;
+
caps_lock_state = keymap_x11->caps_lock_state;
+ num_lock_state = keymap_x11->num_lock_state;
keymap_x11->caps_lock_state = (locked_mods & GDK_LOCK_MASK) != 0;
-
- return caps_lock_state != keymap_x11->caps_lock_state;
+ keymap_x11->num_lock_state = (locked_mods & keymap_x11->num_lock_mask) != 0;
+
+ return (caps_lock_state != keymap_x11->caps_lock_state)
+ || (num_lock_state != keymap_x11->num_lock_state);
}
/* keep this in sync with the XkbSelectEventDetails() call
g_signal_emit_by_name (keymap_x11, "direction-changed");
if (update_lock_state (keymap_x11, xkb_event->state.locked_mods))
- g_signal_emit_by_name (keymap_x11, "state-changed");
+ g_signal_emit_by_name (keymap_x11, "state-changed");
}
}
* gdk_keymap_get_caps_lock_state:
* @keymap: a #GdkKeymap
*
- * Returns wether the Caps Lock modifer is locked.
+ * Returns whether the Caps Lock modifer is locked.
*
* Returns: %TRUE if Caps Lock is on
*
return keymap_x11->caps_lock_state;
}
+/**
+ * gdk_keymap_get_num_lock_state:
+ * @keymap: a #GdkKeymap
+ *
+ * Returns whether the Num Lock modifer is locked.
+ *
+ * Returns: %TRUE if Num Lock is on
+ *
+ * Since: 3.0
+ */
+gboolean
+gdk_keymap_get_num_lock_state (GdkKeymap *keymap)
+{
+ GdkKeymapX11 *keymap_x11;
+
+ keymap = GET_EFFECTIVE_KEYMAP (keymap);
+
+ keymap_x11 = GDK_KEYMAP_X11 (keymap);
+
+ return keymap_x11->num_lock_state;
+}
/**
* gdk_keymap_get_entries_for_keyval:
- * @keymap: a #GdkKeymap, or %NULL to use the default keymap
+ * @keymap: (allow-none): a #GdkKeymap, or %NULL to use the default keymap
* @keyval: a keyval, such as %GDK_a, %GDK_Up, %GDK_Return, etc.
- * @keys: return location for an array of #GdkKeymapKey
- * @n_keys: return location for number of elements in returned array
- *
+ * @keys: (out): return location for an array of #GdkKeymapKey
+ * @n_keys: (out): return location for number of elements in returned array
+ *
* Obtains a list of keycode/group/level combinations that will
* generate @keyval. Groups and levels are two kinds of keyboard mode;
* in general, the level determines whether the top or bottom symbol
/**
* gdk_keymap_get_entries_for_keycode:
- * @keymap: a #GdkKeymap or %NULL to use the default keymap
+ * @keymap: (allow-none): a #GdkKeymap or %NULL to use the default keymap
* @hardware_keycode: a keycode
- * @keys: return location for array of #GdkKeymapKey, or %NULL
- * @keyvals: return location for array of keyvals, or %NULL
+ * @keys: (out): return location for array of #GdkKeymapKey, or %NULL
+ * @keyvals: (out): return location for array of keyvals, or %NULL
* @n_entries: length of @keys and @keyvals
*
* Returns the keyvals bound to @hardware_keycode.
register unsigned int mods,
unsigned int * mods_rtrn,
KeySym * keysym_rtrn,
- unsigned int * group_rtrn,
- unsigned int * level_rtrn)
+ int * group_rtrn,
+ int * level_rtrn)
{
XkbKeyTypeRec *type;
int col,nKeyGroups;
guint hardware_keycode,
gint group,
GdkModifierType state,
- guint *effective_group,
- guint *effective_level)
+ gint *effective_group,
+ gint *effective_level)
{
const KeySym *map = get_keymap (keymap_x11);
const KeySym *syms = map + (hardware_keycode - keymap_x11->min_keycode) * keymap_x11->keysyms_per_keycode;
gint num_lock_index;
shift_modifiers = GDK_SHIFT_MASK;
- if (keymap_x11->lock_keysym == GDK_Shift_Lock)
+ if (keymap_x11->lock_keysym == GDK_KEY_Shift_Lock)
shift_modifiers |= GDK_LOCK_MASK;
/* Fall back to the first group if the passed in group is empty
tmp_keyval = SYM (keymap_x11, group, shift_level);
- if (keymap_x11->lock_keysym == GDK_Caps_Lock && (state & GDK_LOCK_MASK) != 0)
+ if (keymap_x11->lock_keysym == GDK_KEY_Caps_Lock && (state & GDK_LOCK_MASK) != 0)
{
guint upper = gdk_keyval_to_upper (tmp_keyval);
if (upper != tmp_keyval)
/**
* gdk_keymap_translate_keyboard_state:
- * @keymap: a #GdkKeymap, or %NULL to use the default
+ * @keymap: (allow-none): a #GdkKeymap, or %NULL to use the default
* @hardware_keycode: a keycode
- * @state: a modifier state
+ * @state: a modifier state
* @group: active keyboard group
- * @keyval: return location for keyval, or %NULL
- * @effective_group: return location for effective group, or %NULL
- * @level: return location for level, or %NULL
- * @consumed_modifiers: return location for modifiers that were used to
+ * @keyval: (out) (allow-none): return location for keyval, or %NULL
+ * @effective_group: (out) (allow-none): return location for effective group, or %NULL
+ * @level: (out) (allow-none): return location for level, or %NULL
+ * @consumed_modifiers: (out) (allow-none): return location for modifiers that were used to
* determine the group or level, or %NULL
*
* Translates the contents of a #GdkEventKey into a keyval, effective
* group, and level. Modifiers that affected the translation and
* are thus unavailable for application use are returned in
- * @consumed_modifiers. See gdk_keyval_get_keys() for an explanation of
+ * @consumed_modifiers. See <xref linkend="key-group-explanation"/> for an explanation of
* groups and levels. The @effective_group is the group that was
* actually used for the translation; some keys such as Enter are not
* affected by the active keyboard group. The @level is derived from
{
switch (keyval)
{
- case GDK_Page_Up:
+ case GDK_KEY_Page_Up:
return "Page_Up";
- case GDK_Page_Down:
+ case GDK_KEY_Page_Down:
return "Page_Down";
- case GDK_KP_Page_Up:
+ case GDK_KEY_KP_Page_Up:
return "KP_Page_Up";
- case GDK_KP_Page_Down:
+ case GDK_KEY_KP_Page_Down:
return "KP_Page_Down";
}
}
void
-_gdk_keymap_add_virtual_modifiers (GdkKeymap *keymap,
- GdkModifierType *modifiers)
+_gdk_keymap_add_virtual_modifiers_compat (GdkKeymap *keymap,
+ GdkModifierType *modifiers)
{
GdkKeymapX11 *keymap_x11;
int i;
}
}
+/**
+ * gdk_keymap_add_virtual_modifiers:
+ * @keymap: a #GdkKeymap
+ * @state: pointer to the modifier mask to change
+ *
+ * Adds virtual modifiers (i.e. Super, Hyper and Meta) which correspond
+ * to the real modifiers (i.e Mod2, Mod3, ...) in @modifiers.
+ * are set in @state to their non-virtual counterparts (i.e. Mod2,
+ * Mod3,...) and set the corresponding bits in @state.
+ *
+ * GDK already does this before delivering key events, but for
+ * compatibility reasons, it only sets the first virtual modifier
+ * it finds, whereas this function sets all matching virtual modifiers.
+ *
+ * This function is useful when matching key events against
+ * accelerators.
+ *
+ * Since: 2.20
+ */
+void
+gdk_keymap_add_virtual_modifiers (GdkKeymap *keymap,
+ GdkModifierType *state)
+{
+ GdkKeymapX11 *keymap_x11;
+ int i;
+
+ keymap = GET_EFFECTIVE_KEYMAP (keymap);
+ keymap_x11 = GDK_KEYMAP_X11 (keymap);
+
+ for (i = 3; i < 8; i++)
+ {
+ if ((1 << i) & *state)
+ {
+ if (keymap_x11->modmap[i] & GDK_MOD1_MASK)
+ *state |= GDK_MOD1_MASK;
+ if (keymap_x11->modmap[i] & GDK_SUPER_MASK)
+ *state |= GDK_SUPER_MASK;
+ if (keymap_x11->modmap[i] & GDK_HYPER_MASK)
+ *state |= GDK_HYPER_MASK;
+ if (keymap_x11->modmap[i] & GDK_META_MASK)
+ *state |= GDK_META_MASK;
+ }
+ }
+}
+
gboolean
_gdk_keymap_key_is_modifier (GdkKeymap *keymap,
guint keycode)
return FALSE;
}
+/**
+ * gdk_keymap_map_virtual_modifiers:
+ * @keymap: a #GdkKeymap
+ * @state: pointer to the modifier state to map
+ *
+ * Maps the virtual modifiers (i.e. Super, Hyper and Meta) which
+ * are set in @state to their non-virtual counterparts (i.e. Mod2,
+ * Mod3,...) and set the corresponding bits in @state.
+ *
+ * This function is useful when matching key events against
+ * accelerators.
+ *
+ * Returns: %TRUE if no virtual modifiers were mapped to the
+ * same non-virtual modifier. Note that %FALSE is also returned
+ * if a virtual modifier is mapped to a non-virtual modifier that
+ * was already set in @state.
+ *
+ * Since: 2.20
+ */
+gboolean
+gdk_keymap_map_virtual_modifiers (GdkKeymap *keymap,
+ GdkModifierType *state)
+{
+ GdkKeymapX11 *keymap_x11;
+ const guint vmods[] = {
+ GDK_SUPER_MASK, GDK_HYPER_MASK, GDK_META_MASK
+ };
+ int i, j;
+ gboolean retval;
+
+ keymap = GET_EFFECTIVE_KEYMAP (keymap);
+ keymap_x11 = GDK_KEYMAP_X11 (keymap);
+
+ if (KEYMAP_USE_XKB (keymap))
+ get_xkb (keymap_x11);
+
+ retval = TRUE;
+
+ for (j = 0; j < 3; j++)
+ {
+ if (*state & vmods[j])
+ {
+ for (i = 3; i < 8; i++)
+ {
+ if (keymap_x11->modmap[i] & vmods[j])
+ {
+ if (*state & (1 << i))
+ retval = FALSE;
+ else
+ *state |= 1 << i;
+ }
+ }
+ }
+ }
-#define __GDK_KEYS_X11_C__
-#include "gdkaliasdef.c"
+ return retval;
+}