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"
14 #define G_LIST_GET_DATA(list) ((list) ? (((GList *)(list))->data) : NULL)
16 static void _device_modifiers_update(E_Input_Evdev *edev);
17 static void _device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, int *w, int *h);
18 static void _device_output_assign(E_Input_Evdev *edev, E_Input_Seat_Capabilities cap);
21 _device_calibration_set(E_Input_Evdev *edev)
26 E_Comp_Config *comp_conf;
28 if (e_comp->e_comp_screen->num_outputs > 1) //multiple outputs
30 comp_conf = e_comp_config_get();
31 if (comp_conf && (comp_conf->input_output_assign_policy == 1)) //use output-assignment policy
33 _device_output_assign(edev, E_INPUT_SEAT_POINTER);
34 _device_output_assign(edev, E_INPUT_SEAT_TOUCH);
38 output = e_comp_screen_primary_output_get(e_comp->e_comp_screen);
39 e_output_size_get(output, &w, &h);
43 edev->mouse.minx = edev->mouse.miny = 0;
47 if (edev->caps & E_INPUT_SEAT_POINTER)
49 edev->seat->ptr.dx = (double)(w / 2);
50 edev->seat->ptr.dy = (double)(h / 2);
51 edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
52 edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
53 edev->mouse.dx = edev->seat->ptr.dx;
54 edev->mouse.dy = edev->seat->ptr.dy;
56 if (output->config.rotation == 90 || output->config.rotation == 270)
58 temp = edev->mouse.minx;
59 edev->mouse.minx = edev->mouse.miny;
60 edev->mouse.miny = temp;
62 temp = edev->mouse.maxw;
63 edev->mouse.maxw = edev->mouse.maxh;
64 edev->mouse.maxh = temp;
70 #ifdef _F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
76 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
77 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
80 sysname = libinput_device_get_sysname(edev->device);
82 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
83 if (eina_list_count(devices) < 1) return;
85 #ifdef _F_E_INPUT_USE_WL_CALIBRATION_
87 enum libinput_config_status status;
89 EINA_LIST_FREE(devices, device)
91 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
93 (sscanf(vals, "%f %f %f %f %f %f",
94 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
101 libinput_device_config_calibration_set_matrix(edev->device, cal);
103 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
104 ERR("Failed to apply calibration");
107 eina_stringshare_del(device);
110 #endif//_F_E_INPUT_USE_WL_CALIBRATION_
111 #endif//_F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
116 _device_output_assign(E_Input_Evdev *edev, E_Input_Seat_Capabilities cap)
121 Eina_Bool need_assign_output = EINA_FALSE;
122 const char *output_name;
125 if (!(edev->caps & cap)) return;
126 if (edev->output_name) return; //already assigned
127 if (e_comp->e_comp_screen->num_outputs <= 1) return;
129 last_output_idx = e_comp->e_comp_screen->num_outputs - 1;
130 EINA_LIST_FOREACH(edev->seat->devices, l, ed)
132 if (!(ed->caps & cap)) continue;
133 if (ed == edev) continue;
136 need_assign_output = EINA_FALSE;
139 need_assign_output = EINA_TRUE;
141 if (need_assign_output)
143 output = e_output_find_by_index(last_output_idx);
144 if (!output || !output->info.connected) return;
145 output_name = e_output_output_id_get(output);
146 if (output_name) edev->output_name = eina_stringshare_add(output_name);
147 ELOGF("E_INPUT_EVDEV", "Device is assigned to output:%s", NULL, output_name);
152 _device_touch_count_update(E_Input_Evdev *edev)
154 unsigned int device_touch_count = 0;
155 static unsigned int _max_device_touch_count = 0;
157 E_Input *ei = e_input_get();
158 EINA_SAFETY_ON_NULL_RETURN(ei);
160 device_touch_count = libinput_device_touch_get_touch_count(edev->device);
162 if (_max_device_touch_count < device_touch_count)
163 _max_device_touch_count = device_touch_count;
165 if (e_config->configured_max_touch.use)
167 if (_max_device_touch_count > 0 && e_config->configured_max_touch.count > _max_device_touch_count)
169 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",
170 NULL, e_config->configured_max_touch.count, _max_device_touch_count, _max_device_touch_count);
171 ei->touch_max_count = _max_device_touch_count;
175 if (ei->touch_max_count != e_config->configured_max_touch.count)
177 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch_max_count has been updated to %d -> %d.\n",
178 NULL, ei->touch_max_count, e_config->configured_max_touch.count);
179 ei->touch_max_count = e_config->configured_max_touch.count;
185 if (ei->touch_max_count < _max_device_touch_count)
187 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch_max_count has been updated to %d -> %d.\n", NULL,
188 ei->touch_max_count, _max_device_touch_count);
189 ei->touch_max_count = _max_device_touch_count;
193 ei->touch_device_count++;
194 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch device count is %d.\n", NULL, ei->touch_device_count);
198 _device_configure(E_Input_Evdev *edev)
200 if (libinput_device_config_tap_get_finger_count(edev->device) > 0)
202 Eina_Bool tap = EINA_FALSE;
204 tap = libinput_device_config_tap_get_default_enabled(edev->device);
205 libinput_device_config_tap_set_enabled(edev->device, tap);
208 _device_calibration_set(edev);
212 _device_keyboard_setup(E_Input_Evdev *edev)
214 E_Input_Backend *input;
215 xkb_mod_index_t xkb_idx;
217 if ((!edev) || (!edev->seat)) return;
218 if (!(input = edev->seat->input)) return;
219 if (!input->dev->xkb_ctx) return;
221 /* create keymap from xkb context */
222 edev->xkb.keymap = _e_input_device_cached_keymap_get(input->dev->xkb_ctx, NULL, 0);
223 if (!edev->xkb.keymap)
225 ERR("Failed to create keymap: %m");
229 /* create xkb state */
230 if (!(edev->xkb.state = xkb_state_new(edev->xkb.keymap)))
232 ERR("Failed to create xkb state: %m");
236 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CTRL);
237 if (xkb_idx != XKB_MOD_INVALID)
238 edev->xkb.ctrl_mask = 1 << xkb_idx;
240 edev->xkb.ctrl_mask = 0;
242 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_ALT);
243 if (xkb_idx != XKB_MOD_INVALID)
244 edev->xkb.alt_mask = 1 << xkb_idx;
246 edev->xkb.alt_mask = 0;
248 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_SHIFT);
249 if (xkb_idx != XKB_MOD_INVALID)
250 edev->xkb.shift_mask = 1 << xkb_idx;
252 edev->xkb.shift_mask = 0;
254 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_LOGO);
255 if (xkb_idx != XKB_MOD_INVALID)
256 edev->xkb.win_mask = 1 << xkb_idx;
258 edev->xkb.win_mask = 0;
260 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_SCROLL);
261 if (xkb_idx != XKB_MOD_INVALID)
262 edev->xkb.scroll_mask = 1 << xkb_idx;
264 edev->xkb.scroll_mask = 0;
266 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_NUM);
267 if (xkb_idx != XKB_MOD_INVALID)
268 edev->xkb.num_mask = 1 << xkb_idx;
270 edev->xkb.num_mask = 0;
272 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CAPS);
273 if (xkb_idx != XKB_MOD_INVALID)
274 edev->xkb.caps_mask = 1 << xkb_idx;
276 edev->xkb.caps_mask = 0;
278 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, "ISO_Level3_Shift");
279 if (xkb_idx != XKB_MOD_INVALID)
280 edev->xkb.altgr_mask = 1 << xkb_idx;
282 edev->xkb.altgr_mask = 0;
286 _device_keysym_translate(xkb_keysym_t keysym, unsigned int modifiers, char *buffer, int bytes)
288 unsigned long hbytes = 0;
291 if (!keysym) return 0;
292 hbytes = (keysym >> 8);
297 (((keysym >= XKB_KEY_BackSpace) && (keysym <= XKB_KEY_Clear)) ||
298 (keysym == XKB_KEY_Return) || (keysym == XKB_KEY_Escape) ||
299 (keysym == XKB_KEY_KP_Space) || (keysym == XKB_KEY_KP_Tab) ||
300 (keysym == XKB_KEY_KP_Enter) ||
301 ((keysym >= XKB_KEY_KP_Multiply) && (keysym <= XKB_KEY_KP_9)) ||
302 (keysym == XKB_KEY_KP_Equal) || (keysym == XKB_KEY_Delete))))))
305 if (keysym == XKB_KEY_KP_Space)
306 c = (XKB_KEY_space & 0x7F);
307 else if (hbytes == 0xFF)
312 if (modifiers & ECORE_EVENT_MODIFIER_CTRL)
314 if (((c >= '@') && (c < '\177')) || c == ' ')
318 else if ((c >= '3') && (c <= '7'))
330 _device_modifiers_update_device(E_Input_Evdev *edev, E_Input_Evdev *from)
334 edev->xkb.depressed =
335 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_DEPRESSED);
337 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LATCHED);
339 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LOCKED);
341 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_EFFECTIVE);
343 mask = (edev->xkb.depressed | edev->xkb.latched);
345 if (mask & from->xkb.ctrl_mask)
346 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_CTRL;
347 if (mask & from->xkb.alt_mask)
348 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALT;
349 if (mask & from->xkb.shift_mask)
350 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
351 if (mask & from->xkb.win_mask)
352 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_WIN;
353 if (mask & from->xkb.scroll_mask)
354 edev->xkb.modifiers |= ECORE_EVENT_LOCK_SCROLL;
355 if (mask & from->xkb.num_mask)
356 edev->xkb.modifiers |= ECORE_EVENT_LOCK_NUM;
357 if (mask & from->xkb.caps_mask)
358 edev->xkb.modifiers |= ECORE_EVENT_LOCK_CAPS;
359 if (mask & from->xkb.altgr_mask)
360 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALTGR;
364 _device_modifiers_update(E_Input_Evdev *edev)
369 edev->xkb.modifiers = 0;
371 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
372 _device_modifiers_update_device(edev, edev);
375 EINA_LIST_FOREACH(edev->seat->devices, l, ed)
377 if (!(ed->caps & E_INPUT_SEAT_KEYBOARD)) continue;
378 _device_modifiers_update_device(edev, ed);
385 _device_remapped_key_get(E_Input_Evdev *edev, int code)
389 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, code);
390 if (!edev->key_remap_enabled) return code;
391 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->key_remap_hash, code);
393 ret = eina_hash_find(edev->key_remap_hash, &code);
395 if (ret) code = (int)(intptr_t)ret;
401 e_input_evdev_get_e_device(const char *path, Ecore_Device_Class clas)
403 const GList *dev_list = NULL;
405 E_Device *dev = NULL;
406 const char *identifier;
408 if (!path) return NULL;
410 dev_list = e_device_list_get();
411 if (!dev_list) return NULL;
418 identifier = e_device_identifier_get(dev);
419 if (!identifier) continue;
420 if ((e_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
429 EINTERN Ecore_Device *
430 e_input_evdev_get_ecore_device(const char *path, Ecore_Device_Class clas)
432 const Eina_List *dev_list = NULL;
434 Ecore_Device *dev = NULL;
435 const char *identifier;
437 if (!path) return NULL;
439 dev_list = ecore_device_list();
440 if (!dev_list) return NULL;
441 EINA_LIST_FOREACH(dev_list, l, dev)
444 identifier = ecore_device_identifier_get(dev);
445 if (!identifier) continue;
446 if ((ecore_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
453 _e_input_event_mouse_move_cb_free(void *data EINA_UNUSED, void *event)
455 Ecore_Event_Mouse_Move *ev = event;
457 if (ev->dev) ecore_device_unref(ev->dev);
463 _e_input_event_mouse_relative_move_cb_free(void *data EINA_UNUSED, void *event)
465 Ecore_Event_Mouse_Relative_Move *ev = event;
467 if (ev->dev) ecore_device_unref(ev->dev);
473 _e_input_event_mouse_wheel_cb_free(void *data EINA_UNUSED, void *event)
475 Ecore_Event_Mouse_Wheel *ev = event;
477 if (ev->dev) ecore_device_unref(ev->dev);
483 _e_input_event_mouse_button_cb_free(void *data EINA_UNUSED, void *event)
485 Ecore_Event_Mouse_Button *ev = event;
487 if (ev->dev) ecore_device_unref(ev->dev);
493 _e_input_event_key_cb_free(void *data EINA_UNUSED, void *event)
495 Ecore_Event_Key *ev = event;
497 if (e_input_thread_mode_get())
499 if (ev->dev) g_object_unref(ev->dev);
503 if (ev->dev) ecore_device_unref(ev->dev);
506 if (ev->data) E_FREE(ev->data);
512 _device_handle_key(struct libinput_device *device, struct libinput_event_keyboard *event)
515 E_Input_Backend *input;
517 uint32_t code, nsyms;
518 const xkb_keysym_t *syms;
519 enum libinput_key_state state;
521 xkb_keysym_t sym = XKB_KEY_NoSymbol;
522 char key[256] = {0, }, keyname[256] = {0, }, compose_buffer[256] = {0, };
524 char *tmp = NULL, *compose = NULL;
525 E_Keyrouter_Event_Data *key_data;
526 Ecore_Device *ecore_dev = NULL, *data;
527 E_Device *e_dev = NULL, *e_dev_data;
528 Eina_List *l = NULL, *l_next = NULL;
530 E_Comp_Config *comp_conf = NULL;
531 int *pressed_keycode = NULL, *idata = NULL;
532 Eina_Bool dup_found = EINA_FALSE;
533 const char *device_name = NULL;
534 Ecore_Device_Subclass device_subclas = ECORE_DEVICE_SUBCLASS_NONE;
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);
573 device_subclas = ecore_device_subclass_get(ecore_dev);
577 if (edev->e_dev) e_dev = edev->e_dev;
578 else if (edev->e_dev_list && g_list_length(edev->e_dev_list) > 0)
580 glist = edev->e_dev_list;
583 e_dev_data = glist->data;
584 if (e_device_class_get(e_dev_data) == ECORE_DEVICE_CLASS_KEYBOARD)
590 glist = g_list_next(glist);
595 edev->e_dev = e_input_evdev_get_e_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
601 ERR("Failed to get source e device from event !\n");
605 device_name = e_device_name_get(e_dev);
606 device_subclas = e_device_subclass_get(e_dev);
609 timestamp = libinput_event_keyboard_get_time(event);
610 code = libinput_event_keyboard_get_key(event);
611 code = _device_remapped_key_get(edev, code + 8);
612 state = libinput_event_keyboard_get_key_state(event);
613 key_count = libinput_event_keyboard_get_seat_key_count(event);
615 if (state == LIBINPUT_KEY_STATE_PRESSED)
617 if ((edev->seat->dev->blocked & E_INPUT_SEAT_KEYBOARD) ||
618 (edev->seat->dev->server_blocked & E_INPUT_SEAT_KEYBOARD))
620 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
621 ELOGF("Key", "Press (keycode: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
622 code, device_name, blocked_client,
623 edev->seat->dev->server_blocked);
627 /* FIXME: Currently to maintain press/release event pair during input block,
628 * used Eina_List and this is method used in devicemgr module.
629 * But we need to consider which way is better to maintain key press/release pair.
632 EINA_LIST_FOREACH(edev->xkb.pressed_keys, l, idata)
636 dup_found = EINA_TRUE;
642 pressed_keycode = E_NEW(int, 1);
643 EINA_SAFETY_ON_NULL_RETURN(pressed_keycode);
644 *pressed_keycode = code;
646 edev->xkb.pressed_keys = eina_list_append(edev->xkb.pressed_keys, pressed_keycode);
651 dup_found = EINA_FALSE;
652 EINA_LIST_FOREACH_SAFE(edev->xkb.pressed_keys, l, l_next, idata)
656 edev->xkb.pressed_keys = eina_list_remove_list(edev->xkb.pressed_keys, l);
658 dup_found = EINA_TRUE;
664 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
665 ELOGF("Key", "Release (keycode: %d, device: %s) is blocked by %p", NULL,
666 code, device_name, blocked_client);
671 /* ignore key events that are not seat wide state changes */
672 if (((state == LIBINPUT_KEY_STATE_PRESSED) && (key_count != 1)) ||
673 ((state == LIBINPUT_KEY_STATE_RELEASED) && (key_count != 0)))
678 e_input_keyboard_grab_key_cb func = e_input_keyboard_grab_key_handler_get();
681 if (e_devicemgr_keyboard_grab_subtype_is_grabbed(device_subclas))
683 if (!e_input_thread_mode_get())
684 func(code, state, timestamp, ecore_dev);
686 func(code, state, timestamp, e_dev);
691 xkb_state_update_key(edev->xkb.state, code,
692 (state ? XKB_KEY_DOWN : XKB_KEY_UP));
694 /* get the keysym for this code */
695 nsyms = xkb_key_get_syms(edev->xkb.state, code, &syms);
697 if (nsyms == 1) sym = syms[0];
699 /* If no keysym was found, name it "Keycode-NNN" */
700 if (sym == XKB_KEY_NoSymbol)
701 snprintf(key, sizeof(key), "Keycode-%u", code);
704 /* get the keyname for this sym */
705 xkb_keysym_get_name(sym, key, sizeof(key));
710 /* If no keyname was found, name it "Keycode-NNN" */
711 snprintf(keyname, sizeof(keyname), "Keycode-%u", code);
715 memcpy(keyname, key, sizeof(keyname));
718 /* if shift is active, we need to transform the key to lower */
719 if (xkb_state_mod_index_is_active(edev->xkb.state,
720 xkb_map_mod_get_index(edev->xkb.keymap,
722 XKB_STATE_MODS_EFFECTIVE))
724 if (keyname[0] != '\0')
725 keyname[0] = tolower(keyname[0]);
728 if (_device_keysym_translate(sym, edev->xkb.modifiers,
729 compose_buffer, sizeof(compose_buffer)))
731 compose = eina_str_convert("ISO8859-1", "UTF-8", compose_buffer);
734 ERR("E Input cannot convert input key string '%s' to UTF-8. "
735 "Is Eina built with iconv support?", compose_buffer);
741 if (!compose) compose = compose_buffer;
743 e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) +
744 ((compose[0] != '\0') ? strlen(compose) : 0) + 3);
750 key_data = E_NEW(E_Keyrouter_Event_Data, 1);
758 e->keyname = (char *)(e + 1);
759 e->key = e->keyname + strlen(keyname) + 1;
760 e->compose = strlen(compose) ? e->key + strlen(key) + 1 : NULL;
761 e->string = e->compose;
763 strncpy((char *)e->keyname, keyname, strlen(keyname));
764 strncpy((char *)e->key, key, strlen(key));
765 if (strlen(compose)) strncpy((char *)e->compose, compose, strlen(compose));
767 e->window = (Ecore_Window)input->dev->window;
768 e->event_window = (Ecore_Window)input->dev->window;
769 e->root_window = (Ecore_Window)input->dev->window;
770 e->timestamp = timestamp;
775 _device_modifiers_update(edev);
777 e->modifiers = edev->xkb.modifiers;
779 comp_conf = e_comp_config_get();
781 if (comp_conf && comp_conf->input_log_enable)
782 ELOGF("Key", "%s (keyname: %s, keycode: %d, timestamp: %u, device: %s)", NULL, state?"Press":"Release", e->keyname, e->keycode, e->timestamp, device_name);
784 if (e_config->key_input_ttrace_enable)
786 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));
787 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));
790 _e_input_key_event_list_add(e);
792 if (e_input_thread_mode_get())
794 e->dev = (Eo *)g_object_ref(e_dev);
795 e_input_event_add(input->event_source, state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
799 e->dev = ecore_device_ref(ecore_dev);
800 ecore_event_add(state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
803 if (e_config->key_input_ttrace_enable)
806 ELOGF("INPUT", "ECORE_EVENT_KEY|E|", NULL);
813 _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event)
815 E_Input_Backend *input;
816 Ecore_Event_Mouse_Move *ev;
817 Ecore_Device *ecore_dev = NULL, *data, *detent_data = NULL;
819 int x = 0, y = 0, w = 0, h = 0;
821 if (!(input = edev->seat->input)) return;
823 ecore_thread_main_loop_begin();
825 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
826 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
828 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
830 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
835 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
840 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
842 ecore_dev = detent_data;
847 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
848 ecore_dev = edev->ecore_dev;
853 ERR("Failed to get source ecore device from event !\n");
856 else if ((detent_data == ecore_dev) || e_devicemgr_detent_is_detent(ecore_device_name_get(ecore_dev)))
858 /* Do not process detent device's move events. */
862 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
864 _device_configured_size_get(edev, &x, &y, &w, &h);
866 if (edev->seat->ptr.ix < x)
867 edev->seat->ptr.dx = edev->seat->ptr.ix = x;
868 else if (edev->seat->ptr.ix >= (x + w))
869 edev->seat->ptr.dx = edev->seat->ptr.ix = (x + w - 1);
871 if (edev->seat->ptr.iy < y)
872 edev->seat->ptr.dy = edev->seat->ptr.iy = y;
873 else if (edev->seat->ptr.iy >= (y + h))
874 edev->seat->ptr.dy = edev->seat->ptr.iy = (y + h - 1);
876 edev->mouse.dx = edev->seat->ptr.dx;
877 edev->mouse.dy = edev->seat->ptr.dy;
879 ev->window = (Ecore_Window)input->dev->window;
880 ev->event_window = (Ecore_Window)input->dev->window;
881 ev->root_window = (Ecore_Window)input->dev->window;
882 if (event) ev->timestamp = libinput_event_pointer_get_time(event);
885 _device_modifiers_update(edev);
886 ev->modifiers = edev->xkb.modifiers;
888 ev->x = edev->seat->ptr.ix;
889 ev->y = edev->seat->ptr.iy;
893 ev->multi.device = edev->mt_slot;
894 ev->multi.radius = 1;
895 ev->multi.radius_x = 1;
896 ev->multi.radius_y = 1;
897 ev->multi.pressure = 1.0;
898 ev->multi.angle = 0.0;
901 ev->multi.root.x = ev->x;
902 ev->multi.root.y = ev->y;
904 ev->dev = ecore_device_ref(ecore_dev);
906 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
909 ecore_thread_main_loop_end();
913 _e_input_pointer_motion_post(E_Input_Evdev *edev)
915 _device_pointer_motion(edev, NULL);
919 _device_pointer_relative_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event, double dx[2], double dy[2])
921 E_Input_Backend *input;
922 Ecore_Event_Mouse_Relative_Move *ev;
923 Ecore_Device *ecore_dev = NULL, *data, *detent_data = NULL;
925 E_Comp_Config *comp_conf;
927 if (!(input = edev->seat->input)) return;
929 ecore_thread_main_loop_begin();
931 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
932 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
934 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
936 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
941 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
946 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
948 ecore_dev = detent_data;
953 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
954 ecore_dev = edev->ecore_dev;
959 ERR("Failed to get source ecore device from event !\n");
962 else if ((detent_data == ecore_dev) || e_devicemgr_detent_is_detent(ecore_device_name_get(ecore_dev)))
964 /* Do not process detent device's move events. */
968 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Relative_Move)))) return;
970 ev->window = (Ecore_Window)input->dev->window;
971 ev->event_window = (Ecore_Window)input->dev->window;
972 if (event) ev->timestamp = libinput_event_pointer_get_time(event);
974 ev->modifiers = edev->xkb.modifiers;
978 ev->dx_unaccel = (int)dx[1];
979 ev->dy_unaccel = (int)dy[1];
981 ev->dev = ecore_device_ref(ecore_dev);
983 comp_conf = e_comp_config_get();
984 if (comp_conf && comp_conf->input_log_enable)
985 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));
987 ecore_event_add(ECORE_EVENT_MOUSE_RELATIVE_MOVE, ev, _e_input_event_mouse_relative_move_cb_free, NULL);
990 ecore_thread_main_loop_end();
994 _device_pointer_motion_send(E_Input_Evdev *edev, struct libinput_event_pointer *event, double dx[2], double dy[2])
996 e_input_relative_motion_cb func = e_input_relative_motion_handler_get();
999 //func(dx, dy, time_us);
1000 _device_pointer_relative_motion(edev, event, dx, dy);
1004 double seat_dx, seat_dy, temp;
1005 if (edev->disable_acceleration)
1016 if (edev->seat->ptr.swap)
1022 if (edev->seat->ptr.invert_x)
1024 if (edev->seat->ptr.invert_y)
1027 edev->seat->ptr.dx += seat_dx;
1028 edev->seat->ptr.dy += seat_dy;
1030 edev->mouse.dx = edev->seat->ptr.dx;
1031 edev->mouse.dy = edev->seat->ptr.dy;
1033 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
1034 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
1039 edev->seat->ptr.ix = edev->seat->ptr.dx;
1040 edev->seat->ptr.iy = edev->seat->ptr.dy;
1042 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1043 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1048 _device_pointer_motion(edev, event);
1053 _device_handle_pointer_motion(struct libinput_device *device, struct libinput_event_pointer *event)
1055 E_Input_Evdev *edev;
1056 double delta_x[2]; /* delta_x[0] for accelerated, delta_x[1] for unaccelerated */
1057 double delta_y[2]; /* delta_y[0] for accelerated, delta_y[1] for unaccelerated */
1059 if (!(edev = libinput_device_get_user_data(device)))
1064 delta_x[0] = libinput_event_pointer_get_dx(event);
1065 delta_x[1] = libinput_event_pointer_get_dx_unaccelerated(event);
1066 delta_y[0] = libinput_event_pointer_get_dy(event);
1067 delta_y[1] = libinput_event_pointer_get_dy_unaccelerated(event);
1069 _device_pointer_motion_send(edev, event, &delta_x[0], &delta_y[0]);
1073 _device_handle_pointer_motion_absolute(struct libinput_device *device, struct libinput_event_pointer *event)
1075 E_Input_Evdev *edev;
1078 if (!(edev = libinput_device_get_user_data(device)))
1083 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
1085 edev->mouse.dx = edev->seat->ptr.dx =
1086 libinput_event_pointer_get_absolute_x_transformed(event, w);
1087 edev->mouse.dy = edev->seat->ptr.dy =
1088 libinput_event_pointer_get_absolute_y_transformed(event, h);
1090 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
1091 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
1096 edev->seat->ptr.ix = edev->seat->ptr.dx;
1097 edev->seat->ptr.iy = edev->seat->ptr.dy;
1099 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1100 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1105 _device_pointer_motion(edev, event);
1109 _device_handle_button(struct libinput_device *device, struct libinput_event_pointer *event)
1111 E_Input_Evdev *edev;
1112 E_Input_Backend *input;
1113 Ecore_Event_Mouse_Button *ev;
1114 enum libinput_button_state state;
1115 uint32_t button, timestamp;
1116 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1118 E_Comp_Config *comp_conf = NULL;
1120 if (!(edev = libinput_device_get_user_data(device)))
1124 if (!(input = edev->seat->input))
1129 ecore_thread_main_loop_begin();
1131 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1132 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1134 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1136 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1141 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1146 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1148 ecore_dev = detent_data;
1153 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1154 ecore_dev = edev->ecore_dev;
1159 ERR("Failed to get source ecore device from event !\n");
1163 state = libinput_event_pointer_get_button_state(event);
1164 button = libinput_event_pointer_get_button(event);
1165 timestamp = libinput_event_pointer_get_time(event);
1167 button = ((button & 0x00F) + 1);
1168 if (button == 3) button = 2;
1169 else if (button == 2) button = 3;
1171 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
1175 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1176 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1179 ELOGF("Mouse", "Button Press (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
1180 button, ecore_device_name_get(ecore_dev), blocked_client,
1181 edev->seat->dev->server_blocked);
1186 edev->mouse.pressed_button |= (1 << button);
1191 if (!(edev->mouse.pressed_button & (1 << button)))
1193 ELOGF("Mouse", "Button Release (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
1194 button, ecore_device_name_get(ecore_dev), blocked_client,
1195 edev->seat->dev->server_blocked);
1198 edev->mouse.pressed_button &= ~(1 << button);
1201 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button))))
1206 ev->window = (Ecore_Window)input->dev->window;
1207 ev->event_window = (Ecore_Window)input->dev->window;
1208 ev->root_window = (Ecore_Window)input->dev->window;
1209 ev->timestamp = timestamp;
1210 ev->same_screen = 1;
1212 _device_modifiers_update(edev);
1213 ev->modifiers = edev->xkb.modifiers;
1215 ev->x = edev->seat->ptr.ix;
1216 ev->y = edev->seat->ptr.iy;
1220 ev->multi.device = edev->mt_slot;
1221 ev->multi.radius = 1;
1222 ev->multi.radius_x = 1;
1223 ev->multi.radius_y = 1;
1224 ev->multi.pressure = 1.0;
1225 ev->multi.angle = 0.0;
1226 ev->multi.x = ev->x;
1227 ev->multi.y = ev->y;
1228 ev->multi.root.x = ev->x;
1229 ev->multi.root.y = ev->y;
1230 ev->dev = ecore_device_ref(ecore_dev);
1234 unsigned int current;
1236 current = timestamp;
1237 edev->mouse.did_double = EINA_FALSE;
1238 edev->mouse.did_triple = EINA_FALSE;
1240 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1241 (button == edev->mouse.prev_button))
1243 edev->mouse.did_double = EINA_TRUE;
1244 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1245 (button == edev->mouse.last_button))
1247 edev->mouse.did_triple = EINA_TRUE;
1248 edev->mouse.prev = 0;
1249 edev->mouse.last = 0;
1254 edev->mouse.last = edev->mouse.prev;
1255 edev->mouse.prev = current;
1256 edev->mouse.last_button = edev->mouse.prev_button;
1257 edev->mouse.prev_button = button;
1260 ev->buttons = button;
1262 if (edev->mouse.did_double)
1263 ev->double_click = 1;
1264 if (edev->mouse.did_triple)
1265 ev->triple_click = 1;
1267 comp_conf = e_comp_config_get();
1268 if (comp_conf && comp_conf->input_log_enable)
1269 ELOGF("Mouse", "Button %s (btn: %d, device: %s)", NULL, state?"Press":"Release", button, ecore_device_name_get(ev->dev));
1272 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, _e_input_event_mouse_button_cb_free, NULL);
1274 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, _e_input_event_mouse_button_cb_free, NULL);
1277 ecore_thread_main_loop_end();
1280 #if !LIBINPUT_HAVE_SCROLL_VALUE_V120
1282 _axis_value_get(struct libinput_event_pointer *pointer_event, enum libinput_pointer_axis axis)
1284 enum libinput_pointer_axis_source source;
1285 double value = 0.0, value_discrete = 0.0;
1287 E_Comp_Config *comp_conf = NULL;
1289 comp_conf = e_comp_config_get();
1290 source = libinput_event_pointer_get_axis_source(pointer_event);
1293 case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL:
1294 value_discrete = libinput_event_pointer_get_axis_value_discrete(pointer_event, axis);
1295 value = libinput_event_pointer_get_axis_value(pointer_event, axis);
1296 if (comp_conf && comp_conf->input_log_enable)
1298 ELOGF("Axis", "SOURCE_WHEEL discrete: %lf (cf. value: %lf)", NULL, value_discrete, value);
1300 ret = (int)value_discrete;
1302 case LIBINPUT_POINTER_AXIS_SOURCE_FINGER:
1303 case LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS:
1304 value = libinput_event_pointer_get_axis_value(pointer_event, axis);
1305 if (comp_conf && comp_conf->input_log_enable)
1307 ELOGF("Axis", "SOURCE_FINGER/CONTINUOUS value: %lf", NULL, value);
1309 if (value >= E_INPUT_FINGER_SCROLL_THRESHOLD)
1311 else if (value <= E_INPUT_FINGER_SCROLL_THRESHOLD * (-1))
1324 _device_handle_axis(struct libinput_device *device, struct libinput_event_pointer *event)
1326 E_Input_Evdev *edev;
1327 E_Input_Backend *input;
1328 Ecore_Event_Mouse_Wheel *ev;
1330 enum libinput_pointer_axis axis;
1331 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1333 E_Comp_Config *comp_conf = NULL;
1334 int direction = 0, z = 0;
1336 if (!(edev = libinput_device_get_user_data(device)))
1340 if (!(input = edev->seat->input))
1345 ecore_thread_main_loop_begin();
1347 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1348 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1350 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1352 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1357 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1362 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1364 ecore_dev = detent_data;
1369 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1370 ecore_dev = edev->ecore_dev;
1375 ERR("Failed to get source ecore device from event !\n");
1379 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1380 if (libinput_event_pointer_has_axis(event, axis))
1381 z = _axis_value_get(event, axis);
1383 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1384 if (libinput_event_pointer_has_axis(event, axis))
1387 z = _axis_value_get(event, axis);
1392 ELOGF("Mouse", "Axis event is ignored since it has zero value", NULL);
1396 comp_conf = e_comp_config_get();
1397 if (comp_conf && comp_conf->e_wheel_click_angle)
1399 z = (int)(z * comp_conf->e_wheel_click_angle);
1402 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1403 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1405 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
1408 ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1409 direction, z, blocked_client, edev->seat->dev->server_blocked);
1411 ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1412 direction, z, blocked_client, edev->seat->dev->server_blocked);
1417 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1422 timestamp = libinput_event_pointer_get_time(event);
1424 ev->window = (Ecore_Window)input->dev->window;
1425 ev->event_window = (Ecore_Window)input->dev->window;
1426 ev->root_window = (Ecore_Window)input->dev->window;
1427 ev->timestamp = timestamp;
1428 ev->same_screen = 1;
1430 _device_modifiers_update(edev);
1431 ev->modifiers = edev->xkb.modifiers;
1433 ev->x = edev->seat->ptr.ix;
1434 ev->y = edev->seat->ptr.iy;
1438 ev->direction = direction;
1440 if (comp_conf && comp_conf->input_log_enable)
1443 ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1445 ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1449 ev->dev = ecore_device_ref(ecore_dev);
1450 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1453 ecore_thread_main_loop_end();
1457 #if LIBINPUT_HAVE_SCROLL_VALUE_V120
1459 _scroll_value_get(struct libinput_event_pointer *pointer_event, enum libinput_pointer_axis axis, E_Input_Axis_Source source)
1462 double value_v120 = 0.0;
1464 E_Comp_Config *comp_conf = NULL;
1466 comp_conf = e_comp_config_get();
1469 case E_INPUT_AXIS_SOURCE_WHEEL:
1470 value_v120 = libinput_event_pointer_get_scroll_value_v120(pointer_event, axis);
1471 value = libinput_event_pointer_get_scroll_value(pointer_event, axis);
1472 if (comp_conf && comp_conf->input_log_enable)
1474 ELOGF("Scroll", "SOURCE_WHEEL value_v120: %lf (cf. value: %lf)", NULL, value_v120, value);
1476 if (((int)value_v120 % E_INPUT_POINTER_AXIS_DISCRETE_STEP) != 0)
1478 ERR("Wheel movements should be multiples (or fractions) of 120!\n");
1483 ret = value_v120 / E_INPUT_POINTER_AXIS_DISCRETE_STEP;
1486 case E_INPUT_AXIS_SOURCE_FINGER:
1487 case E_INPUT_AXIS_SOURCE_CONTINUOUS:
1488 value = libinput_event_pointer_get_scroll_value(pointer_event, axis);
1489 if (comp_conf && comp_conf->input_log_enable)
1491 ELOGF("Scroll", "SOURCE_FINGER/CONTINUOUS value: %lf", NULL, value);
1493 if (value >= E_INPUT_FINGER_SCROLL_THRESHOLD)
1495 else if (value <= E_INPUT_FINGER_SCROLL_THRESHOLD * (-1))
1508 _device_handle_axis_v120(struct libinput_device *device, struct libinput_event_pointer *event, E_Input_Axis_Source source)
1510 E_Input_Evdev *edev;
1511 E_Input_Backend *input;
1512 Ecore_Event_Mouse_Wheel *ev;
1514 enum libinput_pointer_axis axis;
1515 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1517 E_Comp_Config *comp_conf = NULL;
1518 int direction = 0, z = 0;
1520 if (!(edev = libinput_device_get_user_data(device)))
1524 if (!(input = edev->seat->input))
1529 ecore_thread_main_loop_begin();
1531 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1532 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1534 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1536 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1541 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1546 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1548 ecore_dev = detent_data;
1553 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1554 ecore_dev = edev->ecore_dev;
1559 ERR("Failed to get source ecore device from event !\n");
1563 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1564 if (libinput_event_pointer_has_axis(event, axis))
1565 z = _scroll_value_get(event, axis, source);
1567 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1568 if (libinput_event_pointer_has_axis(event, axis))
1571 z = _scroll_value_get(event, axis, source);
1576 ELOGF("Mouse", "Scroll event is ignored since it has zero value", NULL);
1580 comp_conf = e_comp_config_get();
1581 if (comp_conf && comp_conf->e_wheel_click_angle)
1583 z = (int)(z * comp_conf->e_wheel_click_angle);
1586 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1587 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1589 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
1591 ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1592 direction, z, blocked_client, edev->seat->dev->server_blocked);
1594 ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1595 direction, z, blocked_client, edev->seat->dev->server_blocked);
1600 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1605 timestamp = libinput_event_pointer_get_time(event);
1607 ev->window = (Ecore_Window)input->dev->window;
1608 ev->event_window = (Ecore_Window)input->dev->window;
1609 ev->root_window = (Ecore_Window)input->dev->window;
1610 ev->timestamp = timestamp;
1611 ev->same_screen = 1;
1613 _device_modifiers_update(edev);
1614 ev->modifiers = edev->xkb.modifiers;
1616 ev->x = edev->seat->ptr.ix;
1617 ev->y = edev->seat->ptr.iy;
1621 ev->direction = direction;
1623 if (comp_conf && comp_conf->input_log_enable)
1626 ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1628 ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1631 ev->dev = ecore_device_ref(ecore_dev);
1632 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1635 ecore_thread_main_loop_end();
1640 _device_handle_touch_event_send(E_Input_Evdev *edev, struct libinput_event_touch *event, int state)
1642 E_Input_Backend *input;
1643 Ecore_Event_Mouse_Button *ev;
1644 uint32_t timestamp, button = 0;
1645 Ecore_Device *ecore_dev = NULL, *data;
1649 if (!(input = edev->seat->input)) return;
1651 ecore_thread_main_loop_begin();
1653 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1654 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1656 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1658 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1667 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1668 ecore_dev = edev->ecore_dev;
1673 ERR("Failed to get source ecore device from event !\n");
1677 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) goto end;
1679 timestamp = libinput_event_touch_get_time(event);
1681 ev->window = (Ecore_Window)input->dev->window;
1682 ev->event_window = (Ecore_Window)input->dev->window;
1683 ev->root_window = (Ecore_Window)input->dev->window;
1684 ev->timestamp = timestamp;
1685 ev->same_screen = 1;
1687 _device_modifiers_update(edev);
1688 ev->modifiers = edev->xkb.modifiers;
1690 ev->x = edev->seat->ptr.ix;
1691 ev->y = edev->seat->ptr.iy;
1695 ev->multi.device = edev->mt_slot;
1696 ev->multi.radius = 1;
1697 ev->multi.radius_x = 1;
1698 ev->multi.radius_y = 1;
1699 ev->multi.pressure = 1.0;
1700 ev->multi.angle = 0.0;
1701 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1702 if (libinput_event_get_type(libinput_event_touch_get_base_event(event))
1703 == LIBINPUT_EVENT_TOUCH_DOWN)
1705 if (libinput_event_touch_has_minor(event))
1706 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1707 if (libinput_event_touch_has_major(event))
1708 ev->multi.radius_y = libinput_event_touch_get_major(event);
1709 if (libinput_event_touch_has_pressure(event))
1710 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1711 if (libinput_event_touch_has_orientation(event))
1712 ev->multi.angle = libinput_event_touch_get_orientation(event);
1715 ev->multi.x = ev->x;
1716 ev->multi.y = ev->y;
1717 ev->multi.root.x = ev->x;
1718 ev->multi.root.y = ev->y;
1719 ev->dev = ecore_device_ref(ecore_dev);
1721 if (state == ECORE_EVENT_MOUSE_BUTTON_DOWN)
1723 unsigned int current;
1725 current = timestamp;
1726 edev->mouse.did_double = EINA_FALSE;
1727 edev->mouse.did_triple = EINA_FALSE;
1729 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1730 (button == edev->mouse.prev_button))
1732 edev->mouse.did_double = EINA_TRUE;
1733 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1734 (button == edev->mouse.last_button))
1736 edev->mouse.did_triple = EINA_TRUE;
1737 edev->mouse.prev = 0;
1738 edev->mouse.last = 0;
1743 edev->mouse.last = edev->mouse.prev;
1744 edev->mouse.prev = current;
1745 edev->mouse.last_button = edev->mouse.prev_button;
1746 edev->mouse.prev_button = button;
1747 edev->touch.pressed |= (1 << ev->multi.device);
1751 edev->touch.pressed &= ~(1 << ev->multi.device);
1754 ev->buttons = ((button & 0x00F) + 1);
1756 if (edev->mouse.did_double)
1757 ev->double_click = 1;
1758 if (edev->mouse.did_triple)
1759 ev->triple_click = 1;
1761 ecore_event_add(state, ev, _e_input_event_mouse_button_cb_free, NULL);
1764 ecore_thread_main_loop_end();
1768 _device_handle_touch_motion_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1770 E_Input_Backend *input;
1771 Ecore_Event_Mouse_Move *ev;
1772 Ecore_Device *ecore_dev = NULL, *data;
1776 if (!(input = edev->seat->input)) return;
1778 ecore_thread_main_loop_begin();
1780 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1781 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1783 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1785 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1794 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1795 ecore_dev = edev->ecore_dev;
1800 ERR("Failed to get source ecore device from event !\n");
1804 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) goto end;
1806 ev->window = (Ecore_Window)input->dev->window;
1807 ev->event_window = (Ecore_Window)input->dev->window;
1808 ev->root_window = (Ecore_Window)input->dev->window;
1809 ev->timestamp = libinput_event_touch_get_time(event);
1810 ev->same_screen = 1;
1812 _device_modifiers_update(edev);
1813 ev->modifiers = edev->xkb.modifiers;
1815 ev->x = edev->seat->ptr.ix;
1816 ev->y = edev->seat->ptr.iy;
1820 ev->multi.device = edev->mt_slot;
1821 ev->multi.radius = 1;
1822 ev->multi.radius_x = 1;
1823 ev->multi.radius_y = 1;
1824 ev->multi.pressure = 1.0;
1825 ev->multi.angle = 0.0;
1826 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1827 if (libinput_event_touch_has_minor(event))
1828 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1829 if (libinput_event_touch_has_major(event))
1830 ev->multi.radius_y = libinput_event_touch_get_major(event);
1831 if (libinput_event_touch_has_pressure(event))
1832 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1833 if (libinput_event_touch_has_orientation(event))
1834 ev->multi.angle = libinput_event_touch_get_orientation(event);
1836 ev->multi.x = ev->x;
1837 ev->multi.y = ev->y;
1838 ev->multi.root.x = ev->x;
1839 ev->multi.root.y = ev->y;
1840 ev->dev = ecore_device_ref(ecore_dev);
1842 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
1845 ecore_thread_main_loop_end();
1849 _device_handle_touch_cancel_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1851 E_Input_Backend *input;
1852 Ecore_Event_Mouse_Button *ev;
1853 uint32_t timestamp, button = 0;
1854 Ecore_Device *ecore_dev = NULL, *data;
1858 if (!(input = edev->seat->input)) return;
1860 ecore_thread_main_loop_begin();
1862 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1863 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1865 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1867 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1876 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1877 ecore_dev = edev->ecore_dev;
1882 ERR("Failed to get source ecore device from event !\n");
1886 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) goto end;
1888 timestamp = libinput_event_touch_get_time(event);
1890 ev->window = (Ecore_Window)input->dev->window;
1891 ev->event_window = (Ecore_Window)input->dev->window;
1892 ev->root_window = (Ecore_Window)input->dev->window;
1893 ev->timestamp = timestamp;
1894 ev->same_screen = 1;
1896 ev->x = edev->seat->ptr.ix;
1897 ev->y = edev->seat->ptr.iy;
1901 ev->multi.device = edev->mt_slot;
1902 ev->multi.radius = 1;
1903 ev->multi.radius_x = 1;
1904 ev->multi.radius_y = 1;
1905 ev->multi.pressure = 1.0;
1906 ev->multi.angle = 0.0;
1907 ev->multi.x = ev->x;
1908 ev->multi.y = ev->y;
1909 ev->multi.root.x = ev->x;
1910 ev->multi.root.y = ev->y;
1912 edev->touch.pressed &= ~(1 << ev->multi.device);
1914 ev->buttons = ((button & 0x00F) + 1);
1915 ev->dev = ecore_device_ref(ecore_dev);
1917 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev, _e_input_event_mouse_button_cb_free, NULL);
1920 ecore_thread_main_loop_end();
1924 _device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, int *w, int *h)
1926 E_Output *output = NULL;
1928 EINA_SAFETY_ON_NULL_RETURN(edev);
1930 if (!edev->output_configured)
1932 if (edev->output_name)
1934 output = e_output_find(edev->output_name);
1937 edev->mouse.minx = output->config.geom.x;
1938 edev->mouse.miny = output->config.geom.y;
1939 edev->mouse.maxw = output->config.geom.w;
1940 edev->mouse.maxh = output->config.geom.h;
1941 if (edev->caps & E_INPUT_SEAT_POINTER)
1943 edev->seat->ptr.dx = (double)(edev->mouse.maxw / 2);
1944 edev->seat->ptr.dy = (double)(edev->mouse.maxh / 2);
1945 edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
1946 edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
1947 edev->mouse.dx = edev->seat->ptr.dx;
1948 edev->mouse.dy = edev->seat->ptr.dy;
1953 edev->output_configured = EINA_TRUE;
1954 ELOGF("E_INPUT_EVDEV", "Device is configured by output x:%d,y:%d (w:%d, h:%d)",
1955 NULL, edev->mouse.minx, edev->mouse.miny, edev->mouse.maxw, edev->mouse.maxh);
1957 if (x) *x = edev->mouse.minx;
1958 if (y) *y = edev->mouse.miny;
1959 if (w) *w = edev->mouse.maxw;
1960 if (h) *h = edev->mouse.maxh;
1964 _device_handle_touch_down(struct libinput_device *device, struct libinput_event_touch *event)
1966 E_Input_Evdev *edev;
1967 int x = 0, y = 0, w = 0, h = 0;
1968 E_Comp_Config *comp_conf = NULL;
1970 if (!(edev = libinput_device_get_user_data(device)))
1975 _device_configured_size_get(edev, &x, &y, &w, &h);
1977 edev->mouse.dx = edev->seat->ptr.ix = edev->seat->ptr.dx =
1978 x + libinput_event_touch_get_x_transformed(event, w);
1979 edev->mouse.dy = edev->seat->ptr.iy = edev->seat->ptr.dy =
1980 y + libinput_event_touch_get_y_transformed(event, h);
1982 edev->mt_slot = libinput_event_touch_get_slot(event);
1983 if (edev->mt_slot < 0)
1985 /* FIXME: The single touch device return slot id -1
1986 * But currently we have no API to distinguish multi touch or single touch
1987 * After libinput 1.11 version, libinput provides get_touch_count API,
1988 * so we can distinguish multi touch device or single touch device.
1990 if (edev->mt_slot == -1)
1994 WRN("%d slot touch down events are not supported\n", edev->mt_slot);
1999 if (edev->mt_slot < e_input_touch_max_count_get())
2001 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
2002 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
2005 comp_conf = e_comp_config_get();
2006 if (comp_conf && comp_conf->input_log_enable)
2007 ELOGF("Touch", "Down (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2009 atomic_fetch_or(&edev->touch.raw_pressed, (1 << edev->mt_slot));
2011 if (edev->touch.blocked)
2013 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
2014 ELOGF("Touch", "Down (id: %d, x: %d, y: %d) is blocked by %p, server: 0x%x", NULL,
2015 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, blocked_client,
2016 edev->seat->dev->server_blocked);
2020 _device_handle_touch_motion_send(edev, event);
2021 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_DOWN);
2025 _device_handle_touch_motion(struct libinput_device *device, struct libinput_event_touch *event)
2027 E_Input_Evdev *edev;
2028 int x = 0, y = 0, w = 0, h = 0;
2030 if (!(edev = libinput_device_get_user_data(device)))
2035 _device_configured_size_get(edev, &x, &y, &w, &h);
2037 edev->mouse.dx = edev->seat->ptr.dx =
2038 x + libinput_event_touch_get_x_transformed(event, w);
2039 edev->mouse.dy = edev->seat->ptr.dy =
2040 y + libinput_event_touch_get_y_transformed(event, h);
2042 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
2043 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
2048 edev->seat->ptr.ix = edev->seat->ptr.dx;
2049 edev->seat->ptr.iy = edev->seat->ptr.dy;
2051 edev->mt_slot = libinput_event_touch_get_slot(event);
2052 if (edev->mt_slot < 0)
2054 /* FIXME: The single touch device return slot id -1
2055 * But currently we have no API to distinguish multi touch or single touch
2056 * After libinput 1.11 version, libinput provides get_touch_count API,
2057 * so we can distinguish multi touch device or single touch device.
2059 if (edev->mt_slot == -1)
2063 WRN("%d slot touch motion events are not supported\n", edev->mt_slot);
2068 if (edev->mt_slot < e_input_touch_max_count_get())
2070 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
2071 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
2074 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
2076 if (edev->touch.blocked)
2082 _device_handle_touch_motion_send(edev, event);
2086 _device_handle_touch_up(struct libinput_device *device, struct libinput_event_touch *event)
2088 E_Input_Evdev *edev;
2089 E_Comp_Config *comp_conf = NULL;
2091 if (!(edev = libinput_device_get_user_data(device)))
2096 edev->mt_slot = libinput_event_touch_get_slot(event);
2097 if (edev->mt_slot < 0)
2099 /* FIXME: The single touch device return slot id -1
2100 * But currently we have no API to distinguish multi touch or single touch
2101 * After libinput 1.11 version, libinput provides get_touch_count API,
2102 * so we can distinguish multi touch device or single touch device.
2104 if (edev->mt_slot == -1)
2108 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
2113 if (edev->mt_slot < e_input_touch_max_count_get())
2115 edev->mouse.dx = edev->seat->ptr.dx = edev->seat->ptr.ix =
2116 edev->touch.coords[edev->mt_slot].x;
2117 edev->mouse.dy = edev->seat->ptr.dy = edev->seat->ptr.iy =
2118 edev->touch.coords[edev->mt_slot].y;
2121 comp_conf = e_comp_config_get();
2122 if (comp_conf && comp_conf->input_log_enable)
2123 ELOGF("Touch", "Up (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2125 atomic_fetch_and(&edev->touch.raw_pressed, ~(1 << edev->mt_slot));
2127 if (edev->touch.blocked)
2129 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
2131 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
2132 ELOGF("Touch", "Up (id: %d, x: %d, y: %d) is blocked by %p, server(0x%x)", NULL,
2133 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, blocked_client,
2134 edev->seat->dev->server_blocked);
2136 if (edev->touch.raw_pressed == 0x0)
2138 edev->touch.blocked = EINA_FALSE;
2144 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_UP);
2148 _device_handle_touch_cancel(struct libinput_device *device, struct libinput_event_touch *event)
2150 E_Input_Evdev *edev;
2151 E_Comp_Config *comp_conf = NULL;
2153 if (!(edev = libinput_device_get_user_data(device)))
2158 edev->mt_slot = libinput_event_touch_get_slot(event);
2159 if (edev->mt_slot < 0)
2161 /* FIXME: The single touch device return slot id -1
2162 * But currently we have no API to distinguish multi touch or single touch
2163 * After libinput 1.11 version, libinput provides get_touch_count API,
2164 * so we can distinguish multi touch device or single touch device.
2166 if (edev->mt_slot == -1)
2170 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
2175 comp_conf = e_comp_config_get();
2176 if (comp_conf && comp_conf->input_log_enable)
2177 ELOGF("Touch", "cancel (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2179 _device_handle_touch_cancel_send(edev, event);
2184 _device_handle_touch_frame(struct libinput_device *device EINA_UNUSED, struct libinput_event_touch *event EINA_UNUSED)
2186 /* DBG("Unhandled Touch Frame Event"); */
2190 _e_input_aux_data_event_free(void *user_data EINA_UNUSED, void *ev)
2192 Ecore_Event_Axis_Update *e = (Ecore_Event_Axis_Update *)ev;
2194 if (e->axis) free(e->axis);
2195 if (e->dev) ecore_device_unref(e->dev);
2201 _device_handle_touch_aux_data(struct libinput_device *device, struct libinput_event_touch_aux_data *event)
2203 E_Input_Evdev *edev;
2204 E_Input_Backend *input;
2205 Ecore_Event_Axis_Update *ev;
2207 Ecore_Device *ecore_dev = NULL, *data;
2209 E_Comp_Config *comp_conf;
2211 ecore_thread_main_loop_begin();
2213 if (libinput_event_touch_aux_data_get_type(event) != LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM &&
2214 libinput_event_touch_aux_data_get_value(event) > 0)
2217 if (!(edev = libinput_device_get_user_data(device))) goto end;
2218 if (!(input = edev->seat->input)) goto end;
2220 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
2221 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
2223 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
2225 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
2234 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
2235 ecore_dev = edev->ecore_dev;
2240 ERR("Failed to get source ecore device from event !\n");
2244 if (!(ev = calloc(1, sizeof(Ecore_Event_Axis_Update)))) goto end;
2246 ev->window = (Ecore_Window)input->dev->window;
2247 ev->event_window = (Ecore_Window)input->dev->window;
2248 ev->root_window = (Ecore_Window)input->dev->window;
2249 ev->timestamp = libinput_event_touch_aux_data_get_time(event);
2251 axis = (Ecore_Axis *)calloc(1, sizeof(Ecore_Axis));
2254 axis->label = ECORE_AXIS_LABEL_TOUCH_PALM;
2255 axis->value = libinput_event_touch_aux_data_get_value(event);
2260 comp_conf = e_comp_config_get();
2261 if (comp_conf && comp_conf->input_log_enable)
2262 ELOGF("Touch", "Axis (label: %d, value: %lf)", NULL, axis?axis->label:-1, axis?axis->value:0.0);
2264 ev->dev = ecore_device_ref(ecore_dev);
2266 ecore_event_add(ECORE_EVENT_AXIS_UPDATE, ev, _e_input_aux_data_event_free, NULL);
2269 ecore_thread_main_loop_end();
2273 _e_input_evdev_device_create(E_Input_Seat *seat, struct libinput_device *device)
2275 E_Input_Evdev *edev;
2276 E_Input_Backend *b_input;
2277 const char *output_name;
2279 EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
2281 /* try to allocate space for new evdev */
2282 if (!(edev = calloc(1, sizeof(E_Input_Evdev)))) return NULL;
2285 edev->device = device;
2286 edev->path = eina_stringshare_printf("%s/%s", e_input_base_dir_get(), libinput_device_get_sysname(device));
2288 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
2290 edev->caps |= E_INPUT_SEAT_KEYBOARD;
2291 _device_keyboard_setup(edev);
2294 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
2296 edev->caps |= E_INPUT_SEAT_POINTER;
2298 /* TODO: make this configurable */
2299 edev->mouse.threshold = 250;
2301 b_input = seat->input;
2302 if (b_input->left_handed == EINA_TRUE)
2304 if (libinput_device_config_left_handed_set(device, 1) !=
2305 LIBINPUT_CONFIG_STATUS_SUCCESS)
2307 WRN("Failed to set left hand mode about device: %s\n",
2308 libinput_device_get_name(device));
2313 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
2316 edev->caps |= E_INPUT_SEAT_TOUCH;
2317 palm_code = libinput_device_touch_aux_data_get_code(LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM);
2318 if (libinput_device_touch_has_aux_data(device, palm_code))
2320 libinput_device_touch_set_aux_data(device, palm_code);
2323 _device_touch_count_update(edev);
2325 edev->touch.coords = calloc(1, sizeof(E_Input_Coord)*e_input_touch_max_count_get());
2327 if (!edev->touch.coords)
2328 ERR("Failed to allocate memory for touch coords !\n");
2331 output_name = libinput_device_get_output_name(device);
2334 eina_stringshare_replace(&edev->output_name, output_name);
2335 ELOGF("E_INPUT_EVDEV", "Device has output_name:%s", NULL, output_name);
2338 libinput_device_set_user_data(device, edev);
2339 libinput_device_ref(device);
2341 /* configure device */
2342 _device_configure(edev);
2348 _e_input_evdev_device_destroy(E_Input_Evdev *edev)
2351 EINA_SAFETY_ON_NULL_RETURN(edev);
2353 ecore_thread_main_loop_begin();
2355 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
2357 if (edev->xkb.state) xkb_state_unref(edev->xkb.state);
2359 if (edev->xkb.keymap) xkb_map_unref(edev->xkb.keymap);
2362 if (edev->ecore_dev) ecore_device_del(edev->ecore_dev);
2363 if (edev->ecore_dev_list)
2364 EINA_LIST_FREE(edev->ecore_dev_list, dev)
2366 ecore_device_del(dev);
2369 if (edev->e_dev) g_object_unref(edev->e_dev);
2370 if (edev->e_dev_list)
2372 GList *glist = edev->e_dev_list;
2376 e_dev = glist->data;
2377 g_object_unref(e_dev);
2379 glist = g_list_next(glist);
2382 if (edev->path) eina_stringshare_del(edev->path);
2383 if (edev->device) libinput_device_unref(edev->device);
2384 if (edev->key_remap_hash) eina_hash_free(edev->key_remap_hash);
2385 if (edev->touch.coords)
2387 free(edev->touch.coords);
2388 edev->touch.coords = NULL;
2390 eina_stringshare_del(edev->output_name);
2392 ecore_thread_main_loop_end();
2398 _e_input_evdev_event_process(struct libinput_event *event)
2400 struct libinput_device *device;
2401 Eina_Bool ret = EINA_TRUE;
2403 device = libinput_event_get_device(event);
2404 switch (libinput_event_get_type(event))
2406 case LIBINPUT_EVENT_KEYBOARD_KEY:
2407 _device_handle_key(device, libinput_event_get_keyboard_event(event));
2409 case LIBINPUT_EVENT_POINTER_MOTION:
2410 _device_handle_pointer_motion(device,
2411 libinput_event_get_pointer_event(event));
2413 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
2414 _device_handle_pointer_motion_absolute(device,
2415 libinput_event_get_pointer_event(event));
2417 case LIBINPUT_EVENT_POINTER_BUTTON:
2418 _device_handle_button(device, libinput_event_get_pointer_event(event));
2420 case LIBINPUT_EVENT_POINTER_AXIS:
2421 #if !LIBINPUT_HAVE_SCROLL_VALUE_V120
2422 _device_handle_axis(device, libinput_event_get_pointer_event(event));
2425 #if LIBINPUT_HAVE_SCROLL_VALUE_V120
2426 case LIBINPUT_EVENT_POINTER_SCROLL_WHEEL:
2427 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_WHEEL);
2429 case LIBINPUT_EVENT_POINTER_SCROLL_FINGER:
2430 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_FINGER);
2432 case LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS:
2433 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_CONTINUOUS);
2436 case LIBINPUT_EVENT_TOUCH_DOWN:
2437 _device_handle_touch_down(device, libinput_event_get_touch_event(event));
2439 case LIBINPUT_EVENT_TOUCH_MOTION:
2440 _device_handle_touch_motion(device,
2441 libinput_event_get_touch_event(event));
2443 case LIBINPUT_EVENT_TOUCH_UP:
2444 _device_handle_touch_up(device, libinput_event_get_touch_event(event));
2446 case LIBINPUT_EVENT_TOUCH_CANCEL:
2447 _device_handle_touch_cancel(device, libinput_event_get_touch_event(event));
2449 case LIBINPUT_EVENT_TOUCH_FRAME:
2450 _device_handle_touch_frame(device, libinput_event_get_touch_event(event));
2452 case LIBINPUT_EVENT_TOUCH_AUX_DATA:
2453 _device_handle_touch_aux_data(device, libinput_event_get_touch_aux_data(event));
2464 * @brief Set the axis size of the given device.
2466 * @param dev The device to set the axis size to.
2467 * @param w The width of the axis.
2468 * @param h The height of the axis.
2470 * This function sets set the width @p w and height @p h of the axis
2471 * of device @p dev. If @p dev is a relative input device, a width and
2472 * height must set for it. If its absolute set the ioctl correctly, if
2473 * not, unsupported device.
2476 e_input_evdev_axis_size_set(E_Input_Evdev *edev, int w, int h)
2478 const char *sysname;
2483 enum libinput_config_status status;
2485 EINA_SAFETY_ON_NULL_RETURN(edev);
2486 EINA_SAFETY_ON_TRUE_RETURN((w == 0) || (h == 0));
2488 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
2489 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
2492 sysname = libinput_device_get_sysname(edev->device);
2494 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
2495 if (eina_list_count(devices) < 1) return;
2497 EINA_LIST_FREE(devices, device)
2499 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
2501 (sscanf(vals, "%f %f %f %f %f %f",
2502 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
2509 libinput_device_config_calibration_set_matrix(edev->device, cal);
2511 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
2512 ERR("Failed to apply calibration");
2515 eina_stringshare_del(device);
2520 EINTERN const char *
2521 e_input_evdev_name_get(E_Input_Evdev *evdev)
2523 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2524 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2526 return libinput_device_get_name(evdev->device);
2529 EINTERN const char *
2530 e_input_evdev_sysname_get(E_Input_Evdev *evdev)
2532 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2533 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2535 return libinput_device_get_sysname(evdev->device);
2539 e_input_evdev_key_remap_enable(E_Input_Evdev *edev, Eina_Bool enable)
2541 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2542 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2544 edev->key_remap_enabled = enable;
2546 if (enable == EINA_FALSE && edev->key_remap_hash)
2548 eina_hash_free(edev->key_remap_hash);
2549 edev->key_remap_hash = NULL;
2556 e_input_evdev_key_remap_set(E_Input_Evdev *edev, int *from_keys, int *to_keys, int num)
2560 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2561 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2562 EINA_SAFETY_ON_NULL_RETURN_VAL(from_keys, EINA_FALSE);
2563 EINA_SAFETY_ON_NULL_RETURN_VAL(to_keys, EINA_FALSE);
2564 EINA_SAFETY_ON_TRUE_RETURN_VAL(num <= 0, EINA_FALSE);
2565 EINA_SAFETY_ON_TRUE_RETURN_VAL(!edev->key_remap_enabled, EINA_FALSE);
2567 if (edev->key_remap_hash == NULL)
2568 edev->key_remap_hash = eina_hash_int32_new(NULL);
2570 if (edev->key_remap_hash == NULL)
2572 ERR("Failed to set remap key information : creating a hash is failed.");
2576 for (i = 0; i < num ; i++)
2578 if (!from_keys[i] || !to_keys[i])
2580 ERR("Failed to set remap key information : given arguments are invalid.");
2585 for (i = 0; i < num ; i++)
2587 eina_hash_add(edev->key_remap_hash, &from_keys[i], (void *)(intptr_t)to_keys[i]);
2594 e_input_evdev_wheel_click_angle_get(E_Input_Evdev *dev)
2596 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, -1);
2597 return libinput_device_config_scroll_get_wheel_click_angle(dev->device);
2601 e_input_evdev_touch_calibration_set(E_Input_Evdev *edev, float matrix[6])
2603 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2604 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2606 if (!libinput_device_config_calibration_has_matrix(edev->device) ||
2607 !libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_TOUCH))
2610 if (libinput_device_config_calibration_set_matrix(edev->device, matrix) !=
2611 LIBINPUT_CONFIG_STATUS_SUCCESS)
2613 WRN("Failed to set input transformation about device: %s\n",
2614 libinput_device_get_name(edev->device));
2622 e_input_evdev_mouse_accel_speed_set(E_Input_Evdev *edev, double speed)
2624 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2625 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2627 if (!libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
2630 if (!libinput_device_config_accel_is_available(edev->device))
2633 if (libinput_device_config_accel_set_speed(edev->device, speed) !=
2634 LIBINPUT_CONFIG_STATUS_SUCCESS)
2636 WRN("Failed to set mouse accel about device: %s\n",
2637 libinput_device_get_name(edev->device));
2644 EINTERN unsigned int
2645 e_input_evdev_touch_pressed_get(E_Input_Evdev *edev)
2647 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, 0x0);
2649 return edev->touch.pressed;
2653 e_input_evdev_seatname_get(E_Input_Evdev *evdev)
2655 struct libinput_seat *libinput_seat;
2656 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2657 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2659 libinput_seat = libinput_device_get_seat(evdev->device);
2661 return libinput_seat_get_logical_name(libinput_seat);
2665 e_input_evdev_seatname_set(E_Input_Evdev *evdev, const char *seatname)
2667 Eina_Bool res = EINA_FALSE;
2668 E_Input_Backend *input;
2670 EINA_SAFETY_ON_NULL_RETURN_VAL(seatname, EINA_FALSE);
2671 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, EINA_FALSE);
2672 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, EINA_FALSE);
2674 if (libinput_device_set_seat_logical_name(evdev->device, seatname) == 0)
2676 input = evdev->seat->input;
2677 if (!input) return EINA_FALSE;
2679 if (libinput_dispatch(input->libinput) != 0)
2681 ERR("Failed to dispatch libinput events: %m");
2686 /* process pending events */
2687 _input_events_process(input);