summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@googlemail.com>2012-05-05 22:48:15 +0200
committerDavid Herrmann <dh.herrmann@googlemail.com>2012-05-05 22:48:15 +0200
commit3acc23c9325f46af76d2bc62ca9a85670063ee5d (patch)
treef288eb71dcfec37be40c5818578ca8941fae76f0 /tests
parent2d2c92e6c25ea41b19877ea6b794b590d3654e1e (diff)
test_input: use new input API
Use new uterm_monitor and input API instead. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/test_input.c109
1 files changed, 66 insertions, 43 deletions
diff --git a/tests/test_input.c b/tests/test_input.c
index cf6a145..09e7eec 100644
--- a/tests/test_input.c
+++ b/tests/test_input.c
@@ -2,6 +2,7 @@
* test_input - Test the input system - hotplug and keypresses
*
* Copyright (c) 2011 Ran Benita <ran234@gmail.com>
+ * Copyright (c) 2012 David Herrmann <dh.herrmann@googlemail.com>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files
@@ -33,58 +34,63 @@
#include <string.h>
#include <sys/signalfd.h>
#include <unistd.h>
-
#include <X11/keysym.h>
-
#include "eloop.h"
-#include "input.h"
-#include "kbd.h"
#include "log.h"
+#include "uterm.h"
#include "test_include.h"
+extern void kbd_dev_keysym_to_string(uint32_t keysym, char *str, size_t size);
+
+static struct ev_eloop *eloop;
+static struct uterm_input *input;
+
/* Pressing Ctrl-\ should toggle the capturing. */
-static void sig_quit(struct ev_eloop *p, struct signalfd_siginfo *info,
+static void sig_quit(struct ev_eloop *p,
+ struct signalfd_siginfo *info,
void *data)
{
- struct kmscon_input *input = data;
+ if (!input)
+ return;
- if (kmscon_input_is_asleep(input)) {
- kmscon_input_wake_up(input);
- log_info("Woke Up\n");
- } else {
- kmscon_input_sleep(input);
+ if (uterm_input_is_awake(input)) {
+ uterm_input_sleep(input);
log_info("Went to sleep\n");
+ } else {
+ uterm_input_wake_up(input);
+ log_info("Woke Up\n");
}
}
static void print_modifiers(unsigned int mods)
{
- if (mods & KMSCON_SHIFT_MASK)
+ if (mods & UTERM_SHIFT_MASK)
printf("SHIFT ");
- if (mods & KMSCON_LOCK_MASK)
+ if (mods & UTERM_LOCK_MASK)
printf("LOCK ");
- if (mods & KMSCON_CONTROL_MASK)
+ if (mods & UTERM_CONTROL_MASK)
printf("CONTROL ");
- if (mods & KMSCON_MOD1_MASK)
+ if (mods & UTERM_MOD1_MASK)
printf("MOD1 ");
- if (mods & KMSCON_MOD2_MASK)
+ if (mods & UTERM_MOD2_MASK)
printf("MOD2 ");
- if (mods & KMSCON_MOD3_MASK)
+ if (mods & UTERM_MOD3_MASK)
printf("MOD3 ");
- if (mods & KMSCON_MOD4_MASK)
+ if (mods & UTERM_MOD4_MASK)
printf("MOD4 ");
- if (mods & KMSCON_MOD5_MASK)
+ if (mods & UTERM_MOD5_MASK)
printf("MOD5 ");
printf("\n");
}
-static void input_arrived(struct kmscon_input *input,
- struct kmscon_input_event *ev, void *data)
+static void input_arrived(struct uterm_input *input,
+ struct uterm_input_event *ev,
+ void *data)
{
char s[16];
- if (ev->unicode == KMSCON_INPUT_INVALID) {
- kmscon_kbd_keysym_to_string(ev->keysym, s, sizeof(s));
+ if (ev->unicode == UTERM_INPUT_INVALID) {
+ kbd_dev_keysym_to_string(ev->keysym, s, sizeof(s));
printf("sym %s ", s);
} else {
/*
@@ -96,11 +102,39 @@ static void input_arrived(struct kmscon_input *input,
print_modifiers(ev->mods);
}
+static void monitor_event(struct uterm_monitor *mon,
+ struct uterm_monitor_event *ev,
+ void *data)
+{
+ int ret;
+
+ if (ev->type == UTERM_MONITOR_NEW_SEAT) {
+ if (strcmp(ev->seat_name, "seat0"))
+ return;
+
+ ret = uterm_input_new(&input, eloop);
+ if (ret)
+ return;
+ ret = uterm_input_register_cb(input, input_arrived, NULL);
+ if (ret)
+ return;
+ uterm_input_wake_up(input);
+ } else if (ev->type == UTERM_MONITOR_FREE_SEAT) {
+ uterm_input_unregister_cb(input, input_arrived, NULL);
+ uterm_input_unref(input);
+ } else if (ev->type == UTERM_MONITOR_NEW_DEV) {
+ if (ev->dev_type == UTERM_MONITOR_INPUT)
+ uterm_input_add_dev(input, ev->dev_node);
+ } else if (ev->type == UTERM_MONITOR_FREE_DEV) {
+ if (ev->dev_type == UTERM_MONITOR_INPUT)
+ uterm_input_remove_dev(input, ev->dev_node);
+ }
+}
+
int main(int argc, char **argv)
{
int ret;
- struct ev_eloop *eloop;
- struct kmscon_input *input;
+ struct uterm_monitor *mon;
ret = test_prepare(argc, argv, &eloop);
if (ret)
@@ -112,33 +146,22 @@ int main(int argc, char **argv)
goto err_exit;
}
- ret = kmscon_input_new(&input);
+ ret = uterm_monitor_new(&mon, eloop, monitor_event, NULL);
if (ret)
goto err_exit;
- ret = ev_eloop_register_signal_cb(eloop, SIGQUIT, sig_quit, input);
+ ret = ev_eloop_register_signal_cb(eloop, SIGQUIT, sig_quit, NULL);
if (ret)
- goto err_input;
-
- ret = kmscon_input_connect_eloop(input, eloop);
- if (ret)
- goto err_sigquit;
-
- ret = kmscon_input_register_cb(input, input_arrived, NULL);
- if (ret)
- goto err_sigquit;
-
- kmscon_input_wake_up(input);
+ goto err_mon;
system("stty -echo");
+ uterm_monitor_scan(mon);
ev_eloop_run(eloop, -1);
system("stty echo");
- kmscon_input_unregister_cb(input, input_arrived, NULL);
-err_sigquit:
- ev_eloop_unregister_signal_cb(eloop, SIGQUIT, sig_quit, input);
-err_input:
- kmscon_input_unref(input);
+ ev_eloop_unregister_signal_cb(eloop, SIGQUIT, sig_quit, NULL);
+err_mon:
+ uterm_monitor_unref(mon);
err_exit:
test_exit(eloop);
err_fail: