2 #include "e_mod_main.h"
5 E_GesturePtr gesture = NULL;
6 E_API E_Module_Api e_modapi = { E_MODULE_API_VERSION, "Gesture Module of Window Manager" };
8 static void *_e_gesture_init(E_Module *m);
9 static void _e_gesture_init_handlers(void);
12 static void _e_gesture_wl_client_cb_destroy(struct wl_listener *l, void *data);
15 _e_gesture_swipe_set_client_to_list(struct wl_client *client, E_Gesture_Event_Swipe_Finger *fingers, unsigned int direction)
17 if (direction & TIZEN_GESTURE_DIRECTION_DOWN)
18 fingers->direction[E_GESTURE_DIRECTION_DOWN].client = client;
19 if (direction & TIZEN_GESTURE_DIRECTION_LEFT)
20 fingers->direction[E_GESTURE_DIRECTION_LEFT].client = client;
21 if (direction & TIZEN_GESTURE_DIRECTION_UP)
22 fingers->direction[E_GESTURE_DIRECTION_UP].client = client;
23 if (direction & TIZEN_GESTURE_DIRECTION_RIGHT)
24 fingers->direction[E_GESTURE_DIRECTION_RIGHT].client = client;
27 /* Function for registering wl_client destroy listener */
29 e_gesture_add_client_destroy_listener(struct wl_client *client, int mode EINA_UNUSED, int num_of_fingers, unsigned int direction)
31 struct wl_listener *destroy_listener = NULL;
33 E_Gesture_Grabbed_Client *grabbed_client, *data;
35 EINA_LIST_FOREACH(gesture->grab_client_list, l, data)
37 if (data->client == client)
39 _e_gesture_swipe_set_client_to_list(client, &data->swipe_fingers[num_of_fingers], direction);
41 return TIZEN_GESTURE_ERROR_NONE;
45 destroy_listener = E_NEW(struct wl_listener, 1);
46 if (!destroy_listener)
48 GTERR("Failed to allocate memory for wl_client destroy listener !\n");
49 return TIZEN_GESTURE_ERROR_NO_SYSTEM_RESOURCES;
52 grabbed_client = E_NEW(E_Gesture_Grabbed_Client, 1);
55 GTERR("Failed to allocate memory to save client information !\n");
56 return TIZEN_GESTURE_ERROR_NO_SYSTEM_RESOURCES;
59 destroy_listener->notify = _e_gesture_wl_client_cb_destroy;
60 wl_client_add_destroy_listener(client, destroy_listener);
61 grabbed_client->client = client;
62 grabbed_client->destroy_listener = destroy_listener;
63 _e_gesture_swipe_set_client_to_list(client, &grabbed_client->swipe_fingers[num_of_fingers], direction);
65 gesture->grab_client_list = eina_list_append(gesture->grab_client_list, grabbed_client);
67 return TIZEN_KEYROUTER_ERROR_NONE;
71 _e_gesture_remove_client_destroy_listener(struct wl_client *client, unsigned int num_of_fingers, unsigned int direction)
73 Eina_List *l, *l_next;
74 E_Gesture_Grabbed_Client *data;
77 EINA_LIST_FOREACH_SAFE(gesture->grab_client_list, l, l_next, data)
79 if (data->client == client)
81 _e_gesture_swipe_set_client_to_list(NULL, &data->swipe_fingers[num_of_fingers], direction);
83 for (i = 0; i < E_GESTURE_FINGER_MAX+1; i++)
85 if (data->swipe_fingers[i].direction[E_GESTURE_DIRECTION_DOWN].client ||
86 data->swipe_fingers[i].direction[E_GESTURE_DIRECTION_LEFT].client ||
87 data->swipe_fingers[i].direction[E_GESTURE_DIRECTION_UP].client ||
88 data->swipe_fingers[i].direction[E_GESTURE_DIRECTION_RIGHT].client)
93 wl_list_remove(&data->destroy_listener->link);
94 E_FREE(data->destroy_listener);
95 gesture->grab_client_list = eina_list_remove(gesture->grab_client_list, data);
102 _e_gesture_cb_grab_swipe(struct wl_client *client,
103 struct wl_resource *resource,
104 uint32_t num_of_fingers, uint32_t direction)
106 E_Gesture_Event *gev;
107 unsigned int grabbed_direction = 0x0;
109 GTINF("client %p is request grab gesture, fingers: %d, direction: 0x%x\n", client, num_of_fingers, direction);
110 if (num_of_fingers > E_GESTURE_FINGER_MAX)
112 GTWRN("Do not support %d fingers (max: %d)\n", num_of_fingers, E_GESTURE_FINGER_MAX);
113 tizen_gesture_send_grab_swipe_notify(resource, num_of_fingers, direction, TIZEN_GESTURE_ERROR_INVALID_DATA);
117 gev = &gesture->gesture_events;
119 if (direction & TIZEN_GESTURE_DIRECTION_DOWN)
121 if (gev->swipes.fingers[num_of_fingers].direction[E_GESTURE_DIRECTION_DOWN].client)
123 grabbed_direction |= TIZEN_GESTURE_DIRECTION_DOWN;
127 gev->swipes.fingers[num_of_fingers].direction[E_GESTURE_DIRECTION_DOWN].client = client;
128 gev->swipes.fingers[num_of_fingers].direction[E_GESTURE_DIRECTION_DOWN].res = resource;
131 if (direction & TIZEN_GESTURE_DIRECTION_LEFT)
133 if (gev->swipes.fingers[num_of_fingers].direction[E_GESTURE_DIRECTION_LEFT].client)
135 grabbed_direction |= TIZEN_GESTURE_DIRECTION_LEFT;
139 gev->swipes.fingers[num_of_fingers].direction[E_GESTURE_DIRECTION_LEFT].client = client;
140 gev->swipes.fingers[num_of_fingers].direction[E_GESTURE_DIRECTION_LEFT].res = resource;
143 if (direction & TIZEN_GESTURE_DIRECTION_UP)
145 if (gev->swipes.fingers[num_of_fingers].direction[E_GESTURE_DIRECTION_UP].client)
147 grabbed_direction |= TIZEN_GESTURE_DIRECTION_UP;
151 gev->swipes.fingers[num_of_fingers].direction[E_GESTURE_DIRECTION_UP].client = client;
152 gev->swipes.fingers[num_of_fingers].direction[E_GESTURE_DIRECTION_UP].res = resource;
155 if (direction & TIZEN_GESTURE_DIRECTION_RIGHT)
157 if (gev->swipes.fingers[num_of_fingers].direction[E_GESTURE_DIRECTION_RIGHT].client)
159 grabbed_direction |= TIZEN_GESTURE_DIRECTION_RIGHT;
163 gev->swipes.fingers[num_of_fingers].direction[E_GESTURE_DIRECTION_RIGHT].client = client;
164 gev->swipes.fingers[num_of_fingers].direction[E_GESTURE_DIRECTION_RIGHT].res = resource;
168 if (grabbed_direction)
169 tizen_gesture_send_grab_swipe_notify(resource, num_of_fingers, grabbed_direction, TIZEN_GESTURE_ERROR_GRABBED_ALREADY);
171 e_gesture_add_client_destroy_listener(client, TIZEN_GESTURE_TYPE_SWIPE, num_of_fingers, direction & ~grabbed_direction);
172 gesture->grabbed_gesture |= TIZEN_GESTURE_TYPE_SWIPE;
173 gev->swipes.fingers[num_of_fingers].enabled = EINA_TRUE;
175 if (!grabbed_direction)
176 tizen_gesture_send_grab_swipe_notify(resource, num_of_fingers, direction, TIZEN_GESTURE_ERROR_NONE);
183 _e_gesture_cb_ungrab_swipe(struct wl_client *client,
184 struct wl_resource *resouce,
185 uint32_t num_of_fingers, uint32_t direction)
188 E_Gesture_Event *gev;
189 unsigned int ungrabbed_direction = 0x0;
190 int ret = TIZEN_GESTURE_ERROR_NONE;
192 GTINF("client %p is request ungrab swipe gesture, fingers: %d, direction: 0x%x, client: %p\n", client, num_of_fingers, direction, gesture->gesture_events.swipes.fingers[0].direction[3].client);
194 if (num_of_fingers > E_GESTURE_FINGER_MAX)
196 GTWRN("Do not support %d fingers (max: %d)\n", num_of_fingers, E_GESTURE_FINGER_MAX);
197 ret = TIZEN_GESTURE_ERROR_INVALID_DATA;
201 gev = &gesture->gesture_events;
203 if (direction & TIZEN_GESTURE_DIRECTION_DOWN)
205 if ((gev->swipes.fingers[num_of_fingers].direction[E_GESTURE_DIRECTION_DOWN].client) &&
206 (gev->swipes.fingers[num_of_fingers].direction[E_GESTURE_DIRECTION_DOWN].client == client))
208 gev->swipes.fingers[num_of_fingers].direction[E_GESTURE_DIRECTION_DOWN].client = NULL;
209 gev->swipes.fingers[num_of_fingers].direction[E_GESTURE_DIRECTION_DOWN].res = NULL;
213 ungrabbed_direction |= TIZEN_GESTURE_DIRECTION_DOWN;
216 if (direction & TIZEN_GESTURE_DIRECTION_LEFT)
218 if ((gev->swipes.fingers[num_of_fingers].direction[E_GESTURE_DIRECTION_LEFT].client) &&
219 (gev->swipes.fingers[num_of_fingers].direction[E_GESTURE_DIRECTION_LEFT].client == client))
221 gev->swipes.fingers[num_of_fingers].direction[E_GESTURE_DIRECTION_LEFT].client = NULL;
222 gev->swipes.fingers[num_of_fingers].direction[E_GESTURE_DIRECTION_LEFT].res = NULL;
226 ungrabbed_direction |= TIZEN_GESTURE_DIRECTION_LEFT;
229 if (direction & TIZEN_GESTURE_DIRECTION_UP)
231 if ((gev->swipes.fingers[num_of_fingers].direction[E_GESTURE_DIRECTION_UP].client) &&
232 (gev->swipes.fingers[num_of_fingers].direction[E_GESTURE_DIRECTION_UP].client == client))
234 gev->swipes.fingers[num_of_fingers].direction[E_GESTURE_DIRECTION_UP].client = NULL;
235 gev->swipes.fingers[num_of_fingers].direction[E_GESTURE_DIRECTION_UP].res = NULL;
239 ungrabbed_direction |= TIZEN_GESTURE_DIRECTION_UP;
242 if (direction & TIZEN_GESTURE_DIRECTION_RIGHT)
244 if ((gev->swipes.fingers[num_of_fingers].direction[E_GESTURE_DIRECTION_RIGHT].client) &&
245 (gev->swipes.fingers[num_of_fingers].direction[E_GESTURE_DIRECTION_RIGHT].client == client))
247 gev->swipes.fingers[num_of_fingers].direction[E_GESTURE_DIRECTION_RIGHT].client = NULL;
248 gev->swipes.fingers[num_of_fingers].direction[E_GESTURE_DIRECTION_RIGHT].res = NULL;
252 ungrabbed_direction |= TIZEN_GESTURE_DIRECTION_RIGHT;
256 if (direction & ~ungrabbed_direction)
258 _e_gesture_remove_client_destroy_listener(client, num_of_fingers, direction & ~ungrabbed_direction);
259 for (i = 0; i < E_GESTURE_FINGER_MAX+1; i++)
261 for (j = 0; j < E_GESTURE_DIRECTION_MAX+1; j++)
263 if (gev->swipes.fingers[i].direction[j].client)
268 gev->swipes.fingers[i].enabled = EINA_FALSE;
270 gesture->grabbed_gesture &= ~TIZEN_GESTURE_TYPE_SWIPE;
274 tizen_gesture_send_grab_swipe_notify(resouce, num_of_fingers, direction, ret);
278 static const struct tizen_gesture_interface _e_gesture_implementation = {
279 _e_gesture_cb_grab_swipe,
280 _e_gesture_cb_ungrab_swipe
283 /* tizen_gesture global object destroy function */
285 _e_gesture_cb_destory(struct wl_resource *resource)
287 /* TODO : destroy resources if exist */
290 /* tizen_keyrouter global object bind function */
292 _e_gesture_cb_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
294 E_GesturePtr gesture_instance = data;
295 struct wl_resource *resource;
297 resource = wl_resource_create(client, &tizen_gesture_interface, MIN(version, 1), id);
299 GTDBG("wl_resource_create(...,tizen_gesture_interface,...)\n");
303 GTERR("Failed to create resource ! (version :%d, id:%d)\n", version, id);
304 wl_client_post_no_memory(client);
308 wl_resource_set_implementation(resource, &_e_gesture_implementation, gesture_instance, _e_gesture_cb_destory);
314 _e_gesture_event_filter(void *data, void *loop_data EINA_UNUSED, int type, void *event)
318 return e_gesture_process_events(event, type);
322 _e_gesture_init_handlers(void)
324 gesture->ef_handler = ecore_event_filter_add(NULL, _e_gesture_event_filter, NULL, NULL);
328 _e_gesture_init(E_Module *m)
330 gesture = E_NEW(E_Gesture, 1);
334 GTERR("Failed to allocate memory for gesture !\n");
340 GTERR("Failed to initialize gesture module ! (e_comp == NULL)\n");
344 /* Add filtering mechanism */
345 _e_gesture_init_handlers();
346 gesture->global = wl_global_create(e_comp_wl->wl.disp, &tizen_gesture_interface, 1, gesture, _e_gesture_cb_bind);
347 if (!gesture->global)
349 GTERR("Failed to create global !\n");
353 gesture->gesture_filter = E_GESTURE_TYPE_MAX;
355 if (E_GESTURE_SWIPE_BACK_DEFAULT_ENABLE)
357 gesture->grabbed_gesture |= TIZEN_GESTURE_TYPE_SWIPE;
358 gesture->gesture_events.swipes.fingers[1].enabled = EINA_TRUE;
359 gesture->gesture_events.swipes.fingers[1].direction[E_GESTURE_DIRECTION_DOWN].client = (void *)0x1;
360 gesture->gesture_events.swipes.fingers[1].direction[E_GESTURE_DIRECTION_DOWN].res = (void *)0x1;
363 e_gesture_device_keydev_set(E_GESTURE_KEYBOARD_DEVICE);
368 if (gesture && gesture->ef_handler) ecore_event_filter_del(gesture->ef_handler);
369 if (gesture) E_FREE(gesture);
375 e_modapi_init(E_Module *m)
377 return _e_gesture_init(m);
381 e_modapi_shutdown(E_Module *m)
383 e_gesture_device_shutdown();
388 e_modapi_save(E_Module *m)
390 /* Save something to be kept */
395 _e_gesture_wl_client_cb_destroy(struct wl_listener *l, void *data)
397 struct wl_client *client = data;
399 Eina_List *l_list, *l_next;
400 E_Gesture_Grabbed_Client *client_data;
402 if (gesture->grabbed_gesture & TIZEN_GESTURE_TYPE_SWIPE)
404 for (i = 0; i < E_GESTURE_FINGER_MAX+1; i++)
406 for (j = 0; j < E_GESTURE_DIRECTION_MAX+1; j++)
408 if (gesture->gesture_events.swipes.fingers[i].direction[j].client == client)
410 gesture->gesture_events.swipes.fingers[i].direction[j].client = NULL;
411 gesture->gesture_events.swipes.fingers[i].direction[j].res = NULL;
416 for (i = 0; i < E_GESTURE_FINGER_MAX+1; i++)
418 for (j = 0; j < E_GESTURE_DIRECTION_MAX+1; j++)
420 if (gesture->gesture_events.swipes.fingers[i].direction[j].client)
425 gesture->gesture_events.swipes.fingers[i].enabled = EINA_FALSE;
427 gesture->grabbed_gesture &= ~TIZEN_GESTURE_TYPE_SWIPE;
433 EINA_LIST_FOREACH_SAFE(gesture->grab_client_list, l_list, l_next, client_data)
435 if (client_data->client == client)
437 gesture->grab_client_list = eina_list_remove(gesture->grab_client_list, client_data);