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);
449 ERR("no udev_device");
453 devpath = udev_device_get_property_value(udev_device, "DEVPATH");
454 if (devpath && strstr(devpath, "virtual/input"))
456 if (clas == ECORE_DEVICE_CLASS_MOUSE)
457 subclas = ECORE_DEVICE_SUBCLASS_VIRTUAL_MOUSE;
458 else if (clas == ECORE_DEVICE_CLASS_KEYBOARD)
459 subclas = ECORE_DEVICE_SUBCLASS_VIRTUAL_REMOCON;
461 udev_device_unref(udev_device);
467 _e_input_device_add(E_Input_Evdev *edev)
469 Eina_Bool ret = EINA_FALSE;
470 Ecore_Device_Class clas = ECORE_DEVICE_CLASS_NONE;
471 Ecore_Device_Subclass subclas = ECORE_DEVICE_SUBCLASS_NONE;
473 if (edev->caps & E_INPUT_SEAT_POINTER)
475 if (!e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
477 clas = _e_input_seat_cap_to_ecore_device_class(E_INPUT_SEAT_POINTER);
478 subclas = _e_input_device_get_ecore_device_subclass(edev, clas);
480 ret = _e_input_add_ecore_device(edev, clas, subclas);
482 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
484 clas = _e_input_seat_cap_to_ecore_device_class(E_INPUT_SEAT_KEYBOARD);
485 subclas = _e_input_device_get_ecore_device_subclass(edev, clas);
486 ret = _e_input_add_ecore_device(edev, clas, subclas);
488 if (edev->caps & E_INPUT_SEAT_TOUCH)
490 clas = _e_input_seat_cap_to_ecore_device_class(E_INPUT_SEAT_TOUCH);
491 ret = _e_input_add_ecore_device(edev, clas, subclas);
498 _e_input_device_remove(E_Input_Evdev *edev)
500 Ecore_Device_Class clas = ECORE_DEVICE_CLASS_NONE;
503 if (edev->caps & E_INPUT_SEAT_POINTER)
505 if (!e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
506 clas = _e_input_seat_cap_to_ecore_device_class(E_INPUT_SEAT_POINTER);
507 _e_input_remove_ecore_device(edev, clas);
509 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
511 clas = _e_input_seat_cap_to_ecore_device_class(E_INPUT_SEAT_KEYBOARD);
512 _e_input_remove_ecore_device(edev, clas);
514 if (edev->caps & E_INPUT_SEAT_TOUCH)
516 clas = _e_input_seat_cap_to_ecore_device_class(E_INPUT_SEAT_TOUCH);
517 _e_input_remove_ecore_device(edev, clas);
520 if (edev->ecore_dev_list)
522 if (eina_list_count(edev->ecore_dev_list) > 0)
524 EINA_LIST_FREE(edev->ecore_dev_list, data)
526 WRN("Invalid device is left. name: %s, identifier: %s, clas: %s\n",
527 ecore_device_name_get(data), ecore_device_identifier_get(data),
528 _e_input_ecore_device_class_to_string(ecore_device_class_get(data)));
530 ecore_device_unref(data);
531 ecore_device_del(data);
534 edev->ecore_dev_list = NULL;
539 _device_added(E_Input_Backend *input, struct libinput_device *device)
541 struct libinput_seat *libinput_seat;
542 const char *seat_name;
546 ecore_thread_main_loop_begin();
547 libinput_seat = libinput_device_get_seat(device);
548 seat_name = libinput_seat_get_logical_name(libinput_seat);
550 /* try to get a seat */
551 if (!(seat = _seat_get(input, seat_name)))
553 ERR("Could not get matching seat: %s", seat_name);
554 ecore_thread_main_loop_end();
558 /* try to create a new evdev device */
559 if (!(edev = _e_input_evdev_device_create(seat, device)))
561 ERR("Failed to create new evdev device");
562 ecore_thread_main_loop_end();
566 /* append this device to the seat */
567 seat->devices = eina_list_append(seat->devices, edev);
569 if (EINA_FALSE == _e_input_device_add(edev))
571 ERR("Failed to create evas device !\n");
572 ecore_thread_main_loop_end();
576 ecore_thread_main_loop_end();
580 _device_removed(E_Input_Backend *input, struct libinput_device *device)
584 ecore_thread_main_loop_begin();
586 /* try to get the evdev structure */
587 if (!(edev = libinput_device_get_user_data(device)))
589 ecore_thread_main_loop_end();
593 _e_input_device_remove(edev);
595 /* remove this evdev from the seat's list of devices */
596 edev->seat->devices = eina_list_remove(edev->seat->devices, edev);
598 /* destroy this evdev */
599 _e_input_evdev_device_destroy(edev);
601 ecore_thread_main_loop_end();
605 _udev_event_process(struct libinput_event *event)
607 struct libinput *libinput;
608 struct libinput_device *device;
609 E_Input_Backend *input;
610 Eina_Bool ret = EINA_TRUE;
612 libinput = libinput_event_get_context(event);
613 input = libinput_get_user_data(libinput);
614 device = libinput_event_get_device(event);
616 switch (libinput_event_get_type(event))
618 case LIBINPUT_EVENT_DEVICE_ADDED:
619 if (e_config->key_input_ttrace_enable)
621 TRACE_INPUT_DEVICE_BEGIN(_device_added);
622 ELOGF("INPUT", "_device_added|B|", NULL);
625 _device_added(input, device);
627 if (e_config->key_input_ttrace_enable)
629 TRACE_INPUT_DEVICE_END();
630 ELOGF("INPUT", "_device_added|E|", NULL);
633 case LIBINPUT_EVENT_DEVICE_REMOVED:
634 if (e_config->key_input_ttrace_enable)
636 TRACE_INPUT_DEVICE_BEGIN(_device_removed);
637 ELOGF("INPUT", "_device_removed|B|", NULL);
640 _device_removed(input, device);
642 if (e_config->key_input_ttrace_enable)
644 TRACE_INPUT_DEVICE_END();
645 ELOGF("INPUT", "_device_removed|E|", NULL);
656 _input_event_process(struct libinput_event *event)
658 if (_udev_event_process(event)) return;
659 if (_e_input_evdev_event_process(event)) return;
663 _input_events_process(E_Input_Backend *input)
665 struct libinput_event *event;
666 while ((event = libinput_get_event(input->libinput)))
668 _input_event_process(event);
669 libinput_event_destroy(event);
674 _cb_input_dispatch(void *data, Ecore_Fd_Handler *hdlr EINA_UNUSED)
676 E_Input_Backend *input;
678 if (!(input = data)) return EINA_TRUE;
680 if (e_config->key_input_ttrace_enable)
682 TRACE_INPUT_DEVICE_BEGIN(_cb_input_dispatch);
683 ELOGF("INPUT", "_cb_input_dispatch|B|", NULL);
686 if (libinput_dispatch(input->libinput) != 0)
687 ERR("Failed to dispatch libinput events: %m");
689 /* process pending events */
690 _input_events_process(input);
692 if (e_config->key_input_ttrace_enable)
694 TRACE_INPUT_DEVICE_END();
695 ELOGF("INPUT", "_cb_input_dispatch|E|", NULL);
702 _e_input_delayed_key_events_print()
707 clock_gettime(CLOCK_MONOTONIC, &tp);
708 time = (tp.tv_sec * 1000) + (tp.tv_nsec / 1000000L);
710 GList *key_list = g_list_first(_key_event_list);
713 Ecore_Event_Key *key = (Ecore_Event_Key *)key_list->data;
716 if (e_config->key_input_time_limit <= (time - key->timestamp))
717 ERR("Delayed key event : keyname(%s), keycode(%u), timestamp(%u), elapsed_time(%u ms)", key->keyname, key->keycode, key->timestamp, time - key->timestamp);
720 eina_stringshare_del(key->keyname);
723 GList *next = key_list->next;
724 _key_event_list = g_list_delete_link(_key_event_list, key_list);
728 _key_event_list = NULL;
732 input_thread_prepare(GSource *source, gint *time)
734 if (e_config->key_input_ttrace_enable)
736 TRACE_INPUT_DEVICE_BEGIN(e_comp_wl_focused_client_flush);
737 ELOGF("INPUT", "e_comp_wl_focused_client_flush|B|", NULL);
740 /* flush only focused client events */
741 e_comp_wl_focused_client_flush();
744 _e_input_delayed_key_events_print();
746 if (e_config->key_input_ttrace_enable)
748 TRACE_INPUT_DEVICE_END();
749 ELOGF("INPUT", "e_comp_wl_focused_client_flush|E|", NULL);
759 input_dispatch(GSource *source, GSourceFunc callback, gpointer user_data)
761 InputEventSource *src = (InputEventSource *)source;
762 E_Input_Backend *input = (E_Input_Backend *)user_data;
763 if (!src) return G_SOURCE_REMOVE;
764 if (!input) return G_SOURCE_REMOVE;
766 if (e_config->key_input_ttrace_enable)
768 TRACE_INPUT_DEVICE_BEGIN(input_dispatch);
769 ELOGF("INPUT", "input_dispatch|B|", NULL);
773 cond = g_source_query_unix_fd(source, src->tag);
775 if (cond & G_IO_ERR || cond & G_IO_HUP || cond & G_IO_NVAL)
777 INF("error cond(%d)\n", cond);
778 return G_SOURCE_CONTINUE;
781 if (!input->libinput)
782 return G_SOURCE_REMOVE;
784 if (e_config->key_input_ttrace_enable)
786 TRACE_INPUT_DEVICE_BEGIN(libinput_dispatch);
787 ELOGF("INPUT", "libinput_dispatch|B|", NULL);
790 if (libinput_dispatch(input->libinput) != 0)
791 ERR("Failed to dispatch libinput events: %m");
793 if (e_config->key_input_ttrace_enable)
795 TRACE_INPUT_DEVICE_END();
796 ELOGF("INPUT", "libinput_dispatch|E|", NULL);
799 if (e_config->key_input_ttrace_enable)
801 TRACE_INPUT_DEVICE_BEGIN(_input_events_process);
802 ELOGF("INPUT", "_input_events_process|B|", NULL);
805 /* process pending events */
806 _input_events_process(input);
808 if (e_config->key_input_ttrace_enable)
810 TRACE_INPUT_DEVICE_END();
811 ELOGF("INPUT", "_input_events_process|E|", NULL);
813 TRACE_INPUT_DEVICE_END();
814 ELOGF("INPUT", "input_dispatch|E|", NULL);
817 e_input_event_process((GSource *)input->event_source);
819 return G_SOURCE_CONTINUE;
823 _pipe_recv_handler(GIOChannel *source, GIOCondition condition, gpointer user_data)
825 E_Input_Backend *input = user_data;
828 E_Input_Thread_Request_Data order;
830 if (condition == G_IO_IN)
832 len = read(input->main_to_input_thread_pipe_fd[0], &order, sizeof(E_Input_Thread_Request_Data));
836 data = calloc(1, sizeof(char)*order.data_length);
837 len = read(input->main_to_input_thread_pipe_fd[0], data, order.data_length);
844 if (order.safe_call_cb)
845 order.safe_call_cb(data);
849 else if (condition == G_IO_ERR || condition == G_IO_HUP)
850 ERR("Error or hangup\n");
856 input_thread_start(void *data, Ecore_Thread *th)
859 E_Input_Backend *input;
860 GMainContext *context = NULL;
861 InputEventSource *input_event_source = NULL;
862 GIOChannel *_pipe_iochannel = NULL;
863 GSource *pipe_source = NULL;
865 if (!(input = data)) return;
867 eina_thread_name_set(eina_thread_self(), "input-thread");
869 e_input_libinput_context_create(input);
871 e_comp_wl_input_keymap_init();
872 e_keyrouter_query_tizen_key_table();
874 INF("write wm_ready");
875 if (e_config->create_wm_ready)
876 e_main_create_wm_ready();
879 TSM("[WM] Send start-up completion");
880 sd_notify(0, "READY=1");
882 TSM("[WM] Skip sending start-up completion. (no systemd)");
885 /* enable this input */
886 if (!e_input_enable_input(input))
888 ERR("Failed to enable input");
892 /* append this input */
894 dev->inputs = eina_list_append(dev->inputs, input);
897 context = g_main_context_new();
898 g_main_context_push_thread_default(context);
900 input_event_source = (InputEventSource *)g_source_new(&input_event_funcs, sizeof(InputEventSource));
901 input_event_source->tag = g_source_add_unix_fd(&input_event_source->gsource, input->fd, G_IO_IN);
903 if (!input->event_source)
904 e_input_create_event_source(input);
907 input->input_thread_loop = g_main_loop_new(context, FALSE);
909 g_source_attach((GSource *)input->event_source, context);
911 //set the callback for this source
912 g_source_set_callback(&input_event_source->gsource, NULL, input, NULL);
913 g_source_attach(&input_event_source->gsource, context);
915 _pipe_iochannel = g_io_channel_unix_new(input->main_to_input_thread_pipe_fd[0]);
916 pipe_source = g_io_create_watch(_pipe_iochannel, G_IO_IN);
917 g_source_set_callback(pipe_source, (GSourceFunc)_pipe_recv_handler, input, NULL);
918 g_source_attach(pipe_source, context);
920 e_keyrouter_input_handler_add();
922 e_input_thread_id_set(gettid());
923 e_input_main_thread_id_set(getpid());
925 _e_input_hook_call(E_INPUT_HOOK_INPUT_THREAD_START, NULL);
927 INF("input thread start tid(%d) pid(%d)", e_input_thread_id_get(), e_input_main_thread_id_get());
929 g_main_loop_run(input->input_thread_loop);
933 input_thread_feedback(void *data, Ecore_Thread *th, void *msgdata)
935 E_Input_Backend *input;
937 INF("input thread start");
939 if (!(input = data)) return;
943 input_thread_end(void *data, Ecore_Thread *th)
945 E_Input_Backend *input;
947 if (!(input = data)) return;
948 INF("input thread complete");
950 e_input_event_source_destroy(input->event_source);
951 input->event_source = NULL;
953 g_main_loop_quit(input->input_thread_loop);
954 g_main_loop_unref(input->input_thread_loop);
955 input->input_thread_loop = NULL;
957 if (th == input->input_thread)
958 input->input_thread = NULL;
962 input_thread_cancel(void *data, Ecore_Thread *th)
964 E_Input_Backend *input;
966 if (!(input = data)) return;
968 INF("input thread cancel");
970 if (th == input->input_thread)
971 input->input_thread = NULL;
975 _e_input_key_event_list_add(Ecore_Event_Key *key)
977 Ecore_Event_Key *clone = NULL;
981 clone = E_NEW(Ecore_Event_Key, 1);
985 clone->keyname = (char *)eina_stringshare_add(key->keyname);
987 clone->keycode = key->keycode;
988 clone->timestamp = key->timestamp;
990 _key_event_list = g_list_append(_key_event_list, clone);
994 e_input_enable_input(E_Input_Backend *input)
996 EINA_SAFETY_ON_NULL_RETURN_VAL(input, EINA_FALSE);
997 EINA_SAFETY_ON_NULL_RETURN_VAL(input->libinput, EINA_FALSE);
999 input->fd = libinput_get_fd(input->libinput);
1001 if (!e_input_thread_mode_get())
1006 ecore_main_fd_handler_add(input->fd, ECORE_FD_READ,
1007 _cb_input_dispatch, input, NULL, NULL);
1011 if (input->suspended)
1013 if (libinput_resume(input->libinput) != 0)
1016 input->suspended = EINA_FALSE;
1018 /* process pending events */
1019 _input_events_process(input);
1022 input->enabled = EINA_TRUE;
1023 input->suspended = EINA_FALSE;
1028 input->enabled = EINA_FALSE;
1029 if (!e_input_thread_mode_get())
1032 ecore_main_fd_handler_del(input->hdlr);
1040 e_input_disable_input(E_Input_Backend *input)
1042 EINA_SAFETY_ON_NULL_RETURN(input);
1043 EINA_SAFETY_ON_TRUE_RETURN(input->suspended);
1045 /* suspend this input */
1046 libinput_suspend(input->libinput);
1048 /* process pending events */
1049 _input_events_process(input);
1051 input->suspended = EINA_TRUE;
1053 if (e_input_thread_mode_get())
1055 if (input->input_thread && !ecore_thread_check(input->input_thread))
1056 ecore_thread_cancel(input->input_thread);
1061 e_input_seat_evdev_list_get(E_Input_Seat *seat)
1063 EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
1064 return seat->devices;
1067 E_API E_Input_Event_Source *
1068 e_input_event_source_get()
1070 return g_input_event_source;
1074 e_input_thread_mode_get()
1077 return e_config->input_thread_mode;
1083 e_input_create_event_source(E_Input_Backend *input)
1085 input->event_source = e_input_event_source_create();
1087 g_input_event_source = input->event_source;
1090 EINTERN void e_input_thread_start()
1092 EINA_SAFETY_ON_NULL_RETURN(g_input_backend);
1094 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);
1097 EINTERN void e_input_thread_init()
1099 if (pipe(main_to_input_thread_pipe_fd) != 0)
1100 ERR("error in pipe\n");
1102 if (g_input_backend)
1104 g_input_backend->main_to_input_thread_pipe_fd[0] = main_to_input_thread_pipe_fd[0];
1105 g_input_backend->main_to_input_thread_pipe_fd[1] = main_to_input_thread_pipe_fd[1];
1109 EINTERN void e_input_thread_shutdown()
1111 EINA_SAFETY_ON_NULL_RETURN(g_input_backend);
1113 close(g_input_backend->main_to_input_thread_pipe_fd[0]);
1114 close(g_input_backend->main_to_input_thread_pipe_fd[1]);
1117 EINTERN void e_input_thread_input_backend_set(E_Input_Backend *input)
1119 g_input_backend = input;
1121 if (g_input_backend->main_to_input_thread_pipe_fd[0] == 0)
1123 g_input_backend->main_to_input_thread_pipe_fd[0] = main_to_input_thread_pipe_fd[0];
1124 g_input_backend->main_to_input_thread_pipe_fd[1] = main_to_input_thread_pipe_fd[1];
1129 e_input_thread_safe_call(E_Input_Thread_Safe_Call_Cb cb, void *data, size_t data_length)
1131 E_Input_Thread_Request_Data order;
1132 order.safe_call_cb = cb;
1133 order.data_length = data_length;
1136 if (!g_input_backend)
1138 ERR("Not yet initialized\n");
1142 if (write(g_input_backend->main_to_input_thread_pipe_fd[1], &order, sizeof(E_Input_Thread_Request_Data)) == -1)
1143 ERR("error when writing header in pipe\n");
1145 if (write(g_input_backend->main_to_input_thread_pipe_fd[1], data, data_length) == -1)
1146 ERR("error when writing data in pipe\n");