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 /* create keymap from xkb context */
215 edev->xkb.keymap = _e_input_device_cached_keymap_get(input->dev->xkb_ctx, NULL, 0);
216 if (!edev->xkb.keymap)
218 ERR("Failed to create keymap: %m");
222 /* create xkb state */
223 if (!(edev->xkb.state = xkb_state_new(edev->xkb.keymap)))
225 ERR("Failed to create xkb state: %m");
229 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CTRL);
230 if (xkb_idx != XKB_MOD_INVALID)
231 edev->xkb.ctrl_mask = 1 << xkb_idx;
233 edev->xkb.ctrl_mask = 0;
235 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_ALT);
236 if (xkb_idx != XKB_MOD_INVALID)
237 edev->xkb.alt_mask = 1 << xkb_idx;
239 edev->xkb.alt_mask = 0;
241 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_SHIFT);
242 if (xkb_idx != XKB_MOD_INVALID)
243 edev->xkb.shift_mask = 1 << xkb_idx;
245 edev->xkb.shift_mask = 0;
247 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_LOGO);
248 if (xkb_idx != XKB_MOD_INVALID)
249 edev->xkb.win_mask = 1 << xkb_idx;
251 edev->xkb.win_mask = 0;
253 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_SCROLL);
254 if (xkb_idx != XKB_MOD_INVALID)
255 edev->xkb.scroll_mask = 1 << xkb_idx;
257 edev->xkb.scroll_mask = 0;
259 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_NUM);
260 if (xkb_idx != XKB_MOD_INVALID)
261 edev->xkb.num_mask = 1 << xkb_idx;
263 edev->xkb.num_mask = 0;
265 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CAPS);
266 if (xkb_idx != XKB_MOD_INVALID)
267 edev->xkb.caps_mask = 1 << xkb_idx;
269 edev->xkb.caps_mask = 0;
271 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, "ISO_Level3_Shift");
272 if (xkb_idx != XKB_MOD_INVALID)
273 edev->xkb.altgr_mask = 1 << xkb_idx;
275 edev->xkb.altgr_mask = 0;
279 _device_keysym_translate(xkb_keysym_t keysym, unsigned int modifiers, char *buffer, int bytes)
281 unsigned long hbytes = 0;
284 if (!keysym) return 0;
285 hbytes = (keysym >> 8);
290 (((keysym >= XKB_KEY_BackSpace) && (keysym <= XKB_KEY_Clear)) ||
291 (keysym == XKB_KEY_Return) || (keysym == XKB_KEY_Escape) ||
292 (keysym == XKB_KEY_KP_Space) || (keysym == XKB_KEY_KP_Tab) ||
293 (keysym == XKB_KEY_KP_Enter) ||
294 ((keysym >= XKB_KEY_KP_Multiply) && (keysym <= XKB_KEY_KP_9)) ||
295 (keysym == XKB_KEY_KP_Equal) || (keysym == XKB_KEY_Delete))))))
298 if (keysym == XKB_KEY_KP_Space)
299 c = (XKB_KEY_space & 0x7F);
300 else if (hbytes == 0xFF)
305 if (modifiers & ECORE_EVENT_MODIFIER_CTRL)
307 if (((c >= '@') && (c < '\177')) || c == ' ')
311 else if ((c >= '3') && (c <= '7'))
323 _device_modifiers_update_device(E_Input_Evdev *edev, E_Input_Evdev *from)
327 edev->xkb.depressed =
328 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_DEPRESSED);
330 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LATCHED);
332 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LOCKED);
334 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_EFFECTIVE);
336 mask = (edev->xkb.depressed | edev->xkb.latched);
338 if (mask & from->xkb.ctrl_mask)
339 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_CTRL;
340 if (mask & from->xkb.alt_mask)
341 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALT;
342 if (mask & from->xkb.shift_mask)
343 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
344 if (mask & from->xkb.win_mask)
345 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_WIN;
346 if (mask & from->xkb.scroll_mask)
347 edev->xkb.modifiers |= ECORE_EVENT_LOCK_SCROLL;
348 if (mask & from->xkb.num_mask)
349 edev->xkb.modifiers |= ECORE_EVENT_LOCK_NUM;
350 if (mask & from->xkb.caps_mask)
351 edev->xkb.modifiers |= ECORE_EVENT_LOCK_CAPS;
352 if (mask & from->xkb.altgr_mask)
353 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALTGR;
357 _device_modifiers_update(E_Input_Evdev *edev)
362 edev->xkb.modifiers = 0;
364 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
365 _device_modifiers_update_device(edev, edev);
368 EINA_LIST_FOREACH(edev->seat->devices, l, ed)
370 if (!(ed->caps & E_INPUT_SEAT_KEYBOARD)) continue;
371 _device_modifiers_update_device(edev, ed);
378 _device_remapped_key_get(E_Input_Evdev *edev, int code)
382 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, code);
383 if (!edev->key_remap_enabled) return code;
384 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->key_remap_hash, code);
386 ret = eina_hash_find(edev->key_remap_hash, &code);
388 if (ret) code = (int)(intptr_t)ret;
394 e_input_evdev_get_e_device(const char *path, Ecore_Device_Class clas)
396 const GList *dev_list = NULL;
398 E_Device *dev = NULL;
399 const char *identifier;
401 if (!path) return NULL;
403 dev_list = e_device_list_get();
404 if (!dev_list) return NULL;
405 for (l = dev_list, dev = dev_list->data;
407 l = g_list_next(l), dev = l->data)
410 identifier = e_device_identifier_get(dev);
411 if (!identifier) continue;
412 if ((e_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
419 EINTERN Ecore_Device *
420 e_input_evdev_get_ecore_device(const char *path, Ecore_Device_Class clas)
422 const Eina_List *dev_list = NULL;
424 Ecore_Device *dev = NULL;
425 const char *identifier;
427 if (!path) return NULL;
429 dev_list = ecore_device_list();
430 if (!dev_list) return NULL;
431 EINA_LIST_FOREACH(dev_list, l, dev)
434 identifier = ecore_device_identifier_get(dev);
435 if (!identifier) continue;
436 if ((ecore_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
443 _e_input_event_mouse_move_cb_free(void *data EINA_UNUSED, void *event)
445 Ecore_Event_Mouse_Move *ev = event;
447 if (ev->dev) ecore_device_unref(ev->dev);
453 _e_input_event_mouse_wheel_cb_free(void *data EINA_UNUSED, void *event)
455 Ecore_Event_Mouse_Wheel *ev = event;
457 if (ev->dev) ecore_device_unref(ev->dev);
463 _e_input_event_mouse_button_cb_free(void *data EINA_UNUSED, void *event)
465 Ecore_Event_Mouse_Button *ev = event;
467 if (ev->dev) ecore_device_unref(ev->dev);
473 _e_input_event_key_cb_free(void *data EINA_UNUSED, void *event)
475 Ecore_Event_Key *ev = event;
477 if (e_input_thread_mode_get())
479 if (ev->dev) g_object_unref(ev->dev);
483 if (ev->dev) ecore_device_unref(ev->dev);
486 if (ev->data) E_FREE(ev->data);
492 _device_handle_key(struct libinput_device *device, struct libinput_event_keyboard *event)
495 E_Input_Backend *input;
497 uint32_t code, nsyms;
498 const xkb_keysym_t *syms;
499 enum libinput_key_state state;
501 xkb_keysym_t sym = XKB_KEY_NoSymbol;
502 char key[256] = {0, }, keyname[256] = {0, }, compose_buffer[256] = {0, };
504 char *tmp = NULL, *compose = NULL;
505 E_Keyrouter_Event_Data *key_data;
506 Ecore_Device *ecore_dev = NULL, *data;
507 E_Device *e_dev = NULL, *e_dev_data;
508 Eina_List *l = NULL, *l_next = NULL;
510 E_Comp_Config *comp_conf = NULL;
511 int *pressed_keycode = NULL, *idata = NULL;
512 Eina_Bool dup_found = EINA_FALSE;
514 if (!(edev = libinput_device_get_user_data(device)))
519 if (!(input = edev->seat->input))
524 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
525 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
527 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
529 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_KEYBOARD)
538 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
539 ecore_dev = edev->ecore_dev;
544 ERR("Failed to get source ecore device from event !\n");
548 if (edev->e_dev) e_dev = edev->e_dev;
549 else if (edev->e_dev_list && g_list_length(edev->e_dev_list) > 0)
551 for (glist = edev->e_dev_list, e_dev_data = edev->e_dev_list->data;
553 glist = g_list_next(l), e_dev_data = l->data)
555 if (e_device_class_get(e_dev_data) == ECORE_DEVICE_CLASS_KEYBOARD)
564 edev->e_dev = e_input_evdev_get_e_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
570 ERR("Failed to get source e device from event !\n");
574 timestamp = libinput_event_keyboard_get_time(event);
575 code = libinput_event_keyboard_get_key(event);
576 code = _device_remapped_key_get(edev, code + 8);
577 state = libinput_event_keyboard_get_key_state(event);
578 key_count = libinput_event_keyboard_get_seat_key_count(event);
580 if (state == LIBINPUT_KEY_STATE_PRESSED)
582 if ((edev->seat->dev->blocked & E_INPUT_SEAT_KEYBOARD) ||
583 (edev->seat->dev->server_blocked & E_INPUT_SEAT_KEYBOARD))
585 ELOGF("Key", "Press (keycode: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
586 code, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
587 edev->seat->dev->server_blocked);
591 /* FIXME: Currently to maintain press/release event pair during input block,
592 * used Eina_List and this is method used in devicemgr module.
593 * But we need to consider which way is better to maintain key press/release pair.
596 EINA_LIST_FOREACH(edev->xkb.pressed_keys, l, idata)
600 dup_found = EINA_TRUE;
606 pressed_keycode = E_NEW(int, 1);
607 EINA_SAFETY_ON_NULL_RETURN(pressed_keycode);
608 *pressed_keycode = code;
610 edev->xkb.pressed_keys = eina_list_append(edev->xkb.pressed_keys, pressed_keycode);
615 dup_found = EINA_FALSE;
616 EINA_LIST_FOREACH_SAFE(edev->xkb.pressed_keys, l, l_next, idata)
620 edev->xkb.pressed_keys = eina_list_remove_list(edev->xkb.pressed_keys, l);
622 dup_found = EINA_TRUE;
628 ELOGF("Key", "Release (keycode: %d, device: %s) is blocked by %p", NULL,
629 code, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client);
634 /* ignore key events that are not seat wide state changes */
635 if (((state == LIBINPUT_KEY_STATE_PRESSED) && (key_count != 1)) ||
636 ((state == LIBINPUT_KEY_STATE_RELEASED) && (key_count != 0)))
641 xkb_state_update_key(edev->xkb.state, code,
642 (state ? XKB_KEY_DOWN : XKB_KEY_UP));
644 /* get the keysym for this code */
645 nsyms = xkb_key_get_syms(edev->xkb.state, code, &syms);
646 if (nsyms == 1) sym = syms[0];
648 /* If no keysym was found, name it "Keycode-NNN" */
649 if (sym == XKB_KEY_NoSymbol)
650 snprintf(key, sizeof(key), "Keycode-%u", code);
653 /* get the keyname for this sym */
654 xkb_keysym_get_name(sym, key, sizeof(key));
659 /* If no keyname was found, name it "Keycode-NNN" */
660 snprintf(keyname, sizeof(keyname), "Keycode-%u", code);
664 memcpy(keyname, key, sizeof(keyname));
667 /* if shift is active, we need to transform the key to lower */
668 if (xkb_state_mod_index_is_active(edev->xkb.state,
669 xkb_map_mod_get_index(edev->xkb.keymap,
671 XKB_STATE_MODS_EFFECTIVE))
673 if (keyname[0] != '\0')
674 keyname[0] = tolower(keyname[0]);
677 if (_device_keysym_translate(sym, edev->xkb.modifiers,
678 compose_buffer, sizeof(compose_buffer)))
680 compose = eina_str_convert("ISO8859-1", "UTF-8", compose_buffer);
683 ERR("E Input cannot convert input key string '%s' to UTF-8. "
684 "Is Eina built with iconv support?", compose_buffer);
690 if (!compose) compose = compose_buffer;
692 e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) +
693 ((compose[0] != '\0') ? strlen(compose) : 0) + 3);
699 key_data = E_NEW(E_Keyrouter_Event_Data, 1);
707 e->keyname = (char *)(e + 1);
708 e->key = e->keyname + strlen(keyname) + 1;
709 e->compose = strlen(compose) ? e->key + strlen(key) + 1 : NULL;
710 e->string = e->compose;
712 strncpy((char *)e->keyname, keyname, strlen(keyname));
713 strncpy((char *)e->key, key, strlen(key));
714 if (strlen(compose)) strncpy((char *)e->compose, compose, strlen(compose));
716 e->window = (Ecore_Window)input->dev->window;
717 e->event_window = (Ecore_Window)input->dev->window;
718 e->root_window = (Ecore_Window)input->dev->window;
719 e->timestamp = timestamp;
724 _device_modifiers_update(edev);
726 e->modifiers = edev->xkb.modifiers;
728 comp_conf = e_comp_config_get();
730 if (e_input_thread_mode_get())
732 e->dev = (Eo *)g_object_ref(e_dev);
733 if (comp_conf && comp_conf->input_log_enable)
734 ELOGF("Key", "%s (keyname: %s, keycode: %d, device: %s)", NULL, state?"Press":"Release", e->keyname, e->keycode, e_device_name_get(e_dev));
736 e_input_event_add(input->event_source, state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
740 e->dev = ecore_device_ref(ecore_dev);
741 if (comp_conf && comp_conf->input_log_enable)
742 ELOGF("Key", "%s (keyname: %s, keycode: %d, device: %s)", NULL, state?"Press":"Release", e->keyname, e->keycode, ecore_device_name_get(ecore_dev));
744 ecore_event_add(state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
750 _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event)
752 E_Input_Backend *input;
753 Ecore_Event_Mouse_Move *ev;
754 Ecore_Device *ecore_dev = NULL, *data, *detent_data = NULL;
756 int x = 0, y = 0, w = 0, h = 0;
758 if (!(input = edev->seat->input)) return;
760 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
761 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
763 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
765 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
770 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
775 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
777 ecore_dev = detent_data;
782 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
783 ecore_dev = edev->ecore_dev;
788 ERR("Failed to get source ecore device from event !\n");
791 else if ((detent_data == ecore_dev) || e_devicemgr_detent_is_detent(ecore_device_name_get(ecore_dev)))
793 /* Do not process detent device's move events. */
797 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
799 _device_configured_size_get(edev, &x, &y, &w, &h);
801 if (edev->seat->ptr.ix < x)
802 edev->seat->ptr.dx = edev->seat->ptr.ix = x;
803 else if (edev->seat->ptr.ix >= (x + w))
804 edev->seat->ptr.dx = edev->seat->ptr.ix = (x + w - 1);
806 if (edev->seat->ptr.iy < y)
807 edev->seat->ptr.dy = edev->seat->ptr.iy = y;
808 else if (edev->seat->ptr.iy >= (y + h))
809 edev->seat->ptr.dy = edev->seat->ptr.iy = (y + h - 1);
811 edev->mouse.dx = edev->seat->ptr.dx;
812 edev->mouse.dy = edev->seat->ptr.dy;
814 ev->window = (Ecore_Window)input->dev->window;
815 ev->event_window = (Ecore_Window)input->dev->window;
816 ev->root_window = (Ecore_Window)input->dev->window;
817 if (event) ev->timestamp = libinput_event_pointer_get_time(event);
820 _device_modifiers_update(edev);
821 ev->modifiers = edev->xkb.modifiers;
823 ev->x = edev->seat->ptr.ix;
824 ev->y = edev->seat->ptr.iy;
828 ev->multi.device = edev->mt_slot;
829 ev->multi.radius = 1;
830 ev->multi.radius_x = 1;
831 ev->multi.radius_y = 1;
832 ev->multi.pressure = 1.0;
833 ev->multi.angle = 0.0;
836 ev->multi.root.x = ev->x;
837 ev->multi.root.y = ev->y;
839 ecore_thread_main_loop_begin();
841 ev->dev = ecore_device_ref(ecore_dev);
843 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
845 ecore_thread_main_loop_end();
849 _e_input_pointer_motion_post(E_Input_Evdev *edev)
851 _device_pointer_motion(edev, NULL);
855 _device_pointer_relative_motion_send(double dx[2], double dy[2], uint64_t time_us)
857 e_input_relative_motion_cb func = e_input_relative_motion_handler_get();
858 if (func) func(dx, dy, time_us);
862 _device_handle_pointer_motion(struct libinput_device *device, struct libinput_event_pointer *event)
865 double delta_x[2]; /* delta_x[0] for accelerated, delta_x[1] for unaccelerated */
866 double delta_y[2]; /* delta_y[0] for accelerated, delta_y[1] for unaccelerated */
869 if (!(edev = libinput_device_get_user_data(device)))
874 delta_x[0] = libinput_event_pointer_get_dx(event);
875 delta_x[1] = libinput_event_pointer_get_dx_unaccelerated(event);
876 delta_y[0] = libinput_event_pointer_get_dy(event);
877 delta_y[1] = libinput_event_pointer_get_dy_unaccelerated(event);
879 if (edev->disable_acceleration)
890 if (edev->seat->ptr.swap)
896 if (edev->seat->ptr.invert_x)
898 if (edev->seat->ptr.invert_y)
901 edev->seat->ptr.dx += dx;
902 edev->seat->ptr.dy += dy;
904 edev->mouse.dx = edev->seat->ptr.dx;
905 edev->mouse.dy = edev->seat->ptr.dy;
907 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
908 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
913 edev->seat->ptr.ix = edev->seat->ptr.dx;
914 edev->seat->ptr.iy = edev->seat->ptr.dy;
916 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
917 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
922 _device_pointer_relative_motion_send(&delta_x[0], &delta_y[0],
923 libinput_event_pointer_get_time_usec(event));
924 _device_pointer_motion(edev, event);
928 _device_handle_pointer_motion_absolute(struct libinput_device *device, struct libinput_event_pointer *event)
933 if (!(edev = libinput_device_get_user_data(device)))
938 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
940 edev->mouse.dx = edev->seat->ptr.dx =
941 libinput_event_pointer_get_absolute_x_transformed(event, w);
942 edev->mouse.dy = edev->seat->ptr.dy =
943 libinput_event_pointer_get_absolute_y_transformed(event, h);
945 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
946 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
951 edev->seat->ptr.ix = edev->seat->ptr.dx;
952 edev->seat->ptr.iy = edev->seat->ptr.dy;
954 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
955 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
960 _device_pointer_motion(edev, event);
964 _device_handle_button(struct libinput_device *device, struct libinput_event_pointer *event)
967 E_Input_Backend *input;
968 Ecore_Event_Mouse_Button *ev;
969 enum libinput_button_state state;
970 uint32_t button, timestamp;
971 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
973 E_Comp_Config *comp_conf = NULL;
975 if (!(edev = libinput_device_get_user_data(device)))
979 if (!(input = edev->seat->input))
984 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
985 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
987 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
989 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
994 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
999 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1001 ecore_dev = detent_data;
1006 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1007 ecore_dev = edev->ecore_dev;
1012 ERR("Failed to get source ecore device from event !\n");
1016 state = libinput_event_pointer_get_button_state(event);
1017 button = libinput_event_pointer_get_button(event);
1018 timestamp = libinput_event_pointer_get_time(event);
1020 button = ((button & 0x00F) + 1);
1021 if (button == 3) button = 2;
1022 else if (button == 2) button = 3;
1026 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1027 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1029 ELOGF("Mouse", "Button Press (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
1030 button, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
1031 edev->seat->dev->server_blocked);
1036 edev->mouse.pressed_button |= (1 << button);
1041 if (!(edev->mouse.pressed_button & (1 << button)))
1043 ELOGF("Mouse", "Button Release (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
1044 button, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
1045 edev->seat->dev->server_blocked);
1048 edev->mouse.pressed_button &= ~(1 << button);
1051 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button))))
1056 ev->window = (Ecore_Window)input->dev->window;
1057 ev->event_window = (Ecore_Window)input->dev->window;
1058 ev->root_window = (Ecore_Window)input->dev->window;
1059 ev->timestamp = timestamp;
1060 ev->same_screen = 1;
1062 _device_modifiers_update(edev);
1063 ev->modifiers = edev->xkb.modifiers;
1065 ev->x = edev->seat->ptr.ix;
1066 ev->y = edev->seat->ptr.iy;
1070 ev->multi.device = edev->mt_slot;
1071 ev->multi.radius = 1;
1072 ev->multi.radius_x = 1;
1073 ev->multi.radius_y = 1;
1074 ev->multi.pressure = 1.0;
1075 ev->multi.angle = 0.0;
1076 ev->multi.x = ev->x;
1077 ev->multi.y = ev->y;
1078 ev->multi.root.x = ev->x;
1079 ev->multi.root.y = ev->y;
1081 ecore_thread_main_loop_begin();
1083 ev->dev = ecore_device_ref(ecore_dev);
1087 unsigned int current;
1089 current = timestamp;
1090 edev->mouse.did_double = EINA_FALSE;
1091 edev->mouse.did_triple = EINA_FALSE;
1093 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1094 (button == edev->mouse.prev_button))
1096 edev->mouse.did_double = EINA_TRUE;
1097 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1098 (button == edev->mouse.last_button))
1100 edev->mouse.did_triple = EINA_TRUE;
1101 edev->mouse.prev = 0;
1102 edev->mouse.last = 0;
1107 edev->mouse.last = edev->mouse.prev;
1108 edev->mouse.prev = current;
1109 edev->mouse.last_button = edev->mouse.prev_button;
1110 edev->mouse.prev_button = button;
1113 ev->buttons = button;
1115 if (edev->mouse.did_double)
1116 ev->double_click = 1;
1117 if (edev->mouse.did_triple)
1118 ev->triple_click = 1;
1120 comp_conf = e_comp_config_get();
1121 if (comp_conf && comp_conf->input_log_enable)
1122 ELOGF("Mouse", "Button %s (btn: %d, device: %s)", NULL, state?"Press":"Release", button, ecore_device_name_get(ev->dev));
1125 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, _e_input_event_mouse_button_cb_free, NULL);
1127 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, _e_input_event_mouse_button_cb_free, NULL);
1129 ecore_thread_main_loop_end();
1132 #if !LIBINPUT_HAVE_SCROLL_VALUE_V120
1134 _axis_value_get(struct libinput_event_pointer *pointer_event, enum libinput_pointer_axis axis)
1136 enum libinput_pointer_axis_source source;
1137 double value = 0.0, value_discrete = 0.0;
1139 E_Comp_Config *comp_conf = NULL;
1141 comp_conf = e_comp_config_get();
1142 source = libinput_event_pointer_get_axis_source(pointer_event);
1145 case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL:
1146 value_discrete = libinput_event_pointer_get_axis_value_discrete(pointer_event, axis);
1147 value = libinput_event_pointer_get_axis_value(pointer_event, axis);
1148 if (comp_conf && comp_conf->input_log_enable)
1150 ELOGF("Axis", "SOURCE_WHEEL discrete: %lf (cf. value: %lf)", NULL, value_discrete, value);
1152 ret = (int)value_discrete;
1154 case LIBINPUT_POINTER_AXIS_SOURCE_FINGER:
1155 case LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS:
1156 value = libinput_event_pointer_get_axis_value(pointer_event, axis);
1157 if (comp_conf && comp_conf->input_log_enable)
1159 ELOGF("Axis", "SOURCE_FINGER/CONTINUOUS value: %lf", NULL, value);
1161 if (value >= E_INPUT_FINGER_SCROLL_THRESHOLD)
1163 else if (value <= E_INPUT_FINGER_SCROLL_THRESHOLD * (-1))
1176 _device_handle_axis(struct libinput_device *device, struct libinput_event_pointer *event)
1178 E_Input_Evdev *edev;
1179 E_Input_Backend *input;
1180 Ecore_Event_Mouse_Wheel *ev;
1182 enum libinput_pointer_axis axis;
1183 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1185 E_Comp_Config *comp_conf = NULL;
1186 int direction = 0, z = 0;
1188 if (!(edev = libinput_device_get_user_data(device)))
1192 if (!(input = edev->seat->input))
1197 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1198 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1200 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1202 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1207 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1212 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1214 ecore_dev = detent_data;
1219 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1220 ecore_dev = edev->ecore_dev;
1225 ERR("Failed to get source ecore device from event !\n");
1229 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1230 if (libinput_event_pointer_has_axis(event, axis))
1231 z = _axis_value_get(event, axis);
1233 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1234 if (libinput_event_pointer_has_axis(event, axis))
1237 z = _axis_value_get(event, axis);
1242 ELOGF("Mouse", "Axis event is ignored since it has zero value", NULL);
1246 comp_conf = e_comp_config_get();
1247 if (comp_conf && comp_conf->e_wheel_click_angle)
1249 z = (int)(z * comp_conf->e_wheel_click_angle);
1252 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1253 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1256 ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1257 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1259 ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1260 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1264 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1269 timestamp = libinput_event_pointer_get_time(event);
1271 ev->window = (Ecore_Window)input->dev->window;
1272 ev->event_window = (Ecore_Window)input->dev->window;
1273 ev->root_window = (Ecore_Window)input->dev->window;
1274 ev->timestamp = timestamp;
1275 ev->same_screen = 1;
1277 _device_modifiers_update(edev);
1278 ev->modifiers = edev->xkb.modifiers;
1280 ev->x = edev->seat->ptr.ix;
1281 ev->y = edev->seat->ptr.iy;
1285 ev->direction = direction;
1287 if (comp_conf && comp_conf->input_log_enable)
1290 ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1292 ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1295 ecore_thread_main_loop_begin();
1296 ev->dev = ecore_device_ref(ecore_dev);
1297 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1298 ecore_thread_main_loop_end();
1302 #if LIBINPUT_HAVE_SCROLL_VALUE_V120
1304 _scroll_value_get(struct libinput_event_pointer *pointer_event, enum libinput_pointer_axis axis, E_Input_Axis_Source source)
1307 double value_v120 = 0.0;
1309 E_Comp_Config *comp_conf = NULL;
1311 comp_conf = e_comp_config_get();
1314 case E_INPUT_AXIS_SOURCE_WHEEL:
1315 value_v120 = libinput_event_pointer_get_scroll_value_v120(pointer_event, axis);
1316 value = libinput_event_pointer_get_scroll_value(pointer_event, axis);
1317 if (comp_conf && comp_conf->input_log_enable)
1319 ELOGF("Scroll", "SOURCE_WHEELL value_v120: %lf (cf. value: %lf)", NULL, value_v120, value);
1321 if (((int)value_v120 % E_INPUT_POINTER_AXIS_DISCRETE_STEP) != 0)
1323 ERR("Wheel movements should be multiples (or fractions) of 120!\n");
1328 ret = value_v120 / E_INPUT_POINTER_AXIS_DISCRETE_STEP;
1331 case E_INPUT_AXIS_SOURCE_FINGER:
1332 case E_INPUT_AXIS_SOURCE_CONTINUOUS:
1333 value = libinput_event_pointer_get_scroll_value(pointer_event, axis);
1334 if (comp_conf && comp_conf->input_log_enable)
1336 ELOGF("Scroll", "SOURCE_FINGER/CONTINUOUS value: %lf", NULL, value);
1338 if (value >= E_INPUT_FINGER_SCROLL_THRESHOLD)
1340 else if (value <= E_INPUT_FINGER_SCROLL_THRESHOLD * (-1))
1353 _device_handle_axis_v120(struct libinput_device *device, struct libinput_event_pointer *event, E_Input_Axis_Source source)
1355 E_Input_Evdev *edev;
1356 E_Input_Backend *input;
1357 Ecore_Event_Mouse_Wheel *ev;
1359 enum libinput_pointer_axis axis;
1360 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1362 E_Comp_Config *comp_conf = NULL;
1363 int direction = 0, z = 0;
1365 if (!(edev = libinput_device_get_user_data(device)))
1369 if (!(input = edev->seat->input))
1374 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1375 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1377 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1379 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1384 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1389 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1391 ecore_dev = detent_data;
1396 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1397 ecore_dev = edev->ecore_dev;
1402 ERR("Failed to get source ecore device from event !\n");
1406 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1407 if (libinput_event_pointer_has_axis(event, axis))
1408 z = _scroll_value_get(event, axis, source);
1410 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1411 if (libinput_event_pointer_has_axis(event, axis))
1414 z = _scroll_value_get(event, axis, source);
1419 ELOGF("Mouse", "Scroll event is ignored since it has zero value", NULL);
1423 comp_conf = e_comp_config_get();
1424 if (comp_conf && comp_conf->e_wheel_click_angle)
1426 z = (int)(z * comp_conf->e_wheel_click_angle);
1429 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1430 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1433 ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1434 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1436 ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1437 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1441 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1446 timestamp = libinput_event_pointer_get_time(event);
1448 ev->window = (Ecore_Window)input->dev->window;
1449 ev->event_window = (Ecore_Window)input->dev->window;
1450 ev->root_window = (Ecore_Window)input->dev->window;
1451 ev->timestamp = timestamp;
1452 ev->same_screen = 1;
1454 _device_modifiers_update(edev);
1455 ev->modifiers = edev->xkb.modifiers;
1457 ev->x = edev->seat->ptr.ix;
1458 ev->y = edev->seat->ptr.iy;
1462 ev->direction = direction;
1464 if (comp_conf && comp_conf->input_log_enable)
1467 ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1469 ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1472 ecore_thread_main_loop_begin();
1473 ev->dev = ecore_device_ref(ecore_dev);
1474 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1475 ecore_thread_main_loop_end();
1480 _device_handle_touch_event_send(E_Input_Evdev *edev, struct libinput_event_touch *event, int state)
1482 E_Input_Backend *input;
1483 Ecore_Event_Mouse_Button *ev;
1484 uint32_t timestamp, button = 0;
1485 Ecore_Device *ecore_dev = NULL, *data;
1489 if (!(input = edev->seat->input)) return;
1491 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1492 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1494 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1496 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1505 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1506 ecore_dev = edev->ecore_dev;
1511 ERR("Failed to get source ecore device from event !\n");
1515 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) return;
1517 timestamp = libinput_event_touch_get_time(event);
1519 ev->window = (Ecore_Window)input->dev->window;
1520 ev->event_window = (Ecore_Window)input->dev->window;
1521 ev->root_window = (Ecore_Window)input->dev->window;
1522 ev->timestamp = timestamp;
1523 ev->same_screen = 1;
1525 _device_modifiers_update(edev);
1526 ev->modifiers = edev->xkb.modifiers;
1528 ev->x = edev->seat->ptr.ix;
1529 ev->y = edev->seat->ptr.iy;
1533 ev->multi.device = edev->mt_slot;
1534 ev->multi.radius = 1;
1535 ev->multi.radius_x = 1;
1536 ev->multi.radius_y = 1;
1537 ev->multi.pressure = 1.0;
1538 ev->multi.angle = 0.0;
1539 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1540 if (libinput_event_get_type(libinput_event_touch_get_base_event(event))
1541 == LIBINPUT_EVENT_TOUCH_DOWN)
1543 if (libinput_event_touch_has_minor(event))
1544 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1545 if (libinput_event_touch_has_major(event))
1546 ev->multi.radius_y = libinput_event_touch_get_major(event);
1547 if (libinput_event_touch_has_pressure(event))
1548 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1549 if (libinput_event_touch_has_orientation(event))
1550 ev->multi.angle = libinput_event_touch_get_orientation(event);
1553 ev->multi.x = ev->x;
1554 ev->multi.y = ev->y;
1555 ev->multi.root.x = ev->x;
1556 ev->multi.root.y = ev->y;
1558 ecore_thread_main_loop_begin();
1560 ev->dev = ecore_device_ref(ecore_dev);
1562 if (state == ECORE_EVENT_MOUSE_BUTTON_DOWN)
1564 unsigned int current;
1566 current = timestamp;
1567 edev->mouse.did_double = EINA_FALSE;
1568 edev->mouse.did_triple = EINA_FALSE;
1570 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1571 (button == edev->mouse.prev_button))
1573 edev->mouse.did_double = EINA_TRUE;
1574 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1575 (button == edev->mouse.last_button))
1577 edev->mouse.did_triple = EINA_TRUE;
1578 edev->mouse.prev = 0;
1579 edev->mouse.last = 0;
1584 edev->mouse.last = edev->mouse.prev;
1585 edev->mouse.prev = current;
1586 edev->mouse.last_button = edev->mouse.prev_button;
1587 edev->mouse.prev_button = button;
1588 edev->touch.pressed |= (1 << ev->multi.device);
1592 edev->touch.pressed &= ~(1 << ev->multi.device);
1595 ev->buttons = ((button & 0x00F) + 1);
1597 if (edev->mouse.did_double)
1598 ev->double_click = 1;
1599 if (edev->mouse.did_triple)
1600 ev->triple_click = 1;
1602 ecore_event_add(state, ev, _e_input_event_mouse_button_cb_free, NULL);
1604 ecore_thread_main_loop_end();
1608 _device_handle_touch_motion_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1610 E_Input_Backend *input;
1611 Ecore_Event_Mouse_Move *ev;
1612 Ecore_Device *ecore_dev = NULL, *data;
1616 if (!(input = edev->seat->input)) return;
1618 ecore_thread_main_loop_begin();
1620 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1621 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1623 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1625 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1634 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1635 ecore_dev = edev->ecore_dev;
1640 ERR("Failed to get source ecore device from event !\n");
1644 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
1646 ev->window = (Ecore_Window)input->dev->window;
1647 ev->event_window = (Ecore_Window)input->dev->window;
1648 ev->root_window = (Ecore_Window)input->dev->window;
1649 ev->timestamp = libinput_event_touch_get_time(event);
1650 ev->same_screen = 1;
1652 _device_modifiers_update(edev);
1653 ev->modifiers = edev->xkb.modifiers;
1655 ev->x = edev->seat->ptr.ix;
1656 ev->y = edev->seat->ptr.iy;
1660 ev->multi.device = edev->mt_slot;
1661 ev->multi.radius = 1;
1662 ev->multi.radius_x = 1;
1663 ev->multi.radius_y = 1;
1664 ev->multi.pressure = 1.0;
1665 ev->multi.angle = 0.0;
1666 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1667 if (libinput_event_touch_has_minor(event))
1668 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1669 if (libinput_event_touch_has_major(event))
1670 ev->multi.radius_y = libinput_event_touch_get_major(event);
1671 if (libinput_event_touch_has_pressure(event))
1672 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1673 if (libinput_event_touch_has_orientation(event))
1674 ev->multi.angle = libinput_event_touch_get_orientation(event);
1676 ev->multi.x = ev->x;
1677 ev->multi.y = ev->y;
1678 ev->multi.root.x = ev->x;
1679 ev->multi.root.y = ev->y;
1680 ev->dev = ecore_device_ref(ecore_dev);
1682 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
1684 ecore_thread_main_loop_end();
1688 _device_handle_touch_cancel_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1690 E_Input_Backend *input;
1691 Ecore_Event_Mouse_Button *ev;
1692 uint32_t timestamp, button = 0;
1693 Ecore_Device *ecore_dev = NULL, *data;
1697 if (!(input = edev->seat->input)) return;
1699 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1700 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1702 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1704 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1713 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1714 ecore_dev = edev->ecore_dev;
1719 ERR("Failed to get source ecore device from event !\n");
1723 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) return;
1725 timestamp = libinput_event_touch_get_time(event);
1727 ev->window = (Ecore_Window)input->dev->window;
1728 ev->event_window = (Ecore_Window)input->dev->window;
1729 ev->root_window = (Ecore_Window)input->dev->window;
1730 ev->timestamp = timestamp;
1731 ev->same_screen = 1;
1733 ev->x = edev->seat->ptr.ix;
1734 ev->y = edev->seat->ptr.iy;
1738 ev->multi.device = edev->mt_slot;
1739 ev->multi.radius = 1;
1740 ev->multi.radius_x = 1;
1741 ev->multi.radius_y = 1;
1742 ev->multi.pressure = 1.0;
1743 ev->multi.angle = 0.0;
1744 ev->multi.x = ev->x;
1745 ev->multi.y = ev->y;
1746 ev->multi.root.x = ev->x;
1747 ev->multi.root.y = ev->y;
1749 edev->touch.pressed &= ~(1 << ev->multi.device);
1751 ev->buttons = ((button & 0x00F) + 1);
1753 ecore_thread_main_loop_begin();
1755 ev->dev = ecore_device_ref(ecore_dev);
1757 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev, _e_input_event_mouse_button_cb_free, NULL);
1758 ecore_thread_main_loop_end();
1762 _device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, int *w, int *h)
1764 E_Output *output = NULL;
1766 EINA_SAFETY_ON_NULL_RETURN(edev);
1768 if (!edev->output_configured)
1770 if (edev->output_name)
1772 output = e_output_find(edev->output_name);
1775 edev->mouse.minx = output->config.geom.x;
1776 edev->mouse.miny = output->config.geom.y;
1777 edev->mouse.maxw = output->config.geom.w;
1778 edev->mouse.maxh = output->config.geom.h;
1779 if (libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
1781 edev->seat->ptr.dx = (double)(edev->mouse.maxw / 2);
1782 edev->seat->ptr.dy = (double)(edev->mouse.maxh / 2);
1783 edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
1784 edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
1785 edev->mouse.dx = edev->seat->ptr.dx;
1786 edev->mouse.dy = edev->seat->ptr.dy;
1791 edev->output_configured = EINA_TRUE;
1792 ELOGF("E_INPUT_EVDEV", "Device is configured by output x:%d,y:%d (w:%d, h:%d)",
1793 NULL, edev->mouse.minx, edev->mouse.miny, edev->mouse.maxw, edev->mouse.maxh);
1795 if (x) *x = edev->mouse.minx;
1796 if (y) *y = edev->mouse.miny;
1797 if (w) *w = edev->mouse.maxw;
1798 if (h) *h = edev->mouse.maxh;
1802 _device_handle_touch_down(struct libinput_device *device, struct libinput_event_touch *event)
1804 E_Input_Evdev *edev;
1805 int x = 0, y = 0, w = 0, h = 0;
1806 E_Comp_Config *comp_conf = NULL;
1808 if (!(edev = libinput_device_get_user_data(device)))
1813 _device_configured_size_get(edev, &x, &y, &w, &h);
1815 edev->mouse.dx = edev->seat->ptr.ix = edev->seat->ptr.dx =
1816 x + libinput_event_touch_get_x_transformed(event, w);
1817 edev->mouse.dy = edev->seat->ptr.iy = edev->seat->ptr.dy =
1818 y + libinput_event_touch_get_y_transformed(event, h);
1820 edev->mt_slot = libinput_event_touch_get_slot(event);
1821 if (edev->mt_slot < 0)
1823 /* FIXME: The single touch device return slot id -1
1824 * But currently we have no API to distinguish multi touch or single touch
1825 * After libinput 1.11 version, libinput provides get_touch_count API,
1826 * so we can distinguish multi touch device or single touch device.
1828 if (edev->mt_slot == -1)
1832 WRN("%d slot touch down events are not supported\n", edev->mt_slot);
1837 if (edev->mt_slot < e_input_touch_max_count_get())
1839 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
1840 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
1843 comp_conf = e_comp_config_get();
1844 if (comp_conf && comp_conf->input_log_enable)
1845 ELOGF("Touch", "Down (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
1847 edev->touch.raw_pressed |= (1 << edev->mt_slot);
1849 if (edev->touch.blocked)
1851 ELOGF("Touch", "Down (id: %d, x: %d, y: %d) is blocked by %p, server: 0x%x", NULL,
1852 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, edev->seat->dev->blocked_client,
1853 edev->seat->dev->server_blocked);
1857 _device_handle_touch_motion_send(edev, event);
1858 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_DOWN);
1862 _device_handle_touch_motion(struct libinput_device *device, struct libinput_event_touch *event)
1864 E_Input_Evdev *edev;
1865 int x = 0, y = 0, w = 0, h = 0;
1867 if (!(edev = libinput_device_get_user_data(device)))
1872 _device_configured_size_get(edev, &x, &y, &w, &h);
1874 edev->mouse.dx = edev->seat->ptr.dx =
1875 x + libinput_event_touch_get_x_transformed(event, w);
1876 edev->mouse.dy = edev->seat->ptr.dy =
1877 y + libinput_event_touch_get_y_transformed(event, h);
1879 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
1880 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
1885 edev->seat->ptr.ix = edev->seat->ptr.dx;
1886 edev->seat->ptr.iy = edev->seat->ptr.dy;
1888 edev->mt_slot = libinput_event_touch_get_slot(event);
1889 if (edev->mt_slot < 0)
1891 /* FIXME: The single touch device return slot id -1
1892 * But currently we have no API to distinguish multi touch or single touch
1893 * After libinput 1.11 version, libinput provides get_touch_count API,
1894 * so we can distinguish multi touch device or single touch device.
1896 if (edev->mt_slot == -1)
1900 WRN("%d slot touch motion events are not supported\n", edev->mt_slot);
1905 if (edev->mt_slot < e_input_touch_max_count_get())
1907 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
1908 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
1911 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
1913 if (edev->touch.blocked)
1919 _device_handle_touch_motion_send(edev, event);
1923 _device_handle_touch_up(struct libinput_device *device, struct libinput_event_touch *event)
1925 E_Input_Evdev *edev;
1926 E_Comp_Config *comp_conf = NULL;
1928 if (!(edev = libinput_device_get_user_data(device)))
1933 edev->mt_slot = libinput_event_touch_get_slot(event);
1934 if (edev->mt_slot < 0)
1936 /* FIXME: The single touch device return slot id -1
1937 * But currently we have no API to distinguish multi touch or single touch
1938 * After libinput 1.11 version, libinput provides get_touch_count API,
1939 * so we can distinguish multi touch device or single touch device.
1941 if (edev->mt_slot == -1)
1945 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
1950 if (edev->mt_slot < e_input_touch_max_count_get())
1952 edev->mouse.dx = edev->seat->ptr.dx = edev->seat->ptr.ix =
1953 edev->touch.coords[edev->mt_slot].x;
1954 edev->mouse.dy = edev->seat->ptr.dy = edev->seat->ptr.iy =
1955 edev->touch.coords[edev->mt_slot].y;
1958 comp_conf = e_comp_config_get();
1959 if (comp_conf && comp_conf->input_log_enable)
1960 ELOGF("Touch", "Up (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
1962 edev->touch.raw_pressed &= ~(1 << edev->mt_slot);
1964 if (edev->touch.blocked)
1966 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
1968 ELOGF("Touch", "Up (id: %d, x: %d, y: %d) is blocked by %p, server(0x%x)", NULL,
1969 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, edev->seat->dev->blocked_client,
1970 edev->seat->dev->server_blocked);
1971 if (edev->touch.raw_pressed == 0x0)
1973 edev->touch.blocked = EINA_FALSE;
1979 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_UP);
1983 _device_handle_touch_cancel(struct libinput_device *device, struct libinput_event_touch *event)
1985 E_Input_Evdev *edev;
1986 E_Comp_Config *comp_conf = NULL;
1988 if (!(edev = libinput_device_get_user_data(device)))
1993 edev->mt_slot = libinput_event_touch_get_slot(event);
1994 if (edev->mt_slot < 0)
1996 /* FIXME: The single touch device return slot id -1
1997 * But currently we have no API to distinguish multi touch or single touch
1998 * After libinput 1.11 version, libinput provides get_touch_count API,
1999 * so we can distinguish multi touch device or single touch device.
2001 if (edev->mt_slot == -1)
2005 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
2010 comp_conf = e_comp_config_get();
2011 if (comp_conf && comp_conf->input_log_enable)
2012 ELOGF("Touch", "cancel (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2014 _device_handle_touch_cancel_send(edev, event);
2019 _device_handle_touch_frame(struct libinput_device *device EINA_UNUSED, struct libinput_event_touch *event EINA_UNUSED)
2021 /* DBG("Unhandled Touch Frame Event"); */
2025 _e_input_aux_data_event_free(void *user_data EINA_UNUSED, void *ev)
2027 Ecore_Event_Axis_Update *e = (Ecore_Event_Axis_Update *)ev;
2029 if (e->axis) free(e->axis);
2030 if (e->dev) ecore_device_unref(e->dev);
2036 _device_handle_touch_aux_data(struct libinput_device *device, struct libinput_event_touch_aux_data *event)
2038 E_Input_Evdev *edev;
2039 E_Input_Backend *input;
2040 Ecore_Event_Axis_Update *ev;
2042 Ecore_Device *ecore_dev = NULL, *data;
2044 E_Comp_Config *comp_conf;
2046 if (libinput_event_touch_aux_data_get_type(event) != LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM &&
2047 libinput_event_touch_aux_data_get_value(event) > 0)
2050 if (!(edev = libinput_device_get_user_data(device))) goto end;
2051 if (!(input = edev->seat->input)) goto end;
2053 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
2054 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
2056 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
2058 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
2067 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
2068 ecore_dev = edev->ecore_dev;
2073 ERR("Failed to get source ecore device from event !\n");
2077 if (!(ev = calloc(1, sizeof(Ecore_Event_Axis_Update))))goto end;
2079 ev->window = (Ecore_Window)input->dev->window;
2080 ev->event_window = (Ecore_Window)input->dev->window;
2081 ev->root_window = (Ecore_Window)input->dev->window;
2082 ev->timestamp = libinput_event_touch_aux_data_get_time(event);
2084 axis = (Ecore_Axis *)calloc(1, sizeof(Ecore_Axis));
2087 axis->label = ECORE_AXIS_LABEL_TOUCH_PALM;
2088 axis->value = libinput_event_touch_aux_data_get_value(event);
2093 comp_conf = e_comp_config_get();
2094 if (comp_conf && comp_conf->input_log_enable)
2095 ELOGF("Touch", "Axis (label: %d, value: %lf)", NULL, axis?axis->label:-1, axis?axis->value:0.0);
2097 ecore_thread_main_loop_begin();
2099 ev->dev = ecore_device_ref(ecore_dev);
2101 ecore_event_add(ECORE_EVENT_AXIS_UPDATE, ev, _e_input_aux_data_event_free, NULL);
2102 ecore_thread_main_loop_end();
2109 _e_input_evdev_device_create(E_Input_Seat *seat, struct libinput_device *device)
2111 E_Input_Evdev *edev;
2112 E_Input_Backend *b_input;
2113 const char *output_name;
2115 EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
2117 /* try to allocate space for new evdev */
2118 if (!(edev = calloc(1, sizeof(E_Input_Evdev)))) return NULL;
2121 edev->device = device;
2122 edev->path = eina_stringshare_printf("%s/%s", e_input_base_dir_get(), libinput_device_get_sysname(device));
2124 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
2126 edev->caps |= E_INPUT_SEAT_KEYBOARD;
2127 _device_keyboard_setup(edev);
2130 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
2132 edev->caps |= E_INPUT_SEAT_POINTER;
2134 /* TODO: make this configurable */
2135 edev->mouse.threshold = 250;
2137 b_input = seat->input;
2138 if (b_input->left_handed == EINA_TRUE)
2140 if (libinput_device_config_left_handed_set(device, 1) !=
2141 LIBINPUT_CONFIG_STATUS_SUCCESS)
2143 WRN("Failed to set left hand mode about device: %s\n",
2144 libinput_device_get_name(device));
2149 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
2152 edev->caps |= E_INPUT_SEAT_TOUCH;
2153 palm_code = libinput_device_touch_aux_data_get_code(LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM);
2154 if (libinput_device_touch_has_aux_data(device, palm_code))
2156 libinput_device_touch_set_aux_data(device, palm_code);
2159 _device_touch_count_update(edev);
2161 edev->touch.coords = calloc(1, sizeof(E_Input_Coord)*e_input_touch_max_count_get());
2163 if (!edev->touch.coords)
2164 ERR("Failed to allocate memory for touch coords !\n");
2167 output_name = libinput_device_get_output_name(device);
2170 eina_stringshare_replace(&edev->output_name, output_name);
2171 ELOGF("E_INPUT_EVDEV", "Device has output_name:%s", NULL, output_name);
2174 libinput_device_set_user_data(device, edev);
2175 libinput_device_ref(device);
2177 /* configure device */
2178 _device_configure(edev);
2184 _e_input_evdev_device_destroy(E_Input_Evdev *edev)
2188 EINA_SAFETY_ON_NULL_RETURN(edev);
2190 ecore_thread_main_loop_begin();
2192 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
2194 if (edev->xkb.state) xkb_state_unref(edev->xkb.state);
2195 if (edev->xkb.keymap) xkb_map_unref(edev->xkb.keymap);
2198 if (edev->ecore_dev) ecore_device_del(edev->ecore_dev);
2199 if (edev->ecore_dev_list)
2200 EINA_LIST_FREE(edev->ecore_dev_list, dev)
2202 ecore_device_del(dev);
2204 if (edev->path) eina_stringshare_del(edev->path);
2205 if (edev->device) libinput_device_unref(edev->device);
2206 if (edev->key_remap_hash) eina_hash_free(edev->key_remap_hash);
2207 if (edev->touch.coords)
2209 free(edev->touch.coords);
2210 edev->touch.coords = NULL;
2212 eina_stringshare_del(edev->output_name);
2214 ecore_thread_main_loop_end();
2220 _e_input_evdev_event_process(struct libinput_event *event)
2222 struct libinput_device *device;
2223 Eina_Bool ret = EINA_TRUE;
2225 device = libinput_event_get_device(event);
2226 switch (libinput_event_get_type(event))
2228 case LIBINPUT_EVENT_KEYBOARD_KEY:
2229 _device_handle_key(device, libinput_event_get_keyboard_event(event));
2231 case LIBINPUT_EVENT_POINTER_MOTION:
2232 _device_handle_pointer_motion(device,
2233 libinput_event_get_pointer_event(event));
2235 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
2236 _device_handle_pointer_motion_absolute(device,
2237 libinput_event_get_pointer_event(event));
2239 case LIBINPUT_EVENT_POINTER_BUTTON:
2240 _device_handle_button(device, libinput_event_get_pointer_event(event));
2242 case LIBINPUT_EVENT_POINTER_AXIS:
2243 #if !LIBINPUT_HAVE_SCROLL_VALUE_V120
2244 _device_handle_axis(device, libinput_event_get_pointer_event(event));
2247 #if LIBINPUT_HAVE_SCROLL_VALUE_V120
2248 case LIBINPUT_EVENT_POINTER_SCROLL_WHEEL:
2249 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_WHEEL);
2251 case LIBINPUT_EVENT_POINTER_SCROLL_FINGER:
2252 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_FINGER);
2254 case LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS:
2255 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_CONTINUOUS);
2258 case LIBINPUT_EVENT_TOUCH_DOWN:
2259 _device_handle_touch_down(device, libinput_event_get_touch_event(event));
2261 case LIBINPUT_EVENT_TOUCH_MOTION:
2262 _device_handle_touch_motion(device,
2263 libinput_event_get_touch_event(event));
2265 case LIBINPUT_EVENT_TOUCH_UP:
2266 _device_handle_touch_up(device, libinput_event_get_touch_event(event));
2268 case LIBINPUT_EVENT_TOUCH_CANCEL:
2269 _device_handle_touch_cancel(device, libinput_event_get_touch_event(event));
2271 case LIBINPUT_EVENT_TOUCH_FRAME:
2272 _device_handle_touch_frame(device, libinput_event_get_touch_event(event));
2274 case LIBINPUT_EVENT_TOUCH_AUX_DATA:
2275 _device_handle_touch_aux_data(device, libinput_event_get_touch_aux_data(event));
2286 * @brief Set the axis size of the given device.
2288 * @param dev The device to set the axis size to.
2289 * @param w The width of the axis.
2290 * @param h The height of the axis.
2292 * This function sets set the width @p w and height @p h of the axis
2293 * of device @p dev. If @p dev is a relative input device, a width and
2294 * height must set for it. If its absolute set the ioctl correctly, if
2295 * not, unsupported device.
2298 e_input_evdev_axis_size_set(E_Input_Evdev *edev, int w, int h)
2300 const char *sysname;
2305 enum libinput_config_status status;
2307 EINA_SAFETY_ON_NULL_RETURN(edev);
2308 EINA_SAFETY_ON_TRUE_RETURN((w == 0) || (h == 0));
2310 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
2311 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
2314 sysname = libinput_device_get_sysname(edev->device);
2316 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
2317 if (eina_list_count(devices) < 1) return;
2319 EINA_LIST_FREE(devices, device)
2321 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
2323 (sscanf(vals, "%f %f %f %f %f %f",
2324 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
2331 libinput_device_config_calibration_set_matrix(edev->device, cal);
2333 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
2334 ERR("Failed to apply calibration");
2337 eina_stringshare_del(device);
2342 EINTERN const char *
2343 e_input_evdev_name_get(E_Input_Evdev *evdev)
2345 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2346 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2348 return libinput_device_get_name(evdev->device);
2351 EINTERN const char *
2352 e_input_evdev_sysname_get(E_Input_Evdev *evdev)
2354 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2355 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2357 return libinput_device_get_sysname(evdev->device);
2361 e_input_evdev_key_remap_enable(E_Input_Evdev *edev, Eina_Bool enable)
2363 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2364 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2366 edev->key_remap_enabled = enable;
2368 if (enable == EINA_FALSE && edev->key_remap_hash)
2370 eina_hash_free(edev->key_remap_hash);
2371 edev->key_remap_hash = NULL;
2378 e_input_evdev_key_remap_set(E_Input_Evdev *edev, int *from_keys, int *to_keys, int num)
2382 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2383 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2384 EINA_SAFETY_ON_NULL_RETURN_VAL(from_keys, EINA_FALSE);
2385 EINA_SAFETY_ON_NULL_RETURN_VAL(to_keys, EINA_FALSE);
2386 EINA_SAFETY_ON_TRUE_RETURN_VAL(num <= 0, EINA_FALSE);
2387 EINA_SAFETY_ON_TRUE_RETURN_VAL(!edev->key_remap_enabled, EINA_FALSE);
2389 if (edev->key_remap_hash == NULL)
2390 edev->key_remap_hash = eina_hash_int32_new(NULL);
2392 if (edev->key_remap_hash == NULL)
2394 ERR("Failed to set remap key information : creating a hash is failed.");
2398 for (i = 0; i < num ; i++)
2400 if (!from_keys[i] || !to_keys[i])
2402 ERR("Failed to set remap key information : given arguments are invalid.");
2407 for (i = 0; i < num ; i++)
2409 eina_hash_add(edev->key_remap_hash, &from_keys[i], (void *)(intptr_t)to_keys[i]);
2416 e_input_evdev_wheel_click_angle_get(E_Input_Evdev *dev)
2418 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, -1);
2419 return libinput_device_config_scroll_get_wheel_click_angle(dev->device);
2423 e_input_evdev_touch_calibration_set(E_Input_Evdev *edev, float matrix[6])
2425 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2426 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2428 if (!libinput_device_config_calibration_has_matrix(edev->device) ||
2429 !libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_TOUCH))
2432 if (libinput_device_config_calibration_set_matrix(edev->device, matrix) !=
2433 LIBINPUT_CONFIG_STATUS_SUCCESS)
2435 WRN("Failed to set input transformation about device: %s\n",
2436 libinput_device_get_name(edev->device));
2444 e_input_evdev_mouse_accel_speed_set(E_Input_Evdev *edev, double speed)
2446 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2447 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2449 if (!libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
2452 if (!libinput_device_config_accel_is_available(edev->device))
2455 if (libinput_device_config_accel_set_speed(edev->device, speed) !=
2456 LIBINPUT_CONFIG_STATUS_SUCCESS)
2458 WRN("Failed to set mouse accel about device: %s\n",
2459 libinput_device_get_name(edev->device));
2466 EINTERN unsigned int
2467 e_input_evdev_touch_pressed_get(E_Input_Evdev *edev)
2469 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, 0x0);
2471 return edev->touch.pressed;
2475 e_input_evdev_seatname_get(E_Input_Evdev *evdev)
2477 struct libinput_seat *libinput_seat;
2478 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2479 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2481 libinput_seat = libinput_device_get_seat(evdev->device);
2483 return libinput_seat_get_logical_name(libinput_seat);
2487 e_input_evdev_seatname_set(E_Input_Evdev *evdev, const char *seatname)
2489 Eina_Bool res = EINA_FALSE;
2490 E_Input_Backend *input;
2492 EINA_SAFETY_ON_NULL_RETURN_VAL(seatname, EINA_FALSE);
2493 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, EINA_FALSE);
2494 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, EINA_FALSE);
2496 if (libinput_device_set_seat_logical_name(evdev->device, seatname) == 0)
2498 input = evdev->seat->input;
2499 if (!input) return EINA_FALSE;
2500 if (libinput_dispatch(input->libinput) != 0)
2502 ERR("Failed to dispatch libinput events: %m");
2506 /* process pending events */
2507 _input_events_process(input);
2515 e_input_evdev_mouse_accel_enable(E_Input_Evdev *edev, Eina_Bool enable)
2517 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2518 edev->disable_acceleration = !enable;