1078c6d33118dfe51b9d979815bdce56c27bce81
[platform/core/uifw/e-mod-tizen-gesture.git] / src / e_mod_main.h
1 #ifndef E_MOD_MAIN_H
2 #define E_MOD_MAIN_H
3
4 #include <e.h>
5 #include <tizen-extension-server-protocol.h>
6 #include <Ecore_Input_Evas.h>
7
8 #define GTERR(msg, ARG...) ERR("[tizen_gesture][%s:%d] "msg, __FUNCTION__, __LINE__, ##ARG)
9 #define GTWRN(msg, ARG...) WRN("[tizen_gesture][%s:%d] "msg, __FUNCTION__, __LINE__, ##ARG)
10 #define GTINF(msg, ARG...) INF("[tizen_gesture][%s:%d] "msg, __FUNCTION__, __LINE__, ##ARG)
11 #define GTDBG(msg, ARG...) DBG("[tizen_gesture][%s:%d] "msg, __FUNCTION__, __LINE__, ##ARG)
12
13 #define E_GESTURE_SERVER_CLIENT (void *)0x1
14
15 #define E_GESTURE_TYPE_EDGE_SWIPE TIZEN_GESTURE_TYPE_EDGE_SWIPE
16 #define E_GESTURE_TYPE_EDGE_DRAG TIZEN_GESTURE_TYPE_EDGE_DRAG
17 #define E_GESTURE_TYPE_TAP TIZEN_GESTURE_TYPE_TAP
18 #define E_GESTURE_TYPE_PALM_COVER TIZEN_GESTURE_TYPE_PALM_COVER
19 #define E_GESTURE_TYPE_PAN TIZEN_GESTURE_TYPE_PAN
20 #define E_GESTURE_TYPE_PINCH TIZEN_GESTURE_TYPE_PINCH
21 #define E_GESTURE_TYPE_PALM_SWIPE TIZEN_GESTURE_TYPE_PALM_SWIPE
22
23 #define E_GESTURE_FINGER_MAX 3
24 #define E_GESTURE_TYPE_MAX (E_GESTURE_TYPE_PALM_SWIPE + 1)
25 #define E_GESTURE_TYPE_ALL (E_GESTURE_TYPE_EDGE_SWIPE | E_GESTURE_TYPE_EDGE_DRAG | E_GESTURE_TYPE_TAP | E_GESTURE_TYPE_PAN | E_GESTURE_TYPE_PINCH | E_GESTURE_TYPE_PALM_COVER | E_GESTURE_TYPE_PALM_SWIPE)
26 #define E_GESTURE_KEYBOARD_NAME "Gesture Keyboard"
27 #define E_GESTURE_AUX_HINT_GESTURE_DISABLE "wm.policy.win.gesture.disable"
28
29 /* FIX ME: Set values in contiguration file, do not use definition */
30 #define E_GESTURE_KEYBOARD_DEVICE "Any"
31
32 #define E_GESTURE_EDGE_SWIPE_DONE_TIME 0.5
33 #define E_GESTURE_EDGE_SWIPE_START_TIME 0.01
34 #define E_GESTURE_EDGE_SWIPE_START_AREA 50
35 #define E_GESTURE_EDGE_SWIPE_DIFF_FAIL 100
36 #define E_GESTURE_EDGE_SWIPE_DIFF_SUCCESS 300
37 /* FIX ME: Key code will be get from keymap */
38 #define E_GESTURE_EDGE_SWIPE_COMBINE_KEY 124
39 #define E_GESTURE_EDGE_SWIPE_BACK_KEY 166
40 #define E_GESTURE_EDGE_SWIPE_BACK_DEFAULT_ENABLE EINA_TRUE
41
42 #define E_GESTURE_EDGE_DRAG_START_TIME 0.01
43 #define E_GESTURE_EDGE_DRAG_START_AREA 50
44 #define E_GESTURE_EDGE_DRAG_DIFF 10
45
46 #define E_GESTURE_TAP_REPEATS_MAX 3
47 #define E_GESTURE_TAP_START_TIME 0.05
48 #define E_GESTURE_TAP_DONE_TIME 1.0
49 #define E_GESTURE_TAP_INTERVAL_TIME 1.0
50 #define E_GESTURE_TAP_MOVING_RANGE 25
51
52 #define E_GESTURE_PAN_START_TIME 0.05
53 #define E_GESTURE_PAN_MOVING_RANGE 15
54
55 #define E_GESTURE_PINCH_MOVING_DISTANCE_RANGE 15.0
56
57 #define ABS(x) (((x)>0)?(x):-(x))
58 #define RAD2DEG(x) ((x) * 57.295779513)
59
60 typedef struct _E_Gesture E_Gesture;
61 typedef struct _E_Gesture* E_GesturePtr;
62 typedef struct _E_Gesture_Event E_Gesture_Event;
63 typedef struct _E_Gesture_Event_Edge E_Gesture_Event_Edge;
64 typedef struct _E_Gesture_Event_Edge_Swipe E_Gesture_Event_Edge_Swipe;
65 typedef struct _E_Gesture_Event_Edge_Drag E_Gesture_Event_Edge_Drag;
66 typedef struct _E_Gesture_Event_Edge_Finger E_Gesture_Event_Edge_Finger;
67 typedef struct _E_Gesture_Event_Edge_Finger_Edge E_Gesture_Event_Edge_Finger_Edge;
68 typedef struct _E_Gesture_Grabbed_Client E_Gesture_Grabbed_Client;
69 typedef struct _E_Gesture_Conf_Edd E_Gesture_Conf_Edd;
70 typedef struct _E_Gesture_Config_Data E_Gesture_Config_Data;
71
72 typedef struct _E_Gesture_Event_Tap_Finger_Repeats E_Gesture_Event_Tap_Finger_Repeats;
73 typedef struct _E_Gesture_Event_Tap_Finger E_Gesture_Event_Tap_Finger;
74 typedef struct _E_Gesture_Event_Tap E_Gesture_Event_Tap;
75
76 typedef struct _E_Gesture_Event_Pan E_Gesture_Event_Pan;
77
78 typedef struct _E_Gesture_Event_Pinch E_Gesture_Event_Pinch;
79
80 typedef struct _E_Gesture_Event_Palm_Cover E_Gesture_Event_Palm_Cover;
81
82 typedef struct _Coords Coords;
83 typedef struct _Rect Rect;
84 typedef struct _E_Gesture_Finger E_Gesture_Finger;
85 typedef struct _E_Gesture_Event_Info E_Gesture_Event_Info;
86 typedef struct _E_Gesture_Event_Client E_Gesture_Event_Client;
87 typedef struct _E_Gesture_Select_Surface E_Gesture_Select_Surface;
88 typedef struct _E_Gesture_Activate_Info E_Gesture_Activate_Info;
89
90 typedef enum _E_Gesture_Edge E_Gesture_Edge;
91 typedef enum _E_Gesture_Event_State E_Gesture_Event_State;
92 typedef enum _E_Gesture_Tap_State E_Gesture_Tap_State;
93 typedef enum _E_Gesture_PanPinch_State E_Gesture_PanPinch_State;
94
95 extern E_GesturePtr gesture;
96
97 #define E_GESTURE_EDGE_MAX 4
98
99 #define E_GESTURE_EDGE_ALL ((1 << E_GESTURE_EDGE_TOP) | (1 << E_GESTURE_EDGE_RIGHT) | (1 << E_GESTURE_EDGE_BOTTOM) | (1 << E_GESTURE_EDGE_LEFT))
100
101 enum _E_Gesture_Event_State
102 {
103    E_GESTURE_EVENT_STATE_PROPAGATE,
104    E_GESTURE_EVENT_STATE_KEEP,
105    E_GESTURE_EVENT_STATE_IGNORE
106 };
107
108 enum _E_Gesture_Tap_State
109 {
110    E_GESTURE_TAP_STATE_NONE,
111    E_GESTURE_TAP_STATE_READY, // tap is required, idle
112    E_GESTURE_TAP_STATE_START, // first finger is pressed
113    E_GESTURE_TAP_STATE_PROCESS, // all fingers are pressed or first release
114    E_GESTURE_TAP_STATE_WAIT, // all fingers are released and wait next tap
115    E_GESTURE_TAP_STATE_DONE
116 };
117
118 enum _E_Gesture_PanPinch_State
119 {
120    E_GESTURE_PANPINCH_STATE_NONE,
121    E_GESTURE_PANPINCH_STATE_READY,
122    E_GESTURE_PANPINCH_STATE_START,
123    E_GESTURE_PANPINCH_STATE_MOVING,
124    E_GESTURE_PANPINCH_STATE_DONE
125 };
126
127 struct _Coords
128 {
129    int x, y;
130 };
131
132 struct _Rect
133 {
134    int x1, y1;
135    int x2, y2;
136 };
137
138 struct _E_Gesture_Finger
139 {
140    Eina_Bool pressed;
141    Coords axis;
142 };
143
144 struct _E_Gesture_Event_Info
145 {
146    int type;
147    void *event;
148 };
149
150 struct _E_Gesture_Activate_Info
151 {
152    Eina_Bool active;
153    struct wl_resource *surface;
154    Eina_List *clients;
155    Eina_List *surfaces;
156 };
157
158 struct _E_Gesture_Conf_Edd
159 {
160    char *key_device_name;              // The name of keyboard device to generate key events
161    Eina_Bool event_keep;               // 1: Do not propagate events to client immediatly until recognizing gestures
162                                        // 0: Propagate events immediatly but send a cancel event after recognizing gestures (default)
163    struct
164    {
165       double time_done;                // The duration to recognize a edge swipe
166       double time_begin;               // The minimun of time to distinguish if it is a gesture or normal touch
167       int area_offset;                 // Edge region to start to calculate
168       int min_length;                  // Limit size to move cross direction
169       int max_length;                  // Moving length to recognize edge swipe
170       int compose_key;                 // Keycode of composed with gesture
171       int back_key;                    // Keycode of back key
172       Eina_Bool default_enable_back;   // Convert a top edge swipe to back key
173    } edge_swipe;
174    struct
175      {
176         double time_begin;             // The minimun of time to distinguish if it is a gesture or normal touch
177         int area_offset;               // Edge region to start to calculate
178         int diff_length;               // Moved length to generate edge drag events
179      } edge_drag;
180    struct
181      {
182         int repeats_max;               // Maximum number of repeats
183         double time_start;             // Minimun of time to distinguish if it is a gesture or normal touch
184         double time_done;              // Duration to release all fingers
185         double time_interval;          // Interval duration between taps
186         int moving_range;              // Limit region duriong taps
187      } tap;
188    struct
189      {
190         double time_start;             // The minimun of time to distinguish if it is a gesture or normal touch
191         int moving_range;              // Moved length to generate pan events
192      } pan;
193    struct
194      {
195         double moving_distance_range;  // Moved length to generate pinch events
196      } pinch;
197 };
198
199 struct _E_Gesture_Config_Data
200 {
201    E_Module *module;
202    E_Config_DD *conf_edd;
203    E_Gesture_Conf_Edd *conf;
204 };
205
206 struct _E_Gesture_Event_Client
207 {
208    struct wl_client *client;
209    struct wl_resource *res;
210 };
211
212 struct _E_Gesture_Select_Surface
213 {
214    struct wl_resource *surface;
215    struct wl_resource *res;
216 };
217
218 struct _E_Gesture_Event_Edge_Finger_Edge
219 {
220    struct wl_client *client;
221    struct wl_resource *res;
222    unsigned int sp;
223    unsigned int ep;
224 };
225
226 struct _E_Gesture_Event_Edge_Finger
227 {
228    Coords start;
229    Eina_Bool enabled;
230    Eina_List *edge[E_GESTURE_EDGE_MAX + 1];
231 };
232
233 struct _E_Gesture_Event_Edge
234 {
235    E_Gesture_Activate_Info activation;
236    E_Gesture_Event_Edge_Finger fingers[E_GESTURE_FINGER_MAX + 2];
237
238    unsigned int edge;
239
240    unsigned int enabled_finger;
241    unsigned int enabled_edge;
242 };
243
244 struct _E_Gesture_Event_Edge_Swipe
245 {
246    E_Gesture_Event_Edge base;
247
248    unsigned int combined_keycode;
249    unsigned int back_keycode;
250
251    Ecore_Timer *start_timer;
252    Ecore_Timer *done_timer;
253 };
254
255 struct _E_Gesture_Event_Edge_Drag
256 {
257    E_Gesture_Event_Edge base;
258
259    Ecore_Timer *start_timer;
260
261    int idx;
262
263    Coords start_point;
264    Coords center_point;
265 };
266
267 struct _E_Gesture_Event_Tap_Finger_Repeats
268 {
269    struct wl_client *client;
270    struct wl_resource *res;
271 };
272
273 struct _E_Gesture_Event_Tap_Finger
274 {
275    Eina_Bool enabled;
276    unsigned int max_repeats;
277    E_Gesture_Event_Tap_Finger_Repeats repeats[E_GESTURE_TAP_REPEATS_MAX + 1];
278 };
279
280 struct _E_Gesture_Event_Tap
281 {
282    E_Gesture_Activate_Info activation;
283    E_Gesture_Event_Tap_Finger fingers[E_GESTURE_FINGER_MAX + 2];
284    E_Gesture_Tap_State state;
285    unsigned int enabled_finger;
286    unsigned int current_finger;
287    unsigned int repeats;
288    unsigned int max_fingers;
289
290    /* pressed timer */
291    Ecore_Timer *start_timer;
292    /* release timer */
293    Ecore_Timer *done_timer;
294    /* interval timer */
295    Ecore_Timer *interval_timer;
296
297    Rect base_rect;
298 };
299
300 struct _E_Gesture_Event_Pan
301 {
302    E_Gesture_Activate_Info activation;
303    E_Gesture_Event_Client fingers[E_GESTURE_FINGER_MAX + 2];
304    E_Gesture_PanPinch_State state;
305    Coords start_point;
306    Coords prev_point;
307    Coords center_point;
308    int num_pan_fingers;
309
310    Ecore_Timer *start_timer;
311    Ecore_Timer *move_timer;
312 };
313
314 struct _E_Gesture_Event_Pinch
315 {
316    E_Gesture_Activate_Info activation;
317    E_Gesture_Event_Client fingers[E_GESTURE_FINGER_MAX + 2];
318    E_Gesture_PanPinch_State state;
319    double distance;
320    int num_pinch_fingers;
321
322    Ecore_Timer *start_timer;
323    Ecore_Timer *move_timer;
324 };
325
326 struct _E_Gesture_Event_Palm_Cover
327 {
328    E_Gesture_Activate_Info activation;
329    E_Gesture_Event_Client client_info;
330    Eina_List *select_surface_list;
331    unsigned int start_time;
332 };
333
334 struct _E_Gesture_Grabbed_Client
335 {
336    struct wl_client *client;
337    struct wl_listener *destroy_listener;
338    unsigned int grabbed_gesture;
339
340    E_Gesture_Event_Edge_Finger edge_swipe_fingers[E_GESTURE_FINGER_MAX + 2];
341    E_Gesture_Event_Edge_Finger edge_drag_fingers[E_GESTURE_FINGER_MAX + 2];
342    E_Gesture_Event_Tap_Finger tap_fingers[E_GESTURE_FINGER_MAX + 2];
343    E_Gesture_Event_Client pan_fingers[E_GESTURE_FINGER_MAX + 2];
344    E_Gesture_Event_Client pinch_fingers[E_GESTURE_FINGER_MAX + 2];
345    E_Gesture_Event_Client palm_cover;
346 };
347
348 struct _E_Gesture_Event
349 {
350    E_Gesture_Event_Edge_Swipe edge_swipes;
351    E_Gesture_Event_Edge_Drag edge_drags;
352    E_Gesture_Event_Tap taps;
353    E_Gesture_Event_Pan pans;
354    E_Gesture_Event_Pinch pinchs;
355    E_Gesture_Event_Palm_Cover palm_covers;
356
357    E_Gesture_Finger base_point[E_GESTURE_FINGER_MAX + 2];
358
359    int num_pressed;
360    Eina_Bool recognized_gesture;
361    Eina_Bool event_keep;
362 };
363
364 struct _E_Gesture
365 {
366    struct wl_global *global;
367    E_Gesture_Config_Data *config;
368    Eina_Bool enable;
369    Eina_Bool enabled_window;
370
371    Ecore_Event_Filter *ef_handler;
372    Eina_List *handlers;
373    Eina_List *grab_client_list;
374    Eina_List *select_surface_list;
375    Eina_List *hooks;
376
377    struct
378    {
379       Eina_List *touch_devices;
380       int uinp_fd;
381       char *kbd_identifier;
382       char *kbd_name;
383       Ecore_Device *kbd_device;
384    } device;
385
386    unsigned int grabbed_gesture;
387    E_Gesture_Event gesture_events;
388    E_Gesture_Event_State event_state;
389    E_Gesture_Event_State prev_event_state;
390
391    Eina_List *event_queue;
392
393    unsigned int gesture_filter;
394    unsigned int gesture_recognized;
395 };
396
397 /* E Module */
398 E_API extern E_Module_Api e_modapi;
399 E_API void *e_modapi_init(E_Module *m);
400 E_API int   e_modapi_shutdown(E_Module *m);
401 E_API int   e_modapi_save(E_Module *m);
402
403 Eina_Bool e_gesture_process_events(void *event, int type);
404 int e_gesture_type_convert(uint32_t type);
405
406 /* Config */
407 void e_gesture_conf_init(E_Gesture_Config_Data *gconfig);
408 void e_gesture_conf_deinit(E_Gesture_Config_Data *gconfig);
409
410 /* Device control */
411 void e_gesture_device_shutdown(void);
412 E_Gesture_Event_State e_gesture_device_add(Ecore_Event_Device_Info *ev);
413 E_Gesture_Event_State e_gesture_device_del(Ecore_Event_Device_Info *ev);
414 Eina_Bool e_gesture_is_touch_device(const Ecore_Device *dev);
415 void e_gesture_device_keydev_set(char *option);
416
417 void e_gesture_event_filter_enable(Eina_Bool enabled);
418
419 /* Util functions */
420 unsigned int e_gesture_util_tap_max_fingers_get(void);
421 unsigned int e_gesture_util_tap_max_repeats_get(unsigned int);
422
423 #endif