2 #include "e_input_intern.h"
3 #include "e_input_log.h"
4 #include "e_device_intern.h"
5 #include "e_keyrouter_private.h"
6 #include "e_input_event.h"
7 #include "e_devicemgr_intern.h"
8 #include "e_comp_screen_intern.h"
9 #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 g_mutex_init(&edev->xkb.keymap_mutex);
223 /* create keymap from xkb context */
224 g_mutex_lock(&edev->xkb.keymap_mutex);
225 edev->xkb.keymap = _e_input_device_cached_keymap_get(input->dev->xkb_ctx, NULL, 0);
226 if (!edev->xkb.keymap)
228 g_mutex_unlock(&edev->xkb.keymap_mutex);
229 ERR("Failed to create keymap: %m");
233 g_mutex_lock(&edev->xkb.state_mutex);
235 /* create xkb state */
236 if (!(edev->xkb.state = xkb_state_new(edev->xkb.keymap)))
238 g_mutex_unlock(&edev->xkb.state_mutex);
239 g_mutex_unlock(&edev->xkb.keymap_mutex);
240 ERR("Failed to create xkb state: %m");
244 g_mutex_unlock(&edev->xkb.state_mutex);
246 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CTRL);
247 if (xkb_idx != XKB_MOD_INVALID)
248 edev->xkb.ctrl_mask = 1 << xkb_idx;
250 edev->xkb.ctrl_mask = 0;
252 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_ALT);
253 if (xkb_idx != XKB_MOD_INVALID)
254 edev->xkb.alt_mask = 1 << xkb_idx;
256 edev->xkb.alt_mask = 0;
258 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_SHIFT);
259 if (xkb_idx != XKB_MOD_INVALID)
260 edev->xkb.shift_mask = 1 << xkb_idx;
262 edev->xkb.shift_mask = 0;
264 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_LOGO);
265 if (xkb_idx != XKB_MOD_INVALID)
266 edev->xkb.win_mask = 1 << xkb_idx;
268 edev->xkb.win_mask = 0;
270 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_SCROLL);
271 if (xkb_idx != XKB_MOD_INVALID)
272 edev->xkb.scroll_mask = 1 << xkb_idx;
274 edev->xkb.scroll_mask = 0;
276 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_NUM);
277 if (xkb_idx != XKB_MOD_INVALID)
278 edev->xkb.num_mask = 1 << xkb_idx;
280 edev->xkb.num_mask = 0;
282 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CAPS);
283 if (xkb_idx != XKB_MOD_INVALID)
284 edev->xkb.caps_mask = 1 << xkb_idx;
286 edev->xkb.caps_mask = 0;
288 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, "ISO_Level3_Shift");
289 if (xkb_idx != XKB_MOD_INVALID)
290 edev->xkb.altgr_mask = 1 << xkb_idx;
292 edev->xkb.altgr_mask = 0;
294 g_mutex_unlock(&edev->xkb.keymap_mutex);
298 _device_keysym_translate(xkb_keysym_t keysym, unsigned int modifiers, char *buffer, int bytes)
300 unsigned long hbytes = 0;
303 if (!keysym) return 0;
304 hbytes = (keysym >> 8);
309 (((keysym >= XKB_KEY_BackSpace) && (keysym <= XKB_KEY_Clear)) ||
310 (keysym == XKB_KEY_Return) || (keysym == XKB_KEY_Escape) ||
311 (keysym == XKB_KEY_KP_Space) || (keysym == XKB_KEY_KP_Tab) ||
312 (keysym == XKB_KEY_KP_Enter) ||
313 ((keysym >= XKB_KEY_KP_Multiply) && (keysym <= XKB_KEY_KP_9)) ||
314 (keysym == XKB_KEY_KP_Equal) || (keysym == XKB_KEY_Delete))))))
317 if (keysym == XKB_KEY_KP_Space)
318 c = (XKB_KEY_space & 0x7F);
319 else if (hbytes == 0xFF)
324 if (modifiers & ECORE_EVENT_MODIFIER_CTRL)
326 if (((c >= '@') && (c < '\177')) || c == ' ')
330 else if ((c >= '3') && (c <= '7'))
342 _device_modifiers_update_device(E_Input_Evdev *edev, E_Input_Evdev *from)
346 g_mutex_lock(&from->xkb.state_mutex);
348 edev->xkb.depressed =
349 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_DEPRESSED);
351 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LATCHED);
353 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LOCKED);
355 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_EFFECTIVE);
357 g_mutex_unlock(&from->xkb.state_mutex);
359 mask = (edev->xkb.depressed | edev->xkb.latched);
361 if (mask & from->xkb.ctrl_mask)
362 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_CTRL;
363 if (mask & from->xkb.alt_mask)
364 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALT;
365 if (mask & from->xkb.shift_mask)
366 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
367 if (mask & from->xkb.win_mask)
368 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_WIN;
369 if (mask & from->xkb.scroll_mask)
370 edev->xkb.modifiers |= ECORE_EVENT_LOCK_SCROLL;
371 if (mask & from->xkb.num_mask)
372 edev->xkb.modifiers |= ECORE_EVENT_LOCK_NUM;
373 if (mask & from->xkb.caps_mask)
374 edev->xkb.modifiers |= ECORE_EVENT_LOCK_CAPS;
375 if (mask & from->xkb.altgr_mask)
376 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALTGR;
380 _device_modifiers_update(E_Input_Evdev *edev)
385 edev->xkb.modifiers = 0;
387 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
388 _device_modifiers_update_device(edev, edev);
391 EINA_LIST_FOREACH(edev->seat->devices, l, ed)
393 if (!(ed->caps & E_INPUT_SEAT_KEYBOARD)) continue;
394 _device_modifiers_update_device(edev, ed);
401 _device_remapped_key_get(E_Input_Evdev *edev, int code)
405 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, code);
406 if (!edev->key_remap_enabled) return code;
407 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->key_remap_hash, code);
409 ret = eina_hash_find(edev->key_remap_hash, &code);
411 if (ret) code = (int)(intptr_t)ret;
417 e_input_evdev_get_e_device(const char *path, Ecore_Device_Class clas)
419 const GList *dev_list = NULL;
421 E_Device *dev = NULL;
422 const char *identifier;
424 if (!path) return NULL;
426 dev_list = e_device_list_get();
427 if (!dev_list) return NULL;
434 identifier = e_device_identifier_get(dev);
435 if (!identifier) continue;
436 if ((e_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
445 EINTERN Ecore_Device *
446 e_input_evdev_get_ecore_device(const char *path, Ecore_Device_Class clas)
448 const Eina_List *dev_list = NULL;
450 Ecore_Device *dev = NULL;
451 const char *identifier;
453 if (!path) return NULL;
455 dev_list = ecore_device_list();
456 if (!dev_list) return NULL;
457 EINA_LIST_FOREACH(dev_list, l, dev)
460 identifier = ecore_device_identifier_get(dev);
461 if (!identifier) continue;
462 if ((ecore_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
469 _e_input_event_mouse_move_cb_free(void *data EINA_UNUSED, void *event)
471 Ecore_Event_Mouse_Move *ev = event;
473 if (ev->dev) ecore_device_unref(ev->dev);
479 _e_input_event_mouse_relative_move_cb_free(void *data EINA_UNUSED, void *event)
481 Ecore_Event_Mouse_Relative_Move *ev = event;
483 if (ev->dev) ecore_device_unref(ev->dev);
489 _e_input_event_mouse_wheel_cb_free(void *data EINA_UNUSED, void *event)
491 Ecore_Event_Mouse_Wheel *ev = event;
493 if (ev->dev) ecore_device_unref(ev->dev);
499 _e_input_event_mouse_button_cb_free(void *data EINA_UNUSED, void *event)
501 Ecore_Event_Mouse_Button *ev = event;
503 if (ev->dev) ecore_device_unref(ev->dev);
509 _e_input_event_key_cb_free(void *data EINA_UNUSED, void *event)
511 Ecore_Event_Key *ev = event;
513 if (e_input_thread_mode_get())
515 if (ev->dev) g_object_unref(ev->dev);
519 if (ev->dev) ecore_device_unref(ev->dev);
522 if (ev->data) E_FREE(ev->data);
528 _device_handle_key(struct libinput_device *device, struct libinput_event_keyboard *event)
531 E_Input_Backend *input;
533 uint32_t code, nsyms;
534 const xkb_keysym_t *syms;
535 enum libinput_key_state state;
537 xkb_keysym_t sym = XKB_KEY_NoSymbol;
538 char key[256] = {0, }, keyname[256] = {0, }, compose_buffer[256] = {0, };
540 char *tmp = NULL, *compose = NULL;
541 E_Keyrouter_Event_Data *key_data;
542 Ecore_Device *ecore_dev = NULL, *data;
543 E_Device *e_dev = NULL, *e_dev_data;
544 Eina_List *l = NULL, *l_next = NULL;
546 E_Comp_Config *comp_conf = NULL;
547 int *pressed_keycode = NULL, *idata = NULL;
548 Eina_Bool dup_found = EINA_FALSE;
549 const char *device_name = NULL;
550 Ecore_Device_Subclass device_subclas = ECORE_DEVICE_SUBCLASS_NONE;
552 if (!(edev = libinput_device_get_user_data(device)))
557 if (!(input = edev->seat->input))
562 if (!e_input_thread_mode_get())
564 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
565 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
567 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
569 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_KEYBOARD)
578 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
579 ecore_dev = edev->ecore_dev;
584 ERR("Failed to get source ecore device from event !\n");
588 device_name = ecore_device_name_get(ecore_dev);
589 device_subclas = ecore_device_subclass_get(ecore_dev);
593 if (edev->e_dev) e_dev = edev->e_dev;
594 else if (edev->e_dev_list && g_list_length(edev->e_dev_list) > 0)
596 glist = edev->e_dev_list;
599 e_dev_data = glist->data;
600 if (e_device_class_get(e_dev_data) == ECORE_DEVICE_CLASS_KEYBOARD)
606 glist = g_list_next(glist);
611 edev->e_dev = e_input_evdev_get_e_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
617 ERR("Failed to get source e device from event !\n");
621 device_name = e_device_name_get(e_dev);
622 device_subclas = e_device_subclass_get(e_dev);
625 timestamp = libinput_event_keyboard_get_time(event);
626 code = libinput_event_keyboard_get_key(event);
627 code = _device_remapped_key_get(edev, code + 8);
628 state = libinput_event_keyboard_get_key_state(event);
629 key_count = libinput_event_keyboard_get_seat_key_count(event);
631 if (state == LIBINPUT_KEY_STATE_PRESSED)
633 if ((edev->seat->dev->blocked & E_INPUT_SEAT_KEYBOARD) ||
634 (edev->seat->dev->server_blocked & E_INPUT_SEAT_KEYBOARD))
636 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
637 ELOGF("Key", "Press (keycode: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
638 code, device_name, blocked_client,
639 edev->seat->dev->server_blocked);
643 /* FIXME: Currently to maintain press/release event pair during input block,
644 * used Eina_List and this is method used in devicemgr module.
645 * But we need to consider which way is better to maintain key press/release pair.
648 EINA_LIST_FOREACH(edev->xkb.pressed_keys, l, idata)
652 dup_found = EINA_TRUE;
658 pressed_keycode = E_NEW(int, 1);
659 EINA_SAFETY_ON_NULL_RETURN(pressed_keycode);
660 *pressed_keycode = code;
662 edev->xkb.pressed_keys = eina_list_append(edev->xkb.pressed_keys, pressed_keycode);
667 dup_found = EINA_FALSE;
668 EINA_LIST_FOREACH_SAFE(edev->xkb.pressed_keys, l, l_next, idata)
672 edev->xkb.pressed_keys = eina_list_remove_list(edev->xkb.pressed_keys, l);
674 dup_found = EINA_TRUE;
680 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
681 ELOGF("Key", "Release (keycode: %d, device: %s) is blocked by %p", NULL,
682 code, device_name, blocked_client);
687 /* ignore key events that are not seat wide state changes */
688 if (((state == LIBINPUT_KEY_STATE_PRESSED) && (key_count != 1)) ||
689 ((state == LIBINPUT_KEY_STATE_RELEASED) && (key_count != 0)))
694 e_input_keyboard_grab_key_cb func = e_input_keyboard_grab_key_handler_get();
697 if (e_devicemgr_keyboard_grab_subtype_is_grabbed(device_subclas))
699 if (!e_input_thread_mode_get())
700 func(code, state, timestamp, ecore_dev);
702 func(code, state, timestamp, e_dev);
707 g_mutex_lock(&edev->xkb.state_mutex);
708 xkb_state_update_key(edev->xkb.state, code,
709 (state ? XKB_KEY_DOWN : XKB_KEY_UP));
711 /* get the keysym for this code */
712 nsyms = xkb_key_get_syms(edev->xkb.state, code, &syms);
713 g_mutex_unlock(&edev->xkb.state_mutex);
715 if (nsyms == 1) sym = syms[0];
717 /* If no keysym was found, name it "Keycode-NNN" */
718 if (sym == XKB_KEY_NoSymbol)
719 snprintf(key, sizeof(key), "Keycode-%u", code);
722 /* get the keyname for this sym */
723 xkb_keysym_get_name(sym, key, sizeof(key));
728 /* If no keyname was found, name it "Keycode-NNN" */
729 snprintf(keyname, sizeof(keyname), "Keycode-%u", code);
733 memcpy(keyname, key, sizeof(keyname));
736 /* if shift is active, we need to transform the key to lower */
737 g_mutex_lock(&edev->xkb.keymap_mutex);
738 g_mutex_lock(&edev->xkb.state_mutex);
739 if (xkb_state_mod_index_is_active(edev->xkb.state,
740 xkb_map_mod_get_index(edev->xkb.keymap,
742 XKB_STATE_MODS_EFFECTIVE))
744 if (keyname[0] != '\0')
745 keyname[0] = tolower(keyname[0]);
747 g_mutex_unlock(&edev->xkb.keymap_mutex);
748 g_mutex_unlock(&edev->xkb.state_mutex);
750 if (_device_keysym_translate(sym, edev->xkb.modifiers,
751 compose_buffer, sizeof(compose_buffer)))
753 compose = eina_str_convert("ISO8859-1", "UTF-8", compose_buffer);
756 ERR("E Input cannot convert input key string '%s' to UTF-8. "
757 "Is Eina built with iconv support?", compose_buffer);
763 if (!compose) compose = compose_buffer;
765 e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) +
766 ((compose[0] != '\0') ? strlen(compose) : 0) + 3);
772 key_data = E_NEW(E_Keyrouter_Event_Data, 1);
780 e->keyname = (char *)(e + 1);
781 e->key = e->keyname + strlen(keyname) + 1;
782 e->compose = strlen(compose) ? e->key + strlen(key) + 1 : NULL;
783 e->string = e->compose;
785 strncpy((char *)e->keyname, keyname, strlen(keyname));
786 strncpy((char *)e->key, key, strlen(key));
787 if (strlen(compose)) strncpy((char *)e->compose, compose, strlen(compose));
789 e->window = (Ecore_Window)input->dev->window;
790 e->event_window = (Ecore_Window)input->dev->window;
791 e->root_window = (Ecore_Window)input->dev->window;
792 e->timestamp = timestamp;
797 _device_modifiers_update(edev);
799 e->modifiers = edev->xkb.modifiers;
801 comp_conf = e_comp_config_get();
803 if (comp_conf && comp_conf->input_log_enable)
804 ELOGF("Key", "%s (keyname: %s, keycode: %d, timestamp: %u, device: %s)", NULL, state?"Press":"Release", e->keyname, e->keycode, e->timestamp, device_name);
806 if (e_config->key_input_ttrace_enable)
808 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));
809 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));
812 _e_input_key_event_list_add(e);
814 if (e_input_thread_mode_get())
816 e->dev = (Eo *)g_object_ref(e_dev);
817 e_input_event_add(input->event_source, state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
821 e->dev = ecore_device_ref(ecore_dev);
822 ecore_event_add(state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
825 if (e_config->key_input_ttrace_enable)
828 ELOGF("INPUT", "ECORE_EVENT_KEY|E|", NULL);
835 _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event)
837 E_Input_Backend *input;
838 Ecore_Event_Mouse_Move *ev;
839 Ecore_Device *ecore_dev = NULL, *data, *detent_data = NULL;
841 int x = 0, y = 0, w = 0, h = 0;
843 if (!(input = edev->seat->input)) return;
845 ecore_thread_main_loop_begin();
847 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
848 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
850 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
852 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
857 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
862 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
864 ecore_dev = detent_data;
869 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
870 ecore_dev = edev->ecore_dev;
875 ERR("Failed to get source ecore device from event !\n");
878 else if ((detent_data == ecore_dev) || e_devicemgr_detent_is_detent(ecore_device_name_get(ecore_dev)))
880 /* Do not process detent device's move events. */
884 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
886 _device_configured_size_get(edev, &x, &y, &w, &h);
888 if (edev->seat->ptr.ix < x)
889 edev->seat->ptr.dx = edev->seat->ptr.ix = x;
890 else if (edev->seat->ptr.ix >= (x + w))
891 edev->seat->ptr.dx = edev->seat->ptr.ix = (x + w - 1);
893 if (edev->seat->ptr.iy < y)
894 edev->seat->ptr.dy = edev->seat->ptr.iy = y;
895 else if (edev->seat->ptr.iy >= (y + h))
896 edev->seat->ptr.dy = edev->seat->ptr.iy = (y + h - 1);
898 edev->mouse.dx = edev->seat->ptr.dx;
899 edev->mouse.dy = edev->seat->ptr.dy;
901 ev->window = (Ecore_Window)input->dev->window;
902 ev->event_window = (Ecore_Window)input->dev->window;
903 ev->root_window = (Ecore_Window)input->dev->window;
904 if (event) ev->timestamp = libinput_event_pointer_get_time(event);
907 _device_modifiers_update(edev);
908 ev->modifiers = edev->xkb.modifiers;
910 ev->x = edev->seat->ptr.ix;
911 ev->y = edev->seat->ptr.iy;
915 ev->multi.device = edev->mt_slot;
916 ev->multi.radius = 1;
917 ev->multi.radius_x = 1;
918 ev->multi.radius_y = 1;
919 ev->multi.pressure = 1.0;
920 ev->multi.angle = 0.0;
923 ev->multi.root.x = ev->x;
924 ev->multi.root.y = ev->y;
926 ev->dev = ecore_device_ref(ecore_dev);
928 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
931 ecore_thread_main_loop_end();
935 _e_input_pointer_motion_post(E_Input_Evdev *edev)
937 _device_pointer_motion(edev, NULL);
941 _device_pointer_relative_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event, double dx[2], double dy[2])
943 E_Input_Backend *input;
944 Ecore_Event_Mouse_Relative_Move *ev;
945 Ecore_Device *ecore_dev = NULL, *data, *detent_data = NULL;
947 E_Comp_Config *comp_conf;
949 if (!(input = edev->seat->input)) return;
951 ecore_thread_main_loop_begin();
953 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
954 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
956 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
958 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
963 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
968 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
970 ecore_dev = detent_data;
975 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
976 ecore_dev = edev->ecore_dev;
981 ERR("Failed to get source ecore device from event !\n");
984 else if ((detent_data == ecore_dev) || e_devicemgr_detent_is_detent(ecore_device_name_get(ecore_dev)))
986 /* Do not process detent device's move events. */
990 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Relative_Move)))) return;
992 ev->window = (Ecore_Window)input->dev->window;
993 ev->event_window = (Ecore_Window)input->dev->window;
994 if (event) ev->timestamp = libinput_event_pointer_get_time(event);
996 ev->modifiers = edev->xkb.modifiers;
1000 ev->dx_unaccel = (int)dx[1];
1001 ev->dy_unaccel = (int)dy[1];
1003 ev->dev = ecore_device_ref(ecore_dev);
1005 comp_conf = e_comp_config_get();
1006 if (comp_conf && comp_conf->input_log_enable)
1007 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));
1009 ecore_event_add(ECORE_EVENT_MOUSE_RELATIVE_MOVE, ev, _e_input_event_mouse_relative_move_cb_free, NULL);
1012 ecore_thread_main_loop_end();
1016 _device_pointer_motion_send(E_Input_Evdev *edev, struct libinput_event_pointer *event, double dx[2], double dy[2])
1018 e_input_relative_motion_cb func = e_input_relative_motion_handler_get();
1021 //func(dx, dy, time_us);
1022 _device_pointer_relative_motion(edev, event, dx, dy);
1026 double seat_dx, seat_dy, temp;
1027 if (edev->disable_acceleration)
1038 if (edev->seat->ptr.swap)
1044 if (edev->seat->ptr.invert_x)
1046 if (edev->seat->ptr.invert_y)
1049 edev->seat->ptr.dx += seat_dx;
1050 edev->seat->ptr.dy += seat_dy;
1052 edev->mouse.dx = edev->seat->ptr.dx;
1053 edev->mouse.dy = edev->seat->ptr.dy;
1055 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
1056 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
1061 edev->seat->ptr.ix = edev->seat->ptr.dx;
1062 edev->seat->ptr.iy = edev->seat->ptr.dy;
1064 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1065 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1070 _device_pointer_motion(edev, event);
1075 _device_handle_pointer_motion(struct libinput_device *device, struct libinput_event_pointer *event)
1077 E_Input_Evdev *edev;
1078 double delta_x[2]; /* delta_x[0] for accelerated, delta_x[1] for unaccelerated */
1079 double delta_y[2]; /* delta_y[0] for accelerated, delta_y[1] for unaccelerated */
1081 if (!(edev = libinput_device_get_user_data(device)))
1086 delta_x[0] = libinput_event_pointer_get_dx(event);
1087 delta_x[1] = libinput_event_pointer_get_dx_unaccelerated(event);
1088 delta_y[0] = libinput_event_pointer_get_dy(event);
1089 delta_y[1] = libinput_event_pointer_get_dy_unaccelerated(event);
1091 _device_pointer_motion_send(edev, event, &delta_x[0], &delta_y[0]);
1095 _device_handle_pointer_motion_absolute(struct libinput_device *device, struct libinput_event_pointer *event)
1097 E_Input_Evdev *edev;
1100 if (!(edev = libinput_device_get_user_data(device)))
1105 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
1107 edev->mouse.dx = edev->seat->ptr.dx =
1108 libinput_event_pointer_get_absolute_x_transformed(event, w);
1109 edev->mouse.dy = edev->seat->ptr.dy =
1110 libinput_event_pointer_get_absolute_y_transformed(event, h);
1112 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
1113 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
1118 edev->seat->ptr.ix = edev->seat->ptr.dx;
1119 edev->seat->ptr.iy = edev->seat->ptr.dy;
1121 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1122 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1127 _device_pointer_motion(edev, event);
1131 _device_handle_button(struct libinput_device *device, struct libinput_event_pointer *event)
1133 E_Input_Evdev *edev;
1134 E_Input_Backend *input;
1135 Ecore_Event_Mouse_Button *ev;
1136 enum libinput_button_state state;
1137 uint32_t button, timestamp;
1138 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1140 E_Comp_Config *comp_conf = NULL;
1142 if (!(edev = libinput_device_get_user_data(device)))
1146 if (!(input = edev->seat->input))
1151 ecore_thread_main_loop_begin();
1153 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1154 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1156 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1158 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1163 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1168 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1170 ecore_dev = detent_data;
1175 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1176 ecore_dev = edev->ecore_dev;
1181 ERR("Failed to get source ecore device from event !\n");
1185 state = libinput_event_pointer_get_button_state(event);
1186 button = libinput_event_pointer_get_button(event);
1187 timestamp = libinput_event_pointer_get_time(event);
1189 button = ((button & 0x00F) + 1);
1190 if (button == 3) button = 2;
1191 else if (button == 2) button = 3;
1193 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
1197 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1198 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1201 ELOGF("Mouse", "Button Press (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
1202 button, ecore_device_name_get(ecore_dev), blocked_client,
1203 edev->seat->dev->server_blocked);
1208 edev->mouse.pressed_button |= (1 << button);
1213 if (!(edev->mouse.pressed_button & (1 << button)))
1215 ELOGF("Mouse", "Button Release (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
1216 button, ecore_device_name_get(ecore_dev), blocked_client,
1217 edev->seat->dev->server_blocked);
1220 edev->mouse.pressed_button &= ~(1 << button);
1223 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button))))
1228 ev->window = (Ecore_Window)input->dev->window;
1229 ev->event_window = (Ecore_Window)input->dev->window;
1230 ev->root_window = (Ecore_Window)input->dev->window;
1231 ev->timestamp = timestamp;
1232 ev->same_screen = 1;
1234 _device_modifiers_update(edev);
1235 ev->modifiers = edev->xkb.modifiers;
1237 ev->x = edev->seat->ptr.ix;
1238 ev->y = edev->seat->ptr.iy;
1242 ev->multi.device = edev->mt_slot;
1243 ev->multi.radius = 1;
1244 ev->multi.radius_x = 1;
1245 ev->multi.radius_y = 1;
1246 ev->multi.pressure = 1.0;
1247 ev->multi.angle = 0.0;
1248 ev->multi.x = ev->x;
1249 ev->multi.y = ev->y;
1250 ev->multi.root.x = ev->x;
1251 ev->multi.root.y = ev->y;
1252 ev->dev = ecore_device_ref(ecore_dev);
1256 unsigned int current;
1258 current = timestamp;
1259 edev->mouse.did_double = EINA_FALSE;
1260 edev->mouse.did_triple = EINA_FALSE;
1262 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1263 (button == edev->mouse.prev_button))
1265 edev->mouse.did_double = EINA_TRUE;
1266 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1267 (button == edev->mouse.last_button))
1269 edev->mouse.did_triple = EINA_TRUE;
1270 edev->mouse.prev = 0;
1271 edev->mouse.last = 0;
1276 edev->mouse.last = edev->mouse.prev;
1277 edev->mouse.prev = current;
1278 edev->mouse.last_button = edev->mouse.prev_button;
1279 edev->mouse.prev_button = button;
1282 ev->buttons = button;
1284 if (edev->mouse.did_double)
1285 ev->double_click = 1;
1286 if (edev->mouse.did_triple)
1287 ev->triple_click = 1;
1289 comp_conf = e_comp_config_get();
1290 if (comp_conf && comp_conf->input_log_enable)
1291 ELOGF("Mouse", "Button %s (btn: %d, device: %s)", NULL, state?"Press":"Release", button, ecore_device_name_get(ev->dev));
1294 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, _e_input_event_mouse_button_cb_free, NULL);
1296 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, _e_input_event_mouse_button_cb_free, NULL);
1299 ecore_thread_main_loop_end();
1302 #if !LIBINPUT_HAVE_SCROLL_VALUE_V120
1304 _axis_value_get(struct libinput_event_pointer *pointer_event, enum libinput_pointer_axis axis)
1306 enum libinput_pointer_axis_source source;
1307 double value = 0.0, value_discrete = 0.0;
1309 E_Comp_Config *comp_conf = NULL;
1311 comp_conf = e_comp_config_get();
1312 source = libinput_event_pointer_get_axis_source(pointer_event);
1315 case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL:
1316 value_discrete = libinput_event_pointer_get_axis_value_discrete(pointer_event, axis);
1317 value = libinput_event_pointer_get_axis_value(pointer_event, axis);
1318 if (comp_conf && comp_conf->input_log_enable)
1320 ELOGF("Axis", "SOURCE_WHEEL discrete: %lf (cf. value: %lf)", NULL, value_discrete, value);
1322 ret = (int)value_discrete;
1324 case LIBINPUT_POINTER_AXIS_SOURCE_FINGER:
1325 case LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS:
1326 value = libinput_event_pointer_get_axis_value(pointer_event, axis);
1327 if (comp_conf && comp_conf->input_log_enable)
1329 ELOGF("Axis", "SOURCE_FINGER/CONTINUOUS value: %lf", NULL, value);
1331 if (value >= E_INPUT_FINGER_SCROLL_THRESHOLD)
1333 else if (value <= E_INPUT_FINGER_SCROLL_THRESHOLD * (-1))
1346 _device_handle_axis(struct libinput_device *device, struct libinput_event_pointer *event)
1348 E_Input_Evdev *edev;
1349 E_Input_Backend *input;
1350 Ecore_Event_Mouse_Wheel *ev;
1352 enum libinput_pointer_axis axis;
1353 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1355 E_Comp_Config *comp_conf = NULL;
1356 int direction = 0, z = 0;
1358 if (!(edev = libinput_device_get_user_data(device)))
1362 if (!(input = edev->seat->input))
1367 ecore_thread_main_loop_begin();
1369 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1370 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1372 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1374 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1379 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1384 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1386 ecore_dev = detent_data;
1391 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1392 ecore_dev = edev->ecore_dev;
1397 ERR("Failed to get source ecore device from event !\n");
1401 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1402 if (libinput_event_pointer_has_axis(event, axis))
1403 z = _axis_value_get(event, axis);
1405 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1406 if (libinput_event_pointer_has_axis(event, axis))
1409 z = _axis_value_get(event, axis);
1414 ELOGF("Mouse", "Axis event is ignored since it has zero value", NULL);
1418 comp_conf = e_comp_config_get();
1419 if (comp_conf && comp_conf->e_wheel_click_angle)
1421 z = (int)(z * comp_conf->e_wheel_click_angle);
1424 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1425 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1427 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
1430 ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1431 direction, z, blocked_client, edev->seat->dev->server_blocked);
1433 ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1434 direction, z, blocked_client, edev->seat->dev->server_blocked);
1439 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1444 timestamp = libinput_event_pointer_get_time(event);
1446 ev->window = (Ecore_Window)input->dev->window;
1447 ev->event_window = (Ecore_Window)input->dev->window;
1448 ev->root_window = (Ecore_Window)input->dev->window;
1449 ev->timestamp = timestamp;
1450 ev->same_screen = 1;
1452 _device_modifiers_update(edev);
1453 ev->modifiers = edev->xkb.modifiers;
1455 ev->x = edev->seat->ptr.ix;
1456 ev->y = edev->seat->ptr.iy;
1460 ev->direction = direction;
1462 if (comp_conf && comp_conf->input_log_enable)
1465 ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1467 ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1471 ev->dev = ecore_device_ref(ecore_dev);
1472 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1475 ecore_thread_main_loop_end();
1479 #if LIBINPUT_HAVE_SCROLL_VALUE_V120
1481 _scroll_value_get(struct libinput_event_pointer *pointer_event, enum libinput_pointer_axis axis, E_Input_Axis_Source source)
1484 double value_v120 = 0.0;
1486 E_Comp_Config *comp_conf = NULL;
1488 comp_conf = e_comp_config_get();
1491 case E_INPUT_AXIS_SOURCE_WHEEL:
1492 value_v120 = libinput_event_pointer_get_scroll_value_v120(pointer_event, axis);
1493 value = libinput_event_pointer_get_scroll_value(pointer_event, axis);
1494 if (comp_conf && comp_conf->input_log_enable)
1496 ELOGF("Scroll", "SOURCE_WHEEL value_v120: %lf (cf. value: %lf)", NULL, value_v120, value);
1498 if (((int)value_v120 % E_INPUT_POINTER_AXIS_DISCRETE_STEP) != 0)
1500 ERR("Wheel movements should be multiples (or fractions) of 120!\n");
1505 ret = value_v120 / E_INPUT_POINTER_AXIS_DISCRETE_STEP;
1508 case E_INPUT_AXIS_SOURCE_FINGER:
1509 case E_INPUT_AXIS_SOURCE_CONTINUOUS:
1510 value = libinput_event_pointer_get_scroll_value(pointer_event, axis);
1511 if (comp_conf && comp_conf->input_log_enable)
1513 ELOGF("Scroll", "SOURCE_FINGER/CONTINUOUS value: %lf", NULL, value);
1515 if (value >= E_INPUT_FINGER_SCROLL_THRESHOLD)
1517 else if (value <= E_INPUT_FINGER_SCROLL_THRESHOLD * (-1))
1530 _device_handle_axis_v120(struct libinput_device *device, struct libinput_event_pointer *event, E_Input_Axis_Source source)
1532 E_Input_Evdev *edev;
1533 E_Input_Backend *input;
1534 Ecore_Event_Mouse_Wheel *ev;
1536 enum libinput_pointer_axis axis;
1537 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1539 E_Comp_Config *comp_conf = NULL;
1540 int direction = 0, z = 0;
1542 if (!(edev = libinput_device_get_user_data(device)))
1546 if (!(input = edev->seat->input))
1551 ecore_thread_main_loop_begin();
1553 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1554 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1556 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1558 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1563 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1568 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1570 ecore_dev = detent_data;
1575 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1576 ecore_dev = edev->ecore_dev;
1581 ERR("Failed to get source ecore device from event !\n");
1585 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1586 if (libinput_event_pointer_has_axis(event, axis))
1587 z = _scroll_value_get(event, axis, source);
1589 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1590 if (libinput_event_pointer_has_axis(event, axis))
1593 z = _scroll_value_get(event, axis, source);
1598 ELOGF("Mouse", "Scroll event is ignored since it has zero value", NULL);
1602 comp_conf = e_comp_config_get();
1603 if (comp_conf && comp_conf->e_wheel_click_angle)
1605 z = (int)(z * comp_conf->e_wheel_click_angle);
1608 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1609 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1611 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
1613 ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1614 direction, z, blocked_client, edev->seat->dev->server_blocked);
1616 ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1617 direction, z, blocked_client, edev->seat->dev->server_blocked);
1622 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1627 timestamp = libinput_event_pointer_get_time(event);
1629 ev->window = (Ecore_Window)input->dev->window;
1630 ev->event_window = (Ecore_Window)input->dev->window;
1631 ev->root_window = (Ecore_Window)input->dev->window;
1632 ev->timestamp = timestamp;
1633 ev->same_screen = 1;
1635 _device_modifiers_update(edev);
1636 ev->modifiers = edev->xkb.modifiers;
1638 ev->x = edev->seat->ptr.ix;
1639 ev->y = edev->seat->ptr.iy;
1643 ev->direction = direction;
1645 if (comp_conf && comp_conf->input_log_enable)
1648 ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1650 ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1653 ev->dev = ecore_device_ref(ecore_dev);
1654 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1657 ecore_thread_main_loop_end();
1662 _device_handle_touch_event_send(E_Input_Evdev *edev, struct libinput_event_touch *event, int state)
1664 E_Input_Backend *input;
1665 Ecore_Event_Mouse_Button *ev;
1666 uint32_t timestamp, button = 0;
1667 Ecore_Device *ecore_dev = NULL, *data;
1671 if (!(input = edev->seat->input)) return;
1673 ecore_thread_main_loop_begin();
1675 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1676 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1678 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1680 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1689 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1690 ecore_dev = edev->ecore_dev;
1695 ERR("Failed to get source ecore device from event !\n");
1699 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) goto end;
1701 timestamp = libinput_event_touch_get_time(event);
1703 ev->window = (Ecore_Window)input->dev->window;
1704 ev->event_window = (Ecore_Window)input->dev->window;
1705 ev->root_window = (Ecore_Window)input->dev->window;
1706 ev->timestamp = timestamp;
1707 ev->same_screen = 1;
1709 _device_modifiers_update(edev);
1710 ev->modifiers = edev->xkb.modifiers;
1712 ev->x = edev->seat->ptr.ix;
1713 ev->y = edev->seat->ptr.iy;
1717 ev->multi.device = edev->mt_slot;
1718 ev->multi.radius = 1;
1719 ev->multi.radius_x = 1;
1720 ev->multi.radius_y = 1;
1721 ev->multi.pressure = 1.0;
1722 ev->multi.angle = 0.0;
1723 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1724 if (libinput_event_get_type(libinput_event_touch_get_base_event(event))
1725 == LIBINPUT_EVENT_TOUCH_DOWN)
1727 if (libinput_event_touch_has_minor(event))
1728 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1729 if (libinput_event_touch_has_major(event))
1730 ev->multi.radius_y = libinput_event_touch_get_major(event);
1731 if (libinput_event_touch_has_pressure(event))
1732 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1733 if (libinput_event_touch_has_orientation(event))
1734 ev->multi.angle = libinput_event_touch_get_orientation(event);
1737 ev->multi.x = ev->x;
1738 ev->multi.y = ev->y;
1739 ev->multi.root.x = ev->x;
1740 ev->multi.root.y = ev->y;
1741 ev->dev = ecore_device_ref(ecore_dev);
1743 if (state == ECORE_EVENT_MOUSE_BUTTON_DOWN)
1745 unsigned int current;
1747 current = timestamp;
1748 edev->mouse.did_double = EINA_FALSE;
1749 edev->mouse.did_triple = EINA_FALSE;
1751 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1752 (button == edev->mouse.prev_button))
1754 edev->mouse.did_double = EINA_TRUE;
1755 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1756 (button == edev->mouse.last_button))
1758 edev->mouse.did_triple = EINA_TRUE;
1759 edev->mouse.prev = 0;
1760 edev->mouse.last = 0;
1765 edev->mouse.last = edev->mouse.prev;
1766 edev->mouse.prev = current;
1767 edev->mouse.last_button = edev->mouse.prev_button;
1768 edev->mouse.prev_button = button;
1769 edev->touch.pressed |= (1 << ev->multi.device);
1773 edev->touch.pressed &= ~(1 << ev->multi.device);
1776 ev->buttons = ((button & 0x00F) + 1);
1778 if (edev->mouse.did_double)
1779 ev->double_click = 1;
1780 if (edev->mouse.did_triple)
1781 ev->triple_click = 1;
1783 ecore_event_add(state, ev, _e_input_event_mouse_button_cb_free, NULL);
1786 ecore_thread_main_loop_end();
1790 _device_handle_touch_motion_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1792 E_Input_Backend *input;
1793 Ecore_Event_Mouse_Move *ev;
1794 Ecore_Device *ecore_dev = NULL, *data;
1798 if (!(input = edev->seat->input)) return;
1800 ecore_thread_main_loop_begin();
1802 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1803 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1805 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1807 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1816 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1817 ecore_dev = edev->ecore_dev;
1822 ERR("Failed to get source ecore device from event !\n");
1826 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) goto end;
1828 ev->window = (Ecore_Window)input->dev->window;
1829 ev->event_window = (Ecore_Window)input->dev->window;
1830 ev->root_window = (Ecore_Window)input->dev->window;
1831 ev->timestamp = libinput_event_touch_get_time(event);
1832 ev->same_screen = 1;
1834 _device_modifiers_update(edev);
1835 ev->modifiers = edev->xkb.modifiers;
1837 ev->x = edev->seat->ptr.ix;
1838 ev->y = edev->seat->ptr.iy;
1842 ev->multi.device = edev->mt_slot;
1843 ev->multi.radius = 1;
1844 ev->multi.radius_x = 1;
1845 ev->multi.radius_y = 1;
1846 ev->multi.pressure = 1.0;
1847 ev->multi.angle = 0.0;
1848 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1849 if (libinput_event_touch_has_minor(event))
1850 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1851 if (libinput_event_touch_has_major(event))
1852 ev->multi.radius_y = libinput_event_touch_get_major(event);
1853 if (libinput_event_touch_has_pressure(event))
1854 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1855 if (libinput_event_touch_has_orientation(event))
1856 ev->multi.angle = libinput_event_touch_get_orientation(event);
1858 ev->multi.x = ev->x;
1859 ev->multi.y = ev->y;
1860 ev->multi.root.x = ev->x;
1861 ev->multi.root.y = ev->y;
1862 ev->dev = ecore_device_ref(ecore_dev);
1864 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
1867 ecore_thread_main_loop_end();
1871 _device_handle_touch_cancel_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1873 E_Input_Backend *input;
1874 Ecore_Event_Mouse_Button *ev;
1875 uint32_t timestamp, button = 0;
1876 Ecore_Device *ecore_dev = NULL, *data;
1880 if (!(input = edev->seat->input)) return;
1882 ecore_thread_main_loop_begin();
1884 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1885 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1887 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1889 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1898 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1899 ecore_dev = edev->ecore_dev;
1904 ERR("Failed to get source ecore device from event !\n");
1908 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) goto end;
1910 timestamp = libinput_event_touch_get_time(event);
1912 ev->window = (Ecore_Window)input->dev->window;
1913 ev->event_window = (Ecore_Window)input->dev->window;
1914 ev->root_window = (Ecore_Window)input->dev->window;
1915 ev->timestamp = timestamp;
1916 ev->same_screen = 1;
1918 ev->x = edev->seat->ptr.ix;
1919 ev->y = edev->seat->ptr.iy;
1923 ev->multi.device = edev->mt_slot;
1924 ev->multi.radius = 1;
1925 ev->multi.radius_x = 1;
1926 ev->multi.radius_y = 1;
1927 ev->multi.pressure = 1.0;
1928 ev->multi.angle = 0.0;
1929 ev->multi.x = ev->x;
1930 ev->multi.y = ev->y;
1931 ev->multi.root.x = ev->x;
1932 ev->multi.root.y = ev->y;
1934 edev->touch.pressed &= ~(1 << ev->multi.device);
1936 ev->buttons = ((button & 0x00F) + 1);
1937 ev->dev = ecore_device_ref(ecore_dev);
1939 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev, _e_input_event_mouse_button_cb_free, NULL);
1942 ecore_thread_main_loop_end();
1946 _device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, int *w, int *h)
1948 E_Output *output = NULL;
1950 EINA_SAFETY_ON_NULL_RETURN(edev);
1952 if (!edev->output_configured)
1954 if (edev->output_name)
1956 output = e_output_find(edev->output_name);
1959 edev->mouse.minx = output->config.geom.x;
1960 edev->mouse.miny = output->config.geom.y;
1961 edev->mouse.maxw = output->config.geom.w;
1962 edev->mouse.maxh = output->config.geom.h;
1963 if (edev->caps & E_INPUT_SEAT_POINTER)
1965 edev->seat->ptr.dx = (double)(edev->mouse.maxw / 2);
1966 edev->seat->ptr.dy = (double)(edev->mouse.maxh / 2);
1967 edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
1968 edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
1969 edev->mouse.dx = edev->seat->ptr.dx;
1970 edev->mouse.dy = edev->seat->ptr.dy;
1975 edev->output_configured = EINA_TRUE;
1976 ELOGF("E_INPUT_EVDEV", "Device is configured by output x:%d,y:%d (w:%d, h:%d)",
1977 NULL, edev->mouse.minx, edev->mouse.miny, edev->mouse.maxw, edev->mouse.maxh);
1979 if (x) *x = edev->mouse.minx;
1980 if (y) *y = edev->mouse.miny;
1981 if (w) *w = edev->mouse.maxw;
1982 if (h) *h = edev->mouse.maxh;
1986 _device_handle_touch_down(struct libinput_device *device, struct libinput_event_touch *event)
1988 E_Input_Evdev *edev;
1989 int x = 0, y = 0, w = 0, h = 0;
1990 E_Comp_Config *comp_conf = NULL;
1992 if (!(edev = libinput_device_get_user_data(device)))
1997 _device_configured_size_get(edev, &x, &y, &w, &h);
1999 edev->mouse.dx = edev->seat->ptr.ix = edev->seat->ptr.dx =
2000 x + libinput_event_touch_get_x_transformed(event, w);
2001 edev->mouse.dy = edev->seat->ptr.iy = edev->seat->ptr.dy =
2002 y + libinput_event_touch_get_y_transformed(event, h);
2004 edev->mt_slot = libinput_event_touch_get_slot(event);
2005 if (edev->mt_slot < 0)
2007 /* FIXME: The single touch device return slot id -1
2008 * But currently we have no API to distinguish multi touch or single touch
2009 * After libinput 1.11 version, libinput provides get_touch_count API,
2010 * so we can distinguish multi touch device or single touch device.
2012 if (edev->mt_slot == -1)
2016 WRN("%d slot touch down events are not supported\n", edev->mt_slot);
2021 if (edev->mt_slot < e_input_touch_max_count_get())
2023 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
2024 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
2027 comp_conf = e_comp_config_get();
2028 if (comp_conf && comp_conf->input_log_enable)
2029 ELOGF("Touch", "Down (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2031 atomic_fetch_or(&edev->touch.raw_pressed, (1 << edev->mt_slot));
2033 if (edev->touch.blocked)
2035 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
2036 ELOGF("Touch", "Down (id: %d, x: %d, y: %d) is blocked by %p, server: 0x%x", NULL,
2037 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, blocked_client,
2038 edev->seat->dev->server_blocked);
2042 _device_handle_touch_motion_send(edev, event);
2043 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_DOWN);
2047 _device_handle_touch_motion(struct libinput_device *device, struct libinput_event_touch *event)
2049 E_Input_Evdev *edev;
2050 int x = 0, y = 0, w = 0, h = 0;
2052 if (!(edev = libinput_device_get_user_data(device)))
2057 _device_configured_size_get(edev, &x, &y, &w, &h);
2059 edev->mouse.dx = edev->seat->ptr.dx =
2060 x + libinput_event_touch_get_x_transformed(event, w);
2061 edev->mouse.dy = edev->seat->ptr.dy =
2062 y + libinput_event_touch_get_y_transformed(event, h);
2064 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
2065 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
2070 edev->seat->ptr.ix = edev->seat->ptr.dx;
2071 edev->seat->ptr.iy = edev->seat->ptr.dy;
2073 edev->mt_slot = libinput_event_touch_get_slot(event);
2074 if (edev->mt_slot < 0)
2076 /* FIXME: The single touch device return slot id -1
2077 * But currently we have no API to distinguish multi touch or single touch
2078 * After libinput 1.11 version, libinput provides get_touch_count API,
2079 * so we can distinguish multi touch device or single touch device.
2081 if (edev->mt_slot == -1)
2085 WRN("%d slot touch motion events are not supported\n", edev->mt_slot);
2090 if (edev->mt_slot < e_input_touch_max_count_get())
2092 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
2093 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
2096 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
2098 if (edev->touch.blocked)
2104 _device_handle_touch_motion_send(edev, event);
2108 _device_handle_touch_up(struct libinput_device *device, struct libinput_event_touch *event)
2110 E_Input_Evdev *edev;
2111 E_Comp_Config *comp_conf = NULL;
2113 if (!(edev = libinput_device_get_user_data(device)))
2118 edev->mt_slot = libinput_event_touch_get_slot(event);
2119 if (edev->mt_slot < 0)
2121 /* FIXME: The single touch device return slot id -1
2122 * But currently we have no API to distinguish multi touch or single touch
2123 * After libinput 1.11 version, libinput provides get_touch_count API,
2124 * so we can distinguish multi touch device or single touch device.
2126 if (edev->mt_slot == -1)
2130 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
2135 if (edev->mt_slot < e_input_touch_max_count_get())
2137 edev->mouse.dx = edev->seat->ptr.dx = edev->seat->ptr.ix =
2138 edev->touch.coords[edev->mt_slot].x;
2139 edev->mouse.dy = edev->seat->ptr.dy = edev->seat->ptr.iy =
2140 edev->touch.coords[edev->mt_slot].y;
2143 comp_conf = e_comp_config_get();
2144 if (comp_conf && comp_conf->input_log_enable)
2145 ELOGF("Touch", "Up (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2147 atomic_fetch_and(&edev->touch.raw_pressed, ~(1 << edev->mt_slot));
2149 if (edev->touch.blocked)
2151 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
2153 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
2154 ELOGF("Touch", "Up (id: %d, x: %d, y: %d) is blocked by %p, server(0x%x)", NULL,
2155 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, blocked_client,
2156 edev->seat->dev->server_blocked);
2158 if (edev->touch.raw_pressed == 0x0)
2160 edev->touch.blocked = EINA_FALSE;
2166 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_UP);
2170 _device_handle_touch_cancel(struct libinput_device *device, struct libinput_event_touch *event)
2172 E_Input_Evdev *edev;
2173 E_Comp_Config *comp_conf = NULL;
2175 if (!(edev = libinput_device_get_user_data(device)))
2180 edev->mt_slot = libinput_event_touch_get_slot(event);
2181 if (edev->mt_slot < 0)
2183 /* FIXME: The single touch device return slot id -1
2184 * But currently we have no API to distinguish multi touch or single touch
2185 * After libinput 1.11 version, libinput provides get_touch_count API,
2186 * so we can distinguish multi touch device or single touch device.
2188 if (edev->mt_slot == -1)
2192 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
2197 comp_conf = e_comp_config_get();
2198 if (comp_conf && comp_conf->input_log_enable)
2199 ELOGF("Touch", "cancel (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2201 _device_handle_touch_cancel_send(edev, event);
2206 _device_handle_touch_frame(struct libinput_device *device EINA_UNUSED, struct libinput_event_touch *event EINA_UNUSED)
2208 /* DBG("Unhandled Touch Frame Event"); */
2212 _e_input_aux_data_event_free(void *user_data EINA_UNUSED, void *ev)
2214 Ecore_Event_Axis_Update *e = (Ecore_Event_Axis_Update *)ev;
2216 if (e->axis) free(e->axis);
2217 if (e->dev) ecore_device_unref(e->dev);
2223 _device_handle_touch_aux_data(struct libinput_device *device, struct libinput_event_touch_aux_data *event)
2225 E_Input_Evdev *edev;
2226 E_Input_Backend *input;
2227 Ecore_Event_Axis_Update *ev;
2229 Ecore_Device *ecore_dev = NULL, *data;
2231 E_Comp_Config *comp_conf;
2233 ecore_thread_main_loop_begin();
2235 if (libinput_event_touch_aux_data_get_type(event) != LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM &&
2236 libinput_event_touch_aux_data_get_value(event) > 0)
2239 if (!(edev = libinput_device_get_user_data(device))) goto end;
2240 if (!(input = edev->seat->input)) goto end;
2242 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
2243 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
2245 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
2247 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
2256 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
2257 ecore_dev = edev->ecore_dev;
2262 ERR("Failed to get source ecore device from event !\n");
2266 if (!(ev = calloc(1, sizeof(Ecore_Event_Axis_Update)))) goto end;
2268 ev->window = (Ecore_Window)input->dev->window;
2269 ev->event_window = (Ecore_Window)input->dev->window;
2270 ev->root_window = (Ecore_Window)input->dev->window;
2271 ev->timestamp = libinput_event_touch_aux_data_get_time(event);
2273 axis = (Ecore_Axis *)calloc(1, sizeof(Ecore_Axis));
2276 axis->label = ECORE_AXIS_LABEL_TOUCH_PALM;
2277 axis->value = libinput_event_touch_aux_data_get_value(event);
2282 comp_conf = e_comp_config_get();
2283 if (comp_conf && comp_conf->input_log_enable)
2284 ELOGF("Touch", "Axis (label: %d, value: %lf)", NULL, axis?axis->label:-1, axis?axis->value:0.0);
2286 ev->dev = ecore_device_ref(ecore_dev);
2288 ecore_event_add(ECORE_EVENT_AXIS_UPDATE, ev, _e_input_aux_data_event_free, NULL);
2291 ecore_thread_main_loop_end();
2295 _e_input_evdev_device_create(E_Input_Seat *seat, struct libinput_device *device)
2297 E_Input_Evdev *edev;
2298 E_Input_Backend *b_input;
2299 const char *output_name;
2301 EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
2303 /* try to allocate space for new evdev */
2304 if (!(edev = calloc(1, sizeof(E_Input_Evdev)))) return NULL;
2307 edev->device = device;
2308 edev->path = eina_stringshare_printf("%s/%s", e_input_base_dir_get(), libinput_device_get_sysname(device));
2310 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
2312 edev->caps |= E_INPUT_SEAT_KEYBOARD;
2313 _device_keyboard_setup(edev);
2316 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
2318 edev->caps |= E_INPUT_SEAT_POINTER;
2320 /* TODO: make this configurable */
2321 edev->mouse.threshold = 250;
2323 b_input = seat->input;
2324 if (b_input->left_handed == EINA_TRUE)
2326 if (libinput_device_config_left_handed_set(device, 1) !=
2327 LIBINPUT_CONFIG_STATUS_SUCCESS)
2329 WRN("Failed to set left hand mode about device: %s\n",
2330 libinput_device_get_name(device));
2335 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
2338 edev->caps |= E_INPUT_SEAT_TOUCH;
2339 palm_code = libinput_device_touch_aux_data_get_code(LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM);
2340 if (libinput_device_touch_has_aux_data(device, palm_code))
2342 libinput_device_touch_set_aux_data(device, palm_code);
2345 _device_touch_count_update(edev);
2347 edev->touch.coords = calloc(1, sizeof(E_Input_Coord)*e_input_touch_max_count_get());
2349 if (!edev->touch.coords)
2350 ERR("Failed to allocate memory for touch coords !\n");
2353 output_name = libinput_device_get_output_name(device);
2356 eina_stringshare_replace(&edev->output_name, output_name);
2357 ELOGF("E_INPUT_EVDEV", "Device has output_name:%s", NULL, output_name);
2360 libinput_device_set_user_data(device, edev);
2361 libinput_device_ref(device);
2363 /* configure device */
2364 _device_configure(edev);
2370 _e_input_evdev_device_destroy(E_Input_Evdev *edev)
2373 EINA_SAFETY_ON_NULL_RETURN(edev);
2375 ecore_thread_main_loop_begin();
2377 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
2379 g_mutex_lock(&edev->xkb.state_mutex);
2380 if (edev->xkb.state) xkb_state_unref(edev->xkb.state);
2381 g_mutex_unlock(&edev->xkb.state_mutex);
2383 g_mutex_lock(&edev->xkb.keymap_mutex);
2384 if (edev->xkb.keymap) xkb_map_unref(edev->xkb.keymap);
2385 g_mutex_unlock(&edev->xkb.keymap_mutex);
2388 if (edev->ecore_dev) ecore_device_del(edev->ecore_dev);
2389 if (edev->ecore_dev_list)
2390 EINA_LIST_FREE(edev->ecore_dev_list, dev)
2392 ecore_device_del(dev);
2395 if (edev->e_dev) g_object_unref(edev->e_dev);
2396 if (edev->e_dev_list)
2398 GList *glist = edev->e_dev_list;
2402 e_dev = glist->data;
2403 g_object_unref(e_dev);
2405 glist = g_list_next(glist);
2408 if (edev->path) eina_stringshare_del(edev->path);
2409 if (edev->device) libinput_device_unref(edev->device);
2410 if (edev->key_remap_hash) eina_hash_free(edev->key_remap_hash);
2411 if (edev->touch.coords)
2413 free(edev->touch.coords);
2414 edev->touch.coords = NULL;
2416 eina_stringshare_del(edev->output_name);
2418 ecore_thread_main_loop_end();
2424 _e_input_evdev_event_process(struct libinput_event *event)
2426 struct libinput_device *device;
2427 Eina_Bool ret = EINA_TRUE;
2429 device = libinput_event_get_device(event);
2430 switch (libinput_event_get_type(event))
2432 case LIBINPUT_EVENT_KEYBOARD_KEY:
2433 _device_handle_key(device, libinput_event_get_keyboard_event(event));
2435 case LIBINPUT_EVENT_POINTER_MOTION:
2436 _device_handle_pointer_motion(device,
2437 libinput_event_get_pointer_event(event));
2439 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
2440 _device_handle_pointer_motion_absolute(device,
2441 libinput_event_get_pointer_event(event));
2443 case LIBINPUT_EVENT_POINTER_BUTTON:
2444 _device_handle_button(device, libinput_event_get_pointer_event(event));
2446 case LIBINPUT_EVENT_POINTER_AXIS:
2447 #if !LIBINPUT_HAVE_SCROLL_VALUE_V120
2448 _device_handle_axis(device, libinput_event_get_pointer_event(event));
2451 #if LIBINPUT_HAVE_SCROLL_VALUE_V120
2452 case LIBINPUT_EVENT_POINTER_SCROLL_WHEEL:
2453 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_WHEEL);
2455 case LIBINPUT_EVENT_POINTER_SCROLL_FINGER:
2456 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_FINGER);
2458 case LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS:
2459 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_CONTINUOUS);
2462 case LIBINPUT_EVENT_TOUCH_DOWN:
2463 _device_handle_touch_down(device, libinput_event_get_touch_event(event));
2465 case LIBINPUT_EVENT_TOUCH_MOTION:
2466 _device_handle_touch_motion(device,
2467 libinput_event_get_touch_event(event));
2469 case LIBINPUT_EVENT_TOUCH_UP:
2470 _device_handle_touch_up(device, libinput_event_get_touch_event(event));
2472 case LIBINPUT_EVENT_TOUCH_CANCEL:
2473 _device_handle_touch_cancel(device, libinput_event_get_touch_event(event));
2475 case LIBINPUT_EVENT_TOUCH_FRAME:
2476 _device_handle_touch_frame(device, libinput_event_get_touch_event(event));
2478 case LIBINPUT_EVENT_TOUCH_AUX_DATA:
2479 _device_handle_touch_aux_data(device, libinput_event_get_touch_aux_data(event));
2490 * @brief Set the axis size of the given device.
2492 * @param dev The device to set the axis size to.
2493 * @param w The width of the axis.
2494 * @param h The height of the axis.
2496 * This function sets set the width @p w and height @p h of the axis
2497 * of device @p dev. If @p dev is a relative input device, a width and
2498 * height must set for it. If its absolute set the ioctl correctly, if
2499 * not, unsupported device.
2502 e_input_evdev_axis_size_set(E_Input_Evdev *edev, int w, int h)
2504 const char *sysname;
2509 enum libinput_config_status status;
2511 EINA_SAFETY_ON_NULL_RETURN(edev);
2512 EINA_SAFETY_ON_TRUE_RETURN((w == 0) || (h == 0));
2514 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
2515 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
2518 sysname = libinput_device_get_sysname(edev->device);
2520 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
2521 if (eina_list_count(devices) < 1) return;
2523 EINA_LIST_FREE(devices, device)
2525 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
2527 (sscanf(vals, "%f %f %f %f %f %f",
2528 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
2535 libinput_device_config_calibration_set_matrix(edev->device, cal);
2537 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
2538 ERR("Failed to apply calibration");
2541 eina_stringshare_del(device);
2546 EINTERN const char *
2547 e_input_evdev_name_get(E_Input_Evdev *evdev)
2549 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2550 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2552 return libinput_device_get_name(evdev->device);
2555 EINTERN const char *
2556 e_input_evdev_sysname_get(E_Input_Evdev *evdev)
2558 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2559 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2561 return libinput_device_get_sysname(evdev->device);
2565 e_input_evdev_key_remap_enable(E_Input_Evdev *edev, Eina_Bool enable)
2567 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2568 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2570 edev->key_remap_enabled = enable;
2572 if (enable == EINA_FALSE && edev->key_remap_hash)
2574 eina_hash_free(edev->key_remap_hash);
2575 edev->key_remap_hash = NULL;
2582 e_input_evdev_key_remap_set(E_Input_Evdev *edev, int *from_keys, int *to_keys, int num)
2586 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2587 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2588 EINA_SAFETY_ON_NULL_RETURN_VAL(from_keys, EINA_FALSE);
2589 EINA_SAFETY_ON_NULL_RETURN_VAL(to_keys, EINA_FALSE);
2590 EINA_SAFETY_ON_TRUE_RETURN_VAL(num <= 0, EINA_FALSE);
2591 EINA_SAFETY_ON_TRUE_RETURN_VAL(!edev->key_remap_enabled, EINA_FALSE);
2593 if (edev->key_remap_hash == NULL)
2594 edev->key_remap_hash = eina_hash_int32_new(NULL);
2596 if (edev->key_remap_hash == NULL)
2598 ERR("Failed to set remap key information : creating a hash is failed.");
2602 for (i = 0; i < num ; i++)
2604 if (!from_keys[i] || !to_keys[i])
2606 ERR("Failed to set remap key information : given arguments are invalid.");
2611 for (i = 0; i < num ; i++)
2613 eina_hash_add(edev->key_remap_hash, &from_keys[i], (void *)(intptr_t)to_keys[i]);
2620 e_input_evdev_wheel_click_angle_get(E_Input_Evdev *dev)
2622 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, -1);
2623 return libinput_device_config_scroll_get_wheel_click_angle(dev->device);
2627 e_input_evdev_touch_calibration_set(E_Input_Evdev *edev, float matrix[6])
2629 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2630 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2632 if (!libinput_device_config_calibration_has_matrix(edev->device) ||
2633 !libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_TOUCH))
2636 if (libinput_device_config_calibration_set_matrix(edev->device, matrix) !=
2637 LIBINPUT_CONFIG_STATUS_SUCCESS)
2639 WRN("Failed to set input transformation about device: %s\n",
2640 libinput_device_get_name(edev->device));
2648 e_input_evdev_mouse_accel_speed_set(E_Input_Evdev *edev, double speed)
2650 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2651 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2653 if (!libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
2656 if (!libinput_device_config_accel_is_available(edev->device))
2659 if (libinput_device_config_accel_set_speed(edev->device, speed) !=
2660 LIBINPUT_CONFIG_STATUS_SUCCESS)
2662 WRN("Failed to set mouse accel about device: %s\n",
2663 libinput_device_get_name(edev->device));
2670 EINTERN unsigned int
2671 e_input_evdev_touch_pressed_get(E_Input_Evdev *edev)
2673 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, 0x0);
2675 return edev->touch.pressed;
2679 e_input_evdev_seatname_get(E_Input_Evdev *evdev)
2681 struct libinput_seat *libinput_seat;
2682 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2683 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2685 libinput_seat = libinput_device_get_seat(evdev->device);
2687 return libinput_seat_get_logical_name(libinput_seat);
2691 e_input_evdev_seatname_set(E_Input_Evdev *evdev, const char *seatname)
2693 Eina_Bool res = EINA_FALSE;
2694 E_Input_Backend *input;
2696 EINA_SAFETY_ON_NULL_RETURN_VAL(seatname, EINA_FALSE);
2697 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, EINA_FALSE);
2698 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, EINA_FALSE);
2700 if (libinput_device_set_seat_logical_name(evdev->device, seatname) == 0)
2702 input = evdev->seat->input;
2703 if (!input) return EINA_FALSE;
2705 if (libinput_dispatch(input->libinput) != 0)
2707 ERR("Failed to dispatch libinput events: %m");
2712 /* process pending events */
2713 _input_events_process(input);