1 #include "e_devicemgr_intern.h"
2 #include "e_input_intern.h"
3 #include "e_input_log.h"
4 #include "e_input_event_intern.h"
5 #include "e_keyrouter_intern.h"
6 #include "e_comp_wl_intern.h"
7 #include "e_config_intern.h"
8 #include "e_device_intern.h"
9 #include "e_comp_wl_input_intern.h"
10 #include "e_main_intern.h"
16 # include <systemd/sd-daemon.h>
21 static double t0, t1, t2;
24 static int main_to_input_thread_pipe_fd[2] = {0, };
26 static gboolean input_dispatch(GSource *source, GSourceFunc callback, gpointer user_data);
27 static gboolean input_thread_prepare(GSource *source, gint *time);
29 static E_Input_Backend *g_input_backend = NULL;
30 static E_Input_Event_Source *g_input_event_source = NULL;
31 static GList *_key_event_list = NULL;
33 GSourceFuncs input_event_funcs = {
34 .prepare = input_thread_prepare,
36 .dispatch = input_dispatch,
47 _e_input_ecore_device_class_to_string(Ecore_Device_Class clas)
51 case ECORE_DEVICE_CLASS_NONE:
54 case ECORE_DEVICE_CLASS_SEAT:
57 case ECORE_DEVICE_CLASS_KEYBOARD:
60 case ECORE_DEVICE_CLASS_MOUSE:
63 case ECORE_DEVICE_CLASS_TOUCH:
66 case ECORE_DEVICE_CLASS_PEN:
69 case ECORE_DEVICE_CLASS_WAND:
72 case ECORE_DEVICE_CLASS_GAMEPAD:
80 static Ecore_Device_Class
81 _e_input_seat_cap_to_ecore_device_class(unsigned int cap)
85 case E_INPUT_SEAT_POINTER:
86 return ECORE_DEVICE_CLASS_MOUSE;
87 case E_INPUT_SEAT_KEYBOARD:
88 return ECORE_DEVICE_CLASS_KEYBOARD;
89 case E_INPUT_SEAT_TOUCH:
90 return ECORE_DEVICE_CLASS_TOUCH;
92 return ECORE_DEVICE_CLASS_NONE;
94 return ECORE_DEVICE_CLASS_NONE;
98 _e_input_ecore_device_info_free(void *data EINA_UNUSED, void *ev)
100 Ecore_Event_Device_Info *e;
103 eina_stringshare_del(e->name);
104 eina_stringshare_del(e->identifier);
105 eina_stringshare_del(e->seatname);
111 _e_input_ecore_device_event(Ecore_Device *dev, const char* seat_name, Eina_Bool flag)
113 Ecore_Event_Device_Info *e;
115 const char *name, *identifier;
117 ecore_thread_main_loop_begin();
119 if (!(name = ecore_device_name_get(dev))) goto end;
120 if (!(identifier = ecore_device_identifier_get(dev))) goto end;
122 if (!(e = calloc(1, sizeof(Ecore_Event_Device_Info)))) goto end;
124 e_input = e_input_get();
126 e->window = e_input?e_input->window:(Ecore_Window)0;
127 e->name = eina_stringshare_add(name);
128 e->identifier = eina_stringshare_add(identifier);
129 if (seat_name && strlen(seat_name))
130 e->seatname = eina_stringshare_add(seat_name);
132 e->seatname = eina_stringshare_add(name);
133 e->clas = ecore_device_class_get(dev);
134 e->subclas = ecore_device_subclass_get(dev);
137 ecore_event_add(ECORE_EVENT_DEVICE_ADD, e, _e_input_ecore_device_info_free, NULL);
139 ecore_event_add(ECORE_EVENT_DEVICE_DEL, e, _e_input_ecore_device_info_free, NULL);
142 ecore_thread_main_loop_end();
145 static E_Input_Seat *
146 _seat_create(E_Input_Backend *input, const char *seat)
149 Ecore_Device *ecore_dev = NULL;
150 E_Device *e_dev = NULL;
152 ecore_thread_main_loop_begin();
154 /* create an evas device of a seat */
155 ecore_dev = ecore_device_add();
158 ERR("Failed to create an ecore device for a seat !\n");
159 ecore_thread_main_loop_end();
163 ecore_device_name_set(ecore_dev, seat);
164 ecore_device_identifier_set(ecore_dev, "Enlightenment seat");
165 ecore_device_class_set(ecore_dev, ECORE_DEVICE_CLASS_SEAT);
166 ecore_device_subclass_set(ecore_dev, ECORE_DEVICE_SUBCLASS_NONE);
168 /* create an e device of a seat */
169 e_dev = e_device_new();
172 ERR("Failed to create an ecore device for a seat !\n");
173 ecore_thread_main_loop_end();
177 e_device_name_set(e_dev, seat);
178 e_device_identifier_set(e_dev, "Enlightenment seat");
179 e_device_class_set(e_dev, ECORE_DEVICE_CLASS_SEAT);
180 e_device_subclass_set(e_dev, ECORE_DEVICE_SUBCLASS_NONE);
182 /* try to allocate space for new seat */
183 if (!(s = calloc(1, sizeof(E_Input_Seat))))
185 ecore_device_del(ecore_dev);
186 ecore_thread_main_loop_end();
191 s->name = eina_stringshare_add(seat);
192 s->ecore_dev = ecore_dev;
195 /* add this new seat to list */
196 input->dev->seats = eina_list_append(input->dev->seats, s);
199 ecore_event_add(E_INPUT_EVENT_SEAT_ADD, NULL, NULL, NULL);
200 ecore_thread_main_loop_end();
202 _e_input_ecore_device_event(ecore_dev, seat, EINA_TRUE);
207 static E_Input_Seat *
208 _seat_get(E_Input_Backend *input, const char *seat)
213 /* search for this name in existing seats */
214 EINA_LIST_FOREACH(input->dev->seats, l, s)
215 if (!strcmp(s->name, seat))
218 return _seat_create(input, seat);
222 _e_input_add_ecore_device(E_Input_Evdev *edev, Ecore_Device_Class clas, Ecore_Device_Subclass subclas)
224 const Eina_List *dev_list = NULL;
226 Ecore_Device *dev = NULL;
227 E_Device *e_dev = NULL;
228 const char *identifier;
230 if (!edev || !edev->path) return EINA_FALSE;
232 dev_list = ecore_device_list();
235 EINA_LIST_FOREACH(dev_list, l, dev)
238 identifier = ecore_device_identifier_get(dev);
239 if (!identifier) continue;
240 if ((ecore_device_class_get(dev) == clas) && (!strcmp(identifier, edev->path)))
242 ERR("Found same device in device list");
248 // create ecore device info
249 dev = ecore_device_add();
252 ERR("Failed to create ecore device");
253 edev->ecore_dev = NULL;
257 ecore_device_name_set(dev, libinput_device_get_name(edev->device));
258 ecore_device_identifier_set(dev, edev->path);
259 ecore_device_class_set(dev, clas);
260 ecore_device_subclass_set(dev, subclas);
262 if (!edev->ecore_dev)
264 if (!edev->ecore_dev_list || (eina_list_count(edev->ecore_dev_list) == 0))
266 /* 1st Ecore_Device is added */
267 edev->ecore_dev = ecore_device_ref(dev);
271 /* 3rd or more Ecore_Device is added */
272 edev->ecore_dev_list = eina_list_append(edev->ecore_dev_list, ecore_device_ref(dev));
277 /* 2nd Ecore_Device is added */
278 edev->ecore_dev_list = eina_list_append(edev->ecore_dev_list, edev->ecore_dev);
279 edev->ecore_dev = NULL;
281 edev->ecore_dev_list = eina_list_append(edev->ecore_dev_list, ecore_device_ref(dev));
284 const GList *device_list = e_device_list_get();
285 const gchar *device_identifier;
286 for (GList *list = g_list_first((GList *)device_list); list; list = list->next)
288 E_Device *device = (E_Device *)list->data;
289 if (!device) continue;
290 device_identifier = e_device_identifier_get(device);
291 if (!device_identifier) continue;
293 if ((e_device_class_get(device) == clas) && (!strcmp(device_identifier, edev->path)))
302 // create E_Device info
303 e_dev = e_device_new();
306 ERR("Failed to add e device");
312 e_device_name_set(e_dev, libinput_device_get_name(edev->device));
313 e_device_identifier_set(e_dev, edev->path);
314 e_device_class_set(e_dev, clas);
315 e_device_subclass_set(e_dev, subclas);
319 if (!edev->e_dev_list || (g_list_length(edev->e_dev_list) == 0))
321 /* 1st Ecore_Device is added */
322 edev->e_dev = g_object_ref(e_dev);
326 /* 3rd or more Ecore_Device is added */
327 edev->e_dev_list = g_list_append(edev->e_dev_list, g_object_ref(e_dev));
332 /* 2nd Ecore_Device is added */
333 edev->e_dev_list = g_list_append(edev->e_dev_list, edev->e_dev);
336 edev->e_dev_list = g_list_append(edev->e_dev_list, g_object_ref(e_dev));
339 _e_input_ecore_device_event(dev, edev->seat ? edev->seat->name : NULL, EINA_TRUE);
341 INF("[Add Device] device name(%s), identifier(%s), class(%s) subclas(%d)", e_device_name_get(e_dev), edev->path, _e_input_ecore_device_class_to_string(clas), subclas);
347 _e_input_remove_ecore_device(E_Input_Evdev *edev, Ecore_Device_Class clas)
349 Eina_Bool ret = EINA_FALSE;
350 const Eina_List *dev_list = NULL, *l;
351 const GList *e_dev_list = NULL;
352 Eina_List *ll, *ll_next;
353 Ecore_Device *dev = NULL, *data;
354 const char *identifier;
355 const gchar *device_identifier;
356 const char *device_remove_log = NULL;
358 if (!edev->path) return EINA_FALSE;
360 dev_list = ecore_device_list();
361 if (!dev_list) return EINA_FALSE;
363 EINA_LIST_FOREACH(dev_list, l, dev)
366 identifier = ecore_device_identifier_get(dev);
367 if (!identifier) continue;
368 if ((ecore_device_class_get(dev) == clas) && (!strcmp(identifier, edev->path)))
372 ecore_device_unref(dev);
373 edev->ecore_dev = NULL;
375 else if (edev->ecore_dev_list)
377 EINA_LIST_FOREACH_SAFE(edev->ecore_dev_list, ll, ll_next, data)
381 ecore_device_unref(dev);
382 edev->ecore_dev_list = eina_list_remove_list(edev->ecore_dev_list, ll);
386 _e_input_ecore_device_event(dev, edev->seat ? edev->seat->name : NULL, EINA_FALSE);
387 ecore_device_del(dev);
392 e_dev_list = e_device_list_get();
395 ERR("Failed to get e device list");
399 for (GList *list = g_list_first((GList *)e_dev_list); list; list = list->next)
401 E_Device *device = (E_Device *)list->data;
402 if (!device) continue;
403 device_identifier = e_device_identifier_get(device);
404 if (!device_identifier) continue;
406 if ((e_device_class_get(device) == clas) && (!strcmp(device_identifier, edev->path)))
408 device_remove_log = eina_stringshare_printf("[Remove Device] device name(%s), identifier(%s), class(%s)",
409 e_device_name_get(device),
411 _e_input_ecore_device_class_to_string(clas));
415 g_object_unref(device);
418 else if (edev->e_dev_list)
420 GList *del_list = g_list_find(edev->e_dev_list, device);
423 edev->e_dev_list = g_list_delete_link(edev->e_dev_list, del_list);
430 if (device_remove_log)
432 INF("%s", device_remove_log);
433 eina_stringshare_del(device_remove_log);
439 static Ecore_Device_Subclass
440 _e_input_device_get_ecore_device_subclass(E_Input_Evdev *edev, Ecore_Device_Class clas)
442 Ecore_Device_Subclass subclas = ECORE_DEVICE_SUBCLASS_NONE;
443 struct udev_device *udev_device = NULL;
446 udev_device = libinput_device_get_udev_device(edev->device);
447 devpath = udev_device_get_property_value(udev_device, "DEVPATH");
448 if (devpath && strstr(devpath, "virtual/input"))
450 if (clas == ECORE_DEVICE_CLASS_MOUSE)
451 subclas = ECORE_DEVICE_SUBCLASS_VIRTUAL_MOUSE;
452 else if (clas == ECORE_DEVICE_CLASS_KEYBOARD)
453 subclas = ECORE_DEVICE_SUBCLASS_VIRTUAL_REMOCON;
459 _e_input_device_add(E_Input_Evdev *edev)
461 Eina_Bool ret = EINA_FALSE;
462 Ecore_Device_Class clas = ECORE_DEVICE_CLASS_NONE;
463 Ecore_Device_Subclass subclas = ECORE_DEVICE_SUBCLASS_NONE;
465 if (edev->caps & E_INPUT_SEAT_POINTER)
467 if (!e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
469 clas = _e_input_seat_cap_to_ecore_device_class(E_INPUT_SEAT_POINTER);
470 subclas = _e_input_device_get_ecore_device_subclass(edev, clas);
472 ret = _e_input_add_ecore_device(edev, clas, subclas);
474 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
476 clas = _e_input_seat_cap_to_ecore_device_class(E_INPUT_SEAT_KEYBOARD);
477 subclas = _e_input_device_get_ecore_device_subclass(edev, clas);
478 ret = _e_input_add_ecore_device(edev, clas, subclas);
480 if (edev->caps & E_INPUT_SEAT_TOUCH)
482 clas = _e_input_seat_cap_to_ecore_device_class(E_INPUT_SEAT_TOUCH);
483 ret = _e_input_add_ecore_device(edev, clas, subclas);
490 _e_input_device_remove(E_Input_Evdev *edev)
492 Ecore_Device_Class clas = ECORE_DEVICE_CLASS_NONE;
495 if (edev->caps & E_INPUT_SEAT_POINTER)
497 if (!e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
498 clas = _e_input_seat_cap_to_ecore_device_class(E_INPUT_SEAT_POINTER);
499 _e_input_remove_ecore_device(edev, clas);
501 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
503 clas = _e_input_seat_cap_to_ecore_device_class(E_INPUT_SEAT_KEYBOARD);
504 _e_input_remove_ecore_device(edev, clas);
506 if (edev->caps & E_INPUT_SEAT_TOUCH)
508 clas = _e_input_seat_cap_to_ecore_device_class(E_INPUT_SEAT_TOUCH);
509 _e_input_remove_ecore_device(edev, clas);
512 if (edev->ecore_dev_list)
514 if (eina_list_count(edev->ecore_dev_list) > 0)
516 EINA_LIST_FREE(edev->ecore_dev_list, data)
518 WRN("Invalid device is left. name: %s, identifier: %s, clas: %s\n",
519 ecore_device_name_get(data), ecore_device_identifier_get(data),
520 _e_input_ecore_device_class_to_string(ecore_device_class_get(data)));
522 ecore_device_unref(data);
523 ecore_device_del(data);
526 edev->ecore_dev_list = NULL;
531 _device_added(E_Input_Backend *input, struct libinput_device *device)
533 struct libinput_seat *libinput_seat;
534 const char *seat_name;
538 ecore_thread_main_loop_begin();
539 libinput_seat = libinput_device_get_seat(device);
540 seat_name = libinput_seat_get_logical_name(libinput_seat);
542 /* try to get a seat */
543 if (!(seat = _seat_get(input, seat_name)))
545 ERR("Could not get matching seat: %s", seat_name);
546 ecore_thread_main_loop_end();
550 /* try to create a new evdev device */
551 if (!(edev = _e_input_evdev_device_create(seat, device)))
553 ERR("Failed to create new evdev device");
554 ecore_thread_main_loop_end();
558 /* append this device to the seat */
559 seat->devices = eina_list_append(seat->devices, edev);
561 if (EINA_FALSE == _e_input_device_add(edev))
563 ERR("Failed to create evas device !\n");
564 ecore_thread_main_loop_end();
568 ecore_thread_main_loop_end();
572 _device_removed(E_Input_Backend *input, struct libinput_device *device)
576 ecore_thread_main_loop_begin();
578 /* try to get the evdev structure */
579 if (!(edev = libinput_device_get_user_data(device)))
581 ecore_thread_main_loop_end();
585 _e_input_device_remove(edev);
587 /* remove this evdev from the seat's list of devices */
588 edev->seat->devices = eina_list_remove(edev->seat->devices, edev);
590 /* destroy this evdev */
591 _e_input_evdev_device_destroy(edev);
593 ecore_thread_main_loop_end();
597 _udev_event_process(struct libinput_event *event)
599 struct libinput *libinput;
600 struct libinput_device *device;
601 E_Input_Backend *input;
602 Eina_Bool ret = EINA_TRUE;
604 libinput = libinput_event_get_context(event);
605 input = libinput_get_user_data(libinput);
606 device = libinput_event_get_device(event);
608 switch (libinput_event_get_type(event))
610 case LIBINPUT_EVENT_DEVICE_ADDED:
611 if (e_config->key_input_ttrace_enable)
613 TRACE_INPUT_DEVICE_BEGIN(_device_added);
614 ELOGF("INPUT", "_device_added|B|", NULL);
617 _device_added(input, device);
619 if (e_config->key_input_ttrace_enable)
621 TRACE_INPUT_DEVICE_END();
622 ELOGF("INPUT", "_device_added|E|", NULL);
625 case LIBINPUT_EVENT_DEVICE_REMOVED:
626 if (e_config->key_input_ttrace_enable)
628 TRACE_INPUT_DEVICE_BEGIN(_device_removed);
629 ELOGF("INPUT", "_device_removed|B|", NULL);
632 _device_removed(input, device);
634 if (e_config->key_input_ttrace_enable)
636 TRACE_INPUT_DEVICE_END();
637 ELOGF("INPUT", "_device_removed|E|", NULL);
648 _input_event_process(struct libinput_event *event)
650 if (_udev_event_process(event)) return;
651 if (_e_input_evdev_event_process(event)) return;
655 _input_events_process(E_Input_Backend *input)
657 struct libinput_event *event;
658 while ((event = libinput_get_event(input->libinput)))
660 _input_event_process(event);
661 libinput_event_destroy(event);
666 _cb_input_dispatch(void *data, Ecore_Fd_Handler *hdlr EINA_UNUSED)
668 E_Input_Backend *input;
670 if (!(input = data)) return EINA_TRUE;
672 if (e_config->key_input_ttrace_enable)
674 TRACE_INPUT_DEVICE_BEGIN(_cb_input_dispatch);
675 ELOGF("INPUT", "_cb_input_dispatch|B|", NULL);
678 if (libinput_dispatch(input->libinput) != 0)
679 ERR("Failed to dispatch libinput events: %m");
681 /* process pending events */
682 _input_events_process(input);
684 if (e_config->key_input_ttrace_enable)
686 TRACE_INPUT_DEVICE_END();
687 ELOGF("INPUT", "_cb_input_dispatch|E|", NULL);
694 _e_input_delayed_key_events_print()
699 clock_gettime(CLOCK_MONOTONIC, &tp);
700 time = (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
702 GList *key_list = g_list_first(_key_event_list);
705 Ecore_Event_Key *key = (Ecore_Event_Key *)key_list->data;
708 if (e_config->key_input_time_limit <= (time - key->timestamp))
709 ERR("Delayed key event : keyname(%s), keycode(%u), timestamp(%u), elapsed_time(%u ms)", key->keyname, key->keycode, key->timestamp, time - key->timestamp);
712 eina_stringshare_del(key->keyname);
715 GList *next = key_list->next;
716 _key_event_list = g_list_delete_link(_key_event_list, key_list);
720 _key_event_list = NULL;
724 input_thread_prepare(GSource *source, gint *time)
726 if (e_config->key_input_ttrace_enable)
728 TRACE_INPUT_DEVICE_BEGIN(e_comp_wl_focused_client_flush);
729 ELOGF("INPUT", "e_comp_wl_focused_client_flush|B|", NULL);
732 /* flush only focused client events */
733 e_comp_wl_focused_client_flush();
736 _e_input_delayed_key_events_print();
738 if (e_config->key_input_ttrace_enable)
740 TRACE_INPUT_DEVICE_END();
741 ELOGF("INPUT", "e_comp_wl_focused_client_flush|E|", NULL);
751 input_dispatch(GSource *source, GSourceFunc callback, gpointer user_data)
753 InputEventSource *src = (InputEventSource *)source;
754 E_Input_Backend *input = (E_Input_Backend *)user_data;
755 if (!src) return G_SOURCE_REMOVE;
756 if (!input) return G_SOURCE_REMOVE;
758 if (e_config->key_input_ttrace_enable)
760 TRACE_INPUT_DEVICE_BEGIN(input_dispatch);
761 ELOGF("INPUT", "input_dispatch|B|", NULL);
765 cond = g_source_query_unix_fd(source, src->tag);
767 if (cond & G_IO_ERR || cond & G_IO_HUP || cond & G_IO_NVAL)
769 INF("error cond(%d)\n", cond);
770 return G_SOURCE_CONTINUE;
773 if (!input->libinput)
774 return G_SOURCE_REMOVE;
776 if (e_config->key_input_ttrace_enable)
778 TRACE_INPUT_DEVICE_BEGIN(libinput_dispatch);
779 ELOGF("INPUT", "libinput_dispatch|B|", NULL);
782 if (libinput_dispatch(input->libinput) != 0)
783 ERR("Failed to dispatch libinput events: %m");
785 if (e_config->key_input_ttrace_enable)
787 TRACE_INPUT_DEVICE_END();
788 ELOGF("INPUT", "libinput_dispatch|E|", NULL);
791 if (e_config->key_input_ttrace_enable)
793 TRACE_INPUT_DEVICE_BEGIN(_input_events_process);
794 ELOGF("INPUT", "_input_events_process|B|", NULL);
797 /* process pending events */
798 _input_events_process(input);
800 if (e_config->key_input_ttrace_enable)
802 TRACE_INPUT_DEVICE_END();
803 ELOGF("INPUT", "_input_events_process|E|", NULL);
805 TRACE_INPUT_DEVICE_END();
806 ELOGF("INPUT", "input_dispatch|E|", NULL);
809 e_input_event_process((GSource *)input->event_source);
811 return G_SOURCE_CONTINUE;
815 _pipe_recv_handler(GIOChannel *source, GIOCondition condition, gpointer user_data)
817 E_Input_Backend *input = user_data;
820 E_Input_Thread_Request_Data order;
822 if (condition == G_IO_IN)
824 len = read(input->main_to_input_thread_pipe_fd[0], &order, sizeof(E_Input_Thread_Request_Data));
828 data = calloc(1, sizeof(char)*order.data_length);
829 len = read(input->main_to_input_thread_pipe_fd[0], data, order.data_length);
836 if (order.safe_call_cb)
837 order.safe_call_cb(data);
841 else if (condition == G_IO_ERR || condition == G_IO_HUP)
842 ERR("Error or hangup\n");
848 input_thread_start(void *data, Ecore_Thread *th)
851 E_Input_Backend *input;
852 GMainContext *context = NULL;
853 InputEventSource *input_event_source = NULL;
854 GIOChannel *_pipe_iochannel = NULL;
855 GSource *pipe_source = NULL;
857 if (!(input = data)) return;
859 eina_thread_name_set(eina_thread_self(), "input-thread");
861 e_input_libinput_context_create(input);
863 e_comp_wl_input_keymap_init();
864 e_keyrouter_query_tizen_key_table();
866 INF("write wm_ready");
867 if (e_config->create_wm_ready)
868 e_main_create_wm_ready();
871 TSM("[WM] Send start-up completion");
872 sd_notify(0, "READY=1");
874 TSM("[WM] Skip sending start-up completion. (no systemd)");
877 /* enable this input */
878 if (!e_input_enable_input(input))
880 ERR("Failed to enable input");
884 /* append this input */
886 dev->inputs = eina_list_append(dev->inputs, input);
889 context = g_main_context_new();
890 g_main_context_push_thread_default(context);
892 input_event_source = (InputEventSource *)g_source_new(&input_event_funcs, sizeof(InputEventSource));
893 input_event_source->tag = g_source_add_unix_fd(&input_event_source->gsource, input->fd, G_IO_IN);
895 if (!input->event_source)
896 e_input_create_event_source(input);
899 input->input_thread_loop = g_main_loop_new(context, FALSE);
901 g_source_attach((GSource *)input->event_source, context);
903 //set the callback for this source
904 g_source_set_callback(&input_event_source->gsource, NULL, input, NULL);
905 g_source_attach(&input_event_source->gsource, context);
907 _pipe_iochannel = g_io_channel_unix_new(input->main_to_input_thread_pipe_fd[0]);
908 pipe_source = g_io_create_watch(_pipe_iochannel, G_IO_IN);
909 g_source_set_callback(pipe_source, (GSourceFunc)_pipe_recv_handler, input, NULL);
910 g_source_attach(pipe_source, context);
912 e_keyrouter_input_handler_add();
914 e_input_thread_id_set(gettid());
915 e_input_main_thread_id_set(getpid());
917 _e_input_hook_call(E_INPUT_HOOK_INPUT_THREAD_START, NULL);
919 INF("input thread start tid(%d) pid(%d)", e_input_thread_id_get(), e_input_main_thread_id_get());
921 g_main_loop_run(input->input_thread_loop);
925 input_thread_feedback(void *data, Ecore_Thread *th, void *msgdata)
927 E_Input_Backend *input;
929 INF("input thread start");
931 if (!(input = data)) return;
935 input_thread_end(void *data, Ecore_Thread *th)
937 E_Input_Backend *input;
939 if (!(input = data)) return;
940 INF("input thread complete");
942 e_input_event_source_destroy(input->event_source);
943 input->event_source = NULL;
945 g_main_loop_quit(input->input_thread_loop);
946 g_main_loop_unref(input->input_thread_loop);
947 input->input_thread_loop = NULL;
949 if (th == input->input_thread)
950 input->input_thread = NULL;
954 input_thread_cancel(void *data, Ecore_Thread *th)
956 E_Input_Backend *input;
958 if (!(input = data)) return;
960 INF("input thread cancel");
962 if (th == input->input_thread)
963 input->input_thread = NULL;
967 _e_input_key_event_list_add(Ecore_Event_Key *key)
969 Ecore_Event_Key *clone = NULL;
973 clone = E_NEW(Ecore_Event_Key, 1);
977 clone->keyname = (char *)eina_stringshare_add(key->keyname);
979 clone->keycode = key->keycode;
980 clone->timestamp = key->timestamp;
982 _key_event_list = g_list_append(_key_event_list, clone);
986 e_input_enable_input(E_Input_Backend *input)
988 EINA_SAFETY_ON_NULL_RETURN_VAL(input, EINA_FALSE);
989 EINA_SAFETY_ON_NULL_RETURN_VAL(input->libinput, EINA_FALSE);
991 input->fd = libinput_get_fd(input->libinput);
993 if (!e_input_thread_mode_get())
998 ecore_main_fd_handler_add(input->fd, ECORE_FD_READ,
999 _cb_input_dispatch, input, NULL, NULL);
1003 if (input->suspended)
1005 if (libinput_resume(input->libinput) != 0)
1008 input->suspended = EINA_FALSE;
1010 /* process pending events */
1011 _input_events_process(input);
1014 input->enabled = EINA_TRUE;
1015 input->suspended = EINA_FALSE;
1020 input->enabled = EINA_FALSE;
1021 if (!e_input_thread_mode_get())
1024 ecore_main_fd_handler_del(input->hdlr);
1032 e_input_disable_input(E_Input_Backend *input)
1034 EINA_SAFETY_ON_NULL_RETURN(input);
1035 EINA_SAFETY_ON_TRUE_RETURN(input->suspended);
1037 /* suspend this input */
1038 libinput_suspend(input->libinput);
1040 /* process pending events */
1041 _input_events_process(input);
1043 input->suspended = EINA_TRUE;
1045 if (e_input_thread_mode_get())
1047 if (input->input_thread && !ecore_thread_check(input->input_thread))
1048 ecore_thread_cancel(input->input_thread);
1053 e_input_seat_evdev_list_get(E_Input_Seat *seat)
1055 EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
1056 return seat->devices;
1059 E_API E_Input_Event_Source *
1060 e_input_event_source_get()
1062 return g_input_event_source;
1066 e_input_thread_mode_get()
1069 return e_config->input_thread_mode;
1075 e_input_create_event_source(E_Input_Backend *input)
1077 input->event_source = e_input_event_source_create();
1079 g_input_event_source = input->event_source;
1082 EINTERN void e_input_thread_start()
1084 EINA_SAFETY_ON_NULL_RETURN(g_input_backend);
1086 g_input_backend->input_thread = ecore_thread_feedback_run(input_thread_start, input_thread_feedback, input_thread_end, input_thread_cancel, g_input_backend, EINA_FALSE);
1089 EINTERN void e_input_thread_init()
1091 if (pipe(main_to_input_thread_pipe_fd) != 0)
1092 ERR("error in pipe\n");
1094 if (g_input_backend)
1096 g_input_backend->main_to_input_thread_pipe_fd[0] = main_to_input_thread_pipe_fd[0];
1097 g_input_backend->main_to_input_thread_pipe_fd[1] = main_to_input_thread_pipe_fd[1];
1101 EINTERN void e_input_thread_shutdown()
1103 EINA_SAFETY_ON_NULL_RETURN(g_input_backend);
1105 close(g_input_backend->main_to_input_thread_pipe_fd[0]);
1106 close(g_input_backend->main_to_input_thread_pipe_fd[1]);
1109 EINTERN void e_input_thread_input_backend_set(E_Input_Backend *input)
1111 g_input_backend = input;
1113 if (g_input_backend->main_to_input_thread_pipe_fd[0] == 0)
1115 g_input_backend->main_to_input_thread_pipe_fd[0] = main_to_input_thread_pipe_fd[0];
1116 g_input_backend->main_to_input_thread_pipe_fd[1] = main_to_input_thread_pipe_fd[1];
1121 e_input_thread_safe_call(E_Input_Thread_Safe_Call_Cb cb, void *data, size_t data_length)
1123 E_Input_Thread_Request_Data order;
1124 order.safe_call_cb = cb;
1125 order.data_length = data_length;
1128 if (!g_input_backend)
1130 ERR("Not yet initialized\n");
1134 if (write(g_input_backend->main_to_input_thread_pipe_fd[1], &order, sizeof(E_Input_Thread_Request_Data)) == -1)
1135 ERR("error when writing header in pipe\n");
1137 if (write(g_input_backend->main_to_input_thread_pipe_fd[1], data, data_length) == -1)
1138 ERR("error when writing data in pipe\n");