2 #include "e_input_private.h"
5 _seat_create(E_Input_Backend *input, const char *seat)
10 Ecore_Evas *ee = NULL;
11 Evas_Device *evas_dev = NULL;
16 ee = e_input_ecore_evas_get(ei);
19 evs = ecore_evas_get(ee);
20 if (!evs) return NULL;
22 /* create an evas device of a seat */
23 evas_dev = evas_device_add_full(evs, seat, "Enlightenment seat", NULL, NULL,
24 EVAS_DEVICE_CLASS_SEAT, EVAS_DEVICE_SUBCLASS_NONE);
27 ERR("Failed to create an evas device for a seat !\n");
31 /* try to allocate space for new seat */
32 if (!(s = calloc(1, sizeof(E_Input_Seat))))
34 evas_device_del(evas_dev);
39 s->name = eina_stringshare_add(seat);
40 s->evas_dev = evas_dev;
42 /* add this new seat to list */
43 input->dev->seats = eina_list_append(input->dev->seats, s);
45 ecore_event_add(E_INPUT_EVENT_SEAT_ADD, NULL, NULL, NULL);
51 _e_input_event_input_device_add_free(void *data EINA_UNUSED, void *ev)
53 E_Input_Event_Input_Device_Add *e;
56 eina_stringshare_del(e->name);
57 eina_stringshare_del(e->sysname);
58 eina_stringshare_del(e->seatname);
59 eina_stringshare_del(e->identifier);
65 _e_input_event_input_device_del_free(void *data EINA_UNUSED, void *ev)
67 E_Input_Event_Input_Device_Del *e;
70 eina_stringshare_del(e->name);
71 eina_stringshare_del(e->sysname);
72 eina_stringshare_del(e->seatname);
73 eina_stringshare_del(e->identifier);
79 _seat_get(E_Input_Backend *input, const char *seat)
84 /* search for this name in existing seats */
85 EINA_LIST_FOREACH(input->dev->seats, l, s)
86 if (!strcmp(s->name, seat))
89 return _seat_create(input, seat);
92 static Evas_Device_Class
93 _e_input_seat_cap_to_evas_device_class(unsigned int cap)
97 case E_INPUT_SEAT_POINTER:
98 return EVAS_DEVICE_CLASS_MOUSE;
99 case E_INPUT_SEAT_KEYBOARD:
100 return EVAS_DEVICE_CLASS_KEYBOARD;
101 case E_INPUT_SEAT_TOUCH:
102 return EVAS_DEVICE_CLASS_TOUCH;
104 return EVAS_DEVICE_CLASS_NONE;
106 return EVAS_DEVICE_CLASS_NONE;
110 _e_input_add_evas_device(E_Input_Evdev *edev, Evas_Device_Class clas)
112 const Eina_List *dev_list = NULL;
114 Evas_Device *dev = NULL;
115 const char *identifier;
117 Ecore_Evas *ee = NULL;
121 if (!edev || !edev->path) return EINA_FALSE;
123 dev_list = evas_device_list(e_comp->evas, NULL);
126 EINA_LIST_FOREACH(dev_list, l, dev)
129 identifier = evas_device_description_get(dev);
130 if (!identifier) continue;
131 if ((evas_device_class_get(dev) == clas) && (!strcmp(identifier, edev->path)))
137 if (!ei) return EINA_FALSE;
139 ee = e_input_ecore_evas_get(ei);
140 if (!ee) return EINA_FALSE;
142 evs = ecore_evas_get(ee);
143 if (!evs) return EINA_FALSE;
145 dev = evas_device_add_full(evs,libinput_device_get_name(edev->device),
146 edev->path, edev->seat->evas_dev , NULL, clas, EVAS_DEVICE_SUBCLASS_NONE);
149 edev->evas_dev = NULL;
153 edev->evas_dev = dev;
159 _e_input_remove_evas_device(E_Input_Evdev *edev, Evas_Device_Class clas)
161 const Eina_List *dev_list = NULL;
163 Evas_Device *dev = NULL;
164 const char *identifier;
166 if (!edev->path) return EINA_FALSE;
168 dev_list = evas_device_list(e_comp->evas, NULL);
169 if (!dev_list) return EINA_FALSE;
170 EINA_LIST_FOREACH(dev_list, l, dev)
173 identifier = evas_device_description_get(dev);
174 if (!identifier) continue;
175 if ((evas_device_class_get(dev) == clas) && (!strcmp(identifier, edev->path)))
177 evas_device_del(dev);
178 edev->evas_dev = NULL;
186 _e_input_device_add(E_Input_Evdev *edev)
188 Eina_Bool ret = EINA_FALSE;
189 Evas_Device_Class clas;
191 if (edev->caps & E_INPUT_SEAT_POINTER)
193 clas = _e_input_seat_cap_to_evas_device_class(E_INPUT_SEAT_POINTER);
194 ret = _e_input_add_evas_device(edev, clas);
196 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
198 clas = _e_input_seat_cap_to_evas_device_class(E_INPUT_SEAT_KEYBOARD);
199 ret = _e_input_add_evas_device(edev, clas);
201 if (edev->caps & E_INPUT_SEAT_TOUCH)
203 clas = _e_input_seat_cap_to_evas_device_class(E_INPUT_SEAT_TOUCH);
204 ret = _e_input_add_evas_device(edev, clas);
211 _e_input_device_remove(E_Input_Evdev *edev)
213 Eina_Bool ret = EINA_FALSE;
214 Evas_Device_Class clas;
216 if (edev->caps & E_INPUT_SEAT_POINTER)
218 clas = _e_input_seat_cap_to_evas_device_class(E_INPUT_SEAT_POINTER);
219 _e_input_remove_evas_device(edev, clas);
221 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
223 clas = _e_input_seat_cap_to_evas_device_class(E_INPUT_SEAT_KEYBOARD);
224 _e_input_remove_evas_device(edev, clas);
226 if (edev->caps & E_INPUT_SEAT_TOUCH)
228 clas = _e_input_seat_cap_to_evas_device_class(E_INPUT_SEAT_TOUCH);
229 _e_input_remove_evas_device(edev, clas);
234 _device_added(E_Input_Backend *input, struct libinput_device *device)
236 struct libinput_seat *libinput_seat;
237 const char *seat_name;
240 E_Input_Event_Input_Device_Add *ev;
242 libinput_seat = libinput_device_get_seat(device);
243 seat_name = libinput_seat_get_logical_name(libinput_seat);
245 /* try to get a seat */
246 if (!(seat = _seat_get(input, seat_name)))
248 ERR("Could not get matching seat: %s", seat_name);
252 /* try to create a new evdev device */
253 if (!(edev = _e_input_evdev_device_create(seat, device)))
255 ERR("Failed to create new evdev device");
259 edev->fd = (int)(intptr_t)eina_hash_find(input->dev->fd_hash, edev->path);
261 /* append this device to the seat */
262 seat->devices = eina_list_append(seat->devices, edev);
264 ev = calloc(1, sizeof(E_Input_Event_Input_Device_Add));
270 if (EINA_FALSE == _e_input_device_add(edev))
272 ERR("Failed to create evas device !\n");
276 ev->name = eina_stringshare_add(libinput_device_get_name(device));
277 ev->sysname = eina_stringshare_add(edev->path);
278 ev->seatname = eina_stringshare_add(edev->seat->name);
279 ev->caps = edev->caps;
280 ev->clas = evas_device_class_get(edev->evas_dev);
281 ev->identifier = eina_stringshare_add(edev->path);
282 ev->subclas = evas_device_subclass_get(edev->evas_dev);
284 ecore_event_add(E_INPUT_EVENT_INPUT_DEVICE_ADD,
286 _e_input_event_input_device_add_free,
291 _device_removed(E_Input_Backend *input, struct libinput_device *device)
294 E_Input_Event_Input_Device_Del *ev;
296 /* try to get the evdev structure */
297 if (!(edev = libinput_device_get_user_data(device)))
302 ev = calloc(1, sizeof(E_Input_Event_Input_Device_Del));
308 ev->name = eina_stringshare_add(libinput_device_get_name(device));
309 ev->sysname = eina_stringshare_add(edev->path);
310 ev->seatname = eina_stringshare_add(edev->seat->name);
311 ev->caps = edev->caps;
312 ev->clas = evas_device_class_get(edev->evas_dev);
313 ev->identifier = eina_stringshare_add(edev->path);
314 ev->subclas = evas_device_subclass_get(edev->evas_dev);
316 ecore_event_add(E_INPUT_EVENT_INPUT_DEVICE_DEL,
318 _e_input_event_input_device_del_free,
321 _e_input_device_remove(edev);
323 /* remove this evdev from the seat's list of devices */
324 edev->seat->devices = eina_list_remove(edev->seat->devices, edev);
326 if (input->dev->fd_hash)
327 eina_hash_del_by_key(input->dev->fd_hash, edev->path);
329 /* tell launcher to release device */
336 /* destroy this evdev */
337 _e_input_evdev_device_destroy(edev);
341 _udev_event_process(struct libinput_event *event)
343 struct libinput *libinput;
344 struct libinput_device *device;
345 E_Input_Backend *input;
346 Eina_Bool ret = EINA_TRUE;
348 libinput = libinput_event_get_context(event);
349 input = libinput_get_user_data(libinput);
350 device = libinput_event_get_device(event);
352 switch (libinput_event_get_type(event))
354 case LIBINPUT_EVENT_DEVICE_ADDED:
355 _device_added(input, device);
357 case LIBINPUT_EVENT_DEVICE_REMOVED:
358 _device_removed(input, device);
368 _input_event_process(struct libinput_event *event)
370 if (_udev_event_process(event)) return;
371 if (_e_input_evdev_event_process(event)) return;
375 _input_events_process(E_Input_Backend *input)
377 struct libinput_event *event;
379 while ((event = libinput_get_event(input->libinput)))
381 _input_event_process(event);
382 libinput_event_destroy(event);
387 _cb_input_dispatch(void *data, Ecore_Fd_Handler *hdlr EINA_UNUSED)
389 E_Input_Backend *input;
391 if (!(input = data)) return EINA_TRUE;
393 if (libinput_dispatch(input->libinput) != 0)
394 ERR("Failed to dispatch libinput events: %m");
396 /* process pending events */
397 _input_events_process(input);
403 e_input_enable_input(E_Input_Backend *input)
405 EINA_SAFETY_ON_NULL_RETURN_VAL(input, EINA_FALSE);
406 EINA_SAFETY_ON_NULL_RETURN_VAL(input->libinput, EINA_FALSE);
408 input->fd = libinput_get_fd(input->libinput);
413 ecore_main_fd_handler_add(input->fd, ECORE_FD_READ,
414 _cb_input_dispatch, input, NULL, NULL);
417 if (input->suspended)
419 if (libinput_resume(input->libinput) != 0)
422 input->suspended = EINA_FALSE;
424 /* process pending events */
425 _input_events_process(input);
428 input->enabled = EINA_TRUE;
429 input->suspended = EINA_FALSE;
434 input->enabled = EINA_FALSE;
436 ecore_main_fd_handler_del(input->hdlr);
443 e_input_disable_input(E_Input_Backend *input)
445 EINA_SAFETY_ON_NULL_RETURN(input);
446 EINA_SAFETY_ON_TRUE_RETURN(input->suspended);
448 /* suspend this input */
449 libinput_suspend(input->libinput);
451 /* process pending events */
452 _input_events_process(input);
454 input->suspended = EINA_TRUE;
458 e_input_seat_evdev_list_get(E_Input_Seat *seat)
460 EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
461 return seat->devices;