From: Lukasz Wlazly Date: Wed, 13 Dec 2017 12:38:14 +0000 (+0100) Subject: Send reply when drag gesture is finished X-Git-Tag: accepted/tizen/unified/20171221.071231^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a57d05cd88c5f24342a372f393e0b27a464a5cd8;p=platform%2Fcore%2Fuifw%2Fe-mod-tizen-screen-reader.git Send reply when drag gesture is finished Reply messages are sent when all events are placed in ecore queue not just after parsing arguments Change-Id: Id72543e11400e1392dffcf824465c628d8c8d3ed --- diff --git a/src/e_dispatch_gesture_event.c b/src/e_dispatch_gesture_event.c index e05ba3e..4be9ac5 100644 --- a/src/e_dispatch_gesture_event.c +++ b/src/e_dispatch_gesture_event.c @@ -33,18 +33,17 @@ 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; + typedef struct _TouchHoldThenDragCommand { + DragInfo drag_info; + int type; + int initial_sequence_counter; + int sequence_counter; + TouchInputSequence *ts; + Eldbus_Message *reply; + Eldbus_Connection *conn; + } TouchHoldThenDragCommand; static TouchCommand tc; -static DragTouchCommand dtc; Eina_Bool during_drag = EINA_FALSE; static int _move_count = -1; @@ -477,32 +476,38 @@ _touch_sequnece_timer(void *data) Eina_Bool _drag_touch_sequence_timer(void *data) { - DragTouchCommand *dtc = data; + TouchHoldThenDragCommand *cmd = data; - if (dtc == NULL || dtc->ts->delay < 0) + if (cmd == NULL || cmd->ts->delay < 0) + { + eldbus_connection_send(cmd->conn, cmd->reply, NULL, NULL, -1); + free(cmd); 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++; + if (cmd->initial_sequence_counter < DRAG_INITIAL_STEPS) { + cmd->initial_sequence_counter++; + cmd->ts->dispatch_func(cmd->type, cmd->drag_info.start.x, cmd->drag_info.start.y, 0); + cmd->ts++; - ecore_timer_add(dtc->ts->delay, _drag_touch_sequence_timer, dtc); + ecore_timer_add(cmd->ts->delay, _drag_touch_sequence_timer, cmd); 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); + if (cmd->sequence_counter <= cmd->drag_info.steps) { + int current_x = (cmd->drag_info.start.x * (cmd->drag_info.steps - cmd->sequence_counter) + cmd->drag_info.end.x * cmd->sequence_counter) / (cmd->drag_info.steps); + int current_y = (cmd->drag_info.start.y * (cmd->drag_info.steps - cmd->sequence_counter) + cmd->drag_info.end.y * cmd->sequence_counter) / (cmd->drag_info.steps); + cmd->sequence_counter++; + cmd->ts->dispatch_func(cmd->type, current_x, current_y, 0); - ecore_timer_add(dtc->ts->delay, _drag_touch_sequence_timer, dtc); + ecore_timer_add(cmd->ts->delay, _drag_touch_sequence_timer, cmd); return ECORE_CALLBACK_CANCEL; } - dtc->ts++; - dtc->ts->dispatch_func(dtc->type, dtc->x2, dtc->y2, 0); + cmd->ts++; + cmd->ts->dispatch_func(cmd->type, cmd->drag_info.end.x, cmd->drag_info.end.y, 0); + eldbus_connection_send(cmd->conn, cmd->reply, NULL, NULL, -1); + free(cmd); during_drag = EINA_FALSE; return ECORE_CALLBACK_CANCEL; @@ -566,14 +571,16 @@ 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, double hold_time) +void _e_dispatch_drag_event(DragInfo di, Eldbus_Connection *conn, const Eldbus_Message *msg) { if (during_drag) + { + Eldbus_Message *reply = eldbus_message_error_new(msg, "org.freedesktop.DBus.Error.Failed", "Previous gesture is not finished yet"); + eldbus_connection_send(conn, reply, NULL, NULL, -1); return; + } - E_Zone *zone; - - zone = e_zone_current_get(); + E_Zone *zone = e_zone_current_get(); if (zone) { _zw = zone->w; @@ -582,33 +589,43 @@ void _e_dispatch_drag_event(int x1, int y1, int x2, int y2, int steps, double ho else { ERROR("Fail to find zone"); + Eldbus_Message *reply = eldbus_message_error_new(msg, "org.freedesktop.DBus.Error.Failed", "Fail to find zone"); + eldbus_connection_send(conn, reply, NULL, NULL, -1); return; } - if (x1 < 0 || y1 < 0 || x1 > _zw || y1 > _zh || steps < 1) + if (di.start.x < 0 || di.start.y < 0 || di.start.x > _zw || di.start.y > _zh || di.steps < 1) { - ERROR("Invalid value: %d, %d, %d", x1, y1, steps); + ERROR("Invalid value: start.x: %d, start.y: %d, steps: %d", di.start.x, di.start.y, di.steps); + Eldbus_Message * reply = eldbus_message_error_new(msg, "org.freedesktop.DBus.Error.Failed", "Invalid starting coordinates or steps number"); + eldbus_connection_send(conn, reply, NULL, NULL, -1); 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; - - _ts_drag[3].delay = hold_time; - - 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; + if (di.start.x == 0) di.start.x += 1; + if (di.start.x == _zw) di.start.x -= 1; + if (di.start.y == 0) di.start.y += 1; + if (di.start.y == _zh) di.start.y -= 1; + + _ts_drag[3].delay = di.hold_time; + + TouchHoldThenDragCommand *cmd = (TouchHoldThenDragCommand *)malloc(sizeof(TouchHoldThenDragCommand)); + if (!cmd) + { + Eldbus_Message * reply = eldbus_message_error_new(msg, "org.freedesktop.DBus.Error.Failed", "Malloc error"); + eldbus_connection_send(conn, reply, NULL, NULL, -1); + return; + } + + cmd->drag_info = di; + cmd->type = DRAG; + cmd->initial_sequence_counter = 0; + cmd->sequence_counter = 0; + cmd->ts = _ts_drag; + cmd->conn = conn; + cmd->reply = eldbus_message_method_return_new(msg); during_drag = EINA_TRUE; - ecore_timer_add(0.0, _drag_touch_sequence_timer, &dtc); + ecore_timer_add(0.0, _drag_touch_sequence_timer, cmd); } diff --git a/src/e_dispatch_gesture_event.h b/src/e_dispatch_gesture_event.h index 3af3b0f..0a3f971 100644 --- a/src/e_dispatch_gesture_event.h +++ b/src/e_dispatch_gesture_event.h @@ -1,7 +1,19 @@ #ifndef E_DISPATCH_GESTURE_EVENT_H_ #define E_DISPATCH_GESTURE_EVENT_H_ +typedef struct _Point { + int x; + int y; +} Point; + +typedef struct _DragInfo { + Point start; + Point end; + int steps; + double hold_time; +} DragInfo; + 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, double hold_time); +void _e_dispatch_drag_event(DragInfo di, Eldbus_Connection *conn, const Eldbus_Message *msg); #endif /* E_DISPATCH_GESTURE_EVENT_H_ */ diff --git a/src/e_mod_main.c b/src/e_mod_main.c index f3e4522..eb29e0b 100644 --- a/src/e_mod_main.c +++ b/src/e_mod_main.c @@ -435,16 +435,17 @@ _dispatch_gesture_event(const Eldbus_Service_Interface *iface, const Eldbus_Mess static Eldbus_Message * _dispatch_drag_event(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg) { - int x1, y1, x2, y2, steps; - double hold_time; - if (eldbus_message_arguments_get(msg, "iiiiid", &x1, &y1, &x2, &y2, &steps, &hold_time)) + DragInfo di; + if (eldbus_message_arguments_get(msg, "iiiiid", &di.start.x, &di.start.y, &di.end.x, &di.end.y, &di.steps, &di.hold_time)) { - _e_dispatch_drag_event(x1, y1, x2, y2, steps, hold_time); + _e_dispatch_drag_event(di, conn, msg); + return NULL; } else - ERROR("eldbus_message_arguments_get() error\n"); - - return eldbus_message_method_return_new(msg); + { + ERROR("eldbus_message_arguments_get() error\n"); + return eldbus_message_error_new(msg, "org.freedesktop.DBus.Error.InvalidArgs", "Cannot get correct arguments"); + } } static Eldbus_Message *