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;
429 identifier = e_device_identifier_get(dev);
430 if (!identifier) continue;
431 if ((e_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
440 EINTERN Ecore_Device *
441 e_input_evdev_get_ecore_device(const char *path, Ecore_Device_Class clas)
443 const Eina_List *dev_list = NULL;
445 Ecore_Device *dev = NULL;
446 const char *identifier;
448 if (!path) return NULL;
450 dev_list = ecore_device_list();
451 if (!dev_list) return NULL;
452 EINA_LIST_FOREACH(dev_list, l, dev)
455 identifier = ecore_device_identifier_get(dev);
456 if (!identifier) continue;
457 if ((ecore_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
464 _e_input_event_mouse_move_cb_free(void *data EINA_UNUSED, void *event)
466 Ecore_Event_Mouse_Move *ev = event;
468 if (ev->dev) ecore_device_unref(ev->dev);
474 _e_input_event_mouse_wheel_cb_free(void *data EINA_UNUSED, void *event)
476 Ecore_Event_Mouse_Wheel *ev = event;
478 if (ev->dev) ecore_device_unref(ev->dev);
484 _e_input_event_mouse_button_cb_free(void *data EINA_UNUSED, void *event)
486 Ecore_Event_Mouse_Button *ev = event;
488 if (ev->dev) ecore_device_unref(ev->dev);
494 _e_input_event_key_cb_free(void *data EINA_UNUSED, void *event)
496 Ecore_Event_Key *ev = event;
498 if (e_input_thread_mode_get())
500 if (ev->dev) g_object_unref(ev->dev);
504 if (ev->dev) ecore_device_unref(ev->dev);
507 if (ev->data) E_FREE(ev->data);
513 _device_handle_key(struct libinput_device *device, struct libinput_event_keyboard *event)
516 E_Input_Backend *input;
518 uint32_t code, nsyms;
519 const xkb_keysym_t *syms;
520 enum libinput_key_state state;
522 xkb_keysym_t sym = XKB_KEY_NoSymbol;
523 char key[256] = {0, }, keyname[256] = {0, }, compose_buffer[256] = {0, };
525 char *tmp = NULL, *compose = NULL;
526 E_Keyrouter_Event_Data *key_data;
527 Ecore_Device *ecore_dev = NULL, *data;
528 E_Device *e_dev = NULL, *e_dev_data;
529 Eina_List *l = NULL, *l_next = NULL;
531 E_Comp_Config *comp_conf = NULL;
532 int *pressed_keycode = NULL, *idata = NULL;
533 Eina_Bool dup_found = EINA_FALSE;
534 const char* device_name = NULL;
536 if (!(edev = libinput_device_get_user_data(device)))
541 if (!(input = edev->seat->input))
546 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
547 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
549 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
551 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_KEYBOARD)
560 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
561 ecore_dev = edev->ecore_dev;
566 ERR("Failed to get source ecore device from event !\n");
570 if (edev->e_dev) e_dev = edev->e_dev;
571 else if (edev->e_dev_list && g_list_length(edev->e_dev_list) > 0)
573 glist = edev->e_dev_list;
576 e_dev_data = glist->data;
577 if (e_device_class_get(e_dev_data) == ECORE_DEVICE_CLASS_KEYBOARD)
583 glist = g_list_next(glist);
588 edev->e_dev = e_input_evdev_get_e_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
594 ERR("Failed to get source e device from event !\n");
598 timestamp = libinput_event_keyboard_get_time(event);
599 code = libinput_event_keyboard_get_key(event);
600 code = _device_remapped_key_get(edev, code + 8);
601 state = libinput_event_keyboard_get_key_state(event);
602 key_count = libinput_event_keyboard_get_seat_key_count(event);
604 if (state == LIBINPUT_KEY_STATE_PRESSED)
606 if ((edev->seat->dev->blocked & E_INPUT_SEAT_KEYBOARD) ||
607 (edev->seat->dev->server_blocked & E_INPUT_SEAT_KEYBOARD))
609 ELOGF("Key", "Press (keycode: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
610 code, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
611 edev->seat->dev->server_blocked);
615 /* FIXME: Currently to maintain press/release event pair during input block,
616 * used Eina_List and this is method used in devicemgr module.
617 * But we need to consider which way is better to maintain key press/release pair.
620 EINA_LIST_FOREACH(edev->xkb.pressed_keys, l, idata)
624 dup_found = EINA_TRUE;
630 pressed_keycode = E_NEW(int, 1);
631 EINA_SAFETY_ON_NULL_RETURN(pressed_keycode);
632 *pressed_keycode = code;
634 edev->xkb.pressed_keys = eina_list_append(edev->xkb.pressed_keys, pressed_keycode);
639 dup_found = EINA_FALSE;
640 EINA_LIST_FOREACH_SAFE(edev->xkb.pressed_keys, l, l_next, idata)
644 edev->xkb.pressed_keys = eina_list_remove_list(edev->xkb.pressed_keys, l);
646 dup_found = EINA_TRUE;
652 ELOGF("Key", "Release (keycode: %d, device: %s) is blocked by %p", NULL,
653 code, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client);
658 /* ignore key events that are not seat wide state changes */
659 if (((state == LIBINPUT_KEY_STATE_PRESSED) && (key_count != 1)) ||
660 ((state == LIBINPUT_KEY_STATE_RELEASED) && (key_count != 0)))
665 g_mutex_lock(&edev->xkb.state_mutex);
666 xkb_state_update_key(edev->xkb.state, code,
667 (state ? XKB_KEY_DOWN : XKB_KEY_UP));
669 /* get the keysym for this code */
670 nsyms = xkb_key_get_syms(edev->xkb.state, code, &syms);
671 g_mutex_unlock(&edev->xkb.state_mutex);
673 if (nsyms == 1) sym = syms[0];
675 /* If no keysym was found, name it "Keycode-NNN" */
676 if (sym == XKB_KEY_NoSymbol)
677 snprintf(key, sizeof(key), "Keycode-%u", code);
680 /* get the keyname for this sym */
681 xkb_keysym_get_name(sym, key, sizeof(key));
686 /* If no keyname was found, name it "Keycode-NNN" */
687 snprintf(keyname, sizeof(keyname), "Keycode-%u", code);
691 memcpy(keyname, key, sizeof(keyname));
694 /* if shift is active, we need to transform the key to lower */
695 g_mutex_lock(&edev->xkb.keymap_mutex);
696 g_mutex_lock(&edev->xkb.state_mutex);
697 if (xkb_state_mod_index_is_active(edev->xkb.state,
698 xkb_map_mod_get_index(edev->xkb.keymap,
700 XKB_STATE_MODS_EFFECTIVE))
702 if (keyname[0] != '\0')
703 keyname[0] = tolower(keyname[0]);
705 g_mutex_unlock(&edev->xkb.keymap_mutex);
706 g_mutex_unlock(&edev->xkb.state_mutex);
708 if (_device_keysym_translate(sym, edev->xkb.modifiers,
709 compose_buffer, sizeof(compose_buffer)))
711 compose = eina_str_convert("ISO8859-1", "UTF-8", compose_buffer);
714 ERR("E Input cannot convert input key string '%s' to UTF-8. "
715 "Is Eina built with iconv support?", compose_buffer);
721 if (!compose) compose = compose_buffer;
723 e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) +
724 ((compose[0] != '\0') ? strlen(compose) : 0) + 3);
730 key_data = E_NEW(E_Keyrouter_Event_Data, 1);
738 e->keyname = (char *)(e + 1);
739 e->key = e->keyname + strlen(keyname) + 1;
740 e->compose = strlen(compose) ? e->key + strlen(key) + 1 : NULL;
741 e->string = e->compose;
743 strncpy((char *)e->keyname, keyname, strlen(keyname));
744 strncpy((char *)e->key, key, strlen(key));
745 if (strlen(compose)) strncpy((char *)e->compose, compose, strlen(compose));
747 e->window = (Ecore_Window)input->dev->window;
748 e->event_window = (Ecore_Window)input->dev->window;
749 e->root_window = (Ecore_Window)input->dev->window;
750 e->timestamp = timestamp;
755 _device_modifiers_update(edev);
757 e->modifiers = edev->xkb.modifiers;
759 comp_conf = e_comp_config_get();
761 if (e_input_thread_mode_get())
763 e->dev = (Eo *)g_object_ref(e_dev);
764 device_name = e_device_name_get(e_dev);
765 e_input_event_add(input->event_source, state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
769 e->dev = ecore_device_ref(ecore_dev);
770 device_name = ecore_device_name_get(ecore_dev);
771 ecore_event_add(state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
774 if (comp_conf && comp_conf->input_log_enable)
775 ELOGF("Key", "%s (keyname: %s, keycode: %d, timestamp: %u, device: %s)", NULL, state?"Press":"Release", e->keyname, e->keycode, e->timestamp, device_name);
781 _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event)
783 E_Input_Backend *input;
784 Ecore_Event_Mouse_Move *ev;
785 Ecore_Device *ecore_dev = NULL, *data, *detent_data = NULL;
787 int x = 0, y = 0, w = 0, h = 0;
789 if (!(input = edev->seat->input)) return;
791 ecore_thread_main_loop_begin();
793 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
794 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
796 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
798 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
803 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
808 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
810 ecore_dev = detent_data;
815 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
816 ecore_dev = edev->ecore_dev;
821 ERR("Failed to get source ecore device from event !\n");
824 else if ((detent_data == ecore_dev) || e_devicemgr_detent_is_detent(ecore_device_name_get(ecore_dev)))
826 /* Do not process detent device's move events. */
830 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
832 _device_configured_size_get(edev, &x, &y, &w, &h);
834 if (edev->seat->ptr.ix < x)
835 edev->seat->ptr.dx = edev->seat->ptr.ix = x;
836 else if (edev->seat->ptr.ix >= (x + w))
837 edev->seat->ptr.dx = edev->seat->ptr.ix = (x + w - 1);
839 if (edev->seat->ptr.iy < y)
840 edev->seat->ptr.dy = edev->seat->ptr.iy = y;
841 else if (edev->seat->ptr.iy >= (y + h))
842 edev->seat->ptr.dy = edev->seat->ptr.iy = (y + h - 1);
844 edev->mouse.dx = edev->seat->ptr.dx;
845 edev->mouse.dy = edev->seat->ptr.dy;
847 ev->window = (Ecore_Window)input->dev->window;
848 ev->event_window = (Ecore_Window)input->dev->window;
849 ev->root_window = (Ecore_Window)input->dev->window;
850 if (event) ev->timestamp = libinput_event_pointer_get_time(event);
853 _device_modifiers_update(edev);
854 ev->modifiers = edev->xkb.modifiers;
856 ev->x = edev->seat->ptr.ix;
857 ev->y = edev->seat->ptr.iy;
861 ev->multi.device = edev->mt_slot;
862 ev->multi.radius = 1;
863 ev->multi.radius_x = 1;
864 ev->multi.radius_y = 1;
865 ev->multi.pressure = 1.0;
866 ev->multi.angle = 0.0;
869 ev->multi.root.x = ev->x;
870 ev->multi.root.y = ev->y;
872 ev->dev = ecore_device_ref(ecore_dev);
874 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
877 ecore_thread_main_loop_end();
881 _e_input_pointer_motion_post(E_Input_Evdev *edev)
883 _device_pointer_motion(edev, NULL);
887 _device_pointer_relative_motion_send(double dx[2], double dy[2], uint64_t time_us)
889 e_input_relative_motion_cb func = e_input_relative_motion_handler_get();
890 if (func) func(dx, dy, time_us);
894 _device_handle_pointer_motion(struct libinput_device *device, struct libinput_event_pointer *event)
897 double delta_x[2]; /* delta_x[0] for accelerated, delta_x[1] for unaccelerated */
898 double delta_y[2]; /* delta_y[0] for accelerated, delta_y[1] for unaccelerated */
901 if (!(edev = libinput_device_get_user_data(device)))
906 delta_x[0] = libinput_event_pointer_get_dx(event);
907 delta_x[1] = libinput_event_pointer_get_dx_unaccelerated(event);
908 delta_y[0] = libinput_event_pointer_get_dy(event);
909 delta_y[1] = libinput_event_pointer_get_dy_unaccelerated(event);
911 if (edev->disable_acceleration)
922 if (edev->seat->ptr.swap)
928 if (edev->seat->ptr.invert_x)
930 if (edev->seat->ptr.invert_y)
933 edev->seat->ptr.dx += dx;
934 edev->seat->ptr.dy += dy;
936 edev->mouse.dx = edev->seat->ptr.dx;
937 edev->mouse.dy = edev->seat->ptr.dy;
939 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
940 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
945 edev->seat->ptr.ix = edev->seat->ptr.dx;
946 edev->seat->ptr.iy = edev->seat->ptr.dy;
948 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
949 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
954 _device_pointer_relative_motion_send(&delta_x[0], &delta_y[0],
955 libinput_event_pointer_get_time_usec(event));
956 _device_pointer_motion(edev, event);
960 _device_handle_pointer_motion_absolute(struct libinput_device *device, struct libinput_event_pointer *event)
965 if (!(edev = libinput_device_get_user_data(device)))
970 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
972 edev->mouse.dx = edev->seat->ptr.dx =
973 libinput_event_pointer_get_absolute_x_transformed(event, w);
974 edev->mouse.dy = edev->seat->ptr.dy =
975 libinput_event_pointer_get_absolute_y_transformed(event, h);
977 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
978 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
983 edev->seat->ptr.ix = edev->seat->ptr.dx;
984 edev->seat->ptr.iy = edev->seat->ptr.dy;
986 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
987 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
992 _device_pointer_motion(edev, event);
996 _device_handle_button(struct libinput_device *device, struct libinput_event_pointer *event)
999 E_Input_Backend *input;
1000 Ecore_Event_Mouse_Button *ev;
1001 enum libinput_button_state state;
1002 uint32_t button, timestamp;
1003 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1005 E_Comp_Config *comp_conf = NULL;
1007 if (!(edev = libinput_device_get_user_data(device)))
1011 if (!(input = edev->seat->input))
1016 ecore_thread_main_loop_begin();
1018 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1019 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1021 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1023 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1028 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1033 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1035 ecore_dev = detent_data;
1040 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1041 ecore_dev = edev->ecore_dev;
1046 ERR("Failed to get source ecore device from event !\n");
1050 state = libinput_event_pointer_get_button_state(event);
1051 button = libinput_event_pointer_get_button(event);
1052 timestamp = libinput_event_pointer_get_time(event);
1054 button = ((button & 0x00F) + 1);
1055 if (button == 3) button = 2;
1056 else if (button == 2) button = 3;
1060 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1061 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1063 ELOGF("Mouse", "Button Press (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
1064 button, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
1065 edev->seat->dev->server_blocked);
1070 edev->mouse.pressed_button |= (1 << button);
1075 if (!(edev->mouse.pressed_button & (1 << button)))
1077 ELOGF("Mouse", "Button Release (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
1078 button, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
1079 edev->seat->dev->server_blocked);
1082 edev->mouse.pressed_button &= ~(1 << button);
1085 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button))))
1090 ev->window = (Ecore_Window)input->dev->window;
1091 ev->event_window = (Ecore_Window)input->dev->window;
1092 ev->root_window = (Ecore_Window)input->dev->window;
1093 ev->timestamp = timestamp;
1094 ev->same_screen = 1;
1096 _device_modifiers_update(edev);
1097 ev->modifiers = edev->xkb.modifiers;
1099 ev->x = edev->seat->ptr.ix;
1100 ev->y = edev->seat->ptr.iy;
1104 ev->multi.device = edev->mt_slot;
1105 ev->multi.radius = 1;
1106 ev->multi.radius_x = 1;
1107 ev->multi.radius_y = 1;
1108 ev->multi.pressure = 1.0;
1109 ev->multi.angle = 0.0;
1110 ev->multi.x = ev->x;
1111 ev->multi.y = ev->y;
1112 ev->multi.root.x = ev->x;
1113 ev->multi.root.y = ev->y;
1114 ev->dev = ecore_device_ref(ecore_dev);
1118 unsigned int current;
1120 current = timestamp;
1121 edev->mouse.did_double = EINA_FALSE;
1122 edev->mouse.did_triple = EINA_FALSE;
1124 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1125 (button == edev->mouse.prev_button))
1127 edev->mouse.did_double = EINA_TRUE;
1128 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1129 (button == edev->mouse.last_button))
1131 edev->mouse.did_triple = EINA_TRUE;
1132 edev->mouse.prev = 0;
1133 edev->mouse.last = 0;
1138 edev->mouse.last = edev->mouse.prev;
1139 edev->mouse.prev = current;
1140 edev->mouse.last_button = edev->mouse.prev_button;
1141 edev->mouse.prev_button = button;
1144 ev->buttons = button;
1146 if (edev->mouse.did_double)
1147 ev->double_click = 1;
1148 if (edev->mouse.did_triple)
1149 ev->triple_click = 1;
1151 comp_conf = e_comp_config_get();
1152 if (comp_conf && comp_conf->input_log_enable)
1153 ELOGF("Mouse", "Button %s (btn: %d, device: %s)", NULL, state?"Press":"Release", button, ecore_device_name_get(ev->dev));
1156 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, _e_input_event_mouse_button_cb_free, NULL);
1158 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, _e_input_event_mouse_button_cb_free, NULL);
1161 ecore_thread_main_loop_end();
1164 #if !LIBINPUT_HAVE_SCROLL_VALUE_V120
1166 _axis_value_get(struct libinput_event_pointer *pointer_event, enum libinput_pointer_axis axis)
1168 enum libinput_pointer_axis_source source;
1169 double value = 0.0, value_discrete = 0.0;
1171 E_Comp_Config *comp_conf = NULL;
1173 comp_conf = e_comp_config_get();
1174 source = libinput_event_pointer_get_axis_source(pointer_event);
1177 case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL:
1178 value_discrete = libinput_event_pointer_get_axis_value_discrete(pointer_event, axis);
1179 value = libinput_event_pointer_get_axis_value(pointer_event, axis);
1180 if (comp_conf && comp_conf->input_log_enable)
1182 ELOGF("Axis", "SOURCE_WHEEL discrete: %lf (cf. value: %lf)", NULL, value_discrete, value);
1184 ret = (int)value_discrete;
1186 case LIBINPUT_POINTER_AXIS_SOURCE_FINGER:
1187 case LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS:
1188 value = libinput_event_pointer_get_axis_value(pointer_event, axis);
1189 if (comp_conf && comp_conf->input_log_enable)
1191 ELOGF("Axis", "SOURCE_FINGER/CONTINUOUS value: %lf", NULL, value);
1193 if (value >= E_INPUT_FINGER_SCROLL_THRESHOLD)
1195 else if (value <= E_INPUT_FINGER_SCROLL_THRESHOLD * (-1))
1208 _device_handle_axis(struct libinput_device *device, struct libinput_event_pointer *event)
1210 E_Input_Evdev *edev;
1211 E_Input_Backend *input;
1212 Ecore_Event_Mouse_Wheel *ev;
1214 enum libinput_pointer_axis axis;
1215 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1217 E_Comp_Config *comp_conf = NULL;
1218 int direction = 0, z = 0;
1220 if (!(edev = libinput_device_get_user_data(device)))
1224 if (!(input = edev->seat->input))
1229 ecore_thread_main_loop_begin();
1231 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1232 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1234 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1236 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1241 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1246 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1248 ecore_dev = detent_data;
1253 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1254 ecore_dev = edev->ecore_dev;
1259 ERR("Failed to get source ecore device from event !\n");
1263 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1264 if (libinput_event_pointer_has_axis(event, axis))
1265 z = _axis_value_get(event, axis);
1267 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1268 if (libinput_event_pointer_has_axis(event, axis))
1271 z = _axis_value_get(event, axis);
1276 ELOGF("Mouse", "Axis event is ignored since it has zero value", NULL);
1280 comp_conf = e_comp_config_get();
1281 if (comp_conf && comp_conf->e_wheel_click_angle)
1283 z = (int)(z * comp_conf->e_wheel_click_angle);
1286 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1287 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1290 ELOGF("Mouse", "Detent (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);
1293 ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1294 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1298 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1303 timestamp = libinput_event_pointer_get_time(event);
1305 ev->window = (Ecore_Window)input->dev->window;
1306 ev->event_window = (Ecore_Window)input->dev->window;
1307 ev->root_window = (Ecore_Window)input->dev->window;
1308 ev->timestamp = timestamp;
1309 ev->same_screen = 1;
1311 _device_modifiers_update(edev);
1312 ev->modifiers = edev->xkb.modifiers;
1314 ev->x = edev->seat->ptr.ix;
1315 ev->y = edev->seat->ptr.iy;
1319 ev->direction = direction;
1321 if (comp_conf && comp_conf->input_log_enable)
1324 ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1326 ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1330 ev->dev = ecore_device_ref(ecore_dev);
1331 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1334 ecore_thread_main_loop_end();
1338 #if LIBINPUT_HAVE_SCROLL_VALUE_V120
1340 _scroll_value_get(struct libinput_event_pointer *pointer_event, enum libinput_pointer_axis axis, E_Input_Axis_Source source)
1343 double value_v120 = 0.0;
1345 E_Comp_Config *comp_conf = NULL;
1347 comp_conf = e_comp_config_get();
1350 case E_INPUT_AXIS_SOURCE_WHEEL:
1351 value_v120 = libinput_event_pointer_get_scroll_value_v120(pointer_event, axis);
1352 value = libinput_event_pointer_get_scroll_value(pointer_event, axis);
1353 if (comp_conf && comp_conf->input_log_enable)
1355 ELOGF("Scroll", "SOURCE_WHEELL value_v120: %lf (cf. value: %lf)", NULL, value_v120, value);
1357 if (((int)value_v120 % E_INPUT_POINTER_AXIS_DISCRETE_STEP) != 0)
1359 ERR("Wheel movements should be multiples (or fractions) of 120!\n");
1364 ret = value_v120 / E_INPUT_POINTER_AXIS_DISCRETE_STEP;
1367 case E_INPUT_AXIS_SOURCE_FINGER:
1368 case E_INPUT_AXIS_SOURCE_CONTINUOUS:
1369 value = libinput_event_pointer_get_scroll_value(pointer_event, axis);
1370 if (comp_conf && comp_conf->input_log_enable)
1372 ELOGF("Scroll", "SOURCE_FINGER/CONTINUOUS value: %lf", NULL, value);
1374 if (value >= E_INPUT_FINGER_SCROLL_THRESHOLD)
1376 else if (value <= E_INPUT_FINGER_SCROLL_THRESHOLD * (-1))
1389 _device_handle_axis_v120(struct libinput_device *device, struct libinput_event_pointer *event, E_Input_Axis_Source source)
1391 E_Input_Evdev *edev;
1392 E_Input_Backend *input;
1393 Ecore_Event_Mouse_Wheel *ev;
1395 enum libinput_pointer_axis axis;
1396 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1398 E_Comp_Config *comp_conf = NULL;
1399 int direction = 0, z = 0;
1401 if (!(edev = libinput_device_get_user_data(device)))
1405 if (!(input = edev->seat->input))
1410 ecore_thread_main_loop_begin();
1412 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1413 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1415 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1417 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1422 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1427 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1429 ecore_dev = detent_data;
1434 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1435 ecore_dev = edev->ecore_dev;
1440 ERR("Failed to get source ecore device from event !\n");
1444 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1445 if (libinput_event_pointer_has_axis(event, axis))
1446 z = _scroll_value_get(event, axis, source);
1448 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1449 if (libinput_event_pointer_has_axis(event, axis))
1452 z = _scroll_value_get(event, axis, source);
1457 ELOGF("Mouse", "Scroll event is ignored since it has zero value", NULL);
1461 comp_conf = e_comp_config_get();
1462 if (comp_conf && comp_conf->e_wheel_click_angle)
1464 z = (int)(z * comp_conf->e_wheel_click_angle);
1467 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1468 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1471 ELOGF("Mouse", "Detent (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);
1474 ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1475 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1479 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1484 timestamp = libinput_event_pointer_get_time(event);
1486 ev->window = (Ecore_Window)input->dev->window;
1487 ev->event_window = (Ecore_Window)input->dev->window;
1488 ev->root_window = (Ecore_Window)input->dev->window;
1489 ev->timestamp = timestamp;
1490 ev->same_screen = 1;
1492 _device_modifiers_update(edev);
1493 ev->modifiers = edev->xkb.modifiers;
1495 ev->x = edev->seat->ptr.ix;
1496 ev->y = edev->seat->ptr.iy;
1500 ev->direction = direction;
1502 if (comp_conf && comp_conf->input_log_enable)
1505 ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1507 ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1510 ev->dev = ecore_device_ref(ecore_dev);
1511 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1514 ecore_thread_main_loop_end();
1519 _device_handle_touch_event_send(E_Input_Evdev *edev, struct libinput_event_touch *event, int state)
1521 E_Input_Backend *input;
1522 Ecore_Event_Mouse_Button *ev;
1523 uint32_t timestamp, button = 0;
1524 Ecore_Device *ecore_dev = NULL, *data;
1528 if (!(input = edev->seat->input)) return;
1530 ecore_thread_main_loop_begin();
1532 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1533 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1535 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1537 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1546 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1547 ecore_dev = edev->ecore_dev;
1552 ERR("Failed to get source ecore device from event !\n");
1556 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) goto end;
1558 timestamp = libinput_event_touch_get_time(event);
1560 ev->window = (Ecore_Window)input->dev->window;
1561 ev->event_window = (Ecore_Window)input->dev->window;
1562 ev->root_window = (Ecore_Window)input->dev->window;
1563 ev->timestamp = timestamp;
1564 ev->same_screen = 1;
1566 _device_modifiers_update(edev);
1567 ev->modifiers = edev->xkb.modifiers;
1569 ev->x = edev->seat->ptr.ix;
1570 ev->y = edev->seat->ptr.iy;
1574 ev->multi.device = edev->mt_slot;
1575 ev->multi.radius = 1;
1576 ev->multi.radius_x = 1;
1577 ev->multi.radius_y = 1;
1578 ev->multi.pressure = 1.0;
1579 ev->multi.angle = 0.0;
1580 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1581 if (libinput_event_get_type(libinput_event_touch_get_base_event(event))
1582 == LIBINPUT_EVENT_TOUCH_DOWN)
1584 if (libinput_event_touch_has_minor(event))
1585 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1586 if (libinput_event_touch_has_major(event))
1587 ev->multi.radius_y = libinput_event_touch_get_major(event);
1588 if (libinput_event_touch_has_pressure(event))
1589 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1590 if (libinput_event_touch_has_orientation(event))
1591 ev->multi.angle = libinput_event_touch_get_orientation(event);
1594 ev->multi.x = ev->x;
1595 ev->multi.y = ev->y;
1596 ev->multi.root.x = ev->x;
1597 ev->multi.root.y = ev->y;
1598 ev->dev = ecore_device_ref(ecore_dev);
1600 if (state == ECORE_EVENT_MOUSE_BUTTON_DOWN)
1602 unsigned int current;
1604 current = timestamp;
1605 edev->mouse.did_double = EINA_FALSE;
1606 edev->mouse.did_triple = EINA_FALSE;
1608 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1609 (button == edev->mouse.prev_button))
1611 edev->mouse.did_double = EINA_TRUE;
1612 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1613 (button == edev->mouse.last_button))
1615 edev->mouse.did_triple = EINA_TRUE;
1616 edev->mouse.prev = 0;
1617 edev->mouse.last = 0;
1622 edev->mouse.last = edev->mouse.prev;
1623 edev->mouse.prev = current;
1624 edev->mouse.last_button = edev->mouse.prev_button;
1625 edev->mouse.prev_button = button;
1626 edev->touch.pressed |= (1 << ev->multi.device);
1630 edev->touch.pressed &= ~(1 << ev->multi.device);
1633 ev->buttons = ((button & 0x00F) + 1);
1635 if (edev->mouse.did_double)
1636 ev->double_click = 1;
1637 if (edev->mouse.did_triple)
1638 ev->triple_click = 1;
1640 ecore_event_add(state, ev, _e_input_event_mouse_button_cb_free, NULL);
1643 ecore_thread_main_loop_end();
1647 _device_handle_touch_motion_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1649 E_Input_Backend *input;
1650 Ecore_Event_Mouse_Move *ev;
1651 Ecore_Device *ecore_dev = NULL, *data;
1655 if (!(input = edev->seat->input)) return;
1657 ecore_thread_main_loop_begin();
1659 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1660 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1662 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1664 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1673 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1674 ecore_dev = edev->ecore_dev;
1679 ERR("Failed to get source ecore device from event !\n");
1683 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) goto end;
1685 ev->window = (Ecore_Window)input->dev->window;
1686 ev->event_window = (Ecore_Window)input->dev->window;
1687 ev->root_window = (Ecore_Window)input->dev->window;
1688 ev->timestamp = libinput_event_touch_get_time(event);
1689 ev->same_screen = 1;
1691 _device_modifiers_update(edev);
1692 ev->modifiers = edev->xkb.modifiers;
1694 ev->x = edev->seat->ptr.ix;
1695 ev->y = edev->seat->ptr.iy;
1699 ev->multi.device = edev->mt_slot;
1700 ev->multi.radius = 1;
1701 ev->multi.radius_x = 1;
1702 ev->multi.radius_y = 1;
1703 ev->multi.pressure = 1.0;
1704 ev->multi.angle = 0.0;
1705 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1706 if (libinput_event_touch_has_minor(event))
1707 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1708 if (libinput_event_touch_has_major(event))
1709 ev->multi.radius_y = libinput_event_touch_get_major(event);
1710 if (libinput_event_touch_has_pressure(event))
1711 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1712 if (libinput_event_touch_has_orientation(event))
1713 ev->multi.angle = libinput_event_touch_get_orientation(event);
1715 ev->multi.x = ev->x;
1716 ev->multi.y = ev->y;
1717 ev->multi.root.x = ev->x;
1718 ev->multi.root.y = ev->y;
1719 ev->dev = ecore_device_ref(ecore_dev);
1721 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
1724 ecore_thread_main_loop_end();
1728 _device_handle_touch_cancel_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1730 E_Input_Backend *input;
1731 Ecore_Event_Mouse_Button *ev;
1732 uint32_t timestamp, button = 0;
1733 Ecore_Device *ecore_dev = NULL, *data;
1737 if (!(input = edev->seat->input)) return;
1739 ecore_thread_main_loop_begin();
1741 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1742 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1744 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1746 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1755 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1756 ecore_dev = edev->ecore_dev;
1761 ERR("Failed to get source ecore device from event !\n");
1765 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) goto end;
1767 timestamp = libinput_event_touch_get_time(event);
1769 ev->window = (Ecore_Window)input->dev->window;
1770 ev->event_window = (Ecore_Window)input->dev->window;
1771 ev->root_window = (Ecore_Window)input->dev->window;
1772 ev->timestamp = timestamp;
1773 ev->same_screen = 1;
1775 ev->x = edev->seat->ptr.ix;
1776 ev->y = edev->seat->ptr.iy;
1780 ev->multi.device = edev->mt_slot;
1781 ev->multi.radius = 1;
1782 ev->multi.radius_x = 1;
1783 ev->multi.radius_y = 1;
1784 ev->multi.pressure = 1.0;
1785 ev->multi.angle = 0.0;
1786 ev->multi.x = ev->x;
1787 ev->multi.y = ev->y;
1788 ev->multi.root.x = ev->x;
1789 ev->multi.root.y = ev->y;
1791 edev->touch.pressed &= ~(1 << ev->multi.device);
1793 ev->buttons = ((button & 0x00F) + 1);
1794 ev->dev = ecore_device_ref(ecore_dev);
1796 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev, _e_input_event_mouse_button_cb_free, NULL);
1799 ecore_thread_main_loop_end();
1803 _device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, int *w, int *h)
1805 E_Output *output = NULL;
1807 EINA_SAFETY_ON_NULL_RETURN(edev);
1809 if (!edev->output_configured)
1811 if (edev->output_name)
1813 output = e_output_find(edev->output_name);
1816 edev->mouse.minx = output->config.geom.x;
1817 edev->mouse.miny = output->config.geom.y;
1818 edev->mouse.maxw = output->config.geom.w;
1819 edev->mouse.maxh = output->config.geom.h;
1820 if (libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
1822 edev->seat->ptr.dx = (double)(edev->mouse.maxw / 2);
1823 edev->seat->ptr.dy = (double)(edev->mouse.maxh / 2);
1824 edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
1825 edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
1826 edev->mouse.dx = edev->seat->ptr.dx;
1827 edev->mouse.dy = edev->seat->ptr.dy;
1832 edev->output_configured = EINA_TRUE;
1833 ELOGF("E_INPUT_EVDEV", "Device is configured by output x:%d,y:%d (w:%d, h:%d)",
1834 NULL, edev->mouse.minx, edev->mouse.miny, edev->mouse.maxw, edev->mouse.maxh);
1836 if (x) *x = edev->mouse.minx;
1837 if (y) *y = edev->mouse.miny;
1838 if (w) *w = edev->mouse.maxw;
1839 if (h) *h = edev->mouse.maxh;
1843 _device_handle_touch_down(struct libinput_device *device, struct libinput_event_touch *event)
1845 E_Input_Evdev *edev;
1846 int x = 0, y = 0, w = 0, h = 0;
1847 E_Comp_Config *comp_conf = NULL;
1849 if (!(edev = libinput_device_get_user_data(device)))
1854 _device_configured_size_get(edev, &x, &y, &w, &h);
1856 edev->mouse.dx = edev->seat->ptr.ix = edev->seat->ptr.dx =
1857 x + libinput_event_touch_get_x_transformed(event, w);
1858 edev->mouse.dy = edev->seat->ptr.iy = edev->seat->ptr.dy =
1859 y + libinput_event_touch_get_y_transformed(event, h);
1861 edev->mt_slot = libinput_event_touch_get_slot(event);
1862 if (edev->mt_slot < 0)
1864 /* FIXME: The single touch device return slot id -1
1865 * But currently we have no API to distinguish multi touch or single touch
1866 * After libinput 1.11 version, libinput provides get_touch_count API,
1867 * so we can distinguish multi touch device or single touch device.
1869 if (edev->mt_slot == -1)
1873 WRN("%d slot touch down events are not supported\n", edev->mt_slot);
1878 if (edev->mt_slot < e_input_touch_max_count_get())
1880 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
1881 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
1884 comp_conf = e_comp_config_get();
1885 if (comp_conf && comp_conf->input_log_enable)
1886 ELOGF("Touch", "Down (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
1888 edev->touch.raw_pressed |= (1 << edev->mt_slot);
1890 if (edev->touch.blocked)
1892 ELOGF("Touch", "Down (id: %d, x: %d, y: %d) is blocked by %p, server: 0x%x", NULL,
1893 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, edev->seat->dev->blocked_client,
1894 edev->seat->dev->server_blocked);
1898 _device_handle_touch_motion_send(edev, event);
1899 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_DOWN);
1903 _device_handle_touch_motion(struct libinput_device *device, struct libinput_event_touch *event)
1905 E_Input_Evdev *edev;
1906 int x = 0, y = 0, w = 0, h = 0;
1908 if (!(edev = libinput_device_get_user_data(device)))
1913 _device_configured_size_get(edev, &x, &y, &w, &h);
1915 edev->mouse.dx = edev->seat->ptr.dx =
1916 x + libinput_event_touch_get_x_transformed(event, w);
1917 edev->mouse.dy = edev->seat->ptr.dy =
1918 y + libinput_event_touch_get_y_transformed(event, h);
1920 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
1921 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
1926 edev->seat->ptr.ix = edev->seat->ptr.dx;
1927 edev->seat->ptr.iy = edev->seat->ptr.dy;
1929 edev->mt_slot = libinput_event_touch_get_slot(event);
1930 if (edev->mt_slot < 0)
1932 /* FIXME: The single touch device return slot id -1
1933 * But currently we have no API to distinguish multi touch or single touch
1934 * After libinput 1.11 version, libinput provides get_touch_count API,
1935 * so we can distinguish multi touch device or single touch device.
1937 if (edev->mt_slot == -1)
1941 WRN("%d slot touch motion events are not supported\n", edev->mt_slot);
1946 if (edev->mt_slot < e_input_touch_max_count_get())
1948 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
1949 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
1952 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
1954 if (edev->touch.blocked)
1960 _device_handle_touch_motion_send(edev, event);
1964 _device_handle_touch_up(struct libinput_device *device, struct libinput_event_touch *event)
1966 E_Input_Evdev *edev;
1967 E_Comp_Config *comp_conf = NULL;
1969 if (!(edev = libinput_device_get_user_data(device)))
1974 edev->mt_slot = libinput_event_touch_get_slot(event);
1975 if (edev->mt_slot < 0)
1977 /* FIXME: The single touch device return slot id -1
1978 * But currently we have no API to distinguish multi touch or single touch
1979 * After libinput 1.11 version, libinput provides get_touch_count API,
1980 * so we can distinguish multi touch device or single touch device.
1982 if (edev->mt_slot == -1)
1986 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
1991 if (edev->mt_slot < e_input_touch_max_count_get())
1993 edev->mouse.dx = edev->seat->ptr.dx = edev->seat->ptr.ix =
1994 edev->touch.coords[edev->mt_slot].x;
1995 edev->mouse.dy = edev->seat->ptr.dy = edev->seat->ptr.iy =
1996 edev->touch.coords[edev->mt_slot].y;
1999 comp_conf = e_comp_config_get();
2000 if (comp_conf && comp_conf->input_log_enable)
2001 ELOGF("Touch", "Up (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2003 edev->touch.raw_pressed &= ~(1 << edev->mt_slot);
2005 if (edev->touch.blocked)
2007 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
2009 ELOGF("Touch", "Up (id: %d, x: %d, y: %d) is blocked by %p, server(0x%x)", NULL,
2010 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, edev->seat->dev->blocked_client,
2011 edev->seat->dev->server_blocked);
2012 if (edev->touch.raw_pressed == 0x0)
2014 edev->touch.blocked = EINA_FALSE;
2020 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_UP);
2024 _device_handle_touch_cancel(struct libinput_device *device, struct libinput_event_touch *event)
2026 E_Input_Evdev *edev;
2027 E_Comp_Config *comp_conf = NULL;
2029 if (!(edev = libinput_device_get_user_data(device)))
2034 edev->mt_slot = libinput_event_touch_get_slot(event);
2035 if (edev->mt_slot < 0)
2037 /* FIXME: The single touch device return slot id -1
2038 * But currently we have no API to distinguish multi touch or single touch
2039 * After libinput 1.11 version, libinput provides get_touch_count API,
2040 * so we can distinguish multi touch device or single touch device.
2042 if (edev->mt_slot == -1)
2046 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
2051 comp_conf = e_comp_config_get();
2052 if (comp_conf && comp_conf->input_log_enable)
2053 ELOGF("Touch", "cancel (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2055 _device_handle_touch_cancel_send(edev, event);
2060 _device_handle_touch_frame(struct libinput_device *device EINA_UNUSED, struct libinput_event_touch *event EINA_UNUSED)
2062 /* DBG("Unhandled Touch Frame Event"); */
2066 _e_input_aux_data_event_free(void *user_data EINA_UNUSED, void *ev)
2068 Ecore_Event_Axis_Update *e = (Ecore_Event_Axis_Update *)ev;
2070 if (e->axis) free(e->axis);
2071 if (e->dev) ecore_device_unref(e->dev);
2077 _device_handle_touch_aux_data(struct libinput_device *device, struct libinput_event_touch_aux_data *event)
2079 E_Input_Evdev *edev;
2080 E_Input_Backend *input;
2081 Ecore_Event_Axis_Update *ev;
2083 Ecore_Device *ecore_dev = NULL, *data;
2085 E_Comp_Config *comp_conf;
2087 ecore_thread_main_loop_begin();
2089 if (libinput_event_touch_aux_data_get_type(event) != LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM &&
2090 libinput_event_touch_aux_data_get_value(event) > 0)
2093 if (!(edev = libinput_device_get_user_data(device))) goto end;
2094 if (!(input = edev->seat->input)) goto end;
2096 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
2097 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
2099 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
2101 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
2110 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
2111 ecore_dev = edev->ecore_dev;
2116 ERR("Failed to get source ecore device from event !\n");
2120 if (!(ev = calloc(1, sizeof(Ecore_Event_Axis_Update)))) goto end;
2122 ev->window = (Ecore_Window)input->dev->window;
2123 ev->event_window = (Ecore_Window)input->dev->window;
2124 ev->root_window = (Ecore_Window)input->dev->window;
2125 ev->timestamp = libinput_event_touch_aux_data_get_time(event);
2127 axis = (Ecore_Axis *)calloc(1, sizeof(Ecore_Axis));
2130 axis->label = ECORE_AXIS_LABEL_TOUCH_PALM;
2131 axis->value = libinput_event_touch_aux_data_get_value(event);
2136 comp_conf = e_comp_config_get();
2137 if (comp_conf && comp_conf->input_log_enable)
2138 ELOGF("Touch", "Axis (label: %d, value: %lf)", NULL, axis?axis->label:-1, axis?axis->value:0.0);
2140 ev->dev = ecore_device_ref(ecore_dev);
2142 ecore_event_add(ECORE_EVENT_AXIS_UPDATE, ev, _e_input_aux_data_event_free, NULL);
2145 ecore_thread_main_loop_end();
2149 _e_input_evdev_device_create(E_Input_Seat *seat, struct libinput_device *device)
2151 E_Input_Evdev *edev;
2152 E_Input_Backend *b_input;
2153 const char *output_name;
2155 EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
2157 /* try to allocate space for new evdev */
2158 if (!(edev = calloc(1, sizeof(E_Input_Evdev)))) return NULL;
2161 edev->device = device;
2162 edev->path = eina_stringshare_printf("%s/%s", e_input_base_dir_get(), libinput_device_get_sysname(device));
2164 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
2166 edev->caps |= E_INPUT_SEAT_KEYBOARD;
2167 _device_keyboard_setup(edev);
2170 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
2172 edev->caps |= E_INPUT_SEAT_POINTER;
2174 /* TODO: make this configurable */
2175 edev->mouse.threshold = 250;
2177 b_input = seat->input;
2178 if (b_input->left_handed == EINA_TRUE)
2180 if (libinput_device_config_left_handed_set(device, 1) !=
2181 LIBINPUT_CONFIG_STATUS_SUCCESS)
2183 WRN("Failed to set left hand mode about device: %s\n",
2184 libinput_device_get_name(device));
2189 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
2192 edev->caps |= E_INPUT_SEAT_TOUCH;
2193 palm_code = libinput_device_touch_aux_data_get_code(LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM);
2194 if (libinput_device_touch_has_aux_data(device, palm_code))
2196 libinput_device_touch_set_aux_data(device, palm_code);
2199 _device_touch_count_update(edev);
2201 edev->touch.coords = calloc(1, sizeof(E_Input_Coord)*e_input_touch_max_count_get());
2203 if (!edev->touch.coords)
2204 ERR("Failed to allocate memory for touch coords !\n");
2207 output_name = libinput_device_get_output_name(device);
2210 eina_stringshare_replace(&edev->output_name, output_name);
2211 ELOGF("E_INPUT_EVDEV", "Device has output_name:%s", NULL, output_name);
2214 libinput_device_set_user_data(device, edev);
2215 libinput_device_ref(device);
2217 /* configure device */
2218 _device_configure(edev);
2224 _e_input_evdev_device_destroy(E_Input_Evdev *edev)
2228 EINA_SAFETY_ON_NULL_RETURN(edev);
2230 ecore_thread_main_loop_begin();
2232 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
2234 g_mutex_lock(&edev->xkb.state_mutex);
2235 if (edev->xkb.state) xkb_state_unref(edev->xkb.state);
2236 g_mutex_unlock(&edev->xkb.state_mutex);
2238 g_mutex_lock(&edev->xkb.keymap_mutex);
2239 if (edev->xkb.keymap) xkb_map_unref(edev->xkb.keymap);
2240 g_mutex_unlock(&edev->xkb.keymap_mutex);
2243 if (edev->ecore_dev) ecore_device_del(edev->ecore_dev);
2244 if (edev->ecore_dev_list)
2245 EINA_LIST_FREE(edev->ecore_dev_list, dev)
2247 ecore_device_del(dev);
2249 if (edev->path) eina_stringshare_del(edev->path);
2250 if (edev->device) libinput_device_unref(edev->device);
2251 if (edev->key_remap_hash) eina_hash_free(edev->key_remap_hash);
2252 if (edev->touch.coords)
2254 free(edev->touch.coords);
2255 edev->touch.coords = NULL;
2257 eina_stringshare_del(edev->output_name);
2259 ecore_thread_main_loop_end();
2265 _e_input_evdev_event_process(struct libinput_event *event)
2267 struct libinput_device *device;
2268 Eina_Bool ret = EINA_TRUE;
2270 device = libinput_event_get_device(event);
2271 switch (libinput_event_get_type(event))
2273 case LIBINPUT_EVENT_KEYBOARD_KEY:
2274 _device_handle_key(device, libinput_event_get_keyboard_event(event));
2276 case LIBINPUT_EVENT_POINTER_MOTION:
2277 _device_handle_pointer_motion(device,
2278 libinput_event_get_pointer_event(event));
2280 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
2281 _device_handle_pointer_motion_absolute(device,
2282 libinput_event_get_pointer_event(event));
2284 case LIBINPUT_EVENT_POINTER_BUTTON:
2285 _device_handle_button(device, libinput_event_get_pointer_event(event));
2287 case LIBINPUT_EVENT_POINTER_AXIS:
2288 #if !LIBINPUT_HAVE_SCROLL_VALUE_V120
2289 _device_handle_axis(device, libinput_event_get_pointer_event(event));
2292 #if LIBINPUT_HAVE_SCROLL_VALUE_V120
2293 case LIBINPUT_EVENT_POINTER_SCROLL_WHEEL:
2294 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_WHEEL);
2296 case LIBINPUT_EVENT_POINTER_SCROLL_FINGER:
2297 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_FINGER);
2299 case LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS:
2300 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_CONTINUOUS);
2303 case LIBINPUT_EVENT_TOUCH_DOWN:
2304 _device_handle_touch_down(device, libinput_event_get_touch_event(event));
2306 case LIBINPUT_EVENT_TOUCH_MOTION:
2307 _device_handle_touch_motion(device,
2308 libinput_event_get_touch_event(event));
2310 case LIBINPUT_EVENT_TOUCH_UP:
2311 _device_handle_touch_up(device, libinput_event_get_touch_event(event));
2313 case LIBINPUT_EVENT_TOUCH_CANCEL:
2314 _device_handle_touch_cancel(device, libinput_event_get_touch_event(event));
2316 case LIBINPUT_EVENT_TOUCH_FRAME:
2317 _device_handle_touch_frame(device, libinput_event_get_touch_event(event));
2319 case LIBINPUT_EVENT_TOUCH_AUX_DATA:
2320 _device_handle_touch_aux_data(device, libinput_event_get_touch_aux_data(event));
2331 * @brief Set the axis size of the given device.
2333 * @param dev The device to set the axis size to.
2334 * @param w The width of the axis.
2335 * @param h The height of the axis.
2337 * This function sets set the width @p w and height @p h of the axis
2338 * of device @p dev. If @p dev is a relative input device, a width and
2339 * height must set for it. If its absolute set the ioctl correctly, if
2340 * not, unsupported device.
2343 e_input_evdev_axis_size_set(E_Input_Evdev *edev, int w, int h)
2345 const char *sysname;
2350 enum libinput_config_status status;
2352 EINA_SAFETY_ON_NULL_RETURN(edev);
2353 EINA_SAFETY_ON_TRUE_RETURN((w == 0) || (h == 0));
2355 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
2356 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
2359 sysname = libinput_device_get_sysname(edev->device);
2361 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
2362 if (eina_list_count(devices) < 1) return;
2364 EINA_LIST_FREE(devices, device)
2366 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
2368 (sscanf(vals, "%f %f %f %f %f %f",
2369 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
2376 libinput_device_config_calibration_set_matrix(edev->device, cal);
2378 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
2379 ERR("Failed to apply calibration");
2382 eina_stringshare_del(device);
2387 EINTERN const char *
2388 e_input_evdev_name_get(E_Input_Evdev *evdev)
2390 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2391 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2393 return libinput_device_get_name(evdev->device);
2396 EINTERN const char *
2397 e_input_evdev_sysname_get(E_Input_Evdev *evdev)
2399 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2400 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2402 return libinput_device_get_sysname(evdev->device);
2406 e_input_evdev_key_remap_enable(E_Input_Evdev *edev, Eina_Bool enable)
2408 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2409 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2411 edev->key_remap_enabled = enable;
2413 if (enable == EINA_FALSE && edev->key_remap_hash)
2415 eina_hash_free(edev->key_remap_hash);
2416 edev->key_remap_hash = NULL;
2423 e_input_evdev_key_remap_set(E_Input_Evdev *edev, int *from_keys, int *to_keys, int num)
2427 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2428 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2429 EINA_SAFETY_ON_NULL_RETURN_VAL(from_keys, EINA_FALSE);
2430 EINA_SAFETY_ON_NULL_RETURN_VAL(to_keys, EINA_FALSE);
2431 EINA_SAFETY_ON_TRUE_RETURN_VAL(num <= 0, EINA_FALSE);
2432 EINA_SAFETY_ON_TRUE_RETURN_VAL(!edev->key_remap_enabled, EINA_FALSE);
2434 if (edev->key_remap_hash == NULL)
2435 edev->key_remap_hash = eina_hash_int32_new(NULL);
2437 if (edev->key_remap_hash == NULL)
2439 ERR("Failed to set remap key information : creating a hash is failed.");
2443 for (i = 0; i < num ; i++)
2445 if (!from_keys[i] || !to_keys[i])
2447 ERR("Failed to set remap key information : given arguments are invalid.");
2452 for (i = 0; i < num ; i++)
2454 eina_hash_add(edev->key_remap_hash, &from_keys[i], (void *)(intptr_t)to_keys[i]);
2461 e_input_evdev_wheel_click_angle_get(E_Input_Evdev *dev)
2463 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, -1);
2464 return libinput_device_config_scroll_get_wheel_click_angle(dev->device);
2468 e_input_evdev_touch_calibration_set(E_Input_Evdev *edev, float matrix[6])
2470 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2471 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2473 if (!libinput_device_config_calibration_has_matrix(edev->device) ||
2474 !libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_TOUCH))
2477 if (libinput_device_config_calibration_set_matrix(edev->device, matrix) !=
2478 LIBINPUT_CONFIG_STATUS_SUCCESS)
2480 WRN("Failed to set input transformation about device: %s\n",
2481 libinput_device_get_name(edev->device));
2489 e_input_evdev_mouse_accel_speed_set(E_Input_Evdev *edev, double speed)
2491 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2492 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2494 if (!libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
2497 if (!libinput_device_config_accel_is_available(edev->device))
2500 if (libinput_device_config_accel_set_speed(edev->device, speed) !=
2501 LIBINPUT_CONFIG_STATUS_SUCCESS)
2503 WRN("Failed to set mouse accel about device: %s\n",
2504 libinput_device_get_name(edev->device));
2511 EINTERN unsigned int
2512 e_input_evdev_touch_pressed_get(E_Input_Evdev *edev)
2514 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, 0x0);
2516 return edev->touch.pressed;
2520 e_input_evdev_seatname_get(E_Input_Evdev *evdev)
2522 struct libinput_seat *libinput_seat;
2523 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2524 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2526 libinput_seat = libinput_device_get_seat(evdev->device);
2528 return libinput_seat_get_logical_name(libinput_seat);
2532 e_input_evdev_seatname_set(E_Input_Evdev *evdev, const char *seatname)
2534 Eina_Bool res = EINA_FALSE;
2535 E_Input_Backend *input;
2537 EINA_SAFETY_ON_NULL_RETURN_VAL(seatname, EINA_FALSE);
2538 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, EINA_FALSE);
2539 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, EINA_FALSE);
2541 if (libinput_device_set_seat_logical_name(evdev->device, seatname) == 0)
2543 input = evdev->seat->input;
2544 if (!input) return EINA_FALSE;
2545 if (libinput_dispatch(input->libinput) != 0)
2547 ERR("Failed to dispatch libinput events: %m");
2551 /* process pending events */
2552 _input_events_process(input);
2560 e_input_evdev_mouse_accel_enable(E_Input_Evdev *edev, Eina_Bool enable)
2562 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2563 edev->disable_acceleration = !enable;