2 * Copyright © 2012 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
23 * Author: Daniel Stone <daniel@fooishbar.org>
30 #include <X11/Xdefs.h>
31 #include <X11/keysym.h>
32 #include <linux/input.h>
33 #include "xkbcommon/xkbcommon.h"
34 #include "xkbcomp/utils.h"
35 #include "XKBcommonint.h"
37 /* Offset between evdev keycodes (where KEY_ESCAPE is 1), and the evdev XKB
38 * keycode set (where ESC is 9). */
39 #define EVDEV_OFFSET 8
41 int main(int argc, char *argv[])
43 struct xkb_rule_names rmlvo;
45 struct xkb_state *state;
49 rmlvo.rules = "evdev";
50 rmlvo.model = "pc104";
55 xkb = xkb_compile_keymap_from_rules(&rmlvo);
58 fprintf(stderr, "Failed to compile keymap\n");
62 state = xkb_state_new(xkb);
63 assert(state->mods == 0);
64 assert(state->group == 0);
67 xkb_state_update_key(state, KEY_LEFTCTRL + EVDEV_OFFSET, 1);
68 assert(state->mods & ControlMask);
70 /* LCtrl + RAlt down */
71 xkb_state_update_key(state, KEY_RIGHTALT + EVDEV_OFFSET, 1);
72 assert(state->mods & Mod1Mask);
73 assert(state->locked_mods == 0);
74 assert(state->latched_mods == 0);
77 xkb_state_update_key(state, KEY_LEFTCTRL + EVDEV_OFFSET, 0);
78 assert(!(state->mods & ControlMask) && (state->mods & Mod1Mask));
81 xkb_state_update_key(state, KEY_RIGHTALT + EVDEV_OFFSET, 0);
82 assert(state->mods == 0);
83 assert(state->group == 0);
86 xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, 1);
87 xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, 0);
88 assert(state->mods & LockMask);
89 assert(state->mods == state->locked_mods);
90 num_syms = xkb_key_get_syms(state, KEY_Q + EVDEV_OFFSET, &syms);
91 assert(num_syms == 1 && syms[0] == XK_Q);
94 xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, 1);
95 xkb_state_update_key(state, KEY_CAPSLOCK + EVDEV_OFFSET, 0);
96 assert(state->mods == 0);
97 num_syms = xkb_key_get_syms(state, KEY_Q + EVDEV_OFFSET, &syms);
98 assert(num_syms == 1 && syms[0] == XK_q);
100 xkb_state_unref(state);
101 xkb_free_keymap(xkb);