diff options
author | Chris Michael <cp.michael@samsung.com> | 2017-06-08 09:21:16 -0400 |
---|---|---|
committer | Chris Michael <cp.michael@samsung.com> | 2017-06-08 10:03:36 -0400 |
commit | 26af19b543e313cdf1756cc1d158dca9d8cef02e (patch) | |
tree | 46030c6f87ad6bfd1b613b9940e0ae43274bcc73 | |
parent | 75b5310781bc4c89f8accc94eecae83e3259e422 (diff) |
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>
Diffstat (limited to '')
-rw-r--r-- | src/lib/elput/Elput.h | 13 | ||||
-rw-r--r-- | src/lib/elput/elput_evdev.c | 17 | ||||
-rw-r--r-- | src/lib/elput/elput_input.c | 49 | ||||
-rw-r--r-- | src/lib/elput/elput_private.h | 3 |
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 | |||
354 | EAPI void elput_input_pointer_max_set(Elput_Manager *manager, int maxw, int maxh); | 354 | EAPI void elput_input_pointer_max_set(Elput_Manager *manager, int maxw, int maxh); |
355 | 355 | ||
356 | /** | 356 | /** |
357 | * Set pointer value rotation | ||
358 | * | ||
359 | * @param manager | ||
360 | * @param rotation | ||
361 | * | ||
362 | * @return EINA_TRUE on success, EINA_FALSE otherwise | ||
363 | * | ||
364 | * @ingroup Elput_Input_Group | ||
365 | * @since 1.20 | ||
366 | */ | ||
367 | EAPI Eina_Bool elput_input_pointer_rotation_set(Elput_Manager *manager, int rotation); | ||
368 | |||
369 | /** | ||
357 | * Calibrate input devices for given screen size | 370 | * Calibrate input devices for given screen size |
358 | * | 371 | * |
359 | * @param manager | 372 | * @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 | |||
882 | { | 882 | { |
883 | Elput_Device *edev; | 883 | Elput_Device *edev; |
884 | Elput_Pointer *ptr; | 884 | Elput_Pointer *ptr; |
885 | double dx, dy, tmp; | ||
885 | 886 | ||
886 | edev = libinput_device_get_user_data(idev); | 887 | edev = libinput_device_get_user_data(idev); |
887 | if (!edev) return EINA_FALSE; | 888 | if (!edev) return EINA_FALSE; |
@@ -889,8 +890,20 @@ _pointer_motion(struct libinput_device *idev, struct libinput_event_pointer *eve | |||
889 | ptr = _evdev_pointer_get(edev->seat); | 890 | ptr = _evdev_pointer_get(edev->seat); |
890 | if (!ptr) return EINA_FALSE; | 891 | if (!ptr) return EINA_FALSE; |
891 | 892 | ||
892 | ptr->seat->pointer.x += libinput_event_pointer_get_dx(event); | 893 | dx = libinput_event_pointer_get_dx(event); |
893 | ptr->seat->pointer.y += libinput_event_pointer_get_dy(event); | 894 | dy = libinput_event_pointer_get_dy(event); |
895 | |||
896 | if (edev->swap) | ||
897 | { | ||
898 | tmp = dx; | ||
899 | dx = dy; | ||
900 | dy = tmp; | ||
901 | } | ||
902 | if (edev->invert_x) dx *= -1; | ||
903 | if (edev->invert_y) dy *= -1; | ||
904 | |||
905 | ptr->seat->pointer.x += dx; | ||
906 | ptr->seat->pointer.y += dy; | ||
894 | ptr->timestamp = libinput_event_pointer_get_time(event); | 907 | ptr->timestamp = libinput_event_pointer_get_time(event); |
895 | 908 | ||
896 | _pointer_motion_send(edev); | 909 | _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) | |||
559 | manager->input.pointer_h = maxh; | 559 | manager->input.pointer_h = maxh; |
560 | } | 560 | } |
561 | 561 | ||
562 | EAPI Eina_Bool | ||
563 | elput_input_pointer_rotation_set(Elput_Manager *manager, int rotation) | ||
564 | { | ||
565 | Elput_Seat *eseat; | ||
566 | Elput_Device *edev; | ||
567 | Eina_List *l, *ll; | ||
568 | |||
569 | EINA_SAFETY_ON_NULL_RETURN_VAL(manager, EINA_FALSE); | ||
570 | |||
571 | if ((rotation % 90 != 0) || (rotation / 90 > 3) || (rotation < 0)) | ||
572 | return EINA_FALSE; | ||
573 | |||
574 | EINA_LIST_FOREACH(manager->input.seats, l, eseat) | ||
575 | { | ||
576 | EINA_LIST_FOREACH(eseat->devices, ll, edev) | ||
577 | { | ||
578 | if (!(edev->caps & ELPUT_DEVICE_CAPS_POINTER)) continue; | ||
579 | |||
580 | switch (rotation) | ||
581 | { | ||
582 | case 0: | ||
583 | edev->swap = EINA_FALSE; | ||
584 | edev->invert_x = EINA_FALSE; | ||
585 | edev->invert_y = EINA_FALSE; | ||
586 | break; | ||
587 | case 90: | ||
588 | edev->swap = EINA_TRUE; | ||
589 | edev->invert_x = EINA_FALSE; | ||
590 | edev->invert_y = EINA_TRUE; | ||
591 | break; | ||
592 | case 180: | ||
593 | edev->swap = EINA_FALSE; | ||
594 | edev->invert_x = EINA_TRUE; | ||
595 | edev->invert_y = EINA_TRUE; | ||
596 | break; | ||
597 | case 270: | ||
598 | edev->swap = EINA_TRUE; | ||
599 | edev->invert_x = EINA_TRUE; | ||
600 | edev->invert_y = EINA_FALSE; | ||
601 | break; | ||
602 | default: | ||
603 | break; | ||
604 | } | ||
605 | } | ||
606 | } | ||
607 | |||
608 | return EINA_TRUE; | ||
609 | } | ||
610 | |||
562 | EAPI void | 611 | EAPI void |
563 | elput_input_devices_calibrate(Elput_Manager *manager, int w, int h) | 612 | elput_input_devices_calibrate(Elput_Manager *manager, int w, int h) |
564 | { | 613 | { |
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 | |||
229 | 229 | ||
230 | Eina_Bool left_handed : 1; | 230 | Eina_Bool left_handed : 1; |
231 | Eina_Bool key_remap : 1; | 231 | Eina_Bool key_remap : 1; |
232 | Eina_Bool swap : 1; | ||
233 | Eina_Bool invert_x : 1; | ||
234 | Eina_Bool invert_y : 1; | ||
232 | }; | 235 | }; |
233 | 236 | ||
234 | struct _Elput_Manager | 237 | struct _Elput_Manager |