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>master
parent
2a0f1780f9
commit
74a197d271
|
@ -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
|
||||
|
|
|
@ -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
|
27
test/state.c
27
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);
|
||||
|
|
Loading…
Reference in New Issue