2 * test_input - Test the input system - hotplug and keypresses
4 * Copyright (c) 2011 Ran Benita <ran234@gmail.com>
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files
8 * (the "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #include <linux/input.h>
39 static bool terminate;
41 static void sig_term(struct kmscon_signal *sig, int signum, void *data)
46 /* Pressing Ctrl-\ should toggle the capturing. */
47 static void sig_quit(struct kmscon_signal *sig, int signum, void *data)
49 struct kmscon_input *input = data;
51 if (kmscon_input_is_asleep(input)) {
52 kmscon_input_wake_up(input);
53 log_info("Woke Up\n");
55 kmscon_input_sleep(input);
56 log_info("Went to sleep\n");
60 static void input_arrived(struct kmscon_input *input, uint16_t type,
61 uint16_t code, int32_t value, void *data)
63 printf("got (type %x) (code %x) (value %x)\n", type, code, value);
66 int main(int argc, char **argv)
69 struct kmscon_eloop *loop;
70 struct kmscon_input *input;
71 struct kmscon_signal *sigint, *sigquit;
73 ret = kmscon_eloop_new(&loop);
75 log_err("Cannot create eloop\n");
79 ret = kmscon_input_new(&input);
81 log_err("Cannot create input\n");
85 ret = kmscon_eloop_new_signal(loop, &sigint, SIGINT, sig_term, NULL);
87 log_err("Cannot add INT signal\n");
91 ret = kmscon_eloop_new_signal(loop, &sigquit, SIGQUIT, sig_quit, input);
93 log_err("Cannot add quit signal\n");
97 ret = kmscon_input_connect_eloop(input, loop, input_arrived, NULL);
99 log_err("Cannot connect input\n");
103 kmscon_input_wake_up(input);
105 system("stty -echo");
108 ret = kmscon_eloop_dispatch(loop, -1);
110 log_err("Dispatcher failed\n");
118 kmscon_eloop_rm_signal(sigquit);
120 kmscon_eloop_rm_signal(sigint);
122 kmscon_input_unref(input);
124 kmscon_eloop_unref(loop);