commit caabeb3170640881a7a9153613535b4afd20d702
parent ea0ab20ed1a282a2b43594fe89f15a6fa5ab302f
Author: Michael Forney <mforney@mforney.org>
Date: Thu, 5 Dec 2013 14:35:21 -0800
Use XKB_KEY macro rather than adding 8 to keycodes
Diffstat:
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/libswc/bindings.c b/libswc/bindings.c
@@ -49,15 +49,12 @@ static bool handle_key(struct swc_keyboard * keyboard, uint32_t time,
const xkb_keysym_t * keysyms;
int num_keysyms;
- /* XKB key codes are offset by 8 */
- key += 8;
-
- layout = xkb_state_key_get_layout(keyboard->xkb.state, key);
+ layout = xkb_state_key_get_layout(keyboard->xkb.state, XKB_KEY(key));
/* XXX: Maybe someone might want to register a key binding for a
* keysym with a different shift-level? */
num_keysyms = xkb_keymap_key_get_syms_by_level
- (keyboard->xkb.keymap.map, key, layout, 0, &keysyms);
+ (keyboard->xkb.keymap.map, XKB_KEY(key), layout, 0, &keysyms);
if (num_keysyms == 1)
{
diff --git a/libswc/keyboard.c b/libswc/keyboard.c
@@ -179,10 +179,10 @@ void swc_keyboard_handle_key(struct swc_keyboard * keyboard, uint32_t time,
key, state);
}
- /* Update XKB state. Apparently the keycodes are offset by 8 in XKB. */
+ /* Update XKB state. */
direction = state == WL_KEYBOARD_KEY_STATE_PRESSED ? XKB_KEY_DOWN
: XKB_KEY_UP;
- xkb_state_update_key(xkb->state, key + 8, direction);
+ xkb_state_update_key(xkb->state, XKB_KEY(key), direction);
mods_depressed = xkb_state_serialize_mods(xkb->state, XKB_STATE_DEPRESSED);
mods_latched = xkb_state_serialize_mods(xkb->state, XKB_STATE_LATCHED);
diff --git a/libswc/xkb.h b/libswc/xkb.h
@@ -4,6 +4,9 @@
#ifndef SWC_XKB_H
#define SWC_XKB_H
+/* Keycodes are offset by 8 in XKB. */
+#define XKB_KEY(key) ((key) + 8)
+
struct swc_xkb
{
struct xkb_context * context;