summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Michael <cp.michael@samsung.com>2017-06-08 09:21:16 -0400
committerChris Michael <cp.michael@samsung.com>2017-06-08 10:03:36 -0400
commit26af19b543e313cdf1756cc1d158dca9d8cef02e (patch)
tree46030c6f87ad6bfd1b613b9940e0ae43274bcc73
parent75b5310781bc4c89f8accc94eecae83e3259e422 (diff)
downloadefl-26af19b543e313cdf1756cc1d158dca9d8cef02e.tar.gz
elput: Add API function to swap dx & dy axis from pointer motion event
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>
-rw-r--r--src/lib/elput/Elput.h13
-rw-r--r--src/lib/elput/elput_evdev.c17
-rw-r--r--src/lib/elput/elput_input.c49
-rw-r--r--src/lib/elput/elput_private.h3
4 files changed, 80 insertions, 2 deletions
diff --git a/src/lib/elput/Elput.h b/src/lib/elput/Elput.h
index f52815038e..c434a12859 100644
--- a/src/lib/elput/Elput.h
+++ b/src/lib/elput/Elput.h
@@ -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
diff --git a/src/lib/elput/elput_evdev.c b/src/lib/elput/elput_evdev.c
index f2fd46b36c..a8b4903e02 100644
--- a/src/lib/elput/elput_evdev.c
+++ b/src/lib/elput/elput_evdev.c
@@ -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);
diff --git a/src/lib/elput/elput_input.c b/src/lib/elput/elput_input.c
index aa7351dd69..09551ef727 100644
--- a/src/lib/elput/elput_input.c
+++ b/src/lib/elput/elput_input.c
@@ -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)
{
diff --git a/src/lib/elput/elput_private.h b/src/lib/elput/elput_private.h
index 7d4909a5d9..6b253d2fae 100644
--- a/src/lib/elput/elput_private.h
+++ b/src/lib/elput/elput_private.h
@@ -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