From 74a197d2713fe1e04c2a3f116f1aa10264360653 Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Tue, 8 May 2012 17:59:35 +0100 Subject: [PATCH] Add pre-defined names database xkbcommon-names.h right now just contains a set of hardcoded modifier strings that are most commonly used for the usual modifiers. Provide definitions of these so people don't have to worry about typoing a string or mixing up Mod1 and Mod4. Signed-off-by: Daniel Stone --- Makefile.am | 4 +++- include/xkbcommon/xkbcommon-names.h | 35 +++++++++++++++++++++++++++++ test/state.c | 27 +++++++++++----------- 3 files changed, 52 insertions(+), 14 deletions(-) create mode 100644 include/xkbcommon/xkbcommon-names.h diff --git a/Makefile.am b/Makefile.am index 0b58c70..5e929d5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -30,7 +30,9 @@ AM_CFLAGS = \ AM_YFLAGS = -d xkbcommonincludedir = $(includedir)/xkbcommon -xkbcommoninclude_HEADERS = include/xkbcommon/xkbcommon.h +xkbcommoninclude_HEADERS = \ + include/xkbcommon/xkbcommon.h \ + include/xkbcommon/xkbcommon-names.h lib_LTLIBRARIES = libxkbcommon.la libxkbcommon_la_LDFLAGS = -no-undefined diff --git a/include/xkbcommon/xkbcommon-names.h b/include/xkbcommon/xkbcommon-names.h new file mode 100644 index 0000000..45e9df5 --- /dev/null +++ b/include/xkbcommon/xkbcommon-names.h @@ -0,0 +1,35 @@ +/* + * Copyright © 2012 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Author: Daniel Stone + */ + +#ifndef _XKBCOMMON_NAMES_H +#define _XKBCOMMON_NAMES_H + +#define XKB_MOD_NAME_SHIFT "Shift" +#define XKB_MOD_NAME_CAPS "Caps Lock" +#define XKB_MOD_NAME_CTRL "Control" +#define XKB_MOD_NAME_ALT "Mod1" +#define XKB_MOD_NAME_LOGO "Mod4" + +#endif diff --git a/test/state.c b/test/state.c index 1d8d138..c081ba6 100644 --- a/test/state.c +++ b/test/state.c @@ -30,6 +30,7 @@ #include #include "xkbcommon/xkbcommon.h" +#include "xkbcommon/xkbcommon-names.h" #include "xkb-priv.h" /* Offset between evdev keycodes (where KEY_ESCAPE is 1), and the evdev XKB @@ -100,30 +101,30 @@ test_update_key(struct xkb_keymap *xkb) xkb_state_update_key(state, KEY_LEFTCTRL + EVDEV_OFFSET, XKB_KEY_DOWN); fprintf(stderr, "dumping state for LCtrl down:\n"); print_state(state); - assert(xkb_state_mod_name_is_active(state, "Control", + assert(xkb_state_mod_name_is_active(state, XKB_MOD_NAME_CTRL, XKB_STATE_DEPRESSED)); /* LCtrl + RAlt down */ xkb_state_update_key(state, KEY_RIGHTALT + EVDEV_OFFSET, XKB_KEY_DOWN); fprintf(stderr, "dumping state for LCtrl + RAlt down:\n"); print_state(state); - assert(xkb_state_mod_name_is_active(state, "Control", + assert(xkb_state_mod_name_is_active(state, XKB_MOD_NAME_CTRL, XKB_STATE_DEPRESSED)); - assert(xkb_state_mod_name_is_active(state, "Mod1", + assert(xkb_state_mod_name_is_active(state, XKB_MOD_NAME_ALT, XKB_STATE_DEPRESSED)); /* RAlt down */ xkb_state_update_key(state, KEY_LEFTCTRL + EVDEV_OFFSET, XKB_KEY_UP); fprintf(stderr, "dumping state for RAlt down:\n"); print_state(state); - assert(!xkb_state_mod_name_is_active(state, "Control", + assert(!xkb_state_mod_name_is_active(state, XKB_MOD_NAME_CTRL, XKB_STATE_EFFECTIVE)); - assert(xkb_state_mod_name_is_active(state, "Mod1", + assert(xkb_state_mod_name_is_active(state, XKB_MOD_NAME_ALT, XKB_STATE_DEPRESSED)); /* none down */ xkb_state_update_key(state, KEY_RIGHTALT + EVDEV_OFFSET, XKB_KEY_UP); - assert(!xkb_state_mod_name_is_active(state, "Mod1", + assert(!xkb_state_mod_name_is_active(state, XKB_MOD_NAME_ALT, XKB_STATE_EFFECTIVE)); /* Caps locked */ @@ -131,18 +132,18 @@ test_update_key(struct xkb_keymap *xkb) xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, XKB_KEY_UP); fprintf(stderr, "dumping state for Caps Lock:\n"); print_state(state); - assert(xkb_state_mod_name_is_active(state, "Caps Lock", + assert(xkb_state_mod_name_is_active(state, XKB_MOD_NAME_CAPS, XKB_STATE_LOCKED)); - assert(xkb_state_led_name_is_active(state, "Caps Lock")); + assert(xkb_state_led_name_is_active(state, XKB_MOD_NAME_CAPS)); num_syms = xkb_key_get_syms(state, KEY_Q + EVDEV_OFFSET, &syms); assert(num_syms == 1 && syms[0] == XK_Q); /* Caps unlocked */ xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, XKB_KEY_DOWN); xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, XKB_KEY_UP); - assert(!xkb_state_mod_name_is_active(state, "Caps Lock", + assert(!xkb_state_mod_name_is_active(state, XKB_MOD_NAME_CAPS, XKB_STATE_EFFECTIVE)); - assert(!xkb_state_led_name_is_active(state, "Caps Lock")); + assert(!xkb_state_led_name_is_active(state, XKB_MOD_NAME_CAPS)); num_syms = xkb_key_get_syms(state, KEY_Q + EVDEV_OFFSET, &syms); assert(num_syms == 1 && syms[0] == XK_q); @@ -164,11 +165,11 @@ test_serialisation(struct xkb_keymap *xkb) assert(state); - caps = xkb_map_mod_get_index(state->xkb, "Caps Lock"); + caps = xkb_map_mod_get_index(state->xkb, XKB_MOD_NAME_CAPS); assert(caps != XKB_MOD_INVALID); - shift = xkb_map_mod_get_index(state->xkb, "Shift"); + shift = xkb_map_mod_get_index(state->xkb, XKB_MOD_NAME_SHIFT); assert(shift != XKB_MOD_INVALID); - ctrl = xkb_map_mod_get_index(state->xkb, "Control"); + ctrl = xkb_map_mod_get_index(state->xkb, XKB_MOD_NAME_CTRL); assert(ctrl != XKB_MOD_INVALID); xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, XKB_KEY_DOWN);