Imported Upstream version 0.1.0+git20131207+e452e83
[deb_libhybris.git] / hybris / include / hybris / input / input_stack_compatibility_layer.h
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 Voss <thomas.voss@canonical.com>
17 */
18
19 #ifndef INPUT_STACK_COMPATIBILITY_LAYER_H_
20 #define INPUT_STACK_COMPATIBILITY_LAYER_H_
21
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25
26 #include <stdint.h>
27 #include <stdbool.h>
28
29 #define MAX_POINTER_COUNT 16
30
31 typedef int64_t nsecs_t;
32
33 typedef enum
34 {
35 KEY_EVENT_TYPE,
36 MOTION_EVENT_TYPE,
37 HW_SWITCH_EVENT_TYPE
38 } EventType;
39
40 struct Event
41 {
42 // Generic event properties
43 EventType type;
44 int32_t device_id;
45 int32_t source_id;
46 int32_t action;
47 int32_t flags;
48 int32_t meta_state;
49 // Information specific to key/motion event types
50 union
51 {
52 struct HardwareSwitchEvent
53 {
54 nsecs_t event_time;
55 uint32_t policy_flags;
56 int32_t switch_values;
57 int32_t switch_mask;
58 } hw_switch;
59 struct KeyEvent
60 {
61 int32_t key_code;
62 int32_t scan_code;
63 int32_t repeat_count;
64 nsecs_t down_time;
65 nsecs_t event_time;
66 bool is_system_key;
67 } key;
68 struct MotionEvent
69 {
70 int32_t edge_flags;
71 int32_t button_state;
72 float x_offset;
73 float y_offset;
74 float x_precision;
75 float y_precision;
76 nsecs_t down_time;
77 nsecs_t event_time;
78
79 size_t pointer_count;
80 struct PointerCoordinates
81 {
82 int id;
83 float x, raw_x;
84 float y, raw_y;
85 float touch_major;
86 float touch_minor;
87 float size;
88 float pressure;
89 float orientation;
90 } pointer;
91 struct PointerCoordinates pointer_coordinates[MAX_POINTER_COUNT];
92 } motion;
93 } details;
94 };
95
96 typedef void (*on_new_event_callback)(struct Event* event, void* context);
97
98 struct AndroidEventListener
99 {
100 on_new_event_callback on_new_event;
101 void* context;
102 };
103
104 struct InputStackConfiguration
105 {
106 bool enable_touch_point_visualization;
107 int default_layer_for_touch_point_visualization;
108 int input_area_width;
109 int input_area_height;
110 };
111
112 void android_input_stack_initialize(
113 struct AndroidEventListener* listener,
114 struct InputStackConfiguration* input_stack_configuration);
115
116 void android_input_stack_loop_once();
117 void android_input_stack_start();
118 void android_input_stack_start_waiting_for_flag(bool* flag);
119 void android_input_stack_stop();
120 void android_input_stack_shutdown();
121
122 #ifdef __cplusplus
123 }
124 #endif
125
126 #endif // INPUT_STACK_COMPATIBILITY_LAYER_H_