2012-03-20 20:20:07 -06:00
|
|
|
/*
|
|
|
|
* 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>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <linux/input.h>
|
2012-03-30 17:44:39 -06:00
|
|
|
|
2012-03-20 20:20:07 -06:00
|
|
|
#include "xkbcommon/xkbcommon.h"
|
2012-05-08 10:59:35 -06:00
|
|
|
#include "xkbcommon/xkbcommon-names.h"
|
2012-05-08 05:52:23 -06:00
|
|
|
#include "xkb-priv.h"
|
2012-03-20 20:20:07 -06:00
|
|
|
|
|
|
|
/* Offset between evdev keycodes (where KEY_ESCAPE is 1), and the evdev XKB
|
|
|
|
* keycode set (where ESC is 9). */
|
|
|
|
#define EVDEV_OFFSET 8
|
|
|
|
|
2012-03-21 09:25:32 -06:00
|
|
|
static void
|
|
|
|
print_state(struct xkb_state *state)
|
|
|
|
{
|
2012-06-06 01:38:45 -06:00
|
|
|
struct xkb_keymap *keymap;
|
2012-03-21 09:25:32 -06:00
|
|
|
xkb_group_index_t group;
|
|
|
|
xkb_mod_index_t mod;
|
2012-03-22 08:32:53 -06:00
|
|
|
xkb_led_index_t led;
|
2012-03-21 09:25:32 -06:00
|
|
|
|
2012-06-06 01:38:45 -06:00
|
|
|
group = xkb_state_serialize_group(state, XKB_STATE_EFFECTIVE);
|
|
|
|
mod = xkb_state_serialize_mods(state, XKB_STATE_EFFECTIVE);
|
|
|
|
/* led = xkb_state_serialize_leds(state, XKB_STATE_EFFECTIVE); */
|
|
|
|
if (!group && !mod /* && !led */) {
|
2012-03-21 09:25:32 -06:00
|
|
|
fprintf(stderr, "\tno state\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-06 01:38:45 -06:00
|
|
|
keymap = xkb_state_get_map(state);
|
|
|
|
|
|
|
|
for (group = 0; group < xkb_map_num_groups(keymap); group++) {
|
2012-03-22 08:32:53 -06:00
|
|
|
if (!xkb_state_group_index_is_active(state, group, XKB_STATE_EFFECTIVE))
|
2012-03-21 09:25:32 -06:00
|
|
|
continue;
|
|
|
|
fprintf(stderr, "\tgroup %s (%d): %s%s%s%s\n",
|
2012-06-06 01:38:45 -06:00
|
|
|
xkb_map_group_get_name(keymap, group),
|
2012-03-21 09:25:32 -06:00
|
|
|
group,
|
2012-03-22 08:32:53 -06:00
|
|
|
xkb_state_group_index_is_active(state, group, XKB_STATE_EFFECTIVE) ?
|
|
|
|
"effective " : "",
|
|
|
|
xkb_state_group_index_is_active(state, group, XKB_STATE_DEPRESSED) ?
|
|
|
|
"depressed " : "",
|
|
|
|
xkb_state_group_index_is_active(state, group, XKB_STATE_LATCHED) ?
|
|
|
|
"latched " : "",
|
|
|
|
xkb_state_group_index_is_active(state, group, XKB_STATE_LOCKED) ?
|
|
|
|
"locked " : "");
|
2012-03-21 09:25:32 -06:00
|
|
|
}
|
|
|
|
|
2012-06-06 01:38:45 -06:00
|
|
|
for (mod = 0; mod < xkb_map_num_mods(keymap); mod++) {
|
2012-03-22 08:32:53 -06:00
|
|
|
if (!xkb_state_mod_index_is_active(state, mod, XKB_STATE_EFFECTIVE))
|
2012-03-21 09:25:32 -06:00
|
|
|
continue;
|
|
|
|
fprintf(stderr, "\tmod %s (%d): %s%s%s\n",
|
2012-06-06 01:38:45 -06:00
|
|
|
xkb_map_mod_get_name(keymap, mod),
|
2012-03-21 09:25:32 -06:00
|
|
|
mod,
|
2012-03-22 08:32:53 -06:00
|
|
|
xkb_state_mod_index_is_active(state, mod, XKB_STATE_DEPRESSED) ?
|
|
|
|
"depressed " : "",
|
|
|
|
xkb_state_mod_index_is_active(state, mod, XKB_STATE_LATCHED) ?
|
|
|
|
"latched " : "",
|
|
|
|
xkb_state_mod_index_is_active(state, mod, XKB_STATE_LOCKED) ?
|
|
|
|
"locked " : "");
|
|
|
|
}
|
|
|
|
|
2012-06-06 01:38:45 -06:00
|
|
|
for (led = 0; led < xkb_map_num_leds(keymap); led++) {
|
2012-03-22 08:32:53 -06:00
|
|
|
if (!xkb_state_led_index_is_active(state, led))
|
|
|
|
continue;
|
|
|
|
fprintf(stderr, "\tled %s (%d): active\n",
|
2012-06-06 01:38:45 -06:00
|
|
|
xkb_map_led_get_name(keymap, led),
|
2012-03-22 08:32:53 -06:00
|
|
|
led);
|
2012-03-21 09:25:32 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-27 05:07:57 -06:00
|
|
|
static void
|
2012-05-09 08:15:30 -06:00
|
|
|
test_update_key(struct xkb_keymap *keymap)
|
2012-03-20 20:20:07 -06:00
|
|
|
{
|
2012-05-09 08:15:30 -06:00
|
|
|
struct xkb_state *state = xkb_state_new(keymap);
|
2012-03-30 17:44:39 -06:00
|
|
|
const xkb_keysym_t *syms;
|
2012-03-27 05:07:57 -06:00
|
|
|
int num_syms;
|
2012-03-20 20:20:07 -06:00
|
|
|
|
2012-03-27 05:07:57 -06:00
|
|
|
assert(state);
|
2012-03-20 20:20:07 -06:00
|
|
|
|
|
|
|
/* LCtrl down */
|
2012-03-27 05:11:45 -06:00
|
|
|
xkb_state_update_key(state, KEY_LEFTCTRL + EVDEV_OFFSET, XKB_KEY_DOWN);
|
2012-03-21 09:25:32 -06:00
|
|
|
fprintf(stderr, "dumping state for LCtrl down:\n");
|
|
|
|
print_state(state);
|
2012-05-08 10:59:35 -06:00
|
|
|
assert(xkb_state_mod_name_is_active(state, XKB_MOD_NAME_CTRL,
|
2012-03-21 09:25:32 -06:00
|
|
|
XKB_STATE_DEPRESSED));
|
2012-03-20 20:20:07 -06:00
|
|
|
|
|
|
|
/* LCtrl + RAlt down */
|
2012-03-27 05:11:45 -06:00
|
|
|
xkb_state_update_key(state, KEY_RIGHTALT + EVDEV_OFFSET, XKB_KEY_DOWN);
|
2012-03-21 09:25:32 -06:00
|
|
|
fprintf(stderr, "dumping state for LCtrl + RAlt down:\n");
|
|
|
|
print_state(state);
|
2012-05-08 10:59:35 -06:00
|
|
|
assert(xkb_state_mod_name_is_active(state, XKB_MOD_NAME_CTRL,
|
2012-03-21 09:25:32 -06:00
|
|
|
XKB_STATE_DEPRESSED));
|
2012-05-08 10:59:35 -06:00
|
|
|
assert(xkb_state_mod_name_is_active(state, XKB_MOD_NAME_ALT,
|
2012-03-21 09:25:32 -06:00
|
|
|
XKB_STATE_DEPRESSED));
|
2012-05-08 18:06:10 -06:00
|
|
|
assert(xkb_state_mod_names_are_active(state, XKB_STATE_DEPRESSED,
|
|
|
|
XKB_STATE_MATCH_ALL,
|
|
|
|
XKB_MOD_NAME_CTRL,
|
|
|
|
XKB_MOD_NAME_ALT,
|
|
|
|
NULL));
|
|
|
|
assert(!xkb_state_mod_names_are_active(state, XKB_STATE_DEPRESSED,
|
|
|
|
XKB_STATE_MATCH_ALL,
|
|
|
|
XKB_MOD_NAME_ALT,
|
|
|
|
NULL));
|
|
|
|
assert(xkb_state_mod_names_are_active(state, XKB_STATE_DEPRESSED,
|
|
|
|
(XKB_STATE_MATCH_ANY |
|
|
|
|
XKB_STATE_MATCH_NON_EXCLUSIVE),
|
|
|
|
XKB_MOD_NAME_ALT,
|
|
|
|
NULL));
|
2012-03-20 20:20:07 -06:00
|
|
|
|
|
|
|
/* RAlt down */
|
2012-03-27 05:11:45 -06:00
|
|
|
xkb_state_update_key(state, KEY_LEFTCTRL + EVDEV_OFFSET, XKB_KEY_UP);
|
2012-03-21 09:25:32 -06:00
|
|
|
fprintf(stderr, "dumping state for RAlt down:\n");
|
|
|
|
print_state(state);
|
2012-05-08 10:59:35 -06:00
|
|
|
assert(!xkb_state_mod_name_is_active(state, XKB_MOD_NAME_CTRL,
|
2012-03-21 09:25:32 -06:00
|
|
|
XKB_STATE_EFFECTIVE));
|
2012-05-08 10:59:35 -06:00
|
|
|
assert(xkb_state_mod_name_is_active(state, XKB_MOD_NAME_ALT,
|
2012-03-21 09:25:32 -06:00
|
|
|
XKB_STATE_DEPRESSED));
|
2012-05-08 18:06:10 -06:00
|
|
|
assert(xkb_state_mod_names_are_active(state, XKB_STATE_DEPRESSED,
|
|
|
|
XKB_STATE_MATCH_ANY,
|
|
|
|
XKB_MOD_NAME_CTRL,
|
|
|
|
XKB_MOD_NAME_ALT,
|
|
|
|
NULL));
|
2012-03-20 20:20:07 -06:00
|
|
|
|
|
|
|
/* none down */
|
2012-03-27 05:11:45 -06:00
|
|
|
xkb_state_update_key(state, KEY_RIGHTALT + EVDEV_OFFSET, XKB_KEY_UP);
|
2012-05-08 10:59:35 -06:00
|
|
|
assert(!xkb_state_mod_name_is_active(state, XKB_MOD_NAME_ALT,
|
2012-03-21 09:25:32 -06:00
|
|
|
XKB_STATE_EFFECTIVE));
|
2012-03-20 20:20:07 -06:00
|
|
|
|
|
|
|
/* Caps locked */
|
2012-03-27 05:11:45 -06:00
|
|
|
xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, XKB_KEY_DOWN);
|
|
|
|
xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, XKB_KEY_UP);
|
2012-03-21 09:25:32 -06:00
|
|
|
fprintf(stderr, "dumping state for Caps Lock:\n");
|
|
|
|
print_state(state);
|
2012-05-08 10:59:35 -06:00
|
|
|
assert(xkb_state_mod_name_is_active(state, XKB_MOD_NAME_CAPS,
|
2012-03-21 09:25:32 -06:00
|
|
|
XKB_STATE_LOCKED));
|
2012-05-09 13:18:30 -06:00
|
|
|
assert(xkb_state_led_name_is_active(state, XKB_LED_NAME_CAPS));
|
2012-03-20 20:20:07 -06:00
|
|
|
num_syms = xkb_key_get_syms(state, KEY_Q + EVDEV_OFFSET, &syms);
|
2012-05-09 07:05:00 -06:00
|
|
|
assert(num_syms == 1 && syms[0] == XKB_KEY_Q);
|
2012-03-20 20:20:07 -06:00
|
|
|
|
|
|
|
/* Caps unlocked */
|
2012-03-27 05:11:45 -06:00
|
|
|
xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, XKB_KEY_DOWN);
|
|
|
|
xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, XKB_KEY_UP);
|
2012-05-08 10:59:35 -06:00
|
|
|
assert(!xkb_state_mod_name_is_active(state, XKB_MOD_NAME_CAPS,
|
2012-03-21 09:25:32 -06:00
|
|
|
XKB_STATE_EFFECTIVE));
|
2012-05-09 13:18:30 -06:00
|
|
|
assert(!xkb_state_led_name_is_active(state, XKB_LED_NAME_CAPS));
|
2012-03-20 20:20:07 -06:00
|
|
|
num_syms = xkb_key_get_syms(state, KEY_Q + EVDEV_OFFSET, &syms);
|
2012-05-09 07:05:00 -06:00
|
|
|
assert(num_syms == 1 && syms[0] == XKB_KEY_q);
|
2012-03-20 20:20:07 -06:00
|
|
|
|
|
|
|
xkb_state_unref(state);
|
2012-03-27 05:07:57 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-09 08:15:30 -06:00
|
|
|
test_serialisation(struct xkb_keymap *keymap)
|
2012-03-27 05:07:57 -06:00
|
|
|
{
|
2012-05-09 08:15:30 -06:00
|
|
|
struct xkb_state *state = xkb_state_new(keymap);
|
2012-03-27 05:07:57 -06:00
|
|
|
xkb_mod_mask_t base_mods;
|
|
|
|
xkb_mod_mask_t latched_mods;
|
|
|
|
xkb_mod_mask_t locked_mods;
|
|
|
|
xkb_mod_mask_t effective_mods;
|
|
|
|
xkb_mod_index_t caps, shift, ctrl;
|
|
|
|
xkb_group_index_t base_group = 0;
|
|
|
|
xkb_group_index_t latched_group = 0;
|
|
|
|
xkb_group_index_t locked_group = 0;
|
|
|
|
|
|
|
|
assert(state);
|
|
|
|
|
2012-06-06 01:38:45 -06:00
|
|
|
caps = xkb_map_mod_get_index(keymap, XKB_MOD_NAME_CAPS);
|
2012-03-27 05:07:57 -06:00
|
|
|
assert(caps != XKB_MOD_INVALID);
|
2012-06-06 01:38:45 -06:00
|
|
|
shift = xkb_map_mod_get_index(keymap, XKB_MOD_NAME_SHIFT);
|
2012-03-27 05:07:57 -06:00
|
|
|
assert(shift != XKB_MOD_INVALID);
|
2012-06-06 01:38:45 -06:00
|
|
|
ctrl = xkb_map_mod_get_index(keymap, XKB_MOD_NAME_CTRL);
|
2012-03-27 05:07:57 -06:00
|
|
|
assert(ctrl != XKB_MOD_INVALID);
|
2012-03-20 20:20:07 -06:00
|
|
|
|
2012-03-27 05:11:45 -06:00
|
|
|
xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, XKB_KEY_DOWN);
|
|
|
|
xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, XKB_KEY_UP);
|
2012-05-09 13:20:12 -06:00
|
|
|
base_mods = xkb_state_serialize_mods(state, XKB_STATE_DEPRESSED);
|
2012-03-27 05:07:57 -06:00
|
|
|
assert(base_mods == 0);
|
2012-05-09 13:20:12 -06:00
|
|
|
latched_mods = xkb_state_serialize_mods(state, XKB_STATE_LATCHED);
|
2012-03-27 05:07:57 -06:00
|
|
|
assert(latched_mods == 0);
|
2012-05-09 13:20:12 -06:00
|
|
|
locked_mods = xkb_state_serialize_mods(state, XKB_STATE_LOCKED);
|
2012-03-27 05:07:57 -06:00
|
|
|
assert(locked_mods == (1 << caps));
|
2012-05-09 13:20:12 -06:00
|
|
|
effective_mods = xkb_state_serialize_mods(state, XKB_STATE_EFFECTIVE);
|
2012-03-27 05:07:57 -06:00
|
|
|
assert(effective_mods == locked_mods);
|
|
|
|
|
2012-03-27 05:11:45 -06:00
|
|
|
xkb_state_update_key(state, KEY_LEFTSHIFT + EVDEV_OFFSET, XKB_KEY_DOWN);
|
2012-05-09 13:20:12 -06:00
|
|
|
base_mods = xkb_state_serialize_mods(state, XKB_STATE_DEPRESSED);
|
2012-03-27 05:07:57 -06:00
|
|
|
assert(base_mods == (1 << shift));
|
2012-05-09 13:20:12 -06:00
|
|
|
latched_mods = xkb_state_serialize_mods(state, XKB_STATE_LATCHED);
|
2012-03-27 05:07:57 -06:00
|
|
|
assert(latched_mods == 0);
|
2012-05-09 13:20:12 -06:00
|
|
|
locked_mods = xkb_state_serialize_mods(state, XKB_STATE_LOCKED);
|
2012-03-27 05:07:57 -06:00
|
|
|
assert(locked_mods == (1 << caps));
|
2012-05-09 13:20:12 -06:00
|
|
|
effective_mods = xkb_state_serialize_mods(state, XKB_STATE_EFFECTIVE);
|
2012-03-27 05:07:57 -06:00
|
|
|
assert(effective_mods == (base_mods | locked_mods));
|
|
|
|
|
|
|
|
base_mods |= (1 << ctrl);
|
|
|
|
xkb_state_update_mask(state, base_mods, latched_mods, locked_mods,
|
|
|
|
base_group, latched_group, locked_group);
|
|
|
|
|
|
|
|
assert(xkb_state_mod_index_is_active(state, ctrl, XKB_STATE_DEPRESSED));
|
|
|
|
assert(xkb_state_mod_index_is_active(state, ctrl, XKB_STATE_EFFECTIVE));
|
|
|
|
|
|
|
|
xkb_state_unref(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-03-30 17:44:39 -06:00
|
|
|
main(void)
|
2012-03-27 05:07:57 -06:00
|
|
|
{
|
2012-05-11 08:03:43 -06:00
|
|
|
struct xkb_context *context;
|
2012-05-09 08:15:30 -06:00
|
|
|
struct xkb_keymap *keymap;
|
2012-03-30 17:44:39 -06:00
|
|
|
struct xkb_rule_names rmlvo = {
|
|
|
|
.rules = "evdev",
|
|
|
|
.model = "pc104",
|
|
|
|
.layout = "us",
|
|
|
|
.variant = NULL,
|
|
|
|
.options = NULL,
|
|
|
|
};
|
2012-03-27 05:07:57 -06:00
|
|
|
|
2012-05-11 08:03:43 -06:00
|
|
|
context = xkb_context_new(0);
|
|
|
|
assert(context);
|
2012-03-27 10:22:35 -06:00
|
|
|
|
2012-05-11 08:03:43 -06:00
|
|
|
keymap = xkb_map_new_from_names(context, &rmlvo, 0);
|
2012-05-09 08:15:30 -06:00
|
|
|
assert(keymap);
|
2012-03-27 05:07:57 -06:00
|
|
|
|
2012-05-09 08:15:30 -06:00
|
|
|
test_update_key(keymap);
|
|
|
|
test_serialisation(keymap);
|
2012-03-27 05:07:57 -06:00
|
|
|
|
2012-05-09 08:15:30 -06:00
|
|
|
xkb_map_unref(keymap);
|
2012-05-11 08:03:43 -06:00
|
|
|
xkb_context_unref(context);
|
2012-03-20 20:20:07 -06:00
|
|
|
}
|