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 (!e_input_thread_mode_get())
548 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
549 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
551 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
553 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_KEYBOARD)
562 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
563 ecore_dev = edev->ecore_dev;
568 ERR("Failed to get source ecore device from event !\n");
572 device_name = ecore_device_name_get(ecore_dev);
576 if (edev->e_dev) e_dev = edev->e_dev;
577 else if (edev->e_dev_list && g_list_length(edev->e_dev_list) > 0)
579 glist = edev->e_dev_list;
582 e_dev_data = glist->data;
583 if (e_device_class_get(e_dev_data) == ECORE_DEVICE_CLASS_KEYBOARD)
589 glist = g_list_next(glist);
594 edev->e_dev = e_input_evdev_get_e_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
600 ERR("Failed to get source e device from event !\n");
604 device_name = e_device_name_get(e_dev);
607 timestamp = libinput_event_keyboard_get_time(event);
608 code = libinput_event_keyboard_get_key(event);
609 code = _device_remapped_key_get(edev, code + 8);
610 state = libinput_event_keyboard_get_key_state(event);
611 key_count = libinput_event_keyboard_get_seat_key_count(event);
613 if (state == LIBINPUT_KEY_STATE_PRESSED)
615 if ((edev->seat->dev->blocked & E_INPUT_SEAT_KEYBOARD) ||
616 (edev->seat->dev->server_blocked & E_INPUT_SEAT_KEYBOARD))
618 ELOGF("Key", "Press (keycode: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
619 code, device_name, edev->seat->dev->blocked_client,
620 edev->seat->dev->server_blocked);
624 /* FIXME: Currently to maintain press/release event pair during input block,
625 * used Eina_List and this is method used in devicemgr module.
626 * But we need to consider which way is better to maintain key press/release pair.
629 EINA_LIST_FOREACH(edev->xkb.pressed_keys, l, idata)
633 dup_found = EINA_TRUE;
639 pressed_keycode = E_NEW(int, 1);
640 EINA_SAFETY_ON_NULL_RETURN(pressed_keycode);
641 *pressed_keycode = code;
643 edev->xkb.pressed_keys = eina_list_append(edev->xkb.pressed_keys, pressed_keycode);
648 dup_found = EINA_FALSE;
649 EINA_LIST_FOREACH_SAFE(edev->xkb.pressed_keys, l, l_next, idata)
653 edev->xkb.pressed_keys = eina_list_remove_list(edev->xkb.pressed_keys, l);
655 dup_found = EINA_TRUE;
661 ELOGF("Key", "Release (keycode: %d, device: %s) is blocked by %p", NULL,
662 code, device_name, edev->seat->dev->blocked_client);
667 /* ignore key events that are not seat wide state changes */
668 if (((state == LIBINPUT_KEY_STATE_PRESSED) && (key_count != 1)) ||
669 ((state == LIBINPUT_KEY_STATE_RELEASED) && (key_count != 0)))
674 g_mutex_lock(&edev->xkb.state_mutex);
675 xkb_state_update_key(edev->xkb.state, code,
676 (state ? XKB_KEY_DOWN : XKB_KEY_UP));
678 /* get the keysym for this code */
679 nsyms = xkb_key_get_syms(edev->xkb.state, code, &syms);
680 g_mutex_unlock(&edev->xkb.state_mutex);
682 if (nsyms == 1) sym = syms[0];
684 /* If no keysym was found, name it "Keycode-NNN" */
685 if (sym == XKB_KEY_NoSymbol)
686 snprintf(key, sizeof(key), "Keycode-%u", code);
689 /* get the keyname for this sym */
690 xkb_keysym_get_name(sym, key, sizeof(key));
695 /* If no keyname was found, name it "Keycode-NNN" */
696 snprintf(keyname, sizeof(keyname), "Keycode-%u", code);
700 memcpy(keyname, key, sizeof(keyname));
703 /* if shift is active, we need to transform the key to lower */
704 g_mutex_lock(&edev->xkb.keymap_mutex);
705 g_mutex_lock(&edev->xkb.state_mutex);
706 if (xkb_state_mod_index_is_active(edev->xkb.state,
707 xkb_map_mod_get_index(edev->xkb.keymap,
709 XKB_STATE_MODS_EFFECTIVE))
711 if (keyname[0] != '\0')
712 keyname[0] = tolower(keyname[0]);
714 g_mutex_unlock(&edev->xkb.keymap_mutex);
715 g_mutex_unlock(&edev->xkb.state_mutex);
717 if (_device_keysym_translate(sym, edev->xkb.modifiers,
718 compose_buffer, sizeof(compose_buffer)))
720 compose = eina_str_convert("ISO8859-1", "UTF-8", compose_buffer);
723 ERR("E Input cannot convert input key string '%s' to UTF-8. "
724 "Is Eina built with iconv support?", compose_buffer);
730 if (!compose) compose = compose_buffer;
732 e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) +
733 ((compose[0] != '\0') ? strlen(compose) : 0) + 3);
739 key_data = E_NEW(E_Keyrouter_Event_Data, 1);
747 e->keyname = (char *)(e + 1);
748 e->key = e->keyname + strlen(keyname) + 1;
749 e->compose = strlen(compose) ? e->key + strlen(key) + 1 : NULL;
750 e->string = e->compose;
752 strncpy((char *)e->keyname, keyname, strlen(keyname));
753 strncpy((char *)e->key, key, strlen(key));
754 if (strlen(compose)) strncpy((char *)e->compose, compose, strlen(compose));
756 e->window = (Ecore_Window)input->dev->window;
757 e->event_window = (Ecore_Window)input->dev->window;
758 e->root_window = (Ecore_Window)input->dev->window;
759 e->timestamp = timestamp;
764 _device_modifiers_update(edev);
766 e->modifiers = edev->xkb.modifiers;
768 comp_conf = e_comp_config_get();
770 if (comp_conf && comp_conf->input_log_enable)
771 ELOGF("Key", "%s (keyname: %s, keycode: %d, timestamp: %u, device: %s)", NULL, state?"Press":"Release", e->keyname, e->keycode, e->timestamp, device_name);
773 if (e_input_thread_mode_get())
775 e->dev = (Eo *)g_object_ref(e_dev);
776 e_input_event_add(input->event_source, state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
780 e->dev = ecore_device_ref(ecore_dev);
781 ecore_event_add(state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
788 _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event)
790 E_Input_Backend *input;
791 Ecore_Event_Mouse_Move *ev;
792 Ecore_Device *ecore_dev = NULL, *data, *detent_data = NULL;
794 int x = 0, y = 0, w = 0, h = 0;
796 if (!(input = edev->seat->input)) return;
798 ecore_thread_main_loop_begin();
800 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
801 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
803 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
805 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
810 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
815 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
817 ecore_dev = detent_data;
822 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
823 ecore_dev = edev->ecore_dev;
828 ERR("Failed to get source ecore device from event !\n");
831 else if ((detent_data == ecore_dev) || e_devicemgr_detent_is_detent(ecore_device_name_get(ecore_dev)))
833 /* Do not process detent device's move events. */
837 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
839 _device_configured_size_get(edev, &x, &y, &w, &h);
841 if (edev->seat->ptr.ix < x)
842 edev->seat->ptr.dx = edev->seat->ptr.ix = x;
843 else if (edev->seat->ptr.ix >= (x + w))
844 edev->seat->ptr.dx = edev->seat->ptr.ix = (x + w - 1);
846 if (edev->seat->ptr.iy < y)
847 edev->seat->ptr.dy = edev->seat->ptr.iy = y;
848 else if (edev->seat->ptr.iy >= (y + h))
849 edev->seat->ptr.dy = edev->seat->ptr.iy = (y + h - 1);
851 edev->mouse.dx = edev->seat->ptr.dx;
852 edev->mouse.dy = edev->seat->ptr.dy;
854 ev->window = (Ecore_Window)input->dev->window;
855 ev->event_window = (Ecore_Window)input->dev->window;
856 ev->root_window = (Ecore_Window)input->dev->window;
857 if (event) ev->timestamp = libinput_event_pointer_get_time(event);
860 _device_modifiers_update(edev);
861 ev->modifiers = edev->xkb.modifiers;
863 ev->x = edev->seat->ptr.ix;
864 ev->y = edev->seat->ptr.iy;
868 ev->multi.device = edev->mt_slot;
869 ev->multi.radius = 1;
870 ev->multi.radius_x = 1;
871 ev->multi.radius_y = 1;
872 ev->multi.pressure = 1.0;
873 ev->multi.angle = 0.0;
876 ev->multi.root.x = ev->x;
877 ev->multi.root.y = ev->y;
879 ev->dev = ecore_device_ref(ecore_dev);
881 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
884 ecore_thread_main_loop_end();
888 _e_input_pointer_motion_post(E_Input_Evdev *edev)
890 _device_pointer_motion(edev, NULL);
894 _device_pointer_motion_send(E_Input_Evdev *edev, struct libinput_event_pointer *event, double dx[2], double dy[2])
897 e_input_relative_motion_cb func = e_input_relative_motion_handler_get();
900 time_us = libinput_event_pointer_get_time_usec(event);
901 func(dx, dy, time_us);
905 _device_pointer_motion(edev, event);
910 _device_handle_pointer_motion(struct libinput_device *device, struct libinput_event_pointer *event)
913 double delta_x[2]; /* delta_x[0] for accelerated, delta_x[1] for unaccelerated */
914 double delta_y[2]; /* delta_y[0] for accelerated, delta_y[1] for unaccelerated */
917 if (!(edev = libinput_device_get_user_data(device)))
922 delta_x[0] = libinput_event_pointer_get_dx(event);
923 delta_x[1] = libinput_event_pointer_get_dx_unaccelerated(event);
924 delta_y[0] = libinput_event_pointer_get_dy(event);
925 delta_y[1] = libinput_event_pointer_get_dy_unaccelerated(event);
927 if (edev->disable_acceleration)
938 if (edev->seat->ptr.swap)
944 if (edev->seat->ptr.invert_x)
946 if (edev->seat->ptr.invert_y)
949 edev->seat->ptr.dx += dx;
950 edev->seat->ptr.dy += dy;
952 edev->mouse.dx = edev->seat->ptr.dx;
953 edev->mouse.dy = edev->seat->ptr.dy;
955 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
956 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
961 edev->seat->ptr.ix = edev->seat->ptr.dx;
962 edev->seat->ptr.iy = edev->seat->ptr.dy;
964 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
965 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
970 _device_pointer_motion_send(edev, event, &delta_x[0], &delta_y[0]);
974 _device_handle_pointer_motion_absolute(struct libinput_device *device, struct libinput_event_pointer *event)
979 if (!(edev = libinput_device_get_user_data(device)))
984 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
986 edev->mouse.dx = edev->seat->ptr.dx =
987 libinput_event_pointer_get_absolute_x_transformed(event, w);
988 edev->mouse.dy = edev->seat->ptr.dy =
989 libinput_event_pointer_get_absolute_y_transformed(event, h);
991 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
992 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
997 edev->seat->ptr.ix = edev->seat->ptr.dx;
998 edev->seat->ptr.iy = edev->seat->ptr.dy;
1000 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1001 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1006 _device_pointer_motion(edev, event);
1010 _device_handle_button(struct libinput_device *device, struct libinput_event_pointer *event)
1012 E_Input_Evdev *edev;
1013 E_Input_Backend *input;
1014 Ecore_Event_Mouse_Button *ev;
1015 enum libinput_button_state state;
1016 uint32_t button, timestamp;
1017 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1019 E_Comp_Config *comp_conf = NULL;
1021 if (!(edev = libinput_device_get_user_data(device)))
1025 if (!(input = edev->seat->input))
1030 ecore_thread_main_loop_begin();
1032 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1033 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1035 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1037 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1042 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1047 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1049 ecore_dev = detent_data;
1054 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1055 ecore_dev = edev->ecore_dev;
1060 ERR("Failed to get source ecore device from event !\n");
1064 state = libinput_event_pointer_get_button_state(event);
1065 button = libinput_event_pointer_get_button(event);
1066 timestamp = libinput_event_pointer_get_time(event);
1068 button = ((button & 0x00F) + 1);
1069 if (button == 3) button = 2;
1070 else if (button == 2) button = 3;
1074 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1075 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1077 ELOGF("Mouse", "Button Press (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);
1084 edev->mouse.pressed_button |= (1 << button);
1089 if (!(edev->mouse.pressed_button & (1 << button)))
1091 ELOGF("Mouse", "Button Release (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
1092 button, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
1093 edev->seat->dev->server_blocked);
1096 edev->mouse.pressed_button &= ~(1 << button);
1099 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button))))
1104 ev->window = (Ecore_Window)input->dev->window;
1105 ev->event_window = (Ecore_Window)input->dev->window;
1106 ev->root_window = (Ecore_Window)input->dev->window;
1107 ev->timestamp = timestamp;
1108 ev->same_screen = 1;
1110 _device_modifiers_update(edev);
1111 ev->modifiers = edev->xkb.modifiers;
1113 ev->x = edev->seat->ptr.ix;
1114 ev->y = edev->seat->ptr.iy;
1118 ev->multi.device = edev->mt_slot;
1119 ev->multi.radius = 1;
1120 ev->multi.radius_x = 1;
1121 ev->multi.radius_y = 1;
1122 ev->multi.pressure = 1.0;
1123 ev->multi.angle = 0.0;
1124 ev->multi.x = ev->x;
1125 ev->multi.y = ev->y;
1126 ev->multi.root.x = ev->x;
1127 ev->multi.root.y = ev->y;
1128 ev->dev = ecore_device_ref(ecore_dev);
1132 unsigned int current;
1134 current = timestamp;
1135 edev->mouse.did_double = EINA_FALSE;
1136 edev->mouse.did_triple = EINA_FALSE;
1138 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1139 (button == edev->mouse.prev_button))
1141 edev->mouse.did_double = EINA_TRUE;
1142 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1143 (button == edev->mouse.last_button))
1145 edev->mouse.did_triple = EINA_TRUE;
1146 edev->mouse.prev = 0;
1147 edev->mouse.last = 0;
1152 edev->mouse.last = edev->mouse.prev;
1153 edev->mouse.prev = current;
1154 edev->mouse.last_button = edev->mouse.prev_button;
1155 edev->mouse.prev_button = button;
1158 ev->buttons = button;
1160 if (edev->mouse.did_double)
1161 ev->double_click = 1;
1162 if (edev->mouse.did_triple)
1163 ev->triple_click = 1;
1165 comp_conf = e_comp_config_get();
1166 if (comp_conf && comp_conf->input_log_enable)
1167 ELOGF("Mouse", "Button %s (btn: %d, device: %s)", NULL, state?"Press":"Release", button, ecore_device_name_get(ev->dev));
1170 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, _e_input_event_mouse_button_cb_free, NULL);
1172 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, _e_input_event_mouse_button_cb_free, NULL);
1175 ecore_thread_main_loop_end();
1178 #if !LIBINPUT_HAVE_SCROLL_VALUE_V120
1180 _axis_value_get(struct libinput_event_pointer *pointer_event, enum libinput_pointer_axis axis)
1182 enum libinput_pointer_axis_source source;
1183 double value = 0.0, value_discrete = 0.0;
1185 E_Comp_Config *comp_conf = NULL;
1187 comp_conf = e_comp_config_get();
1188 source = libinput_event_pointer_get_axis_source(pointer_event);
1191 case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL:
1192 value_discrete = libinput_event_pointer_get_axis_value_discrete(pointer_event, axis);
1193 value = libinput_event_pointer_get_axis_value(pointer_event, axis);
1194 if (comp_conf && comp_conf->input_log_enable)
1196 ELOGF("Axis", "SOURCE_WHEEL discrete: %lf (cf. value: %lf)", NULL, value_discrete, value);
1198 ret = (int)value_discrete;
1200 case LIBINPUT_POINTER_AXIS_SOURCE_FINGER:
1201 case LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS:
1202 value = libinput_event_pointer_get_axis_value(pointer_event, axis);
1203 if (comp_conf && comp_conf->input_log_enable)
1205 ELOGF("Axis", "SOURCE_FINGER/CONTINUOUS value: %lf", NULL, value);
1207 if (value >= E_INPUT_FINGER_SCROLL_THRESHOLD)
1209 else if (value <= E_INPUT_FINGER_SCROLL_THRESHOLD * (-1))
1222 _device_handle_axis(struct libinput_device *device, struct libinput_event_pointer *event)
1224 E_Input_Evdev *edev;
1225 E_Input_Backend *input;
1226 Ecore_Event_Mouse_Wheel *ev;
1228 enum libinput_pointer_axis axis;
1229 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1231 E_Comp_Config *comp_conf = NULL;
1232 int direction = 0, z = 0;
1234 if (!(edev = libinput_device_get_user_data(device)))
1238 if (!(input = edev->seat->input))
1243 ecore_thread_main_loop_begin();
1245 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1246 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1248 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1250 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1255 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1260 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1262 ecore_dev = detent_data;
1267 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1268 ecore_dev = edev->ecore_dev;
1273 ERR("Failed to get source ecore device from event !\n");
1277 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1278 if (libinput_event_pointer_has_axis(event, axis))
1279 z = _axis_value_get(event, axis);
1281 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1282 if (libinput_event_pointer_has_axis(event, axis))
1285 z = _axis_value_get(event, axis);
1290 ELOGF("Mouse", "Axis event is ignored since it has zero value", NULL);
1294 comp_conf = e_comp_config_get();
1295 if (comp_conf && comp_conf->e_wheel_click_angle)
1297 z = (int)(z * comp_conf->e_wheel_click_angle);
1300 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1301 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1304 ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1305 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1307 ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1308 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1312 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1317 timestamp = libinput_event_pointer_get_time(event);
1319 ev->window = (Ecore_Window)input->dev->window;
1320 ev->event_window = (Ecore_Window)input->dev->window;
1321 ev->root_window = (Ecore_Window)input->dev->window;
1322 ev->timestamp = timestamp;
1323 ev->same_screen = 1;
1325 _device_modifiers_update(edev);
1326 ev->modifiers = edev->xkb.modifiers;
1328 ev->x = edev->seat->ptr.ix;
1329 ev->y = edev->seat->ptr.iy;
1333 ev->direction = direction;
1335 if (comp_conf && comp_conf->input_log_enable)
1338 ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1340 ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1344 ev->dev = ecore_device_ref(ecore_dev);
1345 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1348 ecore_thread_main_loop_end();
1352 #if LIBINPUT_HAVE_SCROLL_VALUE_V120
1354 _scroll_value_get(struct libinput_event_pointer *pointer_event, enum libinput_pointer_axis axis, E_Input_Axis_Source source)
1357 double value_v120 = 0.0;
1359 E_Comp_Config *comp_conf = NULL;
1361 comp_conf = e_comp_config_get();
1364 case E_INPUT_AXIS_SOURCE_WHEEL:
1365 value_v120 = libinput_event_pointer_get_scroll_value_v120(pointer_event, axis);
1366 value = libinput_event_pointer_get_scroll_value(pointer_event, axis);
1367 if (comp_conf && comp_conf->input_log_enable)
1369 ELOGF("Scroll", "SOURCE_WHEELL value_v120: %lf (cf. value: %lf)", NULL, value_v120, value);
1371 if (((int)value_v120 % E_INPUT_POINTER_AXIS_DISCRETE_STEP) != 0)
1373 ERR("Wheel movements should be multiples (or fractions) of 120!\n");
1378 ret = value_v120 / E_INPUT_POINTER_AXIS_DISCRETE_STEP;
1381 case E_INPUT_AXIS_SOURCE_FINGER:
1382 case E_INPUT_AXIS_SOURCE_CONTINUOUS:
1383 value = libinput_event_pointer_get_scroll_value(pointer_event, axis);
1384 if (comp_conf && comp_conf->input_log_enable)
1386 ELOGF("Scroll", "SOURCE_FINGER/CONTINUOUS value: %lf", NULL, value);
1388 if (value >= E_INPUT_FINGER_SCROLL_THRESHOLD)
1390 else if (value <= E_INPUT_FINGER_SCROLL_THRESHOLD * (-1))
1403 _device_handle_axis_v120(struct libinput_device *device, struct libinput_event_pointer *event, E_Input_Axis_Source source)
1405 E_Input_Evdev *edev;
1406 E_Input_Backend *input;
1407 Ecore_Event_Mouse_Wheel *ev;
1409 enum libinput_pointer_axis axis;
1410 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1412 E_Comp_Config *comp_conf = NULL;
1413 int direction = 0, z = 0;
1415 if (!(edev = libinput_device_get_user_data(device)))
1419 if (!(input = edev->seat->input))
1424 ecore_thread_main_loop_begin();
1426 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1427 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1429 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1431 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1436 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1441 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1443 ecore_dev = detent_data;
1448 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1449 ecore_dev = edev->ecore_dev;
1454 ERR("Failed to get source ecore device from event !\n");
1458 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1459 if (libinput_event_pointer_has_axis(event, axis))
1460 z = _scroll_value_get(event, axis, source);
1462 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1463 if (libinput_event_pointer_has_axis(event, axis))
1466 z = _scroll_value_get(event, axis, source);
1471 ELOGF("Mouse", "Scroll event is ignored since it has zero value", NULL);
1475 comp_conf = e_comp_config_get();
1476 if (comp_conf && comp_conf->e_wheel_click_angle)
1478 z = (int)(z * comp_conf->e_wheel_click_angle);
1481 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1482 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1485 ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1486 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1488 ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1489 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1493 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1498 timestamp = libinput_event_pointer_get_time(event);
1500 ev->window = (Ecore_Window)input->dev->window;
1501 ev->event_window = (Ecore_Window)input->dev->window;
1502 ev->root_window = (Ecore_Window)input->dev->window;
1503 ev->timestamp = timestamp;
1504 ev->same_screen = 1;
1506 _device_modifiers_update(edev);
1507 ev->modifiers = edev->xkb.modifiers;
1509 ev->x = edev->seat->ptr.ix;
1510 ev->y = edev->seat->ptr.iy;
1514 ev->direction = direction;
1516 if (comp_conf && comp_conf->input_log_enable)
1519 ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1521 ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1524 ev->dev = ecore_device_ref(ecore_dev);
1525 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1528 ecore_thread_main_loop_end();
1533 _device_handle_touch_event_send(E_Input_Evdev *edev, struct libinput_event_touch *event, int state)
1535 E_Input_Backend *input;
1536 Ecore_Event_Mouse_Button *ev;
1537 uint32_t timestamp, button = 0;
1538 Ecore_Device *ecore_dev = NULL, *data;
1542 if (!(input = edev->seat->input)) return;
1544 ecore_thread_main_loop_begin();
1546 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1547 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1549 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1551 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1560 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1561 ecore_dev = edev->ecore_dev;
1566 ERR("Failed to get source ecore device from event !\n");
1570 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) goto end;
1572 timestamp = libinput_event_touch_get_time(event);
1574 ev->window = (Ecore_Window)input->dev->window;
1575 ev->event_window = (Ecore_Window)input->dev->window;
1576 ev->root_window = (Ecore_Window)input->dev->window;
1577 ev->timestamp = timestamp;
1578 ev->same_screen = 1;
1580 _device_modifiers_update(edev);
1581 ev->modifiers = edev->xkb.modifiers;
1583 ev->x = edev->seat->ptr.ix;
1584 ev->y = edev->seat->ptr.iy;
1588 ev->multi.device = edev->mt_slot;
1589 ev->multi.radius = 1;
1590 ev->multi.radius_x = 1;
1591 ev->multi.radius_y = 1;
1592 ev->multi.pressure = 1.0;
1593 ev->multi.angle = 0.0;
1594 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1595 if (libinput_event_get_type(libinput_event_touch_get_base_event(event))
1596 == LIBINPUT_EVENT_TOUCH_DOWN)
1598 if (libinput_event_touch_has_minor(event))
1599 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1600 if (libinput_event_touch_has_major(event))
1601 ev->multi.radius_y = libinput_event_touch_get_major(event);
1602 if (libinput_event_touch_has_pressure(event))
1603 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1604 if (libinput_event_touch_has_orientation(event))
1605 ev->multi.angle = libinput_event_touch_get_orientation(event);
1608 ev->multi.x = ev->x;
1609 ev->multi.y = ev->y;
1610 ev->multi.root.x = ev->x;
1611 ev->multi.root.y = ev->y;
1612 ev->dev = ecore_device_ref(ecore_dev);
1614 if (state == ECORE_EVENT_MOUSE_BUTTON_DOWN)
1616 unsigned int current;
1618 current = timestamp;
1619 edev->mouse.did_double = EINA_FALSE;
1620 edev->mouse.did_triple = EINA_FALSE;
1622 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1623 (button == edev->mouse.prev_button))
1625 edev->mouse.did_double = EINA_TRUE;
1626 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1627 (button == edev->mouse.last_button))
1629 edev->mouse.did_triple = EINA_TRUE;
1630 edev->mouse.prev = 0;
1631 edev->mouse.last = 0;
1636 edev->mouse.last = edev->mouse.prev;
1637 edev->mouse.prev = current;
1638 edev->mouse.last_button = edev->mouse.prev_button;
1639 edev->mouse.prev_button = button;
1640 edev->touch.pressed |= (1 << ev->multi.device);
1644 edev->touch.pressed &= ~(1 << ev->multi.device);
1647 ev->buttons = ((button & 0x00F) + 1);
1649 if (edev->mouse.did_double)
1650 ev->double_click = 1;
1651 if (edev->mouse.did_triple)
1652 ev->triple_click = 1;
1654 ecore_event_add(state, ev, _e_input_event_mouse_button_cb_free, NULL);
1657 ecore_thread_main_loop_end();
1661 _device_handle_touch_motion_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1663 E_Input_Backend *input;
1664 Ecore_Event_Mouse_Move *ev;
1665 Ecore_Device *ecore_dev = NULL, *data;
1669 if (!(input = edev->seat->input)) return;
1671 ecore_thread_main_loop_begin();
1673 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1674 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1676 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1678 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1687 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1688 ecore_dev = edev->ecore_dev;
1693 ERR("Failed to get source ecore device from event !\n");
1697 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) goto end;
1699 ev->window = (Ecore_Window)input->dev->window;
1700 ev->event_window = (Ecore_Window)input->dev->window;
1701 ev->root_window = (Ecore_Window)input->dev->window;
1702 ev->timestamp = libinput_event_touch_get_time(event);
1703 ev->same_screen = 1;
1705 _device_modifiers_update(edev);
1706 ev->modifiers = edev->xkb.modifiers;
1708 ev->x = edev->seat->ptr.ix;
1709 ev->y = edev->seat->ptr.iy;
1713 ev->multi.device = edev->mt_slot;
1714 ev->multi.radius = 1;
1715 ev->multi.radius_x = 1;
1716 ev->multi.radius_y = 1;
1717 ev->multi.pressure = 1.0;
1718 ev->multi.angle = 0.0;
1719 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1720 if (libinput_event_touch_has_minor(event))
1721 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1722 if (libinput_event_touch_has_major(event))
1723 ev->multi.radius_y = libinput_event_touch_get_major(event);
1724 if (libinput_event_touch_has_pressure(event))
1725 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1726 if (libinput_event_touch_has_orientation(event))
1727 ev->multi.angle = libinput_event_touch_get_orientation(event);
1729 ev->multi.x = ev->x;
1730 ev->multi.y = ev->y;
1731 ev->multi.root.x = ev->x;
1732 ev->multi.root.y = ev->y;
1733 ev->dev = ecore_device_ref(ecore_dev);
1735 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
1738 ecore_thread_main_loop_end();
1742 _device_handle_touch_cancel_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1744 E_Input_Backend *input;
1745 Ecore_Event_Mouse_Button *ev;
1746 uint32_t timestamp, button = 0;
1747 Ecore_Device *ecore_dev = NULL, *data;
1751 if (!(input = edev->seat->input)) return;
1753 ecore_thread_main_loop_begin();
1755 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1756 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1758 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1760 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1769 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1770 ecore_dev = edev->ecore_dev;
1775 ERR("Failed to get source ecore device from event !\n");
1779 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) goto end;
1781 timestamp = libinput_event_touch_get_time(event);
1783 ev->window = (Ecore_Window)input->dev->window;
1784 ev->event_window = (Ecore_Window)input->dev->window;
1785 ev->root_window = (Ecore_Window)input->dev->window;
1786 ev->timestamp = timestamp;
1787 ev->same_screen = 1;
1789 ev->x = edev->seat->ptr.ix;
1790 ev->y = edev->seat->ptr.iy;
1794 ev->multi.device = edev->mt_slot;
1795 ev->multi.radius = 1;
1796 ev->multi.radius_x = 1;
1797 ev->multi.radius_y = 1;
1798 ev->multi.pressure = 1.0;
1799 ev->multi.angle = 0.0;
1800 ev->multi.x = ev->x;
1801 ev->multi.y = ev->y;
1802 ev->multi.root.x = ev->x;
1803 ev->multi.root.y = ev->y;
1805 edev->touch.pressed &= ~(1 << ev->multi.device);
1807 ev->buttons = ((button & 0x00F) + 1);
1808 ev->dev = ecore_device_ref(ecore_dev);
1810 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev, _e_input_event_mouse_button_cb_free, NULL);
1813 ecore_thread_main_loop_end();
1817 _device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, int *w, int *h)
1819 E_Output *output = NULL;
1821 EINA_SAFETY_ON_NULL_RETURN(edev);
1823 if (!edev->output_configured)
1825 if (edev->output_name)
1827 output = e_output_find(edev->output_name);
1830 edev->mouse.minx = output->config.geom.x;
1831 edev->mouse.miny = output->config.geom.y;
1832 edev->mouse.maxw = output->config.geom.w;
1833 edev->mouse.maxh = output->config.geom.h;
1834 if (libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
1836 edev->seat->ptr.dx = (double)(edev->mouse.maxw / 2);
1837 edev->seat->ptr.dy = (double)(edev->mouse.maxh / 2);
1838 edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
1839 edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
1840 edev->mouse.dx = edev->seat->ptr.dx;
1841 edev->mouse.dy = edev->seat->ptr.dy;
1846 edev->output_configured = EINA_TRUE;
1847 ELOGF("E_INPUT_EVDEV", "Device is configured by output x:%d,y:%d (w:%d, h:%d)",
1848 NULL, edev->mouse.minx, edev->mouse.miny, edev->mouse.maxw, edev->mouse.maxh);
1850 if (x) *x = edev->mouse.minx;
1851 if (y) *y = edev->mouse.miny;
1852 if (w) *w = edev->mouse.maxw;
1853 if (h) *h = edev->mouse.maxh;
1857 _device_handle_touch_down(struct libinput_device *device, struct libinput_event_touch *event)
1859 E_Input_Evdev *edev;
1860 int x = 0, y = 0, w = 0, h = 0;
1861 E_Comp_Config *comp_conf = NULL;
1863 if (!(edev = libinput_device_get_user_data(device)))
1868 _device_configured_size_get(edev, &x, &y, &w, &h);
1870 edev->mouse.dx = edev->seat->ptr.ix = edev->seat->ptr.dx =
1871 x + libinput_event_touch_get_x_transformed(event, w);
1872 edev->mouse.dy = edev->seat->ptr.iy = edev->seat->ptr.dy =
1873 y + libinput_event_touch_get_y_transformed(event, h);
1875 edev->mt_slot = libinput_event_touch_get_slot(event);
1876 if (edev->mt_slot < 0)
1878 /* FIXME: The single touch device return slot id -1
1879 * But currently we have no API to distinguish multi touch or single touch
1880 * After libinput 1.11 version, libinput provides get_touch_count API,
1881 * so we can distinguish multi touch device or single touch device.
1883 if (edev->mt_slot == -1)
1887 WRN("%d slot touch down events are not supported\n", edev->mt_slot);
1892 if (edev->mt_slot < e_input_touch_max_count_get())
1894 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
1895 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
1898 comp_conf = e_comp_config_get();
1899 if (comp_conf && comp_conf->input_log_enable)
1900 ELOGF("Touch", "Down (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
1902 edev->touch.raw_pressed |= (1 << edev->mt_slot);
1904 if (edev->touch.blocked)
1906 ELOGF("Touch", "Down (id: %d, x: %d, y: %d) is blocked by %p, server: 0x%x", NULL,
1907 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, edev->seat->dev->blocked_client,
1908 edev->seat->dev->server_blocked);
1912 _device_handle_touch_motion_send(edev, event);
1913 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_DOWN);
1917 _device_handle_touch_motion(struct libinput_device *device, struct libinput_event_touch *event)
1919 E_Input_Evdev *edev;
1920 int x = 0, y = 0, w = 0, h = 0;
1922 if (!(edev = libinput_device_get_user_data(device)))
1927 _device_configured_size_get(edev, &x, &y, &w, &h);
1929 edev->mouse.dx = edev->seat->ptr.dx =
1930 x + libinput_event_touch_get_x_transformed(event, w);
1931 edev->mouse.dy = edev->seat->ptr.dy =
1932 y + libinput_event_touch_get_y_transformed(event, h);
1934 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
1935 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
1940 edev->seat->ptr.ix = edev->seat->ptr.dx;
1941 edev->seat->ptr.iy = edev->seat->ptr.dy;
1943 edev->mt_slot = libinput_event_touch_get_slot(event);
1944 if (edev->mt_slot < 0)
1946 /* FIXME: The single touch device return slot id -1
1947 * But currently we have no API to distinguish multi touch or single touch
1948 * After libinput 1.11 version, libinput provides get_touch_count API,
1949 * so we can distinguish multi touch device or single touch device.
1951 if (edev->mt_slot == -1)
1955 WRN("%d slot touch motion events are not supported\n", edev->mt_slot);
1960 if (edev->mt_slot < e_input_touch_max_count_get())
1962 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
1963 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
1966 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
1968 if (edev->touch.blocked)
1974 _device_handle_touch_motion_send(edev, event);
1978 _device_handle_touch_up(struct libinput_device *device, struct libinput_event_touch *event)
1980 E_Input_Evdev *edev;
1981 E_Comp_Config *comp_conf = NULL;
1983 if (!(edev = libinput_device_get_user_data(device)))
1988 edev->mt_slot = libinput_event_touch_get_slot(event);
1989 if (edev->mt_slot < 0)
1991 /* FIXME: The single touch device return slot id -1
1992 * But currently we have no API to distinguish multi touch or single touch
1993 * After libinput 1.11 version, libinput provides get_touch_count API,
1994 * so we can distinguish multi touch device or single touch device.
1996 if (edev->mt_slot == -1)
2000 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
2005 if (edev->mt_slot < e_input_touch_max_count_get())
2007 edev->mouse.dx = edev->seat->ptr.dx = edev->seat->ptr.ix =
2008 edev->touch.coords[edev->mt_slot].x;
2009 edev->mouse.dy = edev->seat->ptr.dy = edev->seat->ptr.iy =
2010 edev->touch.coords[edev->mt_slot].y;
2013 comp_conf = e_comp_config_get();
2014 if (comp_conf && comp_conf->input_log_enable)
2015 ELOGF("Touch", "Up (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2017 edev->touch.raw_pressed &= ~(1 << edev->mt_slot);
2019 if (edev->touch.blocked)
2021 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
2023 ELOGF("Touch", "Up (id: %d, x: %d, y: %d) is blocked by %p, server(0x%x)", NULL,
2024 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, edev->seat->dev->blocked_client,
2025 edev->seat->dev->server_blocked);
2026 if (edev->touch.raw_pressed == 0x0)
2028 edev->touch.blocked = EINA_FALSE;
2034 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_UP);
2038 _device_handle_touch_cancel(struct libinput_device *device, struct libinput_event_touch *event)
2040 E_Input_Evdev *edev;
2041 E_Comp_Config *comp_conf = NULL;
2043 if (!(edev = libinput_device_get_user_data(device)))
2048 edev->mt_slot = libinput_event_touch_get_slot(event);
2049 if (edev->mt_slot < 0)
2051 /* FIXME: The single touch device return slot id -1
2052 * But currently we have no API to distinguish multi touch or single touch
2053 * After libinput 1.11 version, libinput provides get_touch_count API,
2054 * so we can distinguish multi touch device or single touch device.
2056 if (edev->mt_slot == -1)
2060 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
2065 comp_conf = e_comp_config_get();
2066 if (comp_conf && comp_conf->input_log_enable)
2067 ELOGF("Touch", "cancel (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2069 _device_handle_touch_cancel_send(edev, event);
2074 _device_handle_touch_frame(struct libinput_device *device EINA_UNUSED, struct libinput_event_touch *event EINA_UNUSED)
2076 /* DBG("Unhandled Touch Frame Event"); */
2080 _e_input_aux_data_event_free(void *user_data EINA_UNUSED, void *ev)
2082 Ecore_Event_Axis_Update *e = (Ecore_Event_Axis_Update *)ev;
2084 if (e->axis) free(e->axis);
2085 if (e->dev) ecore_device_unref(e->dev);
2091 _device_handle_touch_aux_data(struct libinput_device *device, struct libinput_event_touch_aux_data *event)
2093 E_Input_Evdev *edev;
2094 E_Input_Backend *input;
2095 Ecore_Event_Axis_Update *ev;
2097 Ecore_Device *ecore_dev = NULL, *data;
2099 E_Comp_Config *comp_conf;
2101 ecore_thread_main_loop_begin();
2103 if (libinput_event_touch_aux_data_get_type(event) != LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM &&
2104 libinput_event_touch_aux_data_get_value(event) > 0)
2107 if (!(edev = libinput_device_get_user_data(device))) goto end;
2108 if (!(input = edev->seat->input)) goto end;
2110 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
2111 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
2113 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
2115 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
2124 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
2125 ecore_dev = edev->ecore_dev;
2130 ERR("Failed to get source ecore device from event !\n");
2134 if (!(ev = calloc(1, sizeof(Ecore_Event_Axis_Update)))) goto end;
2136 ev->window = (Ecore_Window)input->dev->window;
2137 ev->event_window = (Ecore_Window)input->dev->window;
2138 ev->root_window = (Ecore_Window)input->dev->window;
2139 ev->timestamp = libinput_event_touch_aux_data_get_time(event);
2141 axis = (Ecore_Axis *)calloc(1, sizeof(Ecore_Axis));
2144 axis->label = ECORE_AXIS_LABEL_TOUCH_PALM;
2145 axis->value = libinput_event_touch_aux_data_get_value(event);
2150 comp_conf = e_comp_config_get();
2151 if (comp_conf && comp_conf->input_log_enable)
2152 ELOGF("Touch", "Axis (label: %d, value: %lf)", NULL, axis?axis->label:-1, axis?axis->value:0.0);
2154 ev->dev = ecore_device_ref(ecore_dev);
2156 ecore_event_add(ECORE_EVENT_AXIS_UPDATE, ev, _e_input_aux_data_event_free, NULL);
2159 ecore_thread_main_loop_end();
2163 _e_input_evdev_device_create(E_Input_Seat *seat, struct libinput_device *device)
2165 E_Input_Evdev *edev;
2166 E_Input_Backend *b_input;
2167 const char *output_name;
2169 EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
2171 /* try to allocate space for new evdev */
2172 if (!(edev = calloc(1, sizeof(E_Input_Evdev)))) return NULL;
2175 edev->device = device;
2176 edev->path = eina_stringshare_printf("%s/%s", e_input_base_dir_get(), libinput_device_get_sysname(device));
2178 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
2180 edev->caps |= E_INPUT_SEAT_KEYBOARD;
2181 _device_keyboard_setup(edev);
2184 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
2186 edev->caps |= E_INPUT_SEAT_POINTER;
2188 /* TODO: make this configurable */
2189 edev->mouse.threshold = 250;
2191 b_input = seat->input;
2192 if (b_input->left_handed == EINA_TRUE)
2194 if (libinput_device_config_left_handed_set(device, 1) !=
2195 LIBINPUT_CONFIG_STATUS_SUCCESS)
2197 WRN("Failed to set left hand mode about device: %s\n",
2198 libinput_device_get_name(device));
2203 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
2206 edev->caps |= E_INPUT_SEAT_TOUCH;
2207 palm_code = libinput_device_touch_aux_data_get_code(LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM);
2208 if (libinput_device_touch_has_aux_data(device, palm_code))
2210 libinput_device_touch_set_aux_data(device, palm_code);
2213 _device_touch_count_update(edev);
2215 edev->touch.coords = calloc(1, sizeof(E_Input_Coord)*e_input_touch_max_count_get());
2217 if (!edev->touch.coords)
2218 ERR("Failed to allocate memory for touch coords !\n");
2221 output_name = libinput_device_get_output_name(device);
2224 eina_stringshare_replace(&edev->output_name, output_name);
2225 ELOGF("E_INPUT_EVDEV", "Device has output_name:%s", NULL, output_name);
2228 libinput_device_set_user_data(device, edev);
2229 libinput_device_ref(device);
2231 /* configure device */
2232 _device_configure(edev);
2238 _e_input_evdev_device_destroy(E_Input_Evdev *edev)
2242 EINA_SAFETY_ON_NULL_RETURN(edev);
2244 ecore_thread_main_loop_begin();
2246 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
2248 g_mutex_lock(&edev->xkb.state_mutex);
2249 if (edev->xkb.state) xkb_state_unref(edev->xkb.state);
2250 g_mutex_unlock(&edev->xkb.state_mutex);
2252 g_mutex_lock(&edev->xkb.keymap_mutex);
2253 if (edev->xkb.keymap) xkb_map_unref(edev->xkb.keymap);
2254 g_mutex_unlock(&edev->xkb.keymap_mutex);
2257 if (edev->ecore_dev) ecore_device_del(edev->ecore_dev);
2258 if (edev->ecore_dev_list)
2259 EINA_LIST_FREE(edev->ecore_dev_list, dev)
2261 ecore_device_del(dev);
2263 if (edev->path) eina_stringshare_del(edev->path);
2264 if (edev->device) libinput_device_unref(edev->device);
2265 if (edev->key_remap_hash) eina_hash_free(edev->key_remap_hash);
2266 if (edev->touch.coords)
2268 free(edev->touch.coords);
2269 edev->touch.coords = NULL;
2271 eina_stringshare_del(edev->output_name);
2273 ecore_thread_main_loop_end();
2279 _e_input_evdev_event_process(struct libinput_event *event)
2281 struct libinput_device *device;
2282 Eina_Bool ret = EINA_TRUE;
2284 device = libinput_event_get_device(event);
2285 switch (libinput_event_get_type(event))
2287 case LIBINPUT_EVENT_KEYBOARD_KEY:
2288 _device_handle_key(device, libinput_event_get_keyboard_event(event));
2290 case LIBINPUT_EVENT_POINTER_MOTION:
2291 _device_handle_pointer_motion(device,
2292 libinput_event_get_pointer_event(event));
2294 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
2295 _device_handle_pointer_motion_absolute(device,
2296 libinput_event_get_pointer_event(event));
2298 case LIBINPUT_EVENT_POINTER_BUTTON:
2299 _device_handle_button(device, libinput_event_get_pointer_event(event));
2301 case LIBINPUT_EVENT_POINTER_AXIS:
2302 #if !LIBINPUT_HAVE_SCROLL_VALUE_V120
2303 _device_handle_axis(device, libinput_event_get_pointer_event(event));
2306 #if LIBINPUT_HAVE_SCROLL_VALUE_V120
2307 case LIBINPUT_EVENT_POINTER_SCROLL_WHEEL:
2308 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_WHEEL);
2310 case LIBINPUT_EVENT_POINTER_SCROLL_FINGER:
2311 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_FINGER);
2313 case LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS:
2314 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_CONTINUOUS);
2317 case LIBINPUT_EVENT_TOUCH_DOWN:
2318 _device_handle_touch_down(device, libinput_event_get_touch_event(event));
2320 case LIBINPUT_EVENT_TOUCH_MOTION:
2321 _device_handle_touch_motion(device,
2322 libinput_event_get_touch_event(event));
2324 case LIBINPUT_EVENT_TOUCH_UP:
2325 _device_handle_touch_up(device, libinput_event_get_touch_event(event));
2327 case LIBINPUT_EVENT_TOUCH_CANCEL:
2328 _device_handle_touch_cancel(device, libinput_event_get_touch_event(event));
2330 case LIBINPUT_EVENT_TOUCH_FRAME:
2331 _device_handle_touch_frame(device, libinput_event_get_touch_event(event));
2333 case LIBINPUT_EVENT_TOUCH_AUX_DATA:
2334 _device_handle_touch_aux_data(device, libinput_event_get_touch_aux_data(event));
2345 * @brief Set the axis size of the given device.
2347 * @param dev The device to set the axis size to.
2348 * @param w The width of the axis.
2349 * @param h The height of the axis.
2351 * This function sets set the width @p w and height @p h of the axis
2352 * of device @p dev. If @p dev is a relative input device, a width and
2353 * height must set for it. If its absolute set the ioctl correctly, if
2354 * not, unsupported device.
2357 e_input_evdev_axis_size_set(E_Input_Evdev *edev, int w, int h)
2359 const char *sysname;
2364 enum libinput_config_status status;
2366 EINA_SAFETY_ON_NULL_RETURN(edev);
2367 EINA_SAFETY_ON_TRUE_RETURN((w == 0) || (h == 0));
2369 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
2370 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
2373 sysname = libinput_device_get_sysname(edev->device);
2375 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
2376 if (eina_list_count(devices) < 1) return;
2378 EINA_LIST_FREE(devices, device)
2380 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
2382 (sscanf(vals, "%f %f %f %f %f %f",
2383 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
2390 libinput_device_config_calibration_set_matrix(edev->device, cal);
2392 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
2393 ERR("Failed to apply calibration");
2396 eina_stringshare_del(device);
2401 EINTERN const char *
2402 e_input_evdev_name_get(E_Input_Evdev *evdev)
2404 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2405 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2407 return libinput_device_get_name(evdev->device);
2410 EINTERN const char *
2411 e_input_evdev_sysname_get(E_Input_Evdev *evdev)
2413 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2414 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2416 return libinput_device_get_sysname(evdev->device);
2420 e_input_evdev_key_remap_enable(E_Input_Evdev *edev, Eina_Bool enable)
2422 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2423 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2425 edev->key_remap_enabled = enable;
2427 if (enable == EINA_FALSE && edev->key_remap_hash)
2429 eina_hash_free(edev->key_remap_hash);
2430 edev->key_remap_hash = NULL;
2437 e_input_evdev_key_remap_set(E_Input_Evdev *edev, int *from_keys, int *to_keys, int num)
2441 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2442 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2443 EINA_SAFETY_ON_NULL_RETURN_VAL(from_keys, EINA_FALSE);
2444 EINA_SAFETY_ON_NULL_RETURN_VAL(to_keys, EINA_FALSE);
2445 EINA_SAFETY_ON_TRUE_RETURN_VAL(num <= 0, EINA_FALSE);
2446 EINA_SAFETY_ON_TRUE_RETURN_VAL(!edev->key_remap_enabled, EINA_FALSE);
2448 if (edev->key_remap_hash == NULL)
2449 edev->key_remap_hash = eina_hash_int32_new(NULL);
2451 if (edev->key_remap_hash == NULL)
2453 ERR("Failed to set remap key information : creating a hash is failed.");
2457 for (i = 0; i < num ; i++)
2459 if (!from_keys[i] || !to_keys[i])
2461 ERR("Failed to set remap key information : given arguments are invalid.");
2466 for (i = 0; i < num ; i++)
2468 eina_hash_add(edev->key_remap_hash, &from_keys[i], (void *)(intptr_t)to_keys[i]);
2475 e_input_evdev_wheel_click_angle_get(E_Input_Evdev *dev)
2477 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, -1);
2478 return libinput_device_config_scroll_get_wheel_click_angle(dev->device);
2482 e_input_evdev_touch_calibration_set(E_Input_Evdev *edev, float matrix[6])
2484 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2485 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2487 if (!libinput_device_config_calibration_has_matrix(edev->device) ||
2488 !libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_TOUCH))
2491 if (libinput_device_config_calibration_set_matrix(edev->device, matrix) !=
2492 LIBINPUT_CONFIG_STATUS_SUCCESS)
2494 WRN("Failed to set input transformation about device: %s\n",
2495 libinput_device_get_name(edev->device));
2503 e_input_evdev_mouse_accel_speed_set(E_Input_Evdev *edev, double speed)
2505 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2506 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2508 if (!libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
2511 if (!libinput_device_config_accel_is_available(edev->device))
2514 if (libinput_device_config_accel_set_speed(edev->device, speed) !=
2515 LIBINPUT_CONFIG_STATUS_SUCCESS)
2517 WRN("Failed to set mouse accel about device: %s\n",
2518 libinput_device_get_name(edev->device));
2525 EINTERN unsigned int
2526 e_input_evdev_touch_pressed_get(E_Input_Evdev *edev)
2528 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, 0x0);
2530 return edev->touch.pressed;
2534 e_input_evdev_seatname_get(E_Input_Evdev *evdev)
2536 struct libinput_seat *libinput_seat;
2537 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2538 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2540 libinput_seat = libinput_device_get_seat(evdev->device);
2542 return libinput_seat_get_logical_name(libinput_seat);
2546 e_input_evdev_seatname_set(E_Input_Evdev *evdev, const char *seatname)
2548 Eina_Bool res = EINA_FALSE;
2549 E_Input_Backend *input;
2551 EINA_SAFETY_ON_NULL_RETURN_VAL(seatname, EINA_FALSE);
2552 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, EINA_FALSE);
2553 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, EINA_FALSE);
2555 if (libinput_device_set_seat_logical_name(evdev->device, seatname) == 0)
2557 input = evdev->seat->input;
2558 if (!input) return EINA_FALSE;
2559 if (libinput_dispatch(input->libinput) != 0)
2561 ERR("Failed to dispatch libinput events: %m");
2565 /* process pending events */
2566 _input_events_process(input);
2574 e_input_evdev_mouse_accel_enable(E_Input_Evdev *edev, Eina_Bool enable)
2576 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2577 edev->disable_acceleration = !enable;