1 #include "e_input_intern.h"
2 #include "e_input_log.h"
3 #include "e_input_event.h"
4 #include "e_keyrouter_intern.h"
5 #include "e_devicemgr_intern.h"
6 #include "e_device_intern.h"
7 #include "e_comp_screen_intern.h"
8 #include "e_output_intern.h"
13 #define G_LIST_GET_DATA(list) ((list) ? (((GList *)(list))->data) : NULL)
15 static void _device_modifiers_update(E_Input_Evdev *edev);
16 static void _device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, int *w, int *h);
17 static void _device_output_assign(E_Input_Evdev *edev, E_Input_Seat_Capabilities cap);
20 _device_calibration_set(E_Input_Evdev *edev)
25 E_Comp_Config *comp_conf;
27 if (e_comp->e_comp_screen->num_outputs > 1) //multiple outputs
29 comp_conf = e_comp_config_get();
30 if (comp_conf && (comp_conf->input_output_assign_policy == 1)) //use output-assignment policy
32 _device_output_assign(edev, E_INPUT_SEAT_POINTER);
33 _device_output_assign(edev, E_INPUT_SEAT_TOUCH);
37 output = e_comp_screen_primary_output_get(e_comp->e_comp_screen);
38 e_output_size_get(output, &w, &h);
42 edev->mouse.minx = edev->mouse.miny = 0;
46 if (edev->caps & E_INPUT_SEAT_POINTER)
48 edev->seat->ptr.dx = (double)(w / 2);
49 edev->seat->ptr.dy = (double)(h / 2);
50 edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
51 edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
52 edev->mouse.dx = edev->seat->ptr.dx;
53 edev->mouse.dy = edev->seat->ptr.dy;
55 if (output->config.rotation == 90 || output->config.rotation == 270)
57 temp = edev->mouse.minx;
58 edev->mouse.minx = edev->mouse.miny;
59 edev->mouse.miny = temp;
61 temp = edev->mouse.maxw;
62 edev->mouse.maxw = edev->mouse.maxh;
63 edev->mouse.maxh = temp;
69 #ifdef _F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
72 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
73 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
76 #ifdef _F_E_INPUT_USE_WL_CALIBRATION_
78 enum libinput_config_status status;
79 struct udev_device *udev_device = NULL;
81 udev_device = libinput_device_get_udev_device(edev->device);
84 ERR("no udev_device");
88 vals = udev_device_get_property_value(udev_device, "WL_CALIBRATION");
90 (sscanf(vals, "%f %f %f %f %f %f",
91 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
94 ELOGF("E_INPUT_EVDEV", "calibration_set cal[%lf %lf %lf %lf %lf %lf] (%d x %d)",
95 NULL, cal[0], cal[1], cal[2], cal[3], cal[4], cal[5], w, h);
100 libinput_device_config_calibration_set_matrix(edev->device, cal);
102 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
103 ERR("Failed to apply calibration");
104 #endif//_F_E_INPUT_USE_WL_CALIBRATION_
105 #endif//_F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
110 _device_output_assign(E_Input_Evdev *edev, E_Input_Seat_Capabilities cap)
115 Eina_Bool need_assign_output = EINA_FALSE;
116 const char *output_name;
119 if (!(edev->caps & cap)) return;
120 if (edev->output_name) return; //already assigned
121 if (e_comp->e_comp_screen->num_outputs <= 1) return;
123 last_output_idx = e_comp->e_comp_screen->num_outputs - 1;
124 EINA_LIST_FOREACH(edev->seat->devices, l, ed)
126 if (!(ed->caps & cap)) continue;
127 if (ed == edev) continue;
130 need_assign_output = EINA_FALSE;
133 need_assign_output = EINA_TRUE;
135 if (need_assign_output)
137 output = e_output_find_by_index(last_output_idx);
138 if (!output || !output->info.connected) return;
139 output_name = e_output_output_id_get(output);
140 if (output_name) edev->output_name = eina_stringshare_add(output_name);
141 ELOGF("E_INPUT_EVDEV", "Device is assigned to output:%s", NULL, output_name);
146 _device_touch_count_update(E_Input_Evdev *edev)
148 unsigned int device_touch_count = 0;
149 static unsigned int _max_device_touch_count = 0;
151 E_Input *ei = e_input_get();
152 EINA_SAFETY_ON_NULL_RETURN(ei);
154 device_touch_count = libinput_device_touch_get_touch_count(edev->device);
156 if (_max_device_touch_count < device_touch_count)
157 _max_device_touch_count = device_touch_count;
159 if (e_config->configured_max_touch.use)
161 if (_max_device_touch_count > 0 && e_config->configured_max_touch.count > _max_device_touch_count)
163 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",
164 NULL, e_config->configured_max_touch.count, _max_device_touch_count, _max_device_touch_count);
165 ei->touch_max_count = _max_device_touch_count;
169 if (ei->touch_max_count != e_config->configured_max_touch.count)
171 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch_max_count has been updated to %d -> %d.\n",
172 NULL, ei->touch_max_count, e_config->configured_max_touch.count);
173 ei->touch_max_count = e_config->configured_max_touch.count;
179 if (ei->touch_max_count < _max_device_touch_count)
181 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch_max_count has been updated to %d -> %d.\n", NULL,
182 ei->touch_max_count, _max_device_touch_count);
183 ei->touch_max_count = _max_device_touch_count;
187 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch max count is %d.\n", NULL, ei->touch_max_count);
191 _device_configure(E_Input_Evdev *edev)
193 if (libinput_device_config_tap_get_finger_count(edev->device) > 0)
195 Eina_Bool tap = EINA_FALSE;
197 tap = libinput_device_config_tap_get_default_enabled(edev->device);
198 libinput_device_config_tap_set_enabled(edev->device, tap);
201 _device_calibration_set(edev);
205 _device_keyboard_setup(E_Input_Evdev *edev)
207 E_Input_Backend *input;
208 xkb_mod_index_t xkb_idx;
210 if ((!edev) || (!edev->seat)) return;
211 if (!(input = edev->seat->input)) return;
212 if (!input->dev->xkb_ctx) return;
214 /* create keymap from xkb context */
215 edev->xkb.keymap = _e_input_device_cached_keymap_get(input->dev->xkb_ctx, NULL, 0);
216 if (!edev->xkb.keymap)
218 ERR("Failed to create keymap: %m");
222 /* create xkb state */
223 if (!(edev->xkb.state = xkb_state_new(edev->xkb.keymap)))
225 ERR("Failed to create xkb state: %m");
229 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CTRL);
230 if (xkb_idx != XKB_MOD_INVALID)
231 edev->xkb.ctrl_mask = 1 << xkb_idx;
233 edev->xkb.ctrl_mask = 0;
235 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_ALT);
236 if (xkb_idx != XKB_MOD_INVALID)
237 edev->xkb.alt_mask = 1 << xkb_idx;
239 edev->xkb.alt_mask = 0;
241 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_SHIFT);
242 if (xkb_idx != XKB_MOD_INVALID)
243 edev->xkb.shift_mask = 1 << xkb_idx;
245 edev->xkb.shift_mask = 0;
247 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_LOGO);
248 if (xkb_idx != XKB_MOD_INVALID)
249 edev->xkb.win_mask = 1 << xkb_idx;
251 edev->xkb.win_mask = 0;
253 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_SCROLL);
254 if (xkb_idx != XKB_MOD_INVALID)
255 edev->xkb.scroll_mask = 1 << xkb_idx;
257 edev->xkb.scroll_mask = 0;
259 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_NUM);
260 if (xkb_idx != XKB_MOD_INVALID)
261 edev->xkb.num_mask = 1 << xkb_idx;
263 edev->xkb.num_mask = 0;
265 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CAPS);
266 if (xkb_idx != XKB_MOD_INVALID)
267 edev->xkb.caps_mask = 1 << xkb_idx;
269 edev->xkb.caps_mask = 0;
271 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, "ISO_Level3_Shift");
272 if (xkb_idx != XKB_MOD_INVALID)
273 edev->xkb.altgr_mask = 1 << xkb_idx;
275 edev->xkb.altgr_mask = 0;
279 _device_keysym_translate(xkb_keysym_t keysym, unsigned int modifiers, char *buffer, int bytes)
281 unsigned long hbytes = 0;
284 if (!keysym) return 0;
285 hbytes = (keysym >> 8);
290 (((keysym >= XKB_KEY_BackSpace) && (keysym <= XKB_KEY_Clear)) ||
291 (keysym == XKB_KEY_Return) || (keysym == XKB_KEY_Escape) ||
292 (keysym == XKB_KEY_KP_Space) || (keysym == XKB_KEY_KP_Tab) ||
293 (keysym == XKB_KEY_KP_Enter) ||
294 ((keysym >= XKB_KEY_KP_Multiply) && (keysym <= XKB_KEY_KP_9)) ||
295 (keysym == XKB_KEY_KP_Equal) || (keysym == XKB_KEY_Delete))))))
298 if (keysym == XKB_KEY_KP_Space)
299 c = (XKB_KEY_space & 0x7F);
300 else if (hbytes == 0xFF)
305 if (modifiers & ECORE_EVENT_MODIFIER_CTRL)
307 if (((c >= '@') && (c < '\177')) || c == ' ')
311 else if ((c >= '3') && (c <= '7'))
323 _device_modifiers_update_device(E_Input_Evdev *edev, E_Input_Evdev *from)
327 edev->xkb.depressed =
328 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_DEPRESSED);
330 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LATCHED);
332 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LOCKED);
334 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_EFFECTIVE);
336 mask = (edev->xkb.depressed | edev->xkb.latched);
338 if (mask & from->xkb.ctrl_mask)
339 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_CTRL;
340 if (mask & from->xkb.alt_mask)
341 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALT;
342 if (mask & from->xkb.shift_mask)
343 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
344 if (mask & from->xkb.win_mask)
345 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_WIN;
346 if (mask & from->xkb.scroll_mask)
347 edev->xkb.modifiers |= ECORE_EVENT_LOCK_SCROLL;
348 if (mask & from->xkb.num_mask)
349 edev->xkb.modifiers |= ECORE_EVENT_LOCK_NUM;
350 if (mask & from->xkb.caps_mask)
351 edev->xkb.modifiers |= ECORE_EVENT_LOCK_CAPS;
352 if (mask & from->xkb.altgr_mask)
353 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALTGR;
357 _device_modifiers_update(E_Input_Evdev *edev)
362 edev->xkb.modifiers = 0;
364 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
365 _device_modifiers_update_device(edev, edev);
368 EINA_LIST_FOREACH(edev->seat->devices, l, ed)
370 if (!(ed->caps & E_INPUT_SEAT_KEYBOARD)) continue;
371 _device_modifiers_update_device(edev, ed);
378 _device_remapped_key_get(E_Input_Evdev *edev, int code)
382 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, code);
383 if (!edev->key_remap_enabled) return code;
384 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->key_remap_hash, code);
386 ret = eina_hash_find(edev->key_remap_hash, &code);
388 if (ret) code = (int)(intptr_t)ret;
394 e_input_evdev_get_e_device(const char *path, Ecore_Device_Class clas)
396 const GList *dev_list = NULL;
398 E_Device *dev = NULL;
399 const char *identifier;
401 if (!path) return NULL;
403 dev_list = e_device_list_get();
404 if (!dev_list) return NULL;
411 identifier = e_device_identifier_get(dev);
412 if (!identifier) continue;
413 if ((e_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
422 EINTERN Ecore_Device *
423 e_input_evdev_get_ecore_device(const char *path, Ecore_Device_Class clas)
425 const Eina_List *dev_list = NULL;
427 Ecore_Device *dev = NULL;
428 const char *identifier;
430 if (!path) return NULL;
432 dev_list = ecore_device_list();
433 if (!dev_list) return NULL;
434 EINA_LIST_FOREACH(dev_list, l, dev)
437 identifier = ecore_device_identifier_get(dev);
438 if (!identifier) continue;
439 if ((ecore_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
446 _e_input_event_mouse_move_cb_free(void *data EINA_UNUSED, void *event)
448 Ecore_Event_Mouse_Move *ev = event;
450 if (ev->dev) ecore_device_unref(ev->dev);
456 _e_input_event_mouse_relative_move_cb_free(void *data EINA_UNUSED, void *event)
458 Ecore_Event_Mouse_Relative_Move *ev = event;
460 if (ev->dev) ecore_device_unref(ev->dev);
466 _e_input_event_mouse_wheel_cb_free(void *data EINA_UNUSED, void *event)
468 Ecore_Event_Mouse_Wheel *ev = event;
470 if (ev->dev) ecore_device_unref(ev->dev);
476 _e_input_event_mouse_button_cb_free(void *data EINA_UNUSED, void *event)
478 Ecore_Event_Mouse_Button *ev = event;
480 if (ev->dev) ecore_device_unref(ev->dev);
486 _e_input_event_key_cb_free(void *data EINA_UNUSED, void *event)
488 Ecore_Event_Key *ev = event;
490 if (e_input_thread_mode_get())
492 if (ev->dev) g_object_unref(ev->dev);
496 if (ev->dev) ecore_device_unref(ev->dev);
499 if (ev->data) E_FREE(ev->data);
505 _device_handle_key(struct libinput_device *device, struct libinput_event_keyboard *event)
508 E_Input_Backend *input;
510 uint32_t code, nsyms;
511 const xkb_keysym_t *syms;
512 enum libinput_key_state state;
514 xkb_keysym_t sym = XKB_KEY_NoSymbol;
515 char key[256] = {0, }, keyname[256] = {0, }, compose_buffer[256] = {0, };
517 char *tmp = NULL, *compose = NULL;
518 E_Keyrouter_Event_Data *key_data;
519 Ecore_Device *ecore_dev = NULL, *data;
520 E_Device *e_dev = NULL, *e_dev_data;
521 Eina_List *l = NULL, *l_next = NULL;
523 E_Comp_Config *comp_conf = NULL;
524 int *pressed_keycode = NULL, *idata = NULL;
525 Eina_Bool dup_found = EINA_FALSE;
526 const char *device_name = NULL;
527 Ecore_Device_Subclass device_subclas = ECORE_DEVICE_SUBCLASS_NONE;
529 if (!(edev = libinput_device_get_user_data(device)))
534 if (!(input = edev->seat->input))
539 if (!e_input_thread_mode_get())
541 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
542 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
544 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
546 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_KEYBOARD)
555 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
556 ecore_dev = edev->ecore_dev;
561 ERR("Failed to get source ecore device from event !\n");
565 device_name = ecore_device_name_get(ecore_dev);
566 device_subclas = ecore_device_subclass_get(ecore_dev);
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 device_name = e_device_name_get(e_dev);
599 device_subclas = e_device_subclass_get(e_dev);
602 timestamp = libinput_event_keyboard_get_time(event);
603 code = libinput_event_keyboard_get_key(event);
604 code = _device_remapped_key_get(edev, code + 8);
605 state = libinput_event_keyboard_get_key_state(event);
606 key_count = libinput_event_keyboard_get_seat_key_count(event);
608 if (state == LIBINPUT_KEY_STATE_PRESSED)
610 if ((edev->seat->dev->blocked & E_INPUT_SEAT_KEYBOARD) ||
611 (edev->seat->dev->server_blocked & E_INPUT_SEAT_KEYBOARD))
613 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
614 ELOGF("Key", "Press (keycode: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
615 code, device_name, blocked_client,
616 edev->seat->dev->server_blocked);
620 /* FIXME: Currently to maintain press/release event pair during input block,
621 * used Eina_List and this is method used in devicemgr module.
622 * But we need to consider which way is better to maintain key press/release pair.
625 EINA_LIST_FOREACH(edev->xkb.pressed_keys, l, idata)
629 dup_found = EINA_TRUE;
635 pressed_keycode = E_NEW(int, 1);
636 EINA_SAFETY_ON_NULL_RETURN(pressed_keycode);
637 *pressed_keycode = code;
639 edev->xkb.pressed_keys = eina_list_append(edev->xkb.pressed_keys, pressed_keycode);
644 dup_found = EINA_FALSE;
645 EINA_LIST_FOREACH_SAFE(edev->xkb.pressed_keys, l, l_next, idata)
649 edev->xkb.pressed_keys = eina_list_remove_list(edev->xkb.pressed_keys, l);
651 dup_found = EINA_TRUE;
657 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
658 ELOGF("Key", "Release (keycode: %d, device: %s) is blocked by %p", NULL,
659 code, device_name, blocked_client);
664 /* ignore key events that are not seat wide state changes */
665 if (((state == LIBINPUT_KEY_STATE_PRESSED) && (key_count != 1)) ||
666 ((state == LIBINPUT_KEY_STATE_RELEASED) && (key_count != 0)))
671 e_input_keyboard_grab_key_cb func = e_input_keyboard_grab_key_handler_get();
674 if (e_devicemgr_keyboard_grab_subtype_is_grabbed(device_subclas))
676 if (!e_input_thread_mode_get())
677 func(code, state, timestamp, ecore_dev);
679 func(code, state, timestamp, e_dev);
684 xkb_state_update_key(edev->xkb.state, code,
685 (state ? XKB_KEY_DOWN : XKB_KEY_UP));
687 /* get the keysym for this code */
688 nsyms = xkb_key_get_syms(edev->xkb.state, code, &syms);
690 if (nsyms == 1) sym = syms[0];
692 /* If no keysym was found, name it "Keycode-NNN" */
693 if (sym == XKB_KEY_NoSymbol)
694 snprintf(key, sizeof(key), "Keycode-%u", code);
697 /* get the keyname for this sym */
698 xkb_keysym_get_name(sym, key, sizeof(key));
703 /* If no keyname was found, name it "Keycode-NNN" */
704 snprintf(keyname, sizeof(keyname), "Keycode-%u", code);
708 memcpy(keyname, key, sizeof(keyname));
711 /* if shift is active, we need to transform the key to lower */
712 if (xkb_state_mod_index_is_active(edev->xkb.state,
713 xkb_map_mod_get_index(edev->xkb.keymap,
715 XKB_STATE_MODS_EFFECTIVE))
717 if (keyname[0] != '\0')
718 keyname[0] = tolower(keyname[0]);
721 if (_device_keysym_translate(sym, edev->xkb.modifiers,
722 compose_buffer, sizeof(compose_buffer)))
724 compose = eina_str_convert("ISO8859-1", "UTF-8", compose_buffer);
727 ERR("E Input cannot convert input key string '%s' to UTF-8. "
728 "Is Eina built with iconv support?", compose_buffer);
734 if (!compose) compose = compose_buffer;
736 e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) +
737 ((compose[0] != '\0') ? strlen(compose) : 0) + 3);
743 key_data = E_NEW(E_Keyrouter_Event_Data, 1);
751 e->keyname = (char *)(e + 1);
752 e->key = e->keyname + strlen(keyname) + 1;
753 e->compose = strlen(compose) ? e->key + strlen(key) + 1 : NULL;
754 e->string = e->compose;
756 strncpy((char *)e->keyname, keyname, strlen(keyname));
757 strncpy((char *)e->key, key, strlen(key));
758 if (strlen(compose)) strncpy((char *)e->compose, compose, strlen(compose));
760 e->window = (Ecore_Window)input->dev->window;
761 e->event_window = (Ecore_Window)input->dev->window;
762 e->root_window = (Ecore_Window)input->dev->window;
763 e->timestamp = timestamp;
768 _device_modifiers_update(edev);
770 e->modifiers = edev->xkb.modifiers;
772 comp_conf = e_comp_config_get();
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);
777 if (e_config->key_input_ttrace_enable)
779 TRACE_INPUT_BEGIN(ECORE_EVENT_KEY:%s:%s:%u:%lld, state ? "PRESS" : "RELEASE", e->keyname, timestamp, (long long unsigned int)libinput_event_keyboard_get_time_usec(event));
780 ELOGF("INPUT", "ECORE_EVENT_KEY:%s:%s:%u:%lld|B|", NULL, state ? "PRESS" : "RELEASE", e->keyname, timestamp, (long long unsigned int)libinput_event_keyboard_get_time_usec(event));
783 _e_input_key_event_list_add(e);
785 if (e_input_thread_mode_get())
787 e->dev = (Eo *)g_object_ref(e_dev);
788 e_input_event_add(input->event_source, state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
792 e->dev = ecore_device_ref(ecore_dev);
793 ecore_event_add(state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
796 if (e_config->key_input_ttrace_enable)
799 ELOGF("INPUT", "ECORE_EVENT_KEY|E|", NULL);
806 _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event)
808 E_Input_Backend *input;
809 Ecore_Event_Mouse_Move *ev;
810 Ecore_Device *ecore_dev = NULL, *data, *detent_data = NULL;
812 int x = 0, y = 0, w = 0, h = 0;
814 if (!(input = edev->seat->input)) return;
816 ecore_thread_main_loop_begin();
818 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
819 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
821 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
823 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
828 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
833 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
835 ecore_dev = detent_data;
840 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
841 ecore_dev = edev->ecore_dev;
846 ERR("Failed to get source ecore device from event !\n");
849 else if ((detent_data == ecore_dev) || e_devicemgr_detent_is_detent(ecore_device_name_get(ecore_dev)))
851 /* Do not process detent device's move events. */
855 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
857 _device_configured_size_get(edev, &x, &y, &w, &h);
859 if (edev->seat->ptr.ix < x)
860 edev->seat->ptr.dx = edev->seat->ptr.ix = x;
861 else if (edev->seat->ptr.ix >= (x + w))
862 edev->seat->ptr.dx = edev->seat->ptr.ix = (x + w - 1);
864 if (edev->seat->ptr.iy < y)
865 edev->seat->ptr.dy = edev->seat->ptr.iy = y;
866 else if (edev->seat->ptr.iy >= (y + h))
867 edev->seat->ptr.dy = edev->seat->ptr.iy = (y + h - 1);
869 edev->mouse.dx = edev->seat->ptr.dx;
870 edev->mouse.dy = edev->seat->ptr.dy;
872 ev->window = (Ecore_Window)input->dev->window;
873 ev->event_window = (Ecore_Window)input->dev->window;
874 ev->root_window = (Ecore_Window)input->dev->window;
875 if (event) ev->timestamp = libinput_event_pointer_get_time(event);
878 _device_modifiers_update(edev);
879 ev->modifiers = edev->xkb.modifiers;
881 ev->x = edev->seat->ptr.ix;
882 ev->y = edev->seat->ptr.iy;
886 ev->multi.device = edev->mt_slot;
887 ev->multi.radius = 1;
888 ev->multi.radius_x = 1;
889 ev->multi.radius_y = 1;
890 ev->multi.pressure = 1.0;
891 ev->multi.angle = 0.0;
894 ev->multi.root.x = ev->x;
895 ev->multi.root.y = ev->y;
897 ev->dev = ecore_device_ref(ecore_dev);
899 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
902 ecore_thread_main_loop_end();
906 _e_input_pointer_motion_post(E_Input_Evdev *edev)
908 _device_pointer_motion(edev, NULL);
912 _device_pointer_relative_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event, double dx[2], double dy[2])
914 E_Input_Backend *input;
915 Ecore_Event_Mouse_Relative_Move *ev;
916 Ecore_Device *ecore_dev = NULL, *data, *detent_data = NULL;
918 E_Comp_Config *comp_conf;
920 if (!(input = edev->seat->input)) return;
922 ecore_thread_main_loop_begin();
924 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
925 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
927 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
929 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
934 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
939 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
941 ecore_dev = detent_data;
946 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
947 ecore_dev = edev->ecore_dev;
952 ERR("Failed to get source ecore device from event !\n");
955 else if ((detent_data == ecore_dev) || e_devicemgr_detent_is_detent(ecore_device_name_get(ecore_dev)))
957 /* Do not process detent device's move events. */
961 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Relative_Move)))) return;
963 ev->window = (Ecore_Window)input->dev->window;
964 ev->event_window = (Ecore_Window)input->dev->window;
965 if (event) ev->timestamp = libinput_event_pointer_get_time(event);
967 ev->modifiers = edev->xkb.modifiers;
971 ev->dx_unaccel = (int)dx[1];
972 ev->dy_unaccel = (int)dy[1];
974 ev->dev = ecore_device_ref(ecore_dev);
976 comp_conf = e_comp_config_get();
977 if (comp_conf && comp_conf->input_log_enable)
978 ELOGF("Mouse", "Relative Move (time: %d, dx: %d, dy: %d, unaccel(%d, %d) device: %s)", NULL, ev->timestamp, ev->dx, ev->dy, ev->dx_unaccel, ev->dy_unaccel, ecore_device_name_get(ev->dev));
980 ecore_event_add(ECORE_EVENT_MOUSE_RELATIVE_MOVE, ev, _e_input_event_mouse_relative_move_cb_free, NULL);
983 ecore_thread_main_loop_end();
987 _device_pointer_motion_send(E_Input_Evdev *edev, struct libinput_event_pointer *event, double dx[2], double dy[2])
989 e_input_relative_motion_cb func = e_input_relative_motion_handler_get();
992 //func(dx, dy, time_us);
993 _device_pointer_relative_motion(edev, event, dx, dy);
997 double seat_dx, seat_dy, temp;
998 if (edev->disable_acceleration)
1009 if (edev->seat->ptr.swap)
1015 if (edev->seat->ptr.invert_x)
1017 if (edev->seat->ptr.invert_y)
1020 edev->seat->ptr.dx += seat_dx;
1021 edev->seat->ptr.dy += seat_dy;
1023 edev->mouse.dx = edev->seat->ptr.dx;
1024 edev->mouse.dy = edev->seat->ptr.dy;
1026 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
1027 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
1032 edev->seat->ptr.ix = edev->seat->ptr.dx;
1033 edev->seat->ptr.iy = edev->seat->ptr.dy;
1035 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1036 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1041 _device_pointer_motion(edev, event);
1046 _device_handle_pointer_motion(struct libinput_device *device, struct libinput_event_pointer *event)
1048 E_Input_Evdev *edev;
1049 double delta_x[2]; /* delta_x[0] for accelerated, delta_x[1] for unaccelerated */
1050 double delta_y[2]; /* delta_y[0] for accelerated, delta_y[1] for unaccelerated */
1052 if (!(edev = libinput_device_get_user_data(device)))
1057 delta_x[0] = libinput_event_pointer_get_dx(event);
1058 delta_x[1] = libinput_event_pointer_get_dx_unaccelerated(event);
1059 delta_y[0] = libinput_event_pointer_get_dy(event);
1060 delta_y[1] = libinput_event_pointer_get_dy_unaccelerated(event);
1062 _device_pointer_motion_send(edev, event, &delta_x[0], &delta_y[0]);
1066 _device_handle_pointer_motion_absolute(struct libinput_device *device, struct libinput_event_pointer *event)
1068 E_Input_Evdev *edev;
1071 if (!(edev = libinput_device_get_user_data(device)))
1076 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
1078 edev->mouse.dx = edev->seat->ptr.dx =
1079 libinput_event_pointer_get_absolute_x_transformed(event, w);
1080 edev->mouse.dy = edev->seat->ptr.dy =
1081 libinput_event_pointer_get_absolute_y_transformed(event, h);
1083 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
1084 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
1089 edev->seat->ptr.ix = edev->seat->ptr.dx;
1090 edev->seat->ptr.iy = edev->seat->ptr.dy;
1092 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1093 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1098 _device_pointer_motion(edev, event);
1102 _device_handle_button(struct libinput_device *device, struct libinput_event_pointer *event)
1104 E_Input_Evdev *edev;
1105 E_Input_Backend *input;
1106 Ecore_Event_Mouse_Button *ev;
1107 enum libinput_button_state state;
1108 uint32_t button, timestamp;
1109 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1111 E_Comp_Config *comp_conf = NULL;
1113 if (!(edev = libinput_device_get_user_data(device)))
1117 if (!(input = edev->seat->input))
1122 ecore_thread_main_loop_begin();
1124 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1125 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1127 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1129 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1134 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1139 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1141 ecore_dev = detent_data;
1146 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1147 ecore_dev = edev->ecore_dev;
1152 ERR("Failed to get source ecore device from event !\n");
1156 state = libinput_event_pointer_get_button_state(event);
1157 button = libinput_event_pointer_get_button(event);
1158 timestamp = libinput_event_pointer_get_time(event);
1160 button = ((button & 0x00F) + 1);
1161 if (button == 3) button = 2;
1162 else if (button == 2) button = 3;
1164 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
1168 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1169 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1172 ELOGF("Mouse", "Button Press (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
1173 button, ecore_device_name_get(ecore_dev), blocked_client,
1174 edev->seat->dev->server_blocked);
1179 edev->mouse.pressed_button |= (1 << button);
1184 if (!(edev->mouse.pressed_button & (1 << button)))
1186 ELOGF("Mouse", "Button Release (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
1187 button, ecore_device_name_get(ecore_dev), blocked_client,
1188 edev->seat->dev->server_blocked);
1191 edev->mouse.pressed_button &= ~(1 << button);
1194 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button))))
1199 ev->window = (Ecore_Window)input->dev->window;
1200 ev->event_window = (Ecore_Window)input->dev->window;
1201 ev->root_window = (Ecore_Window)input->dev->window;
1202 ev->timestamp = timestamp;
1203 ev->same_screen = 1;
1205 _device_modifiers_update(edev);
1206 ev->modifiers = edev->xkb.modifiers;
1208 ev->x = edev->seat->ptr.ix;
1209 ev->y = edev->seat->ptr.iy;
1213 ev->multi.device = edev->mt_slot;
1214 ev->multi.radius = 1;
1215 ev->multi.radius_x = 1;
1216 ev->multi.radius_y = 1;
1217 ev->multi.pressure = 1.0;
1218 ev->multi.angle = 0.0;
1219 ev->multi.x = ev->x;
1220 ev->multi.y = ev->y;
1221 ev->multi.root.x = ev->x;
1222 ev->multi.root.y = ev->y;
1223 ev->dev = ecore_device_ref(ecore_dev);
1227 unsigned int current;
1229 current = timestamp;
1230 edev->mouse.did_double = EINA_FALSE;
1231 edev->mouse.did_triple = EINA_FALSE;
1233 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1234 (button == edev->mouse.prev_button))
1236 edev->mouse.did_double = EINA_TRUE;
1237 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1238 (button == edev->mouse.last_button))
1240 edev->mouse.did_triple = EINA_TRUE;
1241 edev->mouse.prev = 0;
1242 edev->mouse.last = 0;
1247 edev->mouse.last = edev->mouse.prev;
1248 edev->mouse.prev = current;
1249 edev->mouse.last_button = edev->mouse.prev_button;
1250 edev->mouse.prev_button = button;
1253 ev->buttons = button;
1255 if (edev->mouse.did_double)
1256 ev->double_click = 1;
1257 if (edev->mouse.did_triple)
1258 ev->triple_click = 1;
1260 comp_conf = e_comp_config_get();
1261 if (comp_conf && comp_conf->input_log_enable)
1262 ELOGF("Mouse", "Button %s (btn: %d, device: %s)", NULL, state?"Press":"Release", button, ecore_device_name_get(ev->dev));
1265 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, _e_input_event_mouse_button_cb_free, NULL);
1267 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, _e_input_event_mouse_button_cb_free, NULL);
1270 ecore_thread_main_loop_end();
1273 #if !LIBINPUT_HAVE_SCROLL_VALUE_V120
1275 _axis_value_get(struct libinput_event_pointer *pointer_event, enum libinput_pointer_axis axis)
1277 enum libinput_pointer_axis_source source;
1278 double value = 0.0, value_discrete = 0.0;
1280 E_Comp_Config *comp_conf = NULL;
1282 comp_conf = e_comp_config_get();
1283 source = libinput_event_pointer_get_axis_source(pointer_event);
1286 case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL:
1287 value_discrete = libinput_event_pointer_get_axis_value_discrete(pointer_event, axis);
1288 value = libinput_event_pointer_get_axis_value(pointer_event, axis);
1289 if (comp_conf && comp_conf->input_log_enable)
1291 ELOGF("Axis", "SOURCE_WHEEL discrete: %lf (cf. value: %lf)", NULL, value_discrete, value);
1293 ret = (int)value_discrete;
1295 case LIBINPUT_POINTER_AXIS_SOURCE_FINGER:
1296 case LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS:
1297 value = libinput_event_pointer_get_axis_value(pointer_event, axis);
1298 if (comp_conf && comp_conf->input_log_enable)
1300 ELOGF("Axis", "SOURCE_FINGER/CONTINUOUS value: %lf", NULL, value);
1302 if (value >= E_INPUT_FINGER_SCROLL_THRESHOLD)
1304 else if (value <= E_INPUT_FINGER_SCROLL_THRESHOLD * (-1))
1317 _device_handle_axis(struct libinput_device *device, struct libinput_event_pointer *event)
1319 E_Input_Evdev *edev;
1320 E_Input_Backend *input;
1321 Ecore_Event_Mouse_Wheel *ev;
1323 enum libinput_pointer_axis axis;
1324 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1326 E_Comp_Config *comp_conf = NULL;
1327 int direction = 0, z = 0;
1329 if (!(edev = libinput_device_get_user_data(device)))
1333 if (!(input = edev->seat->input))
1338 ecore_thread_main_loop_begin();
1340 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1341 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1343 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1345 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1350 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1355 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1357 ecore_dev = detent_data;
1362 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1363 ecore_dev = edev->ecore_dev;
1368 ERR("Failed to get source ecore device from event !\n");
1372 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1373 if (libinput_event_pointer_has_axis(event, axis))
1374 z = _axis_value_get(event, axis);
1376 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1377 if (libinput_event_pointer_has_axis(event, axis))
1380 z = _axis_value_get(event, axis);
1385 ELOGF("Mouse", "Axis event is ignored since it has zero value", NULL);
1389 comp_conf = e_comp_config_get();
1390 if (comp_conf && comp_conf->e_wheel_click_angle)
1392 z = (int)(z * comp_conf->e_wheel_click_angle);
1395 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1396 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1398 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
1401 ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1402 direction, z, blocked_client, edev->seat->dev->server_blocked);
1404 ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1405 direction, z, blocked_client, edev->seat->dev->server_blocked);
1410 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1415 timestamp = libinput_event_pointer_get_time(event);
1417 ev->window = (Ecore_Window)input->dev->window;
1418 ev->event_window = (Ecore_Window)input->dev->window;
1419 ev->root_window = (Ecore_Window)input->dev->window;
1420 ev->timestamp = timestamp;
1421 ev->same_screen = 1;
1423 _device_modifiers_update(edev);
1424 ev->modifiers = edev->xkb.modifiers;
1426 ev->x = edev->seat->ptr.ix;
1427 ev->y = edev->seat->ptr.iy;
1431 ev->direction = direction;
1433 if (comp_conf && comp_conf->input_log_enable)
1436 ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1438 ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1442 ev->dev = ecore_device_ref(ecore_dev);
1443 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1446 ecore_thread_main_loop_end();
1450 #if LIBINPUT_HAVE_SCROLL_VALUE_V120
1452 _scroll_value_get(struct libinput_event_pointer *pointer_event, enum libinput_pointer_axis axis, E_Input_Axis_Source source)
1455 double value_v120 = 0.0;
1457 E_Comp_Config *comp_conf = NULL;
1459 comp_conf = e_comp_config_get();
1462 case E_INPUT_AXIS_SOURCE_WHEEL:
1463 value_v120 = libinput_event_pointer_get_scroll_value_v120(pointer_event, axis);
1464 value = libinput_event_pointer_get_scroll_value(pointer_event, axis);
1465 if (comp_conf && comp_conf->input_log_enable)
1467 ELOGF("Scroll", "SOURCE_WHEEL value_v120: %lf (cf. value: %lf)", NULL, value_v120, value);
1469 if (((int)value_v120 % E_INPUT_POINTER_AXIS_DISCRETE_STEP) != 0)
1471 ERR("Wheel movements should be multiples (or fractions) of 120!\n");
1476 ret = value_v120 / E_INPUT_POINTER_AXIS_DISCRETE_STEP;
1479 case E_INPUT_AXIS_SOURCE_FINGER:
1480 case E_INPUT_AXIS_SOURCE_CONTINUOUS:
1481 value = libinput_event_pointer_get_scroll_value(pointer_event, axis);
1482 if (comp_conf && comp_conf->input_log_enable)
1484 ELOGF("Scroll", "SOURCE_FINGER/CONTINUOUS value: %lf", NULL, value);
1486 if (value >= E_INPUT_FINGER_SCROLL_THRESHOLD)
1488 else if (value <= E_INPUT_FINGER_SCROLL_THRESHOLD * (-1))
1501 _device_handle_axis_v120(struct libinput_device *device, struct libinput_event_pointer *event, E_Input_Axis_Source source)
1503 E_Input_Evdev *edev;
1504 E_Input_Backend *input;
1505 Ecore_Event_Mouse_Wheel *ev;
1507 enum libinput_pointer_axis axis;
1508 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1510 E_Comp_Config *comp_conf = NULL;
1511 int direction = 0, z = 0;
1513 if (!(edev = libinput_device_get_user_data(device)))
1517 if (!(input = edev->seat->input))
1522 ecore_thread_main_loop_begin();
1524 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1525 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1527 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1529 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1534 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1539 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1541 ecore_dev = detent_data;
1546 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1547 ecore_dev = edev->ecore_dev;
1552 ERR("Failed to get source ecore device from event !\n");
1556 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1557 if (libinput_event_pointer_has_axis(event, axis))
1558 z = _scroll_value_get(event, axis, source);
1560 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1561 if (libinput_event_pointer_has_axis(event, axis))
1564 z = _scroll_value_get(event, axis, source);
1569 ELOGF("Mouse", "Scroll event is ignored since it has zero value", NULL);
1573 comp_conf = e_comp_config_get();
1574 if (comp_conf && comp_conf->e_wheel_click_angle)
1576 z = (int)(z * comp_conf->e_wheel_click_angle);
1579 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1580 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1582 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
1584 ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1585 direction, z, blocked_client, edev->seat->dev->server_blocked);
1587 ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1588 direction, z, blocked_client, edev->seat->dev->server_blocked);
1593 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1598 timestamp = libinput_event_pointer_get_time(event);
1600 ev->window = (Ecore_Window)input->dev->window;
1601 ev->event_window = (Ecore_Window)input->dev->window;
1602 ev->root_window = (Ecore_Window)input->dev->window;
1603 ev->timestamp = timestamp;
1604 ev->same_screen = 1;
1606 _device_modifiers_update(edev);
1607 ev->modifiers = edev->xkb.modifiers;
1609 ev->x = edev->seat->ptr.ix;
1610 ev->y = edev->seat->ptr.iy;
1614 ev->direction = direction;
1616 if (comp_conf && comp_conf->input_log_enable)
1619 ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1621 ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1624 ev->dev = ecore_device_ref(ecore_dev);
1625 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1628 ecore_thread_main_loop_end();
1633 _device_handle_touch_event_send(E_Input_Evdev *edev, struct libinput_event_touch *event, int state)
1635 E_Input_Backend *input;
1636 Ecore_Event_Mouse_Button *ev;
1637 uint32_t timestamp, button = 0;
1638 Ecore_Device *ecore_dev = NULL, *data;
1642 if (!(input = edev->seat->input)) return;
1644 ecore_thread_main_loop_begin();
1646 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1647 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1649 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1651 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1660 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1661 ecore_dev = edev->ecore_dev;
1666 ERR("Failed to get source ecore device from event !\n");
1670 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) goto end;
1672 timestamp = libinput_event_touch_get_time(event);
1674 ev->window = (Ecore_Window)input->dev->window;
1675 ev->event_window = (Ecore_Window)input->dev->window;
1676 ev->root_window = (Ecore_Window)input->dev->window;
1677 ev->timestamp = timestamp;
1678 ev->same_screen = 1;
1680 _device_modifiers_update(edev);
1681 ev->modifiers = edev->xkb.modifiers;
1683 ev->x = edev->seat->ptr.ix;
1684 ev->y = edev->seat->ptr.iy;
1688 ev->multi.device = edev->mt_slot;
1689 ev->multi.radius = 1;
1690 ev->multi.radius_x = 1;
1691 ev->multi.radius_y = 1;
1692 ev->multi.pressure = 1.0;
1693 ev->multi.angle = 0.0;
1694 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1695 if (libinput_event_get_type(libinput_event_touch_get_base_event(event))
1696 == LIBINPUT_EVENT_TOUCH_DOWN)
1698 if (libinput_event_touch_has_minor(event))
1699 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1700 if (libinput_event_touch_has_major(event))
1701 ev->multi.radius_y = libinput_event_touch_get_major(event);
1702 if (libinput_event_touch_has_pressure(event))
1703 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1704 if (libinput_event_touch_has_orientation(event))
1705 ev->multi.angle = libinput_event_touch_get_orientation(event);
1708 ev->multi.x = ev->x;
1709 ev->multi.y = ev->y;
1710 ev->multi.root.x = ev->x;
1711 ev->multi.root.y = ev->y;
1712 ev->dev = ecore_device_ref(ecore_dev);
1714 if (state == ECORE_EVENT_MOUSE_BUTTON_DOWN)
1716 unsigned int current;
1718 current = timestamp;
1719 edev->mouse.did_double = EINA_FALSE;
1720 edev->mouse.did_triple = EINA_FALSE;
1722 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1723 (button == edev->mouse.prev_button))
1725 edev->mouse.did_double = EINA_TRUE;
1726 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1727 (button == edev->mouse.last_button))
1729 edev->mouse.did_triple = EINA_TRUE;
1730 edev->mouse.prev = 0;
1731 edev->mouse.last = 0;
1736 edev->mouse.last = edev->mouse.prev;
1737 edev->mouse.prev = current;
1738 edev->mouse.last_button = edev->mouse.prev_button;
1739 edev->mouse.prev_button = button;
1740 edev->touch.pressed |= (1 << ev->multi.device);
1744 edev->touch.pressed &= ~(1 << ev->multi.device);
1747 ev->buttons = ((button & 0x00F) + 1);
1749 if (edev->mouse.did_double)
1750 ev->double_click = 1;
1751 if (edev->mouse.did_triple)
1752 ev->triple_click = 1;
1754 ecore_event_add(state, ev, _e_input_event_mouse_button_cb_free, NULL);
1757 ecore_thread_main_loop_end();
1761 _device_handle_touch_motion_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1763 E_Input_Backend *input;
1764 Ecore_Event_Mouse_Move *ev;
1765 Ecore_Device *ecore_dev = NULL, *data;
1769 if (!(input = edev->seat->input)) return;
1771 ecore_thread_main_loop_begin();
1773 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1774 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1776 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1778 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1787 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1788 ecore_dev = edev->ecore_dev;
1793 ERR("Failed to get source ecore device from event !\n");
1797 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) goto end;
1799 ev->window = (Ecore_Window)input->dev->window;
1800 ev->event_window = (Ecore_Window)input->dev->window;
1801 ev->root_window = (Ecore_Window)input->dev->window;
1802 ev->timestamp = libinput_event_touch_get_time(event);
1803 ev->same_screen = 1;
1805 _device_modifiers_update(edev);
1806 ev->modifiers = edev->xkb.modifiers;
1808 ev->x = edev->seat->ptr.ix;
1809 ev->y = edev->seat->ptr.iy;
1813 ev->multi.device = edev->mt_slot;
1814 ev->multi.radius = 1;
1815 ev->multi.radius_x = 1;
1816 ev->multi.radius_y = 1;
1817 ev->multi.pressure = 1.0;
1818 ev->multi.angle = 0.0;
1819 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1820 if (libinput_event_touch_has_minor(event))
1821 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1822 if (libinput_event_touch_has_major(event))
1823 ev->multi.radius_y = libinput_event_touch_get_major(event);
1824 if (libinput_event_touch_has_pressure(event))
1825 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1826 if (libinput_event_touch_has_orientation(event))
1827 ev->multi.angle = libinput_event_touch_get_orientation(event);
1829 ev->multi.x = ev->x;
1830 ev->multi.y = ev->y;
1831 ev->multi.root.x = ev->x;
1832 ev->multi.root.y = ev->y;
1833 ev->dev = ecore_device_ref(ecore_dev);
1835 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
1838 ecore_thread_main_loop_end();
1842 _device_handle_touch_cancel_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1844 E_Input_Backend *input;
1845 Ecore_Event_Mouse_Button *ev;
1846 uint32_t timestamp, button = 0;
1847 Ecore_Device *ecore_dev = NULL, *data;
1851 if (!(input = edev->seat->input)) return;
1853 ecore_thread_main_loop_begin();
1855 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1856 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1858 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1860 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1869 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1870 ecore_dev = edev->ecore_dev;
1875 ERR("Failed to get source ecore device from event !\n");
1879 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) goto end;
1881 timestamp = libinput_event_touch_get_time(event);
1883 ev->window = (Ecore_Window)input->dev->window;
1884 ev->event_window = (Ecore_Window)input->dev->window;
1885 ev->root_window = (Ecore_Window)input->dev->window;
1886 ev->timestamp = timestamp;
1887 ev->same_screen = 1;
1889 ev->x = edev->seat->ptr.ix;
1890 ev->y = edev->seat->ptr.iy;
1894 ev->multi.device = edev->mt_slot;
1895 ev->multi.radius = 1;
1896 ev->multi.radius_x = 1;
1897 ev->multi.radius_y = 1;
1898 ev->multi.pressure = 1.0;
1899 ev->multi.angle = 0.0;
1900 ev->multi.x = ev->x;
1901 ev->multi.y = ev->y;
1902 ev->multi.root.x = ev->x;
1903 ev->multi.root.y = ev->y;
1905 edev->touch.pressed &= ~(1 << ev->multi.device);
1907 ev->buttons = ((button & 0x00F) + 1);
1908 ev->dev = ecore_device_ref(ecore_dev);
1910 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev, _e_input_event_mouse_button_cb_free, NULL);
1913 ecore_thread_main_loop_end();
1917 _device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, int *w, int *h)
1919 E_Output *output = NULL;
1921 EINA_SAFETY_ON_NULL_RETURN(edev);
1923 if (!edev->output_configured)
1925 if (edev->output_name)
1927 output = e_output_find(edev->output_name);
1930 edev->mouse.minx = output->config.geom.x;
1931 edev->mouse.miny = output->config.geom.y;
1932 edev->mouse.maxw = output->config.geom.w;
1933 edev->mouse.maxh = output->config.geom.h;
1934 if (edev->caps & E_INPUT_SEAT_POINTER)
1936 edev->seat->ptr.dx = (double)(edev->mouse.maxw / 2);
1937 edev->seat->ptr.dy = (double)(edev->mouse.maxh / 2);
1938 edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
1939 edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
1940 edev->mouse.dx = edev->seat->ptr.dx;
1941 edev->mouse.dy = edev->seat->ptr.dy;
1946 edev->output_configured = EINA_TRUE;
1947 ELOGF("E_INPUT_EVDEV", "Device is configured by output x:%d,y:%d (w:%d, h:%d)",
1948 NULL, edev->mouse.minx, edev->mouse.miny, edev->mouse.maxw, edev->mouse.maxh);
1950 if (x) *x = edev->mouse.minx;
1951 if (y) *y = edev->mouse.miny;
1952 if (w) *w = edev->mouse.maxw;
1953 if (h) *h = edev->mouse.maxh;
1957 _device_handle_touch_down(struct libinput_device *device, struct libinput_event_touch *event)
1959 E_Input_Evdev *edev;
1960 int x = 0, y = 0, w = 0, h = 0;
1961 E_Comp_Config *comp_conf = NULL;
1963 if (!(edev = libinput_device_get_user_data(device)))
1968 _device_configured_size_get(edev, &x, &y, &w, &h);
1970 edev->mouse.dx = edev->seat->ptr.ix = edev->seat->ptr.dx =
1971 x + libinput_event_touch_get_x_transformed(event, w);
1972 edev->mouse.dy = edev->seat->ptr.iy = edev->seat->ptr.dy =
1973 y + libinput_event_touch_get_y_transformed(event, h);
1975 edev->mt_slot = libinput_event_touch_get_slot(event);
1976 if (edev->mt_slot < 0)
1978 /* FIXME: The single touch device return slot id -1
1979 * But currently we have no API to distinguish multi touch or single touch
1980 * After libinput 1.11 version, libinput provides get_touch_count API,
1981 * so we can distinguish multi touch device or single touch device.
1983 if (edev->mt_slot == -1)
1987 WRN("%d slot touch down events are not supported\n", edev->mt_slot);
1992 if (edev->mt_slot < e_input_touch_max_count_get())
1994 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
1995 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
1998 comp_conf = e_comp_config_get();
1999 if (comp_conf && comp_conf->input_log_enable)
2000 ELOGF("Touch", "Down (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2002 atomic_fetch_or(&edev->touch.raw_pressed, (1 << edev->mt_slot));
2004 if (edev->touch.blocked)
2006 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
2007 ELOGF("Touch", "Down (id: %d, x: %d, y: %d) is blocked by %p, server: 0x%x", NULL,
2008 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, blocked_client,
2009 edev->seat->dev->server_blocked);
2013 _device_handle_touch_motion_send(edev, event);
2014 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_DOWN);
2018 _device_handle_touch_motion(struct libinput_device *device, struct libinput_event_touch *event)
2020 E_Input_Evdev *edev;
2021 int x = 0, y = 0, w = 0, h = 0;
2023 if (!(edev = libinput_device_get_user_data(device)))
2028 _device_configured_size_get(edev, &x, &y, &w, &h);
2030 edev->mouse.dx = edev->seat->ptr.dx =
2031 x + libinput_event_touch_get_x_transformed(event, w);
2032 edev->mouse.dy = edev->seat->ptr.dy =
2033 y + libinput_event_touch_get_y_transformed(event, h);
2035 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
2036 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
2041 edev->seat->ptr.ix = edev->seat->ptr.dx;
2042 edev->seat->ptr.iy = edev->seat->ptr.dy;
2044 edev->mt_slot = libinput_event_touch_get_slot(event);
2045 if (edev->mt_slot < 0)
2047 /* FIXME: The single touch device return slot id -1
2048 * But currently we have no API to distinguish multi touch or single touch
2049 * After libinput 1.11 version, libinput provides get_touch_count API,
2050 * so we can distinguish multi touch device or single touch device.
2052 if (edev->mt_slot == -1)
2056 WRN("%d slot touch motion events are not supported\n", edev->mt_slot);
2061 if (edev->mt_slot < e_input_touch_max_count_get())
2063 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
2064 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
2067 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
2069 if (edev->touch.blocked)
2075 _device_handle_touch_motion_send(edev, event);
2079 _device_handle_touch_up(struct libinput_device *device, struct libinput_event_touch *event)
2081 E_Input_Evdev *edev;
2082 E_Comp_Config *comp_conf = NULL;
2084 if (!(edev = libinput_device_get_user_data(device)))
2089 edev->mt_slot = libinput_event_touch_get_slot(event);
2090 if (edev->mt_slot < 0)
2092 /* FIXME: The single touch device return slot id -1
2093 * But currently we have no API to distinguish multi touch or single touch
2094 * After libinput 1.11 version, libinput provides get_touch_count API,
2095 * so we can distinguish multi touch device or single touch device.
2097 if (edev->mt_slot == -1)
2101 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
2106 if (edev->mt_slot < e_input_touch_max_count_get())
2108 edev->mouse.dx = edev->seat->ptr.dx = edev->seat->ptr.ix =
2109 edev->touch.coords[edev->mt_slot].x;
2110 edev->mouse.dy = edev->seat->ptr.dy = edev->seat->ptr.iy =
2111 edev->touch.coords[edev->mt_slot].y;
2114 comp_conf = e_comp_config_get();
2115 if (comp_conf && comp_conf->input_log_enable)
2116 ELOGF("Touch", "Up (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2118 atomic_fetch_and(&edev->touch.raw_pressed, ~(1 << edev->mt_slot));
2120 if (edev->touch.blocked)
2122 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
2124 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
2125 ELOGF("Touch", "Up (id: %d, x: %d, y: %d) is blocked by %p, server(0x%x)", NULL,
2126 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, blocked_client,
2127 edev->seat->dev->server_blocked);
2129 if (edev->touch.raw_pressed == 0x0)
2131 edev->touch.blocked = EINA_FALSE;
2137 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_UP);
2141 _device_handle_touch_cancel(struct libinput_device *device, struct libinput_event_touch *event)
2143 E_Input_Evdev *edev;
2144 E_Comp_Config *comp_conf = NULL;
2146 if (!(edev = libinput_device_get_user_data(device)))
2151 edev->mt_slot = libinput_event_touch_get_slot(event);
2152 if (edev->mt_slot < 0)
2154 /* FIXME: The single touch device return slot id -1
2155 * But currently we have no API to distinguish multi touch or single touch
2156 * After libinput 1.11 version, libinput provides get_touch_count API,
2157 * so we can distinguish multi touch device or single touch device.
2159 if (edev->mt_slot == -1)
2163 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
2168 comp_conf = e_comp_config_get();
2169 if (comp_conf && comp_conf->input_log_enable)
2170 ELOGF("Touch", "cancel (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2172 _device_handle_touch_cancel_send(edev, event);
2177 _device_handle_touch_frame(struct libinput_device *device EINA_UNUSED, struct libinput_event_touch *event EINA_UNUSED)
2179 /* DBG("Unhandled Touch Frame Event"); */
2183 _e_input_aux_data_event_free(void *user_data EINA_UNUSED, void *ev)
2185 Ecore_Event_Axis_Update *e = (Ecore_Event_Axis_Update *)ev;
2187 if (e->axis) free(e->axis);
2188 if (e->dev) ecore_device_unref(e->dev);
2194 _device_handle_touch_aux_data(struct libinput_device *device, struct libinput_event_touch_aux_data *event)
2196 E_Input_Evdev *edev;
2197 E_Input_Backend *input;
2198 Ecore_Event_Axis_Update *ev;
2200 Ecore_Device *ecore_dev = NULL, *data;
2202 E_Comp_Config *comp_conf;
2204 ecore_thread_main_loop_begin();
2206 if (libinput_event_touch_aux_data_get_type(event) != LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM &&
2207 libinput_event_touch_aux_data_get_value(event) > 0)
2210 if (!(edev = libinput_device_get_user_data(device))) goto end;
2211 if (!(input = edev->seat->input)) goto end;
2213 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
2214 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
2216 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
2218 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
2227 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
2228 ecore_dev = edev->ecore_dev;
2233 ERR("Failed to get source ecore device from event !\n");
2237 if (!(ev = calloc(1, sizeof(Ecore_Event_Axis_Update)))) goto end;
2239 ev->window = (Ecore_Window)input->dev->window;
2240 ev->event_window = (Ecore_Window)input->dev->window;
2241 ev->root_window = (Ecore_Window)input->dev->window;
2242 ev->timestamp = libinput_event_touch_aux_data_get_time(event);
2244 axis = (Ecore_Axis *)calloc(1, sizeof(Ecore_Axis));
2247 axis->label = ECORE_AXIS_LABEL_TOUCH_PALM;
2248 axis->value = libinput_event_touch_aux_data_get_value(event);
2253 comp_conf = e_comp_config_get();
2254 if (comp_conf && comp_conf->input_log_enable)
2255 ELOGF("Touch", "Axis (label: %d, value: %lf)", NULL, axis?axis->label:-1, axis?axis->value:0.0);
2257 ev->dev = ecore_device_ref(ecore_dev);
2259 ecore_event_add(ECORE_EVENT_AXIS_UPDATE, ev, _e_input_aux_data_event_free, NULL);
2262 ecore_thread_main_loop_end();
2266 _e_input_evdev_device_create(E_Input_Seat *seat, struct libinput_device *device)
2268 E_Input_Evdev *edev;
2269 E_Input_Backend *b_input;
2270 const char *output_name;
2272 EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
2274 /* try to allocate space for new evdev */
2275 if (!(edev = calloc(1, sizeof(E_Input_Evdev)))) return NULL;
2278 edev->device = device;
2279 edev->path = eina_stringshare_printf("%s/%s", e_input_base_dir_get(), libinput_device_get_sysname(device));
2281 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
2283 edev->caps |= E_INPUT_SEAT_KEYBOARD;
2284 _device_keyboard_setup(edev);
2287 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
2289 edev->caps |= E_INPUT_SEAT_POINTER;
2291 /* TODO: make this configurable */
2292 edev->mouse.threshold = 250;
2294 b_input = seat->input;
2295 if (b_input->left_handed == EINA_TRUE)
2297 if (libinput_device_config_left_handed_set(device, 1) !=
2298 LIBINPUT_CONFIG_STATUS_SUCCESS)
2300 WRN("Failed to set left hand mode about device: %s\n",
2301 libinput_device_get_name(device));
2306 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
2309 edev->caps |= E_INPUT_SEAT_TOUCH;
2310 palm_code = libinput_device_touch_aux_data_get_code(LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM);
2311 if (libinput_device_touch_has_aux_data(device, palm_code))
2313 libinput_device_touch_set_aux_data(device, palm_code);
2316 _device_touch_count_update(edev);
2318 edev->touch.coords = calloc(1, sizeof(E_Input_Coord)*e_input_touch_max_count_get());
2320 if (!edev->touch.coords)
2321 ERR("Failed to allocate memory for touch coords !\n");
2324 output_name = libinput_device_get_output_name(device);
2327 eina_stringshare_replace(&edev->output_name, output_name);
2328 ELOGF("E_INPUT_EVDEV", "Device has output_name:%s", NULL, output_name);
2331 libinput_device_set_user_data(device, edev);
2332 libinput_device_ref(device);
2334 /* configure device */
2335 _device_configure(edev);
2341 _e_input_evdev_device_destroy(E_Input_Evdev *edev)
2344 EINA_SAFETY_ON_NULL_RETURN(edev);
2346 ecore_thread_main_loop_begin();
2348 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
2350 if (edev->xkb.state) xkb_state_unref(edev->xkb.state);
2352 if (edev->xkb.keymap) xkb_map_unref(edev->xkb.keymap);
2355 if (edev->ecore_dev) ecore_device_del(edev->ecore_dev);
2356 if (edev->ecore_dev_list)
2357 EINA_LIST_FREE(edev->ecore_dev_list, dev)
2359 ecore_device_del(dev);
2362 if (edev->e_dev) g_object_unref(edev->e_dev);
2363 if (edev->e_dev_list)
2365 GList *glist = edev->e_dev_list;
2369 e_dev = glist->data;
2370 g_object_unref(e_dev);
2372 glist = g_list_next(glist);
2375 if (edev->path) eina_stringshare_del(edev->path);
2376 if (edev->device) libinput_device_unref(edev->device);
2377 if (edev->key_remap_hash) eina_hash_free(edev->key_remap_hash);
2378 if (edev->touch.coords)
2380 free(edev->touch.coords);
2381 edev->touch.coords = NULL;
2383 eina_stringshare_del(edev->output_name);
2385 ecore_thread_main_loop_end();
2391 _e_input_evdev_event_process(struct libinput_event *event)
2393 struct libinput_device *device;
2394 Eina_Bool ret = EINA_TRUE;
2396 device = libinput_event_get_device(event);
2397 switch (libinput_event_get_type(event))
2399 case LIBINPUT_EVENT_KEYBOARD_KEY:
2400 _device_handle_key(device, libinput_event_get_keyboard_event(event));
2402 case LIBINPUT_EVENT_POINTER_MOTION:
2403 _device_handle_pointer_motion(device,
2404 libinput_event_get_pointer_event(event));
2406 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
2407 _device_handle_pointer_motion_absolute(device,
2408 libinput_event_get_pointer_event(event));
2410 case LIBINPUT_EVENT_POINTER_BUTTON:
2411 _device_handle_button(device, libinput_event_get_pointer_event(event));
2413 case LIBINPUT_EVENT_POINTER_AXIS:
2414 #if !LIBINPUT_HAVE_SCROLL_VALUE_V120
2415 _device_handle_axis(device, libinput_event_get_pointer_event(event));
2418 #if LIBINPUT_HAVE_SCROLL_VALUE_V120
2419 case LIBINPUT_EVENT_POINTER_SCROLL_WHEEL:
2420 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_WHEEL);
2422 case LIBINPUT_EVENT_POINTER_SCROLL_FINGER:
2423 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_FINGER);
2425 case LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS:
2426 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_CONTINUOUS);
2429 case LIBINPUT_EVENT_TOUCH_DOWN:
2430 _device_handle_touch_down(device, libinput_event_get_touch_event(event));
2432 case LIBINPUT_EVENT_TOUCH_MOTION:
2433 _device_handle_touch_motion(device,
2434 libinput_event_get_touch_event(event));
2436 case LIBINPUT_EVENT_TOUCH_UP:
2437 _device_handle_touch_up(device, libinput_event_get_touch_event(event));
2439 case LIBINPUT_EVENT_TOUCH_CANCEL:
2440 _device_handle_touch_cancel(device, libinput_event_get_touch_event(event));
2442 case LIBINPUT_EVENT_TOUCH_FRAME:
2443 _device_handle_touch_frame(device, libinput_event_get_touch_event(event));
2445 case LIBINPUT_EVENT_TOUCH_AUX_DATA:
2446 _device_handle_touch_aux_data(device, libinput_event_get_touch_aux_data(event));
2457 * @brief Set the axis size of the given device.
2459 * @param dev The device to set the axis size to.
2460 * @param w The width of the axis.
2461 * @param h The height of the axis.
2463 * This function sets set the width @p w and height @p h of the axis
2464 * of device @p dev. If @p dev is a relative input device, a width and
2465 * height must set for it. If its absolute set the ioctl correctly, if
2466 * not, unsupported device.
2469 e_input_evdev_axis_size_set(E_Input_Evdev *edev, int w, int h)
2473 enum libinput_config_status status;
2474 struct udev_device *udev_device = NULL;
2476 EINA_SAFETY_ON_NULL_RETURN(edev);
2477 EINA_SAFETY_ON_TRUE_RETURN((w == 0) || (h == 0));
2479 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
2480 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
2483 udev_device = libinput_device_get_udev_device(edev->device);
2486 ERR("no udev_device");
2490 vals = udev_device_get_property_value(udev_device, "WL_CALIBRATION");
2492 (sscanf(vals, "%f %f %f %f %f %f",
2493 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
2496 ELOGF("E_INPUT_EVDEV", "axis_size_set cal[%lf %lf %lf %lf %lf %lf] (%d x %d)",
2497 NULL, cal[0], cal[1], cal[2], cal[3], cal[4], cal[5], w, h);
2503 libinput_device_config_calibration_set_matrix(edev->device, cal);
2505 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
2506 ERR("Failed to apply calibration");
2509 EINTERN const char *
2510 e_input_evdev_name_get(E_Input_Evdev *evdev)
2512 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2513 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2515 return libinput_device_get_name(evdev->device);
2518 EINTERN const char *
2519 e_input_evdev_sysname_get(E_Input_Evdev *evdev)
2521 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2522 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2524 return libinput_device_get_sysname(evdev->device);
2528 e_input_evdev_key_remap_enable(E_Input_Evdev *edev, Eina_Bool enable)
2530 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2531 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2533 edev->key_remap_enabled = enable;
2535 if (enable == EINA_FALSE && edev->key_remap_hash)
2537 eina_hash_free(edev->key_remap_hash);
2538 edev->key_remap_hash = NULL;
2545 e_input_evdev_key_remap_set(E_Input_Evdev *edev, int *from_keys, int *to_keys, int num)
2549 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2550 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2551 EINA_SAFETY_ON_NULL_RETURN_VAL(from_keys, EINA_FALSE);
2552 EINA_SAFETY_ON_NULL_RETURN_VAL(to_keys, EINA_FALSE);
2553 EINA_SAFETY_ON_TRUE_RETURN_VAL(num <= 0, EINA_FALSE);
2554 EINA_SAFETY_ON_TRUE_RETURN_VAL(!edev->key_remap_enabled, EINA_FALSE);
2556 if (edev->key_remap_hash == NULL)
2557 edev->key_remap_hash = eina_hash_int32_new(NULL);
2559 if (edev->key_remap_hash == NULL)
2561 ERR("Failed to set remap key information : creating a hash is failed.");
2565 for (i = 0; i < num ; i++)
2567 if (!from_keys[i] || !to_keys[i])
2569 ERR("Failed to set remap key information : given arguments are invalid.");
2574 for (i = 0; i < num ; i++)
2576 eina_hash_add(edev->key_remap_hash, &from_keys[i], (void *)(intptr_t)to_keys[i]);
2583 e_input_evdev_wheel_click_angle_get(E_Input_Evdev *dev)
2585 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, -1);
2586 return libinput_device_config_scroll_get_wheel_click_angle(dev->device);
2590 e_input_evdev_touch_calibration_set(E_Input_Evdev *edev, float matrix[6])
2592 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2593 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2595 if (!libinput_device_config_calibration_has_matrix(edev->device) ||
2596 !libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_TOUCH))
2599 if (libinput_device_config_calibration_set_matrix(edev->device, matrix) !=
2600 LIBINPUT_CONFIG_STATUS_SUCCESS)
2602 WRN("Failed to set input transformation about device: %s\n",
2603 libinput_device_get_name(edev->device));
2611 e_input_evdev_mouse_accel_speed_set(E_Input_Evdev *edev, double speed)
2613 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2614 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2616 if (!libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
2619 if (!libinput_device_config_accel_is_available(edev->device))
2622 if (libinput_device_config_accel_set_speed(edev->device, speed) !=
2623 LIBINPUT_CONFIG_STATUS_SUCCESS)
2625 WRN("Failed to set mouse accel about device: %s\n",
2626 libinput_device_get_name(edev->device));
2633 EINTERN unsigned int
2634 e_input_evdev_touch_pressed_get(E_Input_Evdev *edev)
2636 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, 0x0);
2638 return edev->touch.pressed;
2642 e_input_evdev_seatname_get(E_Input_Evdev *evdev)
2644 struct libinput_seat *libinput_seat;
2645 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2646 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2648 libinput_seat = libinput_device_get_seat(evdev->device);
2650 return libinput_seat_get_logical_name(libinput_seat);
2654 e_input_evdev_seatname_set(E_Input_Evdev *evdev, const char *seatname)
2656 Eina_Bool res = EINA_FALSE;
2657 E_Input_Backend *input;
2659 EINA_SAFETY_ON_NULL_RETURN_VAL(seatname, EINA_FALSE);
2660 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, EINA_FALSE);
2661 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, EINA_FALSE);
2663 if (libinput_device_set_seat_logical_name(evdev->device, seatname) == 0)
2665 input = evdev->seat->input;
2666 if (!input) return EINA_FALSE;
2668 if (libinput_dispatch(input->libinput) != 0)
2670 ERR("Failed to dispatch libinput events: %m");
2675 /* process pending events */
2676 _input_events_process(input);