2 #include "e_input_private.h"
4 static void _device_modifiers_update(E_Input_Evdev *edev);
7 _device_calibration_set(E_Input_Evdev *edev)
13 output = e_comp_screen_primary_output_get(e_comp->e_comp_screen);
14 e_output_size_get(output, &w, &h);
18 edev->mouse.minx = edev->mouse.miny = 0;
22 if (libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
24 edev->seat->ptr.dx = (double)(w / 2);
25 edev->seat->ptr.dy = (double)(h / 2);
26 edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
27 edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
28 edev->mouse.dx = edev->seat->ptr.dx;
29 edev->mouse.dy = edev->seat->ptr.dy;
31 if (output->config.rotation == 90 || output->config.rotation == 270)
33 temp = edev->mouse.minx;
34 edev->mouse.minx = edev->mouse.miny;
35 edev->mouse.miny = temp;
37 temp = edev->mouse.maxw;
38 edev->mouse.maxw = edev->mouse.maxh;
39 edev->mouse.maxh = temp;
45 #ifdef _F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
51 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
52 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
55 sysname = libinput_device_get_sysname(edev->device);
57 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
58 if (eina_list_count(devices) < 1) return;
60 #ifdef _F_E_INPUT_USE_WL_CALIBRATION_
62 enum libinput_config_status status;
64 EINA_LIST_FREE(devices, device)
66 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
68 (sscanf(vals, "%f %f %f %f %f %f",
69 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
76 libinput_device_config_calibration_set_matrix(edev->device, cal);
78 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
79 ERR("Failed to apply calibration");
82 eina_stringshare_del(device);
85 #endif//_F_E_INPUT_USE_WL_CALIBRATION_
86 #endif//_F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
91 _device_touch_count_update(E_Input_Evdev *edev)
93 unsigned int device_touch_count = 0;
94 static unsigned int _max_device_touch_count = 0;
96 E_Input *ei = e_input_get();
97 EINA_SAFETY_ON_NULL_RETURN(ei);
99 device_touch_count = libinput_device_touch_get_touch_count(edev->device);
101 if (_max_device_touch_count < device_touch_count)
102 _max_device_touch_count = device_touch_count;
104 if (e_config->configured_max_touch.use)
106 if (_max_device_touch_count > 0 && e_config->configured_max_touch.count > _max_device_touch_count)
108 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",
109 NULL, e_config->configured_max_touch.count, _max_device_touch_count, _max_device_touch_count);
110 ei->touch_max_count = _max_device_touch_count;
114 if (ei->touch_max_count != e_config->configured_max_touch.count)
116 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch_max_count has been updated to %d -> %d.\n",
117 NULL, ei->touch_max_count, e_config->configured_max_touch.count);
118 ei->touch_max_count = e_config->configured_max_touch.count;
124 if (ei->touch_max_count < _max_device_touch_count)
126 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch_max_count has been updated to %d -> %d.\n", NULL,
127 ei->touch_max_count, _max_device_touch_count);
128 ei->touch_max_count = _max_device_touch_count;
132 ei->touch_device_count++;
133 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch device count is %d.\n", NULL, ei->touch_device_count);
137 _device_configure(E_Input_Evdev *edev)
139 if (libinput_device_config_tap_get_finger_count(edev->device) > 0)
141 Eina_Bool tap = EINA_FALSE;
143 tap = libinput_device_config_tap_get_default_enabled(edev->device);
144 libinput_device_config_tap_set_enabled(edev->device, tap);
147 _device_calibration_set(edev);
151 _device_keyboard_setup(E_Input_Evdev *edev)
153 E_Input_Backend *input;
154 xkb_mod_index_t xkb_idx;
156 if ((!edev) || (!edev->seat)) return;
157 if (!(input = edev->seat->input)) return;
158 if (!input->dev->xkb_ctx) return;
160 /* create keymap from xkb context */
161 edev->xkb.keymap = _e_input_device_cached_keymap_get(input->dev->xkb_ctx, NULL, 0);
162 if (!edev->xkb.keymap)
164 ERR("Failed to create keymap: %m");
168 /* create xkb state */
169 if (!(edev->xkb.state = xkb_state_new(edev->xkb.keymap)))
171 ERR("Failed to create xkb state: %m");
175 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CTRL);
176 if (xkb_idx != XKB_MOD_INVALID)
177 edev->xkb.ctrl_mask = 1 << xkb_idx;
179 edev->xkb.ctrl_mask = 0;
181 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_ALT);
182 if (xkb_idx != XKB_MOD_INVALID)
183 edev->xkb.alt_mask = 1 << xkb_idx;
185 edev->xkb.alt_mask = 0;
187 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_SHIFT);
188 if (xkb_idx != XKB_MOD_INVALID)
189 edev->xkb.shift_mask = 1 << xkb_idx;
191 edev->xkb.shift_mask = 0;
193 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_LOGO);
194 if (xkb_idx != XKB_MOD_INVALID)
195 edev->xkb.win_mask = 1 << xkb_idx;
197 edev->xkb.win_mask = 0;
199 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_SCROLL);
200 if (xkb_idx != XKB_MOD_INVALID)
201 edev->xkb.scroll_mask = 1 << xkb_idx;
203 edev->xkb.scroll_mask = 0;
205 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_NUM);
206 if (xkb_idx != XKB_MOD_INVALID)
207 edev->xkb.num_mask = 1 << xkb_idx;
209 edev->xkb.num_mask = 0;
211 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CAPS);
212 if (xkb_idx != XKB_MOD_INVALID)
213 edev->xkb.caps_mask = 1 << xkb_idx;
215 edev->xkb.caps_mask = 0;
217 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, "ISO_Level3_Shift");
218 if (xkb_idx != XKB_MOD_INVALID)
219 edev->xkb.altgr_mask = 1 << xkb_idx;
221 edev->xkb.altgr_mask = 0;
225 _device_keysym_translate(xkb_keysym_t keysym, unsigned int modifiers, char *buffer, int bytes)
227 unsigned long hbytes = 0;
230 if (!keysym) return 0;
231 hbytes = (keysym >> 8);
236 (((keysym >= XKB_KEY_BackSpace) && (keysym <= XKB_KEY_Clear)) ||
237 (keysym == XKB_KEY_Return) || (keysym == XKB_KEY_Escape) ||
238 (keysym == XKB_KEY_KP_Space) || (keysym == XKB_KEY_KP_Tab) ||
239 (keysym == XKB_KEY_KP_Enter) ||
240 ((keysym >= XKB_KEY_KP_Multiply) && (keysym <= XKB_KEY_KP_9)) ||
241 (keysym == XKB_KEY_KP_Equal) || (keysym == XKB_KEY_Delete))))))
244 if (keysym == XKB_KEY_KP_Space)
245 c = (XKB_KEY_space & 0x7F);
246 else if (hbytes == 0xFF)
251 if (modifiers & ECORE_EVENT_MODIFIER_CTRL)
253 if (((c >= '@') && (c < '\177')) || c == ' ')
257 else if ((c >= '3') && (c <= '7'))
269 _device_modifiers_update_device(E_Input_Evdev *edev, E_Input_Evdev *from)
273 edev->xkb.depressed =
274 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_DEPRESSED);
276 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LATCHED);
278 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LOCKED);
280 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_EFFECTIVE);
282 mask = (edev->xkb.depressed | edev->xkb.latched);
284 if (mask & from->xkb.ctrl_mask)
285 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_CTRL;
286 if (mask & from->xkb.alt_mask)
287 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALT;
288 if (mask & from->xkb.shift_mask)
289 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
290 if (mask & from->xkb.win_mask)
291 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_WIN;
292 if (mask & from->xkb.scroll_mask)
293 edev->xkb.modifiers |= ECORE_EVENT_LOCK_SCROLL;
294 if (mask & from->xkb.num_mask)
295 edev->xkb.modifiers |= ECORE_EVENT_LOCK_NUM;
296 if (mask & from->xkb.caps_mask)
297 edev->xkb.modifiers |= ECORE_EVENT_LOCK_CAPS;
298 if (mask & from->xkb.altgr_mask)
299 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALTGR;
303 _device_modifiers_update(E_Input_Evdev *edev)
308 edev->xkb.modifiers = 0;
310 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
311 _device_modifiers_update_device(edev, edev);
314 EINA_LIST_FOREACH(edev->seat->devices, l, ed)
316 if (!(ed->caps & E_INPUT_SEAT_KEYBOARD)) continue;
317 _device_modifiers_update_device(edev, ed);
324 _device_remapped_key_get(E_Input_Evdev *edev, int code)
328 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, code);
329 if (!edev->key_remap_enabled) return code;
330 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->key_remap_hash, code);
332 ret = eina_hash_find(edev->key_remap_hash, &code);
334 if (ret) code = (int)(intptr_t)ret;
340 e_input_evdev_get_ecore_device(const char *path, Ecore_Device_Class clas)
342 const Eina_List *dev_list = NULL;
344 Ecore_Device *dev = NULL;
345 const char *identifier;
347 if (!path) return NULL;
349 dev_list = ecore_device_list();
350 if (!dev_list) return NULL;
351 EINA_LIST_FOREACH(dev_list, l, dev)
354 identifier = ecore_device_identifier_get(dev);
355 if (!identifier) continue;
356 if ((ecore_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
363 _e_input_event_mouse_move_cb_free(void *data EINA_UNUSED, void *event)
365 Ecore_Event_Mouse_Move *ev = event;
367 if (ev->dev) ecore_device_unref(ev->dev);
373 _e_input_event_mouse_wheel_cb_free(void *data EINA_UNUSED, void *event)
375 Ecore_Event_Mouse_Wheel *ev = event;
377 if (ev->dev) ecore_device_unref(ev->dev);
383 _e_input_event_mouse_button_cb_free(void *data EINA_UNUSED, void *event)
385 Ecore_Event_Mouse_Button *ev = event;
387 if (ev->dev) ecore_device_unref(ev->dev);
393 _e_input_event_key_cb_free(void *data EINA_UNUSED, void *event)
395 Ecore_Event_Key *ev = event;
397 if (ev->dev) ecore_device_unref(ev->dev);
398 if (ev->data) E_FREE(ev->data);
404 _device_handle_key(struct libinput_device *device, struct libinput_event_keyboard *event)
407 E_Input_Backend *input;
409 uint32_t code, nsyms;
410 const xkb_keysym_t *syms;
411 enum libinput_key_state state;
413 xkb_keysym_t sym = XKB_KEY_NoSymbol;
414 char key[256] = {0, }, keyname[256] = {0, }, compose_buffer[256] = {0, };
416 char *tmp = NULL, *compose = NULL;
417 E_Keyrouter_Event_Data *key_data;
418 Ecore_Device *ecore_dev = NULL, *data;
419 Eina_List *l, *l_next;
420 E_Comp_Config *comp_conf = NULL;
421 int *pressed_keycode = NULL, *idata = NULL;
422 Eina_Bool dup_found = EINA_FALSE;
424 if (!(edev = libinput_device_get_user_data(device)))
429 if (!(input = edev->seat->input))
434 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
435 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
437 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
439 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_KEYBOARD)
448 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
449 ecore_dev = edev->ecore_dev;
454 ERR("Failed to get source ecore device from event !\n");
458 timestamp = libinput_event_keyboard_get_time(event);
459 code = libinput_event_keyboard_get_key(event);
460 code = _device_remapped_key_get(edev, code + 8);
461 state = libinput_event_keyboard_get_key_state(event);
462 key_count = libinput_event_keyboard_get_seat_key_count(event);
464 if (state == LIBINPUT_KEY_STATE_PRESSED)
466 if ((edev->seat->dev->blocked & E_INPUT_SEAT_KEYBOARD) ||
467 (edev->seat->dev->server_blocked & E_INPUT_SEAT_KEYBOARD))
469 ELOGF("Key", "Press (keycode: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
470 code, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
471 edev->seat->dev->server_blocked);
475 /* FIXME: Currently to maintain press/release event pair during input block,
476 * used Eina_List and this is method used in devicemgr module.
477 * But we need to consider which way is better to maintain key press/release pair.
480 EINA_LIST_FOREACH(edev->xkb.pressed_keys, l, idata)
484 dup_found = EINA_TRUE;
490 pressed_keycode = E_NEW(int, 1);
491 EINA_SAFETY_ON_NULL_RETURN(pressed_keycode);
492 *pressed_keycode = code;
494 edev->xkb.pressed_keys = eina_list_append(edev->xkb.pressed_keys, pressed_keycode);
499 dup_found = EINA_FALSE;
500 EINA_LIST_FOREACH_SAFE(edev->xkb.pressed_keys, l, l_next, idata)
504 edev->xkb.pressed_keys = eina_list_remove_list(edev->xkb.pressed_keys, l);
506 dup_found = EINA_TRUE;
512 ELOGF("Key", "Release (keycode: %d, device: %s) is blocked by %p", NULL,
513 code, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client);
518 /* ignore key events that are not seat wide state changes */
519 if (((state == LIBINPUT_KEY_STATE_PRESSED) && (key_count != 1)) ||
520 ((state == LIBINPUT_KEY_STATE_RELEASED) && (key_count != 0)))
525 xkb_state_update_key(edev->xkb.state, code,
526 (state ? XKB_KEY_DOWN : XKB_KEY_UP));
528 /* get the keysym for this code */
529 nsyms = xkb_key_get_syms(edev->xkb.state, code, &syms);
530 if (nsyms == 1) sym = syms[0];
532 /* If no keysym was found, name it "Keycode-NNN" */
533 if (sym == XKB_KEY_NoSymbol)
534 snprintf(key, sizeof(key), "Keycode-%u", code);
537 /* get the keyname for this sym */
538 xkb_keysym_get_name(sym, key, sizeof(key));
543 /* If no keyname was found, name it "Keycode-NNN" */
544 snprintf(keyname, sizeof(keyname), "Keycode-%u", code);
548 memcpy(keyname, key, sizeof(keyname));
551 /* if shift is active, we need to transform the key to lower */
552 if (xkb_state_mod_index_is_active(edev->xkb.state,
553 xkb_map_mod_get_index(edev->xkb.keymap,
555 XKB_STATE_MODS_EFFECTIVE))
557 if (keyname[0] != '\0')
558 keyname[0] = tolower(keyname[0]);
561 if (_device_keysym_translate(sym, edev->xkb.modifiers,
562 compose_buffer, sizeof(compose_buffer)))
564 compose = eina_str_convert("ISO8859-1", "UTF-8", compose_buffer);
567 ERR("E Input cannot convert input key string '%s' to UTF-8. "
568 "Is Eina built with iconv support?", compose_buffer);
574 if (!compose) compose = compose_buffer;
576 e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) +
577 ((compose[0] != '\0') ? strlen(compose) : 0) + 3);
583 key_data = E_NEW(E_Keyrouter_Event_Data, 1);
591 e->keyname = (char *)(e + 1);
592 e->key = e->keyname + strlen(keyname) + 1;
593 e->compose = strlen(compose) ? e->key + strlen(key) + 1 : NULL;
594 e->string = e->compose;
596 strncpy((char *)e->keyname, keyname, strlen(keyname));
597 strncpy((char *)e->key, key, strlen(key));
598 if (strlen(compose)) strncpy((char *)e->compose, compose, strlen(compose));
600 e->window = (Ecore_Window)input->dev->window;
601 e->event_window = (Ecore_Window)input->dev->window;
602 e->root_window = (Ecore_Window)input->dev->window;
603 e->timestamp = timestamp;
608 _device_modifiers_update(edev);
610 e->modifiers = edev->xkb.modifiers;
611 e->dev = ecore_device_ref(ecore_dev);
613 comp_conf = e_comp_config_get();
614 if (comp_conf && comp_conf->input_log_enable)
615 ELOGF("Key", "%s (keyname: %s, keycode: %d, device: %s)", NULL, state?"Press":"Release", e->keyname, e->keycode, ecore_device_name_get(e->dev));
618 ecore_event_add(ECORE_EVENT_KEY_DOWN, e, _e_input_event_key_cb_free, NULL);
620 ecore_event_add(ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
626 _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event)
628 E_Input_Backend *input;
629 Ecore_Event_Mouse_Move *ev;
630 Ecore_Device *ecore_dev = NULL, *data, *detent_data = NULL;
633 if (!(input = edev->seat->input)) return;
635 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
636 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
638 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
640 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
645 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
650 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
652 ecore_dev = detent_data;
657 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
658 ecore_dev = edev->ecore_dev;
663 ERR("Failed to get source ecore device from event !\n");
666 else if ((detent_data == ecore_dev) || e_devicemgr_detent_is_detent(ecore_device_name_get(ecore_dev)))
668 /* Do not process detent device's move events. */
672 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
674 if (edev->seat->ptr.ix < edev->mouse.minx)
675 edev->seat->ptr.dx = edev->seat->ptr.ix = edev->mouse.minx;
676 else if (edev->seat->ptr.ix >= (edev->mouse.minx + edev->mouse.maxw))
677 edev->seat->ptr.dx = edev->seat->ptr.ix = (edev->mouse.minx + edev->mouse.maxw - 1);
679 if (edev->seat->ptr.iy < edev->mouse.miny)
680 edev->seat->ptr.dy = edev->seat->ptr.iy = edev->mouse.miny;
681 else if (edev->seat->ptr.iy >= (edev->mouse.miny + edev->mouse.maxh))
682 edev->seat->ptr.dy = edev->seat->ptr.iy = (edev->mouse.miny + edev->mouse.maxh - 1);
684 edev->mouse.dx = edev->seat->ptr.dx;
685 edev->mouse.dy = edev->seat->ptr.dy;
687 ev->window = (Ecore_Window)input->dev->window;
688 ev->event_window = (Ecore_Window)input->dev->window;
689 ev->root_window = (Ecore_Window)input->dev->window;
690 if (event) ev->timestamp = libinput_event_pointer_get_time(event);
693 _device_modifiers_update(edev);
694 ev->modifiers = edev->xkb.modifiers;
696 ev->x = edev->seat->ptr.ix;
697 ev->y = edev->seat->ptr.iy;
701 ev->multi.device = edev->mt_slot;
702 ev->multi.radius = 1;
703 ev->multi.radius_x = 1;
704 ev->multi.radius_y = 1;
705 ev->multi.pressure = 1.0;
706 ev->multi.angle = 0.0;
709 ev->multi.root.x = ev->x;
710 ev->multi.root.y = ev->y;
711 ev->dev = ecore_device_ref(ecore_dev);
713 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
717 _e_input_pointer_motion_post(E_Input_Evdev *edev)
719 _device_pointer_motion(edev, NULL);
723 _device_handle_pointer_motion(struct libinput_device *device, struct libinput_event_pointer *event)
728 if (!(edev = libinput_device_get_user_data(device)))
733 dx = libinput_event_pointer_get_dx(event);
734 dy = libinput_event_pointer_get_dy(event);
736 if (edev->seat->ptr.swap)
742 if (edev->seat->ptr.invert_x)
744 if (edev->seat->ptr.invert_y)
747 edev->seat->ptr.dx += dx;
748 edev->seat->ptr.dy += dy;
750 edev->mouse.dx = edev->seat->ptr.dx;
751 edev->mouse.dy = edev->seat->ptr.dy;
753 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
754 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
759 edev->seat->ptr.ix = edev->seat->ptr.dx;
760 edev->seat->ptr.iy = edev->seat->ptr.dy;
762 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
763 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
768 _device_pointer_motion(edev, event);
772 _device_handle_pointer_motion_absolute(struct libinput_device *device, struct libinput_event_pointer *event)
777 if (!(edev = libinput_device_get_user_data(device)))
782 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
784 edev->mouse.dx = edev->seat->ptr.dx =
785 libinput_event_pointer_get_absolute_x_transformed(event, w);
786 edev->mouse.dy = edev->seat->ptr.dy =
787 libinput_event_pointer_get_absolute_y_transformed(event, h);
789 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
790 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
795 edev->seat->ptr.ix = edev->seat->ptr.dx;
796 edev->seat->ptr.iy = edev->seat->ptr.dy;
798 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
799 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
804 _device_pointer_motion(edev, event);
808 _device_handle_button(struct libinput_device *device, struct libinput_event_pointer *event)
811 E_Input_Backend *input;
812 Ecore_Event_Mouse_Button *ev;
813 enum libinput_button_state state;
814 uint32_t button, timestamp;
815 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
817 E_Comp_Config *comp_conf = NULL;
819 if (!(edev = libinput_device_get_user_data(device)))
823 if (!(input = edev->seat->input))
828 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
829 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
831 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
833 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
838 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
843 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
845 ecore_dev = detent_data;
850 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
851 ecore_dev = edev->ecore_dev;
856 ERR("Failed to get source ecore device from event !\n");
860 state = libinput_event_pointer_get_button_state(event);
861 button = libinput_event_pointer_get_button(event);
862 timestamp = libinput_event_pointer_get_time(event);
864 button = ((button & 0x00F) + 1);
865 if (button == 3) button = 2;
866 else if (button == 2) button = 3;
870 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
871 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
873 ELOGF("Mouse", "Button Press (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
874 button, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
875 edev->seat->dev->server_blocked);
880 edev->mouse.pressed_button |= (1 << button);
885 if (!(edev->mouse.pressed_button & (1 << button)))
887 ELOGF("Mouse", "Button Release (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
888 button, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
889 edev->seat->dev->server_blocked);
892 edev->mouse.pressed_button &= ~(1 << button);
895 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button))))
900 ev->window = (Ecore_Window)input->dev->window;
901 ev->event_window = (Ecore_Window)input->dev->window;
902 ev->root_window = (Ecore_Window)input->dev->window;
903 ev->timestamp = timestamp;
906 _device_modifiers_update(edev);
907 ev->modifiers = edev->xkb.modifiers;
909 ev->x = edev->seat->ptr.ix;
910 ev->y = edev->seat->ptr.iy;
914 ev->multi.device = edev->mt_slot;
915 ev->multi.radius = 1;
916 ev->multi.radius_x = 1;
917 ev->multi.radius_y = 1;
918 ev->multi.pressure = 1.0;
919 ev->multi.angle = 0.0;
922 ev->multi.root.x = ev->x;
923 ev->multi.root.y = ev->y;
924 ev->dev = ecore_device_ref(ecore_dev);
928 unsigned int current;
931 edev->mouse.did_double = EINA_FALSE;
932 edev->mouse.did_triple = EINA_FALSE;
934 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
935 (button == edev->mouse.prev_button))
937 edev->mouse.did_double = EINA_TRUE;
938 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
939 (button == edev->mouse.last_button))
941 edev->mouse.did_triple = EINA_TRUE;
942 edev->mouse.prev = 0;
943 edev->mouse.last = 0;
948 edev->mouse.last = edev->mouse.prev;
949 edev->mouse.prev = current;
950 edev->mouse.last_button = edev->mouse.prev_button;
951 edev->mouse.prev_button = button;
954 ev->buttons = button;
956 if (edev->mouse.did_double)
957 ev->double_click = 1;
958 if (edev->mouse.did_triple)
959 ev->triple_click = 1;
961 comp_conf = e_comp_config_get();
962 if (comp_conf && comp_conf->input_log_enable)
963 ELOGF("Mouse", "Button %s (btn: %d, device: %s)", NULL, state?"Press":"Release", button, ecore_device_name_get(ev->dev));
966 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, _e_input_event_mouse_button_cb_free, NULL);
968 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, _e_input_event_mouse_button_cb_free, NULL);
972 _device_handle_axis(struct libinput_device *device, struct libinput_event_pointer *event)
975 E_Input_Backend *input;
976 Ecore_Event_Mouse_Wheel *ev;
978 enum libinput_pointer_axis axis;
979 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
981 E_Comp_Config *comp_conf = NULL;
982 int direction = 0, z = 0;
984 if (!(edev = libinput_device_get_user_data(device)))
988 if (!(input = edev->seat->input))
993 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
994 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
996 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
998 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1003 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1008 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1010 ecore_dev = detent_data;
1015 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1016 ecore_dev = edev->ecore_dev;
1021 ERR("Failed to get source ecore device from event !\n");
1025 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1026 if (libinput_event_pointer_has_axis(event, axis))
1027 z = libinput_event_pointer_get_axis_value_discrete(event, axis);
1029 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1030 if (libinput_event_pointer_has_axis(event, axis))
1033 z = libinput_event_pointer_get_axis_value_discrete(event, axis);
1036 comp_conf = e_comp_config_get();
1037 if (comp_conf && comp_conf->e_wheel_click_angle)
1039 z = (int)(z * comp_conf->e_wheel_click_angle);
1042 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1043 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1046 ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1047 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1049 ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1050 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1054 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1059 timestamp = libinput_event_pointer_get_time(event);
1061 ev->window = (Ecore_Window)input->dev->window;
1062 ev->event_window = (Ecore_Window)input->dev->window;
1063 ev->root_window = (Ecore_Window)input->dev->window;
1064 ev->timestamp = timestamp;
1065 ev->same_screen = 1;
1067 _device_modifiers_update(edev);
1068 ev->modifiers = edev->xkb.modifiers;
1070 ev->x = edev->seat->ptr.ix;
1071 ev->y = edev->seat->ptr.iy;
1074 ev->dev = ecore_device_ref(ecore_dev);
1077 ev->direction = direction;
1079 if (comp_conf && comp_conf->input_log_enable)
1082 ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1084 ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1087 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1091 _device_handle_touch_event_send(E_Input_Evdev *edev, struct libinput_event_touch *event, int state)
1093 E_Input_Backend *input;
1094 Ecore_Event_Mouse_Button *ev;
1095 uint32_t timestamp, button = 0;
1096 Ecore_Device *ecore_dev = NULL, *data;
1100 if (!(input = edev->seat->input)) return;
1102 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1103 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1105 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1107 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1116 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1117 ecore_dev = edev->ecore_dev;
1122 ERR("Failed to get source ecore device from event !\n");
1126 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) return;
1128 timestamp = libinput_event_touch_get_time(event);
1130 ev->window = (Ecore_Window)input->dev->window;
1131 ev->event_window = (Ecore_Window)input->dev->window;
1132 ev->root_window = (Ecore_Window)input->dev->window;
1133 ev->timestamp = timestamp;
1134 ev->same_screen = 1;
1136 _device_modifiers_update(edev);
1137 ev->modifiers = edev->xkb.modifiers;
1139 ev->x = edev->seat->ptr.ix;
1140 ev->y = edev->seat->ptr.iy;
1144 ev->multi.device = edev->mt_slot;
1145 ev->multi.radius = 1;
1146 ev->multi.radius_x = 1;
1147 ev->multi.radius_y = 1;
1148 ev->multi.pressure = 1.0;
1149 ev->multi.angle = 0.0;
1150 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1151 if (libinput_event_get_type(libinput_event_touch_get_base_event(event))
1152 == LIBINPUT_EVENT_TOUCH_DOWN)
1154 if (libinput_event_touch_has_minor(event))
1155 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1156 if (libinput_event_touch_has_major(event))
1157 ev->multi.radius_y = libinput_event_touch_get_major(event);
1158 if (libinput_event_touch_has_pressure(event))
1159 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1160 if (libinput_event_touch_has_orientation(event))
1161 ev->multi.angle = libinput_event_touch_get_orientation(event);
1164 ev->multi.x = ev->x;
1165 ev->multi.y = ev->y;
1166 ev->multi.root.x = ev->x;
1167 ev->multi.root.y = ev->y;
1168 ev->dev = ecore_device_ref(ecore_dev);
1170 if (state == ECORE_EVENT_MOUSE_BUTTON_DOWN)
1172 unsigned int current;
1174 current = timestamp;
1175 edev->mouse.did_double = EINA_FALSE;
1176 edev->mouse.did_triple = EINA_FALSE;
1178 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1179 (button == edev->mouse.prev_button))
1181 edev->mouse.did_double = EINA_TRUE;
1182 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1183 (button == edev->mouse.last_button))
1185 edev->mouse.did_triple = EINA_TRUE;
1186 edev->mouse.prev = 0;
1187 edev->mouse.last = 0;
1192 edev->mouse.last = edev->mouse.prev;
1193 edev->mouse.prev = current;
1194 edev->mouse.last_button = edev->mouse.prev_button;
1195 edev->mouse.prev_button = button;
1196 edev->touch.pressed |= (1 << ev->multi.device);
1200 edev->touch.pressed &= ~(1 << ev->multi.device);
1203 ev->buttons = ((button & 0x00F) + 1);
1205 if (edev->mouse.did_double)
1206 ev->double_click = 1;
1207 if (edev->mouse.did_triple)
1208 ev->triple_click = 1;
1210 ecore_event_add(state, ev, _e_input_event_mouse_button_cb_free, NULL);
1214 _device_handle_touch_motion_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1216 E_Input_Backend *input;
1217 Ecore_Event_Mouse_Move *ev;
1218 Ecore_Device *ecore_dev = NULL, *data;
1222 if (!(input = edev->seat->input)) return;
1224 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1225 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1227 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1229 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1238 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1239 ecore_dev = edev->ecore_dev;
1244 ERR("Failed to get source ecore device from event !\n");
1248 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
1250 ev->window = (Ecore_Window)input->dev->window;
1251 ev->event_window = (Ecore_Window)input->dev->window;
1252 ev->root_window = (Ecore_Window)input->dev->window;
1253 ev->timestamp = libinput_event_touch_get_time(event);
1254 ev->same_screen = 1;
1256 _device_modifiers_update(edev);
1257 ev->modifiers = edev->xkb.modifiers;
1259 ev->x = edev->seat->ptr.ix;
1260 ev->y = edev->seat->ptr.iy;
1264 ev->multi.device = edev->mt_slot;
1265 ev->multi.radius = 1;
1266 ev->multi.radius_x = 1;
1267 ev->multi.radius_y = 1;
1268 ev->multi.pressure = 1.0;
1269 ev->multi.angle = 0.0;
1270 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1271 if (libinput_event_touch_has_minor(event))
1272 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1273 if (libinput_event_touch_has_major(event))
1274 ev->multi.radius_y = libinput_event_touch_get_major(event);
1275 if (libinput_event_touch_has_pressure(event))
1276 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1277 if (libinput_event_touch_has_orientation(event))
1278 ev->multi.angle = libinput_event_touch_get_orientation(event);
1280 ev->multi.x = ev->x;
1281 ev->multi.y = ev->y;
1282 ev->multi.root.x = ev->x;
1283 ev->multi.root.y = ev->y;
1284 ev->dev = ecore_device_ref(ecore_dev);
1286 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
1290 _device_handle_touch_cancel_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1292 E_Input_Backend *input;
1293 Ecore_Event_Mouse_Button *ev;
1294 uint32_t timestamp, button = 0;
1295 Ecore_Device *ecore_dev = NULL, *data;
1299 if (!(input = edev->seat->input)) return;
1301 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1302 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1304 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1306 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1315 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1316 ecore_dev = edev->ecore_dev;
1321 ERR("Failed to get source ecore device from event !\n");
1325 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) return;
1327 timestamp = libinput_event_touch_get_time(event);
1329 ev->window = (Ecore_Window)input->dev->window;
1330 ev->event_window = (Ecore_Window)input->dev->window;
1331 ev->root_window = (Ecore_Window)input->dev->window;
1332 ev->timestamp = timestamp;
1333 ev->same_screen = 1;
1335 ev->x = edev->seat->ptr.ix;
1336 ev->y = edev->seat->ptr.iy;
1340 ev->multi.device = edev->mt_slot;
1341 ev->multi.radius = 1;
1342 ev->multi.radius_x = 1;
1343 ev->multi.radius_y = 1;
1344 ev->multi.pressure = 1.0;
1345 ev->multi.angle = 0.0;
1346 ev->multi.x = ev->x;
1347 ev->multi.y = ev->y;
1348 ev->multi.root.x = ev->x;
1349 ev->multi.root.y = ev->y;
1350 ev->dev = ecore_device_ref(ecore_dev);
1352 edev->touch.pressed &= ~(1 << ev->multi.device);
1354 ev->buttons = ((button & 0x00F) + 1);
1356 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev, _e_input_event_mouse_button_cb_free, NULL);
1360 _device_handle_touch_down(struct libinput_device *device, struct libinput_event_touch *event)
1362 E_Input_Evdev *edev;
1364 E_Comp_Config *comp_conf = NULL;
1366 if (!(edev = libinput_device_get_user_data(device)))
1371 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
1373 edev->mouse.dx = edev->seat->ptr.ix = edev->seat->ptr.dx =
1374 libinput_event_touch_get_x_transformed(event, w);
1375 edev->mouse.dy = edev->seat->ptr.iy = edev->seat->ptr.dy =
1376 libinput_event_touch_get_y_transformed(event, h);
1378 edev->mt_slot = libinput_event_touch_get_slot(event);
1379 if (edev->mt_slot < 0)
1381 /* FIXME: The single touch device return slot id -1
1382 * But currently we have no API to distinguish multi touch or single touch
1383 * After libinput 1.11 version, libinput provides get_touch_count API,
1384 * so we can distinguish multi touch device or single touch device.
1386 if (edev->mt_slot == -1)
1390 WRN("%d slot touch down events are not supported\n", edev->mt_slot);
1395 if (edev->mt_slot < e_input_touch_max_count_get())
1397 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
1398 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
1401 comp_conf = e_comp_config_get();
1402 if (comp_conf && comp_conf->input_log_enable)
1403 ELOGF("Touch", "Down (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
1405 edev->touch.raw_pressed |= (1 << edev->mt_slot);
1407 if (edev->touch.blocked)
1409 ELOGF("Touch", "Down (id: %d, x: %d, y: %d) is blocked by %p, server: 0x%x", NULL,
1410 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, edev->seat->dev->blocked_client,
1411 edev->seat->dev->server_blocked);
1415 _device_handle_touch_motion_send(edev, event);
1416 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_DOWN);
1420 _device_handle_touch_motion(struct libinput_device *device, struct libinput_event_touch *event)
1422 E_Input_Evdev *edev;
1425 if (!(edev = libinput_device_get_user_data(device)))
1430 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
1432 edev->mouse.dx = edev->seat->ptr.dx =
1433 libinput_event_touch_get_x_transformed(event, w);
1434 edev->mouse.dy = edev->seat->ptr.dy =
1435 libinput_event_touch_get_y_transformed(event, h);
1437 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
1438 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
1443 edev->seat->ptr.ix = edev->seat->ptr.dx;
1444 edev->seat->ptr.iy = edev->seat->ptr.dy;
1446 edev->mt_slot = libinput_event_touch_get_slot(event);
1447 if (edev->mt_slot < 0)
1449 /* FIXME: The single touch device return slot id -1
1450 * But currently we have no API to distinguish multi touch or single touch
1451 * After libinput 1.11 version, libinput provides get_touch_count API,
1452 * so we can distinguish multi touch device or single touch device.
1454 if (edev->mt_slot == -1)
1458 WRN("%d slot touch motion events are not supported\n", edev->mt_slot);
1463 if (edev->mt_slot < e_input_touch_max_count_get())
1465 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
1466 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
1469 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
1471 if (edev->touch.blocked)
1477 _device_handle_touch_motion_send(edev, event);
1481 _device_handle_touch_up(struct libinput_device *device, struct libinput_event_touch *event)
1483 E_Input_Evdev *edev;
1484 E_Comp_Config *comp_conf = NULL;
1486 if (!(edev = libinput_device_get_user_data(device)))
1491 edev->mt_slot = libinput_event_touch_get_slot(event);
1492 if (edev->mt_slot < 0)
1494 /* FIXME: The single touch device return slot id -1
1495 * But currently we have no API to distinguish multi touch or single touch
1496 * After libinput 1.11 version, libinput provides get_touch_count API,
1497 * so we can distinguish multi touch device or single touch device.
1499 if (edev->mt_slot == -1)
1503 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
1508 if (edev->mt_slot < e_input_touch_max_count_get())
1510 edev->mouse.dx = edev->seat->ptr.dx = edev->seat->ptr.ix =
1511 edev->touch.coords[edev->mt_slot].x;
1512 edev->mouse.dy = edev->seat->ptr.dy = edev->seat->ptr.iy =
1513 edev->touch.coords[edev->mt_slot].y;
1516 comp_conf = e_comp_config_get();
1517 if (comp_conf && comp_conf->input_log_enable)
1518 ELOGF("Touch", "Up (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
1520 edev->touch.raw_pressed &= ~(1 << edev->mt_slot);
1522 if (edev->touch.blocked)
1524 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
1526 ELOGF("Touch", "Up (id: %d, x: %d, y: %d) is blocked by %p, server(0x%x)", NULL,
1527 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, edev->seat->dev->blocked_client,
1528 edev->seat->dev->server_blocked);
1529 if (edev->touch.raw_pressed == 0x0)
1531 edev->touch.blocked = EINA_FALSE;
1537 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_UP);
1541 _device_handle_touch_cancel(struct libinput_device *device, struct libinput_event_touch *event)
1543 E_Input_Evdev *edev;
1544 E_Comp_Config *comp_conf = NULL;
1546 if (!(edev = libinput_device_get_user_data(device)))
1551 edev->mt_slot = libinput_event_touch_get_slot(event);
1552 if (edev->mt_slot < 0)
1554 /* FIXME: The single touch device return slot id -1
1555 * But currently we have no API to distinguish multi touch or single touch
1556 * After libinput 1.11 version, libinput provides get_touch_count API,
1557 * so we can distinguish multi touch device or single touch device.
1559 if (edev->mt_slot == -1)
1563 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
1568 comp_conf = e_comp_config_get();
1569 if (comp_conf && comp_conf->input_log_enable)
1570 ELOGF("Touch", "cancel (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
1572 _device_handle_touch_cancel_send(edev, event);
1577 _device_handle_touch_frame(struct libinput_device *device EINA_UNUSED, struct libinput_event_touch *event EINA_UNUSED)
1579 /* DBG("Unhandled Touch Frame Event"); */
1583 _e_input_aux_data_event_free(void *user_data EINA_UNUSED, void *ev)
1585 Ecore_Event_Axis_Update *e = (Ecore_Event_Axis_Update *)ev;
1587 if (e->axis) free(e->axis);
1588 if (e->dev) ecore_device_unref(e->dev);
1594 _device_handle_touch_aux_data(struct libinput_device *device, struct libinput_event_touch_aux_data *event)
1596 E_Input_Evdev *edev;
1597 E_Input_Backend *input;
1598 Ecore_Event_Axis_Update *ev;
1600 Ecore_Device *ecore_dev = NULL, *data;
1602 E_Comp_Config *comp_conf;
1604 if (libinput_event_touch_aux_data_get_type(event) != LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM &&
1605 libinput_event_touch_aux_data_get_value(event) > 0)
1608 if (!(edev = libinput_device_get_user_data(device))) goto end;
1609 if (!(input = edev->seat->input)) goto end;
1611 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1612 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1614 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1616 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1625 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1626 ecore_dev = edev->ecore_dev;
1631 ERR("Failed to get source ecore device from event !\n");
1635 if (!(ev = calloc(1, sizeof(Ecore_Event_Axis_Update))))goto end;
1637 ev->window = (Ecore_Window)input->dev->window;
1638 ev->event_window = (Ecore_Window)input->dev->window;
1639 ev->root_window = (Ecore_Window)input->dev->window;
1640 ev->timestamp = libinput_event_touch_aux_data_get_time(event);
1642 axis = (Ecore_Axis *)calloc(1, sizeof(Ecore_Axis));
1645 axis->label = ECORE_AXIS_LABEL_TOUCH_PALM;
1646 axis->value = libinput_event_touch_aux_data_get_value(event);
1650 ev->dev = ecore_device_ref(ecore_dev);
1652 comp_conf = e_comp_config_get();
1653 if (comp_conf && comp_conf->input_log_enable)
1654 ELOGF("Touch", "Axis (label: %d, value: %lf)", NULL, axis?axis->label:-1, axis?axis->value:0.0);
1656 ecore_event_add(ECORE_EVENT_AXIS_UPDATE, ev, _e_input_aux_data_event_free, NULL);
1663 _e_input_evdev_device_create(E_Input_Seat *seat, struct libinput_device *device)
1665 E_Input_Evdev *edev;
1666 E_Input_Backend *b_input;
1668 EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
1670 /* try to allocate space for new evdev */
1671 if (!(edev = calloc(1, sizeof(E_Input_Evdev)))) return NULL;
1674 edev->device = device;
1675 edev->path = eina_stringshare_printf("%s/%s", e_input_base_dir_get(), libinput_device_get_sysname(device));
1677 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
1679 edev->caps |= E_INPUT_SEAT_KEYBOARD;
1680 _device_keyboard_setup(edev);
1683 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
1685 edev->caps |= E_INPUT_SEAT_POINTER;
1687 /* TODO: make this configurable */
1688 edev->mouse.threshold = 250;
1690 b_input = seat->input;
1691 if (b_input->left_handed == EINA_TRUE)
1693 if (libinput_device_config_left_handed_set(device, 1) !=
1694 LIBINPUT_CONFIG_STATUS_SUCCESS)
1696 WRN("Failed to set left hand mode about device: %s\n",
1697 libinput_device_get_name(device));
1702 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
1705 edev->caps |= E_INPUT_SEAT_TOUCH;
1706 palm_code = libinput_device_touch_aux_data_get_code(LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM);
1707 if (libinput_device_touch_has_aux_data(device, palm_code))
1709 libinput_device_touch_set_aux_data(device, palm_code);
1712 _device_touch_count_update(edev);
1714 edev->touch.coords = calloc(1, sizeof(E_Input_Coord)*e_input_touch_max_count_get());
1716 if (!edev->touch.coords)
1717 ERR("Failed to allocate memory for touch coords !\n");
1720 libinput_device_set_user_data(device, edev);
1721 libinput_device_ref(device);
1723 /* configure device */
1724 _device_configure(edev);
1730 _e_input_evdev_device_destroy(E_Input_Evdev *edev)
1734 EINA_SAFETY_ON_NULL_RETURN(edev);
1736 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
1738 if (edev->xkb.state) xkb_state_unref(edev->xkb.state);
1739 if (edev->xkb.keymap) xkb_map_unref(edev->xkb.keymap);
1742 if (edev->ecore_dev) ecore_device_del(edev->ecore_dev);
1743 if (edev->ecore_dev_list)
1744 EINA_LIST_FREE(edev->ecore_dev_list, dev)
1746 ecore_device_del(dev);
1748 if (edev->path) eina_stringshare_del(edev->path);
1749 if (edev->device) libinput_device_unref(edev->device);
1750 if (edev->key_remap_hash) eina_hash_free(edev->key_remap_hash);
1751 if (edev->touch.coords)
1753 free(edev->touch.coords);
1754 edev->touch.coords = NULL;
1761 _e_input_evdev_event_process(struct libinput_event *event)
1763 struct libinput_device *device;
1764 Eina_Bool ret = EINA_TRUE;
1766 device = libinput_event_get_device(event);
1767 switch (libinput_event_get_type(event))
1769 case LIBINPUT_EVENT_KEYBOARD_KEY:
1770 _device_handle_key(device, libinput_event_get_keyboard_event(event));
1772 case LIBINPUT_EVENT_POINTER_MOTION:
1773 _device_handle_pointer_motion(device,
1774 libinput_event_get_pointer_event(event));
1776 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
1777 _device_handle_pointer_motion_absolute(device,
1778 libinput_event_get_pointer_event(event));
1780 case LIBINPUT_EVENT_POINTER_BUTTON:
1781 _device_handle_button(device, libinput_event_get_pointer_event(event));
1783 case LIBINPUT_EVENT_POINTER_AXIS:
1784 _device_handle_axis(device, libinput_event_get_pointer_event(event));
1786 case LIBINPUT_EVENT_TOUCH_DOWN:
1787 _device_handle_touch_down(device, libinput_event_get_touch_event(event));
1789 case LIBINPUT_EVENT_TOUCH_MOTION:
1790 _device_handle_touch_motion(device,
1791 libinput_event_get_touch_event(event));
1793 case LIBINPUT_EVENT_TOUCH_UP:
1794 _device_handle_touch_up(device, libinput_event_get_touch_event(event));
1796 case LIBINPUT_EVENT_TOUCH_CANCEL:
1797 _device_handle_touch_cancel(device, libinput_event_get_touch_event(event));
1799 case LIBINPUT_EVENT_TOUCH_FRAME:
1800 _device_handle_touch_frame(device, libinput_event_get_touch_event(event));
1802 case LIBINPUT_EVENT_TOUCH_AUX_DATA:
1803 _device_handle_touch_aux_data(device, libinput_event_get_touch_aux_data(event));
1814 * @brief Set the axis size of the given device.
1816 * @param dev The device to set the axis size to.
1817 * @param w The width of the axis.
1818 * @param h The height of the axis.
1820 * This function sets set the width @p w and height @p h of the axis
1821 * of device @p dev. If @p dev is a relative input device, a width and
1822 * height must set for it. If its absolute set the ioctl correctly, if
1823 * not, unsupported device.
1826 e_input_evdev_axis_size_set(E_Input_Evdev *edev, int w, int h)
1828 const char *sysname;
1833 enum libinput_config_status status;
1835 EINA_SAFETY_ON_NULL_RETURN(edev);
1836 EINA_SAFETY_ON_TRUE_RETURN((w == 0) || (h == 0));
1838 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
1839 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
1842 sysname = libinput_device_get_sysname(edev->device);
1844 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
1845 if (eina_list_count(devices) < 1) return;
1847 EINA_LIST_FREE(devices, device)
1849 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
1851 (sscanf(vals, "%f %f %f %f %f %f",
1852 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
1859 libinput_device_config_calibration_set_matrix(edev->device, cal);
1861 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
1862 ERR("Failed to apply calibration");
1865 eina_stringshare_del(device);
1871 e_input_evdev_name_get(E_Input_Evdev *evdev)
1873 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
1874 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
1876 return libinput_device_get_name(evdev->device);
1879 EINTERN const char *
1880 e_input_evdev_sysname_get(E_Input_Evdev *evdev)
1882 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
1883 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
1885 return libinput_device_get_sysname(evdev->device);
1889 e_input_evdev_key_remap_enable(E_Input_Evdev *edev, Eina_Bool enable)
1891 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
1892 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
1894 edev->key_remap_enabled = enable;
1896 if (enable == EINA_FALSE && edev->key_remap_hash)
1898 eina_hash_free(edev->key_remap_hash);
1899 edev->key_remap_hash = NULL;
1906 e_input_evdev_key_remap_set(E_Input_Evdev *edev, int *from_keys, int *to_keys, int num)
1910 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
1911 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
1912 EINA_SAFETY_ON_NULL_RETURN_VAL(from_keys, EINA_FALSE);
1913 EINA_SAFETY_ON_NULL_RETURN_VAL(to_keys, EINA_FALSE);
1914 EINA_SAFETY_ON_TRUE_RETURN_VAL(num <= 0, EINA_FALSE);
1915 EINA_SAFETY_ON_TRUE_RETURN_VAL(!edev->key_remap_enabled, EINA_FALSE);
1917 if (edev->key_remap_hash == NULL)
1918 edev->key_remap_hash = eina_hash_int32_new(NULL);
1920 if (edev->key_remap_hash == NULL)
1922 ERR("Failed to set remap key information : creating a hash is failed.");
1926 for (i = 0; i < num ; i++)
1928 if (!from_keys[i] || !to_keys[i])
1930 ERR("Failed to set remap key information : given arguments are invalid.");
1935 for (i = 0; i < num ; i++)
1937 eina_hash_add(edev->key_remap_hash, &from_keys[i], (void *)(intptr_t)to_keys[i]);
1944 e_input_evdev_wheel_click_angle_get(E_Input_Evdev *dev)
1946 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, -1);
1947 return libinput_device_config_scroll_get_wheel_click_angle(dev->device);
1951 e_input_evdev_touch_calibration_set(E_Input_Evdev *edev, float matrix[6])
1953 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
1954 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
1956 if (!libinput_device_config_calibration_has_matrix(edev->device) ||
1957 !libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_TOUCH))
1960 if (libinput_device_config_calibration_set_matrix(edev->device, matrix) !=
1961 LIBINPUT_CONFIG_STATUS_SUCCESS)
1963 WRN("Failed to set input transformation about device: %s\n",
1964 libinput_device_get_name(edev->device));
1972 e_input_evdev_mouse_accel_speed_set(E_Input_Evdev *edev, double speed)
1974 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
1975 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
1977 if (!libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
1980 if (!libinput_device_config_accel_is_available(edev->device))
1983 if (libinput_device_config_accel_set_speed(edev->device, speed) !=
1984 LIBINPUT_CONFIG_STATUS_SUCCESS)
1986 WRN("Failed to set mouse accel about device: %s\n",
1987 libinput_device_get_name(edev->device));
1994 EINTERN unsigned int
1995 e_input_evdev_touch_pressed_get(E_Input_Evdev *edev)
1997 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, 0x0);
1999 return edev->touch.pressed;