Commit fea2e7bf authored by Fabiano Fidêncio's avatar Fabiano Fidêncio

gdkkeys: Add support to _get_scroll_lock_state()

GdkKeymap already has support for _get_num_lock_state() and
_get_caps_lock_state(). Adding _get_scroll_lock_state() would be good
for completness and some backends (Windows?) could take advantage of
this.
parent aa269d93
......@@ -668,6 +668,7 @@ gdk_keymap_get_direction
gdk_keymap_have_bidi_layouts
gdk_keymap_get_caps_lock_state
gdk_keymap_get_num_lock_state
gdk_keymap_get_scroll_lock_state
gdk_keymap_get_modifier_state
gdk_keymap_add_virtual_modifiers
gdk_keymap_map_virtual_modifiers
......
......@@ -115,6 +115,12 @@ gdk_broadway_keymap_get_num_lock_state (GdkKeymap *keymap)
return FALSE;
}
static gboolean
gdk_broadway_keymap_get_scroll_lock_state (GdkKeymap *keymap)
{
return FALSE;
}
static gboolean
gdk_broadway_keymap_get_entries_for_keyval (GdkKeymap *keymap,
guint keyval,
......@@ -206,6 +212,7 @@ gdk_broadway_keymap_class_init (GdkBroadwayKeymapClass *klass)
keymap_class->have_bidi_layouts = gdk_broadway_keymap_have_bidi_layouts;
keymap_class->get_caps_lock_state = gdk_broadway_keymap_get_caps_lock_state;
keymap_class->get_num_lock_state = gdk_broadway_keymap_get_num_lock_state;
keymap_class->get_scroll_lock_state = gdk_broadway_keymap_get_scroll_lock_state;
keymap_class->get_entries_for_keyval = gdk_broadway_keymap_get_entries_for_keyval;
keymap_class->get_entries_for_keycode = gdk_broadway_keymap_get_entries_for_keycode;
keymap_class->lookup_key = gdk_broadway_keymap_lookup_key;
......
......@@ -357,6 +357,24 @@ gdk_keymap_get_num_lock_state (GdkKeymap *keymap)
return GDK_KEYMAP_GET_CLASS (keymap)->get_num_lock_state (keymap);
}
/**
* gdk_keymap_get_scroll_lock_state:
* @keymap: a #GdkKeymap
*
* Returns whether the Scroll Lock modifer is locked.
*
* Returns: %TRUE if Scroll Lock is on
*
* Since: 3.18
*/
gboolean
gdk_keymap_get_scroll_lock_state (GdkKeymap *keymap)
{
g_return_val_if_fail (GDK_IS_KEYMAP (keymap), FALSE);
return GDK_KEYMAP_GET_CLASS (keymap)->get_scroll_lock_state (keymap);
}
/**
* gdk_keymap_get_modifier_state:
* @keymap: a #GdkKeymap
......
......@@ -117,6 +117,8 @@ GDK_AVAILABLE_IN_ALL
gboolean gdk_keymap_get_caps_lock_state (GdkKeymap *keymap);
GDK_AVAILABLE_IN_ALL
gboolean gdk_keymap_get_num_lock_state (GdkKeymap *keymap);
GDK_AVAILABLE_IN_3_18
gboolean gdk_keymap_get_scroll_lock_state (GdkKeymap *keymap);
GDK_AVAILABLE_IN_3_4
guint gdk_keymap_get_modifier_state (GdkKeymap *keymap);
GDK_AVAILABLE_IN_ALL
......
......@@ -36,6 +36,7 @@ struct _GdkKeymapClass
gboolean (* have_bidi_layouts) (GdkKeymap *keymap);
gboolean (* get_caps_lock_state) (GdkKeymap *keymap);
gboolean (* get_num_lock_state) (GdkKeymap *keymap);
gboolean (* get_scroll_lock_state) (GdkKeymap *keymap);
gboolean (* get_entries_for_keyval) (GdkKeymap *keymap,
guint keyval,
GdkKeymapKey **keys,
......
......@@ -98,6 +98,13 @@ gdk_mir_keymap_get_num_lock_state (GdkKeymap *keymap)
return xkb_state_led_name_is_active (GDK_MIR_KEYMAP (keymap)->xkb_state, XKB_LED_NAME_NUM);
}
static gboolean
gdk_mir_keymap_get_scroll_lock_state (GdkKeymap *keymap)
{
//g_printerr ("gdk_mir_keymap_get_scroll_lock_state\n");
return xkb_state_led_name_is_active (GDK_MIR_KEYMAP (keymap)->xkb_state, XKB_LED_NAME_SCROLL);
}
static gboolean
gdk_mir_keymap_get_entries_for_keyval (GdkKeymap *keymap,
guint keyval,
......@@ -470,6 +477,7 @@ gdk_mir_keymap_class_init (GdkMirKeymapClass *klass)
keymap_class->have_bidi_layouts = gdk_mir_keymap_have_bidi_layouts;
keymap_class->get_caps_lock_state = gdk_mir_keymap_get_caps_lock_state;
keymap_class->get_num_lock_state = gdk_mir_keymap_get_num_lock_state;
keymap_class->get_scroll_lock_state = gdk_mir_keymap_get_scroll_lock_state;
keymap_class->get_entries_for_keyval = gdk_mir_keymap_get_entries_for_keyval;
keymap_class->get_entries_for_keycode = gdk_mir_keymap_get_entries_for_keycode;
keymap_class->lookup_key = gdk_mir_keymap_lookup_key;
......
......@@ -523,6 +523,13 @@ gdk_quartz_keymap_get_num_lock_state (GdkKeymap *keymap)
return FALSE;
}
static gboolean
gdk_quartz_keymap_get_scroll_lock_state (GdkKeymap *keymap)
{
/* FIXME: Implement this. */
return FALSE;
}
static gboolean
gdk_quartz_keymap_get_entries_for_keyval (GdkKeymap *keymap,
guint keyval,
......@@ -864,6 +871,7 @@ gdk_quartz_keymap_class_init (GdkQuartzKeymapClass *klass)
keymap_class->have_bidi_layouts = gdk_quartz_keymap_have_bidi_layouts;
keymap_class->get_caps_lock_state = gdk_quartz_keymap_get_caps_lock_state;
keymap_class->get_num_lock_state = gdk_quartz_keymap_get_num_lock_state;
keymap_class->get_scroll_lock_state = gdk_quartz_keymap_get_scroll_lock_state;
keymap_class->get_entries_for_keyval = gdk_quartz_keymap_get_entries_for_keyval;
keymap_class->get_entries_for_keycode = gdk_quartz_keymap_get_entries_for_keycode;
keymap_class->lookup_key = gdk_quartz_keymap_lookup_key;
......
......@@ -117,6 +117,13 @@ gdk_wayland_keymap_get_num_lock_state (GdkKeymap *keymap)
XKB_LED_NAME_NUM);
}
static gboolean
gdk_wayland_keymap_get_scroll_lock_state (GdkKeymap *keymap)
{
return xkb_state_led_name_is_active (GDK_WAYLAND_KEYMAP (keymap)->xkb_state,
XKB_LED_NAME_SCROLL);
}
static gboolean
gdk_wayland_keymap_get_entries_for_keyval (GdkKeymap *keymap,
guint keyval,
......@@ -373,6 +380,7 @@ _gdk_wayland_keymap_class_init (GdkWaylandKeymapClass *klass)
keymap_class->have_bidi_layouts = gdk_wayland_keymap_have_bidi_layouts;
keymap_class->get_caps_lock_state = gdk_wayland_keymap_get_caps_lock_state;
keymap_class->get_num_lock_state = gdk_wayland_keymap_get_num_lock_state;
keymap_class->get_scroll_lock_state = gdk_wayland_keymap_get_scroll_lock_state;
keymap_class->get_entries_for_keyval = gdk_wayland_keymap_get_entries_for_keyval;
keymap_class->get_entries_for_keycode = gdk_wayland_keymap_get_entries_for_keycode;
keymap_class->lookup_key = gdk_wayland_keymap_lookup_key;
......
......@@ -563,6 +563,12 @@ gdk_win32_keymap_get_num_lock_state (GdkKeymap *keymap)
return ((GetKeyState (VK_NUMLOCK) & 1) != 0);
}
static gboolean
gdk_win32_keymap_get_scroll_lock_state (GdkKeymap *keymap)
{
return ((GetKeyState (VK_SCROLL) & 1) != 0);
}
static gboolean
gdk_win32_keymap_get_entries_for_keyval (GdkKeymap *keymap,
guint keyval,
......@@ -930,6 +936,7 @@ gdk_win32_keymap_class_init (GdkWin32KeymapClass *klass)
keymap_class->have_bidi_layouts = gdk_win32_keymap_have_bidi_layouts;
keymap_class->get_caps_lock_state = gdk_win32_keymap_get_caps_lock_state;
keymap_class->get_num_lock_state = gdk_win32_keymap_get_num_lock_state;
keymap_class->get_scroll_lock_state = gdk_win32_keymap_get_scroll_lock_state;
keymap_class->get_entries_for_keyval = gdk_win32_keymap_get_entries_for_keyval;
keymap_class->get_entries_for_keycode = gdk_win32_keymap_get_entries_for_keycode;
keymap_class->lookup_key = gdk_win32_keymap_lookup_key;
......
......@@ -69,12 +69,14 @@ struct _GdkX11Keymap
guint lock_keysym;
GdkModifierType group_switch_mask;
GdkModifierType num_lock_mask;
GdkModifierType scroll_lock_mask;
GdkModifierType modmap[8];
PangoDirection current_direction;
guint have_direction : 1;
guint have_lock_state : 1;
guint caps_lock_state : 1;
guint num_lock_state : 1;
guint have_direction : 1;
guint have_lock_state : 1;
guint caps_lock_state : 1;
guint num_lock_state : 1;
guint scroll_lock_state : 1;
guint modifier_state;
guint current_serial;
......@@ -113,6 +115,7 @@ gdk_x11_keymap_init (GdkX11Keymap *keymap)
keymap->mod_keymap = NULL;
keymap->num_lock_mask = 0;
keymap->scroll_lock_mask = 0;
keymap->group_switch_mask = 0;
keymap->lock_keysym = GDK_KEY_Caps_Lock;
keymap->have_direction = FALSE;
......@@ -231,6 +234,10 @@ get_xkb (GdkX11Keymap *keymap_x11)
if (keymap_x11->num_lock_mask == 0)
keymap_x11->num_lock_mask = XkbKeysymToModifiers (KEYMAP_XDISPLAY (GDK_KEYMAP (keymap_x11)), GDK_KEY_Num_Lock);
if (keymap_x11->scroll_lock_mask == 0)
keymap_x11->scroll_lock_mask = XkbKeysymToModifiers (KEYMAP_XDISPLAY (GDK_KEYMAP (keymap_x11)), GDK_KEY_Scroll_Lock);
return keymap_x11->xkb_desc;
}
#endif /* HAVE_XKB */
......@@ -353,6 +360,7 @@ update_keymaps (GdkX11Keymap *keymap_x11)
keymap_x11->lock_keysym = GDK_KEY_VoidSymbol;
keymap_x11->group_switch_mask = 0;
keymap_x11->num_lock_mask = 0;
keymap_x11->scroll_lock_mask = 0;
for (i = 0; i < 8; i++)
keymap_x11->modmap[i] = 1 << i;
......@@ -426,7 +434,7 @@ update_keymaps (GdkX11Keymap *keymap_x11)
break;
default:
/* Find the Mode_Switch and Num_Lock modifiers. */
/* Find the Mode_Switch, Num_Lock and Scroll_Lock modifiers. */
for (j = 0; j < keymap_x11->keysyms_per_keycode; j++)
{
if (syms[j] == GDK_KEY_Mode_switch)
......@@ -439,6 +447,11 @@ update_keymaps (GdkX11Keymap *keymap_x11)
/* This modifier is used for Num_Lock */
keymap_x11->num_lock_mask |= mask;
}
else if (syms[j] == GDK_KEY_Scroll_Lock)
{
/* This modifier is used for Scroll_Lock */
keymap_x11->scroll_lock_mask |= mask;
}
}
break;
}
......@@ -594,6 +607,7 @@ update_lock_state (GdkX11Keymap *keymap_x11,
gboolean have_lock_state;
gboolean caps_lock_state;
gboolean num_lock_state;
gboolean scroll_lock_state;
guint modifier_state;
/* ensure keymap_x11->num_lock_mask is initialized */
......@@ -602,17 +616,20 @@ update_lock_state (GdkX11Keymap *keymap_x11,
have_lock_state = keymap_x11->have_lock_state;
caps_lock_state = keymap_x11->caps_lock_state;
num_lock_state = keymap_x11->num_lock_state;
scroll_lock_state = keymap_x11->scroll_lock_state;
modifier_state = keymap_x11->modifier_state;
keymap_x11->have_lock_state = TRUE;
keymap_x11->caps_lock_state = (locked_mods & GDK_LOCK_MASK) != 0;
keymap_x11->num_lock_state = (locked_mods & keymap_x11->num_lock_mask) != 0;
keymap_x11->scroll_lock_state = (locked_mods & keymap_x11->scroll_lock_mask) != 0;
/* FIXME: sanitize this */
keymap_x11->modifier_state = (guint)effective_mods;
return !have_lock_state
|| (caps_lock_state != keymap_x11->caps_lock_state)
|| (num_lock_state != keymap_x11->num_lock_state)
|| (scroll_lock_state != keymap_x11->scroll_lock_state)
|| (modifier_state != keymap_x11->modifier_state);
}
......@@ -747,6 +764,16 @@ gdk_x11_keymap_get_num_lock_state (GdkKeymap *keymap)
return keymap_x11->num_lock_state;
}
static gboolean
gdk_x11_keymap_get_scroll_lock_state (GdkKeymap *keymap)
{
GdkX11Keymap *keymap_x11 = GDK_X11_KEYMAP (keymap);
ensure_lock_state (keymap);
return keymap_x11->scroll_lock_state;
}
static guint
gdk_x11_keymap_get_modifier_state (GdkKeymap *keymap)
{
......@@ -1556,6 +1583,7 @@ gdk_x11_keymap_class_init (GdkX11KeymapClass *klass)
keymap_class->have_bidi_layouts = gdk_x11_keymap_have_bidi_layouts;
keymap_class->get_caps_lock_state = gdk_x11_keymap_get_caps_lock_state;
keymap_class->get_num_lock_state = gdk_x11_keymap_get_num_lock_state;
keymap_class->get_scroll_lock_state = gdk_x11_keymap_get_scroll_lock_state;
keymap_class->get_modifier_state = gdk_x11_keymap_get_modifier_state;
keymap_class->get_entries_for_keyval = gdk_x11_keymap_get_entries_for_keyval;
keymap_class->get_entries_for_keycode = gdk_x11_keymap_get_entries_for_keycode;
......
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