2 #include "e_input_private.h"
3 #include <Ecore_Input_Evas.h>
5 int _e_input_init_count;
6 int _e_input_log_dom = -1;
8 EINTERN int E_INPUT_EVENT_SEAT_ADD = -1;
9 EINTERN int E_EVENT_INPUT_ENABLED = -1;
10 EINTERN int E_EVENT_INPUT_DISABLED = -1;
12 E_API E_Input *e_input = NULL;
15 _e_input_cb_screen_change(void *data EINA_UNUSED, int type EINA_UNUSED, void *event EINA_UNUSED)
19 E_Input_Device *dev_data;
21 devices = (Eina_List *)e_input_devices_get();
23 EINA_LIST_FOREACH(devices, l, dev_data)
25 e_input_device_output_changed(dev_data);
27 return ECORE_CALLBACK_PASS_ON;
31 e_input_base_dir_get(void)
33 return e_input->input_base_dir;
37 e_input_thread_enabled_get(void)
39 return e_input->use_thread;
43 e_input_init(Ecore_Evas *ee)
46 unsigned int seat_caps = 0;
50 Eina_Bool use_udev_backend = EINA_FALSE;
51 Eina_Bool use_path_backend = EINA_FALSE;
52 Eina_Bool skip_udev_enumeration = EINA_FALSE;
54 EINA_SAFETY_ON_NULL_RETURN_VAL(ee, _e_input_init_count);
56 TRACE_INPUT_BEGIN(e_input_init);
58 if (++_e_input_init_count != 1) return _e_input_init_count;
59 if (!ecore_event_evas_init()) goto ecore_event_evas_err;
60 if (!eeze_init()) goto eeze_err;
62 _e_input_log_dom = eina_log_domain_register("e_input", EINA_COLOR_GREEN);
63 if (!_e_input_log_dom)
65 EINA_LOG_ERR("Could not create logging domain for E_Input");
69 E_INPUT_EVENT_SEAT_ADD = ecore_event_type_new();
70 E_EVENT_INPUT_ENABLED = ecore_event_type_new();
71 E_EVENT_INPUT_DISABLED = ecore_event_type_new();
73 ecore_event_add(E_EVENT_INPUT_ENABLED, NULL, NULL, NULL);
75 ecore_evas_input_event_register_with_multi2(ee);
79 e_input = (E_Input *)calloc(1, sizeof(E_Input));
84 EINA_LOG_ERR("Failed to alloc memory for e_input\n");
88 // TODO : make this variable configurable e.g. e.cfg
89 e_input->input_base_dir = eina_stringshare_add("/dev/input");
90 e_input->use_thread = EINA_FALSE;
92 e_input->touch_device_count = 0;
93 e_input->touch_max_count = 1;//This is going to updated when a touch device is attached.
95 dev = e_input_device_open();
102 EINA_LOG_ERR("Failed to open device\n");
106 e_input->window = ecore_evas_window_get(ee);
107 e_input_device_window_set(dev, e_input->window);
109 env = e_util_env_get("E_INPUT_USE_THREAD_INIT");
113 e_input->use_thread = EINA_TRUE;
117 env = e_util_env_get("LIBINPUT_UDEV_SKIP_INITIAL_ENUMERATION");
120 skip_udev_enumeration = EINA_TRUE;
124 env = e_util_env_get("E_INPUT_USE_LIBINPUT_UDEV_BACKEND");
127 use_udev_backend = EINA_TRUE;
131 env = e_util_env_get("E_INPUT_USE_LIBINPUT_PATH_BACKEND");
134 use_path_backend = EINA_TRUE;
138 TRACE_INPUT_BEGIN(e_input_device_input_backend_create);
140 /* FIXME: we need to select default backend udev or path.
141 * Input system will not be initialized, if there are no enviroment is set.
143 if ((!use_udev_backend) && (!use_path_backend))
145 EINA_LOG_INFO("This system doesn't select input backend. We use udev backend defaultly\n");
146 use_udev_backend = EINA_TRUE;
149 if ((use_udev_backend) &&
150 (!e_input_device_input_backend_create(dev, E_INPUT_LIBINPUT_BACKEND_UDEV)))
152 EINA_LOG_ERR("Failed to create e_input_device\n");
154 goto device_create_err;
157 if ((use_path_backend) && (!use_udev_backend || skip_udev_enumeration) &&
158 (!e_input_device_input_backend_create(dev, E_INPUT_LIBINPUT_BACKEND_PATH)))
160 EINA_LOG_ERR("Failed to create e_input_device\n");
162 goto device_create_err;
167 if (use_udev_backend && skip_udev_enumeration && !use_path_backend)
169 /* Enable some of keyboard, touch devices temporarily */
170 /* FIXME : get seat caps from e_input configuration or env */
171 seat_caps = E_INPUT_SEAT_KEYBOARD | E_INPUT_SEAT_TOUCH;
172 e_comp_wl_input_seat_caps_set(seat_caps);
175 E_LIST_HANDLER_APPEND(e_input->handlers, E_EVENT_SCREEN_CHANGE, _e_input_cb_screen_change, NULL);
179 return _e_input_init_count;
182 e_input_device_close(dev);
185 if (e_input && e_input->input_base_dir)
187 eina_stringshare_del(e_input->input_base_dir);
188 e_input->input_base_dir = NULL;
194 ecore_event_evas_shutdown();
196 ecore_event_evas_err:
200 return --_e_input_init_count;
204 e_input_shutdown(void)
206 Ecore_Event_Handler *h = NULL;
208 if (_e_input_init_count < 1) return 0;
209 if (--_e_input_init_count != 0) return _e_input_init_count;
211 ecore_event_add(E_EVENT_INPUT_DISABLED, NULL, NULL, NULL);
213 E_INPUT_EVENT_SEAT_ADD = -1;
214 E_EVENT_INPUT_ENABLED = -1;
215 E_EVENT_INPUT_DISABLED = -1;
217 EINA_LIST_FREE(e_input->handlers, h)
218 ecore_event_handler_del(h);
220 if (e_input->input_base_dir)
221 eina_stringshare_del(e_input->input_base_dir);
222 e_input_device_close(e_input->dev);
225 ecore_event_evas_shutdown();
227 ecore_event_shutdown();
231 return _e_input_init_count;
237 if (e_input) return e_input;
242 e_input_ecore_evas_get(E_Input *ei)
244 if (ei) return ei->ee;
249 e_input_touch_max_count_get()
252 return e_input->touch_max_count;
258 e_input_touch_max_count_set(unsigned int max_count)
261 e_input->touch_max_count = max_count;