#include "e_dispatch_gesture_event.h"
#include "e_mod_utils.h"
+#define ERROR_BUFFER_SIZE 1024
#define STEP_DURATION 0.01
int device_number_shift;
}
static Eldbus_Message *
-_correct_coordinates(Point *start_point, Point *end_point, int steps, const Eldbus_Message *msg)
+_check_and_correct_gesture_data(DragInfo *drag_info, const Eldbus_Message *msg)
{
if (during_gesture)
- return eldbus_message_error_new(msg, "org.freedesktop.DBus.Error.Failed", "Previous gesture is not finished yet");
+ return eldbus_message_error_new(msg, "org.freedesktop.DBus.Error.Failed", "Previous gesture is not finished yet.");
E_Zone *zone = e_zone_current_get();
if (!zone)
- return eldbus_message_error_new(msg, "org.freedesktop.DBus.Error.Failed", "Fail to find zone");
-
- if (start_point->x < 0 || start_point->y < 0 || start_point->x > zone->w || start_point->y > zone->h || steps < 1)
- {
- ERROR("Invalid value: start.x: %d, start.y: %d, steps: %d", start_point->x, start_point->y, steps);
- return eldbus_message_error_new(msg, "org.freedesktop.DBus.Error.Failed", "Invalid starting coordinates or steps number");
- }
-
- _transform_coordinates(&start_point->x, &start_point->y);
- _transform_coordinates(&end_point->x, &end_point->y);
+ return eldbus_message_error_new(msg, "org.freedesktop.DBus.Error.Failed", "Fail to find zone.");
+
+ if (drag_info->start.x < 0 || drag_info->start.y < 0 || drag_info->start.x > zone->w || drag_info->start.y > zone->h)
+ {
+ char message[ERROR_BUFFER_SIZE] = {0};
+ snprintf(message, ERROR_BUFFER_SIZE, "Invalid value of starting point: x: %d, y: %d. Point is outside of the viewport.", drag_info->start.x, drag_info->start.y);
+ ERROR("%s", message);
+ return eldbus_message_error_new(msg, "org.freedesktop.DBus.Error.Failed", message);
+ }
+
+ if (drag_info->steps < 1)
+ {
+ char message[ERROR_BUFFER_SIZE] = {0};
+ snprintf(message, ERROR_BUFFER_SIZE, "Invalid steps value: %d. Expected higher than 0.", drag_info->steps);
+ ERROR("%s", message);
+ return eldbus_message_error_new(msg, "org.freedesktop.DBus.Error.Failed", message);
+ }
+
+ _transform_coordinates(&drag_info->start.x, &drag_info->start.y);
+ _transform_coordinates(&drag_info->end.x, &drag_info->end.y);
// Starting gesture from edge causes additional gesture on the screen
- if (start_point->x == 0) start_point->x += 1;
- if (start_point->x == zone->w) start_point->x -= 1;
- if (start_point->y == 0) start_point->y += 1;
- if (start_point->y == zone->h) start_point->y -= 1;
+ if (drag_info->start.x == 0) drag_info->start.x += 1;
+ if (drag_info->start.x == zone->w) drag_info->start.x -= 1;
+ if (drag_info->start.y == 0) drag_info->start.y += 1;
+ if (drag_info->start.y == zone->h) drag_info->start.y -= 1;
return NULL;
}
Eldbus_Message *
_e_dispatch_drag_event(DragInfo drag_info, Eldbus_Connection *conn, const Eldbus_Message *msg)
{
- Eldbus_Message *error_message = _correct_coordinates(&drag_info.start, &drag_info.end, drag_info.steps, msg);
+ Eldbus_Message *error_message = _check_and_correct_gesture_data(&drag_info, msg);
if (error_message)
return error_message;
GestureCommand *cmd = (GestureCommand *)malloc(sizeof(GestureCommand));
if (!cmd)
- return eldbus_message_error_new(msg, "org.freedesktop.DBus.Error.Failed", "Malloc error");
+ return eldbus_message_error_new(msg, "org.freedesktop.DBus.Error.Failed", "Malloc error.");
cmd->drag_info[0] = drag_info;
cmd->drag_info_size = 1;
if (pinch_info.radius_change < 0)
_swap_points(&temporary_drag_info[i].start, &temporary_drag_info[i].end);
- Eldbus_Message *error_message = _correct_coordinates(&temporary_drag_info[i].start, &temporary_drag_info[i].end, temporary_drag_info[i].steps, msg);
+ Eldbus_Message *error_message = _check_and_correct_gesture_data(&temporary_drag_info[i], msg);
if (error_message)
return error_message;
}
GestureCommand *cmd = (GestureCommand *)malloc(sizeof(GestureCommand));
if (!cmd)
- return eldbus_message_error_new(msg, "org.freedesktop.DBus.Error.Failed", "Malloc error");
+ return eldbus_message_error_new(msg, "org.freedesktop.DBus.Error.Failed", "Malloc error.");
cmd->drag_info[0] = temporary_drag_info[0];
cmd->drag_info[1] = temporary_drag_info[1];