ecore_drm: swap dx and dy axis from relative pointer motion event 67/89367/8
authorDuna Oh <duna.oh@samsung.com>
Fri, 23 Sep 2016 07:38:56 +0000 (16:38 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Tue, 4 Oct 2016 04:47:34 +0000 (21:47 -0700)
Since user gives mouse input events accoring to canvas coordinates,
when canvas is rotated, we swap x, y axis and inverse them according to rotation angle.

Change-Id: Ie88bdba9d1aa02dcd841fe82d64b2ef5dbd4f70c
Signed-off-by: Duna Oh <duna.oh@samsung.com>
src/lib/ecore_drm/Ecore_Drm.h
src/lib/ecore_drm/ecore_drm_device.c
src/lib/ecore_drm/ecore_drm_evdev.c
src/lib/ecore_drm/ecore_drm_private.h

index 6c413a4..7cffd4c 100644 (file)
@@ -1162,6 +1162,8 @@ EAPI void ecore_drm_display_fb_remove(Ecore_Drm_Fb *fb);
 EAPI Eina_Bool ecore_drm_display_fb_hal_buffer_create(Ecore_Drm_Fb *fb);
 EAPI void ecore_drm_display_fb_hal_buffer_destroy(Ecore_Drm_Fb *fb);
 
+EAPI Eina_Bool ecore_drm_device_pointer_rotation_set(Ecore_Drm_Device *dev, int rotation);
+
 # ifdef __cplusplus
 }
 # endif
index be372c7..f09df69 100644 (file)
@@ -857,3 +857,46 @@ ecore_drm_device_keyboard_cached_keymap_set(struct xkb_keymap *map)
 
    cached_keymap = map;
 }
+
+EAPI Eina_Bool
+ecore_drm_device_pointer_rotation_set(Ecore_Drm_Device *dev, int rotation)
+{
+   Ecore_Drm_Seat *seat = NULL;
+   Ecore_Drm_Evdev *edev = NULL;
+   Eina_List *l = NULL, *l2 = NULL;
+
+   EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
+   EINA_SAFETY_ON_NULL_RETURN_VAL(dev->seats, EINA_FALSE);
+
+   if ((rotation % 90 != 0) || (rotation / 90 > 3) || (rotation < 0)) return EINA_FALSE;
+
+   EINA_LIST_FOREACH(dev->seats, l, seat)
+     {
+        switch (rotation)
+          {
+           case 90:
+              seat->ptr.swap = EINA_TRUE;
+              seat->ptr.invert_x = EINA_FALSE;
+              seat->ptr.invert_y = EINA_TRUE;
+              break;
+           case 180:
+              seat->ptr.swap = EINA_FALSE;
+              seat->ptr.invert_x = EINA_TRUE;
+              seat->ptr.invert_y = EINA_TRUE;
+              break;
+           case 270:
+              seat->ptr.swap = EINA_TRUE;
+              seat->ptr.invert_x = EINA_TRUE;
+              seat->ptr.invert_y = EINA_FALSE;
+               break;
+           case 0:
+              seat->ptr.swap = EINA_FALSE;
+              seat->ptr.invert_x = EINA_FALSE;
+              seat->ptr.invert_y = EINA_FALSE;
+              break;
+           default:
+              break;
+          }
+     }
+   return EINA_TRUE;
+}
index 3ef7220..810e1d9 100644 (file)
@@ -473,6 +473,7 @@ static void
 _device_handle_pointer_motion(struct libinput_device *device, struct libinput_event_pointer *event)
 {
    Ecore_Drm_Evdev *edev;
+   double dx, dy, temp;
 
    TRACE_INPUT_BEGIN(_device_handle_pointer_motion);
 
@@ -482,8 +483,22 @@ _device_handle_pointer_motion(struct libinput_device *device, struct libinput_ev
         return;
      }
 
-   edev->seat->ptr.dx += libinput_event_pointer_get_dx(event);
-   edev->seat->ptr.dy += libinput_event_pointer_get_dy(event);
+   dx = libinput_event_pointer_get_dx(event);
+   dy = libinput_event_pointer_get_dy(event);
+
+   if (edev->seat->ptr.swap)
+     {
+         temp = dx;
+         dx = dy;
+         dy = temp;
+     }
+   if (edev->seat->ptr.invert_x)
+     dx *= -1;
+   if (edev->seat->ptr.invert_y)
+     dy *= -1;
+
+   edev->seat->ptr.dx += dx;
+   edev->seat->ptr.dy += dy;
 
    edev->mouse.dx = edev->seat->ptr.dx;
    edev->mouse.dy = edev->seat->ptr.dy;
index c3ab37d..ab18bf7 100644 (file)
@@ -194,6 +194,9 @@ struct _Ecore_Drm_Seat
      {
         int ix, iy;
         double dx, dy;
+        Eina_Bool swap;
+        Eina_Bool invert_x;
+        Eina_Bool invert_y;
      } ptr;
 };