Add transformation of coordinates 94/168994/1
authorLukasz Wlazly <l.wlazly@partner.samsung.com>
Thu, 1 Feb 2018 14:01:40 +0000 (15:01 +0100)
committerLukasz Wlazly <l.wlazly@partner.samsung.com>
Thu, 1 Feb 2018 14:01:40 +0000 (15:01 +0100)
When screen is rotated coordinates used in DispatchDragEvent
and DispatchPinchEvent are transformed to new orientation

Change-Id: I4f58567a6989c0daec9fc7a0ed322276aa29382b

src/Makefile.am
src/e_dispatch_gesture_event.c
src/e_mod_utils.c [new file with mode: 0644]
src/e_mod_utils.h [new file with mode: 0644]
src/e_screen_reader_gestures.c

index 02b0558..c50946b 100644 (file)
@@ -11,7 +11,8 @@ module_la_SOURCES      = \
        e_screen_reader_gestures.c \
        e_dispatch_gesture_event.c \
        e_dispatch_rotation_event.c \
-       e_universal_switch.c
+       e_universal_switch.c \
+       e_mod_utils.c
 
 module_la_LIBADD       =
 module_la_CFLAGS       = @ENLIGHTENMENT_CFLAGS@
index 2382648..a2cf7db 100644 (file)
@@ -1,6 +1,7 @@
 #include "e.h"
 #include "e_screen_reader_private.h"
 #include "e_dispatch_gesture_event.h"
+#include "e_mod_utils.h"
 
 #define STEP_DURATION 0.01
 
@@ -149,7 +150,7 @@ static void _dispatch_mouse_up_event(int x, int y, int device)
 }
 
 static Eldbus_Message *
-_correct_coordinates(Point *point, int steps, const Eldbus_Message *msg)
+_correct_coordinates(Point *start_point, Point *end_point, int steps, const Eldbus_Message *msg)
 {
    if (during_gesture)
      return eldbus_message_error_new(msg, "org.freedesktop.DBus.Error.Failed", "Previous gesture is not finished yet");
@@ -158,17 +159,20 @@ _correct_coordinates(Point *point, int steps, const Eldbus_Message *msg)
    if (!zone)
      return eldbus_message_error_new(msg, "org.freedesktop.DBus.Error.Failed", "Fail to find zone");
 
-   if (point->x < 0 || point->y < 0 || point->x > zone->w || point->y > zone->h || steps < 1)
+   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", point->x, point->y, steps);
+      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);
+
    // Starting gesture from edge causes additional gesture on the screen
-   if (point->x == 0) point->x += 1;
-   if (point->x == zone->w) point->x -= 1;
-   if (point->y == 0) point->y += 1;
-   if (point->y == zone->h) point->y -= 1;
+   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;
 
    return NULL;
 }
@@ -184,7 +188,7 @@ _swap_points(Point *a, Point *b)
 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.steps, msg);
+   Eldbus_Message *error_message = _correct_coordinates(&drag_info.start, &drag_info.end, drag_info.steps, msg);
    if (error_message)
      return error_message;
 
@@ -222,7 +226,7 @@ _e_dispatch_pinch_event(PinchInfo pinch_info, Eldbus_Connection *conn, const Eld
        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].steps, msg);
+       Eldbus_Message *error_message = _correct_coordinates(&temporary_drag_info[i].start, &temporary_drag_info[i].end, temporary_drag_info[i].steps, msg);
        if (error_message)
          return error_message;
      }
@@ -304,4 +308,4 @@ _on_terminate_gesture_sequence(GestureCommand *cmd)
    during_gesture = EINA_FALSE;
    eldbus_connection_send(cmd->conn, cmd->reply, NULL, NULL, -1);
    free(cmd);
-}
\ No newline at end of file
+}
diff --git a/src/e_mod_utils.c b/src/e_mod_utils.c
new file mode 100644 (file)
index 0000000..d8199b5
--- /dev/null
@@ -0,0 +1,47 @@
+#include "e_mod_utils.h"
+
+#include "e_screen_reader_private.h"
+
+#include "e.h"
+
+int _get_window_angle(void)
+{
+   E_Zone *zone = e_zone_current_get();
+
+   if (!zone)
+     {
+        ERROR("Fail to find zone");
+        return -1;
+     }
+
+   return zone->rot.act;
+}
+
+void _transform_coordinates(int *ax, int *ay)
+{
+    E_Zone *zone = e_zone_current_get();
+
+    int win_angle = _get_window_angle();
+    if (win_angle < 0)
+      {
+          ERROR("Invalid angle");
+          return;
+      }
+
+    switch (win_angle) {
+       case 90:
+       {
+           int tmp = *ax;
+           *ax = *ay;
+           *ay = zone->h - tmp;
+           break;
+       }
+       case 270:
+       {
+           int tmp = *ax;
+           *ax = zone->w - *ay;
+           *ay = tmp;
+           break;
+       }
+    }
+}
diff --git a/src/e_mod_utils.h b/src/e_mod_utils.h
new file mode 100644 (file)
index 0000000..0ca6ff4
--- /dev/null
@@ -0,0 +1,7 @@
+#ifndef E_MOD_UTILS_H
+#define E_MOD_UTILS_H
+
+int _get_window_angle(void);
+void _transform_coordinates(int *ax, int *ay);
+
+#endif
index 063173e..5124442 100644 (file)
@@ -183,7 +183,7 @@ static void _emit_mouse_move_event ( Ecore_Event_Mouse_Button *ev_btn)
    ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev_move, NULL, NULL);
 }
 
-int __get_window_angle(void)
+int __get_and_set_window_angle(void)
 {
    E_Zone *zone;
 
@@ -198,11 +198,11 @@ int __get_window_angle(void)
    return cover->angle;
 }
 
-void __transform_coordinates(int *ax, int *ay)
+void __update_cover_and_transform_coordinates(int *ax, int *ay)
 {
     int win_angle, tmp;
 
-    win_angle = __get_window_angle();
+    win_angle = __get_and_set_window_angle();
     switch (win_angle) {
        case 90:
           tmp = *ax;
@@ -222,8 +222,8 @@ static void _event_emit(Gesture g, int x, int y, int x_e, int y_e, gesture_state
    Gesture_Info *info = calloc(sizeof(Gesture_Info), 1);
    EINA_SAFETY_ON_NULL_RETURN(info);
 
-   __transform_coordinates(&x, &y);
-   __transform_coordinates(&x_e, &y_e);
+   __update_cover_and_transform_coordinates(&x, &y);
+   __update_cover_and_transform_coordinates(&x_e, &y_e);
 
    info->type = g;
    info->x_beg = x;
@@ -888,7 +888,7 @@ void __inverse_transform_coordinates(int *ax, int *ay)
 {
    int win_angle, tmp;
 
-   win_angle = __get_window_angle();
+   win_angle = __get_and_set_window_angle();
    switch (win_angle) {
       case 90:
          tmp = *ax;