2 #include "e_input_private.h"
4 /* e_input_device private variable */
5 static Eina_List *einput_devices;
6 static E_Input_Device *e_input_device_default = NULL;
8 struct xkb_keymap *cached_keymap;
9 struct xkb_context *cached_context;
12 _device_open_no_pending(const char *device, int flags)
17 fd = open(device, flags | O_CLOEXEC);
19 if (fd < 0) return fd;
20 if (fstat(fd, &s) == -1)
31 _e_input_device_cb_open_restricted(const char *path, int flags, void *data)
33 E_Input_Backend *input = (E_Input_Backend *)data;
36 EINA_SAFETY_ON_NULL_RETURN_VAL(input, -1);
38 /* try to open the device */
39 fd = _device_open_no_pending(path, flags);
43 ERR("Could not open device");
51 _e_input_device_cb_close_restricted(int fd, void *data)
53 if (fd >= 0) close(fd);
56 const struct libinput_interface _input_interface =
58 _e_input_device_cb_open_restricted,
59 _e_input_device_cb_close_restricted,
62 static E_Input_Device *
63 _e_input_device_default_get(void)
65 return e_input_device_default;
69 _e_input_device_cached_context_get(enum xkb_context_flags flags)
72 return xkb_context_new(flags);
74 return xkb_context_ref(cached_context);
78 _e_input_device_cached_keymap_get(struct xkb_context *ctx,
79 const struct xkb_rule_names *names,
80 enum xkb_keymap_compile_flags flags)
82 EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, NULL);
85 return xkb_map_new_from_names(ctx, names, flags);
87 return xkb_map_ref(cached_keymap);
91 _e_input_device_cached_context_update(struct xkb_context *ctx)
96 EINA_LIST_FOREACH(einput_devices, l, dev)
98 xkb_context_unref(dev->xkb_ctx);
99 dev->xkb_ctx = xkb_context_ref(ctx);
104 _e_input_device_cached_keymap_update(struct xkb_keymap *map)
106 Eina_List *l, *l2, *l3;
111 EINA_LIST_FOREACH(einput_devices, l, dev)
112 EINA_LIST_FOREACH(dev->seats, l2, seat)
113 EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l3, edev)
115 xkb_keymap_unref(edev->xkb.keymap);
116 edev->xkb.keymap = xkb_keymap_ref(map);
117 xkb_state_unref(edev->xkb.state);
118 edev->xkb.state = xkb_state_new(map);
123 e_input_device_keyboard_cached_context_set(struct xkb_context *ctx)
125 EINA_SAFETY_ON_NULL_RETURN(ctx);
127 if (cached_context == ctx) return;
130 _e_input_device_cached_context_update(ctx);
132 cached_context = ctx;
136 e_input_device_keyboard_cached_keymap_set(struct xkb_keymap *map)
138 EINA_SAFETY_ON_NULL_RETURN(map);
140 if (cached_keymap == map) return;
143 _e_input_device_cached_keymap_update(map);
149 e_input_device_destroy(E_Input_Device *dev)
151 E_Input_Backend *input;
155 EINA_SAFETY_ON_NULL_RETURN(dev);
157 EINA_LIST_FREE(dev->seats, seat)
159 EINA_LIST_FREE(seat->devices, edev)
161 libinput_device_config_send_events_set_mode(edev->device,
162 LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
163 _e_input_evdev_device_destroy(edev);
167 eina_stringshare_del(seat->name);
171 EINA_LIST_FREE(dev->inputs, input)
174 ecore_main_fd_handler_del(input->hdlr);
176 libinput_unref(input->libinput);
180 eina_stringshare_del(dev->seat);
181 xkb_context_unref(dev->xkb_ctx);
182 eina_hash_free(dev->fd_hash);
185 if (dev == e_input_device_default)
186 e_input_device_default = NULL;
192 _e_input_device_add_list(E_Input_Device *dev)
195 E_Input_Device *dev_data;
197 EINA_LIST_FOREACH(einput_devices, l, dev_data)
199 if (dev_data == dev) return;
202 einput_devices = eina_list_append(einput_devices, dev);
206 _e_input_device_remove_list(E_Input_Device *dev)
208 Eina_List *l, *l_next;
209 E_Input_Device *dev_data;
211 EINA_LIST_FOREACH_SAFE(einput_devices, l, l_next, dev_data)
214 einput_devices = eina_list_remove_list(einput_devices, l);
218 EINTERN E_Input_Device *
219 e_input_device_open(void)
221 E_Input_Device *dev = NULL;
223 dev = (E_Input_Device *)calloc(1, sizeof(E_Input_Device));
227 EINA_LOG_ERR("Failed to alloc memory for E_Input_Device\n");
231 dev->seat = eina_stringshare_add("seat0");
232 dev->fd_hash = eina_hash_string_superfast_new(NULL);
234 /* try to create xkb context */
235 if (!(dev->xkb_ctx = _e_input_device_cached_context_get(0)))
237 ERR("Failed to create xkb context: %m");
241 if (!e_input_device_default)
242 e_input_device_default = dev;
244 _e_input_device_add_list(dev);
251 eina_stringshare_del(dev->seat);
252 xkb_context_unref(dev->xkb_ctx);
260 e_input_device_close(E_Input_Device *dev)
262 /* check for valid device */
263 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
265 _e_input_device_remove_list(dev);
266 e_input_device_destroy(dev);
272 e_input_device_window_set(E_Input_Device *dev, Ecore_Window window)
274 /* check for valid device */
275 EINA_SAFETY_ON_TRUE_RETURN(!dev);
277 /* TODO : Must update window of ecore/evas device when the given window */
278 /* is not equal to the existing window. */
280 dev->window = window;
284 e_input_device_pointer_xy_get(E_Input_Device *dev, int *x, int *y)
294 dev = _e_input_device_default_get();
296 /* check for valid device */
297 EINA_SAFETY_ON_TRUE_RETURN(!dev);
298 EINA_LIST_FOREACH(dev->seats, l, seat)
300 EINA_LIST_FOREACH(seat->devices, ll, edev)
302 if (!libinput_device_has_capability(edev->device,
303 LIBINPUT_DEVICE_CAP_POINTER))
306 if (x) *x = seat->ptr.dx;
307 if (y) *y = seat->ptr.dy;
315 e_input_device_pointer_warp(E_Input_Device *dev, int x, int y)
320 Eina_Bool found = EINA_FALSE;
323 dev = _e_input_device_default_get();
325 /* check for valid device */
326 EINA_SAFETY_ON_TRUE_RETURN_VAL(!dev, EINA_FALSE);
327 EINA_LIST_FOREACH(dev->seats, l, seat)
329 EINA_LIST_FOREACH(seat->devices, ll, edev)
331 if (!libinput_device_has_capability(edev->device,
332 LIBINPUT_DEVICE_CAP_POINTER))
335 seat->ptr.dx = seat->ptr.ix = x;
336 seat->ptr.dy = seat->ptr.iy = y;
337 _e_input_pointer_motion_post(edev);
350 e_input_device_pointer_left_handed_set(E_Input_Device *dev, Eina_Bool left_handed)
352 E_Input_Seat *seat = NULL;
353 E_Input_Evdev *edev = NULL;
354 Eina_List *l = NULL, *l2 = NULL;
356 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
357 EINA_SAFETY_ON_NULL_RETURN_VAL(dev->seats, EINA_FALSE);
359 if (dev->left_handed == left_handed)
361 dev->left_handed = left_handed;
363 EINA_LIST_FOREACH(dev->seats, l, seat)
365 EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
367 if (libinput_device_has_capability(edev->device,
368 LIBINPUT_DEVICE_CAP_POINTER))
370 if (libinput_device_config_left_handed_set(edev->device, (int)left_handed) !=
371 LIBINPUT_CONFIG_STATUS_SUCCESS)
373 WRN("Failed to set left hand mode about device: %s\n",
374 libinput_device_get_name(edev->device));
385 e_input_device_pointer_rotation_set(E_Input_Device *dev, int rotation)
387 E_Input_Seat *seat = NULL;
390 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
391 EINA_SAFETY_ON_NULL_RETURN_VAL(dev->seats, EINA_FALSE);
393 if ((rotation % 90 != 0) || (rotation / 90 > 3) || (rotation < 0)) return EINA_FALSE;
395 EINA_LIST_FOREACH(dev->seats, l, seat)
400 seat->ptr.swap = EINA_TRUE;
401 seat->ptr.invert_x = EINA_FALSE;
402 seat->ptr.invert_y = EINA_TRUE;
405 seat->ptr.swap = EINA_FALSE;
406 seat->ptr.invert_x = EINA_TRUE;
407 seat->ptr.invert_y = EINA_TRUE;
410 seat->ptr.swap = EINA_TRUE;
411 seat->ptr.invert_x = EINA_TRUE;
412 seat->ptr.invert_y = EINA_FALSE;
415 seat->ptr.swap = EINA_FALSE;
416 seat->ptr.invert_x = EINA_FALSE;
417 seat->ptr.invert_y = EINA_FALSE;
427 e_input_device_rotation_set(E_Input_Device *dev, unsigned int rotation)
429 E_Input_Seat *seat = NULL;
430 E_Input_Evdev *edev = NULL;
431 Eina_List *l = NULL, *l2 = NULL;
434 EINA_SAFETY_ON_NULL_RETURN(dev);
435 EINA_SAFETY_ON_NULL_RETURN(dev->seats);
437 EINA_LIST_FOREACH(dev->seats, l, seat)
439 EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
441 if (libinput_device_has_capability(edev->device,
442 LIBINPUT_DEVICE_CAP_POINTER))
444 edev->mouse.minx = edev->mouse.miny = 0;
445 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen),
446 &edev->mouse.maxw, &edev->mouse.maxh);
448 if (rotation == 90 || rotation == 270)
450 temp = edev->mouse.minx;
451 edev->mouse.minx = edev->mouse.miny;
452 edev->mouse.miny = temp;
454 temp = edev->mouse.maxw;
455 edev->mouse.maxw = edev->mouse.maxh;
456 edev->mouse.maxh = temp;
464 _e_input_device_touch_matrix_identify(float result[6])
475 _e_input_device_touch_matrix_mulifly(float result[6], float m1[6], float m2[6])
477 result[0] = m1[0] * m2 [0] + m1[1] * m2[3];
478 result[1] = m1[0] * m2 [1] + m1[1] * m2[4];
479 result[2] = m1[0] * m2 [2] + m1[1] * m2[5] + m1[2];
480 result[3] = m1[3] * m2 [0] + m1[4] * m2[3];
481 result[4] = m1[3] * m2 [1] + m1[4] * m2[4];
482 result[5] = m1[3] * m2 [2] + m1[4] * m2[5] + m1[5];
486 _e_input_device_touch_matrix_rotation_get(float result[6], int degree, float w, float h)
488 if (w == 0.0) w = 1.0;
489 if (h == 0.0) h = 1.0;
518 _e_input_device_touch_matrix_identify(result);
521 WRN("Please input valid angle(%d)\n", degree);
526 _e_input_device_touch_matrix_translate_get(float result[6], float x, float y, float w, float h, float default_w, float default_h)
528 if (default_w == 0.0) default_w = 1.0;
529 if (default_h == 0.0) default_h = 1.0;
531 result[0] = w / default_w;
532 result[4] = h / default_h;
533 result[2] = x / default_w;
534 result[5] = y / default_h;
538 e_input_device_touch_rotation_set(E_Input_Device *dev, unsigned int rotation)
540 E_Input_Seat *seat = NULL;
541 E_Input_Evdev *edev = NULL;
542 Eina_List *l = NULL, *l2 = NULL;
543 float mat_translate[6] = {0.0, }, mat_rotation[6] = {0.0, }, result[6] = {0.0, };
544 float default_w = 0.0, default_h = 0.0;
545 Eina_Bool res = EINA_TRUE;
546 int output_w = 0, output_h = 0;
548 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
549 EINA_SAFETY_ON_NULL_RETURN_VAL(dev->seats, EINA_FALSE);
551 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &output_w, &output_h);
552 default_w = (float)output_w;
553 default_h = (float)output_h;
555 EINA_LIST_FOREACH(dev->seats, l, seat)
557 EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
559 if (edev->caps & E_INPUT_SEAT_TOUCH)
561 _e_input_device_touch_matrix_identify(mat_translate);
562 _e_input_device_touch_matrix_identify(mat_rotation);
563 _e_input_device_touch_matrix_identify(result);
565 if (edev->touch.transform.x || edev->touch.transform.y ||
566 edev->touch.transform.w || edev->touch.transform.h)
568 _e_input_device_touch_matrix_translate_get(mat_translate,
569 (float)edev->touch.transform.x,
570 (float)edev->touch.transform.y,
571 (float)edev->touch.transform.w,
572 (float)edev->touch.transform.h,
573 default_w, default_h);
577 _e_input_device_touch_matrix_rotation_get(mat_rotation, rotation, default_w, default_h);
579 _e_input_device_touch_matrix_mulifly(result, mat_translate, mat_rotation);
581 if (!e_input_evdev_touch_calibration_set(edev, result))
588 edev->touch.transform.rotation = rotation;
598 e_input_device_touch_transformation_set(E_Input_Device *dev, int offset_x, int offset_y, int w, int h)
600 E_Input_Seat *seat = NULL;
601 E_Input_Evdev *edev = NULL;
602 Eina_List *l = NULL, *l2 = NULL;
603 float mat_translate[6] = {0.0, }, mat_rotation[6] = {0.0 }, result[6] = {0.0, };
604 float default_w = 0.0, default_h = 0.0;
605 Eina_Bool res = EINA_TRUE;
606 int output_w = 0, output_h = 0;
608 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
609 EINA_SAFETY_ON_NULL_RETURN_VAL(dev->seats, EINA_FALSE);
610 EINA_SAFETY_ON_TRUE_RETURN_VAL((w == 0) || (h == 0), EINA_FALSE);
612 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &output_w, &output_h);
613 default_w = (float)output_w;
614 default_h = (float)output_h;
616 EINA_LIST_FOREACH(dev->seats, l, seat)
618 EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
620 if (edev->caps & E_INPUT_SEAT_TOUCH)
622 _e_input_device_touch_matrix_identify(mat_translate);
623 _e_input_device_touch_matrix_identify(mat_rotation);
624 _e_input_device_touch_matrix_identify(result);
626 _e_input_device_touch_matrix_translate_get(mat_translate,
627 (float)offset_x, (float)offset_y,
628 (float)w, (float)h, default_w, default_h);
630 if (edev->touch.transform.rotation)
632 _e_input_device_touch_matrix_rotation_get(mat_rotation,
633 edev->touch.transform.rotation,
634 default_w, default_h);
637 _e_input_device_touch_matrix_mulifly(result, mat_translate, mat_rotation);
639 if (!e_input_evdev_touch_calibration_set(edev, result))
646 edev->touch.transform.x = offset_x;
647 edev->touch.transform.y = offset_y;
648 edev->touch.transform.w = w;
649 edev->touch.transform.h = h;
658 e_input_device_libinput_log_handler(struct libinput *libinput EINA_UNUSED,
659 enum libinput_log_priority priority,
660 const char *format, va_list args)
662 char buf[1024] = {0,};
664 vsnprintf(buf, 1024, format, args);
667 case LIBINPUT_LOG_PRIORITY_DEBUG:
670 case LIBINPUT_LOG_PRIORITY_INFO:
673 case LIBINPUT_LOG_PRIORITY_ERROR:
682 e_input_device_input_backend_create(E_Input_Device *dev, E_Input_Libinput_Backend backend)
684 Eina_Bool res = EINA_FALSE;
686 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
688 if (backend == E_INPUT_LIBINPUT_BACKEND_UDEV)
690 TRACE_INPUT_BEGIN(e_input_device_input_create_libinput_udev);
691 res = e_input_device_input_create_libinput_udev(dev);
694 else if (backend == E_INPUT_LIBINPUT_BACKEND_PATH)
696 TRACE_INPUT_BEGIN(e_input_device_input_create_libinput_path);
697 res = e_input_device_input_create_libinput_path(dev);
705 _einput_device_input_thread_udev_backend_heavy(void *data, Ecore_Thread *th, void *msg_data)
707 E_Input_Backend *input = (E_Input_Backend *)data;
709 EINA_SAFETY_ON_NULL_RETURN(input);
710 EINA_SAFETY_ON_NULL_RETURN(input->dev);
711 EINA_SAFETY_ON_NULL_RETURN(input->dev->seat);
713 /* try to create libinput context */
715 libinput_udev_create_context(&_input_interface, input, eeze_udev_get());
717 if (!input->libinput)
721 ERR("Could not create libinput context: %m");
725 if (input->log_disable)
726 libinput_log_set_handler(input->libinput, NULL);
729 if (input->log_use_eina)
730 libinput_log_set_handler(input->libinput, e_input_device_libinput_log_handler);
731 libinput_log_set_priority(input->libinput, LIBINPUT_LOG_PRIORITY_INFO);
734 TRACE_INPUT_BEGIN(libinput_udev_assign_seat);
735 /* assign udev seat */
736 if (libinput_udev_assign_seat(input->libinput, input->dev->seat) != 0)
738 ERR("Failed to assign seat: %m");
748 _einput_device_input_thread_udev_backend_notify(void *data, Ecore_Thread *th, void *msg_data)
750 //TODO : do if there is something to do in main thread
754 _einput_device_input_thread_udev_backend_end(void *data, Ecore_Thread *th, void *msg_data)
756 E_Input_Backend *input = (E_Input_Backend *)data;
757 E_Input_Device *dev = NULL;
759 EINA_SAFETY_ON_NULL_RETURN(input);
760 EINA_SAFETY_ON_NULL_RETURN(input->dev);
762 input->thread = NULL;
764 /* enable this input */
765 if (!e_input_enable_input(input))
767 ERR("Failed to enable input");
771 /* append this input */
773 dev->inputs = eina_list_append(dev->inputs, input);
775 /* process pending events */
776 _input_events_process(input);
781 _einput_device_input_thread_udev_backend_cancel(void *data, Ecore_Thread *th, void *msg_data)
783 E_Input_Backend *input = (E_Input_Backend *)data;
785 EINA_SAFETY_ON_NULL_RETURN(input);
787 input->thread = NULL;
791 _e_input_device_input_thread_init_udev_backend(E_Input_Backend *input)
793 EINA_SAFETY_ON_NULL_RETURN_VAL(input, EINA_FALSE);
795 input->thread = ecore_thread_feedback_run((Ecore_Thread_Cb)_einput_device_input_thread_udev_backend_heavy,
796 (Ecore_Thread_Notify_Cb)_einput_device_input_thread_udev_backend_notify,
797 (Ecore_Thread_Cb)_einput_device_input_thread_udev_backend_end,
798 (Ecore_Thread_Cb)_einput_device_input_thread_udev_backend_cancel, input, 1);
799 return !!(input->thread);
802 /* public functions */
804 e_input_device_input_create_libinput_udev(E_Input_Device *dev)
806 E_Input_Backend *input;
811 /* check for valid device */
812 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
814 /* try to allocate space for new input structure */
815 if (!(input = calloc(1, sizeof(E_Input_Backend))))
820 /* set reference for parent device */
823 input->backend = E_INPUT_LIBINPUT_BACKEND_UDEV;
824 input->log_disable = EINA_FALSE;
825 input->log_use_eina = EINA_FALSE;
827 env = e_util_env_get(E_INPUT_ENV_LIBINPUT_LOG_DISABLE);
828 if ((env) && (atoi(env) == 1))
829 input->log_disable = EINA_TRUE;
832 if (env) E_FREE(env);
834 env = e_util_env_get(E_INPUT_ENV_LIBINPUT_LOG_EINA_LOG);
835 if ((env) && (atoi(env) == 1))
836 input->log_use_eina = EINA_TRUE;
840 env = e_util_env_get("UDEV_MONITOR_EVENT_SOURCE");
844 libinput_udev_set_udev_monitor_event_source(env);
848 env = e_util_env_get("UDEV_MONITOR_BUFFER_SIZE");
850 if ((env) && (buf_size = atoi(env)))
852 res = libinput_udev_set_udev_monitor_buffer_size(buf_size);
854 ERR("Wrong buffer size for udev monitor : %d\n", buf_size);
858 if (e_input_thread_enabled_get())
860 /* intialize libinput udev backend within an ecore thread */
861 if (!_e_input_device_input_thread_init_udev_backend(input))
863 ERR("Failed to initialize e_input backend (libinput udev backend) !");
870 /* try to create libinput context */
872 libinput_udev_create_context(&_input_interface, input, eeze_udev_get());
873 if (!input->libinput)
875 ERR("Could not create libinput context: %m");
879 if (input->log_disable)
880 libinput_log_set_handler(input->libinput, NULL);
883 if (input->log_use_eina)
884 libinput_log_set_handler(input->libinput, e_input_device_libinput_log_handler);
885 libinput_log_set_priority(input->libinput, LIBINPUT_LOG_PRIORITY_INFO);
888 /* assign udev seat */
889 TRACE_INPUT_BEGIN(libinput_udev_assign_seat);
890 if (libinput_udev_assign_seat(input->libinput, dev->seat) != 0)
892 ERR("Failed to assign seat: %m");
898 /* enable this input */
899 if (!e_input_enable_input(input))
901 ERR("Failed to enable input");
905 /* append this input */
906 dev->inputs = eina_list_append(dev->inputs, input);
908 /* process pending events */
909 _input_events_process(input);
914 if (input->libinput) libinput_unref(input->libinput);
921 _einput_device_input_thread_path_backend_heavy(void *data, Ecore_Thread *th, void *msg_data)
924 struct libinput_device *device;
925 E_Input_Backend *input = (E_Input_Backend *)data;
927 EINA_SAFETY_ON_NULL_RETURN(input);
928 EINA_SAFETY_ON_NULL_RETURN(input->dev);
929 EINA_SAFETY_ON_NULL_RETURN(input->dev->seat);
931 /* try to create libinput context */
933 libinput_path_create_context(&_input_interface, input);
934 if (!input->libinput)
938 ERR("Could not create libinput path context: %m");
942 if (input->log_disable)
943 libinput_log_set_handler(input->libinput, NULL);
946 if (input->log_use_eina)
947 libinput_log_set_handler(input->libinput, e_input_device_libinput_log_handler);
948 libinput_log_set_priority(input->libinput, LIBINPUT_LOG_PRIORITY_INFO);
951 TRACE_INPUT_BEGIN(libinput_path_add_device_loop);
952 for (int i = 0; i < input->path_ndevices; i++)
954 char buf[1024] = "PATH_DEVICE_";
955 eina_convert_itoa(i + 1, buf + 12);
956 env = e_util_env_get(buf);
960 device = libinput_path_add_device(input->libinput, env);
962 ERR("Failed to initialized device %s", env);
964 INF("libinput_path created input device %s", env);
974 _einput_device_input_thread_path_backend_notify(void *data, Ecore_Thread *th, void *msg_data)
976 //TODO : do if there is something to do in main thread
980 _einput_device_input_thread_path_backend_end(void *data, Ecore_Thread *th, void *msg_data)
982 E_Input_Backend *input = (E_Input_Backend *)data;
983 E_Input_Device *dev = NULL;
985 EINA_SAFETY_ON_NULL_RETURN(input);
986 EINA_SAFETY_ON_NULL_RETURN(input->dev);
988 input->thread = NULL;
990 /* enable this input */
991 if (!e_input_enable_input(input))
993 ERR("Failed to enable input");
997 /* append this input */
999 dev->inputs = eina_list_append(dev->inputs, input);
1001 /* process pending events */
1002 _input_events_process(input);
1006 _einput_device_input_thread_path_backend_cancel(void *data, Ecore_Thread *th, void *msg_data)
1008 E_Input_Backend *input = (E_Input_Backend *)data;
1010 EINA_SAFETY_ON_NULL_RETURN(input);
1012 input->thread = NULL;
1016 _e_input_device_input_thread_init_path_backend(E_Input_Backend *input)
1018 EINA_SAFETY_ON_NULL_RETURN_VAL(input, EINA_FALSE);
1020 input->thread = ecore_thread_feedback_run((Ecore_Thread_Cb)_einput_device_input_thread_path_backend_heavy,
1021 (Ecore_Thread_Notify_Cb)_einput_device_input_thread_path_backend_notify,
1022 (Ecore_Thread_Cb)_einput_device_input_thread_path_backend_end,
1023 (Ecore_Thread_Cb)_einput_device_input_thread_path_backend_cancel, input, 1);
1024 return !!(input->thread);
1028 e_input_device_input_create_libinput_path(E_Input_Device *dev)
1030 E_Input_Backend *input;
1031 struct libinput_device *device;
1035 /* check for valid device */
1036 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
1038 env = e_util_env_get("PATH_DEVICES_NUM");
1041 ndevices = atoi(env);
1045 if (ndevices <= 0 || ndevices >= INT_MAX)
1050 INF("PATH_DEVICES_NUM : %d", ndevices);
1052 /* try to allocate space for new input structure */
1053 if (!(input = calloc(1, sizeof(E_Input_Backend))))
1058 /* set reference for parent device */
1061 input->backend = E_INPUT_LIBINPUT_BACKEND_PATH;
1062 input->path_ndevices = ndevices;
1063 input->log_disable = EINA_FALSE;
1064 input->log_use_eina = EINA_FALSE;
1066 env = e_util_env_get(E_INPUT_ENV_LIBINPUT_LOG_DISABLE);
1067 if ((env) && (atoi(env) == 1))
1068 input->log_disable = EINA_TRUE;
1071 if (env) E_FREE(env);
1073 env = e_util_env_get(E_INPUT_ENV_LIBINPUT_LOG_EINA_LOG);
1074 if ((env) && (atoi(env) == 1))
1075 input->log_use_eina = EINA_TRUE;
1079 if (e_input_thread_enabled_get())
1081 /* intialize libinput path backend within an ecore thread */
1082 if (!_e_input_device_input_thread_init_path_backend(input))
1084 ERR("Failed to initialize e_input backend (libinput path backend) !");
1091 /* try to create libinput context */
1093 libinput_path_create_context(&_input_interface, input);
1094 if (!input->libinput)
1096 ERR("Could not create libinput path context: %m");
1100 if (input->log_disable)
1101 libinput_log_set_handler(input->libinput, NULL);
1104 if (input->log_use_eina)
1105 libinput_log_set_handler(input->libinput, e_input_device_libinput_log_handler);
1106 libinput_log_set_priority(input->libinput, LIBINPUT_LOG_PRIORITY_INFO);
1109 TRACE_INPUT_BEGIN(libinput_path_add_device_loop);
1110 for (int i = 0; i < ndevices; i++)
1112 char buf[1024] = "PATH_DEVICE_";
1113 eina_convert_itoa(i + 1, buf + 12);
1114 env = e_util_env_get(buf);
1117 device = libinput_path_add_device(input->libinput, env);
1119 ERR("Failed to initialized device %s", env);
1121 INF("libinput_path created input device %s", env);
1127 /* enable this input */
1128 if (!e_input_enable_input(input))
1130 ERR("Failed to enable input");
1134 /* append this input */
1135 dev->inputs = eina_list_append(dev->inputs, input);
1137 /* process pending events */
1138 _input_events_process(input);
1143 if (input->libinput) libinput_unref(input->libinput);
1150 e_input_device_output_changed(E_Input_Device *dev)
1152 E_Input_Seat *seat = NULL;
1153 E_Input_Evdev *edev = NULL;
1154 Eina_List *l = NULL, *l2 = NULL;
1156 EINA_SAFETY_ON_NULL_RETURN(dev);
1157 EINA_SAFETY_ON_NULL_RETURN(dev->seats);
1159 EINA_LIST_FOREACH(dev->seats, l, seat)
1161 EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
1163 _device_calibration_set(edev);
1168 E_API const Eina_List *
1169 e_input_devices_get(void)
1171 return einput_devices;
1175 e_input_device_mouse_accel_speed_set(E_Input_Device *dev, double speed)
1177 E_Input_Seat *seat = NULL;
1178 E_Input_Evdev *edev = NULL;
1179 Eina_List *l = NULL, *l2 = NULL;
1180 Eina_Bool res = EINA_TRUE, ret = EINA_TRUE;
1182 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
1183 EINA_SAFETY_ON_NULL_RETURN_VAL(dev->seats, EINA_FALSE);
1185 EINA_LIST_FOREACH(dev->seats, l, seat)
1187 EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
1189 if (edev->caps & E_INPUT_SEAT_POINTER)
1190 res = e_input_evdev_mouse_accel_speed_set(edev, speed);
1191 if (!res) ret = EINA_FALSE;
1199 e_input_device_touch_pressed_get(E_Input_Device *dev)
1201 E_Input_Seat *seat = NULL;
1202 E_Input_Evdev *edev = NULL;
1203 Eina_List *l = NULL, *l2 = NULL;
1204 unsigned int pressed = 0x0;
1206 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
1208 EINA_LIST_FOREACH(dev->seats, l, seat)
1210 EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
1212 if (edev->caps & E_INPUT_SEAT_TOUCH)
1213 pressed |= e_input_evdev_touch_pressed_get(edev);