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 g_mutex_lock(&edev->xkb.keymap_mutex);
116 xkb_keymap_unref(edev->xkb.keymap);
117 edev->xkb.keymap = xkb_keymap_ref(map);
118 g_mutex_unlock(&edev->xkb.keymap_mutex);
120 g_mutex_lock(&edev->xkb.state_mutex);
121 xkb_state_unref(edev->xkb.state);
122 edev->xkb.state = xkb_state_new(map);
123 g_mutex_unlock(&edev->xkb.state_mutex);
128 e_input_device_keyboard_cached_context_set(struct xkb_context *ctx)
130 EINA_SAFETY_ON_NULL_RETURN(ctx);
132 if (cached_context == ctx) return;
135 _e_input_device_cached_context_update(ctx);
137 cached_context = ctx;
141 e_input_device_keyboard_cached_keymap_set(struct xkb_keymap *map)
143 EINA_SAFETY_ON_NULL_RETURN(map);
145 if (cached_keymap == map) return;
148 _e_input_device_cached_keymap_update(map);
154 e_input_device_destroy(E_Input_Device *dev)
156 E_Input_Backend *input;
160 EINA_SAFETY_ON_NULL_RETURN(dev);
162 EINA_LIST_FREE(dev->seats, seat)
164 EINA_LIST_FREE(seat->devices, edev)
166 libinput_device_config_send_events_set_mode(edev->device,
167 LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
168 _e_input_evdev_device_destroy(edev);
172 eina_stringshare_del(seat->name);
176 EINA_LIST_FREE(dev->inputs, input)
179 ecore_main_fd_handler_del(input->hdlr);
181 libinput_unref(input->libinput);
185 eina_stringshare_del(dev->seat);
186 xkb_context_unref(dev->xkb_ctx);
187 eina_hash_free(dev->fd_hash);
190 if (dev == e_input_device_default)
191 e_input_device_default = NULL;
197 _e_input_device_add_list(E_Input_Device *dev)
200 E_Input_Device *dev_data;
202 EINA_LIST_FOREACH(einput_devices, l, dev_data)
204 if (dev_data == dev) return;
207 einput_devices = eina_list_append(einput_devices, dev);
211 _e_input_device_remove_list(E_Input_Device *dev)
213 Eina_List *l, *l_next;
214 E_Input_Device *dev_data;
216 EINA_LIST_FOREACH_SAFE(einput_devices, l, l_next, dev_data)
219 einput_devices = eina_list_remove_list(einput_devices, l);
223 EINTERN E_Input_Device *
224 e_input_device_open(void)
226 E_Input_Device *dev = NULL;
228 dev = (E_Input_Device *)calloc(1, sizeof(E_Input_Device));
232 EINA_LOG_ERR("Failed to alloc memory for E_Input_Device\n");
236 dev->seat = eina_stringshare_add("seat0");
237 dev->fd_hash = eina_hash_string_superfast_new(NULL);
239 /* try to create xkb context */
240 if (!(dev->xkb_ctx = _e_input_device_cached_context_get(0)))
242 ERR("Failed to create xkb context: %m");
246 if (!e_input_device_default)
247 e_input_device_default = dev;
249 _e_input_device_add_list(dev);
256 eina_stringshare_del(dev->seat);
257 eina_hash_free(dev->fd_hash);
258 xkb_context_unref(dev->xkb_ctx);
266 e_input_device_close(E_Input_Device *dev)
268 /* check for valid device */
269 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
271 _e_input_device_remove_list(dev);
272 e_input_device_destroy(dev);
278 e_input_device_window_set(E_Input_Device *dev, Ecore_Window window)
280 /* check for valid device */
281 EINA_SAFETY_ON_TRUE_RETURN(!dev);
283 /* TODO : Must update window of ecore/evas device when the given window */
284 /* is not equal to the existing window. */
286 dev->window = window;
290 e_input_device_pointer_xy_get(E_Input_Device *dev, int *x, int *y)
300 dev = _e_input_device_default_get();
302 /* check for valid device */
303 EINA_SAFETY_ON_TRUE_RETURN(!dev);
304 EINA_LIST_FOREACH(dev->seats, l, seat)
306 EINA_LIST_FOREACH(seat->devices, ll, edev)
308 if (!(edev->caps & E_INPUT_SEAT_POINTER ||
309 edev->caps & E_INPUT_SEAT_TOUCH))
312 if (x) *x = seat->ptr.dx;
313 if (y) *y = seat->ptr.dy;
321 e_input_device_pointer_warp(E_Input_Device *dev, int x, int y)
324 E_Input_Evdev *edev, *warp_dev;
326 Eina_Bool found = EINA_FALSE;
327 char *device_name = NULL, *device_path = NULL;
330 dev = _e_input_device_default_get();
332 if (e_devicemgr && e_devicemgr->last_device_ptr)
334 device_name = (char *)e_devicemgr->last_device_ptr->name;
335 device_path = (char *)e_devicemgr->last_device_ptr->identifier;
338 /* check for valid device */
339 EINA_SAFETY_ON_TRUE_RETURN_VAL(!dev, EINA_FALSE);
340 EINA_LIST_FOREACH(dev->seats, l, seat)
343 EINA_LIST_FOREACH(seat->devices, ll, edev)
345 if (!libinput_device_has_capability(edev->device,
346 LIBINPUT_DEVICE_CAP_POINTER))
349 if (!e_util_strcmp(libinput_device_get_name(edev->device), device_name) &&
350 !e_util_strcmp(edev->path, device_path))
356 if (!warp_dev) warp_dev = edev;
361 _e_input_hook_call(E_INPUT_HOOK_POINTER_WARP, libinput_device_get_name(warp_dev->device));
363 seat->ptr.dx = seat->ptr.ix = x;
364 seat->ptr.dy = seat->ptr.iy = y;
365 _e_input_pointer_motion_post(warp_dev);
378 e_input_device_pointer_left_handed_set(E_Input_Device *dev, Eina_Bool left_handed)
380 E_Input_Seat *seat = NULL;
381 E_Input_Evdev *edev = NULL;
382 Eina_List *l = NULL, *l2 = NULL;
384 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
385 EINA_SAFETY_ON_NULL_RETURN_VAL(dev->seats, EINA_FALSE);
387 if (dev->left_handed == left_handed)
389 dev->left_handed = left_handed;
391 EINA_LIST_FOREACH(dev->seats, l, seat)
393 EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
395 if (libinput_device_has_capability(edev->device,
396 LIBINPUT_DEVICE_CAP_POINTER))
398 if (libinput_device_config_left_handed_set(edev->device, (int)left_handed) !=
399 LIBINPUT_CONFIG_STATUS_SUCCESS)
401 WRN("Failed to set left hand mode about device: %s\n",
402 libinput_device_get_name(edev->device));
413 e_input_device_pointer_rotation_set(E_Input_Device *dev, int rotation)
415 E_Input_Seat *seat = NULL;
418 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
419 EINA_SAFETY_ON_NULL_RETURN_VAL(dev->seats, EINA_FALSE);
421 if ((rotation % 90 != 0) || (rotation / 90 > 3) || (rotation < 0)) return EINA_FALSE;
423 EINA_LIST_FOREACH(dev->seats, l, seat)
428 seat->ptr.swap = EINA_TRUE;
429 seat->ptr.invert_x = EINA_FALSE;
430 seat->ptr.invert_y = EINA_TRUE;
433 seat->ptr.swap = EINA_FALSE;
434 seat->ptr.invert_x = EINA_TRUE;
435 seat->ptr.invert_y = EINA_TRUE;
438 seat->ptr.swap = EINA_TRUE;
439 seat->ptr.invert_x = EINA_TRUE;
440 seat->ptr.invert_y = EINA_FALSE;
443 seat->ptr.swap = EINA_FALSE;
444 seat->ptr.invert_x = EINA_FALSE;
445 seat->ptr.invert_y = EINA_FALSE;
455 e_input_device_rotation_set(E_Input_Device *dev, unsigned int rotation)
457 E_Input_Seat *seat = NULL;
458 E_Input_Evdev *edev = NULL;
459 Eina_List *l = NULL, *l2 = NULL;
462 EINA_SAFETY_ON_NULL_RETURN(dev);
463 EINA_SAFETY_ON_NULL_RETURN(dev->seats);
465 EINA_LIST_FOREACH(dev->seats, l, seat)
467 EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
469 if (libinput_device_has_capability(edev->device,
470 LIBINPUT_DEVICE_CAP_POINTER))
472 edev->mouse.minx = edev->mouse.miny = 0;
473 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen),
474 &edev->mouse.maxw, &edev->mouse.maxh);
476 if (rotation == 90 || rotation == 270)
478 temp = edev->mouse.minx;
479 edev->mouse.minx = edev->mouse.miny;
480 edev->mouse.miny = temp;
482 temp = edev->mouse.maxw;
483 edev->mouse.maxw = edev->mouse.maxh;
484 edev->mouse.maxh = temp;
492 _e_input_device_touch_matrix_identify(float result[6])
503 _e_input_device_touch_matrix_multiply(float result[6], float m1[6], float m2[6])
505 result[0] = m1[0] * m2 [0] + m1[1] * m2[3];
506 result[1] = m1[0] * m2 [1] + m1[1] * m2[4];
507 result[2] = m1[0] * m2 [2] + m1[1] * m2[5] + m1[2];
508 result[3] = m1[3] * m2 [0] + m1[4] * m2[3];
509 result[4] = m1[3] * m2 [1] + m1[4] * m2[4];
510 result[5] = m1[3] * m2 [2] + m1[4] * m2[5] + m1[5];
514 _e_input_device_touch_matrix_rotation_get(float result[6], int degree, float w, float h)
516 if (w == 0.0) w = 1.0;
517 if (h == 0.0) h = 1.0;
546 _e_input_device_touch_matrix_identify(result);
549 WRN("Please input valid angle(%d)\n", degree);
554 _e_input_device_touch_matrix_translate_get(float result[6], float x, float y, float w, float h, float default_w, float default_h)
556 if (default_w == 0.0) default_w = 1.0;
557 if (default_h == 0.0) default_h = 1.0;
559 result[0] = w / default_w;
560 result[4] = h / default_h;
561 result[2] = x / default_w;
562 result[5] = y / default_h;
566 e_input_device_touch_rotation_set(E_Input_Device *dev, unsigned int rotation)
568 E_Input_Seat *seat = NULL;
569 E_Input_Evdev *edev = NULL;
570 Eina_List *l = NULL, *l2 = NULL;
571 float mat_translate[6] = {0.0, }, mat_rotation[6] = {0.0, }, result[6] = {0.0, };
572 float default_w = 0.0, default_h = 0.0;
573 Eina_Bool res = EINA_TRUE;
574 int output_w = 0, output_h = 0;
576 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
577 EINA_SAFETY_ON_NULL_RETURN_VAL(dev->seats, EINA_FALSE);
579 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &output_w, &output_h);
580 default_w = (float)output_w;
581 default_h = (float)output_h;
583 EINA_LIST_FOREACH(dev->seats, l, seat)
585 EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
587 if (edev->caps & E_INPUT_SEAT_TOUCH)
589 _e_input_device_touch_matrix_identify(mat_translate);
590 _e_input_device_touch_matrix_identify(mat_rotation);
591 _e_input_device_touch_matrix_identify(result);
593 if (edev->touch.transform.x || edev->touch.transform.y ||
594 edev->touch.transform.w || edev->touch.transform.h)
596 _e_input_device_touch_matrix_translate_get(mat_translate,
597 (float)edev->touch.transform.x,
598 (float)edev->touch.transform.y,
599 (float)edev->touch.transform.w,
600 (float)edev->touch.transform.h,
601 default_w, default_h);
605 _e_input_device_touch_matrix_rotation_get(mat_rotation, rotation, default_w, default_h);
607 _e_input_device_touch_matrix_multiply(result, mat_translate, mat_rotation);
609 if (!e_input_evdev_touch_calibration_set(edev, result))
616 edev->touch.transform.rotation = rotation;
626 e_input_device_touch_transformation_set(E_Input_Device *dev, int offset_x, int offset_y, int w, int h)
628 E_Input_Seat *seat = NULL;
629 E_Input_Evdev *edev = NULL;
630 Eina_List *l = NULL, *l2 = NULL;
631 float mat_translate[6] = {0.0, }, mat_rotation[6] = {0.0 }, result[6] = {0.0, };
632 float default_w = 0.0, default_h = 0.0;
633 Eina_Bool res = EINA_TRUE;
634 int output_w = 0, output_h = 0;
636 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
637 EINA_SAFETY_ON_NULL_RETURN_VAL(dev->seats, EINA_FALSE);
638 EINA_SAFETY_ON_TRUE_RETURN_VAL((w == 0) || (h == 0), EINA_FALSE);
640 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &output_w, &output_h);
641 default_w = (float)output_w;
642 default_h = (float)output_h;
644 EINA_LIST_FOREACH(dev->seats, l, seat)
646 EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
648 if (edev->caps & E_INPUT_SEAT_TOUCH)
650 _e_input_device_touch_matrix_identify(mat_translate);
651 _e_input_device_touch_matrix_identify(mat_rotation);
652 _e_input_device_touch_matrix_identify(result);
654 _e_input_device_touch_matrix_translate_get(mat_translate,
655 (float)offset_x, (float)offset_y,
656 (float)w, (float)h, default_w, default_h);
658 if (edev->touch.transform.rotation)
660 _e_input_device_touch_matrix_rotation_get(mat_rotation,
661 edev->touch.transform.rotation,
662 default_w, default_h);
665 _e_input_device_touch_matrix_multiply(result, mat_translate, mat_rotation);
667 if (!e_input_evdev_touch_calibration_set(edev, result))
674 edev->touch.transform.x = offset_x;
675 edev->touch.transform.y = offset_y;
676 edev->touch.transform.w = w;
677 edev->touch.transform.h = h;
686 _libinput_log_handler(struct libinput *libinput EINA_UNUSED,
687 enum libinput_log_priority priority,
688 const char *format, va_list args)
690 char buf[1024] = {0,};
692 vsnprintf(buf, 1024, format, args);
695 case LIBINPUT_LOG_PRIORITY_DEBUG:
698 case LIBINPUT_LOG_PRIORITY_INFO:
701 case LIBINPUT_LOG_PRIORITY_ERROR:
710 e_input_device_input_backend_create(E_Input_Device *dev, E_Input_Libinput_Backend backend)
712 Eina_Bool res = EINA_FALSE;
714 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
716 if (backend == E_INPUT_LIBINPUT_BACKEND_UDEV)
718 TRACE_INPUT_BEGIN(e_input_device_input_create_libinput_udev);
719 res = e_input_device_input_create_libinput_udev(dev);
722 else if (backend == E_INPUT_LIBINPUT_BACKEND_PATH)
724 TRACE_INPUT_BEGIN(e_input_device_input_create_libinput_path);
725 res = e_input_device_input_create_libinput_path(dev);
733 _e_input_device_input_thread_name_set(void)
735 eina_thread_name_set(eina_thread_self(), "input-device-thread");
739 _einput_device_input_thread_udev_backend_heavy(void *data, Ecore_Thread *th, void *msg_data)
741 E_Input_Backend *input = (E_Input_Backend *)data;
743 EINA_SAFETY_ON_NULL_RETURN(input);
744 EINA_SAFETY_ON_NULL_RETURN(input->dev);
745 EINA_SAFETY_ON_NULL_RETURN(input->dev->seat);
747 /* try to create libinput context */
749 libinput_udev_create_context(&_input_interface, input, eeze_udev_get());
751 if (!input->libinput)
755 ERR("Could not create libinput context: %m");
759 _e_input_device_input_thread_name_set();
761 if (input->log_disable)
762 libinput_log_set_handler(input->libinput, NULL);
765 if (input->log_use_eina)
766 libinput_log_set_handler(input->libinput, _libinput_log_handler);
767 libinput_log_set_priority(input->libinput, LIBINPUT_LOG_PRIORITY_INFO);
770 TRACE_INPUT_BEGIN(libinput_udev_assign_seat);
771 /* assign udev seat */
772 if (libinput_udev_assign_seat(input->libinput, input->dev->seat) != 0)
774 ERR("Failed to assign seat: %m");
784 _einput_device_input_thread_udev_backend_notify(void *data, Ecore_Thread *th, void *msg_data)
786 //TODO : do if there is something to do in main thread
790 _einput_device_input_thread_udev_backend_end(void *data, Ecore_Thread *th, void *msg_data)
792 E_Input_Backend *input = (E_Input_Backend *)data;
793 E_Input_Device *dev = NULL;
795 EINA_SAFETY_ON_NULL_RETURN(input);
796 EINA_SAFETY_ON_NULL_RETURN(input->dev);
798 input->thread = NULL;
800 /* enable this input */
801 if (!e_input_enable_input(input))
803 ERR("Failed to enable input");
807 /* append this input */
809 dev->inputs = eina_list_append(dev->inputs, input);
811 /* process pending events */
812 _input_events_process(input);
816 _einput_device_input_thread_udev_backend_cancel(void *data, Ecore_Thread *th, void *msg_data)
818 E_Input_Backend *input = (E_Input_Backend *)data;
820 EINA_SAFETY_ON_NULL_RETURN(input);
822 input->thread = NULL;
826 _e_input_device_input_thread_init_udev_backend(E_Input_Backend *input)
828 EINA_SAFETY_ON_NULL_RETURN_VAL(input, EINA_FALSE);
830 input->thread = ecore_thread_feedback_run((Ecore_Thread_Cb)_einput_device_input_thread_udev_backend_heavy,
831 (Ecore_Thread_Notify_Cb)_einput_device_input_thread_udev_backend_notify,
832 (Ecore_Thread_Cb)_einput_device_input_thread_udev_backend_end,
833 (Ecore_Thread_Cb)_einput_device_input_thread_udev_backend_cancel, input, 1);
834 return !!(input->thread);
837 /* public functions */
839 e_input_device_input_create_libinput_udev(E_Input_Device *dev)
841 E_Input_Backend *input;
846 /* check for valid device */
847 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
849 /* try to allocate space for new input structure */
850 if (!(input = calloc(1, sizeof(E_Input_Backend))))
855 /* set reference for parent device */
858 input->backend = E_INPUT_LIBINPUT_BACKEND_UDEV;
859 input->log_disable = EINA_FALSE;
860 input->log_use_eina = EINA_FALSE;
862 env = e_util_env_get(E_INPUT_ENV_LIBINPUT_LOG_DISABLE);
863 if ((env) && (atoi(env) == 1))
864 input->log_disable = EINA_TRUE;
867 if (env) E_FREE(env);
869 env = e_util_env_get(E_INPUT_ENV_LIBINPUT_LOG_EINA_LOG);
870 if ((env) && (atoi(env) == 1))
871 input->log_use_eina = EINA_TRUE;
875 env = e_util_env_get("UDEV_MONITOR_EVENT_SOURCE");
879 libinput_udev_set_udev_monitor_event_source(env);
883 env = e_util_env_get("UDEV_MONITOR_BUFFER_SIZE");
885 if ((env) && (buf_size = atoi(env)))
887 res = libinput_udev_set_udev_monitor_buffer_size(buf_size);
889 ERR("Wrong buffer size for udev monitor : %d\n", buf_size);
893 if (e_input_thread_enabled_get())
895 /* initialize libinput udev backend within an ecore thread */
896 if (!_e_input_device_input_thread_init_udev_backend(input))
898 ERR("Failed to initialize e_input backend (libinput udev backend) !");
905 /* try to create libinput context */
907 libinput_udev_create_context(&_input_interface, input, eeze_udev_get());
908 if (!input->libinput)
910 ERR("Could not create libinput context: %m");
914 if (input->log_disable)
915 libinput_log_set_handler(input->libinput, NULL);
918 if (input->log_use_eina)
919 libinput_log_set_handler(input->libinput, _libinput_log_handler);
920 libinput_log_set_priority(input->libinput, LIBINPUT_LOG_PRIORITY_INFO);
923 /* assign udev seat */
924 TRACE_INPUT_BEGIN(libinput_udev_assign_seat);
925 if (libinput_udev_assign_seat(input->libinput, dev->seat) != 0)
927 ERR("Failed to assign seat: %m");
933 /* enable this input */
934 if (!e_input_enable_input(input))
936 ERR("Failed to enable input");
940 /* append this input */
941 dev->inputs = eina_list_append(dev->inputs, input);
943 /* process pending events */
944 _input_events_process(input);
949 if (input->libinput) libinput_unref(input->libinput);
956 _einput_device_input_thread_path_backend_heavy(void *data, Ecore_Thread *th, void *msg_data)
959 struct libinput_device *device;
960 E_Input_Backend *input = (E_Input_Backend *)data;
962 EINA_SAFETY_ON_NULL_RETURN(input);
963 EINA_SAFETY_ON_NULL_RETURN(input->dev);
964 EINA_SAFETY_ON_NULL_RETURN(input->dev->seat);
966 /* try to create libinput context */
968 libinput_path_create_context(&_input_interface, input);
969 if (!input->libinput)
973 ERR("Could not create libinput path context: %m");
977 _e_input_device_input_thread_name_set();
979 if (input->log_disable)
980 libinput_log_set_handler(input->libinput, NULL);
983 if (input->log_use_eina)
984 libinput_log_set_handler(input->libinput, _libinput_log_handler);
985 libinput_log_set_priority(input->libinput, LIBINPUT_LOG_PRIORITY_INFO);
988 TRACE_INPUT_BEGIN(libinput_path_add_device_loop);
989 for (int i = 0; i < input->path_ndevices; i++)
991 char buf[1024] = "PATH_DEVICE_";
992 eina_convert_itoa(i + 1, buf + 12);
993 env = e_util_env_get(buf);
997 device = libinput_path_add_device(input->libinput, env);
999 ERR("Failed to initialized device %s", env);
1001 INF("libinput_path created input device %s", env);
1011 _einput_device_input_thread_path_backend_notify(void *data, Ecore_Thread *th, void *msg_data)
1013 //TODO : do if there is something to do in main thread
1017 _einput_device_input_thread_path_backend_end(void *data, Ecore_Thread *th, void *msg_data)
1019 E_Input_Backend *input = (E_Input_Backend *)data;
1020 E_Input_Device *dev = NULL;
1022 EINA_SAFETY_ON_NULL_RETURN(input);
1023 EINA_SAFETY_ON_NULL_RETURN(input->dev);
1025 input->thread = NULL;
1027 /* enable this input */
1028 if (!e_input_enable_input(input))
1030 ERR("Failed to enable input");
1034 /* append this input */
1036 dev->inputs = eina_list_append(dev->inputs, input);
1038 /* process pending events */
1039 _input_events_process(input);
1043 _einput_device_input_thread_path_backend_cancel(void *data, Ecore_Thread *th, void *msg_data)
1045 E_Input_Backend *input = (E_Input_Backend *)data;
1047 EINA_SAFETY_ON_NULL_RETURN(input);
1049 input->thread = NULL;
1053 _e_input_device_input_thread_init_path_backend(E_Input_Backend *input)
1055 EINA_SAFETY_ON_NULL_RETURN_VAL(input, EINA_FALSE);
1057 input->thread = ecore_thread_feedback_run((Ecore_Thread_Cb)_einput_device_input_thread_path_backend_heavy,
1058 (Ecore_Thread_Notify_Cb)_einput_device_input_thread_path_backend_notify,
1059 (Ecore_Thread_Cb)_einput_device_input_thread_path_backend_end,
1060 (Ecore_Thread_Cb)_einput_device_input_thread_path_backend_cancel, input, 1);
1061 return !!(input->thread);
1065 e_input_device_input_create_libinput_path(E_Input_Device *dev)
1067 E_Input_Backend *input;
1068 struct libinput_device *device;
1072 /* check for valid device */
1073 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
1075 env = e_util_env_get("PATH_DEVICES_NUM");
1078 ndevices = atoi(env);
1082 if (ndevices <= 0 || ndevices >= INT_MAX)
1087 INF("PATH_DEVICES_NUM : %d", ndevices);
1089 /* try to allocate space for new input structure */
1090 if (!(input = calloc(1, sizeof(E_Input_Backend))))
1095 /* set reference for parent device */
1098 input->backend = E_INPUT_LIBINPUT_BACKEND_PATH;
1099 input->path_ndevices = ndevices;
1100 input->log_disable = EINA_FALSE;
1101 input->log_use_eina = EINA_FALSE;
1103 env = e_util_env_get(E_INPUT_ENV_LIBINPUT_LOG_DISABLE);
1104 if ((env) && (atoi(env) == 1))
1105 input->log_disable = EINA_TRUE;
1108 if (env) E_FREE(env);
1110 env = e_util_env_get(E_INPUT_ENV_LIBINPUT_LOG_EINA_LOG);
1111 if ((env) && (atoi(env) == 1))
1112 input->log_use_eina = EINA_TRUE;
1116 if (e_input_thread_enabled_get())
1118 /* initialize libinput path backend within an ecore thread */
1119 if (!_e_input_device_input_thread_init_path_backend(input))
1121 ERR("Failed to initialize e_input backend (libinput path backend) !");
1128 /* try to create libinput context */
1130 libinput_path_create_context(&_input_interface, input);
1131 if (!input->libinput)
1133 ERR("Could not create libinput path context: %m");
1137 if (input->log_disable)
1138 libinput_log_set_handler(input->libinput, NULL);
1141 if (input->log_use_eina)
1142 libinput_log_set_handler(input->libinput, _libinput_log_handler);
1143 libinput_log_set_priority(input->libinput, LIBINPUT_LOG_PRIORITY_INFO);
1146 TRACE_INPUT_BEGIN(libinput_path_add_device_loop);
1147 for (int i = 0; i < ndevices; i++)
1149 char buf[1024] = "PATH_DEVICE_";
1150 eina_convert_itoa(i + 1, buf + 12);
1151 env = e_util_env_get(buf);
1154 device = libinput_path_add_device(input->libinput, env);
1156 ERR("Failed to initialized device %s", env);
1158 INF("libinput_path created input device %s", env);
1164 /* enable this input */
1165 if (!e_input_enable_input(input))
1167 ERR("Failed to enable input");
1171 /* append this input */
1172 dev->inputs = eina_list_append(dev->inputs, input);
1174 /* process pending events */
1175 _input_events_process(input);
1180 if (input->libinput) libinput_unref(input->libinput);
1187 e_input_device_output_changed(E_Input_Device *dev)
1189 E_Input_Seat *seat = NULL;
1190 E_Input_Evdev *edev = NULL;
1191 Eina_List *l = NULL, *l2 = NULL;
1193 EINA_SAFETY_ON_NULL_RETURN(dev);
1194 EINA_SAFETY_ON_NULL_RETURN(dev->seats);
1196 EINA_LIST_FOREACH(dev->seats, l, seat)
1198 EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
1200 _device_calibration_set(edev);
1205 E_API const Eina_List *
1206 e_input_devices_get(void)
1208 return einput_devices;
1212 e_input_device_mouse_accel_speed_set(E_Input_Device *dev, double speed)
1214 E_Input_Seat *seat = NULL;
1215 E_Input_Evdev *edev = NULL;
1216 Eina_List *l = NULL, *l2 = NULL;
1217 Eina_Bool res = EINA_TRUE, ret = EINA_TRUE;
1219 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
1220 EINA_SAFETY_ON_NULL_RETURN_VAL(dev->seats, EINA_FALSE);
1222 EINA_LIST_FOREACH(dev->seats, l, seat)
1224 EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
1226 if (edev->caps & E_INPUT_SEAT_POINTER)
1227 res = e_input_evdev_mouse_accel_speed_set(edev, speed);
1228 if (!res) ret = EINA_FALSE;
1235 EINTERN unsigned int
1236 e_input_device_touch_pressed_get(E_Input_Device *dev)
1238 E_Input_Seat *seat = NULL;
1239 E_Input_Evdev *edev = NULL;
1240 Eina_List *l = NULL, *l2 = NULL;
1241 unsigned int pressed = 0x0;
1243 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
1245 EINA_LIST_FOREACH(dev->seats, l, seat)
1247 EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
1249 if (edev->caps & E_INPUT_SEAT_TOUCH)
1250 pressed |= e_input_evdev_touch_pressed_get(edev);
1258 e_input_device_keyboard_remap_set(E_Input_Device *dev, int *from_keys, int *to_keys, int num)
1260 E_Input_Seat *seat = NULL;
1261 E_Input_Evdev *edev = NULL;
1262 Eina_List *l = NULL, *l2 = NULL;
1263 Eina_Bool res = EINA_TRUE, ret = EINA_TRUE;
1265 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
1266 EINA_SAFETY_ON_NULL_RETURN_VAL(dev->seats, EINA_FALSE);
1267 EINA_SAFETY_ON_NULL_RETURN_VAL(from_keys, EINA_FALSE);
1268 EINA_SAFETY_ON_NULL_RETURN_VAL(to_keys, EINA_FALSE);
1269 EINA_SAFETY_ON_TRUE_RETURN_VAL(num <= 0, EINA_FALSE);
1271 EINA_LIST_FOREACH(dev->seats, l, seat)
1273 EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
1275 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
1277 res = e_input_evdev_key_remap_enable(edev, EINA_TRUE);
1279 res = e_input_evdev_key_remap_set(edev, from_keys, to_keys, num);
1281 if (!res) ret = EINA_FALSE;
1289 e_input_device_block(E_Input_Device *dev, unsigned int type, void *client)
1291 E_Input_Seat *seat = NULL;
1292 E_Input_Evdev *edev = NULL;
1293 Eina_List *l = NULL, *l2 = NULL;
1295 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
1297 if (client && client != E_INPUT_REQUEST_SERVER)
1299 if (dev->blocked_client && (dev->blocked_client != client))
1301 WRN("Already blocked by client: %p (type: 0x%x)\n", dev->blocked_client, dev->blocked);
1305 dev->blocked |= type;
1306 dev->blocked_client = client;
1308 else if (client == E_INPUT_REQUEST_SERVER)
1310 dev->server_blocked = type;
1313 if (type & E_INPUT_SEAT_TOUCH)
1315 EINA_LIST_FOREACH(dev->seats, l, seat)
1317 EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
1319 edev->touch.blocked = EINA_TRUE;
1328 e_input_device_unblock(E_Input_Device *dev, void *client)
1330 E_Input_Seat *seat = NULL;
1331 E_Input_Evdev *edev = NULL;
1332 Eina_List *l = NULL, *l2 = NULL;
1334 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
1336 if (client != E_INPUT_REQUEST_SERVER && dev->blocked_client != client)
1338 WRN("Currently %p client has already bloked (type: 0x%x)\n", dev->blocked_client, dev->blocked);
1342 if ((dev->server_blocked & E_INPUT_SEAT_TOUCH) ||
1343 (dev->blocked & E_INPUT_SEAT_TOUCH))
1345 EINA_LIST_FOREACH(dev->seats, l, seat)
1347 EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
1349 if (edev->touch.raw_pressed == 0x0)
1350 edev->touch.blocked = EINA_FALSE;
1355 if (client == E_INPUT_REQUEST_SERVER)
1357 dev->server_blocked = 0x0;
1362 dev->blocked_client = NULL;
1369 e_input_device_output_name_set(E_Input_Device *dev, const char *input, const char *output)
1372 E_Input_Evdev *edev = NULL;
1374 Eina_Bool found = EINA_FALSE;
1377 dev = _e_input_device_default_get();
1379 EINA_SAFETY_ON_TRUE_RETURN_VAL(!dev, EINA_FALSE);
1380 EINA_SAFETY_ON_TRUE_RETURN_VAL(!input, EINA_FALSE);
1381 EINA_SAFETY_ON_TRUE_RETURN_VAL(!output, EINA_FALSE);
1382 EINA_LIST_FOREACH(dev->seats, l, seat)
1384 EINA_LIST_FOREACH(seat->devices, ll, edev)
1386 if (!e_util_strcmp(edev->path, input))
1395 if (!found || !edev)
1397 ERR("Failed to find input device: %s", input);
1401 if (e_output_find(output))
1403 INF("output device found: %s", output);
1404 eina_stringshare_replace(&edev->output_name, output);
1405 edev->output_configured = EINA_FALSE;
1409 ERR("Failed to find output device: %s", output);
1414 EINTERN const char *
1415 e_input_device_output_name_get(E_Input_Device *dev, const char *input)
1418 E_Input_Evdev *edev = NULL;
1420 Eina_Bool found = EINA_FALSE;
1423 dev = _e_input_device_default_get();
1425 EINA_SAFETY_ON_TRUE_RETURN_VAL(!dev, NULL);
1426 EINA_SAFETY_ON_TRUE_RETURN_VAL(!input, NULL);
1427 EINA_LIST_FOREACH(dev->seats, l, seat)
1429 EINA_LIST_FOREACH(seat->devices, ll, edev)
1431 if (!e_util_strcmp(edev->path, input))
1439 if (!found || !edev)
1441 ERR("Failed to find input device: %s", input);
1444 return edev->output_name;
1448 e_input_device_seat_name_set(E_Input_Device *dev, const char *input, const char *seat_name)
1451 E_Input_Evdev *edev = NULL;
1453 Eina_Bool found = EINA_FALSE;
1456 dev = _e_input_device_default_get();
1458 EINA_SAFETY_ON_TRUE_RETURN_VAL(!dev, EINA_FALSE);
1459 EINA_SAFETY_ON_TRUE_RETURN_VAL(!input, EINA_FALSE);
1460 EINA_SAFETY_ON_TRUE_RETURN_VAL(!seat_name, EINA_FALSE);
1461 EINA_LIST_FOREACH(dev->seats, l, seat)
1463 EINA_LIST_FOREACH(seat->devices, ll, edev)
1465 if (!e_util_strcmp(edev->path, input))
1474 if (!found || !edev)
1476 ERR("Failed to find input device: %s", input);
1480 INF("Current seatname:%s", e_input_evdev_seatname_get(edev));
1481 if (e_input_evdev_seatname_set(edev, seat_name))
1483 INF("New seatname is now set: %s", seat_name);
1487 ERR("Failed to set new seatname: %s", seat_name);
1493 e_input_device_subtype_set(E_Input_Device *dev, const char *input, const char *subtype_name)
1495 Ecore_Device *ecore_dev = NULL;
1496 E_Device *e_dev = NULL;
1497 Ecore_Device_Subclass device_subclas = ECORE_DEVICE_SUBCLASS_NONE;
1500 dev = _e_input_device_default_get();
1502 EINA_SAFETY_ON_TRUE_RETURN_VAL(!dev, EINA_FALSE);
1503 EINA_SAFETY_ON_TRUE_RETURN_VAL(!input, EINA_FALSE);
1504 EINA_SAFETY_ON_TRUE_RETURN_VAL(!subtype_name, EINA_FALSE);
1506 //TODO : find device other than keyboard type.
1507 //right now, subclas is only used with keyboard type.
1508 if (!e_input_thread_mode_get())
1510 ecore_dev = e_input_evdev_get_ecore_device(input, ECORE_DEVICE_CLASS_KEYBOARD);
1513 ERR("Failed to find input device: %s", input);
1517 device_subclas = ecore_device_subclass_get(ecore_dev);
1519 if (!e_util_strcmp(subtype_name, "Remocon") &&
1520 device_subclas != ECORE_DEVICE_SUBCLASS_REMOCON)
1522 ecore_device_subclass_set(ecore_dev, ECORE_DEVICE_SUBCLASS_REMOCON);
1523 INF("device(%s) subtype is changed to Remocon(%d->%d)", input,
1524 device_subclas, ECORE_DEVICE_SUBCLASS_REMOCON);
1526 else if (!e_util_strcmp(subtype_name, "None") &&
1527 device_subclas != ECORE_DEVICE_SUBCLASS_NONE)
1529 ecore_device_subclass_set(ecore_dev, ECORE_DEVICE_SUBCLASS_NONE);
1530 INF("device(%s) subtype is changed to None(%d->%d)", input,
1531 device_subclas, ECORE_DEVICE_SUBCLASS_NONE);
1535 ERR("Failed to set new subtype: %s (current:%d)", subtype_name, device_subclas);
1541 e_dev = e_input_evdev_get_e_device(input, ECORE_DEVICE_CLASS_KEYBOARD);
1544 ERR("Failed to find input device: %s", input);
1548 device_subclas = e_device_subclass_get(e_dev);
1550 if (!e_util_strcmp(subtype_name, "Remocon") &&
1551 device_subclas != ECORE_DEVICE_SUBCLASS_REMOCON)
1553 e_device_subclass_set(e_dev, ECORE_DEVICE_SUBCLASS_REMOCON);
1554 INF("device(%s) subtype is changed to Remocon(%d->%d)", input,
1555 device_subclas, ECORE_DEVICE_SUBCLASS_REMOCON);
1557 else if (!e_util_strcmp(subtype_name, "None") &&
1558 device_subclas != ECORE_DEVICE_SUBCLASS_NONE)
1560 e_device_subclass_set(e_dev, ECORE_DEVICE_SUBCLASS_NONE);
1561 INF("device(%s) subtype is changed to None(%d->%d)", input,
1562 device_subclas, ECORE_DEVICE_SUBCLASS_NONE);
1566 ERR("Failed to set new subtype: %s (current:%d)", subtype_name, device_subclas);
1575 e_input_device_mouse_accel_enable_set(const char *device_name, Eina_Bool enable)
1577 const Eina_List *l, *ll, *lll;
1578 E_Input_Device *dev;
1580 E_Input_Evdev *edev;
1581 Eina_Bool found = EINA_FALSE;
1583 EINA_SAFETY_ON_NULL_RETURN_VAL(device_name, EINA_FALSE);
1585 EINA_LIST_FOREACH(e_input_devices_get(), l, dev)
1587 EINA_LIST_FOREACH(dev->seats, ll, seat)
1589 EINA_LIST_FOREACH(seat->devices, lll, edev)
1591 if ((edev->caps & E_INPUT_SEAT_POINTER) &&
1592 (!e_util_strcmp(device_name, libinput_device_get_name(edev->device))))
1595 edev->disable_acceleration = !enable;
1603 ERR("Failed to find input device. device(%s)", device_name);
1607 INF("device(%s) mouse_accel is %s", device_name, enable ? "ON" : "OFF");