summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorChris Michael <cp.michael@samsung.com>2014-12-10 09:45:29 -0500
committerChris Michael <cp.michael@samsung.com>2014-12-10 12:01:58 -0500
commit011b2a36af622f44f452d64b85e7a917f7d2ed07 (patch)
treeac7e1592a4700d56a0c65caa16068d0a0d8a8814 /src/lib
parent893297e6f711c37c9e36602467739d4dfa6bd141 (diff)
ecore-drm: Handle various touch events
Summary: This adds code to handle various touch events (up, down, motion) so that touchscreen devices can work with ecore_drm. @feature Signed-off-by: Chris Michael <cp.michael@samsung.com>
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/ecore_drm/ecore_drm_evdev.c164
1 files changed, 164 insertions, 0 deletions
diff --git a/src/lib/ecore_drm/ecore_drm_evdev.c b/src/lib/ecore_drm/ecore_drm_evdev.c
index d2b46961b1..ee19c4ac03 100644
--- a/src/lib/ecore_drm/ecore_drm_evdev.c
+++ b/src/lib/ecore_drm/ecore_drm_evdev.c
@@ -523,6 +523,165 @@ _ecore_drm_evdev_device_create(Ecore_Drm_Seat *seat, struct libinput_device *dev
523 return edev; 523 return edev;
524} 524}
525 525
526static void
527_device_handle_touch_event(Ecore_Drm_Evdev *edev, struct libinput_event_touch *event, int state)
528{
529 Ecore_Drm_Input *input;
530 Ecore_Event_Mouse_Button *ev;
531 uint32_t timestamp, button = 0;
532
533 if (!edev) return;
534 if (!(input = edev->seat->input)) return;
535
536 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) return;
537
538 timestamp = libinput_event_touch_get_time(event);
539
540 ev->window = (Ecore_Window)input->dev->window;
541 ev->event_window = (Ecore_Window)input->dev->window;
542 ev->root_window = (Ecore_Window)input->dev->window;
543 ev->timestamp = timestamp;
544 ev->same_screen = 1;
545
546 /* NB: Commented out. This borks mouse button if no key has been
547 * pressed yet due to 'state' not being set */
548// _device_modifiers_update(dev);
549 ev->modifiers = edev->xkb.modifiers;
550
551 ev->x = edev->mouse.x;
552 ev->y = edev->mouse.y;
553 ev->root.x = ev->x;
554 ev->root.y = ev->y;
555
556 ev->multi.device = edev->mt_slot;
557 ev->multi.radius = 1;
558 ev->multi.radius_x = 1;
559 ev->multi.radius_y = 1;
560 ev->multi.pressure = 1.0;
561 ev->multi.angle = 0.0;
562 ev->multi.x = ev->x;
563 ev->multi.y = ev->y;
564 ev->multi.root.x = ev->x;
565 ev->multi.root.y = ev->y;
566
567 if (state == ECORE_EVENT_MOUSE_BUTTON_DOWN)
568 {
569 unsigned int current;
570
571 current = timestamp;
572 edev->mouse.did_double = EINA_FALSE;
573 edev->mouse.did_triple = EINA_FALSE;
574
575 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
576 (button == edev->mouse.prev_button))
577 {
578 edev->mouse.did_double = EINA_TRUE;
579 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
580 (button == edev->mouse.last_button))
581 {
582 edev->mouse.did_triple = EINA_TRUE;
583 edev->mouse.prev = 0;
584 edev->mouse.last = 0;
585 current = 0;
586 }
587 }
588
589 edev->mouse.last = edev->mouse.prev;
590 edev->mouse.prev = current;
591 edev->mouse.last_button = edev->mouse.prev_button;
592 edev->mouse.prev_button = button;
593 }
594
595 ev->buttons = button;
596
597 if (edev->mouse.did_double)
598 ev->double_click = 1;
599 if (edev->mouse.did_triple)
600 ev->triple_click = 1;
601
602 ecore_event_add(state, ev, NULL, NULL);
603}
604
605static void
606_device_handle_touch_down(struct libinput_device *device, struct libinput_event_touch *event)
607{
608 Ecore_Drm_Evdev *edev;
609
610 if (!(edev = libinput_device_get_user_data(device))) return;
611
612 edev->mouse.x = libinput_event_touch_get_x(event);
613 edev->mouse.y = libinput_event_touch_get_y(event);
614 edev->mt_slot = libinput_event_touch_get_seat_slot(event);
615
616 _device_handle_touch_event(edev, event, ECORE_EVENT_MOUSE_BUTTON_DOWN);
617}
618
619static void
620_device_handle_touch_motion(struct libinput_device *device, struct libinput_event_touch *event)
621{
622 Ecore_Drm_Evdev *edev;
623 Ecore_Drm_Input *input;
624 Ecore_Event_Mouse_Move *ev;
625
626 if (!(edev = libinput_device_get_user_data(device))) return;
627 if (!(input = edev->seat->input)) return;
628
629 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
630
631 edev->mouse.x = libinput_event_touch_get_x(event);
632 edev->mouse.y = libinput_event_touch_get_y(event);
633 edev->mt_slot = libinput_event_touch_get_seat_slot(event);
634
635 ev->window = (Ecore_Window)input->dev->window;
636 ev->event_window = (Ecore_Window)input->dev->window;
637 ev->root_window = (Ecore_Window)input->dev->window;
638 ev->timestamp = libinput_event_touch_get_time(event);
639 ev->same_screen = 1;
640
641 /* NB: Commented out. This borks mouse movement if no key has been
642 * pressed yet due to 'state' not being set */
643// _device_modifiers_update(dev);
644 ev->modifiers = edev->xkb.modifiers;
645
646 ev->x = edev->mouse.x;
647 ev->y = edev->mouse.y;
648 ev->root.x = ev->x;
649 ev->root.y = ev->y;
650
651 ev->multi.device = edev->mt_slot;
652 ev->multi.radius = 1;
653 ev->multi.radius_x = 1;
654 ev->multi.radius_y = 1;
655 ev->multi.pressure = 1.0;
656 ev->multi.angle = 0.0;
657 ev->multi.x = ev->x;
658 ev->multi.y = ev->y;
659 ev->multi.root.x = ev->x;
660 ev->multi.root.y = ev->y;
661
662 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL);
663}
664
665static void
666_device_handle_touch_up(struct libinput_device *device, struct libinput_event_touch *event)
667{
668 Ecore_Drm_Evdev *edev;
669
670 if (!(edev = libinput_device_get_user_data(device))) return;
671
672 edev->mouse.x = 0;
673 edev->mouse.y = 0;
674 edev->mt_slot = libinput_event_touch_get_seat_slot(event);
675
676 _device_handle_touch_event(edev, event, ECORE_EVENT_MOUSE_BUTTON_UP);
677}
678
679static void
680_device_handle_touch_frame(struct libinput_device *device EINA_UNUSED, struct libinput_event_touch *event EINA_UNUSED)
681{
682 DBG("Unhandled Touch Frame Event");
683}
684
526void 685void
527_ecore_drm_evdev_device_destroy(Ecore_Drm_Evdev *edev) 686_ecore_drm_evdev_device_destroy(Ecore_Drm_Evdev *edev)
528{ 687{
@@ -569,12 +728,17 @@ _ecore_drm_evdev_event_process(struct libinput_event *event)
569 _device_handle_axis(device, libinput_event_get_pointer_event(event)); 728 _device_handle_axis(device, libinput_event_get_pointer_event(event));
570 break; 729 break;
571 case LIBINPUT_EVENT_TOUCH_DOWN: 730 case LIBINPUT_EVENT_TOUCH_DOWN:
731 _device_handle_touch_down(device, libinput_event_get_touch_event(event));
572 break; 732 break;
573 case LIBINPUT_EVENT_TOUCH_MOTION: 733 case LIBINPUT_EVENT_TOUCH_MOTION:
734 _device_handle_touch_motion(device,
735 libinput_event_get_touch_event(event));
574 break; 736 break;
575 case LIBINPUT_EVENT_TOUCH_UP: 737 case LIBINPUT_EVENT_TOUCH_UP:
738 _device_handle_touch_up(device, libinput_event_get_touch_event(event));
576 break; 739 break;
577 case LIBINPUT_EVENT_TOUCH_FRAME: 740 case LIBINPUT_EVENT_TOUCH_FRAME:
741 _device_handle_touch_frame(device, libinput_event_get_touch_event(event));
578 break; 742 break;
579 default: 743 default:
580 ret = EINA_FALSE; 744 ret = EINA_FALSE;