2 #include "e_input_private.h"
4 #include "e_keyrouter_private.h"
5 #include "e_input_event.h"
9 static void _device_modifiers_update(E_Input_Evdev *edev);
10 static void _device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, int *w, int *h);
11 static void _device_output_assign(E_Input_Evdev *edev, E_Input_Seat_Capabilities cap);
14 _device_calibration_set(E_Input_Evdev *edev)
19 E_Comp_Config *comp_conf;
21 if (e_comp->e_comp_screen->num_outputs > 1) //multiple outputs
23 comp_conf = e_comp_config_get();
24 if (comp_conf && (comp_conf->input_output_assign_policy == 1)) //use output-assignment policy
26 _device_output_assign(edev, E_INPUT_SEAT_POINTER);
27 _device_output_assign(edev, E_INPUT_SEAT_TOUCH);
31 output = e_comp_screen_primary_output_get(e_comp->e_comp_screen);
32 e_output_size_get(output, &w, &h);
36 edev->mouse.minx = edev->mouse.miny = 0;
40 if (libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
42 edev->seat->ptr.dx = (double)(w / 2);
43 edev->seat->ptr.dy = (double)(h / 2);
44 edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
45 edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
46 edev->mouse.dx = edev->seat->ptr.dx;
47 edev->mouse.dy = edev->seat->ptr.dy;
49 if (output->config.rotation == 90 || output->config.rotation == 270)
51 temp = edev->mouse.minx;
52 edev->mouse.minx = edev->mouse.miny;
53 edev->mouse.miny = temp;
55 temp = edev->mouse.maxw;
56 edev->mouse.maxw = edev->mouse.maxh;
57 edev->mouse.maxh = temp;
63 #ifdef _F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
69 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
70 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
73 sysname = libinput_device_get_sysname(edev->device);
75 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
76 if (eina_list_count(devices) < 1) return;
78 #ifdef _F_E_INPUT_USE_WL_CALIBRATION_
80 enum libinput_config_status status;
82 EINA_LIST_FREE(devices, device)
84 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
86 (sscanf(vals, "%f %f %f %f %f %f",
87 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
94 libinput_device_config_calibration_set_matrix(edev->device, cal);
96 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
97 ERR("Failed to apply calibration");
100 eina_stringshare_del(device);
103 #endif//_F_E_INPUT_USE_WL_CALIBRATION_
104 #endif//_F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
109 _device_output_assign(E_Input_Evdev *edev, E_Input_Seat_Capabilities cap)
114 Eina_Bool need_assign_output = EINA_FALSE;
115 const char *output_name;
118 if (!(edev->caps & cap)) return;
119 if (edev->output_name) return; //already assigned
120 if (e_comp->e_comp_screen->num_outputs <= 1) return;
122 last_output_idx = e_comp->e_comp_screen->num_outputs - 1;
123 EINA_LIST_FOREACH(edev->seat->devices, l, ed)
125 if (!(ed->caps & cap)) continue;
126 if (ed == edev) continue;
129 need_assign_output = EINA_FALSE;
132 need_assign_output = EINA_TRUE;
134 if (need_assign_output)
136 output = e_output_find_by_index(last_output_idx);
137 if (!output || !output->info.connected) return;
138 output_name = e_output_output_id_get(output);
139 if (output_name) edev->output_name = eina_stringshare_add(output_name);
140 ELOGF("E_INPUT_EVDEV", "Device is assigned to output:%s", NULL, output_name);
145 _device_touch_count_update(E_Input_Evdev *edev)
147 unsigned int device_touch_count = 0;
148 static unsigned int _max_device_touch_count = 0;
150 E_Input *ei = e_input_get();
151 EINA_SAFETY_ON_NULL_RETURN(ei);
153 device_touch_count = libinput_device_touch_get_touch_count(edev->device);
155 if (_max_device_touch_count < device_touch_count)
156 _max_device_touch_count = device_touch_count;
158 if (e_config->configured_max_touch.use)
160 if (_max_device_touch_count > 0 && e_config->configured_max_touch.count > _max_device_touch_count)
162 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch max count(%d) must be less or equal to device's touch count(%d) !\nTouch max count has been shrinken to %d.\n",
163 NULL, e_config->configured_max_touch.count, _max_device_touch_count, _max_device_touch_count);
164 ei->touch_max_count = _max_device_touch_count;
168 if (ei->touch_max_count != e_config->configured_max_touch.count)
170 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch_max_count has been updated to %d -> %d.\n",
171 NULL, ei->touch_max_count, e_config->configured_max_touch.count);
172 ei->touch_max_count = e_config->configured_max_touch.count;
178 if (ei->touch_max_count < _max_device_touch_count)
180 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch_max_count has been updated to %d -> %d.\n", NULL,
181 ei->touch_max_count, _max_device_touch_count);
182 ei->touch_max_count = _max_device_touch_count;
186 ei->touch_device_count++;
187 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch device count is %d.\n", NULL, ei->touch_device_count);
191 _device_configure(E_Input_Evdev *edev)
193 if (libinput_device_config_tap_get_finger_count(edev->device) > 0)
195 Eina_Bool tap = EINA_FALSE;
197 tap = libinput_device_config_tap_get_default_enabled(edev->device);
198 libinput_device_config_tap_set_enabled(edev->device, tap);
201 _device_calibration_set(edev);
205 _device_keyboard_setup(E_Input_Evdev *edev)
207 E_Input_Backend *input;
208 xkb_mod_index_t xkb_idx;
210 if ((!edev) || (!edev->seat)) return;
211 if (!(input = edev->seat->input)) return;
212 if (!input->dev->xkb_ctx) return;
214 g_mutex_init(&edev->xkb.keymap_mutex);
216 /* create keymap from xkb context */
217 g_mutex_lock(&edev->xkb.keymap_mutex);
218 edev->xkb.keymap = _e_input_device_cached_keymap_get(input->dev->xkb_ctx, NULL, 0);
219 if (!edev->xkb.keymap)
221 g_mutex_unlock(&edev->xkb.keymap_mutex);
222 ERR("Failed to create keymap: %m");
226 g_mutex_lock(&edev->xkb.state_mutex);
228 /* create xkb state */
229 if (!(edev->xkb.state = xkb_state_new(edev->xkb.keymap)))
231 g_mutex_unlock(&edev->xkb.state_mutex);
232 g_mutex_unlock(&edev->xkb.keymap_mutex);
233 ERR("Failed to create xkb state: %m");
237 g_mutex_unlock(&edev->xkb.state_mutex);
239 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CTRL);
240 if (xkb_idx != XKB_MOD_INVALID)
241 edev->xkb.ctrl_mask = 1 << xkb_idx;
243 edev->xkb.ctrl_mask = 0;
245 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_ALT);
246 if (xkb_idx != XKB_MOD_INVALID)
247 edev->xkb.alt_mask = 1 << xkb_idx;
249 edev->xkb.alt_mask = 0;
251 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_SHIFT);
252 if (xkb_idx != XKB_MOD_INVALID)
253 edev->xkb.shift_mask = 1 << xkb_idx;
255 edev->xkb.shift_mask = 0;
257 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_LOGO);
258 if (xkb_idx != XKB_MOD_INVALID)
259 edev->xkb.win_mask = 1 << xkb_idx;
261 edev->xkb.win_mask = 0;
263 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_SCROLL);
264 if (xkb_idx != XKB_MOD_INVALID)
265 edev->xkb.scroll_mask = 1 << xkb_idx;
267 edev->xkb.scroll_mask = 0;
269 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_NUM);
270 if (xkb_idx != XKB_MOD_INVALID)
271 edev->xkb.num_mask = 1 << xkb_idx;
273 edev->xkb.num_mask = 0;
275 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CAPS);
276 if (xkb_idx != XKB_MOD_INVALID)
277 edev->xkb.caps_mask = 1 << xkb_idx;
279 edev->xkb.caps_mask = 0;
281 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, "ISO_Level3_Shift");
282 if (xkb_idx != XKB_MOD_INVALID)
283 edev->xkb.altgr_mask = 1 << xkb_idx;
285 edev->xkb.altgr_mask = 0;
287 g_mutex_unlock(&edev->xkb.keymap_mutex);
291 _device_keysym_translate(xkb_keysym_t keysym, unsigned int modifiers, char *buffer, int bytes)
293 unsigned long hbytes = 0;
296 if (!keysym) return 0;
297 hbytes = (keysym >> 8);
302 (((keysym >= XKB_KEY_BackSpace) && (keysym <= XKB_KEY_Clear)) ||
303 (keysym == XKB_KEY_Return) || (keysym == XKB_KEY_Escape) ||
304 (keysym == XKB_KEY_KP_Space) || (keysym == XKB_KEY_KP_Tab) ||
305 (keysym == XKB_KEY_KP_Enter) ||
306 ((keysym >= XKB_KEY_KP_Multiply) && (keysym <= XKB_KEY_KP_9)) ||
307 (keysym == XKB_KEY_KP_Equal) || (keysym == XKB_KEY_Delete))))))
310 if (keysym == XKB_KEY_KP_Space)
311 c = (XKB_KEY_space & 0x7F);
312 else if (hbytes == 0xFF)
317 if (modifiers & ECORE_EVENT_MODIFIER_CTRL)
319 if (((c >= '@') && (c < '\177')) || c == ' ')
323 else if ((c >= '3') && (c <= '7'))
335 _device_modifiers_update_device(E_Input_Evdev *edev, E_Input_Evdev *from)
339 g_mutex_lock(&from->xkb.state_mutex);
341 edev->xkb.depressed =
342 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_DEPRESSED);
344 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LATCHED);
346 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LOCKED);
348 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_EFFECTIVE);
350 g_mutex_unlock(&from->xkb.state_mutex);
352 mask = (edev->xkb.depressed | edev->xkb.latched);
354 if (mask & from->xkb.ctrl_mask)
355 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_CTRL;
356 if (mask & from->xkb.alt_mask)
357 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALT;
358 if (mask & from->xkb.shift_mask)
359 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
360 if (mask & from->xkb.win_mask)
361 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_WIN;
362 if (mask & from->xkb.scroll_mask)
363 edev->xkb.modifiers |= ECORE_EVENT_LOCK_SCROLL;
364 if (mask & from->xkb.num_mask)
365 edev->xkb.modifiers |= ECORE_EVENT_LOCK_NUM;
366 if (mask & from->xkb.caps_mask)
367 edev->xkb.modifiers |= ECORE_EVENT_LOCK_CAPS;
368 if (mask & from->xkb.altgr_mask)
369 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALTGR;
373 _device_modifiers_update(E_Input_Evdev *edev)
378 edev->xkb.modifiers = 0;
380 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
381 _device_modifiers_update_device(edev, edev);
384 EINA_LIST_FOREACH(edev->seat->devices, l, ed)
386 if (!(ed->caps & E_INPUT_SEAT_KEYBOARD)) continue;
387 _device_modifiers_update_device(edev, ed);
394 _device_remapped_key_get(E_Input_Evdev *edev, int code)
398 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, code);
399 if (!edev->key_remap_enabled) return code;
400 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->key_remap_hash, code);
402 ret = eina_hash_find(edev->key_remap_hash, &code);
404 if (ret) code = (int)(intptr_t)ret;
410 e_input_evdev_get_e_device(const char *path, Ecore_Device_Class clas)
412 const GList *dev_list = NULL;
414 E_Device *dev = NULL;
415 const char *identifier;
417 if (!path) return NULL;
419 dev_list = e_device_list_get();
420 if (!dev_list) return NULL;
421 for (l = dev_list, dev = dev_list->data;
423 l = g_list_next(l), dev = l->data)
426 identifier = e_device_identifier_get(dev);
427 if (!identifier) continue;
428 if ((e_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
435 EINTERN Ecore_Device *
436 e_input_evdev_get_ecore_device(const char *path, Ecore_Device_Class clas)
438 const Eina_List *dev_list = NULL;
440 Ecore_Device *dev = NULL;
441 const char *identifier;
443 if (!path) return NULL;
445 dev_list = ecore_device_list();
446 if (!dev_list) return NULL;
447 EINA_LIST_FOREACH(dev_list, l, dev)
450 identifier = ecore_device_identifier_get(dev);
451 if (!identifier) continue;
452 if ((ecore_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
459 _e_input_event_mouse_move_cb_free(void *data EINA_UNUSED, void *event)
461 Ecore_Event_Mouse_Move *ev = event;
463 if (ev->dev) ecore_device_unref(ev->dev);
469 _e_input_event_mouse_wheel_cb_free(void *data EINA_UNUSED, void *event)
471 Ecore_Event_Mouse_Wheel *ev = event;
473 if (ev->dev) ecore_device_unref(ev->dev);
479 _e_input_event_mouse_button_cb_free(void *data EINA_UNUSED, void *event)
481 Ecore_Event_Mouse_Button *ev = event;
483 if (ev->dev) ecore_device_unref(ev->dev);
489 _e_input_event_key_cb_free(void *data EINA_UNUSED, void *event)
491 Ecore_Event_Key *ev = event;
493 if (e_input_thread_mode_get())
495 if (ev->dev) g_object_unref(ev->dev);
499 if (ev->dev) ecore_device_unref(ev->dev);
502 if (ev->data) E_FREE(ev->data);
508 _device_handle_key(struct libinput_device *device, struct libinput_event_keyboard *event)
511 E_Input_Backend *input;
513 uint32_t code, nsyms;
514 const xkb_keysym_t *syms;
515 enum libinput_key_state state;
517 xkb_keysym_t sym = XKB_KEY_NoSymbol;
518 char key[256] = {0, }, keyname[256] = {0, }, compose_buffer[256] = {0, };
520 char *tmp = NULL, *compose = NULL;
521 E_Keyrouter_Event_Data *key_data;
522 Ecore_Device *ecore_dev = NULL, *data;
523 E_Device *e_dev = NULL, *e_dev_data;
524 Eina_List *l = NULL, *l_next = NULL;
526 E_Comp_Config *comp_conf = NULL;
527 int *pressed_keycode = NULL, *idata = NULL;
528 Eina_Bool dup_found = EINA_FALSE;
529 const char* device_name = NULL;
531 if (!(edev = libinput_device_get_user_data(device)))
536 if (!(input = edev->seat->input))
541 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
542 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
544 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
546 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_KEYBOARD)
555 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
556 ecore_dev = edev->ecore_dev;
561 ERR("Failed to get source ecore device from event !\n");
565 if (edev->e_dev) e_dev = edev->e_dev;
566 else if (edev->e_dev_list && g_list_length(edev->e_dev_list) > 0)
568 for (glist = edev->e_dev_list, e_dev_data = edev->e_dev_list->data;
570 glist = g_list_next(l), e_dev_data = l->data)
572 if (e_device_class_get(e_dev_data) == ECORE_DEVICE_CLASS_KEYBOARD)
581 edev->e_dev = e_input_evdev_get_e_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
587 ERR("Failed to get source e device from event !\n");
591 timestamp = libinput_event_keyboard_get_time(event);
592 code = libinput_event_keyboard_get_key(event);
593 code = _device_remapped_key_get(edev, code + 8);
594 state = libinput_event_keyboard_get_key_state(event);
595 key_count = libinput_event_keyboard_get_seat_key_count(event);
597 if (state == LIBINPUT_KEY_STATE_PRESSED)
599 if ((edev->seat->dev->blocked & E_INPUT_SEAT_KEYBOARD) ||
600 (edev->seat->dev->server_blocked & E_INPUT_SEAT_KEYBOARD))
602 ELOGF("Key", "Press (keycode: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
603 code, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
604 edev->seat->dev->server_blocked);
608 /* FIXME: Currently to maintain press/release event pair during input block,
609 * used Eina_List and this is method used in devicemgr module.
610 * But we need to consider which way is better to maintain key press/release pair.
613 EINA_LIST_FOREACH(edev->xkb.pressed_keys, l, idata)
617 dup_found = EINA_TRUE;
623 pressed_keycode = E_NEW(int, 1);
624 EINA_SAFETY_ON_NULL_RETURN(pressed_keycode);
625 *pressed_keycode = code;
627 edev->xkb.pressed_keys = eina_list_append(edev->xkb.pressed_keys, pressed_keycode);
632 dup_found = EINA_FALSE;
633 EINA_LIST_FOREACH_SAFE(edev->xkb.pressed_keys, l, l_next, idata)
637 edev->xkb.pressed_keys = eina_list_remove_list(edev->xkb.pressed_keys, l);
639 dup_found = EINA_TRUE;
645 ELOGF("Key", "Release (keycode: %d, device: %s) is blocked by %p", NULL,
646 code, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client);
651 /* ignore key events that are not seat wide state changes */
652 if (((state == LIBINPUT_KEY_STATE_PRESSED) && (key_count != 1)) ||
653 ((state == LIBINPUT_KEY_STATE_RELEASED) && (key_count != 0)))
658 g_mutex_lock(&edev->xkb.state_mutex);
659 xkb_state_update_key(edev->xkb.state, code,
660 (state ? XKB_KEY_DOWN : XKB_KEY_UP));
662 /* get the keysym for this code */
663 nsyms = xkb_key_get_syms(edev->xkb.state, code, &syms);
664 g_mutex_unlock(&edev->xkb.state_mutex);
666 if (nsyms == 1) sym = syms[0];
668 /* If no keysym was found, name it "Keycode-NNN" */
669 if (sym == XKB_KEY_NoSymbol)
670 snprintf(key, sizeof(key), "Keycode-%u", code);
673 /* get the keyname for this sym */
674 xkb_keysym_get_name(sym, key, sizeof(key));
679 /* If no keyname was found, name it "Keycode-NNN" */
680 snprintf(keyname, sizeof(keyname), "Keycode-%u", code);
684 memcpy(keyname, key, sizeof(keyname));
687 /* if shift is active, we need to transform the key to lower */
688 g_mutex_lock(&edev->xkb.keymap_mutex);
689 g_mutex_lock(&edev->xkb.state_mutex);
690 if (xkb_state_mod_index_is_active(edev->xkb.state,
691 xkb_map_mod_get_index(edev->xkb.keymap,
693 XKB_STATE_MODS_EFFECTIVE))
695 if (keyname[0] != '\0')
696 keyname[0] = tolower(keyname[0]);
698 g_mutex_unlock(&edev->xkb.keymap_mutex);
699 g_mutex_unlock(&edev->xkb.state_mutex);
701 if (_device_keysym_translate(sym, edev->xkb.modifiers,
702 compose_buffer, sizeof(compose_buffer)))
704 compose = eina_str_convert("ISO8859-1", "UTF-8", compose_buffer);
707 ERR("E Input cannot convert input key string '%s' to UTF-8. "
708 "Is Eina built with iconv support?", compose_buffer);
714 if (!compose) compose = compose_buffer;
716 e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) +
717 ((compose[0] != '\0') ? strlen(compose) : 0) + 3);
723 key_data = E_NEW(E_Keyrouter_Event_Data, 1);
731 e->keyname = (char *)(e + 1);
732 e->key = e->keyname + strlen(keyname) + 1;
733 e->compose = strlen(compose) ? e->key + strlen(key) + 1 : NULL;
734 e->string = e->compose;
736 strncpy((char *)e->keyname, keyname, strlen(keyname));
737 strncpy((char *)e->key, key, strlen(key));
738 if (strlen(compose)) strncpy((char *)e->compose, compose, strlen(compose));
740 e->window = (Ecore_Window)input->dev->window;
741 e->event_window = (Ecore_Window)input->dev->window;
742 e->root_window = (Ecore_Window)input->dev->window;
743 e->timestamp = timestamp;
748 _device_modifiers_update(edev);
750 e->modifiers = edev->xkb.modifiers;
752 comp_conf = e_comp_config_get();
754 if (e_input_thread_mode_get())
756 e->dev = (Eo *)g_object_ref(e_dev);
757 device_name = e_device_name_get(e_dev);
758 e_input_event_add(input->event_source, state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
762 e->dev = ecore_device_ref(ecore_dev);
763 device_name = ecore_device_name_get(ecore_dev);
764 ecore_event_add(state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
767 if (comp_conf && comp_conf->input_log_enable)
768 ELOGF("Key", "%s (keyname: %s, keycode: %d, timestamp: %u, device: %s)", NULL, state?"Press":"Release", e->keyname, e->keycode, e->timestamp, device_name);
774 _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event)
776 E_Input_Backend *input;
777 Ecore_Event_Mouse_Move *ev;
778 Ecore_Device *ecore_dev = NULL, *data, *detent_data = NULL;
780 int x = 0, y = 0, w = 0, h = 0;
782 if (!(input = edev->seat->input)) return;
784 ecore_thread_main_loop_begin();
786 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
787 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
789 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
791 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
796 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
801 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
803 ecore_dev = detent_data;
808 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
809 ecore_dev = edev->ecore_dev;
814 ERR("Failed to get source ecore device from event !\n");
817 else if ((detent_data == ecore_dev) || e_devicemgr_detent_is_detent(ecore_device_name_get(ecore_dev)))
819 /* Do not process detent device's move events. */
823 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
825 _device_configured_size_get(edev, &x, &y, &w, &h);
827 if (edev->seat->ptr.ix < x)
828 edev->seat->ptr.dx = edev->seat->ptr.ix = x;
829 else if (edev->seat->ptr.ix >= (x + w))
830 edev->seat->ptr.dx = edev->seat->ptr.ix = (x + w - 1);
832 if (edev->seat->ptr.iy < y)
833 edev->seat->ptr.dy = edev->seat->ptr.iy = y;
834 else if (edev->seat->ptr.iy >= (y + h))
835 edev->seat->ptr.dy = edev->seat->ptr.iy = (y + h - 1);
837 edev->mouse.dx = edev->seat->ptr.dx;
838 edev->mouse.dy = edev->seat->ptr.dy;
840 ev->window = (Ecore_Window)input->dev->window;
841 ev->event_window = (Ecore_Window)input->dev->window;
842 ev->root_window = (Ecore_Window)input->dev->window;
843 if (event) ev->timestamp = libinput_event_pointer_get_time(event);
846 _device_modifiers_update(edev);
847 ev->modifiers = edev->xkb.modifiers;
849 ev->x = edev->seat->ptr.ix;
850 ev->y = edev->seat->ptr.iy;
854 ev->multi.device = edev->mt_slot;
855 ev->multi.radius = 1;
856 ev->multi.radius_x = 1;
857 ev->multi.radius_y = 1;
858 ev->multi.pressure = 1.0;
859 ev->multi.angle = 0.0;
862 ev->multi.root.x = ev->x;
863 ev->multi.root.y = ev->y;
865 ev->dev = ecore_device_ref(ecore_dev);
867 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
870 ecore_thread_main_loop_end();
874 _e_input_pointer_motion_post(E_Input_Evdev *edev)
876 _device_pointer_motion(edev, NULL);
880 _device_pointer_relative_motion_send(double dx[2], double dy[2], uint64_t time_us)
882 e_input_relative_motion_cb func = e_input_relative_motion_handler_get();
883 if (func) func(dx, dy, time_us);
887 _device_handle_pointer_motion(struct libinput_device *device, struct libinput_event_pointer *event)
890 double delta_x[2]; /* delta_x[0] for accelerated, delta_x[1] for unaccelerated */
891 double delta_y[2]; /* delta_y[0] for accelerated, delta_y[1] for unaccelerated */
894 if (!(edev = libinput_device_get_user_data(device)))
899 delta_x[0] = libinput_event_pointer_get_dx(event);
900 delta_x[1] = libinput_event_pointer_get_dx_unaccelerated(event);
901 delta_y[0] = libinput_event_pointer_get_dy(event);
902 delta_y[1] = libinput_event_pointer_get_dy_unaccelerated(event);
904 if (edev->disable_acceleration)
915 if (edev->seat->ptr.swap)
921 if (edev->seat->ptr.invert_x)
923 if (edev->seat->ptr.invert_y)
926 edev->seat->ptr.dx += dx;
927 edev->seat->ptr.dy += dy;
929 edev->mouse.dx = edev->seat->ptr.dx;
930 edev->mouse.dy = edev->seat->ptr.dy;
932 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
933 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
938 edev->seat->ptr.ix = edev->seat->ptr.dx;
939 edev->seat->ptr.iy = edev->seat->ptr.dy;
941 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
942 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
947 _device_pointer_relative_motion_send(&delta_x[0], &delta_y[0],
948 libinput_event_pointer_get_time_usec(event));
949 _device_pointer_motion(edev, event);
953 _device_handle_pointer_motion_absolute(struct libinput_device *device, struct libinput_event_pointer *event)
958 if (!(edev = libinput_device_get_user_data(device)))
963 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
965 edev->mouse.dx = edev->seat->ptr.dx =
966 libinput_event_pointer_get_absolute_x_transformed(event, w);
967 edev->mouse.dy = edev->seat->ptr.dy =
968 libinput_event_pointer_get_absolute_y_transformed(event, h);
970 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
971 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
976 edev->seat->ptr.ix = edev->seat->ptr.dx;
977 edev->seat->ptr.iy = edev->seat->ptr.dy;
979 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
980 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
985 _device_pointer_motion(edev, event);
989 _device_handle_button(struct libinput_device *device, struct libinput_event_pointer *event)
992 E_Input_Backend *input;
993 Ecore_Event_Mouse_Button *ev;
994 enum libinput_button_state state;
995 uint32_t button, timestamp;
996 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
998 E_Comp_Config *comp_conf = NULL;
1000 if (!(edev = libinput_device_get_user_data(device)))
1004 if (!(input = edev->seat->input))
1009 ecore_thread_main_loop_begin();
1011 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1012 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1014 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1016 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1021 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1026 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1028 ecore_dev = detent_data;
1033 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1034 ecore_dev = edev->ecore_dev;
1039 ERR("Failed to get source ecore device from event !\n");
1043 state = libinput_event_pointer_get_button_state(event);
1044 button = libinput_event_pointer_get_button(event);
1045 timestamp = libinput_event_pointer_get_time(event);
1047 button = ((button & 0x00F) + 1);
1048 if (button == 3) button = 2;
1049 else if (button == 2) button = 3;
1053 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1054 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1056 ELOGF("Mouse", "Button Press (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
1057 button, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
1058 edev->seat->dev->server_blocked);
1063 edev->mouse.pressed_button |= (1 << button);
1068 if (!(edev->mouse.pressed_button & (1 << button)))
1070 ELOGF("Mouse", "Button Release (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
1071 button, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
1072 edev->seat->dev->server_blocked);
1075 edev->mouse.pressed_button &= ~(1 << button);
1078 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button))))
1083 ev->window = (Ecore_Window)input->dev->window;
1084 ev->event_window = (Ecore_Window)input->dev->window;
1085 ev->root_window = (Ecore_Window)input->dev->window;
1086 ev->timestamp = timestamp;
1087 ev->same_screen = 1;
1089 _device_modifiers_update(edev);
1090 ev->modifiers = edev->xkb.modifiers;
1092 ev->x = edev->seat->ptr.ix;
1093 ev->y = edev->seat->ptr.iy;
1097 ev->multi.device = edev->mt_slot;
1098 ev->multi.radius = 1;
1099 ev->multi.radius_x = 1;
1100 ev->multi.radius_y = 1;
1101 ev->multi.pressure = 1.0;
1102 ev->multi.angle = 0.0;
1103 ev->multi.x = ev->x;
1104 ev->multi.y = ev->y;
1105 ev->multi.root.x = ev->x;
1106 ev->multi.root.y = ev->y;
1107 ev->dev = ecore_device_ref(ecore_dev);
1111 unsigned int current;
1113 current = timestamp;
1114 edev->mouse.did_double = EINA_FALSE;
1115 edev->mouse.did_triple = EINA_FALSE;
1117 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1118 (button == edev->mouse.prev_button))
1120 edev->mouse.did_double = EINA_TRUE;
1121 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1122 (button == edev->mouse.last_button))
1124 edev->mouse.did_triple = EINA_TRUE;
1125 edev->mouse.prev = 0;
1126 edev->mouse.last = 0;
1131 edev->mouse.last = edev->mouse.prev;
1132 edev->mouse.prev = current;
1133 edev->mouse.last_button = edev->mouse.prev_button;
1134 edev->mouse.prev_button = button;
1137 ev->buttons = button;
1139 if (edev->mouse.did_double)
1140 ev->double_click = 1;
1141 if (edev->mouse.did_triple)
1142 ev->triple_click = 1;
1144 comp_conf = e_comp_config_get();
1145 if (comp_conf && comp_conf->input_log_enable)
1146 ELOGF("Mouse", "Button %s (btn: %d, device: %s)", NULL, state?"Press":"Release", button, ecore_device_name_get(ev->dev));
1149 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, _e_input_event_mouse_button_cb_free, NULL);
1151 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, _e_input_event_mouse_button_cb_free, NULL);
1154 ecore_thread_main_loop_end();
1157 #if !LIBINPUT_HAVE_SCROLL_VALUE_V120
1159 _axis_value_get(struct libinput_event_pointer *pointer_event, enum libinput_pointer_axis axis)
1161 enum libinput_pointer_axis_source source;
1162 double value = 0.0, value_discrete = 0.0;
1164 E_Comp_Config *comp_conf = NULL;
1166 comp_conf = e_comp_config_get();
1167 source = libinput_event_pointer_get_axis_source(pointer_event);
1170 case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL:
1171 value_discrete = libinput_event_pointer_get_axis_value_discrete(pointer_event, axis);
1172 value = libinput_event_pointer_get_axis_value(pointer_event, axis);
1173 if (comp_conf && comp_conf->input_log_enable)
1175 ELOGF("Axis", "SOURCE_WHEEL discrete: %lf (cf. value: %lf)", NULL, value_discrete, value);
1177 ret = (int)value_discrete;
1179 case LIBINPUT_POINTER_AXIS_SOURCE_FINGER:
1180 case LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS:
1181 value = libinput_event_pointer_get_axis_value(pointer_event, axis);
1182 if (comp_conf && comp_conf->input_log_enable)
1184 ELOGF("Axis", "SOURCE_FINGER/CONTINUOUS value: %lf", NULL, value);
1186 if (value >= E_INPUT_FINGER_SCROLL_THRESHOLD)
1188 else if (value <= E_INPUT_FINGER_SCROLL_THRESHOLD * (-1))
1201 _device_handle_axis(struct libinput_device *device, struct libinput_event_pointer *event)
1203 E_Input_Evdev *edev;
1204 E_Input_Backend *input;
1205 Ecore_Event_Mouse_Wheel *ev;
1207 enum libinput_pointer_axis axis;
1208 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1210 E_Comp_Config *comp_conf = NULL;
1211 int direction = 0, z = 0;
1213 if (!(edev = libinput_device_get_user_data(device)))
1217 if (!(input = edev->seat->input))
1222 ecore_thread_main_loop_begin();
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_MOUSE)
1234 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1239 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1241 ecore_dev = detent_data;
1246 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1247 ecore_dev = edev->ecore_dev;
1252 ERR("Failed to get source ecore device from event !\n");
1256 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1257 if (libinput_event_pointer_has_axis(event, axis))
1258 z = _axis_value_get(event, axis);
1260 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1261 if (libinput_event_pointer_has_axis(event, axis))
1264 z = _axis_value_get(event, axis);
1269 ELOGF("Mouse", "Axis event is ignored since it has zero value", NULL);
1273 comp_conf = e_comp_config_get();
1274 if (comp_conf && comp_conf->e_wheel_click_angle)
1276 z = (int)(z * comp_conf->e_wheel_click_angle);
1279 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1280 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1283 ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1284 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1286 ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1287 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1291 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1296 timestamp = libinput_event_pointer_get_time(event);
1298 ev->window = (Ecore_Window)input->dev->window;
1299 ev->event_window = (Ecore_Window)input->dev->window;
1300 ev->root_window = (Ecore_Window)input->dev->window;
1301 ev->timestamp = timestamp;
1302 ev->same_screen = 1;
1304 _device_modifiers_update(edev);
1305 ev->modifiers = edev->xkb.modifiers;
1307 ev->x = edev->seat->ptr.ix;
1308 ev->y = edev->seat->ptr.iy;
1312 ev->direction = direction;
1314 if (comp_conf && comp_conf->input_log_enable)
1317 ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1319 ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1323 ev->dev = ecore_device_ref(ecore_dev);
1324 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1327 ecore_thread_main_loop_end();
1331 #if LIBINPUT_HAVE_SCROLL_VALUE_V120
1333 _scroll_value_get(struct libinput_event_pointer *pointer_event, enum libinput_pointer_axis axis, E_Input_Axis_Source source)
1336 double value_v120 = 0.0;
1338 E_Comp_Config *comp_conf = NULL;
1340 comp_conf = e_comp_config_get();
1343 case E_INPUT_AXIS_SOURCE_WHEEL:
1344 value_v120 = libinput_event_pointer_get_scroll_value_v120(pointer_event, axis);
1345 value = libinput_event_pointer_get_scroll_value(pointer_event, axis);
1346 if (comp_conf && comp_conf->input_log_enable)
1348 ELOGF("Scroll", "SOURCE_WHEELL value_v120: %lf (cf. value: %lf)", NULL, value_v120, value);
1350 if (((int)value_v120 % E_INPUT_POINTER_AXIS_DISCRETE_STEP) != 0)
1352 ERR("Wheel movements should be multiples (or fractions) of 120!\n");
1357 ret = value_v120 / E_INPUT_POINTER_AXIS_DISCRETE_STEP;
1360 case E_INPUT_AXIS_SOURCE_FINGER:
1361 case E_INPUT_AXIS_SOURCE_CONTINUOUS:
1362 value = libinput_event_pointer_get_scroll_value(pointer_event, axis);
1363 if (comp_conf && comp_conf->input_log_enable)
1365 ELOGF("Scroll", "SOURCE_FINGER/CONTINUOUS value: %lf", NULL, value);
1367 if (value >= E_INPUT_FINGER_SCROLL_THRESHOLD)
1369 else if (value <= E_INPUT_FINGER_SCROLL_THRESHOLD * (-1))
1382 _device_handle_axis_v120(struct libinput_device *device, struct libinput_event_pointer *event, E_Input_Axis_Source source)
1384 E_Input_Evdev *edev;
1385 E_Input_Backend *input;
1386 Ecore_Event_Mouse_Wheel *ev;
1388 enum libinput_pointer_axis axis;
1389 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1391 E_Comp_Config *comp_conf = NULL;
1392 int direction = 0, z = 0;
1394 if (!(edev = libinput_device_get_user_data(device)))
1398 if (!(input = edev->seat->input))
1403 ecore_thread_main_loop_begin();
1405 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1406 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1408 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1410 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1415 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1420 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1422 ecore_dev = detent_data;
1427 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1428 ecore_dev = edev->ecore_dev;
1433 ERR("Failed to get source ecore device from event !\n");
1437 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1438 if (libinput_event_pointer_has_axis(event, axis))
1439 z = _scroll_value_get(event, axis, source);
1441 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1442 if (libinput_event_pointer_has_axis(event, axis))
1445 z = _scroll_value_get(event, axis, source);
1450 ELOGF("Mouse", "Scroll event is ignored since it has zero value", NULL);
1454 comp_conf = e_comp_config_get();
1455 if (comp_conf && comp_conf->e_wheel_click_angle)
1457 z = (int)(z * comp_conf->e_wheel_click_angle);
1460 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1461 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1464 ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1465 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1467 ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1468 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1472 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1477 timestamp = libinput_event_pointer_get_time(event);
1479 ev->window = (Ecore_Window)input->dev->window;
1480 ev->event_window = (Ecore_Window)input->dev->window;
1481 ev->root_window = (Ecore_Window)input->dev->window;
1482 ev->timestamp = timestamp;
1483 ev->same_screen = 1;
1485 _device_modifiers_update(edev);
1486 ev->modifiers = edev->xkb.modifiers;
1488 ev->x = edev->seat->ptr.ix;
1489 ev->y = edev->seat->ptr.iy;
1493 ev->direction = direction;
1495 if (comp_conf && comp_conf->input_log_enable)
1498 ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1500 ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1503 ev->dev = ecore_device_ref(ecore_dev);
1504 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1507 ecore_thread_main_loop_end();
1512 _device_handle_touch_event_send(E_Input_Evdev *edev, struct libinput_event_touch *event, int state)
1514 E_Input_Backend *input;
1515 Ecore_Event_Mouse_Button *ev;
1516 uint32_t timestamp, button = 0;
1517 Ecore_Device *ecore_dev = NULL, *data;
1521 if (!(input = edev->seat->input)) return;
1523 ecore_thread_main_loop_begin();
1525 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1526 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1528 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1530 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1539 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1540 ecore_dev = edev->ecore_dev;
1545 ERR("Failed to get source ecore device from event !\n");
1549 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) goto end;
1551 timestamp = libinput_event_touch_get_time(event);
1553 ev->window = (Ecore_Window)input->dev->window;
1554 ev->event_window = (Ecore_Window)input->dev->window;
1555 ev->root_window = (Ecore_Window)input->dev->window;
1556 ev->timestamp = timestamp;
1557 ev->same_screen = 1;
1559 _device_modifiers_update(edev);
1560 ev->modifiers = edev->xkb.modifiers;
1562 ev->x = edev->seat->ptr.ix;
1563 ev->y = edev->seat->ptr.iy;
1567 ev->multi.device = edev->mt_slot;
1568 ev->multi.radius = 1;
1569 ev->multi.radius_x = 1;
1570 ev->multi.radius_y = 1;
1571 ev->multi.pressure = 1.0;
1572 ev->multi.angle = 0.0;
1573 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1574 if (libinput_event_get_type(libinput_event_touch_get_base_event(event))
1575 == LIBINPUT_EVENT_TOUCH_DOWN)
1577 if (libinput_event_touch_has_minor(event))
1578 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1579 if (libinput_event_touch_has_major(event))
1580 ev->multi.radius_y = libinput_event_touch_get_major(event);
1581 if (libinput_event_touch_has_pressure(event))
1582 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1583 if (libinput_event_touch_has_orientation(event))
1584 ev->multi.angle = libinput_event_touch_get_orientation(event);
1587 ev->multi.x = ev->x;
1588 ev->multi.y = ev->y;
1589 ev->multi.root.x = ev->x;
1590 ev->multi.root.y = ev->y;
1591 ev->dev = ecore_device_ref(ecore_dev);
1593 if (state == ECORE_EVENT_MOUSE_BUTTON_DOWN)
1595 unsigned int current;
1597 current = timestamp;
1598 edev->mouse.did_double = EINA_FALSE;
1599 edev->mouse.did_triple = EINA_FALSE;
1601 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1602 (button == edev->mouse.prev_button))
1604 edev->mouse.did_double = EINA_TRUE;
1605 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1606 (button == edev->mouse.last_button))
1608 edev->mouse.did_triple = EINA_TRUE;
1609 edev->mouse.prev = 0;
1610 edev->mouse.last = 0;
1615 edev->mouse.last = edev->mouse.prev;
1616 edev->mouse.prev = current;
1617 edev->mouse.last_button = edev->mouse.prev_button;
1618 edev->mouse.prev_button = button;
1619 edev->touch.pressed |= (1 << ev->multi.device);
1623 edev->touch.pressed &= ~(1 << ev->multi.device);
1626 ev->buttons = ((button & 0x00F) + 1);
1628 if (edev->mouse.did_double)
1629 ev->double_click = 1;
1630 if (edev->mouse.did_triple)
1631 ev->triple_click = 1;
1633 ecore_event_add(state, ev, _e_input_event_mouse_button_cb_free, NULL);
1636 ecore_thread_main_loop_end();
1640 _device_handle_touch_motion_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1642 E_Input_Backend *input;
1643 Ecore_Event_Mouse_Move *ev;
1644 Ecore_Device *ecore_dev = NULL, *data;
1648 if (!(input = edev->seat->input)) return;
1650 ecore_thread_main_loop_begin();
1652 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1653 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1655 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1657 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1666 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1667 ecore_dev = edev->ecore_dev;
1672 ERR("Failed to get source ecore device from event !\n");
1676 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) goto end;
1678 ev->window = (Ecore_Window)input->dev->window;
1679 ev->event_window = (Ecore_Window)input->dev->window;
1680 ev->root_window = (Ecore_Window)input->dev->window;
1681 ev->timestamp = libinput_event_touch_get_time(event);
1682 ev->same_screen = 1;
1684 _device_modifiers_update(edev);
1685 ev->modifiers = edev->xkb.modifiers;
1687 ev->x = edev->seat->ptr.ix;
1688 ev->y = edev->seat->ptr.iy;
1692 ev->multi.device = edev->mt_slot;
1693 ev->multi.radius = 1;
1694 ev->multi.radius_x = 1;
1695 ev->multi.radius_y = 1;
1696 ev->multi.pressure = 1.0;
1697 ev->multi.angle = 0.0;
1698 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1699 if (libinput_event_touch_has_minor(event))
1700 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1701 if (libinput_event_touch_has_major(event))
1702 ev->multi.radius_y = libinput_event_touch_get_major(event);
1703 if (libinput_event_touch_has_pressure(event))
1704 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1705 if (libinput_event_touch_has_orientation(event))
1706 ev->multi.angle = libinput_event_touch_get_orientation(event);
1708 ev->multi.x = ev->x;
1709 ev->multi.y = ev->y;
1710 ev->multi.root.x = ev->x;
1711 ev->multi.root.y = ev->y;
1712 ev->dev = ecore_device_ref(ecore_dev);
1714 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
1717 ecore_thread_main_loop_end();
1721 _device_handle_touch_cancel_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1723 E_Input_Backend *input;
1724 Ecore_Event_Mouse_Button *ev;
1725 uint32_t timestamp, button = 0;
1726 Ecore_Device *ecore_dev = NULL, *data;
1730 if (!(input = edev->seat->input)) return;
1732 ecore_thread_main_loop_begin();
1734 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1735 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1737 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1739 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1748 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1749 ecore_dev = edev->ecore_dev;
1754 ERR("Failed to get source ecore device from event !\n");
1758 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) goto end;
1760 timestamp = libinput_event_touch_get_time(event);
1762 ev->window = (Ecore_Window)input->dev->window;
1763 ev->event_window = (Ecore_Window)input->dev->window;
1764 ev->root_window = (Ecore_Window)input->dev->window;
1765 ev->timestamp = timestamp;
1766 ev->same_screen = 1;
1768 ev->x = edev->seat->ptr.ix;
1769 ev->y = edev->seat->ptr.iy;
1773 ev->multi.device = edev->mt_slot;
1774 ev->multi.radius = 1;
1775 ev->multi.radius_x = 1;
1776 ev->multi.radius_y = 1;
1777 ev->multi.pressure = 1.0;
1778 ev->multi.angle = 0.0;
1779 ev->multi.x = ev->x;
1780 ev->multi.y = ev->y;
1781 ev->multi.root.x = ev->x;
1782 ev->multi.root.y = ev->y;
1784 edev->touch.pressed &= ~(1 << ev->multi.device);
1786 ev->buttons = ((button & 0x00F) + 1);
1787 ev->dev = ecore_device_ref(ecore_dev);
1789 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev, _e_input_event_mouse_button_cb_free, NULL);
1792 ecore_thread_main_loop_end();
1796 _device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, int *w, int *h)
1798 E_Output *output = NULL;
1800 EINA_SAFETY_ON_NULL_RETURN(edev);
1802 if (!edev->output_configured)
1804 if (edev->output_name)
1806 output = e_output_find(edev->output_name);
1809 edev->mouse.minx = output->config.geom.x;
1810 edev->mouse.miny = output->config.geom.y;
1811 edev->mouse.maxw = output->config.geom.w;
1812 edev->mouse.maxh = output->config.geom.h;
1813 if (libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
1815 edev->seat->ptr.dx = (double)(edev->mouse.maxw / 2);
1816 edev->seat->ptr.dy = (double)(edev->mouse.maxh / 2);
1817 edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
1818 edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
1819 edev->mouse.dx = edev->seat->ptr.dx;
1820 edev->mouse.dy = edev->seat->ptr.dy;
1825 edev->output_configured = EINA_TRUE;
1826 ELOGF("E_INPUT_EVDEV", "Device is configured by output x:%d,y:%d (w:%d, h:%d)",
1827 NULL, edev->mouse.minx, edev->mouse.miny, edev->mouse.maxw, edev->mouse.maxh);
1829 if (x) *x = edev->mouse.minx;
1830 if (y) *y = edev->mouse.miny;
1831 if (w) *w = edev->mouse.maxw;
1832 if (h) *h = edev->mouse.maxh;
1836 _device_handle_touch_down(struct libinput_device *device, struct libinput_event_touch *event)
1838 E_Input_Evdev *edev;
1839 int x = 0, y = 0, w = 0, h = 0;
1840 E_Comp_Config *comp_conf = NULL;
1842 if (!(edev = libinput_device_get_user_data(device)))
1847 _device_configured_size_get(edev, &x, &y, &w, &h);
1849 edev->mouse.dx = edev->seat->ptr.ix = edev->seat->ptr.dx =
1850 x + libinput_event_touch_get_x_transformed(event, w);
1851 edev->mouse.dy = edev->seat->ptr.iy = edev->seat->ptr.dy =
1852 y + libinput_event_touch_get_y_transformed(event, h);
1854 edev->mt_slot = libinput_event_touch_get_slot(event);
1855 if (edev->mt_slot < 0)
1857 /* FIXME: The single touch device return slot id -1
1858 * But currently we have no API to distinguish multi touch or single touch
1859 * After libinput 1.11 version, libinput provides get_touch_count API,
1860 * so we can distinguish multi touch device or single touch device.
1862 if (edev->mt_slot == -1)
1866 WRN("%d slot touch down events are not supported\n", edev->mt_slot);
1871 if (edev->mt_slot < e_input_touch_max_count_get())
1873 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
1874 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
1877 comp_conf = e_comp_config_get();
1878 if (comp_conf && comp_conf->input_log_enable)
1879 ELOGF("Touch", "Down (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
1881 edev->touch.raw_pressed |= (1 << edev->mt_slot);
1883 if (edev->touch.blocked)
1885 ELOGF("Touch", "Down (id: %d, x: %d, y: %d) is blocked by %p, server: 0x%x", NULL,
1886 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, edev->seat->dev->blocked_client,
1887 edev->seat->dev->server_blocked);
1891 _device_handle_touch_motion_send(edev, event);
1892 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_DOWN);
1896 _device_handle_touch_motion(struct libinput_device *device, struct libinput_event_touch *event)
1898 E_Input_Evdev *edev;
1899 int x = 0, y = 0, w = 0, h = 0;
1901 if (!(edev = libinput_device_get_user_data(device)))
1906 _device_configured_size_get(edev, &x, &y, &w, &h);
1908 edev->mouse.dx = edev->seat->ptr.dx =
1909 x + libinput_event_touch_get_x_transformed(event, w);
1910 edev->mouse.dy = edev->seat->ptr.dy =
1911 y + libinput_event_touch_get_y_transformed(event, h);
1913 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
1914 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
1919 edev->seat->ptr.ix = edev->seat->ptr.dx;
1920 edev->seat->ptr.iy = edev->seat->ptr.dy;
1922 edev->mt_slot = libinput_event_touch_get_slot(event);
1923 if (edev->mt_slot < 0)
1925 /* FIXME: The single touch device return slot id -1
1926 * But currently we have no API to distinguish multi touch or single touch
1927 * After libinput 1.11 version, libinput provides get_touch_count API,
1928 * so we can distinguish multi touch device or single touch device.
1930 if (edev->mt_slot == -1)
1934 WRN("%d slot touch motion events are not supported\n", edev->mt_slot);
1939 if (edev->mt_slot < e_input_touch_max_count_get())
1941 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
1942 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
1945 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
1947 if (edev->touch.blocked)
1953 _device_handle_touch_motion_send(edev, event);
1957 _device_handle_touch_up(struct libinput_device *device, struct libinput_event_touch *event)
1959 E_Input_Evdev *edev;
1960 E_Comp_Config *comp_conf = NULL;
1962 if (!(edev = libinput_device_get_user_data(device)))
1967 edev->mt_slot = libinput_event_touch_get_slot(event);
1968 if (edev->mt_slot < 0)
1970 /* FIXME: The single touch device return slot id -1
1971 * But currently we have no API to distinguish multi touch or single touch
1972 * After libinput 1.11 version, libinput provides get_touch_count API,
1973 * so we can distinguish multi touch device or single touch device.
1975 if (edev->mt_slot == -1)
1979 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
1984 if (edev->mt_slot < e_input_touch_max_count_get())
1986 edev->mouse.dx = edev->seat->ptr.dx = edev->seat->ptr.ix =
1987 edev->touch.coords[edev->mt_slot].x;
1988 edev->mouse.dy = edev->seat->ptr.dy = edev->seat->ptr.iy =
1989 edev->touch.coords[edev->mt_slot].y;
1992 comp_conf = e_comp_config_get();
1993 if (comp_conf && comp_conf->input_log_enable)
1994 ELOGF("Touch", "Up (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
1996 edev->touch.raw_pressed &= ~(1 << edev->mt_slot);
1998 if (edev->touch.blocked)
2000 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
2002 ELOGF("Touch", "Up (id: %d, x: %d, y: %d) is blocked by %p, server(0x%x)", NULL,
2003 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, edev->seat->dev->blocked_client,
2004 edev->seat->dev->server_blocked);
2005 if (edev->touch.raw_pressed == 0x0)
2007 edev->touch.blocked = EINA_FALSE;
2013 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_UP);
2017 _device_handle_touch_cancel(struct libinput_device *device, struct libinput_event_touch *event)
2019 E_Input_Evdev *edev;
2020 E_Comp_Config *comp_conf = NULL;
2022 if (!(edev = libinput_device_get_user_data(device)))
2027 edev->mt_slot = libinput_event_touch_get_slot(event);
2028 if (edev->mt_slot < 0)
2030 /* FIXME: The single touch device return slot id -1
2031 * But currently we have no API to distinguish multi touch or single touch
2032 * After libinput 1.11 version, libinput provides get_touch_count API,
2033 * so we can distinguish multi touch device or single touch device.
2035 if (edev->mt_slot == -1)
2039 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
2044 comp_conf = e_comp_config_get();
2045 if (comp_conf && comp_conf->input_log_enable)
2046 ELOGF("Touch", "cancel (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2048 _device_handle_touch_cancel_send(edev, event);
2053 _device_handle_touch_frame(struct libinput_device *device EINA_UNUSED, struct libinput_event_touch *event EINA_UNUSED)
2055 /* DBG("Unhandled Touch Frame Event"); */
2059 _e_input_aux_data_event_free(void *user_data EINA_UNUSED, void *ev)
2061 Ecore_Event_Axis_Update *e = (Ecore_Event_Axis_Update *)ev;
2063 if (e->axis) free(e->axis);
2064 if (e->dev) ecore_device_unref(e->dev);
2070 _device_handle_touch_aux_data(struct libinput_device *device, struct libinput_event_touch_aux_data *event)
2072 E_Input_Evdev *edev;
2073 E_Input_Backend *input;
2074 Ecore_Event_Axis_Update *ev;
2076 Ecore_Device *ecore_dev = NULL, *data;
2078 E_Comp_Config *comp_conf;
2080 ecore_thread_main_loop_begin();
2082 if (libinput_event_touch_aux_data_get_type(event) != LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM &&
2083 libinput_event_touch_aux_data_get_value(event) > 0)
2086 if (!(edev = libinput_device_get_user_data(device))) goto end;
2087 if (!(input = edev->seat->input)) goto end;
2089 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
2090 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
2092 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
2094 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
2103 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
2104 ecore_dev = edev->ecore_dev;
2109 ERR("Failed to get source ecore device from event !\n");
2113 if (!(ev = calloc(1, sizeof(Ecore_Event_Axis_Update)))) goto end;
2115 ev->window = (Ecore_Window)input->dev->window;
2116 ev->event_window = (Ecore_Window)input->dev->window;
2117 ev->root_window = (Ecore_Window)input->dev->window;
2118 ev->timestamp = libinput_event_touch_aux_data_get_time(event);
2120 axis = (Ecore_Axis *)calloc(1, sizeof(Ecore_Axis));
2123 axis->label = ECORE_AXIS_LABEL_TOUCH_PALM;
2124 axis->value = libinput_event_touch_aux_data_get_value(event);
2129 comp_conf = e_comp_config_get();
2130 if (comp_conf && comp_conf->input_log_enable)
2131 ELOGF("Touch", "Axis (label: %d, value: %lf)", NULL, axis?axis->label:-1, axis?axis->value:0.0);
2133 ev->dev = ecore_device_ref(ecore_dev);
2135 ecore_event_add(ECORE_EVENT_AXIS_UPDATE, ev, _e_input_aux_data_event_free, NULL);
2138 ecore_thread_main_loop_end();
2142 _e_input_evdev_device_create(E_Input_Seat *seat, struct libinput_device *device)
2144 E_Input_Evdev *edev;
2145 E_Input_Backend *b_input;
2146 const char *output_name;
2148 EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
2150 /* try to allocate space for new evdev */
2151 if (!(edev = calloc(1, sizeof(E_Input_Evdev)))) return NULL;
2154 edev->device = device;
2155 edev->path = eina_stringshare_printf("%s/%s", e_input_base_dir_get(), libinput_device_get_sysname(device));
2157 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
2159 edev->caps |= E_INPUT_SEAT_KEYBOARD;
2160 _device_keyboard_setup(edev);
2163 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
2165 edev->caps |= E_INPUT_SEAT_POINTER;
2167 /* TODO: make this configurable */
2168 edev->mouse.threshold = 250;
2170 b_input = seat->input;
2171 if (b_input->left_handed == EINA_TRUE)
2173 if (libinput_device_config_left_handed_set(device, 1) !=
2174 LIBINPUT_CONFIG_STATUS_SUCCESS)
2176 WRN("Failed to set left hand mode about device: %s\n",
2177 libinput_device_get_name(device));
2182 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
2185 edev->caps |= E_INPUT_SEAT_TOUCH;
2186 palm_code = libinput_device_touch_aux_data_get_code(LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM);
2187 if (libinput_device_touch_has_aux_data(device, palm_code))
2189 libinput_device_touch_set_aux_data(device, palm_code);
2192 _device_touch_count_update(edev);
2194 edev->touch.coords = calloc(1, sizeof(E_Input_Coord)*e_input_touch_max_count_get());
2196 if (!edev->touch.coords)
2197 ERR("Failed to allocate memory for touch coords !\n");
2200 output_name = libinput_device_get_output_name(device);
2203 eina_stringshare_replace(&edev->output_name, output_name);
2204 ELOGF("E_INPUT_EVDEV", "Device has output_name:%s", NULL, output_name);
2207 libinput_device_set_user_data(device, edev);
2208 libinput_device_ref(device);
2210 /* configure device */
2211 _device_configure(edev);
2217 _e_input_evdev_device_destroy(E_Input_Evdev *edev)
2221 EINA_SAFETY_ON_NULL_RETURN(edev);
2223 ecore_thread_main_loop_begin();
2225 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
2227 g_mutex_lock(&edev->xkb.state_mutex);
2228 if (edev->xkb.state) xkb_state_unref(edev->xkb.state);
2229 g_mutex_unlock(&edev->xkb.state_mutex);
2231 g_mutex_lock(&edev->xkb.keymap_mutex);
2232 if (edev->xkb.keymap) xkb_map_unref(edev->xkb.keymap);
2233 g_mutex_unlock(&edev->xkb.keymap_mutex);
2236 if (edev->ecore_dev) ecore_device_del(edev->ecore_dev);
2237 if (edev->ecore_dev_list)
2238 EINA_LIST_FREE(edev->ecore_dev_list, dev)
2240 ecore_device_del(dev);
2242 if (edev->path) eina_stringshare_del(edev->path);
2243 if (edev->device) libinput_device_unref(edev->device);
2244 if (edev->key_remap_hash) eina_hash_free(edev->key_remap_hash);
2245 if (edev->touch.coords)
2247 free(edev->touch.coords);
2248 edev->touch.coords = NULL;
2250 eina_stringshare_del(edev->output_name);
2252 ecore_thread_main_loop_end();
2258 _e_input_evdev_event_process(struct libinput_event *event)
2260 struct libinput_device *device;
2261 Eina_Bool ret = EINA_TRUE;
2263 device = libinput_event_get_device(event);
2264 switch (libinput_event_get_type(event))
2266 case LIBINPUT_EVENT_KEYBOARD_KEY:
2267 _device_handle_key(device, libinput_event_get_keyboard_event(event));
2269 case LIBINPUT_EVENT_POINTER_MOTION:
2270 _device_handle_pointer_motion(device,
2271 libinput_event_get_pointer_event(event));
2273 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
2274 _device_handle_pointer_motion_absolute(device,
2275 libinput_event_get_pointer_event(event));
2277 case LIBINPUT_EVENT_POINTER_BUTTON:
2278 _device_handle_button(device, libinput_event_get_pointer_event(event));
2280 case LIBINPUT_EVENT_POINTER_AXIS:
2281 #if !LIBINPUT_HAVE_SCROLL_VALUE_V120
2282 _device_handle_axis(device, libinput_event_get_pointer_event(event));
2285 #if LIBINPUT_HAVE_SCROLL_VALUE_V120
2286 case LIBINPUT_EVENT_POINTER_SCROLL_WHEEL:
2287 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_WHEEL);
2289 case LIBINPUT_EVENT_POINTER_SCROLL_FINGER:
2290 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_FINGER);
2292 case LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS:
2293 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_CONTINUOUS);
2296 case LIBINPUT_EVENT_TOUCH_DOWN:
2297 _device_handle_touch_down(device, libinput_event_get_touch_event(event));
2299 case LIBINPUT_EVENT_TOUCH_MOTION:
2300 _device_handle_touch_motion(device,
2301 libinput_event_get_touch_event(event));
2303 case LIBINPUT_EVENT_TOUCH_UP:
2304 _device_handle_touch_up(device, libinput_event_get_touch_event(event));
2306 case LIBINPUT_EVENT_TOUCH_CANCEL:
2307 _device_handle_touch_cancel(device, libinput_event_get_touch_event(event));
2309 case LIBINPUT_EVENT_TOUCH_FRAME:
2310 _device_handle_touch_frame(device, libinput_event_get_touch_event(event));
2312 case LIBINPUT_EVENT_TOUCH_AUX_DATA:
2313 _device_handle_touch_aux_data(device, libinput_event_get_touch_aux_data(event));
2324 * @brief Set the axis size of the given device.
2326 * @param dev The device to set the axis size to.
2327 * @param w The width of the axis.
2328 * @param h The height of the axis.
2330 * This function sets set the width @p w and height @p h of the axis
2331 * of device @p dev. If @p dev is a relative input device, a width and
2332 * height must set for it. If its absolute set the ioctl correctly, if
2333 * not, unsupported device.
2336 e_input_evdev_axis_size_set(E_Input_Evdev *edev, int w, int h)
2338 const char *sysname;
2343 enum libinput_config_status status;
2345 EINA_SAFETY_ON_NULL_RETURN(edev);
2346 EINA_SAFETY_ON_TRUE_RETURN((w == 0) || (h == 0));
2348 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
2349 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
2352 sysname = libinput_device_get_sysname(edev->device);
2354 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
2355 if (eina_list_count(devices) < 1) return;
2357 EINA_LIST_FREE(devices, device)
2359 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
2361 (sscanf(vals, "%f %f %f %f %f %f",
2362 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
2369 libinput_device_config_calibration_set_matrix(edev->device, cal);
2371 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
2372 ERR("Failed to apply calibration");
2375 eina_stringshare_del(device);
2380 EINTERN const char *
2381 e_input_evdev_name_get(E_Input_Evdev *evdev)
2383 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2384 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2386 return libinput_device_get_name(evdev->device);
2389 EINTERN const char *
2390 e_input_evdev_sysname_get(E_Input_Evdev *evdev)
2392 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2393 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2395 return libinput_device_get_sysname(evdev->device);
2399 e_input_evdev_key_remap_enable(E_Input_Evdev *edev, Eina_Bool enable)
2401 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2402 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2404 edev->key_remap_enabled = enable;
2406 if (enable == EINA_FALSE && edev->key_remap_hash)
2408 eina_hash_free(edev->key_remap_hash);
2409 edev->key_remap_hash = NULL;
2416 e_input_evdev_key_remap_set(E_Input_Evdev *edev, int *from_keys, int *to_keys, int num)
2420 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2421 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2422 EINA_SAFETY_ON_NULL_RETURN_VAL(from_keys, EINA_FALSE);
2423 EINA_SAFETY_ON_NULL_RETURN_VAL(to_keys, EINA_FALSE);
2424 EINA_SAFETY_ON_TRUE_RETURN_VAL(num <= 0, EINA_FALSE);
2425 EINA_SAFETY_ON_TRUE_RETURN_VAL(!edev->key_remap_enabled, EINA_FALSE);
2427 if (edev->key_remap_hash == NULL)
2428 edev->key_remap_hash = eina_hash_int32_new(NULL);
2430 if (edev->key_remap_hash == NULL)
2432 ERR("Failed to set remap key information : creating a hash is failed.");
2436 for (i = 0; i < num ; i++)
2438 if (!from_keys[i] || !to_keys[i])
2440 ERR("Failed to set remap key information : given arguments are invalid.");
2445 for (i = 0; i < num ; i++)
2447 eina_hash_add(edev->key_remap_hash, &from_keys[i], (void *)(intptr_t)to_keys[i]);
2454 e_input_evdev_wheel_click_angle_get(E_Input_Evdev *dev)
2456 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, -1);
2457 return libinput_device_config_scroll_get_wheel_click_angle(dev->device);
2461 e_input_evdev_touch_calibration_set(E_Input_Evdev *edev, float matrix[6])
2463 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2464 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2466 if (!libinput_device_config_calibration_has_matrix(edev->device) ||
2467 !libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_TOUCH))
2470 if (libinput_device_config_calibration_set_matrix(edev->device, matrix) !=
2471 LIBINPUT_CONFIG_STATUS_SUCCESS)
2473 WRN("Failed to set input transformation about device: %s\n",
2474 libinput_device_get_name(edev->device));
2482 e_input_evdev_mouse_accel_speed_set(E_Input_Evdev *edev, double speed)
2484 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2485 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2487 if (!libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
2490 if (!libinput_device_config_accel_is_available(edev->device))
2493 if (libinput_device_config_accel_set_speed(edev->device, speed) !=
2494 LIBINPUT_CONFIG_STATUS_SUCCESS)
2496 WRN("Failed to set mouse accel about device: %s\n",
2497 libinput_device_get_name(edev->device));
2504 EINTERN unsigned int
2505 e_input_evdev_touch_pressed_get(E_Input_Evdev *edev)
2507 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, 0x0);
2509 return edev->touch.pressed;
2513 e_input_evdev_seatname_get(E_Input_Evdev *evdev)
2515 struct libinput_seat *libinput_seat;
2516 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2517 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2519 libinput_seat = libinput_device_get_seat(evdev->device);
2521 return libinput_seat_get_logical_name(libinput_seat);
2525 e_input_evdev_seatname_set(E_Input_Evdev *evdev, const char *seatname)
2527 Eina_Bool res = EINA_FALSE;
2528 E_Input_Backend *input;
2530 EINA_SAFETY_ON_NULL_RETURN_VAL(seatname, EINA_FALSE);
2531 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, EINA_FALSE);
2532 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, EINA_FALSE);
2534 if (libinput_device_set_seat_logical_name(evdev->device, seatname) == 0)
2536 input = evdev->seat->input;
2537 if (!input) return EINA_FALSE;
2538 if (libinput_dispatch(input->libinput) != 0)
2540 ERR("Failed to dispatch libinput events: %m");
2544 /* process pending events */
2545 _input_events_process(input);
2553 e_input_evdev_mouse_accel_enable(E_Input_Evdev *edev, Eina_Bool enable)
2555 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2556 edev->disable_acceleration = !enable;