summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRan Benita <ran234@gmail.com>2012-10-22 21:16:35 +0200
committerRan Benita <ran234@gmail.com>2012-10-22 22:23:29 +0200
commita807494e470320cd1da3a7aaa7d60ebab0227c7a (patch)
treeb1a627ca8b412796324a43b2407d27db4f855358 /test
parent4b81c9f3e31a5128d4c9f55696f684948e5ad3f1 (diff)
test/interactive: add option to show state changes
Pass -c to see. Signed-off-by: Ran Benita <ran234@gmail.com>
Diffstat (limited to 'test')
-rw-r--r--test/interactive.c49
1 files changed, 43 insertions, 6 deletions
diff --git a/test/interactive.c b/test/interactive.c
index 333f2ff..90b1df2 100644
--- a/test/interactive.c
+++ b/test/interactive.c
@@ -46,6 +46,7 @@ struct keyboard {
static bool terminate;
static int evdev_offset = 8;
+static bool report_state_changes;
#define NLONGS(n) (((n) + LONG_BIT - 1) / LONG_BIT)
@@ -286,6 +287,34 @@ print_keycode(struct keyboard *kbd, xkb_keycode_t keycode)
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,
@@ -298,6 +327,7 @@ process_event(struct keyboard *kbd, uint16_t type, uint16_t code, int32_t value)
{
xkb_keycode_t keycode;
struct xkb_keymap *keymap;
+ enum xkb_state_component changed;
if (type != EV_KEY)
return;
@@ -312,9 +342,12 @@ process_event(struct keyboard *kbd, uint16_t type, uint16_t code, int32_t value)
print_keycode(kbd, keycode);
if (value == KEY_STATE_RELEASE)
- xkb_state_update_key(kbd->state, keycode, XKB_KEY_UP);
+ changed = xkb_state_update_key(kbd->state, keycode, XKB_KEY_UP);
else
- xkb_state_update_key(kbd->state, keycode, XKB_KEY_DOWN);
+ changed = xkb_state_update_key(kbd->state, keycode, XKB_KEY_DOWN);
+
+ if (report_state_changes)
+ print_state_changes(changed);
}
static int
@@ -422,7 +455,7 @@ main(int argc, char *argv[])
setlocale(LC_ALL, "");
- while ((opt = getopt(argc, argv, "r:m:l:v:o:k:n:")) != -1) {
+ while ((opt = getopt(argc, argv, "r:m:l:v:o:k:n:c")) != -1) {
switch (opt) {
case 'r':
rules = optarg;
@@ -450,13 +483,17 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
break;
+ case 'c':
+ report_state_changes = true;
+ break;
case '?':
- fprintf(stderr, "Usage: %s [-r <rules>] [-m <model>] "
+ fprintf(stderr, " Usage: %s [-r <rules>] [-m <model>] "
"[-l <layout>] [-v <variant>] [-o <options>]\n",
argv[0]);
- fprintf(stderr, " or: %s -k <path to keymap file>\n",
+ fprintf(stderr, " or: %s -k <path to keymap file>\n",
argv[0]);
- fprintf(stderr, "For both: -n <evdev keycode offset>\n");
+ fprintf(stderr, "For both: -n <evdev keycode offset>\n"
+ " -c (to report changes to the state)\n");
exit(EX_USAGE);
}
}