From: Chris Michael Date: Thu, 8 Jun 2017 13:21:16 +0000 (-0400) Subject: elput: Add API function to swap dx & dy axis from pointer motion event X-Git-Tag: upstream/1.20.0~711 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=26af19b543e313cdf1756cc1d158dca9d8cef02e;p=platform%2Fupstream%2Fefl.git 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 --- diff --git a/src/lib/elput/Elput.h b/src/lib/elput/Elput.h index f528150..c434a12 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 f2fd46b..a8b4903 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 aa7351d..09551ef 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 7d4909a..6b253d2 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