2 #include "e_input_private.h"
4 #include "e_keyrouter_private.h"
5 #include "e_input_event.h"
9 static void _device_modifiers_update(E_Input_Evdev *edev);
10 static void _device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, int *w, int *h);
11 static void _device_output_assign(E_Input_Evdev *edev, E_Input_Seat_Capabilities cap);
14 _device_calibration_set(E_Input_Evdev *edev)
19 E_Comp_Config *comp_conf;
21 if (e_comp->e_comp_screen->num_outputs > 1) //multiple outputs
23 comp_conf = e_comp_config_get();
24 if (comp_conf && (comp_conf->input_output_assign_policy == 1)) //use output-assignment policy
26 _device_output_assign(edev, E_INPUT_SEAT_POINTER);
27 _device_output_assign(edev, E_INPUT_SEAT_TOUCH);
31 output = e_comp_screen_primary_output_get(e_comp->e_comp_screen);
32 e_output_size_get(output, &w, &h);
36 edev->mouse.minx = edev->mouse.miny = 0;
40 if (libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
42 edev->seat->ptr.dx = (double)(w / 2);
43 edev->seat->ptr.dy = (double)(h / 2);
44 edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
45 edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
46 edev->mouse.dx = edev->seat->ptr.dx;
47 edev->mouse.dy = edev->seat->ptr.dy;
49 if (output->config.rotation == 90 || output->config.rotation == 270)
51 temp = edev->mouse.minx;
52 edev->mouse.minx = edev->mouse.miny;
53 edev->mouse.miny = temp;
55 temp = edev->mouse.maxw;
56 edev->mouse.maxw = edev->mouse.maxh;
57 edev->mouse.maxh = temp;
63 #ifdef _F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
69 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
70 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
73 sysname = libinput_device_get_sysname(edev->device);
75 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
76 if (eina_list_count(devices) < 1) return;
78 #ifdef _F_E_INPUT_USE_WL_CALIBRATION_
80 enum libinput_config_status status;
82 EINA_LIST_FREE(devices, device)
84 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
86 (sscanf(vals, "%f %f %f %f %f %f",
87 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
94 libinput_device_config_calibration_set_matrix(edev->device, cal);
96 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
97 ERR("Failed to apply calibration");
100 eina_stringshare_del(device);
103 #endif//_F_E_INPUT_USE_WL_CALIBRATION_
104 #endif//_F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
109 _device_output_assign(E_Input_Evdev *edev, E_Input_Seat_Capabilities cap)
114 Eina_Bool need_assign_output = EINA_FALSE;
115 const char *output_name;
118 if (!(edev->caps & cap)) return;
119 if (edev->output_name) return; //already assigned
120 if (e_comp->e_comp_screen->num_outputs <= 1) return;
122 last_output_idx = e_comp->e_comp_screen->num_outputs - 1;
123 EINA_LIST_FOREACH(edev->seat->devices, l, ed)
125 if (!(ed->caps & cap)) continue;
126 if (ed == edev) continue;
129 need_assign_output = EINA_FALSE;
132 need_assign_output = EINA_TRUE;
134 if (need_assign_output)
136 output = e_output_find_by_index(last_output_idx);
137 if (!output || !output->info.connected) return;
138 output_name = e_output_output_id_get(output);
139 if (output_name) edev->output_name = eina_stringshare_add(output_name);
140 ELOGF("E_INPUT_EVDEV", "Device is assigned to output:%s", NULL, output_name);
145 _device_touch_count_update(E_Input_Evdev *edev)
147 unsigned int device_touch_count = 0;
148 static unsigned int _max_device_touch_count = 0;
150 E_Input *ei = e_input_get();
151 EINA_SAFETY_ON_NULL_RETURN(ei);
153 device_touch_count = libinput_device_touch_get_touch_count(edev->device);
155 if (_max_device_touch_count < device_touch_count)
156 _max_device_touch_count = device_touch_count;
158 if (e_config->configured_max_touch.use)
160 if (_max_device_touch_count > 0 && e_config->configured_max_touch.count > _max_device_touch_count)
162 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch max count(%d) must be less or equal to device's touch count(%d) !\nTouch max count has been shrinken to %d.\n",
163 NULL, e_config->configured_max_touch.count, _max_device_touch_count, _max_device_touch_count);
164 ei->touch_max_count = _max_device_touch_count;
168 if (ei->touch_max_count != e_config->configured_max_touch.count)
170 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch_max_count has been updated to %d -> %d.\n",
171 NULL, ei->touch_max_count, e_config->configured_max_touch.count);
172 ei->touch_max_count = e_config->configured_max_touch.count;
178 if (ei->touch_max_count < _max_device_touch_count)
180 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch_max_count has been updated to %d -> %d.\n", NULL,
181 ei->touch_max_count, _max_device_touch_count);
182 ei->touch_max_count = _max_device_touch_count;
186 ei->touch_device_count++;
187 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch device count is %d.\n", NULL, ei->touch_device_count);
191 _device_configure(E_Input_Evdev *edev)
193 if (libinput_device_config_tap_get_finger_count(edev->device) > 0)
195 Eina_Bool tap = EINA_FALSE;
197 tap = libinput_device_config_tap_get_default_enabled(edev->device);
198 libinput_device_config_tap_set_enabled(edev->device, tap);
201 _device_calibration_set(edev);
205 _device_keyboard_setup(E_Input_Evdev *edev)
207 E_Input_Backend *input;
208 xkb_mod_index_t xkb_idx;
210 if ((!edev) || (!edev->seat)) return;
211 if (!(input = edev->seat->input)) return;
212 if (!input->dev->xkb_ctx) return;
214 g_mutex_init(&edev->xkb.keymap_mutex);
216 /* create keymap from xkb context */
217 g_mutex_lock(&edev->xkb.keymap_mutex);
218 edev->xkb.keymap = _e_input_device_cached_keymap_get(input->dev->xkb_ctx, NULL, 0);
219 if (!edev->xkb.keymap)
221 g_mutex_unlock(&edev->xkb.keymap_mutex);
222 ERR("Failed to create keymap: %m");
226 g_mutex_lock(&edev->xkb.state_mutex);
228 /* create xkb state */
229 if (!(edev->xkb.state = xkb_state_new(edev->xkb.keymap)))
231 g_mutex_unlock(&edev->xkb.state_mutex);
232 ERR("Failed to create xkb state: %m");
236 g_mutex_unlock(&edev->xkb.state_mutex);
238 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CTRL);
239 if (xkb_idx != XKB_MOD_INVALID)
240 edev->xkb.ctrl_mask = 1 << xkb_idx;
242 edev->xkb.ctrl_mask = 0;
244 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_ALT);
245 if (xkb_idx != XKB_MOD_INVALID)
246 edev->xkb.alt_mask = 1 << xkb_idx;
248 edev->xkb.alt_mask = 0;
250 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_SHIFT);
251 if (xkb_idx != XKB_MOD_INVALID)
252 edev->xkb.shift_mask = 1 << xkb_idx;
254 edev->xkb.shift_mask = 0;
256 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_LOGO);
257 if (xkb_idx != XKB_MOD_INVALID)
258 edev->xkb.win_mask = 1 << xkb_idx;
260 edev->xkb.win_mask = 0;
262 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_SCROLL);
263 if (xkb_idx != XKB_MOD_INVALID)
264 edev->xkb.scroll_mask = 1 << xkb_idx;
266 edev->xkb.scroll_mask = 0;
268 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_NUM);
269 if (xkb_idx != XKB_MOD_INVALID)
270 edev->xkb.num_mask = 1 << xkb_idx;
272 edev->xkb.num_mask = 0;
274 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CAPS);
275 if (xkb_idx != XKB_MOD_INVALID)
276 edev->xkb.caps_mask = 1 << xkb_idx;
278 edev->xkb.caps_mask = 0;
280 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, "ISO_Level3_Shift");
281 if (xkb_idx != XKB_MOD_INVALID)
282 edev->xkb.altgr_mask = 1 << xkb_idx;
284 edev->xkb.altgr_mask = 0;
286 g_mutex_unlock(&edev->xkb.keymap_mutex);
290 _device_keysym_translate(xkb_keysym_t keysym, unsigned int modifiers, char *buffer, int bytes)
292 unsigned long hbytes = 0;
295 if (!keysym) return 0;
296 hbytes = (keysym >> 8);
301 (((keysym >= XKB_KEY_BackSpace) && (keysym <= XKB_KEY_Clear)) ||
302 (keysym == XKB_KEY_Return) || (keysym == XKB_KEY_Escape) ||
303 (keysym == XKB_KEY_KP_Space) || (keysym == XKB_KEY_KP_Tab) ||
304 (keysym == XKB_KEY_KP_Enter) ||
305 ((keysym >= XKB_KEY_KP_Multiply) && (keysym <= XKB_KEY_KP_9)) ||
306 (keysym == XKB_KEY_KP_Equal) || (keysym == XKB_KEY_Delete))))))
309 if (keysym == XKB_KEY_KP_Space)
310 c = (XKB_KEY_space & 0x7F);
311 else if (hbytes == 0xFF)
316 if (modifiers & ECORE_EVENT_MODIFIER_CTRL)
318 if (((c >= '@') && (c < '\177')) || c == ' ')
322 else if ((c >= '3') && (c <= '7'))
334 _device_modifiers_update_device(E_Input_Evdev *edev, E_Input_Evdev *from)
338 g_mutex_lock(&from->xkb.state_mutex);
340 edev->xkb.depressed =
341 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_DEPRESSED);
343 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LATCHED);
345 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LOCKED);
347 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_EFFECTIVE);
349 g_mutex_unlock(&from->xkb.state_mutex);
351 mask = (edev->xkb.depressed | edev->xkb.latched);
353 if (mask & from->xkb.ctrl_mask)
354 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_CTRL;
355 if (mask & from->xkb.alt_mask)
356 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALT;
357 if (mask & from->xkb.shift_mask)
358 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
359 if (mask & from->xkb.win_mask)
360 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_WIN;
361 if (mask & from->xkb.scroll_mask)
362 edev->xkb.modifiers |= ECORE_EVENT_LOCK_SCROLL;
363 if (mask & from->xkb.num_mask)
364 edev->xkb.modifiers |= ECORE_EVENT_LOCK_NUM;
365 if (mask & from->xkb.caps_mask)
366 edev->xkb.modifiers |= ECORE_EVENT_LOCK_CAPS;
367 if (mask & from->xkb.altgr_mask)
368 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALTGR;
372 _device_modifiers_update(E_Input_Evdev *edev)
377 edev->xkb.modifiers = 0;
379 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
380 _device_modifiers_update_device(edev, edev);
383 EINA_LIST_FOREACH(edev->seat->devices, l, ed)
385 if (!(ed->caps & E_INPUT_SEAT_KEYBOARD)) continue;
386 _device_modifiers_update_device(edev, ed);
393 _device_remapped_key_get(E_Input_Evdev *edev, int code)
397 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, code);
398 if (!edev->key_remap_enabled) return code;
399 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->key_remap_hash, code);
401 ret = eina_hash_find(edev->key_remap_hash, &code);
403 if (ret) code = (int)(intptr_t)ret;
409 e_input_evdev_get_e_device(const char *path, Ecore_Device_Class clas)
411 const GList *dev_list = NULL;
413 E_Device *dev = NULL;
414 const char *identifier;
416 if (!path) return NULL;
418 dev_list = e_device_list_get();
419 if (!dev_list) return NULL;
420 for (l = dev_list, dev = dev_list->data;
422 l = g_list_next(l), dev = l->data)
425 identifier = e_device_identifier_get(dev);
426 if (!identifier) continue;
427 if ((e_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
434 EINTERN Ecore_Device *
435 e_input_evdev_get_ecore_device(const char *path, Ecore_Device_Class clas)
437 const Eina_List *dev_list = NULL;
439 Ecore_Device *dev = NULL;
440 const char *identifier;
442 if (!path) return NULL;
444 dev_list = ecore_device_list();
445 if (!dev_list) return NULL;
446 EINA_LIST_FOREACH(dev_list, l, dev)
449 identifier = ecore_device_identifier_get(dev);
450 if (!identifier) continue;
451 if ((ecore_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
458 _e_input_event_mouse_move_cb_free(void *data EINA_UNUSED, void *event)
460 Ecore_Event_Mouse_Move *ev = event;
462 if (ev->dev) ecore_device_unref(ev->dev);
468 _e_input_event_mouse_wheel_cb_free(void *data EINA_UNUSED, void *event)
470 Ecore_Event_Mouse_Wheel *ev = event;
472 if (ev->dev) ecore_device_unref(ev->dev);
478 _e_input_event_mouse_button_cb_free(void *data EINA_UNUSED, void *event)
480 Ecore_Event_Mouse_Button *ev = event;
482 if (ev->dev) ecore_device_unref(ev->dev);
488 _e_input_event_key_cb_free(void *data EINA_UNUSED, void *event)
490 Ecore_Event_Key *ev = event;
492 if (e_input_thread_mode_get())
494 if (ev->dev) g_object_unref(ev->dev);
498 if (ev->dev) ecore_device_unref(ev->dev);
501 if (ev->data) E_FREE(ev->data);
507 _device_handle_key(struct libinput_device *device, struct libinput_event_keyboard *event)
510 E_Input_Backend *input;
512 uint32_t code, nsyms;
513 const xkb_keysym_t *syms;
514 enum libinput_key_state state;
516 xkb_keysym_t sym = XKB_KEY_NoSymbol;
517 char key[256] = {0, }, keyname[256] = {0, }, compose_buffer[256] = {0, };
519 char *tmp = NULL, *compose = NULL;
520 E_Keyrouter_Event_Data *key_data;
521 Ecore_Device *ecore_dev = NULL, *data;
522 E_Device *e_dev = NULL, *e_dev_data;
523 Eina_List *l = NULL, *l_next = NULL;
525 E_Comp_Config *comp_conf = NULL;
526 int *pressed_keycode = NULL, *idata = NULL;
527 Eina_Bool dup_found = EINA_FALSE;
528 const char* device_name = NULL;
530 if (!(edev = libinput_device_get_user_data(device)))
535 if (!(input = edev->seat->input))
540 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
541 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
543 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
545 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_KEYBOARD)
554 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
555 ecore_dev = edev->ecore_dev;
560 ERR("Failed to get source ecore device from event !\n");
564 if (edev->e_dev) e_dev = edev->e_dev;
565 else if (edev->e_dev_list && g_list_length(edev->e_dev_list) > 0)
567 for (glist = edev->e_dev_list, e_dev_data = edev->e_dev_list->data;
569 glist = g_list_next(l), e_dev_data = l->data)
571 if (e_device_class_get(e_dev_data) == ECORE_DEVICE_CLASS_KEYBOARD)
580 edev->e_dev = e_input_evdev_get_e_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
586 ERR("Failed to get source e device from event !\n");
590 timestamp = libinput_event_keyboard_get_time(event);
591 code = libinput_event_keyboard_get_key(event);
592 code = _device_remapped_key_get(edev, code + 8);
593 state = libinput_event_keyboard_get_key_state(event);
594 key_count = libinput_event_keyboard_get_seat_key_count(event);
596 if (state == LIBINPUT_KEY_STATE_PRESSED)
598 if ((edev->seat->dev->blocked & E_INPUT_SEAT_KEYBOARD) ||
599 (edev->seat->dev->server_blocked & E_INPUT_SEAT_KEYBOARD))
601 ELOGF("Key", "Press (keycode: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
602 code, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
603 edev->seat->dev->server_blocked);
607 /* FIXME: Currently to maintain press/release event pair during input block,
608 * used Eina_List and this is method used in devicemgr module.
609 * But we need to consider which way is better to maintain key press/release pair.
612 EINA_LIST_FOREACH(edev->xkb.pressed_keys, l, idata)
616 dup_found = EINA_TRUE;
622 pressed_keycode = E_NEW(int, 1);
623 EINA_SAFETY_ON_NULL_RETURN(pressed_keycode);
624 *pressed_keycode = code;
626 edev->xkb.pressed_keys = eina_list_append(edev->xkb.pressed_keys, pressed_keycode);
631 dup_found = EINA_FALSE;
632 EINA_LIST_FOREACH_SAFE(edev->xkb.pressed_keys, l, l_next, idata)
636 edev->xkb.pressed_keys = eina_list_remove_list(edev->xkb.pressed_keys, l);
638 dup_found = EINA_TRUE;
644 ELOGF("Key", "Release (keycode: %d, device: %s) is blocked by %p", NULL,
645 code, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client);
650 /* ignore key events that are not seat wide state changes */
651 if (((state == LIBINPUT_KEY_STATE_PRESSED) && (key_count != 1)) ||
652 ((state == LIBINPUT_KEY_STATE_RELEASED) && (key_count != 0)))
657 g_mutex_lock(&edev->xkb.state_mutex);
658 xkb_state_update_key(edev->xkb.state, code,
659 (state ? XKB_KEY_DOWN : XKB_KEY_UP));
661 /* get the keysym for this code */
662 nsyms = xkb_key_get_syms(edev->xkb.state, code, &syms);
663 g_mutex_unlock(&edev->xkb.state_mutex);
665 if (nsyms == 1) sym = syms[0];
667 /* If no keysym was found, name it "Keycode-NNN" */
668 if (sym == XKB_KEY_NoSymbol)
669 snprintf(key, sizeof(key), "Keycode-%u", code);
672 /* get the keyname for this sym */
673 xkb_keysym_get_name(sym, key, sizeof(key));
678 /* If no keyname was found, name it "Keycode-NNN" */
679 snprintf(keyname, sizeof(keyname), "Keycode-%u", code);
683 memcpy(keyname, key, sizeof(keyname));
686 /* if shift is active, we need to transform the key to lower */
687 g_mutex_lock(&edev->xkb.keymap_mutex);
688 g_mutex_lock(&edev->xkb.state_mutex);
689 if (xkb_state_mod_index_is_active(edev->xkb.state,
690 xkb_map_mod_get_index(edev->xkb.keymap,
692 XKB_STATE_MODS_EFFECTIVE))
694 if (keyname[0] != '\0')
695 keyname[0] = tolower(keyname[0]);
697 g_mutex_unlock(&edev->xkb.keymap_mutex);
698 g_mutex_unlock(&edev->xkb.state_mutex);
700 if (_device_keysym_translate(sym, edev->xkb.modifiers,
701 compose_buffer, sizeof(compose_buffer)))
703 compose = eina_str_convert("ISO8859-1", "UTF-8", compose_buffer);
706 ERR("E Input cannot convert input key string '%s' to UTF-8. "
707 "Is Eina built with iconv support?", compose_buffer);
713 if (!compose) compose = compose_buffer;
715 e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) +
716 ((compose[0] != '\0') ? strlen(compose) : 0) + 3);
722 key_data = E_NEW(E_Keyrouter_Event_Data, 1);
730 e->keyname = (char *)(e + 1);
731 e->key = e->keyname + strlen(keyname) + 1;
732 e->compose = strlen(compose) ? e->key + strlen(key) + 1 : NULL;
733 e->string = e->compose;
735 strncpy((char *)e->keyname, keyname, strlen(keyname));
736 strncpy((char *)e->key, key, strlen(key));
737 if (strlen(compose)) strncpy((char *)e->compose, compose, strlen(compose));
739 e->window = (Ecore_Window)input->dev->window;
740 e->event_window = (Ecore_Window)input->dev->window;
741 e->root_window = (Ecore_Window)input->dev->window;
742 e->timestamp = timestamp;
747 _device_modifiers_update(edev);
749 e->modifiers = edev->xkb.modifiers;
751 comp_conf = e_comp_config_get();
753 if (e_input_thread_mode_get())
755 e->dev = (Eo *)g_object_ref(e_dev);
756 device_name = e_device_name_get(e_dev);
757 e_input_event_add(input->event_source, state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
761 e->dev = ecore_device_ref(ecore_dev);
762 device_name = ecore_device_name_get(ecore_dev);
763 ecore_event_add(state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
766 if (comp_conf && comp_conf->input_log_enable)
767 ELOGF("Key", "%s (keyname: %s, keycode: %d, timestamp: %u, device: %s)", NULL, state?"Press":"Release", e->keyname, e->keycode, e->timestamp, device_name);
773 _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event)
775 E_Input_Backend *input;
776 Ecore_Event_Mouse_Move *ev;
777 Ecore_Device *ecore_dev = NULL, *data, *detent_data = NULL;
779 int x = 0, y = 0, w = 0, h = 0;
781 if (!(input = edev->seat->input)) return;
783 ecore_thread_main_loop_begin();
785 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
786 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
788 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
790 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
795 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
800 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
802 ecore_dev = detent_data;
807 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
808 ecore_dev = edev->ecore_dev;
813 ERR("Failed to get source ecore device from event !\n");
816 else if ((detent_data == ecore_dev) || e_devicemgr_detent_is_detent(ecore_device_name_get(ecore_dev)))
818 /* Do not process detent device's move events. */
822 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
824 _device_configured_size_get(edev, &x, &y, &w, &h);
826 if (edev->seat->ptr.ix < x)
827 edev->seat->ptr.dx = edev->seat->ptr.ix = x;
828 else if (edev->seat->ptr.ix >= (x + w))
829 edev->seat->ptr.dx = edev->seat->ptr.ix = (x + w - 1);
831 if (edev->seat->ptr.iy < y)
832 edev->seat->ptr.dy = edev->seat->ptr.iy = y;
833 else if (edev->seat->ptr.iy >= (y + h))
834 edev->seat->ptr.dy = edev->seat->ptr.iy = (y + h - 1);
836 edev->mouse.dx = edev->seat->ptr.dx;
837 edev->mouse.dy = edev->seat->ptr.dy;
839 ev->window = (Ecore_Window)input->dev->window;
840 ev->event_window = (Ecore_Window)input->dev->window;
841 ev->root_window = (Ecore_Window)input->dev->window;
842 if (event) ev->timestamp = libinput_event_pointer_get_time(event);
845 _device_modifiers_update(edev);
846 ev->modifiers = edev->xkb.modifiers;
848 ev->x = edev->seat->ptr.ix;
849 ev->y = edev->seat->ptr.iy;
853 ev->multi.device = edev->mt_slot;
854 ev->multi.radius = 1;
855 ev->multi.radius_x = 1;
856 ev->multi.radius_y = 1;
857 ev->multi.pressure = 1.0;
858 ev->multi.angle = 0.0;
861 ev->multi.root.x = ev->x;
862 ev->multi.root.y = ev->y;
864 ev->dev = ecore_device_ref(ecore_dev);
866 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
869 ecore_thread_main_loop_end();
873 _e_input_pointer_motion_post(E_Input_Evdev *edev)
875 _device_pointer_motion(edev, NULL);
879 _device_pointer_relative_motion_send(double dx[2], double dy[2], uint64_t time_us)
881 e_input_relative_motion_cb func = e_input_relative_motion_handler_get();
882 if (func) func(dx, dy, time_us);
886 _device_handle_pointer_motion(struct libinput_device *device, struct libinput_event_pointer *event)
889 double delta_x[2]; /* delta_x[0] for accelerated, delta_x[1] for unaccelerated */
890 double delta_y[2]; /* delta_y[0] for accelerated, delta_y[1] for unaccelerated */
893 if (!(edev = libinput_device_get_user_data(device)))
898 delta_x[0] = libinput_event_pointer_get_dx(event);
899 delta_x[1] = libinput_event_pointer_get_dx_unaccelerated(event);
900 delta_y[0] = libinput_event_pointer_get_dy(event);
901 delta_y[1] = libinput_event_pointer_get_dy_unaccelerated(event);
903 if (edev->disable_acceleration)
914 if (edev->seat->ptr.swap)
920 if (edev->seat->ptr.invert_x)
922 if (edev->seat->ptr.invert_y)
925 edev->seat->ptr.dx += dx;
926 edev->seat->ptr.dy += dy;
928 edev->mouse.dx = edev->seat->ptr.dx;
929 edev->mouse.dy = edev->seat->ptr.dy;
931 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
932 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
937 edev->seat->ptr.ix = edev->seat->ptr.dx;
938 edev->seat->ptr.iy = edev->seat->ptr.dy;
940 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
941 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
946 _device_pointer_relative_motion_send(&delta_x[0], &delta_y[0],
947 libinput_event_pointer_get_time_usec(event));
948 _device_pointer_motion(edev, event);
952 _device_handle_pointer_motion_absolute(struct libinput_device *device, struct libinput_event_pointer *event)
957 if (!(edev = libinput_device_get_user_data(device)))
962 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
964 edev->mouse.dx = edev->seat->ptr.dx =
965 libinput_event_pointer_get_absolute_x_transformed(event, w);
966 edev->mouse.dy = edev->seat->ptr.dy =
967 libinput_event_pointer_get_absolute_y_transformed(event, h);
969 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
970 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
975 edev->seat->ptr.ix = edev->seat->ptr.dx;
976 edev->seat->ptr.iy = edev->seat->ptr.dy;
978 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
979 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
984 _device_pointer_motion(edev, event);
988 _device_handle_button(struct libinput_device *device, struct libinput_event_pointer *event)
991 E_Input_Backend *input;
992 Ecore_Event_Mouse_Button *ev;
993 enum libinput_button_state state;
994 uint32_t button, timestamp;
995 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
997 E_Comp_Config *comp_conf = NULL;
999 if (!(edev = libinput_device_get_user_data(device)))
1003 if (!(input = edev->seat->input))
1008 ecore_thread_main_loop_begin();
1010 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1011 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1013 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1015 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1020 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1025 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1027 ecore_dev = detent_data;
1032 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1033 ecore_dev = edev->ecore_dev;
1038 ERR("Failed to get source ecore device from event !\n");
1042 state = libinput_event_pointer_get_button_state(event);
1043 button = libinput_event_pointer_get_button(event);
1044 timestamp = libinput_event_pointer_get_time(event);
1046 button = ((button & 0x00F) + 1);
1047 if (button == 3) button = 2;
1048 else if (button == 2) button = 3;
1052 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1053 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1055 ELOGF("Mouse", "Button Press (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
1056 button, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
1057 edev->seat->dev->server_blocked);
1062 edev->mouse.pressed_button |= (1 << button);
1067 if (!(edev->mouse.pressed_button & (1 << button)))
1069 ELOGF("Mouse", "Button Release (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
1070 button, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
1071 edev->seat->dev->server_blocked);
1074 edev->mouse.pressed_button &= ~(1 << button);
1077 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button))))
1082 ev->window = (Ecore_Window)input->dev->window;
1083 ev->event_window = (Ecore_Window)input->dev->window;
1084 ev->root_window = (Ecore_Window)input->dev->window;
1085 ev->timestamp = timestamp;
1086 ev->same_screen = 1;
1088 _device_modifiers_update(edev);
1089 ev->modifiers = edev->xkb.modifiers;
1091 ev->x = edev->seat->ptr.ix;
1092 ev->y = edev->seat->ptr.iy;
1096 ev->multi.device = edev->mt_slot;
1097 ev->multi.radius = 1;
1098 ev->multi.radius_x = 1;
1099 ev->multi.radius_y = 1;
1100 ev->multi.pressure = 1.0;
1101 ev->multi.angle = 0.0;
1102 ev->multi.x = ev->x;
1103 ev->multi.y = ev->y;
1104 ev->multi.root.x = ev->x;
1105 ev->multi.root.y = ev->y;
1106 ev->dev = ecore_device_ref(ecore_dev);
1110 unsigned int current;
1112 current = timestamp;
1113 edev->mouse.did_double = EINA_FALSE;
1114 edev->mouse.did_triple = EINA_FALSE;
1116 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1117 (button == edev->mouse.prev_button))
1119 edev->mouse.did_double = EINA_TRUE;
1120 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1121 (button == edev->mouse.last_button))
1123 edev->mouse.did_triple = EINA_TRUE;
1124 edev->mouse.prev = 0;
1125 edev->mouse.last = 0;
1130 edev->mouse.last = edev->mouse.prev;
1131 edev->mouse.prev = current;
1132 edev->mouse.last_button = edev->mouse.prev_button;
1133 edev->mouse.prev_button = button;
1136 ev->buttons = button;
1138 if (edev->mouse.did_double)
1139 ev->double_click = 1;
1140 if (edev->mouse.did_triple)
1141 ev->triple_click = 1;
1143 comp_conf = e_comp_config_get();
1144 if (comp_conf && comp_conf->input_log_enable)
1145 ELOGF("Mouse", "Button %s (btn: %d, device: %s)", NULL, state?"Press":"Release", button, ecore_device_name_get(ev->dev));
1148 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, _e_input_event_mouse_button_cb_free, NULL);
1150 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, _e_input_event_mouse_button_cb_free, NULL);
1153 ecore_thread_main_loop_end();
1156 #if !LIBINPUT_HAVE_SCROLL_VALUE_V120
1158 _axis_value_get(struct libinput_event_pointer *pointer_event, enum libinput_pointer_axis axis)
1160 enum libinput_pointer_axis_source source;
1161 double value = 0.0, value_discrete = 0.0;
1163 E_Comp_Config *comp_conf = NULL;
1165 comp_conf = e_comp_config_get();
1166 source = libinput_event_pointer_get_axis_source(pointer_event);
1169 case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL:
1170 value_discrete = libinput_event_pointer_get_axis_value_discrete(pointer_event, axis);
1171 value = libinput_event_pointer_get_axis_value(pointer_event, axis);
1172 if (comp_conf && comp_conf->input_log_enable)
1174 ELOGF("Axis", "SOURCE_WHEEL discrete: %lf (cf. value: %lf)", NULL, value_discrete, value);
1176 ret = (int)value_discrete;
1178 case LIBINPUT_POINTER_AXIS_SOURCE_FINGER:
1179 case LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS:
1180 value = libinput_event_pointer_get_axis_value(pointer_event, axis);
1181 if (comp_conf && comp_conf->input_log_enable)
1183 ELOGF("Axis", "SOURCE_FINGER/CONTINUOUS value: %lf", NULL, value);
1185 if (value >= E_INPUT_FINGER_SCROLL_THRESHOLD)
1187 else if (value <= E_INPUT_FINGER_SCROLL_THRESHOLD * (-1))
1200 _device_handle_axis(struct libinput_device *device, struct libinput_event_pointer *event)
1202 E_Input_Evdev *edev;
1203 E_Input_Backend *input;
1204 Ecore_Event_Mouse_Wheel *ev;
1206 enum libinput_pointer_axis axis;
1207 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1209 E_Comp_Config *comp_conf = NULL;
1210 int direction = 0, z = 0;
1212 if (!(edev = libinput_device_get_user_data(device)))
1216 if (!(input = edev->seat->input))
1221 ecore_thread_main_loop_begin();
1223 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1224 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1226 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1228 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1233 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1238 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1240 ecore_dev = detent_data;
1245 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1246 ecore_dev = edev->ecore_dev;
1251 ERR("Failed to get source ecore device from event !\n");
1255 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1256 if (libinput_event_pointer_has_axis(event, axis))
1257 z = _axis_value_get(event, axis);
1259 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1260 if (libinput_event_pointer_has_axis(event, axis))
1263 z = _axis_value_get(event, axis);
1268 ELOGF("Mouse", "Axis event is ignored since it has zero value", NULL);
1272 comp_conf = e_comp_config_get();
1273 if (comp_conf && comp_conf->e_wheel_click_angle)
1275 z = (int)(z * comp_conf->e_wheel_click_angle);
1278 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1279 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1282 ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1283 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1285 ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1286 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1290 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1295 timestamp = libinput_event_pointer_get_time(event);
1297 ev->window = (Ecore_Window)input->dev->window;
1298 ev->event_window = (Ecore_Window)input->dev->window;
1299 ev->root_window = (Ecore_Window)input->dev->window;
1300 ev->timestamp = timestamp;
1301 ev->same_screen = 1;
1303 _device_modifiers_update(edev);
1304 ev->modifiers = edev->xkb.modifiers;
1306 ev->x = edev->seat->ptr.ix;
1307 ev->y = edev->seat->ptr.iy;
1311 ev->direction = direction;
1313 if (comp_conf && comp_conf->input_log_enable)
1316 ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1318 ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1322 ev->dev = ecore_device_ref(ecore_dev);
1323 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1326 ecore_thread_main_loop_end();
1330 #if LIBINPUT_HAVE_SCROLL_VALUE_V120
1332 _scroll_value_get(struct libinput_event_pointer *pointer_event, enum libinput_pointer_axis axis, E_Input_Axis_Source source)
1335 double value_v120 = 0.0;
1337 E_Comp_Config *comp_conf = NULL;
1339 comp_conf = e_comp_config_get();
1342 case E_INPUT_AXIS_SOURCE_WHEEL:
1343 value_v120 = libinput_event_pointer_get_scroll_value_v120(pointer_event, axis);
1344 value = libinput_event_pointer_get_scroll_value(pointer_event, axis);
1345 if (comp_conf && comp_conf->input_log_enable)
1347 ELOGF("Scroll", "SOURCE_WHEELL value_v120: %lf (cf. value: %lf)", NULL, value_v120, value);
1349 if (((int)value_v120 % E_INPUT_POINTER_AXIS_DISCRETE_STEP) != 0)
1351 ERR("Wheel movements should be multiples (or fractions) of 120!\n");
1356 ret = value_v120 / E_INPUT_POINTER_AXIS_DISCRETE_STEP;
1359 case E_INPUT_AXIS_SOURCE_FINGER:
1360 case E_INPUT_AXIS_SOURCE_CONTINUOUS:
1361 value = libinput_event_pointer_get_scroll_value(pointer_event, axis);
1362 if (comp_conf && comp_conf->input_log_enable)
1364 ELOGF("Scroll", "SOURCE_FINGER/CONTINUOUS value: %lf", NULL, value);
1366 if (value >= E_INPUT_FINGER_SCROLL_THRESHOLD)
1368 else if (value <= E_INPUT_FINGER_SCROLL_THRESHOLD * (-1))
1381 _device_handle_axis_v120(struct libinput_device *device, struct libinput_event_pointer *event, E_Input_Axis_Source source)
1383 E_Input_Evdev *edev;
1384 E_Input_Backend *input;
1385 Ecore_Event_Mouse_Wheel *ev;
1387 enum libinput_pointer_axis axis;
1388 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1390 E_Comp_Config *comp_conf = NULL;
1391 int direction = 0, z = 0;
1393 if (!(edev = libinput_device_get_user_data(device)))
1397 if (!(input = edev->seat->input))
1402 ecore_thread_main_loop_begin();
1404 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1405 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1407 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1409 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1414 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1419 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1421 ecore_dev = detent_data;
1426 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1427 ecore_dev = edev->ecore_dev;
1432 ERR("Failed to get source ecore device from event !\n");
1436 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1437 if (libinput_event_pointer_has_axis(event, axis))
1438 z = _scroll_value_get(event, axis, source);
1440 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1441 if (libinput_event_pointer_has_axis(event, axis))
1444 z = _scroll_value_get(event, axis, source);
1449 ELOGF("Mouse", "Scroll event is ignored since it has zero value", NULL);
1453 comp_conf = e_comp_config_get();
1454 if (comp_conf && comp_conf->e_wheel_click_angle)
1456 z = (int)(z * comp_conf->e_wheel_click_angle);
1459 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1460 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1463 ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1464 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1466 ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1467 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1471 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1476 timestamp = libinput_event_pointer_get_time(event);
1478 ev->window = (Ecore_Window)input->dev->window;
1479 ev->event_window = (Ecore_Window)input->dev->window;
1480 ev->root_window = (Ecore_Window)input->dev->window;
1481 ev->timestamp = timestamp;
1482 ev->same_screen = 1;
1484 _device_modifiers_update(edev);
1485 ev->modifiers = edev->xkb.modifiers;
1487 ev->x = edev->seat->ptr.ix;
1488 ev->y = edev->seat->ptr.iy;
1492 ev->direction = direction;
1494 if (comp_conf && comp_conf->input_log_enable)
1497 ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1499 ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1502 ev->dev = ecore_device_ref(ecore_dev);
1503 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1506 ecore_thread_main_loop_end();
1511 _device_handle_touch_event_send(E_Input_Evdev *edev, struct libinput_event_touch *event, int state)
1513 E_Input_Backend *input;
1514 Ecore_Event_Mouse_Button *ev;
1515 uint32_t timestamp, button = 0;
1516 Ecore_Device *ecore_dev = NULL, *data;
1520 if (!(input = edev->seat->input)) return;
1522 ecore_thread_main_loop_begin();
1524 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1525 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1527 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1529 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1538 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1539 ecore_dev = edev->ecore_dev;
1544 ERR("Failed to get source ecore device from event !\n");
1548 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) goto end;
1550 timestamp = libinput_event_touch_get_time(event);
1552 ev->window = (Ecore_Window)input->dev->window;
1553 ev->event_window = (Ecore_Window)input->dev->window;
1554 ev->root_window = (Ecore_Window)input->dev->window;
1555 ev->timestamp = timestamp;
1556 ev->same_screen = 1;
1558 _device_modifiers_update(edev);
1559 ev->modifiers = edev->xkb.modifiers;
1561 ev->x = edev->seat->ptr.ix;
1562 ev->y = edev->seat->ptr.iy;
1566 ev->multi.device = edev->mt_slot;
1567 ev->multi.radius = 1;
1568 ev->multi.radius_x = 1;
1569 ev->multi.radius_y = 1;
1570 ev->multi.pressure = 1.0;
1571 ev->multi.angle = 0.0;
1572 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1573 if (libinput_event_get_type(libinput_event_touch_get_base_event(event))
1574 == LIBINPUT_EVENT_TOUCH_DOWN)
1576 if (libinput_event_touch_has_minor(event))
1577 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1578 if (libinput_event_touch_has_major(event))
1579 ev->multi.radius_y = libinput_event_touch_get_major(event);
1580 if (libinput_event_touch_has_pressure(event))
1581 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1582 if (libinput_event_touch_has_orientation(event))
1583 ev->multi.angle = libinput_event_touch_get_orientation(event);
1586 ev->multi.x = ev->x;
1587 ev->multi.y = ev->y;
1588 ev->multi.root.x = ev->x;
1589 ev->multi.root.y = ev->y;
1590 ev->dev = ecore_device_ref(ecore_dev);
1592 if (state == ECORE_EVENT_MOUSE_BUTTON_DOWN)
1594 unsigned int current;
1596 current = timestamp;
1597 edev->mouse.did_double = EINA_FALSE;
1598 edev->mouse.did_triple = EINA_FALSE;
1600 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1601 (button == edev->mouse.prev_button))
1603 edev->mouse.did_double = EINA_TRUE;
1604 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1605 (button == edev->mouse.last_button))
1607 edev->mouse.did_triple = EINA_TRUE;
1608 edev->mouse.prev = 0;
1609 edev->mouse.last = 0;
1614 edev->mouse.last = edev->mouse.prev;
1615 edev->mouse.prev = current;
1616 edev->mouse.last_button = edev->mouse.prev_button;
1617 edev->mouse.prev_button = button;
1618 edev->touch.pressed |= (1 << ev->multi.device);
1622 edev->touch.pressed &= ~(1 << ev->multi.device);
1625 ev->buttons = ((button & 0x00F) + 1);
1627 if (edev->mouse.did_double)
1628 ev->double_click = 1;
1629 if (edev->mouse.did_triple)
1630 ev->triple_click = 1;
1632 ecore_event_add(state, ev, _e_input_event_mouse_button_cb_free, NULL);
1635 ecore_thread_main_loop_end();
1639 _device_handle_touch_motion_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1641 E_Input_Backend *input;
1642 Ecore_Event_Mouse_Move *ev;
1643 Ecore_Device *ecore_dev = NULL, *data;
1647 if (!(input = edev->seat->input)) return;
1649 ecore_thread_main_loop_begin();
1651 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1652 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1654 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1656 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1665 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1666 ecore_dev = edev->ecore_dev;
1671 ERR("Failed to get source ecore device from event !\n");
1675 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) goto end;
1677 ev->window = (Ecore_Window)input->dev->window;
1678 ev->event_window = (Ecore_Window)input->dev->window;
1679 ev->root_window = (Ecore_Window)input->dev->window;
1680 ev->timestamp = libinput_event_touch_get_time(event);
1681 ev->same_screen = 1;
1683 _device_modifiers_update(edev);
1684 ev->modifiers = edev->xkb.modifiers;
1686 ev->x = edev->seat->ptr.ix;
1687 ev->y = edev->seat->ptr.iy;
1691 ev->multi.device = edev->mt_slot;
1692 ev->multi.radius = 1;
1693 ev->multi.radius_x = 1;
1694 ev->multi.radius_y = 1;
1695 ev->multi.pressure = 1.0;
1696 ev->multi.angle = 0.0;
1697 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1698 if (libinput_event_touch_has_minor(event))
1699 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1700 if (libinput_event_touch_has_major(event))
1701 ev->multi.radius_y = libinput_event_touch_get_major(event);
1702 if (libinput_event_touch_has_pressure(event))
1703 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1704 if (libinput_event_touch_has_orientation(event))
1705 ev->multi.angle = libinput_event_touch_get_orientation(event);
1707 ev->multi.x = ev->x;
1708 ev->multi.y = ev->y;
1709 ev->multi.root.x = ev->x;
1710 ev->multi.root.y = ev->y;
1711 ev->dev = ecore_device_ref(ecore_dev);
1713 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
1716 ecore_thread_main_loop_end();
1720 _device_handle_touch_cancel_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1722 E_Input_Backend *input;
1723 Ecore_Event_Mouse_Button *ev;
1724 uint32_t timestamp, button = 0;
1725 Ecore_Device *ecore_dev = NULL, *data;
1729 if (!(input = edev->seat->input)) return;
1731 ecore_thread_main_loop_begin();
1733 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1734 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1736 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1738 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1747 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1748 ecore_dev = edev->ecore_dev;
1753 ERR("Failed to get source ecore device from event !\n");
1757 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) goto end;
1759 timestamp = libinput_event_touch_get_time(event);
1761 ev->window = (Ecore_Window)input->dev->window;
1762 ev->event_window = (Ecore_Window)input->dev->window;
1763 ev->root_window = (Ecore_Window)input->dev->window;
1764 ev->timestamp = timestamp;
1765 ev->same_screen = 1;
1767 ev->x = edev->seat->ptr.ix;
1768 ev->y = edev->seat->ptr.iy;
1772 ev->multi.device = edev->mt_slot;
1773 ev->multi.radius = 1;
1774 ev->multi.radius_x = 1;
1775 ev->multi.radius_y = 1;
1776 ev->multi.pressure = 1.0;
1777 ev->multi.angle = 0.0;
1778 ev->multi.x = ev->x;
1779 ev->multi.y = ev->y;
1780 ev->multi.root.x = ev->x;
1781 ev->multi.root.y = ev->y;
1783 edev->touch.pressed &= ~(1 << ev->multi.device);
1785 ev->buttons = ((button & 0x00F) + 1);
1786 ev->dev = ecore_device_ref(ecore_dev);
1788 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev, _e_input_event_mouse_button_cb_free, NULL);
1791 ecore_thread_main_loop_end();
1795 _device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, int *w, int *h)
1797 E_Output *output = NULL;
1799 EINA_SAFETY_ON_NULL_RETURN(edev);
1801 if (!edev->output_configured)
1803 if (edev->output_name)
1805 output = e_output_find(edev->output_name);
1808 edev->mouse.minx = output->config.geom.x;
1809 edev->mouse.miny = output->config.geom.y;
1810 edev->mouse.maxw = output->config.geom.w;
1811 edev->mouse.maxh = output->config.geom.h;
1812 if (libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
1814 edev->seat->ptr.dx = (double)(edev->mouse.maxw / 2);
1815 edev->seat->ptr.dy = (double)(edev->mouse.maxh / 2);
1816 edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
1817 edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
1818 edev->mouse.dx = edev->seat->ptr.dx;
1819 edev->mouse.dy = edev->seat->ptr.dy;
1824 edev->output_configured = EINA_TRUE;
1825 ELOGF("E_INPUT_EVDEV", "Device is configured by output x:%d,y:%d (w:%d, h:%d)",
1826 NULL, edev->mouse.minx, edev->mouse.miny, edev->mouse.maxw, edev->mouse.maxh);
1828 if (x) *x = edev->mouse.minx;
1829 if (y) *y = edev->mouse.miny;
1830 if (w) *w = edev->mouse.maxw;
1831 if (h) *h = edev->mouse.maxh;
1835 _device_handle_touch_down(struct libinput_device *device, struct libinput_event_touch *event)
1837 E_Input_Evdev *edev;
1838 int x = 0, y = 0, w = 0, h = 0;
1839 E_Comp_Config *comp_conf = NULL;
1841 if (!(edev = libinput_device_get_user_data(device)))
1846 _device_configured_size_get(edev, &x, &y, &w, &h);
1848 edev->mouse.dx = edev->seat->ptr.ix = edev->seat->ptr.dx =
1849 x + libinput_event_touch_get_x_transformed(event, w);
1850 edev->mouse.dy = edev->seat->ptr.iy = edev->seat->ptr.dy =
1851 y + libinput_event_touch_get_y_transformed(event, h);
1853 edev->mt_slot = libinput_event_touch_get_slot(event);
1854 if (edev->mt_slot < 0)
1856 /* FIXME: The single touch device return slot id -1
1857 * But currently we have no API to distinguish multi touch or single touch
1858 * After libinput 1.11 version, libinput provides get_touch_count API,
1859 * so we can distinguish multi touch device or single touch device.
1861 if (edev->mt_slot == -1)
1865 WRN("%d slot touch down events are not supported\n", edev->mt_slot);
1870 if (edev->mt_slot < e_input_touch_max_count_get())
1872 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
1873 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
1876 comp_conf = e_comp_config_get();
1877 if (comp_conf && comp_conf->input_log_enable)
1878 ELOGF("Touch", "Down (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
1880 edev->touch.raw_pressed |= (1 << edev->mt_slot);
1882 if (edev->touch.blocked)
1884 ELOGF("Touch", "Down (id: %d, x: %d, y: %d) is blocked by %p, server: 0x%x", NULL,
1885 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, edev->seat->dev->blocked_client,
1886 edev->seat->dev->server_blocked);
1890 _device_handle_touch_motion_send(edev, event);
1891 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_DOWN);
1895 _device_handle_touch_motion(struct libinput_device *device, struct libinput_event_touch *event)
1897 E_Input_Evdev *edev;
1898 int x = 0, y = 0, w = 0, h = 0;
1900 if (!(edev = libinput_device_get_user_data(device)))
1905 _device_configured_size_get(edev, &x, &y, &w, &h);
1907 edev->mouse.dx = edev->seat->ptr.dx =
1908 x + libinput_event_touch_get_x_transformed(event, w);
1909 edev->mouse.dy = edev->seat->ptr.dy =
1910 y + libinput_event_touch_get_y_transformed(event, h);
1912 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
1913 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
1918 edev->seat->ptr.ix = edev->seat->ptr.dx;
1919 edev->seat->ptr.iy = edev->seat->ptr.dy;
1921 edev->mt_slot = libinput_event_touch_get_slot(event);
1922 if (edev->mt_slot < 0)
1924 /* FIXME: The single touch device return slot id -1
1925 * But currently we have no API to distinguish multi touch or single touch
1926 * After libinput 1.11 version, libinput provides get_touch_count API,
1927 * so we can distinguish multi touch device or single touch device.
1929 if (edev->mt_slot == -1)
1933 WRN("%d slot touch motion events are not supported\n", edev->mt_slot);
1938 if (edev->mt_slot < e_input_touch_max_count_get())
1940 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
1941 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
1944 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
1946 if (edev->touch.blocked)
1952 _device_handle_touch_motion_send(edev, event);
1956 _device_handle_touch_up(struct libinput_device *device, struct libinput_event_touch *event)
1958 E_Input_Evdev *edev;
1959 E_Comp_Config *comp_conf = NULL;
1961 if (!(edev = libinput_device_get_user_data(device)))
1966 edev->mt_slot = libinput_event_touch_get_slot(event);
1967 if (edev->mt_slot < 0)
1969 /* FIXME: The single touch device return slot id -1
1970 * But currently we have no API to distinguish multi touch or single touch
1971 * After libinput 1.11 version, libinput provides get_touch_count API,
1972 * so we can distinguish multi touch device or single touch device.
1974 if (edev->mt_slot == -1)
1978 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
1983 if (edev->mt_slot < e_input_touch_max_count_get())
1985 edev->mouse.dx = edev->seat->ptr.dx = edev->seat->ptr.ix =
1986 edev->touch.coords[edev->mt_slot].x;
1987 edev->mouse.dy = edev->seat->ptr.dy = edev->seat->ptr.iy =
1988 edev->touch.coords[edev->mt_slot].y;
1991 comp_conf = e_comp_config_get();
1992 if (comp_conf && comp_conf->input_log_enable)
1993 ELOGF("Touch", "Up (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
1995 edev->touch.raw_pressed &= ~(1 << edev->mt_slot);
1997 if (edev->touch.blocked)
1999 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
2001 ELOGF("Touch", "Up (id: %d, x: %d, y: %d) is blocked by %p, server(0x%x)", NULL,
2002 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, edev->seat->dev->blocked_client,
2003 edev->seat->dev->server_blocked);
2004 if (edev->touch.raw_pressed == 0x0)
2006 edev->touch.blocked = EINA_FALSE;
2012 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_UP);
2016 _device_handle_touch_cancel(struct libinput_device *device, struct libinput_event_touch *event)
2018 E_Input_Evdev *edev;
2019 E_Comp_Config *comp_conf = NULL;
2021 if (!(edev = libinput_device_get_user_data(device)))
2026 edev->mt_slot = libinput_event_touch_get_slot(event);
2027 if (edev->mt_slot < 0)
2029 /* FIXME: The single touch device return slot id -1
2030 * But currently we have no API to distinguish multi touch or single touch
2031 * After libinput 1.11 version, libinput provides get_touch_count API,
2032 * so we can distinguish multi touch device or single touch device.
2034 if (edev->mt_slot == -1)
2038 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
2043 comp_conf = e_comp_config_get();
2044 if (comp_conf && comp_conf->input_log_enable)
2045 ELOGF("Touch", "cancel (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2047 _device_handle_touch_cancel_send(edev, event);
2052 _device_handle_touch_frame(struct libinput_device *device EINA_UNUSED, struct libinput_event_touch *event EINA_UNUSED)
2054 /* DBG("Unhandled Touch Frame Event"); */
2058 _e_input_aux_data_event_free(void *user_data EINA_UNUSED, void *ev)
2060 Ecore_Event_Axis_Update *e = (Ecore_Event_Axis_Update *)ev;
2062 if (e->axis) free(e->axis);
2063 if (e->dev) ecore_device_unref(e->dev);
2069 _device_handle_touch_aux_data(struct libinput_device *device, struct libinput_event_touch_aux_data *event)
2071 E_Input_Evdev *edev;
2072 E_Input_Backend *input;
2073 Ecore_Event_Axis_Update *ev;
2075 Ecore_Device *ecore_dev = NULL, *data;
2077 E_Comp_Config *comp_conf;
2079 ecore_thread_main_loop_begin();
2081 if (libinput_event_touch_aux_data_get_type(event) != LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM &&
2082 libinput_event_touch_aux_data_get_value(event) > 0)
2085 if (!(edev = libinput_device_get_user_data(device))) goto end;
2086 if (!(input = edev->seat->input)) goto end;
2088 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
2089 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
2091 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
2093 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
2102 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
2103 ecore_dev = edev->ecore_dev;
2108 ERR("Failed to get source ecore device from event !\n");
2112 if (!(ev = calloc(1, sizeof(Ecore_Event_Axis_Update)))) goto end;
2114 ev->window = (Ecore_Window)input->dev->window;
2115 ev->event_window = (Ecore_Window)input->dev->window;
2116 ev->root_window = (Ecore_Window)input->dev->window;
2117 ev->timestamp = libinput_event_touch_aux_data_get_time(event);
2119 axis = (Ecore_Axis *)calloc(1, sizeof(Ecore_Axis));
2122 axis->label = ECORE_AXIS_LABEL_TOUCH_PALM;
2123 axis->value = libinput_event_touch_aux_data_get_value(event);
2128 comp_conf = e_comp_config_get();
2129 if (comp_conf && comp_conf->input_log_enable)
2130 ELOGF("Touch", "Axis (label: %d, value: %lf)", NULL, axis?axis->label:-1, axis?axis->value:0.0);
2132 ev->dev = ecore_device_ref(ecore_dev);
2134 ecore_event_add(ECORE_EVENT_AXIS_UPDATE, ev, _e_input_aux_data_event_free, NULL);
2137 ecore_thread_main_loop_end();
2141 _e_input_evdev_device_create(E_Input_Seat *seat, struct libinput_device *device)
2143 E_Input_Evdev *edev;
2144 E_Input_Backend *b_input;
2145 const char *output_name;
2147 EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
2149 /* try to allocate space for new evdev */
2150 if (!(edev = calloc(1, sizeof(E_Input_Evdev)))) return NULL;
2153 edev->device = device;
2154 edev->path = eina_stringshare_printf("%s/%s", e_input_base_dir_get(), libinput_device_get_sysname(device));
2156 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
2158 edev->caps |= E_INPUT_SEAT_KEYBOARD;
2159 _device_keyboard_setup(edev);
2162 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
2164 edev->caps |= E_INPUT_SEAT_POINTER;
2166 /* TODO: make this configurable */
2167 edev->mouse.threshold = 250;
2169 b_input = seat->input;
2170 if (b_input->left_handed == EINA_TRUE)
2172 if (libinput_device_config_left_handed_set(device, 1) !=
2173 LIBINPUT_CONFIG_STATUS_SUCCESS)
2175 WRN("Failed to set left hand mode about device: %s\n",
2176 libinput_device_get_name(device));
2181 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
2184 edev->caps |= E_INPUT_SEAT_TOUCH;
2185 palm_code = libinput_device_touch_aux_data_get_code(LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM);
2186 if (libinput_device_touch_has_aux_data(device, palm_code))
2188 libinput_device_touch_set_aux_data(device, palm_code);
2191 _device_touch_count_update(edev);
2193 edev->touch.coords = calloc(1, sizeof(E_Input_Coord)*e_input_touch_max_count_get());
2195 if (!edev->touch.coords)
2196 ERR("Failed to allocate memory for touch coords !\n");
2199 output_name = libinput_device_get_output_name(device);
2202 eina_stringshare_replace(&edev->output_name, output_name);
2203 ELOGF("E_INPUT_EVDEV", "Device has output_name:%s", NULL, output_name);
2206 libinput_device_set_user_data(device, edev);
2207 libinput_device_ref(device);
2209 /* configure device */
2210 _device_configure(edev);
2216 _e_input_evdev_device_destroy(E_Input_Evdev *edev)
2220 EINA_SAFETY_ON_NULL_RETURN(edev);
2222 ecore_thread_main_loop_begin();
2224 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
2226 g_mutex_lock(&edev->xkb.state_mutex);
2227 if (edev->xkb.state) xkb_state_unref(edev->xkb.state);
2228 g_mutex_unlock(&edev->xkb.state_mutex);
2230 g_mutex_lock(&edev->xkb.keymap_mutex);
2231 if (edev->xkb.keymap) xkb_map_unref(edev->xkb.keymap);
2232 g_mutex_unlock(&edev->xkb.keymap_mutex);
2235 if (edev->ecore_dev) ecore_device_del(edev->ecore_dev);
2236 if (edev->ecore_dev_list)
2237 EINA_LIST_FREE(edev->ecore_dev_list, dev)
2239 ecore_device_del(dev);
2241 if (edev->path) eina_stringshare_del(edev->path);
2242 if (edev->device) libinput_device_unref(edev->device);
2243 if (edev->key_remap_hash) eina_hash_free(edev->key_remap_hash);
2244 if (edev->touch.coords)
2246 free(edev->touch.coords);
2247 edev->touch.coords = NULL;
2249 eina_stringshare_del(edev->output_name);
2251 ecore_thread_main_loop_end();
2257 _e_input_evdev_event_process(struct libinput_event *event)
2259 struct libinput_device *device;
2260 Eina_Bool ret = EINA_TRUE;
2262 device = libinput_event_get_device(event);
2263 switch (libinput_event_get_type(event))
2265 case LIBINPUT_EVENT_KEYBOARD_KEY:
2266 _device_handle_key(device, libinput_event_get_keyboard_event(event));
2268 case LIBINPUT_EVENT_POINTER_MOTION:
2269 _device_handle_pointer_motion(device,
2270 libinput_event_get_pointer_event(event));
2272 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
2273 _device_handle_pointer_motion_absolute(device,
2274 libinput_event_get_pointer_event(event));
2276 case LIBINPUT_EVENT_POINTER_BUTTON:
2277 _device_handle_button(device, libinput_event_get_pointer_event(event));
2279 case LIBINPUT_EVENT_POINTER_AXIS:
2280 #if !LIBINPUT_HAVE_SCROLL_VALUE_V120
2281 _device_handle_axis(device, libinput_event_get_pointer_event(event));
2284 #if LIBINPUT_HAVE_SCROLL_VALUE_V120
2285 case LIBINPUT_EVENT_POINTER_SCROLL_WHEEL:
2286 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_WHEEL);
2288 case LIBINPUT_EVENT_POINTER_SCROLL_FINGER:
2289 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_FINGER);
2291 case LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS:
2292 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_CONTINUOUS);
2295 case LIBINPUT_EVENT_TOUCH_DOWN:
2296 _device_handle_touch_down(device, libinput_event_get_touch_event(event));
2298 case LIBINPUT_EVENT_TOUCH_MOTION:
2299 _device_handle_touch_motion(device,
2300 libinput_event_get_touch_event(event));
2302 case LIBINPUT_EVENT_TOUCH_UP:
2303 _device_handle_touch_up(device, libinput_event_get_touch_event(event));
2305 case LIBINPUT_EVENT_TOUCH_CANCEL:
2306 _device_handle_touch_cancel(device, libinput_event_get_touch_event(event));
2308 case LIBINPUT_EVENT_TOUCH_FRAME:
2309 _device_handle_touch_frame(device, libinput_event_get_touch_event(event));
2311 case LIBINPUT_EVENT_TOUCH_AUX_DATA:
2312 _device_handle_touch_aux_data(device, libinput_event_get_touch_aux_data(event));
2323 * @brief Set the axis size of the given device.
2325 * @param dev The device to set the axis size to.
2326 * @param w The width of the axis.
2327 * @param h The height of the axis.
2329 * This function sets set the width @p w and height @p h of the axis
2330 * of device @p dev. If @p dev is a relative input device, a width and
2331 * height must set for it. If its absolute set the ioctl correctly, if
2332 * not, unsupported device.
2335 e_input_evdev_axis_size_set(E_Input_Evdev *edev, int w, int h)
2337 const char *sysname;
2342 enum libinput_config_status status;
2344 EINA_SAFETY_ON_NULL_RETURN(edev);
2345 EINA_SAFETY_ON_TRUE_RETURN((w == 0) || (h == 0));
2347 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
2348 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
2351 sysname = libinput_device_get_sysname(edev->device);
2353 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
2354 if (eina_list_count(devices) < 1) return;
2356 EINA_LIST_FREE(devices, device)
2358 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
2360 (sscanf(vals, "%f %f %f %f %f %f",
2361 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
2368 libinput_device_config_calibration_set_matrix(edev->device, cal);
2370 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
2371 ERR("Failed to apply calibration");
2374 eina_stringshare_del(device);
2379 EINTERN const char *
2380 e_input_evdev_name_get(E_Input_Evdev *evdev)
2382 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2383 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2385 return libinput_device_get_name(evdev->device);
2388 EINTERN const char *
2389 e_input_evdev_sysname_get(E_Input_Evdev *evdev)
2391 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2392 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2394 return libinput_device_get_sysname(evdev->device);
2398 e_input_evdev_key_remap_enable(E_Input_Evdev *edev, Eina_Bool enable)
2400 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2401 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2403 edev->key_remap_enabled = enable;
2405 if (enable == EINA_FALSE && edev->key_remap_hash)
2407 eina_hash_free(edev->key_remap_hash);
2408 edev->key_remap_hash = NULL;
2415 e_input_evdev_key_remap_set(E_Input_Evdev *edev, int *from_keys, int *to_keys, int num)
2419 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2420 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2421 EINA_SAFETY_ON_NULL_RETURN_VAL(from_keys, EINA_FALSE);
2422 EINA_SAFETY_ON_NULL_RETURN_VAL(to_keys, EINA_FALSE);
2423 EINA_SAFETY_ON_TRUE_RETURN_VAL(num <= 0, EINA_FALSE);
2424 EINA_SAFETY_ON_TRUE_RETURN_VAL(!edev->key_remap_enabled, EINA_FALSE);
2426 if (edev->key_remap_hash == NULL)
2427 edev->key_remap_hash = eina_hash_int32_new(NULL);
2429 if (edev->key_remap_hash == NULL)
2431 ERR("Failed to set remap key information : creating a hash is failed.");
2435 for (i = 0; i < num ; i++)
2437 if (!from_keys[i] || !to_keys[i])
2439 ERR("Failed to set remap key information : given arguments are invalid.");
2444 for (i = 0; i < num ; i++)
2446 eina_hash_add(edev->key_remap_hash, &from_keys[i], (void *)(intptr_t)to_keys[i]);
2453 e_input_evdev_wheel_click_angle_get(E_Input_Evdev *dev)
2455 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, -1);
2456 return libinput_device_config_scroll_get_wheel_click_angle(dev->device);
2460 e_input_evdev_touch_calibration_set(E_Input_Evdev *edev, float matrix[6])
2462 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2463 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2465 if (!libinput_device_config_calibration_has_matrix(edev->device) ||
2466 !libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_TOUCH))
2469 if (libinput_device_config_calibration_set_matrix(edev->device, matrix) !=
2470 LIBINPUT_CONFIG_STATUS_SUCCESS)
2472 WRN("Failed to set input transformation about device: %s\n",
2473 libinput_device_get_name(edev->device));
2481 e_input_evdev_mouse_accel_speed_set(E_Input_Evdev *edev, double speed)
2483 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2484 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2486 if (!libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
2489 if (!libinput_device_config_accel_is_available(edev->device))
2492 if (libinput_device_config_accel_set_speed(edev->device, speed) !=
2493 LIBINPUT_CONFIG_STATUS_SUCCESS)
2495 WRN("Failed to set mouse accel about device: %s\n",
2496 libinput_device_get_name(edev->device));
2503 EINTERN unsigned int
2504 e_input_evdev_touch_pressed_get(E_Input_Evdev *edev)
2506 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, 0x0);
2508 return edev->touch.pressed;
2512 e_input_evdev_seatname_get(E_Input_Evdev *evdev)
2514 struct libinput_seat *libinput_seat;
2515 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2516 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2518 libinput_seat = libinput_device_get_seat(evdev->device);
2520 return libinput_seat_get_logical_name(libinput_seat);
2524 e_input_evdev_seatname_set(E_Input_Evdev *evdev, const char *seatname)
2526 Eina_Bool res = EINA_FALSE;
2527 E_Input_Backend *input;
2529 EINA_SAFETY_ON_NULL_RETURN_VAL(seatname, EINA_FALSE);
2530 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, EINA_FALSE);
2531 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, EINA_FALSE);
2533 if (libinput_device_set_seat_logical_name(evdev->device, seatname) == 0)
2535 input = evdev->seat->input;
2536 if (!input) return EINA_FALSE;
2537 if (libinput_dispatch(input->libinput) != 0)
2539 ERR("Failed to dispatch libinput events: %m");
2543 /* process pending events */
2544 _input_events_process(input);
2552 e_input_evdev_mouse_accel_enable(E_Input_Evdev *edev, Eina_Bool enable)
2554 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2555 edev->disable_acceleration = !enable;