Drag gesture implementation 76/159676/7 accepted/tizen/unified/20171204.072215 submit/tizen/20171130.115009
authorLukasz Wlazly <l.wlazly@partner.samsung.com>
Tue, 7 Nov 2017 13:22:23 +0000 (14:22 +0100)
committerLukasz Wlazly <l.wlazly@partner.samsung.com>
Tue, 28 Nov 2017 07:27:43 +0000 (08:27 +0100)
New dbus method which allows to dispatch drag gesture
from one point to another in defined number of steps

Change-Id: I42b29c1f0cb1943c9c4f13bfc6908416597e5406

src/e_dispatch_gesture_event.c
src/e_dispatch_gesture_event.h
src/e_mod_main.c

index b50677d7c7fa07d6501e16f75e0939779872d513..4f9181b02a8b1336398f20ede81c9f9e157c4fc2 100644 (file)
@@ -4,6 +4,10 @@
 
 #define MOVE_STEP 10
 #define ZOOM_LENGTH 150
+
+#define DRAG_INITIAL_STEPS 3
+#define DRAG_FINAL_STEPS 1
+
 enum
 {
    TAP,
@@ -13,6 +17,7 @@ enum
    SWIPE_DOWN,
    ZOOM_IN,
    ZOOM_OUT,
+   DRAG
 };
 
 int device_number_shift;
@@ -29,7 +34,18 @@ typedef struct _TouchCommand {
    TouchInputSequence *ts;
  } TouchCommand;
 
+ typedef struct _DragTouchCommand {
+    int type;
+    int x1, y1;
+    int x2, y2;
+    int steps;
+    int initial_sequence_counter;
+    int sequence_counter;
+    TouchInputSequence *ts;
+  } DragTouchCommand;
+
 static TouchCommand tc;
+static DragTouchCommand dtc;
 
 static int _move_count = -1;
 static int _zw = 0;
@@ -114,6 +130,18 @@ static TouchInputSequence _ts_zoom[] = {
    {-1}
 };
 
+static TouchInputSequence _ts_drag[] = {
+   /* 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},
+   /* up */
+   {0.1, _dispatch_mouse_up_event, 0},
+   {-1}
+};
+
 static Ecore_Device * _get_device()
 {
    const Eina_List *dev_list = NULL;
@@ -445,6 +473,39 @@ _touch_sequnece_timer(void *data)
    return ECORE_CALLBACK_CANCEL;
 }
 
+Eina_Bool
+_drag_touch_sequence_timer(void *data)
+{
+   DragTouchCommand *dtc = data;
+
+   if (dtc == NULL || dtc->ts->delay < 0)
+       return ECORE_CALLBACK_CANCEL;
+
+   if (dtc->initial_sequence_counter < DRAG_INITIAL_STEPS) {
+     dtc->initial_sequence_counter++;
+     dtc->ts->dispatch_func(dtc->type, dtc->x1, dtc->y1, 0);
+     dtc->ts++;
+
+     ecore_timer_add(dtc->ts->delay, _drag_touch_sequence_timer, dtc);
+     return ECORE_CALLBACK_CANCEL;
+   }
+
+   if (dtc->sequence_counter <= dtc->steps) {
+     int current_x = (dtc->x1 * (dtc->steps - dtc->sequence_counter) + dtc->x2 * dtc->sequence_counter) / (dtc->steps);
+     int current_y = (dtc->y1 * (dtc->steps - dtc->sequence_counter) + dtc->y2 * dtc->sequence_counter) / (dtc->steps);
+     dtc->sequence_counter++;
+     dtc->ts->dispatch_func(dtc->type, current_x, current_y, 0);
+
+     ecore_timer_add(dtc->ts->delay, _drag_touch_sequence_timer, dtc);
+     return ECORE_CALLBACK_CANCEL;
+   }
+
+   dtc->ts++;
+   dtc->ts->dispatch_func(dtc->type, dtc->x2, dtc->y2, 0);
+
+   return ECORE_CALLBACK_CANCEL;
+}
+
 void _e_dispatch_gesture_event(int type, int x, int y)
 {
    E_Zone *zone;
@@ -502,3 +563,44 @@ void _e_dispatch_gesture_event(int type, int x, int y)
 
    ecore_timer_add(tc.ts->delay, _touch_sequnece_timer, &tc);
 }
+
+void _e_dispatch_drag_event(int x1, int y1, int x2, int y2, int steps)
+{
+   E_Zone *zone;
+
+   zone = e_zone_current_get();
+   if (zone)
+     {
+        _zw = zone->w;
+        _zh = zone->h;
+     }
+   else
+     {
+        ERROR("Fail to find zone");
+        return;
+     }
+
+   if (x1 < 0 || y1 < 0 || x1 > _zw || y1 > _zh || steps < 1)
+     {
+        ERROR("Invalid value: %d, %d, %d", x1, y1, steps);
+        return;
+     }
+
+   // Starting drag gesture from edge causes additional gesture on the screen
+   if (x1 == 0) x1 += 1;
+   if (x1 == _zw) x1 -= 1;
+   if (y1 == 0) y1 += 1;
+   if (y1 == _zh) y1 -= 1;
+
+   dtc.type = DRAG;
+   dtc.x1 = x1;
+   dtc.y1 = y1;
+   dtc.x2 = x2;
+   dtc.y2 = y2;
+   dtc.steps = steps;
+   dtc.initial_sequence_counter = 0;
+   dtc.sequence_counter = 0;
+   dtc.ts = _ts_drag;
+
+   ecore_timer_add(0.0, _drag_touch_sequence_timer, &dtc);
+}
index 07a687b5da0f49a408f540fe63f6b14d906e623f..40aaebcd3b6054d35020f94f5e8d4a93bf52aa90 100644 (file)
@@ -2,5 +2,6 @@
 #define E_DISPATCH_GESTURE_EVENT_H_
 
 void _e_dispatch_gesture_event(int type, int x, int y);
+void _e_dispatch_drag_event(int x1, int y1, int x2, int y2, int steps);
 
 #endif /* E_DISPATCH_GESTURE_EVENT_H_ */
index b6bf4b38c78e3d5987df28d49ed58859375dbe36..6897ff4922c0f1f4de551f1619a7452f00142c02 100644 (file)
@@ -43,6 +43,7 @@ static Eldbus_Message *_is_screen_reader_support(const Eldbus_Service_Interface
 static Eldbus_Message *_is_selection_mode(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
 static Eldbus_Message *_object_needs_scroll_gesture(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
 static Eldbus_Message *_dispatch_gesture_event(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
+static Eldbus_Message *_dispatch_drag_event(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
 
 static const Eldbus_Method methods[] = {
       { "ScreenReaderEnabled", ELDBUS_ARGS({"b", "bool"}), ELDBUS_ARGS({"b", "bool"}),
@@ -75,6 +76,9 @@ static const Eldbus_Method methods[] = {
       { "DispatchGestureEvent", ELDBUS_ARGS({"i", "int"}, {"i", "int"}, {"i", "int"}), NULL,
         _dispatch_gesture_event
       },
+      { "DispatchDragEvent", ELDBUS_ARGS({"i", "int"}, {"i", "int"}, {"i", "int"}, {"i", "int"}, {"i", "int"}), NULL,
+        _dispatch_drag_event
+      },
       { }
 };
 
@@ -423,6 +427,20 @@ _dispatch_gesture_event(const Eldbus_Service_Interface *iface, const Eldbus_Mess
    return eldbus_message_method_return_new(msg);
 }
 
+static Eldbus_Message *
+_dispatch_drag_event(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
+{
+   int x1, y1, x2, y2, steps;
+   if (eldbus_message_arguments_get(msg, "iiiii", &x1, &y1, &x2, &y2, &steps))
+     {
+        _e_dispatch_drag_event(x1, y1, x2, y2, steps);
+     }
+   else
+     ERROR("eldbus_message_arguments_get() error\n");
+
+   return eldbus_message_method_return_new(msg);
+}
+
 static int
 _fetch_a11y_bus_address(void)
 {