2 #include "e_devicemgr_intern.h"
3 #include "e_devicemgr_private.h"
4 #include "e_input_intern.h"
8 static Ecore_Device_Class
9 _e_devicemgr_inputgen_class_to_ecore_device_class(unsigned int clas)
13 case TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE:
14 return ECORE_DEVICE_CLASS_MOUSE;
15 case TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD:
16 return ECORE_DEVICE_CLASS_KEYBOARD;
17 case TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN:
18 return ECORE_DEVICE_CLASS_TOUCH;
20 return ECORE_DEVICE_CLASS_NONE;
25 _e_devicemgr_inputgen_list_get(Ecore_Device_Class clas)
29 case ECORE_DEVICE_CLASS_KEYBOARD:
30 return &e_devicemgr->inputgen.kbd_list;
32 case ECORE_DEVICE_CLASS_MOUSE:
33 return &e_devicemgr->inputgen.ptr_list;
35 case ECORE_DEVICE_CLASS_TOUCH:
36 return &e_devicemgr->inputgen.touch_list;
44 _e_devicemgr_inputgen_name_get(struct wl_resource *resource)
47 E_Devicemgr_Inputgen_Resource_Data *rdata;
49 EINA_LIST_FOREACH(e_devicemgr->inputgen.resource_list, l, rdata)
51 if (rdata->resource == resource) return rdata->name;
58 _e_devicemgr_inputgen_device_check(char *name, Ecore_Device_Class clas)
60 Eina_List **dev_list, *l;
61 E_Devicemgr_Inputgen_Device_Data *ddata;
63 if (!name) return EINA_FALSE;
64 dev_list = _e_devicemgr_inputgen_list_get(clas);
65 EINA_SAFETY_ON_NULL_RETURN_VAL(dev_list, EINA_FALSE);
67 EINA_LIST_FOREACH(*dev_list, l, ddata)
69 if (!strncmp(ddata->name, name, UINPUT_MAX_NAME_SIZE))
77 _e_devicemgr_inputgen_key_event_free(void *data EINA_UNUSED, void *ev)
79 Ecore_Event_Key *e = ev;
81 eina_stringshare_del(e->keyname);
82 eina_stringshare_del(e->key);
83 eina_stringshare_del(e->compose);
85 if (e_input_thread_mode_get())
87 if (e->dev) g_object_unref(e->dev);
91 if (e->dev) ecore_device_unref(e->dev);
94 if (e->data) E_FREE(e->data);
100 e_devicemgr_inputgen_key_event_add(const char *key, Eina_Bool pressed, char *identifier)
103 unsigned int keycode;
104 E_Keyrouter_Event_Data *key_data;
105 E_Device *dev = NULL;
107 EINA_SAFETY_ON_NULL_RETURN_VAL(key, TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER);
109 e = E_NEW(Ecore_Event_Key, 1);
110 EINA_SAFETY_ON_NULL_RETURN_VAL(e, TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES);
112 keycode = e_comp_wl_input_keymap_keyname_to_keycode(key);
113 if (keycode <= 0) goto finish;
115 e->keyname = eina_stringshare_add(key);
116 e->key = eina_stringshare_add(key);
117 e->compose = eina_stringshare_add(key);
118 e->string = e->compose;
120 e->window = e_comp->ee_win;
121 e->event_window = e_comp->ee_win;
122 e->root_window = e_comp->ee_win;
123 e->timestamp = e_util_timestamp_get();
125 e->keycode = keycode;
126 key_data = E_NEW(E_Keyrouter_Event_Data, 1);
127 EINA_SAFETY_ON_NULL_GOTO(key_data, finish);
132 if (e_input_thread_mode_get())
134 dev = e_input_evdev_get_e_device(identifier, ECORE_DEVICE_CLASS_KEYBOARD);
135 e->dev = (Eo *)g_object_ref(dev);
139 e->dev = ecore_device_ref(e_input_evdev_get_ecore_device(identifier, ECORE_DEVICE_CLASS_KEYBOARD));
142 DMDBG("Generate key event: key: %s, keycode: %d, iden: %s\n", e->key, e->keycode, identifier);
144 if (e_input_thread_mode_get())
146 E_Input_Event_Source *input_event_source = e_input_event_source_get();
147 e_input_event_add(input_event_source, pressed ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_devicemgr_inputgen_key_event_free, NULL);
151 ecore_event_add(pressed ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_devicemgr_inputgen_key_event_free, NULL);
154 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
158 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER;
162 _e_devicemgr_inputgen_mouse_button_event_free(void *data EINA_UNUSED, void *ev)
164 Ecore_Event_Mouse_Button *e = ev;
166 if (e->dev) ecore_device_unref(e->dev);
172 _e_devicemgr_inputgen_mouse_button_event(Eina_Bool state, int x, int y, int buttons, char *identifier)
174 Ecore_Event_Mouse_Button *e;
176 e = calloc(1, sizeof(Ecore_Event_Mouse_Button));
177 EINA_SAFETY_ON_NULL_RETURN_VAL(e, TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES);
179 e->window = e_comp->ee_win;
180 e->event_window = e_comp->ee_win;
181 e->root_window = e_comp->ee_win;
182 e->timestamp = e_util_timestamp_get();
192 e->multi.radius_x = 1;
193 e->multi.radius_y = 1;
194 e->multi.pressure = 1.0;
195 e->multi.angle = 0.0;
199 e->multi.root.x = e->x;
200 e->multi.root.y = e->y;
202 ecore_thread_main_loop_begin();
203 e->dev = ecore_device_ref(e_input_evdev_get_ecore_device(identifier, ECORE_DEVICE_CLASS_MOUSE));
204 e->buttons = buttons;
206 DMDBG("Generate mouse button event: button: %d (state: %d)\n", buttons, state);
209 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, e, _e_devicemgr_inputgen_mouse_button_event_free, NULL);
211 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, e, _e_devicemgr_inputgen_mouse_button_event_free, NULL);
213 ecore_thread_main_loop_end();
215 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
219 _e_devicemgr_inputgen_mouse_move_event_free(void *data EINA_UNUSED, void *ev)
221 Ecore_Event_Mouse_Move *e = ev;
223 if (e->dev) ecore_device_unref(e->dev);
229 _e_devicemgr_inputgen_mouse_move_event(int x, int y, char *identifier)
231 Ecore_Event_Mouse_Move *e;
233 e = calloc(1, sizeof(Ecore_Event_Mouse_Move));
234 if (!e) return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES;
236 e->window = e_comp->ee_win;
237 e->event_window = e_comp->ee_win;
238 e->root_window = e_comp->ee_win;
239 e->timestamp = e_util_timestamp_get();
249 e->multi.radius_x = 1;
250 e->multi.radius_y = 1;
251 e->multi.pressure = 1.0;
252 e->multi.angle = 0.0;
256 e->multi.root.x = e->x;
257 e->multi.root.y = e->y;
259 ecore_thread_main_loop_begin();
260 e->dev = ecore_device_ref(e_input_evdev_get_ecore_device(identifier, ECORE_DEVICE_CLASS_MOUSE));
262 DMDBG("Generate mouse move event: (%d, %d)\n", e->x, e->y);
264 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, e, _e_devicemgr_inputgen_mouse_move_event_free, NULL);
265 ecore_thread_main_loop_end();
267 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
271 _e_devicemgr_inputgen_mouse_wheel_event_free(void *data EINA_UNUSED, void *ev)
273 Ecore_Event_Mouse_Wheel *e = ev;
275 if (e->dev) ecore_device_unref(e->dev);
281 _e_devicemgr_inputgen_mouse_wheel_event(unsigned int type, int value, E_Devicemgr_Inputgen_Device_Data *device)
283 Ecore_Event_Mouse_Wheel *e;
284 Ecore_Device_Class clas = ECORE_DEVICE_CLASS_NONE;
286 e = calloc(1, sizeof(Ecore_Event_Mouse_Wheel));
287 if (!e) return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES;
289 e->window = e_comp->ee_win;
290 e->event_window = e_comp->ee_win;
291 e->root_window = e_comp->ee_win;
292 e->timestamp = e_util_timestamp_get();
295 /* FIXME: set current coords */
301 if (type == TIZEN_INPUT_DEVICE_MANAGER_AXIS_TYPE_WHEEL)
307 ecore_thread_main_loop_begin();
311 if (!e_devicemgr_detent_is_detent(device->name))
313 e->dev = ecore_device_ref(e_input_evdev_get_ecore_device(device->identifier, clas));
316 DMDBG("Generate mouse wheel event: direction: %s, value: %d\n", e->direction?"HWHEEL":"WHEEL", e->z);
318 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, e, _e_devicemgr_inputgen_mouse_wheel_event_free, NULL);
320 ecore_thread_main_loop_end();
322 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
326 _e_devicemgr_inputgen_touch_axis_store(E_Devicemgr_Inputgen_Device_Data *device, unsigned int type, double value)
328 EINA_SAFETY_ON_NULL_RETURN(device);
332 case TIZEN_INPUT_DEVICE_MANAGER_AXIS_TYPE_RADIUS_X:
333 device->touch.axis_tmp.radius_x = value;
335 case TIZEN_INPUT_DEVICE_MANAGER_AXIS_TYPE_RADIUS_Y:
336 device->touch.axis_tmp.radius_y = value;
338 case TIZEN_INPUT_DEVICE_MANAGER_AXIS_TYPE_PRESSURE:
339 device->touch.axis_tmp.pressure = value;
341 case TIZEN_INPUT_DEVICE_MANAGER_AXIS_TYPE_ANGLE:
342 device->touch.axis_tmp.angle = value;
344 case TIZEN_INPUT_DEVICE_MANAGER_AXIS_TYPE_PALM:
345 device->touch.axis_tmp.palm = value;
348 DMWRN("Invalid type (%d).\n", type);
354 _e_devicemgr_inputgen_touch_axis_update(E_Devicemgr_Inputgen_Device_Data *device, int idx)
356 EINA_SAFETY_ON_NULL_RETURN(device);
358 if (device->touch.axis_tmp.radius_x != -1.0)
359 device->touch.axis[idx].radius_x = device->touch.axis_tmp.radius_x;
361 if (device->touch.axis_tmp.radius_y != -1.0)
362 device->touch.axis[idx].radius_y = device->touch.axis_tmp.radius_y;
364 if (device->touch.axis_tmp.pressure != -1.0)
365 device->touch.axis[idx].pressure = device->touch.axis_tmp.pressure;
367 if (device->touch.axis_tmp.angle != -1.0)
368 device->touch.axis[idx].angle = device->touch.axis_tmp.angle;
370 if (device->touch.axis_tmp.palm != -1.0)
371 device->touch.axis[idx].palm = device->touch.axis_tmp.palm;
375 _e_devicemgr_inputgen_touch_axis_cleanup(E_Devicemgr_Inputgen_Device_Data *device, int idx)
377 EINA_SAFETY_ON_NULL_RETURN(device);
381 device->touch.axis_tmp.radius_x = -1.0;
382 device->touch.axis_tmp.radius_y = -1.0;
383 device->touch.axis_tmp.pressure = -1.0;
384 device->touch.axis_tmp.angle = -1.0;
385 device->touch.axis_tmp.palm = -1.0;
389 device->touch.axis[idx].radius_x = 1.0;
390 device->touch.axis[idx].radius_y = 1.0;
391 device->touch.axis[idx].pressure = 1.0;
392 device->touch.axis[idx].angle = 0.0;
393 device->touch.axis[idx].palm = 0.0;
398 _e_devicemgr_inputgen_touch_event(uint32_t type, uint32_t x, uint32_t y, uint32_t finger, E_Devicemgr_Inputgen_Device_Data *device)
400 Ecore_Event_Mouse_Button *e;
402 e = calloc(1, sizeof(Ecore_Event_Mouse_Button));
403 EINA_SAFETY_ON_NULL_RETURN_VAL(e, TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES);
405 e->window = e_comp->ee_win;
406 e->event_window = e_comp->ee_win;
407 e->root_window = e_comp->ee_win;
408 e->timestamp = e_util_timestamp_get();
416 if (type == TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN)
417 _e_devicemgr_inputgen_touch_axis_update(device, finger);
419 _e_devicemgr_inputgen_touch_axis_cleanup(device, finger);
420 _e_devicemgr_inputgen_touch_axis_cleanup(device, -1);
422 e->multi.device = finger;
425 e->multi.radius = device->touch.axis[finger].radius_x;
426 e->multi.radius_x = device->touch.axis[finger].radius_x;
427 e->multi.radius_y = device->touch.axis[finger].radius_y;
428 e->multi.pressure = device->touch.axis[finger].pressure;
429 e->multi.angle = device->touch.axis[finger].angle;
433 e->multi.radius = 1.0;
434 e->multi.radius_x = 1.0;
435 e->multi.radius_y = 1.0;
436 e->multi.pressure = 1.0;
437 e->multi.angle = 0.0;
442 e->multi.root.x = e->x;
443 e->multi.root.y = e->y;
445 ecore_thread_main_loop_begin();
446 e->dev = ecore_device_ref(e_input_evdev_get_ecore_device(device?device->identifier:NULL, ECORE_DEVICE_CLASS_TOUCH));
449 DMDBG("Generate touch event: device: %d (%d, %d)\n", e->multi.device, e->x, e->y);
451 if (type == TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN)
452 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, e, _e_devicemgr_inputgen_mouse_button_event_free, NULL);
454 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, e, _e_devicemgr_inputgen_mouse_button_event_free, NULL);
456 ecore_thread_main_loop_end();
458 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
462 _e_devicemgr_inputgen_touch_update_event(uint32_t x, uint32_t y, uint32_t finger, E_Devicemgr_Inputgen_Device_Data *device)
464 Ecore_Event_Mouse_Move *e;
466 e = calloc(1, sizeof(Ecore_Event_Mouse_Move));
467 EINA_SAFETY_ON_NULL_RETURN_VAL(e, TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES);
469 e->window = e_comp->ee_win;
470 e->event_window = e_comp->ee_win;
471 e->root_window = e_comp->ee_win;
472 e->timestamp = e_util_timestamp_get();
480 _e_devicemgr_inputgen_touch_axis_update(device, finger);
481 _e_devicemgr_inputgen_touch_axis_cleanup(device, -1);
483 e->multi.device = finger;
486 e->multi.radius = device->touch.axis[finger].radius_x;
487 e->multi.radius_x = device->touch.axis[finger].radius_x;
488 e->multi.radius_y = device->touch.axis[finger].radius_y;
489 e->multi.pressure = device->touch.axis[finger].pressure;
490 e->multi.angle = device->touch.axis[finger].angle;
494 e->multi.radius = 1.0;
495 e->multi.radius_x = 1.0;
496 e->multi.radius_y = 1.0;
497 e->multi.pressure = 1.0;
498 e->multi.angle = 0.0;
503 e->multi.root.x = e->x;
504 e->multi.root.y = e->y;
506 ecore_thread_main_loop_begin();
508 e->dev = ecore_device_ref(e_input_evdev_get_ecore_device(device?device->identifier:NULL, ECORE_DEVICE_CLASS_TOUCH));
510 DMDBG("Generate touch move event: device: %d (%d, %d)\n", e->multi.device, e->x, e->y);
512 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, e, _e_devicemgr_inputgen_mouse_move_event_free, NULL);
513 ecore_thread_main_loop_end();
515 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
519 _e_devicemgr_inputgen_remove_device(E_Devicemgr_Inputgen_Device_Data *device)
522 Eina_List *l, *l_next;
523 Eina_Stringshare *str_data;
527 DMWRN("There are no devices created for input generation.\n");
531 switch (device->clas)
533 case ECORE_DEVICE_CLASS_TOUCH:
534 while (device->touch.pressed)
536 if (device->touch.pressed & (1 << i))
538 ret = _e_devicemgr_inputgen_touch_event(
539 TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END,
540 device->touch.coords[i].x,
541 device->touch.coords[i].y,
543 if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE)
544 DMWRN("Failed to generate touch up event: %d\n", ret);
545 device->touch.pressed &= ~(1 << i);
548 if (i >= e_input_touch_max_count_get()) break;
550 if (device->touch.coords)
552 free(device->touch.coords);
553 device->touch.coords = NULL;
555 if (device->touch.axis)
557 free(device->touch.axis);
558 device->touch.axis = NULL;
561 case ECORE_DEVICE_CLASS_MOUSE:
562 while (device->mouse.pressed)
564 if (device->mouse.pressed & (1 << i))
566 ret = _e_devicemgr_inputgen_mouse_button_event(
568 device->mouse.coords.x,
569 device->mouse.coords.y,
570 i + 1, device->identifier);
571 if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE)
572 DMWRN("Failed to generate mouse button up event: %d\n", ret);
573 device->mouse.pressed &= ~(1 << i);
576 if (i >= INPUTGEN_MAX_BTN) break;
579 case ECORE_DEVICE_CLASS_KEYBOARD:
580 EINA_LIST_FOREACH_SAFE(device->key.pressed, l, l_next, str_data)
582 ret = e_devicemgr_inputgen_key_event_add(str_data, EINA_FALSE, device->identifier);
583 if (ret != TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE)
584 DMWRN("Failed to generate key up event: %d\n", ret);
585 eina_stringshare_del(str_data);
586 device->key.pressed = eina_list_remove_list(device->key.pressed, l);
593 if (device->uinp_fd >= 0)
595 e_devicemgr_destroy_virtual_device(device->uinp_fd);
596 device->uinp_fd = -1;
598 E_FREE(device->identifier);
602 _e_devicemgr_inputgen_client_device_remove(struct wl_client *client, Ecore_Device_Class clas)
604 Eina_List **dev_list, *l, *l_next, *ll, *ll_next;
605 E_Devicemgr_Inputgen_Device_Data *ddata;
606 E_Devicemgr_Inputgen_Client_Data *cdata;
608 dev_list = _e_devicemgr_inputgen_list_get(clas);
609 EINA_SAFETY_ON_NULL_RETURN(dev_list);
611 EINA_LIST_FOREACH_SAFE(*dev_list, l, l_next, ddata)
613 EINA_LIST_FOREACH_SAFE(ddata->clients, ll, ll_next, cdata)
615 if (cdata->client == client)
617 ddata->clients = eina_list_remove_list(ddata->clients, ll);
621 if (eina_list_count(ddata->clients) == 0)
623 _e_devicemgr_inputgen_remove_device(ddata);
624 *dev_list = eina_list_remove_list(*dev_list, l);
631 _e_devicemgr_inputgen_client_cb_destroy(struct wl_listener *l, void *data)
633 struct wl_client *client = (struct wl_client *)data;
634 E_Devicemgr_Inputgen_Resource_Data *rdata;
635 E_Devicemgr_Inputgen_Client_Global_Data *gdata;
636 Eina_List *list, *l_next;
638 EINA_SAFETY_ON_NULL_RETURN(l);
640 wl_list_remove(&l->link);
643 EINA_LIST_FOREACH_SAFE(e_devicemgr->watched_clients, list, l_next, gdata)
645 if (gdata->client == client)
647 e_devicemgr->watched_clients =
648 eina_list_remove_list(e_devicemgr->watched_clients, list);
655 _e_devicemgr_inputgen_client_device_remove(client, ECORE_DEVICE_CLASS_KEYBOARD);
656 _e_devicemgr_inputgen_client_device_remove(client, ECORE_DEVICE_CLASS_MOUSE);
657 _e_devicemgr_inputgen_client_device_remove(client, ECORE_DEVICE_CLASS_TOUCH);
659 EINA_LIST_FOREACH_SAFE(e_devicemgr->inputgen.resource_list, list, l_next, rdata)
661 if (wl_resource_get_client(rdata->resource) == client)
663 e_devicemgr->inputgen.resource_list =
664 eina_list_remove_list(e_devicemgr->inputgen.resource_list, list);
665 E_FREE_FUNC(rdata->sync_timer, ecore_timer_del);
672 _e_devicemgr_inputgen_client_add(struct wl_client *client, unsigned int clas)
674 struct wl_listener *destroy_listener;
675 E_Devicemgr_Inputgen_Client_Global_Data *data;
678 EINA_LIST_FOREACH(e_devicemgr->watched_clients, l, data)
680 if (data->client == client)
688 destroy_listener = E_NEW(struct wl_listener, 1);
689 EINA_SAFETY_ON_NULL_GOTO(destroy_listener, failed);
690 destroy_listener->notify = _e_devicemgr_inputgen_client_cb_destroy;
691 wl_client_add_destroy_listener(client, destroy_listener);
693 data = E_NEW(E_Devicemgr_Inputgen_Client_Global_Data, 1);
694 EINA_SAFETY_ON_NULL_GOTO(data, failed);
696 data->client = client;
699 e_devicemgr->watched_clients =
700 eina_list_append(e_devicemgr->watched_clients, data);
705 if (destroy_listener)
707 wl_list_remove(&destroy_listener->link);
708 E_FREE(destroy_listener);
713 _e_devicemgr_inputgen_client_del(struct wl_client *client, unsigned int clas)
715 E_Devicemgr_Inputgen_Client_Global_Data *data;
716 E_Devicemgr_Inputgen_Client_Data *cdata;
717 E_Devicemgr_Inputgen_Device_Data *ddata;
718 Eina_List *l, *ll, *l_next, *ll_next, **list;
719 Ecore_Device_Class eclas = ECORE_DEVICE_CLASS_NONE;
721 eclas = _e_devicemgr_inputgen_class_to_ecore_device_class(clas);
722 list = _e_devicemgr_inputgen_list_get(eclas);
723 EINA_SAFETY_ON_NULL_RETURN(list);
725 EINA_LIST_FOREACH_SAFE(*list, l, l_next, ddata)
727 EINA_LIST_FOREACH_SAFE(ddata->clients, ll, ll_next, cdata)
729 if (cdata->client == client)
734 ddata->clients = eina_list_remove_list(ddata->clients, ll);
740 if (eina_list_count(ddata->clients) == 0)
742 ddata->clients = NULL;
743 _e_devicemgr_inputgen_remove_device(ddata);
744 *list = eina_list_remove_list(*list, l);
749 EINA_LIST_FOREACH(e_devicemgr->watched_clients, l, data)
751 if (data->client == client)
758 static E_Devicemgr_Inputgen_Resource_Data *
759 _e_devicemgr_inputgen_resource_add(struct wl_resource *resource, const char *name)
761 E_Devicemgr_Inputgen_Resource_Data *rdata;
764 EINA_LIST_FOREACH(e_devicemgr->inputgen.resource_list, l, rdata)
766 if (rdata->resource == resource) return rdata;
770 rdata = E_NEW(E_Devicemgr_Inputgen_Resource_Data, 1);
771 EINA_SAFETY_ON_NULL_RETURN_VAL(rdata, NULL);
773 rdata->resource = resource;
774 strncpy(rdata->name, name, UINPUT_MAX_NAME_SIZE - 1);
776 e_devicemgr->inputgen.resource_list = eina_list_append(e_devicemgr->inputgen.resource_list, rdata);
782 _e_devicemgr_inputgen_resource_del(struct wl_resource *resource)
784 E_Devicemgr_Inputgen_Resource_Data *rdata;
785 Eina_List *l, *l_next;
787 EINA_LIST_FOREACH_SAFE(e_devicemgr->inputgen.resource_list, l, l_next, rdata)
789 if (rdata->resource == resource)
791 e_devicemgr->inputgen.resource_list =
792 eina_list_remove_list(e_devicemgr->inputgen.resource_list, l);
793 E_FREE_FUNC(rdata->sync_timer, ecore_timer_del);
800 _e_devicemgr_inputgen_hw_device_check(E_Devicemgr_Inputgen_Device_Data *device)
803 E_Devicemgr_Input_Device *dev;
804 Ecore_Device_Class clas = ECORE_DEVICE_CLASS_NONE;
806 if (!e_devicemgr_detent_is_detent(device->name))
809 g_rec_mutex_lock(&e_devicemgr->device_list_mutex);
810 EINA_LIST_FOREACH(e_devicemgr->device_list, l, dev)
812 if ((dev->clas == clas) &&
813 (e_devicemgr_strcmp(dev->name, device->name)))
815 E_FREE(device->identifier);
816 if (dev->identifier) device->identifier = strdup(dev->identifier);
817 g_rec_mutex_unlock(&e_devicemgr->device_list_mutex);
821 g_rec_mutex_unlock(&e_devicemgr->device_list_mutex);
827 _e_devicemgr_init_touch_coords_and_axis(E_Devicemgr_Inputgen_Device_Data *device)
829 int touch_max = e_input_touch_max_count_get();
831 if (device->touch.coords)
832 free(device->touch.coords);
834 if (e_config->configured_max_touch.use)
836 touch_max = e_config->configured_max_touch.count;
838 device->touch.coords = calloc(1, sizeof(E_Devicemgr_Coords)*touch_max);
839 if (!device->touch.coords)
841 DMWRN("Failed to allocate memory for coords ptr ! (finger=%d)\n", touch_max);
845 for (i = 0; i < touch_max; i++)
847 device->touch.coords[i].x = -1;
848 device->touch.coords[i].y = -1;
851 if (device->touch.axis)
852 free(device->touch.axis);
854 device->touch.axis = calloc(1, sizeof(E_Devicemgr_Inputgen_Touch_Axis)*touch_max);
855 if (!device->touch.axis)
857 DMWRN("Failed to allocate memory for axis ptr ! (finger=%d)\n", touch_max);
858 free(device->touch.coords);
866 _e_devicemgr_inputgen_create_device(Ecore_Device_Class clas, struct wl_client *client, const char *device_name)
869 Eina_List **dev_list, *l, *ll;
870 E_Devicemgr_Inputgen_Client_Data *cdata;
871 E_Devicemgr_Inputgen_Device_Data *ddata, *device = NULL;
872 Eina_Bool exist_device_flag = EINA_FALSE;
874 dev_list = _e_devicemgr_inputgen_list_get(clas);
875 EINA_SAFETY_ON_NULL_RETURN_VAL(dev_list, EINA_FALSE);
877 EINA_LIST_FOREACH(*dev_list, l, ddata)
879 if (!strncmp(ddata->name, device_name, UINPUT_MAX_NAME_SIZE))
881 EINA_LIST_FOREACH(ddata->clients, ll, cdata)
883 if (cdata->client == client)
886 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
891 exist_device_flag = EINA_TRUE;
898 device = E_NEW(E_Devicemgr_Inputgen_Device_Data, 1);
899 EINA_SAFETY_ON_NULL_RETURN_VAL(device, TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES);
900 strncpy(device->name, device_name, UINPUT_MAX_NAME_SIZE - 1);
904 cdata = E_NEW(E_Devicemgr_Inputgen_Client_Data, 1);
907 if (!exist_device_flag) E_FREE(device);
908 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES;
912 cdata->client = client;
914 device->clients = eina_list_append(device->clients, cdata);
916 if (exist_device_flag)
917 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
919 if (!_e_devicemgr_inputgen_hw_device_check(device))
921 uinp_fd = e_devicemgr_create_virtual_device(clas, device_name);
924 goto fail_create_device;
927 device->uinp_fd = uinp_fd;
928 *dev_list = eina_list_append(*dev_list, device);
930 if (!_e_devicemgr_init_touch_coords_and_axis(device))
932 DMERR("DEVMGR_TOUCH Failed to init touch coords and axis !\n");
933 goto fail_create_device;
936 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
939 EINA_LIST_FREE(device->clients, cdata)
942 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES;
946 e_devicemgr_inputgen_add(struct wl_client *client, struct wl_resource *resource, uint32_t clas, const char *name)
948 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
950 if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD)
951 ret = _e_devicemgr_inputgen_create_device(ECORE_DEVICE_CLASS_KEYBOARD, client, name);
952 if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE)
953 ret = _e_devicemgr_inputgen_create_device(ECORE_DEVICE_CLASS_MOUSE, client, name);
954 if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN)
955 ret = _e_devicemgr_inputgen_create_device(ECORE_DEVICE_CLASS_TOUCH, client, name);
957 if (ret == TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE)
959 _e_devicemgr_inputgen_client_add(client, clas);
960 _e_devicemgr_inputgen_resource_add(resource, name);
967 e_devicemgr_inputgen_device_ready_send(E_Devicemgr_Input_Device *dev)
969 E_Devicemgr_Inputgen_Resource_Data *rdata;
971 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
973 EINA_LIST_FOREACH(e_devicemgr->inputgen.resource_list, l, rdata)
975 if (e_devicemgr_strcmp(rdata->name, dev->name) == EINA_FALSE) continue;
976 if (rdata->sync_timer)
978 e_devicemgr_wl_generator_with_sync_send_event(rdata->resource, ret);
980 ecore_timer_del(rdata->sync_timer);
981 rdata->sync_timer = NULL;
987 _e_devicemgr_inputgen_sync_timer(void *data)
989 E_Devicemgr_Inputgen_Resource_Data *rdata = data;
990 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES;
992 DMERR("Init Generator with sync. timer expired!!! dev: %s", rdata->name);
994 if (!rdata || !rdata->resource) return ECORE_CALLBACK_CANCEL;
996 e_devicemgr_wl_generator_with_sync_send_event(rdata->resource, ret);
998 rdata->sync_timer = NULL;
1000 return ECORE_CALLBACK_CANCEL;
1004 e_devicemgr_inputgen_add_with_sync(struct wl_client *client, struct wl_resource *resource, uint32_t clas, const char *name)
1006 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
1007 E_Devicemgr_Inputgen_Resource_Data *rdata;
1009 if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD)
1010 ret = _e_devicemgr_inputgen_create_device(ECORE_DEVICE_CLASS_KEYBOARD, client, name);
1011 if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE)
1012 ret = _e_devicemgr_inputgen_create_device(ECORE_DEVICE_CLASS_MOUSE, client, name);
1013 if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN)
1014 ret = _e_devicemgr_inputgen_create_device(ECORE_DEVICE_CLASS_TOUCH, client, name);
1016 if (ret == TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE)
1018 _e_devicemgr_inputgen_client_add(client, clas);
1019 rdata = _e_devicemgr_inputgen_resource_add(resource, name);
1021 rdata->sync_timer = ecore_timer_add(2.0, _e_devicemgr_inputgen_sync_timer, rdata);
1028 e_devicemgr_inputgen_remove(struct wl_client *client, struct wl_resource *resource, uint32_t clas)
1030 Eina_List *l, *l_next;
1031 E_Devicemgr_Inputgen_Client_Global_Data *data;
1032 struct wl_listener *listener;
1034 if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD)
1035 _e_devicemgr_inputgen_client_del(client, TIZEN_INPUT_DEVICE_MANAGER_CLAS_KEYBOARD);
1036 if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE)
1037 _e_devicemgr_inputgen_client_del(client, TIZEN_INPUT_DEVICE_MANAGER_CLAS_MOUSE);
1038 if (clas & TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN)
1039 _e_devicemgr_inputgen_client_del(client, TIZEN_INPUT_DEVICE_MANAGER_CLAS_TOUCHSCREEN);
1041 EINA_LIST_FOREACH_SAFE(e_devicemgr->watched_clients, l, l_next, data)
1043 if (data && data->client == client && !data->clas)
1045 listener = wl_client_get_destroy_listener(client,
1046 _e_devicemgr_inputgen_client_cb_destroy);
1049 wl_list_remove(&listener->link);
1053 e_devicemgr->watched_clients =
1054 eina_list_remove_list(e_devicemgr->watched_clients, l);
1061 _e_devicemgr_inputgen_resource_del(resource);
1066 e_devicemgr_inputgen_generate_key(struct wl_client *client, struct wl_resource *resource, const char *keyname, Eina_Bool pressed)
1068 Eina_List *l, *l_next;
1069 E_Devicemgr_Inputgen_Device_Data *ddata;
1070 char *name, *identifier = NULL;
1071 Eina_Stringshare *name_data;
1074 name = _e_devicemgr_inputgen_name_get(resource);
1076 if (!_e_devicemgr_inputgen_device_check(name, ECORE_DEVICE_CLASS_KEYBOARD))
1078 DMWRN("generate is not init\n");
1079 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER;
1082 g_mutex_lock(&e_comp_wl->xkb.keymap_mutex);
1083 if (!e_comp_wl->xkb.keymap)
1085 DMWRN("keymap is not ready\n");
1086 g_mutex_unlock(&e_comp_wl->xkb.keymap_mutex);
1087 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER;
1089 g_mutex_unlock(&e_comp_wl->xkb.keymap_mutex);
1091 EINA_LIST_FOREACH(e_devicemgr->inputgen.kbd_list, l, ddata)
1093 if (!strncmp(ddata->name, name, UINPUT_MAX_NAME_SIZE))
1095 identifier = ddata->identifier;
1102 DMWRN("device is not ready\n");
1103 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER;
1110 ddata->key.pressed = eina_list_append(ddata->key.pressed, eina_stringshare_add(keyname));
1114 EINA_LIST_FOREACH_SAFE(ddata->key.pressed, l, l_next, name_data)
1116 if (e_devicemgr_strcmp(name_data, keyname))
1118 ddata->key.pressed = eina_list_remove_list(ddata->key.pressed, l);
1119 eina_stringshare_del(name_data);
1125 ret = e_devicemgr_inputgen_key_event_add(keyname, pressed, identifier);
1130 e_devicemgr_inputgen_generate_pointer(struct wl_client *client, struct wl_resource *resource, uint32_t type, uint32_t x, uint32_t y, uint32_t button)
1132 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
1135 E_Devicemgr_Inputgen_Device_Data *ddata = NULL;
1136 char *name, *identifier = NULL;
1138 if (0 >= button || button >= INPUTGEN_MAX_BTN)
1140 DMWRN("Invalid button: %d\n", button);
1141 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER;
1144 name = _e_devicemgr_inputgen_name_get(resource);
1146 if (!_e_devicemgr_inputgen_device_check(name, ECORE_DEVICE_CLASS_MOUSE))
1148 DMWRN("generate is not init\n");
1149 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER;
1152 EINA_LIST_FOREACH(e_devicemgr->inputgen.ptr_list, l, ddata)
1154 if (!strncmp(ddata->name, name, UINPUT_MAX_NAME_SIZE))
1156 identifier = ddata->identifier;
1163 DMWRN("device is not ready\n");
1164 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER;
1167 if (type == TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE)
1169 ret = _e_devicemgr_inputgen_mouse_move_event(x, y, identifier);
1172 ddata->mouse.coords.x = x;
1173 ddata->mouse.coords.y = y;
1178 state = (type == TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN) ?
1179 EINA_TRUE : EINA_FALSE;
1182 if (state) ddata->mouse.pressed |= 1 << (button - 1);
1183 else ddata->mouse.pressed &= ~(1 << (button - 1));
1184 ddata->mouse.coords.x = x;
1185 ddata->mouse.coords.y = y;
1187 ret = _e_devicemgr_inputgen_mouse_button_event(state, x, y, button, identifier);
1194 e_devicemgr_inputgen_generate_wheel(struct wl_client *client, struct wl_resource *resource, uint32_t type, int32_t value)
1196 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
1198 E_Devicemgr_Inputgen_Device_Data *ddata = NULL, *device = NULL;
1199 char *name, *identifier = NULL;
1201 name = _e_devicemgr_inputgen_name_get(resource);
1203 if (!_e_devicemgr_inputgen_device_check(name, ECORE_DEVICE_CLASS_MOUSE))
1205 DMWRN("generate is not init\n");
1206 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER;
1209 EINA_LIST_FOREACH(e_devicemgr->inputgen.ptr_list, l, ddata)
1211 if (!strncmp(ddata->name, name, UINPUT_MAX_NAME_SIZE))
1214 identifier = ddata->identifier;
1221 DMWRN("device is not ready\n");
1222 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER;
1225 ret = _e_devicemgr_inputgen_mouse_wheel_event(type, value, device);
1232 e_devicemgr_inputgen_generate_touch(struct wl_client *client, struct wl_resource *resource, uint32_t type, uint32_t x, uint32_t y, uint32_t finger)
1234 int ret = TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
1236 E_Devicemgr_Inputgen_Device_Data *ddata = NULL, *device = NULL;
1237 char *name, *identifier = NULL;
1239 name = _e_devicemgr_inputgen_name_get(resource);
1241 if (finger >= e_input_touch_max_count_get())
1243 DMWRN("Invalid fingers: %d\n", finger);
1244 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER;
1247 if (!_e_devicemgr_inputgen_device_check(name, ECORE_DEVICE_CLASS_TOUCH))
1249 DMWRN("generate is not init\n");
1250 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER;
1253 EINA_LIST_FOREACH(e_devicemgr->inputgen.touch_list, l, ddata)
1255 if (!strncmp(ddata->name, name, UINPUT_MAX_NAME_SIZE))
1258 identifier = ddata->identifier;
1265 DMWRN("device is not ready\n");
1266 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER;
1271 case TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_BEGIN:
1272 ret = _e_devicemgr_inputgen_touch_update_event(x, y, finger, device);
1273 ret = _e_devicemgr_inputgen_touch_event(type, x, y, finger, device);
1276 ddata->touch.pressed |= 1 << finger;
1277 ddata->touch.coords[finger].x = x;
1278 ddata->touch.coords[finger].y = y;
1281 case TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_END:
1282 ret = _e_devicemgr_inputgen_touch_event(type, x, y, finger, device);
1285 ddata->touch.pressed &= ~(1 << finger);
1286 ddata->touch.coords[finger].x = -1;
1287 ddata->touch.coords[finger].y = -1;
1290 case TIZEN_INPUT_DEVICE_MANAGER_POINTER_EVENT_TYPE_UPDATE:
1291 ret = _e_devicemgr_inputgen_touch_update_event(x, y, finger, device);
1294 ddata->touch.coords[finger].x = x;
1295 ddata->touch.coords[finger].y = y;
1304 e_devicemgr_inputgen_touch_axis_store(struct wl_client *client, struct wl_resource *resource, uint32_t type, double value)
1307 E_Devicemgr_Inputgen_Device_Data *ddata = NULL, *device = NULL;
1310 name = _e_devicemgr_inputgen_name_get(resource);
1312 if (!_e_devicemgr_inputgen_device_check(name, ECORE_DEVICE_CLASS_TOUCH))
1314 DMWRN("generate is not init\n");
1315 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_INVALID_PARAMETER;
1318 EINA_LIST_FOREACH(e_devicemgr->inputgen.touch_list, l, ddata)
1320 if (!strncmp(ddata->name, name, UINPUT_MAX_NAME_SIZE))
1326 _e_devicemgr_inputgen_touch_axis_store(device, type, value);
1328 return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
1332 e_devicemgr_inputgen_get_device_info(E_Devicemgr_Input_Device *dev)
1334 E_Devicemgr_Inputgen_Device_Data *ddata;
1335 Eina_List **dev_list, *l;
1337 if (dev->clas == ECORE_DEVICE_CLASS_NONE ||
1338 dev->clas == ECORE_DEVICE_CLASS_SEAT)
1341 dev_list = _e_devicemgr_inputgen_list_get(dev->clas);
1342 EINA_SAFETY_ON_NULL_RETURN(dev_list);
1344 EINA_LIST_FOREACH(*dev_list, l, ddata)
1346 if (e_devicemgr_strcmp(ddata->name, dev->name))
1348 E_FREE(ddata->identifier);
1349 if (dev->identifier) ddata->identifier = strdup(dev->identifier);
1356 #define DM_IOCTL_SET_BIT(fd, bit, val) \
1357 ret = ioctl(fd, bit, val); \
1358 if (ret) DMWRN("Failed to set %s to fd(%d) (ret: %d)\n", #val, fd, ret)
1361 e_devicemgr_create_virtual_device(Ecore_Device_Class clas, const char *name)
1365 struct uinput_user_dev uinp;
1367 memset(&uinp, 0, sizeof(uinp));
1368 strncpy(uinp.name, name, UINPUT_MAX_NAME_SIZE - 1);
1369 uinp.id.version = 4;
1370 uinp.id.bustype = BUS_VIRTUAL;
1372 uinp_fd = open("/dev/uinput", O_WRONLY | O_NDELAY);
1375 DMWRN("Failed to open /dev/uinput: (%d)\n", uinp_fd);
1376 goto fail_create_device;
1379 if (ECORE_DEVICE_CLASS_KEYBOARD == clas)
1381 /* key device setup */
1382 DM_IOCTL_SET_BIT(uinp_fd, UI_SET_EVBIT, EV_KEY);
1383 DM_IOCTL_SET_BIT(uinp_fd, UI_SET_EVBIT, EV_SYN);
1384 DM_IOCTL_SET_BIT(uinp_fd, UI_SET_EVBIT, EV_MSC);
1385 DM_IOCTL_SET_BIT(uinp_fd, UI_SET_MSCBIT, MSC_SCAN);
1386 DM_IOCTL_SET_BIT(uinp_fd, UI_SET_KEYBIT, KEY_ESC);
1388 else if (ECORE_DEVICE_CLASS_MOUSE == clas)
1390 /* mouse device setup */
1391 DM_IOCTL_SET_BIT(uinp_fd, UI_SET_EVBIT, EV_KEY);
1392 DM_IOCTL_SET_BIT(uinp_fd, UI_SET_EVBIT, EV_SYN);
1393 DM_IOCTL_SET_BIT(uinp_fd, UI_SET_EVBIT, EV_MSC);
1394 DM_IOCTL_SET_BIT(uinp_fd, UI_SET_EVBIT, EV_REL);
1395 DM_IOCTL_SET_BIT(uinp_fd, UI_SET_MSCBIT, MSC_SCAN);
1396 DM_IOCTL_SET_BIT(uinp_fd, UI_SET_KEYBIT, BTN_LEFT);
1397 DM_IOCTL_SET_BIT(uinp_fd, UI_SET_RELBIT, BTN_RIGHT);
1398 DM_IOCTL_SET_BIT(uinp_fd, UI_SET_RELBIT, BTN_MIDDLE);
1399 DM_IOCTL_SET_BIT(uinp_fd, UI_SET_RELBIT, REL_X);
1400 DM_IOCTL_SET_BIT(uinp_fd, UI_SET_RELBIT, REL_Y);
1401 DM_IOCTL_SET_BIT(uinp_fd, UI_SET_RELBIT, REL_WHEEL);
1402 DM_IOCTL_SET_BIT(uinp_fd, UI_SET_RELBIT, REL_HWHEEL);
1404 else if (ECORE_DEVICE_CLASS_TOUCH == clas)
1406 /* touch device setup */
1407 DM_IOCTL_SET_BIT(uinp_fd, UI_SET_EVBIT, EV_KEY);
1408 DM_IOCTL_SET_BIT(uinp_fd, UI_SET_EVBIT, EV_SYN);
1409 DM_IOCTL_SET_BIT(uinp_fd, UI_SET_EVBIT, EV_MSC);
1410 DM_IOCTL_SET_BIT(uinp_fd, UI_SET_EVBIT, EV_ABS);
1412 DM_IOCTL_SET_BIT(uinp_fd, UI_SET_KEYBIT, BTN_TOUCH);
1413 DM_IOCTL_SET_BIT(uinp_fd, UI_SET_ABSBIT, ABS_X);
1414 DM_IOCTL_SET_BIT(uinp_fd, UI_SET_ABSBIT, ABS_Y);
1415 DM_IOCTL_SET_BIT(uinp_fd, UI_SET_ABSBIT, ABS_MT_SLOT);
1416 DM_IOCTL_SET_BIT(uinp_fd, UI_SET_ABSBIT, ABS_MT_TOUCH_MAJOR);
1417 DM_IOCTL_SET_BIT(uinp_fd, UI_SET_ABSBIT, ABS_MT_TOUCH_MINOR);
1418 DM_IOCTL_SET_BIT(uinp_fd, UI_SET_ABSBIT, ABS_MT_WIDTH_MAJOR);
1419 DM_IOCTL_SET_BIT(uinp_fd, UI_SET_ABSBIT, ABS_MT_POSITION_X);
1420 DM_IOCTL_SET_BIT(uinp_fd, UI_SET_ABSBIT, ABS_MT_POSITION_Y);
1421 DM_IOCTL_SET_BIT(uinp_fd, UI_SET_ABSBIT, ABS_MT_TRACKING_ID);
1422 DM_IOCTL_SET_BIT(uinp_fd, UI_SET_MSCBIT, MSC_SCAN);
1424 uinp.absmin[ABS_X] = 0;
1425 uinp.absmax[ABS_X] = 1000;
1426 uinp.absmin[ABS_Y] = 0;
1427 uinp.absmax[ABS_Y] = 1000;
1428 uinp.absmin[ABS_MT_SLOT] = 0;
1429 if (e_config->configured_max_touch.use)
1430 uinp.absmax[ABS_MT_SLOT] = e_config->configured_max_touch.count - 1;
1432 uinp.absmax[ABS_MT_SLOT] = e_input_touch_max_count_get() - 1;
1433 uinp.absmin[ABS_MT_TOUCH_MAJOR] = 0;
1434 uinp.absmax[ABS_MT_TOUCH_MAJOR] = 255;
1435 uinp.absmin[ABS_MT_TOUCH_MINOR] = 0;
1436 uinp.absmax[ABS_MT_TOUCH_MINOR] = 255;
1437 uinp.absmin[ABS_MT_WIDTH_MAJOR] = 0;
1438 uinp.absmax[ABS_MT_WIDTH_MAJOR] = 255;
1439 uinp.absmin[ABS_MT_POSITION_X] = 0;
1440 uinp.absmax[ABS_MT_POSITION_X] = 1000;
1441 uinp.absmin[ABS_MT_POSITION_Y] = 0;
1442 uinp.absmax[ABS_MT_POSITION_Y] = 1000;
1443 uinp.absmin[ABS_MT_TRACKING_ID] = 0;
1444 uinp.absmax[ABS_MT_TRACKING_ID] = 65535;
1445 uinp.absmin[ABS_MT_ORIENTATION] = 0;
1446 uinp.absmax[ABS_MT_ORIENTATION] = 2;
1449 goto fail_create_device;
1451 ret = write(uinp_fd, &uinp, sizeof(struct uinput_user_dev));
1455 DMWRN("Failed to write to uinput fd ! (fd:%d, type:%d, name:%s)\n", uinp_fd, clas, name);
1456 goto fail_create_device;
1459 if (ioctl(uinp_fd, UI_DEV_CREATE))
1461 DMWRN("Failed to create a virtual device ! (type:%d, name:%s)\n", clas, name);
1462 goto fail_create_device;
1476 e_devicemgr_destroy_virtual_device(int uinp_fd)
1479 ret = ioctl(uinp_fd, UI_DEV_DESTROY, NULL);
1480 if (ret) DMWRN("Failed destroy fd: %d (ret: %d)\n", uinp_fd, ret);