elput: Add API function to swap dx & dy axis from pointer motion event
authorChris Michael <cp.michael@samsung.com>
Thu, 8 Jun 2017 13:21:16 +0000 (09:21 -0400)
committerChris Michael <cp.michael@samsung.com>
Thu, 8 Jun 2017 14:03:36 +0000 (10:03 -0400)
Small patch which adds an API function that can be called to swap x
and y axis and invert them according to rotation angle.

@feature

Signed-off-by: Chris Michael <cp.michael@samsung.com>
src/lib/elput/Elput.h
src/lib/elput/elput_evdev.c
src/lib/elput/elput_input.c
src/lib/elput/elput_private.h

index f528150..c434a12 100644 (file)
@@ -354,6 +354,19 @@ EAPI Eina_Bool elput_input_pointer_left_handed_set(Elput_Manager *manager, const
 EAPI void elput_input_pointer_max_set(Elput_Manager *manager, int maxw, int maxh);
 
 /**
+ * Set pointer value rotation
+ *
+ * @param manager
+ * @param rotation
+ *
+ * @return EINA_TRUE on success, EINA_FALSE otherwise
+ *
+ * @ingroup Elput_Input_Group
+ * @since 1.20
+ */
+EAPI Eina_Bool elput_input_pointer_rotation_set(Elput_Manager *manager, int rotation);
+
+/**
  * Calibrate input devices for given screen size
  *
  * @param manager
index f2fd46b..a8b4903 100644 (file)
@@ -882,6 +882,7 @@ _pointer_motion(struct libinput_device *idev, struct libinput_event_pointer *eve
 {
    Elput_Device *edev;
    Elput_Pointer *ptr;
+   double dx, dy, tmp;
 
    edev = libinput_device_get_user_data(idev);
    if (!edev) return EINA_FALSE;
@@ -889,8 +890,20 @@ _pointer_motion(struct libinput_device *idev, struct libinput_event_pointer *eve
    ptr = _evdev_pointer_get(edev->seat);
    if (!ptr) return EINA_FALSE;
 
-   ptr->seat->pointer.x += libinput_event_pointer_get_dx(event);
-   ptr->seat->pointer.y += libinput_event_pointer_get_dy(event);
+   dx = libinput_event_pointer_get_dx(event);
+   dy = libinput_event_pointer_get_dy(event);
+
+   if (edev->swap)
+     {
+        tmp = dx;
+        dx = dy;
+        dy = tmp;
+     }
+   if (edev->invert_x) dx *= -1;
+   if (edev->invert_y) dy *= -1;
+
+   ptr->seat->pointer.x += dx;
+   ptr->seat->pointer.y += dy;
    ptr->timestamp = libinput_event_pointer_get_time(event);
 
    _pointer_motion_send(edev);
index aa7351d..09551ef 100644 (file)
@@ -559,6 +559,55 @@ elput_input_pointer_max_set(Elput_Manager *manager, int maxw, int maxh)
    manager->input.pointer_h = maxh;
 }
 
+EAPI Eina_Bool
+elput_input_pointer_rotation_set(Elput_Manager *manager, int rotation)
+{
+   Elput_Seat *eseat;
+   Elput_Device *edev;
+   Eina_List *l, *ll;
+
+   EINA_SAFETY_ON_NULL_RETURN_VAL(manager, EINA_FALSE);
+
+   if ((rotation % 90 != 0) || (rotation / 90 > 3) || (rotation < 0))
+     return EINA_FALSE;
+
+   EINA_LIST_FOREACH(manager->input.seats, l, eseat)
+     {
+        EINA_LIST_FOREACH(eseat->devices, ll, edev)
+          {
+             if (!(edev->caps & ELPUT_DEVICE_CAPS_POINTER)) continue;
+
+             switch (rotation)
+               {
+                case 0:
+                  edev->swap = EINA_FALSE;
+                  edev->invert_x = EINA_FALSE;
+                  edev->invert_y = EINA_FALSE;
+                  break;
+                case 90:
+                  edev->swap = EINA_TRUE;
+                  edev->invert_x = EINA_FALSE;
+                  edev->invert_y = EINA_TRUE;
+                  break;
+                case 180:
+                  edev->swap = EINA_FALSE;
+                  edev->invert_x = EINA_TRUE;
+                  edev->invert_y = EINA_TRUE;
+                  break;
+                case 270:
+                  edev->swap = EINA_TRUE;
+                  edev->invert_x = EINA_TRUE;
+                  edev->invert_y = EINA_FALSE;
+                  break;
+                default:
+                  break;
+               }
+          }
+     }
+
+   return EINA_TRUE;
+}
+
 EAPI void
 elput_input_devices_calibrate(Elput_Manager *manager, int w, int h)
 {
index 7d4909a..6b253d2 100644 (file)
@@ -229,6 +229,9 @@ struct _Elput_Device
 
    Eina_Bool left_handed : 1;
    Eina_Bool key_remap : 1;
+   Eina_Bool swap : 1;
+   Eina_Bool invert_x : 1;
+   Eina_Bool invert_y : 1;
 };
 
 struct _Elput_Manager