--- /dev/null
+#include "e.h"
+#include "e_screen_reader_private.h"
+#include "e_dispatch_gesture_event.h"
+
+#define MOVE_STEP 10
+#define ZOOM_LENGTH 150
+enum
+{
+ TAP,
+ SWIPE_RIGHT,
+ SWIPE_LEFT,
+ SWIPE_UP,
+ SWIPE_DOWN,
+ ZOOM_IN,
+ ZOOM_OUT,
+};
+
+typedef struct _TouchInputSequence {
+ double delay;
+ void (*dispatch_func)(int type, int x, int y, int device);
+ int device;
+} TouchInputSequence;
+
+typedef struct _TouchCommand {
+ int type;
+ int x, y;
+ TouchInputSequence *ts;
+ } TouchCommand;
+
+static TouchCommand tc;
+
+static int _move_count = -1;
+static int _zw = 0;
+static int _zh = 0;
+
+static void _dispatch_mouse_in_event(int type, int x, int y, int device);
+static void _dispatch_mouse_move_event(int type, int x, int y, int device);
+static void _dispatch_mouse_down_event(int type, int x, int y, int device);
+static void _dispatch_mouse_up_event(int type, int x, int y, int device);
+static TouchInputSequence _ts_single_tap[] = {
+ /* down */
+ {0.0, _dispatch_mouse_in_event, 0},
+ {0.0, _dispatch_mouse_move_event, 0},
+ {0.0, _dispatch_mouse_down_event, 0},
+ /* up */
+ {0.1, _dispatch_mouse_up_event, 0},
+ {-1}
+};
+
+static TouchInputSequence _ts_swipe[] = {
+ /* down */
+ {0.0, _dispatch_mouse_in_event, 0},
+ {0.0, _dispatch_mouse_move_event, 0},
+ {0.0, _dispatch_mouse_down_event, 0},
+ /* move */
+ {0.01, _dispatch_mouse_move_event, 0},
+ {0.01, _dispatch_mouse_move_event, 0},
+ {0.01, _dispatch_mouse_move_event, 0},
+ {0.01, _dispatch_mouse_move_event, 0},
+ {0.01, _dispatch_mouse_move_event, 0},
+ {0.01, _dispatch_mouse_move_event, 0},
+ {0.01, _dispatch_mouse_move_event, 0},
+ {0.01, _dispatch_mouse_move_event, 0},
+ {0.01, _dispatch_mouse_move_event, 0},
+ {0.01, _dispatch_mouse_move_event, 0},
+ {0.01, _dispatch_mouse_move_event, 0},
+ {0.01, _dispatch_mouse_move_event, 0},
+ {0.01, _dispatch_mouse_move_event, 0},
+ {0.01, _dispatch_mouse_move_event, 0},
+ {0.01, _dispatch_mouse_move_event, 0},
+ {0.01, _dispatch_mouse_move_event, 0},
+ {0.01, _dispatch_mouse_move_event, 0},
+ {0.01, _dispatch_mouse_move_event, 0},
+ {0.01, _dispatch_mouse_move_event, 0},
+ {0.01, _dispatch_mouse_move_event, 0},
+ /* up */
+ {0.1, _dispatch_mouse_up_event, 0},
+ {-1}
+};
+
+static TouchInputSequence _ts_zoom[] = {
+ /* down */
+ {0.0, _dispatch_mouse_in_event, 0},
+ {0.0, _dispatch_mouse_move_event, 0},
+ {0.0, _dispatch_mouse_down_event, 0},
+ {0.0, _dispatch_mouse_move_event, 1},
+ {0.0, _dispatch_mouse_down_event, 1},
+ /* move */
+ {0.01, _dispatch_mouse_move_event, 0},
+ {0.01, _dispatch_mouse_move_event, 1},
+ {0.01, _dispatch_mouse_move_event, 0},
+ {0.01, _dispatch_mouse_move_event, 1},
+ {0.01, _dispatch_mouse_move_event, 0},
+ {0.01, _dispatch_mouse_move_event, 1},
+ {0.01, _dispatch_mouse_move_event, 0},
+ {0.01, _dispatch_mouse_move_event, 1},
+ {0.01, _dispatch_mouse_move_event, 0},
+ {0.01, _dispatch_mouse_move_event, 1},
+ {0.01, _dispatch_mouse_move_event, 0},
+ {0.01, _dispatch_mouse_move_event, 1},
+ {0.01, _dispatch_mouse_move_event, 0},
+ {0.01, _dispatch_mouse_move_event, 1},
+ {0.01, _dispatch_mouse_move_event, 0},
+ {0.01, _dispatch_mouse_move_event, 1},
+ {0.01, _dispatch_mouse_move_event, 0},
+ {0.01, _dispatch_mouse_move_event, 1},
+ {0.01, _dispatch_mouse_move_event, 0},
+ {0.01, _dispatch_mouse_move_event, 1},
+ /* up */
+ {0.1, _dispatch_mouse_up_event, 0},
+ {0.0, _dispatch_mouse_up_event, 1},
+ {-1}
+};
+
+static Ecore_Device * _get_device()
+{
+ const Eina_List *dev_list = NULL;
+ const Eina_List *l;
+ Ecore_Device *dev = NULL;
+ const char *identifier;
+
+ dev_list = ecore_device_list();
+ if (!dev_list) return NULL;
+ EINA_LIST_FOREACH(dev_list, l, dev)
+ {
+ if (!dev) continue;
+ identifier = ecore_device_identifier_get(dev);
+ if (!identifier) continue;
+
+ //FIXME: Find right way to get device class
+ if (ecore_device_class_get(dev) == ECORE_DEVICE_CLASS_TOUCH)
+ return dev;
+ }
+ return NULL;
+}
+
+static void _dispatch_mouse_in_event(int type, int x, int y, int device)
+{
+ Ecore_Event_Mouse_IO *ev;
+
+ if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_IO)))) return;
+
+ ev->x = x;
+ ev->y = y;
+ ev->modifiers = 0;
+ ev->timestamp = (int)(ecore_time_get() * 1000.0);
+ ev->window = e_comp->win;
+ ev->event_window = ev->window;
+ ev->event_window = 1;
+ ev->dev = _get_device();
+
+ ecore_event_add(ECORE_EVENT_MOUSE_IN, ev, NULL, NULL);
+}
+
+static void _dispatch_mouse_move_event(int type, int x, int y, int device)
+{
+ Ecore_Event_Mouse_Move *ev;
+
+ if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
+
+ switch(type)
+ {
+ case TAP:
+ break;
+
+ case SWIPE_RIGHT:
+ _move_count++;
+ x += (MOVE_STEP * _move_count);
+ if (x > _zw) x = _zw;
+ break;
+
+ case SWIPE_LEFT:
+ _move_count++;
+ x -= (MOVE_STEP * _move_count);
+ if (x < 0) x = 0;
+ break;
+
+ case SWIPE_UP:
+ _move_count++;
+ y -= (MOVE_STEP * _move_count);
+ if (y < 0) y = 0;
+ break;
+
+ case SWIPE_DOWN:
+ _move_count++;
+ y += (MOVE_STEP * _move_count);
+ if (y > _zh) y = _zh;
+ break;
+
+ case ZOOM_IN:
+ if (device == 0)
+ {
+ _move_count++;
+ x -= (MOVE_STEP * _move_count);
+ if (x < 0) x = 0;
+ }
+ else if (device == 1)
+ {
+ x += (MOVE_STEP * _move_count);
+ if (x > _zw) x = _zw;
+ }
+ break;
+
+ case ZOOM_OUT:
+ if (device == 0)
+ {
+ _move_count++;
+ x -= (ZOOM_LENGTH - (MOVE_STEP * _move_count));
+ if (x < 0) x = 0;
+ }
+ else if (device == 1)
+ {
+ x += (ZOOM_LENGTH - (MOVE_STEP * _move_count));
+ if (x > _zw) x = _zw;
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ ev->timestamp = (int)(ecore_time_get() * 1000.0);
+ ev->x = x;
+ ev->y = y;
+ ev->root.x = x;
+ ev->root.y = y;
+ ev->modifiers = 0;
+ ev->multi.x = x;
+ ev->multi.y = y;
+ ev->multi.root.x = x;
+ ev->multi.root.y = y;
+ ev->multi.device = device;
+ ev->window = e_comp->win;
+ ev->event_window = ev->window;
+ ev->root_window = e_comp->root;
+ ev->same_screen = 1;
+ ev->dev = _get_device();
+
+ ev->multi.radius = 1;
+ ev->multi.radius_x = 1;
+ ev->multi.radius_y = 1;
+ ev->multi.pressure = 1.0;
+ ev->multi.angle = 0.0;
+
+ ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL);
+}
+
+static void _dispatch_mouse_down_event(int type, int x, int y, int device)
+{
+ Ecore_Event_Mouse_Button *ev;
+
+ if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) return;
+
+ switch(type)
+ {
+ case TAP:
+ break;
+
+ case SWIPE_RIGHT:
+ x += (MOVE_STEP * _move_count);
+ if (x > _zw) x = _zw;
+ break;
+
+ case SWIPE_LEFT:
+ x -= (MOVE_STEP * _move_count);
+ if (x < 0) x = 0;
+ break;
+
+ case SWIPE_UP:
+ y -= (MOVE_STEP * _move_count);
+ if (y < 0) y = 0;
+ break;
+
+ case SWIPE_DOWN:
+ y += (MOVE_STEP * _move_count);
+ if (y > _zh) y = _zh;
+ break;
+
+ case ZOOM_IN:
+ if (device == 0)
+ {
+ x -= (MOVE_STEP * _move_count);
+ if (x < 0) x = 0;
+ }
+ else if (device == 1)
+ {
+ x += (MOVE_STEP * _move_count);
+ if (x > _zw) x = _zw;
+ }
+ break;
+
+ case ZOOM_OUT:
+ if (device == 0)
+ {
+ x -= (ZOOM_LENGTH - (MOVE_STEP * _move_count));
+ if (x < 0) x = 0;
+ }
+ else if (device == 1)
+ {
+ x += (ZOOM_LENGTH - (MOVE_STEP * _move_count));
+ if (x > _zw) x = _zw;
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ ev->buttons = 1;
+ ev->timestamp = (int)(ecore_time_get() * 1000.0);
+ ev->x = x;
+ ev->y = y;
+ ev->root.x = x;
+ ev->root.y = y;
+ ev->modifiers = 0;
+ ev->double_click = 0;
+ ev->triple_click = 0;
+ ev->multi.x = x;
+ ev->multi.y = y;
+ ev->multi.root.x = x;
+ ev->multi.root.y = y;
+ ev->multi.device = device;
+ ev->window = e_comp->win;
+ ev->event_window = ev->window;
+ ev->root_window = e_comp->root;
+ ev->same_screen = 1;
+ ev->dev = _get_device();
+
+ ev->multi.radius = 1;
+ ev->multi.radius_x = 1;
+ ev->multi.radius_y = 1;
+ ev->multi.pressure = 1.0;
+ ev->multi.angle = 0.0;
+
+ ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL);
+}
+
+static void _dispatch_mouse_up_event(int type, int x, int y, int device)
+{
+ Ecore_Event_Mouse_Button *ev;
+
+ if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) return;
+
+ switch(type)
+ {
+ case TAP:
+ break;
+
+ case SWIPE_RIGHT:
+ x += (MOVE_STEP * _move_count);
+ if (x > _zw) x = _zw;
+ break;
+
+ case SWIPE_LEFT:
+ x -= (MOVE_STEP * _move_count);
+ if (x < 0) x = 0;
+ break;
+
+ case SWIPE_UP:
+ y -= (MOVE_STEP * _move_count);
+ if (y < 0) y = 0;
+ break;
+
+ case SWIPE_DOWN:
+ y += (MOVE_STEP * _move_count);
+ if (y > _zh) y = _zh;
+ break;
+
+ case ZOOM_IN:
+ if (device == 0)
+ {
+ x -= (MOVE_STEP * _move_count);
+ if (x < 0) x = 0;
+ }
+ else if (device == 1)
+ {
+ x += (MOVE_STEP * _move_count);
+ if (x > _zw) x = _zw;
+ }
+ break;
+
+ case ZOOM_OUT:
+ if (device == 0)
+ {
+ x -= (ZOOM_LENGTH - (MOVE_STEP * _move_count));
+ if (x < 0) x = 0;
+ }
+ else if (device == 1)
+ {
+ x += (ZOOM_LENGTH - (MOVE_STEP * _move_count));
+ if (x > _zw) x = _zw;
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ ev->buttons = 1;
+ ev->timestamp = (int)(ecore_time_get() * 1000.0);
+ ev->x = x;
+ ev->y = y;
+ ev->root.x = x;
+ ev->root.y = y;
+ ev->modifiers = 0;
+ ev->double_click = 0;
+ ev->triple_click = 0;
+ ev->multi.x = x;
+ ev->multi.y = y;
+ ev->multi.root.x = x;
+ ev->multi.root.y = y;
+ ev->multi.device = device;
+ ev->window = e_comp->win;
+ ev->event_window = ev->window;
+ ev->root_window = e_comp->root;
+ ev->same_screen = 1;
+ ev->dev = _get_device();
+
+ ev->multi.radius = 1;
+ ev->multi.radius_x = 1;
+ ev->multi.radius_y = 1;
+ ev->multi.pressure = 1.0;
+ ev->multi.angle = 0.0;
+
+ ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL);
+}
+
+
+Eina_Bool
+_touch_sequnece_timer(void *data)
+{
+ TouchCommand *tc = data;
+
+ if (tc == NULL || tc->ts->delay < 0)
+ {
+ _move_count = -1;
+ return ECORE_CALLBACK_CANCEL;
+ }
+
+ tc->ts->dispatch_func(tc->type, tc->x, tc->y, tc->ts->device);
+
+ tc->ts++;
+ ecore_timer_add(tc->ts->delay, _touch_sequnece_timer, tc);
+ return ECORE_CALLBACK_CANCEL;
+}
+
+void _e_dispatch_gesture_event(int type, int x, int y)
+{
+ E_Zone *zone;
+
+ if (_move_count >= 0) return;
+ _move_count++;
+
+ zone = e_zone_current_get();
+ if (zone)
+ {
+ _zw = zone->w;
+ _zh = zone->h;
+ }
+ else
+ {
+ ERROR("Fail to find zone");
+ _move_count = -1;
+ return;
+ }
+
+ if (x < 0 || y < 0 || x > _zw || y > _zh)
+ {
+ ERROR("Invalid value: %d, %d", x, y);
+ _move_count = -1;
+ return;
+ }
+
+ tc.type = type;
+ tc.x = x;
+ tc.y = y;
+
+ switch(type)
+ {
+ case TAP:
+ tc.ts = _ts_single_tap;
+ break;
+
+ case SWIPE_LEFT:
+ case SWIPE_RIGHT:
+ case SWIPE_UP:
+ case SWIPE_DOWN:
+ tc.ts = _ts_swipe;
+ break;
+
+ case ZOOM_IN:
+ case ZOOM_OUT:
+ tc.ts = _ts_zoom;
+ break;
+
+ default:
+ ERROR("Invalid type: %d", type);
+ _move_count = -1;
+ return;
+ }
+
+ ecore_timer_add(tc.ts->delay, _touch_sequnece_timer, &tc);
+}