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 eina_hash_free(dev->fd_hash);
253 xkb_context_unref(dev->xkb_ctx);
261 e_input_device_close(E_Input_Device *dev)
263 /* check for valid device */
264 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
266 _e_input_device_remove_list(dev);
267 e_input_device_destroy(dev);
273 e_input_device_window_set(E_Input_Device *dev, Ecore_Window window)
275 /* check for valid device */
276 EINA_SAFETY_ON_TRUE_RETURN(!dev);
278 /* TODO : Must update window of ecore/evas device when the given window */
279 /* is not equal to the existing window. */
281 dev->window = window;
285 e_input_device_pointer_xy_get(E_Input_Device *dev, int *x, int *y)
295 dev = _e_input_device_default_get();
297 /* check for valid device */
298 EINA_SAFETY_ON_TRUE_RETURN(!dev);
299 EINA_LIST_FOREACH(dev->seats, l, seat)
301 EINA_LIST_FOREACH(seat->devices, ll, edev)
303 if (!(edev->caps & E_INPUT_SEAT_POINTER ||
304 edev->caps & E_INPUT_SEAT_TOUCH))
307 if (x) *x = seat->ptr.dx;
308 if (y) *y = seat->ptr.dy;
316 e_input_device_pointer_warp(E_Input_Device *dev, int x, int y)
319 E_Input_Evdev *edev, *warp_dev;
321 Eina_Bool found = EINA_FALSE;
322 char *device_name = NULL, *device_path = NULL;
325 dev = _e_input_device_default_get();
327 if (e_devicemgr && e_devicemgr->last_device_ptr)
329 device_name = (char *)e_devicemgr->last_device_ptr->name;
330 device_path = (char *)e_devicemgr->last_device_ptr->identifier;
333 /* check for valid device */
334 EINA_SAFETY_ON_TRUE_RETURN_VAL(!dev, EINA_FALSE);
335 EINA_LIST_FOREACH(dev->seats, l, seat)
338 EINA_LIST_FOREACH(seat->devices, ll, edev)
340 if (!libinput_device_has_capability(edev->device,
341 LIBINPUT_DEVICE_CAP_POINTER))
344 if (!e_util_strcmp(libinput_device_get_name(edev->device), device_name) &&
345 !e_util_strcmp(edev->path, device_path))
351 if (!warp_dev) warp_dev = edev;
356 seat->ptr.dx = seat->ptr.ix = x;
357 seat->ptr.dy = seat->ptr.iy = y;
358 _e_input_pointer_motion_post(warp_dev);
371 e_input_device_pointer_left_handed_set(E_Input_Device *dev, Eina_Bool left_handed)
373 E_Input_Seat *seat = NULL;
374 E_Input_Evdev *edev = NULL;
375 Eina_List *l = NULL, *l2 = NULL;
377 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
378 EINA_SAFETY_ON_NULL_RETURN_VAL(dev->seats, EINA_FALSE);
380 if (dev->left_handed == left_handed)
382 dev->left_handed = left_handed;
384 EINA_LIST_FOREACH(dev->seats, l, seat)
386 EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
388 if (libinput_device_has_capability(edev->device,
389 LIBINPUT_DEVICE_CAP_POINTER))
391 if (libinput_device_config_left_handed_set(edev->device, (int)left_handed) !=
392 LIBINPUT_CONFIG_STATUS_SUCCESS)
394 WRN("Failed to set left hand mode about device: %s\n",
395 libinput_device_get_name(edev->device));
406 e_input_device_pointer_rotation_set(E_Input_Device *dev, int rotation)
408 E_Input_Seat *seat = NULL;
411 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
412 EINA_SAFETY_ON_NULL_RETURN_VAL(dev->seats, EINA_FALSE);
414 if ((rotation % 90 != 0) || (rotation / 90 > 3) || (rotation < 0)) return EINA_FALSE;
416 EINA_LIST_FOREACH(dev->seats, l, seat)
421 seat->ptr.swap = EINA_TRUE;
422 seat->ptr.invert_x = EINA_FALSE;
423 seat->ptr.invert_y = EINA_TRUE;
426 seat->ptr.swap = EINA_FALSE;
427 seat->ptr.invert_x = EINA_TRUE;
428 seat->ptr.invert_y = EINA_TRUE;
431 seat->ptr.swap = EINA_TRUE;
432 seat->ptr.invert_x = EINA_TRUE;
433 seat->ptr.invert_y = EINA_FALSE;
436 seat->ptr.swap = EINA_FALSE;
437 seat->ptr.invert_x = EINA_FALSE;
438 seat->ptr.invert_y = EINA_FALSE;
448 e_input_device_rotation_set(E_Input_Device *dev, unsigned int rotation)
450 E_Input_Seat *seat = NULL;
451 E_Input_Evdev *edev = NULL;
452 Eina_List *l = NULL, *l2 = NULL;
455 EINA_SAFETY_ON_NULL_RETURN(dev);
456 EINA_SAFETY_ON_NULL_RETURN(dev->seats);
458 EINA_LIST_FOREACH(dev->seats, l, seat)
460 EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
462 if (libinput_device_has_capability(edev->device,
463 LIBINPUT_DEVICE_CAP_POINTER))
465 edev->mouse.minx = edev->mouse.miny = 0;
466 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen),
467 &edev->mouse.maxw, &edev->mouse.maxh);
469 if (rotation == 90 || rotation == 270)
471 temp = edev->mouse.minx;
472 edev->mouse.minx = edev->mouse.miny;
473 edev->mouse.miny = temp;
475 temp = edev->mouse.maxw;
476 edev->mouse.maxw = edev->mouse.maxh;
477 edev->mouse.maxh = temp;
485 _e_input_device_touch_matrix_identify(float result[6])
496 _e_input_device_touch_matrix_mulifly(float result[6], float m1[6], float m2[6])
498 result[0] = m1[0] * m2 [0] + m1[1] * m2[3];
499 result[1] = m1[0] * m2 [1] + m1[1] * m2[4];
500 result[2] = m1[0] * m2 [2] + m1[1] * m2[5] + m1[2];
501 result[3] = m1[3] * m2 [0] + m1[4] * m2[3];
502 result[4] = m1[3] * m2 [1] + m1[4] * m2[4];
503 result[5] = m1[3] * m2 [2] + m1[4] * m2[5] + m1[5];
507 _e_input_device_touch_matrix_rotation_get(float result[6], int degree, float w, float h)
509 if (w == 0.0) w = 1.0;
510 if (h == 0.0) h = 1.0;
539 _e_input_device_touch_matrix_identify(result);
542 WRN("Please input valid angle(%d)\n", degree);
547 _e_input_device_touch_matrix_translate_get(float result[6], float x, float y, float w, float h, float default_w, float default_h)
549 if (default_w == 0.0) default_w = 1.0;
550 if (default_h == 0.0) default_h = 1.0;
552 result[0] = w / default_w;
553 result[4] = h / default_h;
554 result[2] = x / default_w;
555 result[5] = y / default_h;
559 e_input_device_touch_rotation_set(E_Input_Device *dev, unsigned int rotation)
561 E_Input_Seat *seat = NULL;
562 E_Input_Evdev *edev = NULL;
563 Eina_List *l = NULL, *l2 = NULL;
564 float mat_translate[6] = {0.0, }, mat_rotation[6] = {0.0, }, result[6] = {0.0, };
565 float default_w = 0.0, default_h = 0.0;
566 Eina_Bool res = EINA_TRUE;
567 int output_w = 0, output_h = 0;
569 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
570 EINA_SAFETY_ON_NULL_RETURN_VAL(dev->seats, EINA_FALSE);
572 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &output_w, &output_h);
573 default_w = (float)output_w;
574 default_h = (float)output_h;
576 EINA_LIST_FOREACH(dev->seats, l, seat)
578 EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
580 if (edev->caps & E_INPUT_SEAT_TOUCH)
582 _e_input_device_touch_matrix_identify(mat_translate);
583 _e_input_device_touch_matrix_identify(mat_rotation);
584 _e_input_device_touch_matrix_identify(result);
586 if (edev->touch.transform.x || edev->touch.transform.y ||
587 edev->touch.transform.w || edev->touch.transform.h)
589 _e_input_device_touch_matrix_translate_get(mat_translate,
590 (float)edev->touch.transform.x,
591 (float)edev->touch.transform.y,
592 (float)edev->touch.transform.w,
593 (float)edev->touch.transform.h,
594 default_w, default_h);
598 _e_input_device_touch_matrix_rotation_get(mat_rotation, rotation, default_w, default_h);
600 _e_input_device_touch_matrix_mulifly(result, mat_translate, mat_rotation);
602 if (!e_input_evdev_touch_calibration_set(edev, result))
609 edev->touch.transform.rotation = rotation;
619 e_input_device_touch_transformation_set(E_Input_Device *dev, int offset_x, int offset_y, int w, int h)
621 E_Input_Seat *seat = NULL;
622 E_Input_Evdev *edev = NULL;
623 Eina_List *l = NULL, *l2 = NULL;
624 float mat_translate[6] = {0.0, }, mat_rotation[6] = {0.0 }, result[6] = {0.0, };
625 float default_w = 0.0, default_h = 0.0;
626 Eina_Bool res = EINA_TRUE;
627 int output_w = 0, output_h = 0;
629 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
630 EINA_SAFETY_ON_NULL_RETURN_VAL(dev->seats, EINA_FALSE);
631 EINA_SAFETY_ON_TRUE_RETURN_VAL((w == 0) || (h == 0), EINA_FALSE);
633 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &output_w, &output_h);
634 default_w = (float)output_w;
635 default_h = (float)output_h;
637 EINA_LIST_FOREACH(dev->seats, l, seat)
639 EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
641 if (edev->caps & E_INPUT_SEAT_TOUCH)
643 _e_input_device_touch_matrix_identify(mat_translate);
644 _e_input_device_touch_matrix_identify(mat_rotation);
645 _e_input_device_touch_matrix_identify(result);
647 _e_input_device_touch_matrix_translate_get(mat_translate,
648 (float)offset_x, (float)offset_y,
649 (float)w, (float)h, default_w, default_h);
651 if (edev->touch.transform.rotation)
653 _e_input_device_touch_matrix_rotation_get(mat_rotation,
654 edev->touch.transform.rotation,
655 default_w, default_h);
658 _e_input_device_touch_matrix_mulifly(result, mat_translate, mat_rotation);
660 if (!e_input_evdev_touch_calibration_set(edev, result))
667 edev->touch.transform.x = offset_x;
668 edev->touch.transform.y = offset_y;
669 edev->touch.transform.w = w;
670 edev->touch.transform.h = h;
679 e_input_device_libinput_log_handler(struct libinput *libinput EINA_UNUSED,
680 enum libinput_log_priority priority,
681 const char *format, va_list args)
683 char buf[1024] = {0,};
685 vsnprintf(buf, 1024, format, args);
688 case LIBINPUT_LOG_PRIORITY_DEBUG:
691 case LIBINPUT_LOG_PRIORITY_INFO:
694 case LIBINPUT_LOG_PRIORITY_ERROR:
703 e_input_device_input_backend_create(E_Input_Device *dev, E_Input_Libinput_Backend backend)
705 Eina_Bool res = EINA_FALSE;
707 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
709 if (backend == E_INPUT_LIBINPUT_BACKEND_UDEV)
711 TRACE_INPUT_BEGIN(e_input_device_input_create_libinput_udev);
712 res = e_input_device_input_create_libinput_udev(dev);
715 else if (backend == E_INPUT_LIBINPUT_BACKEND_PATH)
717 TRACE_INPUT_BEGIN(e_input_device_input_create_libinput_path);
718 res = e_input_device_input_create_libinput_path(dev);
726 _e_input_device_input_thread_name_set(void)
728 eina_thread_name_set(eina_thread_self(), "input-device-thread");
732 _einput_device_input_thread_udev_backend_heavy(void *data, Ecore_Thread *th, void *msg_data)
734 E_Input_Backend *input = (E_Input_Backend *)data;
736 EINA_SAFETY_ON_NULL_RETURN(input);
737 EINA_SAFETY_ON_NULL_RETURN(input->dev);
738 EINA_SAFETY_ON_NULL_RETURN(input->dev->seat);
740 /* try to create libinput context */
742 libinput_udev_create_context(&_input_interface, input, eeze_udev_get());
744 if (!input->libinput)
748 ERR("Could not create libinput context: %m");
752 _e_input_device_input_thread_name_set();
754 if (input->log_disable)
755 libinput_log_set_handler(input->libinput, NULL);
758 if (input->log_use_eina)
759 libinput_log_set_handler(input->libinput, e_input_device_libinput_log_handler);
760 libinput_log_set_priority(input->libinput, LIBINPUT_LOG_PRIORITY_INFO);
763 TRACE_INPUT_BEGIN(libinput_udev_assign_seat);
764 /* assign udev seat */
765 if (libinput_udev_assign_seat(input->libinput, input->dev->seat) != 0)
767 ERR("Failed to assign seat: %m");
777 _einput_device_input_thread_udev_backend_notify(void *data, Ecore_Thread *th, void *msg_data)
779 //TODO : do if there is something to do in main thread
783 _einput_device_input_thread_udev_backend_end(void *data, Ecore_Thread *th, void *msg_data)
785 E_Input_Backend *input = (E_Input_Backend *)data;
786 E_Input_Device *dev = NULL;
788 EINA_SAFETY_ON_NULL_RETURN(input);
789 EINA_SAFETY_ON_NULL_RETURN(input->dev);
791 input->thread = NULL;
793 /* enable this input */
794 if (!e_input_enable_input(input))
796 ERR("Failed to enable input");
800 /* append this input */
802 dev->inputs = eina_list_append(dev->inputs, input);
804 /* process pending events */
805 _input_events_process(input);
810 _einput_device_input_thread_udev_backend_cancel(void *data, Ecore_Thread *th, void *msg_data)
812 E_Input_Backend *input = (E_Input_Backend *)data;
814 EINA_SAFETY_ON_NULL_RETURN(input);
816 input->thread = NULL;
820 _e_input_device_input_thread_init_udev_backend(E_Input_Backend *input)
822 EINA_SAFETY_ON_NULL_RETURN_VAL(input, EINA_FALSE);
824 input->thread = ecore_thread_feedback_run((Ecore_Thread_Cb)_einput_device_input_thread_udev_backend_heavy,
825 (Ecore_Thread_Notify_Cb)_einput_device_input_thread_udev_backend_notify,
826 (Ecore_Thread_Cb)_einput_device_input_thread_udev_backend_end,
827 (Ecore_Thread_Cb)_einput_device_input_thread_udev_backend_cancel, input, 1);
828 return !!(input->thread);
831 /* public functions */
833 e_input_device_input_create_libinput_udev(E_Input_Device *dev)
835 E_Input_Backend *input;
840 /* check for valid device */
841 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
843 /* try to allocate space for new input structure */
844 if (!(input = calloc(1, sizeof(E_Input_Backend))))
849 /* set reference for parent device */
852 input->backend = E_INPUT_LIBINPUT_BACKEND_UDEV;
853 input->log_disable = EINA_FALSE;
854 input->log_use_eina = EINA_FALSE;
856 env = e_util_env_get(E_INPUT_ENV_LIBINPUT_LOG_DISABLE);
857 if ((env) && (atoi(env) == 1))
858 input->log_disable = EINA_TRUE;
861 if (env) E_FREE(env);
863 env = e_util_env_get(E_INPUT_ENV_LIBINPUT_LOG_EINA_LOG);
864 if ((env) && (atoi(env) == 1))
865 input->log_use_eina = EINA_TRUE;
869 env = e_util_env_get("UDEV_MONITOR_EVENT_SOURCE");
873 libinput_udev_set_udev_monitor_event_source(env);
877 env = e_util_env_get("UDEV_MONITOR_BUFFER_SIZE");
879 if ((env) && (buf_size = atoi(env)))
881 res = libinput_udev_set_udev_monitor_buffer_size(buf_size);
883 ERR("Wrong buffer size for udev monitor : %d\n", buf_size);
887 if (e_input_thread_enabled_get())
889 /* initialize libinput udev backend within an ecore thread */
890 if (!_e_input_device_input_thread_init_udev_backend(input))
892 ERR("Failed to initialize e_input backend (libinput udev backend) !");
899 /* try to create libinput context */
901 libinput_udev_create_context(&_input_interface, input, eeze_udev_get());
902 if (!input->libinput)
904 ERR("Could not create libinput context: %m");
908 if (input->log_disable)
909 libinput_log_set_handler(input->libinput, NULL);
912 if (input->log_use_eina)
913 libinput_log_set_handler(input->libinput, e_input_device_libinput_log_handler);
914 libinput_log_set_priority(input->libinput, LIBINPUT_LOG_PRIORITY_INFO);
917 /* assign udev seat */
918 TRACE_INPUT_BEGIN(libinput_udev_assign_seat);
919 if (libinput_udev_assign_seat(input->libinput, dev->seat) != 0)
921 ERR("Failed to assign seat: %m");
927 /* enable this input */
928 if (!e_input_enable_input(input))
930 ERR("Failed to enable input");
934 /* append this input */
935 dev->inputs = eina_list_append(dev->inputs, input);
937 /* process pending events */
938 _input_events_process(input);
943 if (input->libinput) libinput_unref(input->libinput);
950 _einput_device_input_thread_path_backend_heavy(void *data, Ecore_Thread *th, void *msg_data)
953 struct libinput_device *device;
954 E_Input_Backend *input = (E_Input_Backend *)data;
956 EINA_SAFETY_ON_NULL_RETURN(input);
957 EINA_SAFETY_ON_NULL_RETURN(input->dev);
958 EINA_SAFETY_ON_NULL_RETURN(input->dev->seat);
960 /* try to create libinput context */
962 libinput_path_create_context(&_input_interface, input);
963 if (!input->libinput)
967 ERR("Could not create libinput path context: %m");
971 _e_input_device_input_thread_name_set();
973 if (input->log_disable)
974 libinput_log_set_handler(input->libinput, NULL);
977 if (input->log_use_eina)
978 libinput_log_set_handler(input->libinput, e_input_device_libinput_log_handler);
979 libinput_log_set_priority(input->libinput, LIBINPUT_LOG_PRIORITY_INFO);
982 TRACE_INPUT_BEGIN(libinput_path_add_device_loop);
983 for (int i = 0; i < input->path_ndevices; i++)
985 char buf[1024] = "PATH_DEVICE_";
986 eina_convert_itoa(i + 1, buf + 12);
987 env = e_util_env_get(buf);
991 device = libinput_path_add_device(input->libinput, env);
993 ERR("Failed to initialized device %s", env);
995 INF("libinput_path created input device %s", env);
1005 _einput_device_input_thread_path_backend_notify(void *data, Ecore_Thread *th, void *msg_data)
1007 //TODO : do if there is something to do in main thread
1011 _einput_device_input_thread_path_backend_end(void *data, Ecore_Thread *th, void *msg_data)
1013 E_Input_Backend *input = (E_Input_Backend *)data;
1014 E_Input_Device *dev = NULL;
1016 EINA_SAFETY_ON_NULL_RETURN(input);
1017 EINA_SAFETY_ON_NULL_RETURN(input->dev);
1019 input->thread = NULL;
1021 /* enable this input */
1022 if (!e_input_enable_input(input))
1024 ERR("Failed to enable input");
1028 /* append this input */
1030 dev->inputs = eina_list_append(dev->inputs, input);
1032 /* process pending events */
1033 _input_events_process(input);
1037 _einput_device_input_thread_path_backend_cancel(void *data, Ecore_Thread *th, void *msg_data)
1039 E_Input_Backend *input = (E_Input_Backend *)data;
1041 EINA_SAFETY_ON_NULL_RETURN(input);
1043 input->thread = NULL;
1047 _e_input_device_input_thread_init_path_backend(E_Input_Backend *input)
1049 EINA_SAFETY_ON_NULL_RETURN_VAL(input, EINA_FALSE);
1051 input->thread = ecore_thread_feedback_run((Ecore_Thread_Cb)_einput_device_input_thread_path_backend_heavy,
1052 (Ecore_Thread_Notify_Cb)_einput_device_input_thread_path_backend_notify,
1053 (Ecore_Thread_Cb)_einput_device_input_thread_path_backend_end,
1054 (Ecore_Thread_Cb)_einput_device_input_thread_path_backend_cancel, input, 1);
1055 return !!(input->thread);
1059 e_input_device_input_create_libinput_path(E_Input_Device *dev)
1061 E_Input_Backend *input;
1062 struct libinput_device *device;
1066 /* check for valid device */
1067 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
1069 env = e_util_env_get("PATH_DEVICES_NUM");
1072 ndevices = atoi(env);
1076 if (ndevices <= 0 || ndevices >= INT_MAX)
1081 INF("PATH_DEVICES_NUM : %d", ndevices);
1083 /* try to allocate space for new input structure */
1084 if (!(input = calloc(1, sizeof(E_Input_Backend))))
1089 /* set reference for parent device */
1092 input->backend = E_INPUT_LIBINPUT_BACKEND_PATH;
1093 input->path_ndevices = ndevices;
1094 input->log_disable = EINA_FALSE;
1095 input->log_use_eina = EINA_FALSE;
1097 env = e_util_env_get(E_INPUT_ENV_LIBINPUT_LOG_DISABLE);
1098 if ((env) && (atoi(env) == 1))
1099 input->log_disable = EINA_TRUE;
1102 if (env) E_FREE(env);
1104 env = e_util_env_get(E_INPUT_ENV_LIBINPUT_LOG_EINA_LOG);
1105 if ((env) && (atoi(env) == 1))
1106 input->log_use_eina = EINA_TRUE;
1110 if (e_input_thread_enabled_get())
1112 /* initialize libinput path backend within an ecore thread */
1113 if (!_e_input_device_input_thread_init_path_backend(input))
1115 ERR("Failed to initialize e_input backend (libinput path backend) !");
1122 /* try to create libinput context */
1124 libinput_path_create_context(&_input_interface, input);
1125 if (!input->libinput)
1127 ERR("Could not create libinput path context: %m");
1131 if (input->log_disable)
1132 libinput_log_set_handler(input->libinput, NULL);
1135 if (input->log_use_eina)
1136 libinput_log_set_handler(input->libinput, e_input_device_libinput_log_handler);
1137 libinput_log_set_priority(input->libinput, LIBINPUT_LOG_PRIORITY_INFO);
1140 TRACE_INPUT_BEGIN(libinput_path_add_device_loop);
1141 for (int i = 0; i < ndevices; i++)
1143 char buf[1024] = "PATH_DEVICE_";
1144 eina_convert_itoa(i + 1, buf + 12);
1145 env = e_util_env_get(buf);
1148 device = libinput_path_add_device(input->libinput, env);
1150 ERR("Failed to initialized device %s", env);
1152 INF("libinput_path created input device %s", env);
1158 /* enable this input */
1159 if (!e_input_enable_input(input))
1161 ERR("Failed to enable input");
1165 /* append this input */
1166 dev->inputs = eina_list_append(dev->inputs, input);
1168 /* process pending events */
1169 _input_events_process(input);
1174 if (input->libinput) libinput_unref(input->libinput);
1181 e_input_device_output_changed(E_Input_Device *dev)
1183 E_Input_Seat *seat = NULL;
1184 E_Input_Evdev *edev = NULL;
1185 Eina_List *l = NULL, *l2 = NULL;
1187 EINA_SAFETY_ON_NULL_RETURN(dev);
1188 EINA_SAFETY_ON_NULL_RETURN(dev->seats);
1190 EINA_LIST_FOREACH(dev->seats, l, seat)
1192 EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
1194 _device_calibration_set(edev);
1199 E_API const Eina_List *
1200 e_input_devices_get(void)
1202 return einput_devices;
1206 e_input_device_mouse_accel_speed_set(E_Input_Device *dev, double speed)
1208 E_Input_Seat *seat = NULL;
1209 E_Input_Evdev *edev = NULL;
1210 Eina_List *l = NULL, *l2 = NULL;
1211 Eina_Bool res = EINA_TRUE, ret = EINA_TRUE;
1213 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
1214 EINA_SAFETY_ON_NULL_RETURN_VAL(dev->seats, EINA_FALSE);
1216 EINA_LIST_FOREACH(dev->seats, l, seat)
1218 EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
1220 if (edev->caps & E_INPUT_SEAT_POINTER)
1221 res = e_input_evdev_mouse_accel_speed_set(edev, speed);
1222 if (!res) ret = EINA_FALSE;
1230 e_input_device_touch_pressed_get(E_Input_Device *dev)
1232 E_Input_Seat *seat = NULL;
1233 E_Input_Evdev *edev = NULL;
1234 Eina_List *l = NULL, *l2 = NULL;
1235 unsigned int pressed = 0x0;
1237 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
1239 EINA_LIST_FOREACH(dev->seats, l, seat)
1241 EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
1243 if (edev->caps & E_INPUT_SEAT_TOUCH)
1244 pressed |= e_input_evdev_touch_pressed_get(edev);
1252 e_input_device_keyboard_remap_set(E_Input_Device *dev, int *from_keys, int *to_keys, int num)
1254 E_Input_Seat *seat = NULL;
1255 E_Input_Evdev *edev = NULL;
1256 Eina_List *l = NULL, *l2 = NULL;
1257 Eina_Bool res = EINA_TRUE, ret = EINA_TRUE;
1259 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
1260 EINA_SAFETY_ON_NULL_RETURN_VAL(dev->seats, EINA_FALSE);
1261 EINA_SAFETY_ON_NULL_RETURN_VAL(from_keys, EINA_FALSE);
1262 EINA_SAFETY_ON_NULL_RETURN_VAL(to_keys, EINA_FALSE);
1263 EINA_SAFETY_ON_TRUE_RETURN_VAL(num <= 0, EINA_FALSE);
1265 EINA_LIST_FOREACH(dev->seats, l, seat)
1267 EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
1269 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
1271 res = e_input_evdev_key_remap_enable(edev, EINA_TRUE);
1273 res = e_input_evdev_key_remap_set(edev, from_keys, to_keys, num);
1275 if (!res) ret = EINA_FALSE;
1283 e_input_device_block(E_Input_Device *dev, unsigned int type, void *client)
1285 E_Input_Seat *seat = NULL;
1286 E_Input_Evdev *edev = NULL;
1287 Eina_List *l = NULL, *l2 = NULL;
1289 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
1291 if (client && client != E_INPUT_REQUEST_SERVER)
1293 if (dev->blocked_client && (dev->blocked_client != client))
1295 WRN("Already blocked by client: %p (type: 0x%x)\n", dev->blocked_client, dev->blocked);
1299 dev->blocked |= type;
1300 dev->blocked_client = client;
1302 else if (client == E_INPUT_REQUEST_SERVER)
1304 dev->server_blocked = type;
1307 if (type & E_INPUT_SEAT_TOUCH)
1309 EINA_LIST_FOREACH(dev->seats, l, seat)
1311 EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
1313 edev->touch.blocked = EINA_TRUE;
1322 e_input_device_unblock(E_Input_Device *dev, void *client)
1324 E_Input_Seat *seat = NULL;
1325 E_Input_Evdev *edev = NULL;
1326 Eina_List *l = NULL, *l2 = NULL;
1328 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
1330 if (client != E_INPUT_REQUEST_SERVER && dev->blocked_client != client)
1332 WRN("Currently %p client has already bloked (type: 0x%x)\n", dev->blocked_client, dev->blocked);
1336 if ((dev->server_blocked & E_INPUT_SEAT_TOUCH) ||
1337 (dev->blocked & E_INPUT_SEAT_TOUCH))
1339 EINA_LIST_FOREACH(dev->seats, l, seat)
1341 EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
1343 if (edev->touch.raw_pressed == 0x0)
1344 edev->touch.blocked = EINA_FALSE;
1349 if (client == E_INPUT_REQUEST_SERVER)
1351 dev->server_blocked = 0x0;
1356 dev->blocked_client = NULL;
1363 e_input_device_output_name_set(E_Input_Device *dev, const char *input, const char *output)
1366 E_Input_Evdev *edev = NULL;
1368 Eina_Bool found = EINA_FALSE;
1371 dev = _e_input_device_default_get();
1373 EINA_SAFETY_ON_TRUE_RETURN_VAL(!dev, EINA_FALSE);
1374 EINA_SAFETY_ON_TRUE_RETURN_VAL(!input, EINA_FALSE);
1375 EINA_SAFETY_ON_TRUE_RETURN_VAL(!output, EINA_FALSE);
1376 EINA_LIST_FOREACH(dev->seats, l, seat)
1378 EINA_LIST_FOREACH(seat->devices, ll, edev)
1380 if (!e_util_strcmp(edev->path, input))
1389 if (!found || !edev)
1391 ERR("Failed to find input device: %s", input);
1395 if (e_output_find(output))
1397 INF("output device found: %s", output);
1398 eina_stringshare_replace(&edev->output_name, output);
1399 edev->output_configured = EINA_FALSE;
1403 ERR("Failed to find output device: %s", output);
1408 EINTERN const char *
1409 e_input_device_output_name_get(E_Input_Device *dev, const char *input)
1412 E_Input_Evdev *edev = NULL;
1414 Eina_Bool found = EINA_FALSE;
1417 dev = _e_input_device_default_get();
1419 EINA_SAFETY_ON_TRUE_RETURN_VAL(!dev, NULL);
1420 EINA_SAFETY_ON_TRUE_RETURN_VAL(!input, NULL);
1421 EINA_LIST_FOREACH(dev->seats, l, seat)
1423 EINA_LIST_FOREACH(seat->devices, ll, edev)
1425 if (!e_util_strcmp(edev->path, input))
1433 if (!found || !edev)
1435 ERR("Failed to find input device: %s", input);
1438 return edev->output_name;
1442 e_input_device_seat_name_set(E_Input_Device *dev, const char *input, const char *seat_name)
1445 E_Input_Evdev *edev = NULL;
1447 Eina_Bool found = EINA_FALSE;
1450 dev = _e_input_device_default_get();
1452 EINA_SAFETY_ON_TRUE_RETURN_VAL(!dev, EINA_FALSE);
1453 EINA_SAFETY_ON_TRUE_RETURN_VAL(!input, EINA_FALSE);
1454 EINA_SAFETY_ON_TRUE_RETURN_VAL(!seat_name, EINA_FALSE);
1455 EINA_LIST_FOREACH(dev->seats, l, seat)
1457 EINA_LIST_FOREACH(seat->devices, ll, edev)
1459 if (!e_util_strcmp(edev->path, input))
1468 if (!found || !edev)
1470 ERR("Failed to find input device: %s", input);
1474 INF("Current seatname:%s", e_input_evdev_seatname_get(edev));
1475 if (e_input_evdev_seatname_set(edev, seat_name))
1477 INF("New seatname is now set: %s", seat_name);
1481 ERR("Failed to set new seatname: %s", seat_name);