2 #include "e_input_private.h"
4 #include "e_keyrouter_private.h"
5 #include "e_input_event.h"
9 #define G_LIST_GET_DATA(list) ((list) ? (((GList *)(list))->data) : NULL)
11 static void _device_modifiers_update(E_Input_Evdev *edev);
12 static void _device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, int *w, int *h);
13 static void _device_output_assign(E_Input_Evdev *edev, E_Input_Seat_Capabilities cap);
16 _device_calibration_set(E_Input_Evdev *edev)
21 E_Comp_Config *comp_conf;
23 if (e_comp->e_comp_screen->num_outputs > 1) //multiple outputs
25 comp_conf = e_comp_config_get();
26 if (comp_conf && (comp_conf->input_output_assign_policy == 1)) //use output-assignment policy
28 _device_output_assign(edev, E_INPUT_SEAT_POINTER);
29 _device_output_assign(edev, E_INPUT_SEAT_TOUCH);
33 output = e_comp_screen_primary_output_get(e_comp->e_comp_screen);
34 e_output_size_get(output, &w, &h);
38 edev->mouse.minx = edev->mouse.miny = 0;
42 if (libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
44 edev->seat->ptr.dx = (double)(w / 2);
45 edev->seat->ptr.dy = (double)(h / 2);
46 edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
47 edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
48 edev->mouse.dx = edev->seat->ptr.dx;
49 edev->mouse.dy = edev->seat->ptr.dy;
51 if (output->config.rotation == 90 || output->config.rotation == 270)
53 temp = edev->mouse.minx;
54 edev->mouse.minx = edev->mouse.miny;
55 edev->mouse.miny = temp;
57 temp = edev->mouse.maxw;
58 edev->mouse.maxw = edev->mouse.maxh;
59 edev->mouse.maxh = temp;
65 #ifdef _F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
71 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
72 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
75 sysname = libinput_device_get_sysname(edev->device);
77 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
78 if (eina_list_count(devices) < 1) return;
80 #ifdef _F_E_INPUT_USE_WL_CALIBRATION_
82 enum libinput_config_status status;
84 EINA_LIST_FREE(devices, device)
86 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
88 (sscanf(vals, "%f %f %f %f %f %f",
89 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
96 libinput_device_config_calibration_set_matrix(edev->device, cal);
98 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
99 ERR("Failed to apply calibration");
102 eina_stringshare_del(device);
105 #endif//_F_E_INPUT_USE_WL_CALIBRATION_
106 #endif//_F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
111 _device_output_assign(E_Input_Evdev *edev, E_Input_Seat_Capabilities cap)
116 Eina_Bool need_assign_output = EINA_FALSE;
117 const char *output_name;
120 if (!(edev->caps & cap)) return;
121 if (edev->output_name) return; //already assigned
122 if (e_comp->e_comp_screen->num_outputs <= 1) return;
124 last_output_idx = e_comp->e_comp_screen->num_outputs - 1;
125 EINA_LIST_FOREACH(edev->seat->devices, l, ed)
127 if (!(ed->caps & cap)) continue;
128 if (ed == edev) continue;
131 need_assign_output = EINA_FALSE;
134 need_assign_output = EINA_TRUE;
136 if (need_assign_output)
138 output = e_output_find_by_index(last_output_idx);
139 if (!output || !output->info.connected) return;
140 output_name = e_output_output_id_get(output);
141 if (output_name) edev->output_name = eina_stringshare_add(output_name);
142 ELOGF("E_INPUT_EVDEV", "Device is assigned to output:%s", NULL, output_name);
147 _device_touch_count_update(E_Input_Evdev *edev)
149 unsigned int device_touch_count = 0;
150 static unsigned int _max_device_touch_count = 0;
152 E_Input *ei = e_input_get();
153 EINA_SAFETY_ON_NULL_RETURN(ei);
155 device_touch_count = libinput_device_touch_get_touch_count(edev->device);
157 if (_max_device_touch_count < device_touch_count)
158 _max_device_touch_count = device_touch_count;
160 if (e_config->configured_max_touch.use)
162 if (_max_device_touch_count > 0 && e_config->configured_max_touch.count > _max_device_touch_count)
164 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",
165 NULL, e_config->configured_max_touch.count, _max_device_touch_count, _max_device_touch_count);
166 ei->touch_max_count = _max_device_touch_count;
170 if (ei->touch_max_count != e_config->configured_max_touch.count)
172 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch_max_count has been updated to %d -> %d.\n",
173 NULL, ei->touch_max_count, e_config->configured_max_touch.count);
174 ei->touch_max_count = e_config->configured_max_touch.count;
180 if (ei->touch_max_count < _max_device_touch_count)
182 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch_max_count has been updated to %d -> %d.\n", NULL,
183 ei->touch_max_count, _max_device_touch_count);
184 ei->touch_max_count = _max_device_touch_count;
188 ei->touch_device_count++;
189 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch device count is %d.\n", NULL, ei->touch_device_count);
193 _device_configure(E_Input_Evdev *edev)
195 if (libinput_device_config_tap_get_finger_count(edev->device) > 0)
197 Eina_Bool tap = EINA_FALSE;
199 tap = libinput_device_config_tap_get_default_enabled(edev->device);
200 libinput_device_config_tap_set_enabled(edev->device, tap);
203 _device_calibration_set(edev);
207 _device_keyboard_setup(E_Input_Evdev *edev)
209 E_Input_Backend *input;
210 xkb_mod_index_t xkb_idx;
212 if ((!edev) || (!edev->seat)) return;
213 if (!(input = edev->seat->input)) return;
214 if (!input->dev->xkb_ctx) return;
216 g_mutex_init(&edev->xkb.keymap_mutex);
218 /* create keymap from xkb context */
219 g_mutex_lock(&edev->xkb.keymap_mutex);
220 edev->xkb.keymap = _e_input_device_cached_keymap_get(input->dev->xkb_ctx, NULL, 0);
221 if (!edev->xkb.keymap)
223 g_mutex_unlock(&edev->xkb.keymap_mutex);
224 ERR("Failed to create keymap: %m");
228 g_mutex_lock(&edev->xkb.state_mutex);
230 /* create xkb state */
231 if (!(edev->xkb.state = xkb_state_new(edev->xkb.keymap)))
233 g_mutex_unlock(&edev->xkb.state_mutex);
234 g_mutex_unlock(&edev->xkb.keymap_mutex);
235 ERR("Failed to create xkb state: %m");
239 g_mutex_unlock(&edev->xkb.state_mutex);
241 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CTRL);
242 if (xkb_idx != XKB_MOD_INVALID)
243 edev->xkb.ctrl_mask = 1 << xkb_idx;
245 edev->xkb.ctrl_mask = 0;
247 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_ALT);
248 if (xkb_idx != XKB_MOD_INVALID)
249 edev->xkb.alt_mask = 1 << xkb_idx;
251 edev->xkb.alt_mask = 0;
253 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_SHIFT);
254 if (xkb_idx != XKB_MOD_INVALID)
255 edev->xkb.shift_mask = 1 << xkb_idx;
257 edev->xkb.shift_mask = 0;
259 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_LOGO);
260 if (xkb_idx != XKB_MOD_INVALID)
261 edev->xkb.win_mask = 1 << xkb_idx;
263 edev->xkb.win_mask = 0;
265 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_SCROLL);
266 if (xkb_idx != XKB_MOD_INVALID)
267 edev->xkb.scroll_mask = 1 << xkb_idx;
269 edev->xkb.scroll_mask = 0;
271 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_NUM);
272 if (xkb_idx != XKB_MOD_INVALID)
273 edev->xkb.num_mask = 1 << xkb_idx;
275 edev->xkb.num_mask = 0;
277 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CAPS);
278 if (xkb_idx != XKB_MOD_INVALID)
279 edev->xkb.caps_mask = 1 << xkb_idx;
281 edev->xkb.caps_mask = 0;
283 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, "ISO_Level3_Shift");
284 if (xkb_idx != XKB_MOD_INVALID)
285 edev->xkb.altgr_mask = 1 << xkb_idx;
287 edev->xkb.altgr_mask = 0;
289 g_mutex_unlock(&edev->xkb.keymap_mutex);
293 _device_keysym_translate(xkb_keysym_t keysym, unsigned int modifiers, char *buffer, int bytes)
295 unsigned long hbytes = 0;
298 if (!keysym) return 0;
299 hbytes = (keysym >> 8);
304 (((keysym >= XKB_KEY_BackSpace) && (keysym <= XKB_KEY_Clear)) ||
305 (keysym == XKB_KEY_Return) || (keysym == XKB_KEY_Escape) ||
306 (keysym == XKB_KEY_KP_Space) || (keysym == XKB_KEY_KP_Tab) ||
307 (keysym == XKB_KEY_KP_Enter) ||
308 ((keysym >= XKB_KEY_KP_Multiply) && (keysym <= XKB_KEY_KP_9)) ||
309 (keysym == XKB_KEY_KP_Equal) || (keysym == XKB_KEY_Delete))))))
312 if (keysym == XKB_KEY_KP_Space)
313 c = (XKB_KEY_space & 0x7F);
314 else if (hbytes == 0xFF)
319 if (modifiers & ECORE_EVENT_MODIFIER_CTRL)
321 if (((c >= '@') && (c < '\177')) || c == ' ')
325 else if ((c >= '3') && (c <= '7'))
337 _device_modifiers_update_device(E_Input_Evdev *edev, E_Input_Evdev *from)
341 g_mutex_lock(&from->xkb.state_mutex);
343 edev->xkb.depressed =
344 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_DEPRESSED);
346 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LATCHED);
348 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LOCKED);
350 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_EFFECTIVE);
352 g_mutex_unlock(&from->xkb.state_mutex);
354 mask = (edev->xkb.depressed | edev->xkb.latched);
356 if (mask & from->xkb.ctrl_mask)
357 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_CTRL;
358 if (mask & from->xkb.alt_mask)
359 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALT;
360 if (mask & from->xkb.shift_mask)
361 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
362 if (mask & from->xkb.win_mask)
363 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_WIN;
364 if (mask & from->xkb.scroll_mask)
365 edev->xkb.modifiers |= ECORE_EVENT_LOCK_SCROLL;
366 if (mask & from->xkb.num_mask)
367 edev->xkb.modifiers |= ECORE_EVENT_LOCK_NUM;
368 if (mask & from->xkb.caps_mask)
369 edev->xkb.modifiers |= ECORE_EVENT_LOCK_CAPS;
370 if (mask & from->xkb.altgr_mask)
371 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALTGR;
375 _device_modifiers_update(E_Input_Evdev *edev)
380 edev->xkb.modifiers = 0;
382 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
383 _device_modifiers_update_device(edev, edev);
386 EINA_LIST_FOREACH(edev->seat->devices, l, ed)
388 if (!(ed->caps & E_INPUT_SEAT_KEYBOARD)) continue;
389 _device_modifiers_update_device(edev, ed);
396 _device_remapped_key_get(E_Input_Evdev *edev, int code)
400 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, code);
401 if (!edev->key_remap_enabled) return code;
402 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->key_remap_hash, code);
404 ret = eina_hash_find(edev->key_remap_hash, &code);
406 if (ret) code = (int)(intptr_t)ret;
412 e_input_evdev_get_e_device(const char *path, Ecore_Device_Class clas)
414 const GList *dev_list = NULL;
416 E_Device *dev = NULL;
417 const char *identifier;
419 if (!path) return NULL;
421 dev_list = e_device_list_get();
422 if (!dev_list) return NULL;
423 for (l = dev_list, dev = dev_list->data; \
425 l = g_list_next(l), dev = G_LIST_GET_DATA(l))
428 identifier = e_device_identifier_get(dev);
429 if (!identifier) continue;
430 if ((e_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
437 EINTERN Ecore_Device *
438 e_input_evdev_get_ecore_device(const char *path, Ecore_Device_Class clas)
440 const Eina_List *dev_list = NULL;
442 Ecore_Device *dev = NULL;
443 const char *identifier;
445 if (!path) return NULL;
447 dev_list = ecore_device_list();
448 if (!dev_list) return NULL;
449 EINA_LIST_FOREACH(dev_list, l, dev)
452 identifier = ecore_device_identifier_get(dev);
453 if (!identifier) continue;
454 if ((ecore_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
461 _e_input_event_mouse_move_cb_free(void *data EINA_UNUSED, void *event)
463 Ecore_Event_Mouse_Move *ev = event;
465 if (ev->dev) ecore_device_unref(ev->dev);
471 _e_input_event_mouse_wheel_cb_free(void *data EINA_UNUSED, void *event)
473 Ecore_Event_Mouse_Wheel *ev = event;
475 if (ev->dev) ecore_device_unref(ev->dev);
481 _e_input_event_mouse_button_cb_free(void *data EINA_UNUSED, void *event)
483 Ecore_Event_Mouse_Button *ev = event;
485 if (ev->dev) ecore_device_unref(ev->dev);
491 _e_input_event_key_cb_free(void *data EINA_UNUSED, void *event)
493 Ecore_Event_Key *ev = event;
495 if (e_input_thread_mode_get())
497 if (ev->dev) g_object_unref(ev->dev);
501 if (ev->dev) ecore_device_unref(ev->dev);
504 if (ev->data) E_FREE(ev->data);
510 _device_handle_key(struct libinput_device *device, struct libinput_event_keyboard *event)
513 E_Input_Backend *input;
515 uint32_t code, nsyms;
516 const xkb_keysym_t *syms;
517 enum libinput_key_state state;
519 xkb_keysym_t sym = XKB_KEY_NoSymbol;
520 char key[256] = {0, }, keyname[256] = {0, }, compose_buffer[256] = {0, };
522 char *tmp = NULL, *compose = NULL;
523 E_Keyrouter_Event_Data *key_data;
524 Ecore_Device *ecore_dev = NULL, *data;
525 E_Device *e_dev = NULL, *e_dev_data;
526 Eina_List *l = NULL, *l_next = NULL;
528 E_Comp_Config *comp_conf = NULL;
529 int *pressed_keycode = NULL, *idata = NULL;
530 Eina_Bool dup_found = EINA_FALSE;
531 const char* device_name = NULL;
533 if (!(edev = libinput_device_get_user_data(device)))
538 if (!(input = edev->seat->input))
543 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
544 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
546 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
548 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_KEYBOARD)
557 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
558 ecore_dev = edev->ecore_dev;
563 ERR("Failed to get source ecore device from event !\n");
567 if (edev->e_dev) e_dev = edev->e_dev;
568 else if (edev->e_dev_list && g_list_length(edev->e_dev_list) > 0)
570 glist = edev->e_dev_list;
573 e_dev_data = glist->data;
574 if (e_device_class_get(e_dev_data) == ECORE_DEVICE_CLASS_KEYBOARD)
580 glist = g_list_next(glist);
585 edev->e_dev = e_input_evdev_get_e_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
591 ERR("Failed to get source e device from event !\n");
595 timestamp = libinput_event_keyboard_get_time(event);
596 code = libinput_event_keyboard_get_key(event);
597 code = _device_remapped_key_get(edev, code + 8);
598 state = libinput_event_keyboard_get_key_state(event);
599 key_count = libinput_event_keyboard_get_seat_key_count(event);
601 if (state == LIBINPUT_KEY_STATE_PRESSED)
603 if ((edev->seat->dev->blocked & E_INPUT_SEAT_KEYBOARD) ||
604 (edev->seat->dev->server_blocked & E_INPUT_SEAT_KEYBOARD))
606 ELOGF("Key", "Press (keycode: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
607 code, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
608 edev->seat->dev->server_blocked);
612 /* FIXME: Currently to maintain press/release event pair during input block,
613 * used Eina_List and this is method used in devicemgr module.
614 * But we need to consider which way is better to maintain key press/release pair.
617 EINA_LIST_FOREACH(edev->xkb.pressed_keys, l, idata)
621 dup_found = EINA_TRUE;
627 pressed_keycode = E_NEW(int, 1);
628 EINA_SAFETY_ON_NULL_RETURN(pressed_keycode);
629 *pressed_keycode = code;
631 edev->xkb.pressed_keys = eina_list_append(edev->xkb.pressed_keys, pressed_keycode);
636 dup_found = EINA_FALSE;
637 EINA_LIST_FOREACH_SAFE(edev->xkb.pressed_keys, l, l_next, idata)
641 edev->xkb.pressed_keys = eina_list_remove_list(edev->xkb.pressed_keys, l);
643 dup_found = EINA_TRUE;
649 ELOGF("Key", "Release (keycode: %d, device: %s) is blocked by %p", NULL,
650 code, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client);
655 /* ignore key events that are not seat wide state changes */
656 if (((state == LIBINPUT_KEY_STATE_PRESSED) && (key_count != 1)) ||
657 ((state == LIBINPUT_KEY_STATE_RELEASED) && (key_count != 0)))
662 g_mutex_lock(&edev->xkb.state_mutex);
663 xkb_state_update_key(edev->xkb.state, code,
664 (state ? XKB_KEY_DOWN : XKB_KEY_UP));
666 /* get the keysym for this code */
667 nsyms = xkb_key_get_syms(edev->xkb.state, code, &syms);
668 g_mutex_unlock(&edev->xkb.state_mutex);
670 if (nsyms == 1) sym = syms[0];
672 /* If no keysym was found, name it "Keycode-NNN" */
673 if (sym == XKB_KEY_NoSymbol)
674 snprintf(key, sizeof(key), "Keycode-%u", code);
677 /* get the keyname for this sym */
678 xkb_keysym_get_name(sym, key, sizeof(key));
683 /* If no keyname was found, name it "Keycode-NNN" */
684 snprintf(keyname, sizeof(keyname), "Keycode-%u", code);
688 memcpy(keyname, key, sizeof(keyname));
691 /* if shift is active, we need to transform the key to lower */
692 g_mutex_lock(&edev->xkb.keymap_mutex);
693 g_mutex_lock(&edev->xkb.state_mutex);
694 if (xkb_state_mod_index_is_active(edev->xkb.state,
695 xkb_map_mod_get_index(edev->xkb.keymap,
697 XKB_STATE_MODS_EFFECTIVE))
699 if (keyname[0] != '\0')
700 keyname[0] = tolower(keyname[0]);
702 g_mutex_unlock(&edev->xkb.keymap_mutex);
703 g_mutex_unlock(&edev->xkb.state_mutex);
705 if (_device_keysym_translate(sym, edev->xkb.modifiers,
706 compose_buffer, sizeof(compose_buffer)))
708 compose = eina_str_convert("ISO8859-1", "UTF-8", compose_buffer);
711 ERR("E Input cannot convert input key string '%s' to UTF-8. "
712 "Is Eina built with iconv support?", compose_buffer);
718 if (!compose) compose = compose_buffer;
720 e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) +
721 ((compose[0] != '\0') ? strlen(compose) : 0) + 3);
727 key_data = E_NEW(E_Keyrouter_Event_Data, 1);
735 e->keyname = (char *)(e + 1);
736 e->key = e->keyname + strlen(keyname) + 1;
737 e->compose = strlen(compose) ? e->key + strlen(key) + 1 : NULL;
738 e->string = e->compose;
740 strncpy((char *)e->keyname, keyname, strlen(keyname));
741 strncpy((char *)e->key, key, strlen(key));
742 if (strlen(compose)) strncpy((char *)e->compose, compose, strlen(compose));
744 e->window = (Ecore_Window)input->dev->window;
745 e->event_window = (Ecore_Window)input->dev->window;
746 e->root_window = (Ecore_Window)input->dev->window;
747 e->timestamp = timestamp;
752 _device_modifiers_update(edev);
754 e->modifiers = edev->xkb.modifiers;
756 comp_conf = e_comp_config_get();
758 if (e_input_thread_mode_get())
760 e->dev = (Eo *)g_object_ref(e_dev);
761 device_name = e_device_name_get(e_dev);
762 e_input_event_add(input->event_source, state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
766 e->dev = ecore_device_ref(ecore_dev);
767 device_name = ecore_device_name_get(ecore_dev);
768 ecore_event_add(state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
771 if (comp_conf && comp_conf->input_log_enable)
772 ELOGF("Key", "%s (keyname: %s, keycode: %d, timestamp: %u, device: %s)", NULL, state?"Press":"Release", e->keyname, e->keycode, e->timestamp, device_name);
778 _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event)
780 E_Input_Backend *input;
781 Ecore_Event_Mouse_Move *ev;
782 Ecore_Device *ecore_dev = NULL, *data, *detent_data = NULL;
784 int x = 0, y = 0, w = 0, h = 0;
786 if (!(input = edev->seat->input)) return;
788 ecore_thread_main_loop_begin();
790 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
791 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
793 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
795 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
800 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
805 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
807 ecore_dev = detent_data;
812 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
813 ecore_dev = edev->ecore_dev;
818 ERR("Failed to get source ecore device from event !\n");
821 else if ((detent_data == ecore_dev) || e_devicemgr_detent_is_detent(ecore_device_name_get(ecore_dev)))
823 /* Do not process detent device's move events. */
827 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
829 _device_configured_size_get(edev, &x, &y, &w, &h);
831 if (edev->seat->ptr.ix < x)
832 edev->seat->ptr.dx = edev->seat->ptr.ix = x;
833 else if (edev->seat->ptr.ix >= (x + w))
834 edev->seat->ptr.dx = edev->seat->ptr.ix = (x + w - 1);
836 if (edev->seat->ptr.iy < y)
837 edev->seat->ptr.dy = edev->seat->ptr.iy = y;
838 else if (edev->seat->ptr.iy >= (y + h))
839 edev->seat->ptr.dy = edev->seat->ptr.iy = (y + h - 1);
841 edev->mouse.dx = edev->seat->ptr.dx;
842 edev->mouse.dy = edev->seat->ptr.dy;
844 ev->window = (Ecore_Window)input->dev->window;
845 ev->event_window = (Ecore_Window)input->dev->window;
846 ev->root_window = (Ecore_Window)input->dev->window;
847 if (event) ev->timestamp = libinput_event_pointer_get_time(event);
850 _device_modifiers_update(edev);
851 ev->modifiers = edev->xkb.modifiers;
853 ev->x = edev->seat->ptr.ix;
854 ev->y = edev->seat->ptr.iy;
858 ev->multi.device = edev->mt_slot;
859 ev->multi.radius = 1;
860 ev->multi.radius_x = 1;
861 ev->multi.radius_y = 1;
862 ev->multi.pressure = 1.0;
863 ev->multi.angle = 0.0;
866 ev->multi.root.x = ev->x;
867 ev->multi.root.y = ev->y;
869 ev->dev = ecore_device_ref(ecore_dev);
871 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
874 ecore_thread_main_loop_end();
878 _e_input_pointer_motion_post(E_Input_Evdev *edev)
880 _device_pointer_motion(edev, NULL);
884 _device_pointer_relative_motion_send(double dx[2], double dy[2], uint64_t time_us)
886 e_input_relative_motion_cb func = e_input_relative_motion_handler_get();
887 if (func) func(dx, dy, time_us);
891 _device_handle_pointer_motion(struct libinput_device *device, struct libinput_event_pointer *event)
894 double delta_x[2]; /* delta_x[0] for accelerated, delta_x[1] for unaccelerated */
895 double delta_y[2]; /* delta_y[0] for accelerated, delta_y[1] for unaccelerated */
898 if (!(edev = libinput_device_get_user_data(device)))
903 delta_x[0] = libinput_event_pointer_get_dx(event);
904 delta_x[1] = libinput_event_pointer_get_dx_unaccelerated(event);
905 delta_y[0] = libinput_event_pointer_get_dy(event);
906 delta_y[1] = libinput_event_pointer_get_dy_unaccelerated(event);
908 if (edev->disable_acceleration)
919 if (edev->seat->ptr.swap)
925 if (edev->seat->ptr.invert_x)
927 if (edev->seat->ptr.invert_y)
930 edev->seat->ptr.dx += dx;
931 edev->seat->ptr.dy += dy;
933 edev->mouse.dx = edev->seat->ptr.dx;
934 edev->mouse.dy = edev->seat->ptr.dy;
936 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
937 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
942 edev->seat->ptr.ix = edev->seat->ptr.dx;
943 edev->seat->ptr.iy = edev->seat->ptr.dy;
945 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
946 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
951 _device_pointer_relative_motion_send(&delta_x[0], &delta_y[0],
952 libinput_event_pointer_get_time_usec(event));
953 _device_pointer_motion(edev, event);
957 _device_handle_pointer_motion_absolute(struct libinput_device *device, struct libinput_event_pointer *event)
962 if (!(edev = libinput_device_get_user_data(device)))
967 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
969 edev->mouse.dx = edev->seat->ptr.dx =
970 libinput_event_pointer_get_absolute_x_transformed(event, w);
971 edev->mouse.dy = edev->seat->ptr.dy =
972 libinput_event_pointer_get_absolute_y_transformed(event, h);
974 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
975 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
980 edev->seat->ptr.ix = edev->seat->ptr.dx;
981 edev->seat->ptr.iy = edev->seat->ptr.dy;
983 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
984 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
989 _device_pointer_motion(edev, event);
993 _device_handle_button(struct libinput_device *device, struct libinput_event_pointer *event)
996 E_Input_Backend *input;
997 Ecore_Event_Mouse_Button *ev;
998 enum libinput_button_state state;
999 uint32_t button, timestamp;
1000 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1002 E_Comp_Config *comp_conf = NULL;
1004 if (!(edev = libinput_device_get_user_data(device)))
1008 if (!(input = edev->seat->input))
1013 ecore_thread_main_loop_begin();
1015 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1016 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1018 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1020 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1025 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1030 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1032 ecore_dev = detent_data;
1037 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1038 ecore_dev = edev->ecore_dev;
1043 ERR("Failed to get source ecore device from event !\n");
1047 state = libinput_event_pointer_get_button_state(event);
1048 button = libinput_event_pointer_get_button(event);
1049 timestamp = libinput_event_pointer_get_time(event);
1051 button = ((button & 0x00F) + 1);
1052 if (button == 3) button = 2;
1053 else if (button == 2) button = 3;
1057 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1058 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1060 ELOGF("Mouse", "Button Press (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
1061 button, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
1062 edev->seat->dev->server_blocked);
1067 edev->mouse.pressed_button |= (1 << button);
1072 if (!(edev->mouse.pressed_button & (1 << button)))
1074 ELOGF("Mouse", "Button Release (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
1075 button, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
1076 edev->seat->dev->server_blocked);
1079 edev->mouse.pressed_button &= ~(1 << button);
1082 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button))))
1087 ev->window = (Ecore_Window)input->dev->window;
1088 ev->event_window = (Ecore_Window)input->dev->window;
1089 ev->root_window = (Ecore_Window)input->dev->window;
1090 ev->timestamp = timestamp;
1091 ev->same_screen = 1;
1093 _device_modifiers_update(edev);
1094 ev->modifiers = edev->xkb.modifiers;
1096 ev->x = edev->seat->ptr.ix;
1097 ev->y = edev->seat->ptr.iy;
1101 ev->multi.device = edev->mt_slot;
1102 ev->multi.radius = 1;
1103 ev->multi.radius_x = 1;
1104 ev->multi.radius_y = 1;
1105 ev->multi.pressure = 1.0;
1106 ev->multi.angle = 0.0;
1107 ev->multi.x = ev->x;
1108 ev->multi.y = ev->y;
1109 ev->multi.root.x = ev->x;
1110 ev->multi.root.y = ev->y;
1111 ev->dev = ecore_device_ref(ecore_dev);
1115 unsigned int current;
1117 current = timestamp;
1118 edev->mouse.did_double = EINA_FALSE;
1119 edev->mouse.did_triple = EINA_FALSE;
1121 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1122 (button == edev->mouse.prev_button))
1124 edev->mouse.did_double = EINA_TRUE;
1125 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1126 (button == edev->mouse.last_button))
1128 edev->mouse.did_triple = EINA_TRUE;
1129 edev->mouse.prev = 0;
1130 edev->mouse.last = 0;
1135 edev->mouse.last = edev->mouse.prev;
1136 edev->mouse.prev = current;
1137 edev->mouse.last_button = edev->mouse.prev_button;
1138 edev->mouse.prev_button = button;
1141 ev->buttons = button;
1143 if (edev->mouse.did_double)
1144 ev->double_click = 1;
1145 if (edev->mouse.did_triple)
1146 ev->triple_click = 1;
1148 comp_conf = e_comp_config_get();
1149 if (comp_conf && comp_conf->input_log_enable)
1150 ELOGF("Mouse", "Button %s (btn: %d, device: %s)", NULL, state?"Press":"Release", button, ecore_device_name_get(ev->dev));
1153 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, _e_input_event_mouse_button_cb_free, NULL);
1155 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, _e_input_event_mouse_button_cb_free, NULL);
1158 ecore_thread_main_loop_end();
1161 #if !LIBINPUT_HAVE_SCROLL_VALUE_V120
1163 _axis_value_get(struct libinput_event_pointer *pointer_event, enum libinput_pointer_axis axis)
1165 enum libinput_pointer_axis_source source;
1166 double value = 0.0, value_discrete = 0.0;
1168 E_Comp_Config *comp_conf = NULL;
1170 comp_conf = e_comp_config_get();
1171 source = libinput_event_pointer_get_axis_source(pointer_event);
1174 case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL:
1175 value_discrete = libinput_event_pointer_get_axis_value_discrete(pointer_event, axis);
1176 value = libinput_event_pointer_get_axis_value(pointer_event, axis);
1177 if (comp_conf && comp_conf->input_log_enable)
1179 ELOGF("Axis", "SOURCE_WHEEL discrete: %lf (cf. value: %lf)", NULL, value_discrete, value);
1181 ret = (int)value_discrete;
1183 case LIBINPUT_POINTER_AXIS_SOURCE_FINGER:
1184 case LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS:
1185 value = libinput_event_pointer_get_axis_value(pointer_event, axis);
1186 if (comp_conf && comp_conf->input_log_enable)
1188 ELOGF("Axis", "SOURCE_FINGER/CONTINUOUS value: %lf", NULL, value);
1190 if (value >= E_INPUT_FINGER_SCROLL_THRESHOLD)
1192 else if (value <= E_INPUT_FINGER_SCROLL_THRESHOLD * (-1))
1205 _device_handle_axis(struct libinput_device *device, struct libinput_event_pointer *event)
1207 E_Input_Evdev *edev;
1208 E_Input_Backend *input;
1209 Ecore_Event_Mouse_Wheel *ev;
1211 enum libinput_pointer_axis axis;
1212 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1214 E_Comp_Config *comp_conf = NULL;
1215 int direction = 0, z = 0;
1217 if (!(edev = libinput_device_get_user_data(device)))
1221 if (!(input = edev->seat->input))
1226 ecore_thread_main_loop_begin();
1228 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1229 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1231 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1233 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1238 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1243 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1245 ecore_dev = detent_data;
1250 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1251 ecore_dev = edev->ecore_dev;
1256 ERR("Failed to get source ecore device from event !\n");
1260 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1261 if (libinput_event_pointer_has_axis(event, axis))
1262 z = _axis_value_get(event, axis);
1264 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1265 if (libinput_event_pointer_has_axis(event, axis))
1268 z = _axis_value_get(event, axis);
1273 ELOGF("Mouse", "Axis event is ignored since it has zero value", NULL);
1277 comp_conf = e_comp_config_get();
1278 if (comp_conf && comp_conf->e_wheel_click_angle)
1280 z = (int)(z * comp_conf->e_wheel_click_angle);
1283 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1284 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1287 ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1288 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1290 ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1291 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1295 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1300 timestamp = libinput_event_pointer_get_time(event);
1302 ev->window = (Ecore_Window)input->dev->window;
1303 ev->event_window = (Ecore_Window)input->dev->window;
1304 ev->root_window = (Ecore_Window)input->dev->window;
1305 ev->timestamp = timestamp;
1306 ev->same_screen = 1;
1308 _device_modifiers_update(edev);
1309 ev->modifiers = edev->xkb.modifiers;
1311 ev->x = edev->seat->ptr.ix;
1312 ev->y = edev->seat->ptr.iy;
1316 ev->direction = direction;
1318 if (comp_conf && comp_conf->input_log_enable)
1321 ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1323 ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1327 ev->dev = ecore_device_ref(ecore_dev);
1328 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1331 ecore_thread_main_loop_end();
1335 #if LIBINPUT_HAVE_SCROLL_VALUE_V120
1337 _scroll_value_get(struct libinput_event_pointer *pointer_event, enum libinput_pointer_axis axis, E_Input_Axis_Source source)
1340 double value_v120 = 0.0;
1342 E_Comp_Config *comp_conf = NULL;
1344 comp_conf = e_comp_config_get();
1347 case E_INPUT_AXIS_SOURCE_WHEEL:
1348 value_v120 = libinput_event_pointer_get_scroll_value_v120(pointer_event, axis);
1349 value = libinput_event_pointer_get_scroll_value(pointer_event, axis);
1350 if (comp_conf && comp_conf->input_log_enable)
1352 ELOGF("Scroll", "SOURCE_WHEELL value_v120: %lf (cf. value: %lf)", NULL, value_v120, value);
1354 if (((int)value_v120 % E_INPUT_POINTER_AXIS_DISCRETE_STEP) != 0)
1356 ERR("Wheel movements should be multiples (or fractions) of 120!\n");
1361 ret = value_v120 / E_INPUT_POINTER_AXIS_DISCRETE_STEP;
1364 case E_INPUT_AXIS_SOURCE_FINGER:
1365 case E_INPUT_AXIS_SOURCE_CONTINUOUS:
1366 value = libinput_event_pointer_get_scroll_value(pointer_event, axis);
1367 if (comp_conf && comp_conf->input_log_enable)
1369 ELOGF("Scroll", "SOURCE_FINGER/CONTINUOUS value: %lf", NULL, value);
1371 if (value >= E_INPUT_FINGER_SCROLL_THRESHOLD)
1373 else if (value <= E_INPUT_FINGER_SCROLL_THRESHOLD * (-1))
1386 _device_handle_axis_v120(struct libinput_device *device, struct libinput_event_pointer *event, E_Input_Axis_Source source)
1388 E_Input_Evdev *edev;
1389 E_Input_Backend *input;
1390 Ecore_Event_Mouse_Wheel *ev;
1392 enum libinput_pointer_axis axis;
1393 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1395 E_Comp_Config *comp_conf = NULL;
1396 int direction = 0, z = 0;
1398 if (!(edev = libinput_device_get_user_data(device)))
1402 if (!(input = edev->seat->input))
1407 ecore_thread_main_loop_begin();
1409 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1410 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1412 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1414 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1419 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1424 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1426 ecore_dev = detent_data;
1431 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1432 ecore_dev = edev->ecore_dev;
1437 ERR("Failed to get source ecore device from event !\n");
1441 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1442 if (libinput_event_pointer_has_axis(event, axis))
1443 z = _scroll_value_get(event, axis, source);
1445 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1446 if (libinput_event_pointer_has_axis(event, axis))
1449 z = _scroll_value_get(event, axis, source);
1454 ELOGF("Mouse", "Scroll event is ignored since it has zero value", NULL);
1458 comp_conf = e_comp_config_get();
1459 if (comp_conf && comp_conf->e_wheel_click_angle)
1461 z = (int)(z * comp_conf->e_wheel_click_angle);
1464 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1465 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1468 ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1469 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1471 ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1472 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1476 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1481 timestamp = libinput_event_pointer_get_time(event);
1483 ev->window = (Ecore_Window)input->dev->window;
1484 ev->event_window = (Ecore_Window)input->dev->window;
1485 ev->root_window = (Ecore_Window)input->dev->window;
1486 ev->timestamp = timestamp;
1487 ev->same_screen = 1;
1489 _device_modifiers_update(edev);
1490 ev->modifiers = edev->xkb.modifiers;
1492 ev->x = edev->seat->ptr.ix;
1493 ev->y = edev->seat->ptr.iy;
1497 ev->direction = direction;
1499 if (comp_conf && comp_conf->input_log_enable)
1502 ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1504 ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1507 ev->dev = ecore_device_ref(ecore_dev);
1508 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1511 ecore_thread_main_loop_end();
1516 _device_handle_touch_event_send(E_Input_Evdev *edev, struct libinput_event_touch *event, int state)
1518 E_Input_Backend *input;
1519 Ecore_Event_Mouse_Button *ev;
1520 uint32_t timestamp, button = 0;
1521 Ecore_Device *ecore_dev = NULL, *data;
1525 if (!(input = edev->seat->input)) return;
1527 ecore_thread_main_loop_begin();
1529 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1530 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1532 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1534 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1543 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1544 ecore_dev = edev->ecore_dev;
1549 ERR("Failed to get source ecore device from event !\n");
1553 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) goto end;
1555 timestamp = libinput_event_touch_get_time(event);
1557 ev->window = (Ecore_Window)input->dev->window;
1558 ev->event_window = (Ecore_Window)input->dev->window;
1559 ev->root_window = (Ecore_Window)input->dev->window;
1560 ev->timestamp = timestamp;
1561 ev->same_screen = 1;
1563 _device_modifiers_update(edev);
1564 ev->modifiers = edev->xkb.modifiers;
1566 ev->x = edev->seat->ptr.ix;
1567 ev->y = edev->seat->ptr.iy;
1571 ev->multi.device = edev->mt_slot;
1572 ev->multi.radius = 1;
1573 ev->multi.radius_x = 1;
1574 ev->multi.radius_y = 1;
1575 ev->multi.pressure = 1.0;
1576 ev->multi.angle = 0.0;
1577 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1578 if (libinput_event_get_type(libinput_event_touch_get_base_event(event))
1579 == LIBINPUT_EVENT_TOUCH_DOWN)
1581 if (libinput_event_touch_has_minor(event))
1582 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1583 if (libinput_event_touch_has_major(event))
1584 ev->multi.radius_y = libinput_event_touch_get_major(event);
1585 if (libinput_event_touch_has_pressure(event))
1586 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1587 if (libinput_event_touch_has_orientation(event))
1588 ev->multi.angle = libinput_event_touch_get_orientation(event);
1591 ev->multi.x = ev->x;
1592 ev->multi.y = ev->y;
1593 ev->multi.root.x = ev->x;
1594 ev->multi.root.y = ev->y;
1595 ev->dev = ecore_device_ref(ecore_dev);
1597 if (state == ECORE_EVENT_MOUSE_BUTTON_DOWN)
1599 unsigned int current;
1601 current = timestamp;
1602 edev->mouse.did_double = EINA_FALSE;
1603 edev->mouse.did_triple = EINA_FALSE;
1605 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1606 (button == edev->mouse.prev_button))
1608 edev->mouse.did_double = EINA_TRUE;
1609 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1610 (button == edev->mouse.last_button))
1612 edev->mouse.did_triple = EINA_TRUE;
1613 edev->mouse.prev = 0;
1614 edev->mouse.last = 0;
1619 edev->mouse.last = edev->mouse.prev;
1620 edev->mouse.prev = current;
1621 edev->mouse.last_button = edev->mouse.prev_button;
1622 edev->mouse.prev_button = button;
1623 edev->touch.pressed |= (1 << ev->multi.device);
1627 edev->touch.pressed &= ~(1 << ev->multi.device);
1630 ev->buttons = ((button & 0x00F) + 1);
1632 if (edev->mouse.did_double)
1633 ev->double_click = 1;
1634 if (edev->mouse.did_triple)
1635 ev->triple_click = 1;
1637 ecore_event_add(state, ev, _e_input_event_mouse_button_cb_free, NULL);
1640 ecore_thread_main_loop_end();
1644 _device_handle_touch_motion_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1646 E_Input_Backend *input;
1647 Ecore_Event_Mouse_Move *ev;
1648 Ecore_Device *ecore_dev = NULL, *data;
1652 if (!(input = edev->seat->input)) return;
1654 ecore_thread_main_loop_begin();
1656 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1657 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1659 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1661 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1670 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1671 ecore_dev = edev->ecore_dev;
1676 ERR("Failed to get source ecore device from event !\n");
1680 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) goto end;
1682 ev->window = (Ecore_Window)input->dev->window;
1683 ev->event_window = (Ecore_Window)input->dev->window;
1684 ev->root_window = (Ecore_Window)input->dev->window;
1685 ev->timestamp = libinput_event_touch_get_time(event);
1686 ev->same_screen = 1;
1688 _device_modifiers_update(edev);
1689 ev->modifiers = edev->xkb.modifiers;
1691 ev->x = edev->seat->ptr.ix;
1692 ev->y = edev->seat->ptr.iy;
1696 ev->multi.device = edev->mt_slot;
1697 ev->multi.radius = 1;
1698 ev->multi.radius_x = 1;
1699 ev->multi.radius_y = 1;
1700 ev->multi.pressure = 1.0;
1701 ev->multi.angle = 0.0;
1702 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1703 if (libinput_event_touch_has_minor(event))
1704 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1705 if (libinput_event_touch_has_major(event))
1706 ev->multi.radius_y = libinput_event_touch_get_major(event);
1707 if (libinput_event_touch_has_pressure(event))
1708 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1709 if (libinput_event_touch_has_orientation(event))
1710 ev->multi.angle = libinput_event_touch_get_orientation(event);
1712 ev->multi.x = ev->x;
1713 ev->multi.y = ev->y;
1714 ev->multi.root.x = ev->x;
1715 ev->multi.root.y = ev->y;
1716 ev->dev = ecore_device_ref(ecore_dev);
1718 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
1721 ecore_thread_main_loop_end();
1725 _device_handle_touch_cancel_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1727 E_Input_Backend *input;
1728 Ecore_Event_Mouse_Button *ev;
1729 uint32_t timestamp, button = 0;
1730 Ecore_Device *ecore_dev = NULL, *data;
1734 if (!(input = edev->seat->input)) return;
1736 ecore_thread_main_loop_begin();
1738 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1739 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1741 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1743 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1752 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1753 ecore_dev = edev->ecore_dev;
1758 ERR("Failed to get source ecore device from event !\n");
1762 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) goto end;
1764 timestamp = libinput_event_touch_get_time(event);
1766 ev->window = (Ecore_Window)input->dev->window;
1767 ev->event_window = (Ecore_Window)input->dev->window;
1768 ev->root_window = (Ecore_Window)input->dev->window;
1769 ev->timestamp = timestamp;
1770 ev->same_screen = 1;
1772 ev->x = edev->seat->ptr.ix;
1773 ev->y = edev->seat->ptr.iy;
1777 ev->multi.device = edev->mt_slot;
1778 ev->multi.radius = 1;
1779 ev->multi.radius_x = 1;
1780 ev->multi.radius_y = 1;
1781 ev->multi.pressure = 1.0;
1782 ev->multi.angle = 0.0;
1783 ev->multi.x = ev->x;
1784 ev->multi.y = ev->y;
1785 ev->multi.root.x = ev->x;
1786 ev->multi.root.y = ev->y;
1788 edev->touch.pressed &= ~(1 << ev->multi.device);
1790 ev->buttons = ((button & 0x00F) + 1);
1791 ev->dev = ecore_device_ref(ecore_dev);
1793 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev, _e_input_event_mouse_button_cb_free, NULL);
1796 ecore_thread_main_loop_end();
1800 _device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, int *w, int *h)
1802 E_Output *output = NULL;
1804 EINA_SAFETY_ON_NULL_RETURN(edev);
1806 if (!edev->output_configured)
1808 if (edev->output_name)
1810 output = e_output_find(edev->output_name);
1813 edev->mouse.minx = output->config.geom.x;
1814 edev->mouse.miny = output->config.geom.y;
1815 edev->mouse.maxw = output->config.geom.w;
1816 edev->mouse.maxh = output->config.geom.h;
1817 if (libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
1819 edev->seat->ptr.dx = (double)(edev->mouse.maxw / 2);
1820 edev->seat->ptr.dy = (double)(edev->mouse.maxh / 2);
1821 edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
1822 edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
1823 edev->mouse.dx = edev->seat->ptr.dx;
1824 edev->mouse.dy = edev->seat->ptr.dy;
1829 edev->output_configured = EINA_TRUE;
1830 ELOGF("E_INPUT_EVDEV", "Device is configured by output x:%d,y:%d (w:%d, h:%d)",
1831 NULL, edev->mouse.minx, edev->mouse.miny, edev->mouse.maxw, edev->mouse.maxh);
1833 if (x) *x = edev->mouse.minx;
1834 if (y) *y = edev->mouse.miny;
1835 if (w) *w = edev->mouse.maxw;
1836 if (h) *h = edev->mouse.maxh;
1840 _device_handle_touch_down(struct libinput_device *device, struct libinput_event_touch *event)
1842 E_Input_Evdev *edev;
1843 int x = 0, y = 0, w = 0, h = 0;
1844 E_Comp_Config *comp_conf = NULL;
1846 if (!(edev = libinput_device_get_user_data(device)))
1851 _device_configured_size_get(edev, &x, &y, &w, &h);
1853 edev->mouse.dx = edev->seat->ptr.ix = edev->seat->ptr.dx =
1854 x + libinput_event_touch_get_x_transformed(event, w);
1855 edev->mouse.dy = edev->seat->ptr.iy = edev->seat->ptr.dy =
1856 y + libinput_event_touch_get_y_transformed(event, h);
1858 edev->mt_slot = libinput_event_touch_get_slot(event);
1859 if (edev->mt_slot < 0)
1861 /* FIXME: The single touch device return slot id -1
1862 * But currently we have no API to distinguish multi touch or single touch
1863 * After libinput 1.11 version, libinput provides get_touch_count API,
1864 * so we can distinguish multi touch device or single touch device.
1866 if (edev->mt_slot == -1)
1870 WRN("%d slot touch down events are not supported\n", edev->mt_slot);
1875 if (edev->mt_slot < e_input_touch_max_count_get())
1877 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
1878 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
1881 comp_conf = e_comp_config_get();
1882 if (comp_conf && comp_conf->input_log_enable)
1883 ELOGF("Touch", "Down (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
1885 edev->touch.raw_pressed |= (1 << edev->mt_slot);
1887 if (edev->touch.blocked)
1889 ELOGF("Touch", "Down (id: %d, x: %d, y: %d) is blocked by %p, server: 0x%x", NULL,
1890 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, edev->seat->dev->blocked_client,
1891 edev->seat->dev->server_blocked);
1895 _device_handle_touch_motion_send(edev, event);
1896 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_DOWN);
1900 _device_handle_touch_motion(struct libinput_device *device, struct libinput_event_touch *event)
1902 E_Input_Evdev *edev;
1903 int x = 0, y = 0, w = 0, h = 0;
1905 if (!(edev = libinput_device_get_user_data(device)))
1910 _device_configured_size_get(edev, &x, &y, &w, &h);
1912 edev->mouse.dx = edev->seat->ptr.dx =
1913 x + libinput_event_touch_get_x_transformed(event, w);
1914 edev->mouse.dy = edev->seat->ptr.dy =
1915 y + libinput_event_touch_get_y_transformed(event, h);
1917 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
1918 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
1923 edev->seat->ptr.ix = edev->seat->ptr.dx;
1924 edev->seat->ptr.iy = edev->seat->ptr.dy;
1926 edev->mt_slot = libinput_event_touch_get_slot(event);
1927 if (edev->mt_slot < 0)
1929 /* FIXME: The single touch device return slot id -1
1930 * But currently we have no API to distinguish multi touch or single touch
1931 * After libinput 1.11 version, libinput provides get_touch_count API,
1932 * so we can distinguish multi touch device or single touch device.
1934 if (edev->mt_slot == -1)
1938 WRN("%d slot touch motion events are not supported\n", edev->mt_slot);
1943 if (edev->mt_slot < e_input_touch_max_count_get())
1945 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
1946 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
1949 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
1951 if (edev->touch.blocked)
1957 _device_handle_touch_motion_send(edev, event);
1961 _device_handle_touch_up(struct libinput_device *device, struct libinput_event_touch *event)
1963 E_Input_Evdev *edev;
1964 E_Comp_Config *comp_conf = NULL;
1966 if (!(edev = libinput_device_get_user_data(device)))
1971 edev->mt_slot = libinput_event_touch_get_slot(event);
1972 if (edev->mt_slot < 0)
1974 /* FIXME: The single touch device return slot id -1
1975 * But currently we have no API to distinguish multi touch or single touch
1976 * After libinput 1.11 version, libinput provides get_touch_count API,
1977 * so we can distinguish multi touch device or single touch device.
1979 if (edev->mt_slot == -1)
1983 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
1988 if (edev->mt_slot < e_input_touch_max_count_get())
1990 edev->mouse.dx = edev->seat->ptr.dx = edev->seat->ptr.ix =
1991 edev->touch.coords[edev->mt_slot].x;
1992 edev->mouse.dy = edev->seat->ptr.dy = edev->seat->ptr.iy =
1993 edev->touch.coords[edev->mt_slot].y;
1996 comp_conf = e_comp_config_get();
1997 if (comp_conf && comp_conf->input_log_enable)
1998 ELOGF("Touch", "Up (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2000 edev->touch.raw_pressed &= ~(1 << edev->mt_slot);
2002 if (edev->touch.blocked)
2004 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
2006 ELOGF("Touch", "Up (id: %d, x: %d, y: %d) is blocked by %p, server(0x%x)", NULL,
2007 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, edev->seat->dev->blocked_client,
2008 edev->seat->dev->server_blocked);
2009 if (edev->touch.raw_pressed == 0x0)
2011 edev->touch.blocked = EINA_FALSE;
2017 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_UP);
2021 _device_handle_touch_cancel(struct libinput_device *device, struct libinput_event_touch *event)
2023 E_Input_Evdev *edev;
2024 E_Comp_Config *comp_conf = NULL;
2026 if (!(edev = libinput_device_get_user_data(device)))
2031 edev->mt_slot = libinput_event_touch_get_slot(event);
2032 if (edev->mt_slot < 0)
2034 /* FIXME: The single touch device return slot id -1
2035 * But currently we have no API to distinguish multi touch or single touch
2036 * After libinput 1.11 version, libinput provides get_touch_count API,
2037 * so we can distinguish multi touch device or single touch device.
2039 if (edev->mt_slot == -1)
2043 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
2048 comp_conf = e_comp_config_get();
2049 if (comp_conf && comp_conf->input_log_enable)
2050 ELOGF("Touch", "cancel (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2052 _device_handle_touch_cancel_send(edev, event);
2057 _device_handle_touch_frame(struct libinput_device *device EINA_UNUSED, struct libinput_event_touch *event EINA_UNUSED)
2059 /* DBG("Unhandled Touch Frame Event"); */
2063 _e_input_aux_data_event_free(void *user_data EINA_UNUSED, void *ev)
2065 Ecore_Event_Axis_Update *e = (Ecore_Event_Axis_Update *)ev;
2067 if (e->axis) free(e->axis);
2068 if (e->dev) ecore_device_unref(e->dev);
2074 _device_handle_touch_aux_data(struct libinput_device *device, struct libinput_event_touch_aux_data *event)
2076 E_Input_Evdev *edev;
2077 E_Input_Backend *input;
2078 Ecore_Event_Axis_Update *ev;
2080 Ecore_Device *ecore_dev = NULL, *data;
2082 E_Comp_Config *comp_conf;
2084 ecore_thread_main_loop_begin();
2086 if (libinput_event_touch_aux_data_get_type(event) != LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM &&
2087 libinput_event_touch_aux_data_get_value(event) > 0)
2090 if (!(edev = libinput_device_get_user_data(device))) goto end;
2091 if (!(input = edev->seat->input)) goto end;
2093 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
2094 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
2096 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
2098 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
2107 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
2108 ecore_dev = edev->ecore_dev;
2113 ERR("Failed to get source ecore device from event !\n");
2117 if (!(ev = calloc(1, sizeof(Ecore_Event_Axis_Update)))) goto end;
2119 ev->window = (Ecore_Window)input->dev->window;
2120 ev->event_window = (Ecore_Window)input->dev->window;
2121 ev->root_window = (Ecore_Window)input->dev->window;
2122 ev->timestamp = libinput_event_touch_aux_data_get_time(event);
2124 axis = (Ecore_Axis *)calloc(1, sizeof(Ecore_Axis));
2127 axis->label = ECORE_AXIS_LABEL_TOUCH_PALM;
2128 axis->value = libinput_event_touch_aux_data_get_value(event);
2133 comp_conf = e_comp_config_get();
2134 if (comp_conf && comp_conf->input_log_enable)
2135 ELOGF("Touch", "Axis (label: %d, value: %lf)", NULL, axis?axis->label:-1, axis?axis->value:0.0);
2137 ev->dev = ecore_device_ref(ecore_dev);
2139 ecore_event_add(ECORE_EVENT_AXIS_UPDATE, ev, _e_input_aux_data_event_free, NULL);
2142 ecore_thread_main_loop_end();
2146 _e_input_evdev_device_create(E_Input_Seat *seat, struct libinput_device *device)
2148 E_Input_Evdev *edev;
2149 E_Input_Backend *b_input;
2150 const char *output_name;
2152 EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
2154 /* try to allocate space for new evdev */
2155 if (!(edev = calloc(1, sizeof(E_Input_Evdev)))) return NULL;
2158 edev->device = device;
2159 edev->path = eina_stringshare_printf("%s/%s", e_input_base_dir_get(), libinput_device_get_sysname(device));
2161 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
2163 edev->caps |= E_INPUT_SEAT_KEYBOARD;
2164 _device_keyboard_setup(edev);
2167 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
2169 edev->caps |= E_INPUT_SEAT_POINTER;
2171 /* TODO: make this configurable */
2172 edev->mouse.threshold = 250;
2174 b_input = seat->input;
2175 if (b_input->left_handed == EINA_TRUE)
2177 if (libinput_device_config_left_handed_set(device, 1) !=
2178 LIBINPUT_CONFIG_STATUS_SUCCESS)
2180 WRN("Failed to set left hand mode about device: %s\n",
2181 libinput_device_get_name(device));
2186 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
2189 edev->caps |= E_INPUT_SEAT_TOUCH;
2190 palm_code = libinput_device_touch_aux_data_get_code(LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM);
2191 if (libinput_device_touch_has_aux_data(device, palm_code))
2193 libinput_device_touch_set_aux_data(device, palm_code);
2196 _device_touch_count_update(edev);
2198 edev->touch.coords = calloc(1, sizeof(E_Input_Coord)*e_input_touch_max_count_get());
2200 if (!edev->touch.coords)
2201 ERR("Failed to allocate memory for touch coords !\n");
2204 output_name = libinput_device_get_output_name(device);
2207 eina_stringshare_replace(&edev->output_name, output_name);
2208 ELOGF("E_INPUT_EVDEV", "Device has output_name:%s", NULL, output_name);
2211 libinput_device_set_user_data(device, edev);
2212 libinput_device_ref(device);
2214 /* configure device */
2215 _device_configure(edev);
2221 _e_input_evdev_device_destroy(E_Input_Evdev *edev)
2225 EINA_SAFETY_ON_NULL_RETURN(edev);
2227 ecore_thread_main_loop_begin();
2229 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
2231 g_mutex_lock(&edev->xkb.state_mutex);
2232 if (edev->xkb.state) xkb_state_unref(edev->xkb.state);
2233 g_mutex_unlock(&edev->xkb.state_mutex);
2235 g_mutex_lock(&edev->xkb.keymap_mutex);
2236 if (edev->xkb.keymap) xkb_map_unref(edev->xkb.keymap);
2237 g_mutex_unlock(&edev->xkb.keymap_mutex);
2240 if (edev->ecore_dev) ecore_device_del(edev->ecore_dev);
2241 if (edev->ecore_dev_list)
2242 EINA_LIST_FREE(edev->ecore_dev_list, dev)
2244 ecore_device_del(dev);
2246 if (edev->path) eina_stringshare_del(edev->path);
2247 if (edev->device) libinput_device_unref(edev->device);
2248 if (edev->key_remap_hash) eina_hash_free(edev->key_remap_hash);
2249 if (edev->touch.coords)
2251 free(edev->touch.coords);
2252 edev->touch.coords = NULL;
2254 eina_stringshare_del(edev->output_name);
2256 ecore_thread_main_loop_end();
2262 _e_input_evdev_event_process(struct libinput_event *event)
2264 struct libinput_device *device;
2265 Eina_Bool ret = EINA_TRUE;
2267 device = libinput_event_get_device(event);
2268 switch (libinput_event_get_type(event))
2270 case LIBINPUT_EVENT_KEYBOARD_KEY:
2271 _device_handle_key(device, libinput_event_get_keyboard_event(event));
2273 case LIBINPUT_EVENT_POINTER_MOTION:
2274 _device_handle_pointer_motion(device,
2275 libinput_event_get_pointer_event(event));
2277 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
2278 _device_handle_pointer_motion_absolute(device,
2279 libinput_event_get_pointer_event(event));
2281 case LIBINPUT_EVENT_POINTER_BUTTON:
2282 _device_handle_button(device, libinput_event_get_pointer_event(event));
2284 case LIBINPUT_EVENT_POINTER_AXIS:
2285 #if !LIBINPUT_HAVE_SCROLL_VALUE_V120
2286 _device_handle_axis(device, libinput_event_get_pointer_event(event));
2289 #if LIBINPUT_HAVE_SCROLL_VALUE_V120
2290 case LIBINPUT_EVENT_POINTER_SCROLL_WHEEL:
2291 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_WHEEL);
2293 case LIBINPUT_EVENT_POINTER_SCROLL_FINGER:
2294 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_FINGER);
2296 case LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS:
2297 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_CONTINUOUS);
2300 case LIBINPUT_EVENT_TOUCH_DOWN:
2301 _device_handle_touch_down(device, libinput_event_get_touch_event(event));
2303 case LIBINPUT_EVENT_TOUCH_MOTION:
2304 _device_handle_touch_motion(device,
2305 libinput_event_get_touch_event(event));
2307 case LIBINPUT_EVENT_TOUCH_UP:
2308 _device_handle_touch_up(device, libinput_event_get_touch_event(event));
2310 case LIBINPUT_EVENT_TOUCH_CANCEL:
2311 _device_handle_touch_cancel(device, libinput_event_get_touch_event(event));
2313 case LIBINPUT_EVENT_TOUCH_FRAME:
2314 _device_handle_touch_frame(device, libinput_event_get_touch_event(event));
2316 case LIBINPUT_EVENT_TOUCH_AUX_DATA:
2317 _device_handle_touch_aux_data(device, libinput_event_get_touch_aux_data(event));
2328 * @brief Set the axis size of the given device.
2330 * @param dev The device to set the axis size to.
2331 * @param w The width of the axis.
2332 * @param h The height of the axis.
2334 * This function sets set the width @p w and height @p h of the axis
2335 * of device @p dev. If @p dev is a relative input device, a width and
2336 * height must set for it. If its absolute set the ioctl correctly, if
2337 * not, unsupported device.
2340 e_input_evdev_axis_size_set(E_Input_Evdev *edev, int w, int h)
2342 const char *sysname;
2347 enum libinput_config_status status;
2349 EINA_SAFETY_ON_NULL_RETURN(edev);
2350 EINA_SAFETY_ON_TRUE_RETURN((w == 0) || (h == 0));
2352 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
2353 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
2356 sysname = libinput_device_get_sysname(edev->device);
2358 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
2359 if (eina_list_count(devices) < 1) return;
2361 EINA_LIST_FREE(devices, device)
2363 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
2365 (sscanf(vals, "%f %f %f %f %f %f",
2366 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
2373 libinput_device_config_calibration_set_matrix(edev->device, cal);
2375 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
2376 ERR("Failed to apply calibration");
2379 eina_stringshare_del(device);
2384 EINTERN const char *
2385 e_input_evdev_name_get(E_Input_Evdev *evdev)
2387 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2388 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2390 return libinput_device_get_name(evdev->device);
2393 EINTERN const char *
2394 e_input_evdev_sysname_get(E_Input_Evdev *evdev)
2396 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2397 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2399 return libinput_device_get_sysname(evdev->device);
2403 e_input_evdev_key_remap_enable(E_Input_Evdev *edev, Eina_Bool enable)
2405 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2406 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2408 edev->key_remap_enabled = enable;
2410 if (enable == EINA_FALSE && edev->key_remap_hash)
2412 eina_hash_free(edev->key_remap_hash);
2413 edev->key_remap_hash = NULL;
2420 e_input_evdev_key_remap_set(E_Input_Evdev *edev, int *from_keys, int *to_keys, int num)
2424 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2425 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2426 EINA_SAFETY_ON_NULL_RETURN_VAL(from_keys, EINA_FALSE);
2427 EINA_SAFETY_ON_NULL_RETURN_VAL(to_keys, EINA_FALSE);
2428 EINA_SAFETY_ON_TRUE_RETURN_VAL(num <= 0, EINA_FALSE);
2429 EINA_SAFETY_ON_TRUE_RETURN_VAL(!edev->key_remap_enabled, EINA_FALSE);
2431 if (edev->key_remap_hash == NULL)
2432 edev->key_remap_hash = eina_hash_int32_new(NULL);
2434 if (edev->key_remap_hash == NULL)
2436 ERR("Failed to set remap key information : creating a hash is failed.");
2440 for (i = 0; i < num ; i++)
2442 if (!from_keys[i] || !to_keys[i])
2444 ERR("Failed to set remap key information : given arguments are invalid.");
2449 for (i = 0; i < num ; i++)
2451 eina_hash_add(edev->key_remap_hash, &from_keys[i], (void *)(intptr_t)to_keys[i]);
2458 e_input_evdev_wheel_click_angle_get(E_Input_Evdev *dev)
2460 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, -1);
2461 return libinput_device_config_scroll_get_wheel_click_angle(dev->device);
2465 e_input_evdev_touch_calibration_set(E_Input_Evdev *edev, float matrix[6])
2467 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2468 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2470 if (!libinput_device_config_calibration_has_matrix(edev->device) ||
2471 !libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_TOUCH))
2474 if (libinput_device_config_calibration_set_matrix(edev->device, matrix) !=
2475 LIBINPUT_CONFIG_STATUS_SUCCESS)
2477 WRN("Failed to set input transformation about device: %s\n",
2478 libinput_device_get_name(edev->device));
2486 e_input_evdev_mouse_accel_speed_set(E_Input_Evdev *edev, double speed)
2488 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2489 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2491 if (!libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
2494 if (!libinput_device_config_accel_is_available(edev->device))
2497 if (libinput_device_config_accel_set_speed(edev->device, speed) !=
2498 LIBINPUT_CONFIG_STATUS_SUCCESS)
2500 WRN("Failed to set mouse accel about device: %s\n",
2501 libinput_device_get_name(edev->device));
2508 EINTERN unsigned int
2509 e_input_evdev_touch_pressed_get(E_Input_Evdev *edev)
2511 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, 0x0);
2513 return edev->touch.pressed;
2517 e_input_evdev_seatname_get(E_Input_Evdev *evdev)
2519 struct libinput_seat *libinput_seat;
2520 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2521 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2523 libinput_seat = libinput_device_get_seat(evdev->device);
2525 return libinput_seat_get_logical_name(libinput_seat);
2529 e_input_evdev_seatname_set(E_Input_Evdev *evdev, const char *seatname)
2531 Eina_Bool res = EINA_FALSE;
2532 E_Input_Backend *input;
2534 EINA_SAFETY_ON_NULL_RETURN_VAL(seatname, EINA_FALSE);
2535 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, EINA_FALSE);
2536 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, EINA_FALSE);
2538 if (libinput_device_set_seat_logical_name(evdev->device, seatname) == 0)
2540 input = evdev->seat->input;
2541 if (!input) return EINA_FALSE;
2542 if (libinput_dispatch(input->libinput) != 0)
2544 ERR("Failed to dispatch libinput events: %m");
2548 /* process pending events */
2549 _input_events_process(input);
2557 e_input_evdev_mouse_accel_enable(E_Input_Evdev *edev, Eina_Bool enable)
2559 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2560 edev->disable_acceleration = !enable;