| 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 <hybris/input/input_stack_compatibility_layer.h> |
| 21 | |
| 22 | #include <gtest/gtest.h> |
| 23 | #include <utils/threads.h> |
| 24 | |
| 25 | #include <signal.h> |
| 26 | |
| 27 | namespace |
| 28 | { |
| 29 | |
| 30 | bool g_stop = false; |
| 31 | |
| 32 | void signal_handler(int) |
| 33 | { |
| 34 | g_stop = true; |
| 35 | } |
| 36 | |
| 37 | void on_new_event(Event* event, void* context) |
| 38 | { |
| 39 | printf("%s", __PRETTY_FUNCTION__); |
| 40 | |
| 41 | printf("\tEventType: %d \n", event->type); |
| 42 | printf("\tdevice_id: %d \n", event->device_id); |
| 43 | printf("\tsource_id: %d \n", event->source_id); |
| 44 | printf("\taction: %d \n", event->action); |
| 45 | printf("\tflags: %d \n", event->flags); |
| 46 | printf("\tmeta_state: %d \n", event->meta_state); |
| 47 | |
| 48 | switch (event->type) { |
| 49 | case MOTION_EVENT_TYPE: |
| 50 | printf("\tdetails.motion.event_time: %lld\n", |
| 51 | event->details.motion.event_time); |
| 52 | printf("\tdetails.motion.pointer_coords.x: %f\n", |
| 53 | event->details.motion.pointer_coordinates[0].x); |
| 54 | printf("\tdetails.motion.pointer_coords.y: %f\n", |
| 55 | event->details.motion.pointer_coordinates[0].y); |
| 56 | break; |
| 57 | default: |
| 58 | break; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | } |
| 63 | |
| 64 | int main(int argc, char** argv) |
| 65 | { |
| 66 | g_stop = false; |
| 67 | signal(SIGINT, signal_handler); |
| 68 | |
| 69 | AndroidEventListener listener; |
| 70 | listener.on_new_event = on_new_event; |
| 71 | listener.context = NULL; |
| 72 | |
| 73 | InputStackConfiguration config = { |
| 74 | enable_touch_point_visualization : true, |
| 75 | default_layer_for_touch_point_visualization : 10000, |
| 76 | input_area_width : 1024, |
| 77 | input_area_height : 1024 |
| 78 | }; |
| 79 | |
| 80 | android_input_stack_initialize(&listener, &config); |
| 81 | android_input_stack_start_waiting_for_flag(&g_stop); |
| 82 | |
| 83 | android_input_stack_stop(); |
| 84 | android_input_stack_shutdown(); |
| 85 | } |