return keymap;
}
+
+void
+test_print_keycode_state(struct xkb_state *state, xkb_keycode_t keycode)
+{
+ struct xkb_keymap *keymap;
+
+ const xkb_keysym_t *syms;
+ int nsyms;
+ char s[16];
+ xkb_layout_index_t layout;
+
+ keymap = xkb_state_get_keymap(state);
+
+ nsyms = xkb_state_key_get_syms(state, keycode, &syms);
+
+ if (nsyms <= 0)
+ return;
+
+ if (nsyms == 1) {
+ xkb_keysym_t sym = xkb_state_key_get_one_sym(state, keycode);
+ xkb_keysym_get_name(sym, s, sizeof(s));
+ printf("keysym [ %-*s ] ", (int) sizeof(s), s);
+ }
+ else {
+ printf("keysyms [ ");
+ for (int i = 0; i < nsyms; i++) {
+ xkb_keysym_get_name(syms[i], s, sizeof(s));
+ printf("%-*s ", (int) sizeof(s), s);
+ }
+ printf("] ");
+ }
+
+ /*
+ * Only do this if wchar_t is UCS-4, so we can be lazy and print
+ * with %lc.
+ */
+#ifdef __STDC_ISO_10646__
+ printf("unicode [ ");
+ for (int i = 0; i < nsyms; i++) {
+ uint32_t unicode = xkb_keysym_to_utf32(syms[i]);
+ printf("%lc ", (int)(unicode ? unicode : L' '));
+ }
+ printf("] ");
+#endif
+
+ layout = xkb_state_key_get_layout(state, keycode);
+ printf("layout [ %s (%d) ] ",
+ xkb_keymap_layout_get_name(keymap, layout), layout);
+
+ printf("level [ %d ] ",
+ xkb_state_key_get_level(state, keycode, layout));
+
+ printf("mods [ ");
+ for (xkb_mod_index_t mod = 0; mod < xkb_keymap_num_mods(keymap); mod++) {
+ if (xkb_state_mod_index_is_active(state, mod,
+ XKB_STATE_MODS_EFFECTIVE) <= 0)
+ continue;
+ if (xkb_state_mod_index_is_consumed(state, keycode, mod))
+ printf("-%s ", xkb_keymap_mod_get_name(keymap, mod));
+ else
+ printf("%s ", xkb_keymap_mod_get_name(keymap, mod));
+ }
+ printf("] ");
+
+ printf("leds [ ");
+ for (xkb_led_index_t led = 0; led < xkb_keymap_num_leds(keymap); led++) {
+ if (xkb_state_led_index_is_active(state, led) <= 0)
+ continue;
+ printf("%s ", xkb_keymap_led_get_name(keymap, led));
+ }
+ printf("] ");
+
+ printf("\n");
+}
+
+void
+test_print_state_changes(enum xkb_state_component changed)
+{
+ if (changed == 0)
+ return;
+
+ printf("changed [ ");
+ if (changed & XKB_STATE_LAYOUT_EFFECTIVE)
+ printf("effective-layout ");
+ if (changed & XKB_STATE_LAYOUT_DEPRESSED)
+ printf("depressed-layout ");
+ if (changed & XKB_STATE_LAYOUT_LATCHED)
+ printf("latched-layout ");
+ if (changed & XKB_STATE_LAYOUT_LOCKED)
+ printf("locked-layout ");
+ if (changed & XKB_STATE_MODS_EFFECTIVE)
+ printf("effective-mods ");
+ if (changed & XKB_STATE_MODS_DEPRESSED)
+ printf("depressed-mods ");
+ if (changed & XKB_STATE_MODS_LATCHED)
+ printf("latched-mods ");
+ if (changed & XKB_STATE_MODS_LOCKED)
+ printf("locked-mods ");
+ if (changed & XKB_STATE_LEDS)
+ printf("leds ");
+ printf("]\n");
+}
}
}
-static void
-print_keycode(struct keyboard *kbd, xkb_keycode_t keycode)
-{
- struct xkb_keymap *keymap;
- struct xkb_state *state;
-
- const xkb_keysym_t *syms;
- int nsyms;
- char s[16];
- xkb_layout_index_t layout;
-
- state = kbd->state;
- keymap = xkb_state_get_keymap(state);
-
- nsyms = xkb_state_key_get_syms(state, keycode, &syms);
-
- if (nsyms <= 0)
- return;
-
- if (nsyms == 1) {
- xkb_keysym_t sym = xkb_state_key_get_one_sym(state, keycode);
- xkb_keysym_get_name(sym, s, sizeof(s));
- printf("keysym [ %-*s ] ", (int) sizeof(s), s);
- }
- else {
- printf("keysyms [ ");
- for (int i = 0; i < nsyms; i++) {
- xkb_keysym_get_name(syms[i], s, sizeof(s));
- printf("%-*s ", (int) sizeof(s), s);
- }
- printf("] ");
- }
-
- /*
- * Only do this if wchar_t is UCS-4, so we can be lazy and print
- * with %lc.
- */
-#ifdef __STDC_ISO_10646__
- printf("unicode [ ");
- for (int i = 0; i < nsyms; i++) {
- uint32_t unicode = xkb_keysym_to_utf32(syms[i]);
- printf("%lc ", (int)(unicode ? unicode : L' '));
- }
- printf("] ");
-#endif
-
- layout = xkb_state_key_get_layout(state, keycode);
- printf("layout [ %s (%d) ] ",
- xkb_keymap_layout_get_name(keymap, layout), layout);
-
- printf("level [ %d ] ",
- xkb_state_key_get_level(state, keycode, layout));
-
- printf("mods [ ");
- for (xkb_mod_index_t mod = 0; mod < xkb_keymap_num_mods(keymap); mod++) {
- if (xkb_state_mod_index_is_active(state, mod,
- XKB_STATE_MODS_EFFECTIVE) <= 0)
- continue;
- if (xkb_state_mod_index_is_consumed(state, keycode, mod))
- printf("-%s ", xkb_keymap_mod_get_name(keymap, mod));
- else
- printf("%s ", xkb_keymap_mod_get_name(keymap, mod));
- }
- printf("] ");
-
- printf("leds [ ");
- for (xkb_led_index_t led = 0; led < xkb_keymap_num_leds(keymap); led++) {
- if (xkb_state_led_index_is_active(state, led) <= 0)
- continue;
- printf("%s ", xkb_keymap_led_get_name(keymap, led));
- }
- printf("] ");
-
- printf("\n");
-}
-
-static void
-print_state_changes(enum xkb_state_component changed)
-{
- if (changed == 0)
- return;
-
- printf("changed [ ");
- if (changed & XKB_STATE_LAYOUT_EFFECTIVE)
- printf("effective-layout ");
- if (changed & XKB_STATE_LAYOUT_DEPRESSED)
- printf("depressed-layout ");
- if (changed & XKB_STATE_LAYOUT_LATCHED)
- printf("latched-layout ");
- if (changed & XKB_STATE_LAYOUT_LOCKED)
- printf("locked-layout ");
- if (changed & XKB_STATE_MODS_EFFECTIVE)
- printf("effective-mods ");
- if (changed & XKB_STATE_MODS_DEPRESSED)
- printf("depressed-mods ");
- if (changed & XKB_STATE_MODS_LATCHED)
- printf("latched-mods ");
- if (changed & XKB_STATE_MODS_LOCKED)
- printf("locked-mods ");
- if (changed & XKB_STATE_LEDS)
- printf("leds ");
- printf("]\n");
-}
-
/* The meaning of the input_event 'value' field. */
enum {
KEY_STATE_RELEASE = 0,
return;
if (value != KEY_STATE_RELEASE)
- print_keycode(kbd, keycode);
+ test_print_keycode_state(kbd->state, keycode);
if (value == KEY_STATE_RELEASE)
changed = xkb_state_update_key(kbd->state, keycode, XKB_KEY_UP);
changed = xkb_state_update_key(kbd->state, keycode, XKB_KEY_DOWN);
if (report_state_changes)
- print_state_changes(changed);
+ test_print_state_changes(changed);
}
static int