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 <daniel@fooishbar.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
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 <daniel@fooishbar.org>
+ */
+
+#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 <linux/input.h>
#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);