Imported Upstream version 0.1.0+git20131207+e452e83
[deb_libhybris.git] / hybris / tests / test_input.c
1 /*
2 * Copyright (C) 2013 Canonical Ltd
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 * Authored by: Thomas Voß <thomas.voss@canonical.com>
17 * Ricardo Salveti de Araujo <ricardo.salveti@canonical.com>
18 */
19
20 #include <stddef.h>
21 #include <stdio.h>
22 #include <stdbool.h>
23 #include <signal.h>
24
25 #include <hybris/input/input_stack_compatibility_layer.h>
26
27 bool g_stop = false;
28
29 void signal_handler(int sig)
30 {
31 g_stop = true;
32 }
33
34 void on_new_event(struct Event* event, void* context)
35 {
36 printf("%s", __PRETTY_FUNCTION__);
37
38 printf("\tEventType: %d \n", event->type);
39 printf("\tdevice_id: %d \n", event->device_id);
40 printf("\tsource_id: %d \n", event->source_id);
41 printf("\taction: %d \n", event->action);
42 printf("\tflags: %d \n", event->flags);
43 printf("\tmeta_state: %d \n", event->meta_state);
44
45 switch (event->type) {
46 case MOTION_EVENT_TYPE:
47 printf("\tdetails.motion.event_time: %lld\n",
48 event->details.motion.event_time);
49 printf("\tdetails.motion.pointer_coords.x: %f\n",
50 event->details.motion.pointer_coordinates[0].x);
51 printf("\tdetails.motion.pointer_coords.y: %f\n",
52 event->details.motion.pointer_coordinates[0].y);
53 break;
54 default:
55 break;
56 }
57 }
58
59 int main(int argc, char** argv)
60 {
61 g_stop = false;
62 signal(SIGINT, signal_handler);
63
64 struct AndroidEventListener listener;
65 listener.on_new_event = on_new_event;
66 listener.context = NULL;
67
68 struct InputStackConfiguration config = {
69 enable_touch_point_visualization : true,
70 default_layer_for_touch_point_visualization : 10000,
71 input_area_width : 1024,
72 input_area_height : 1024
73 };
74
75 android_input_stack_initialize(&listener, &config);
76 android_input_stack_start_waiting_for_flag(&g_stop);
77
78 android_input_stack_stop();
79 android_input_stack_shutdown();
80 }