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;
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;
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;
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);
}
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 *