2 #include "e_input_intern.h"
3 #include "e_input_private.h"
4 #include "e_device_intern.h"
5 #include "e_keyrouter_private.h"
6 #include "e_input_event.h"
7 #include "e_devicemgr.h"
8 #include "e_comp_screen_intern.h"
12 #define G_LIST_GET_DATA(list) ((list) ? (((GList *)(list))->data) : NULL)
14 static void _device_modifiers_update(E_Input_Evdev *edev);
15 static void _device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, int *w, int *h);
16 static void _device_output_assign(E_Input_Evdev *edev, E_Input_Seat_Capabilities cap);
19 _device_calibration_set(E_Input_Evdev *edev)
24 E_Comp_Config *comp_conf;
26 if (e_comp->e_comp_screen->num_outputs > 1) //multiple outputs
28 comp_conf = e_comp_config_get();
29 if (comp_conf && (comp_conf->input_output_assign_policy == 1)) //use output-assignment policy
31 _device_output_assign(edev, E_INPUT_SEAT_POINTER);
32 _device_output_assign(edev, E_INPUT_SEAT_TOUCH);
36 output = e_comp_screen_primary_output_get(e_comp->e_comp_screen);
37 e_output_size_get(output, &w, &h);
41 edev->mouse.minx = edev->mouse.miny = 0;
45 if (edev->caps & E_INPUT_SEAT_POINTER)
47 edev->seat->ptr.dx = (double)(w / 2);
48 edev->seat->ptr.dy = (double)(h / 2);
49 edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
50 edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
51 edev->mouse.dx = edev->seat->ptr.dx;
52 edev->mouse.dy = edev->seat->ptr.dy;
54 if (output->config.rotation == 90 || output->config.rotation == 270)
56 temp = edev->mouse.minx;
57 edev->mouse.minx = edev->mouse.miny;
58 edev->mouse.miny = temp;
60 temp = edev->mouse.maxw;
61 edev->mouse.maxw = edev->mouse.maxh;
62 edev->mouse.maxh = temp;
68 #ifdef _F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
74 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
75 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
78 sysname = libinput_device_get_sysname(edev->device);
80 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
81 if (eina_list_count(devices) < 1) return;
83 #ifdef _F_E_INPUT_USE_WL_CALIBRATION_
85 enum libinput_config_status status;
87 EINA_LIST_FREE(devices, device)
89 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
91 (sscanf(vals, "%f %f %f %f %f %f",
92 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
99 libinput_device_config_calibration_set_matrix(edev->device, cal);
101 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
102 ERR("Failed to apply calibration");
105 eina_stringshare_del(device);
108 #endif//_F_E_INPUT_USE_WL_CALIBRATION_
109 #endif//_F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
114 _device_output_assign(E_Input_Evdev *edev, E_Input_Seat_Capabilities cap)
119 Eina_Bool need_assign_output = EINA_FALSE;
120 const char *output_name;
123 if (!(edev->caps & cap)) return;
124 if (edev->output_name) return; //already assigned
125 if (e_comp->e_comp_screen->num_outputs <= 1) return;
127 last_output_idx = e_comp->e_comp_screen->num_outputs - 1;
128 EINA_LIST_FOREACH(edev->seat->devices, l, ed)
130 if (!(ed->caps & cap)) continue;
131 if (ed == edev) continue;
134 need_assign_output = EINA_FALSE;
137 need_assign_output = EINA_TRUE;
139 if (need_assign_output)
141 output = e_output_find_by_index(last_output_idx);
142 if (!output || !output->info.connected) return;
143 output_name = e_output_output_id_get(output);
144 if (output_name) edev->output_name = eina_stringshare_add(output_name);
145 ELOGF("E_INPUT_EVDEV", "Device is assigned to output:%s", NULL, output_name);
150 _device_touch_count_update(E_Input_Evdev *edev)
152 unsigned int device_touch_count = 0;
153 static unsigned int _max_device_touch_count = 0;
155 E_Input *ei = e_input_get();
156 EINA_SAFETY_ON_NULL_RETURN(ei);
158 device_touch_count = libinput_device_touch_get_touch_count(edev->device);
160 if (_max_device_touch_count < device_touch_count)
161 _max_device_touch_count = device_touch_count;
163 if (e_config->configured_max_touch.use)
165 if (_max_device_touch_count > 0 && e_config->configured_max_touch.count > _max_device_touch_count)
167 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",
168 NULL, e_config->configured_max_touch.count, _max_device_touch_count, _max_device_touch_count);
169 ei->touch_max_count = _max_device_touch_count;
173 if (ei->touch_max_count != e_config->configured_max_touch.count)
175 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch_max_count has been updated to %d -> %d.\n",
176 NULL, ei->touch_max_count, e_config->configured_max_touch.count);
177 ei->touch_max_count = e_config->configured_max_touch.count;
183 if (ei->touch_max_count < _max_device_touch_count)
185 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch_max_count has been updated to %d -> %d.\n", NULL,
186 ei->touch_max_count, _max_device_touch_count);
187 ei->touch_max_count = _max_device_touch_count;
191 ei->touch_device_count++;
192 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch device count is %d.\n", NULL, ei->touch_device_count);
196 _device_configure(E_Input_Evdev *edev)
198 if (libinput_device_config_tap_get_finger_count(edev->device) > 0)
200 Eina_Bool tap = EINA_FALSE;
202 tap = libinput_device_config_tap_get_default_enabled(edev->device);
203 libinput_device_config_tap_set_enabled(edev->device, tap);
206 _device_calibration_set(edev);
210 _device_keyboard_setup(E_Input_Evdev *edev)
212 E_Input_Backend *input;
213 xkb_mod_index_t xkb_idx;
215 if ((!edev) || (!edev->seat)) return;
216 if (!(input = edev->seat->input)) return;
217 if (!input->dev->xkb_ctx) return;
219 g_mutex_init(&edev->xkb.keymap_mutex);
221 /* create keymap from xkb context */
222 g_mutex_lock(&edev->xkb.keymap_mutex);
223 edev->xkb.keymap = _e_input_device_cached_keymap_get(input->dev->xkb_ctx, NULL, 0);
224 if (!edev->xkb.keymap)
226 g_mutex_unlock(&edev->xkb.keymap_mutex);
227 ERR("Failed to create keymap: %m");
231 g_mutex_lock(&edev->xkb.state_mutex);
233 /* create xkb state */
234 if (!(edev->xkb.state = xkb_state_new(edev->xkb.keymap)))
236 g_mutex_unlock(&edev->xkb.state_mutex);
237 g_mutex_unlock(&edev->xkb.keymap_mutex);
238 ERR("Failed to create xkb state: %m");
242 g_mutex_unlock(&edev->xkb.state_mutex);
244 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CTRL);
245 if (xkb_idx != XKB_MOD_INVALID)
246 edev->xkb.ctrl_mask = 1 << xkb_idx;
248 edev->xkb.ctrl_mask = 0;
250 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_ALT);
251 if (xkb_idx != XKB_MOD_INVALID)
252 edev->xkb.alt_mask = 1 << xkb_idx;
254 edev->xkb.alt_mask = 0;
256 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_SHIFT);
257 if (xkb_idx != XKB_MOD_INVALID)
258 edev->xkb.shift_mask = 1 << xkb_idx;
260 edev->xkb.shift_mask = 0;
262 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_LOGO);
263 if (xkb_idx != XKB_MOD_INVALID)
264 edev->xkb.win_mask = 1 << xkb_idx;
266 edev->xkb.win_mask = 0;
268 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_SCROLL);
269 if (xkb_idx != XKB_MOD_INVALID)
270 edev->xkb.scroll_mask = 1 << xkb_idx;
272 edev->xkb.scroll_mask = 0;
274 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_NUM);
275 if (xkb_idx != XKB_MOD_INVALID)
276 edev->xkb.num_mask = 1 << xkb_idx;
278 edev->xkb.num_mask = 0;
280 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CAPS);
281 if (xkb_idx != XKB_MOD_INVALID)
282 edev->xkb.caps_mask = 1 << xkb_idx;
284 edev->xkb.caps_mask = 0;
286 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, "ISO_Level3_Shift");
287 if (xkb_idx != XKB_MOD_INVALID)
288 edev->xkb.altgr_mask = 1 << xkb_idx;
290 edev->xkb.altgr_mask = 0;
292 g_mutex_unlock(&edev->xkb.keymap_mutex);
296 _device_keysym_translate(xkb_keysym_t keysym, unsigned int modifiers, char *buffer, int bytes)
298 unsigned long hbytes = 0;
301 if (!keysym) return 0;
302 hbytes = (keysym >> 8);
307 (((keysym >= XKB_KEY_BackSpace) && (keysym <= XKB_KEY_Clear)) ||
308 (keysym == XKB_KEY_Return) || (keysym == XKB_KEY_Escape) ||
309 (keysym == XKB_KEY_KP_Space) || (keysym == XKB_KEY_KP_Tab) ||
310 (keysym == XKB_KEY_KP_Enter) ||
311 ((keysym >= XKB_KEY_KP_Multiply) && (keysym <= XKB_KEY_KP_9)) ||
312 (keysym == XKB_KEY_KP_Equal) || (keysym == XKB_KEY_Delete))))))
315 if (keysym == XKB_KEY_KP_Space)
316 c = (XKB_KEY_space & 0x7F);
317 else if (hbytes == 0xFF)
322 if (modifiers & ECORE_EVENT_MODIFIER_CTRL)
324 if (((c >= '@') && (c < '\177')) || c == ' ')
328 else if ((c >= '3') && (c <= '7'))
340 _device_modifiers_update_device(E_Input_Evdev *edev, E_Input_Evdev *from)
344 g_mutex_lock(&from->xkb.state_mutex);
346 edev->xkb.depressed =
347 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_DEPRESSED);
349 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LATCHED);
351 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LOCKED);
353 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_EFFECTIVE);
355 g_mutex_unlock(&from->xkb.state_mutex);
357 mask = (edev->xkb.depressed | edev->xkb.latched);
359 if (mask & from->xkb.ctrl_mask)
360 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_CTRL;
361 if (mask & from->xkb.alt_mask)
362 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALT;
363 if (mask & from->xkb.shift_mask)
364 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
365 if (mask & from->xkb.win_mask)
366 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_WIN;
367 if (mask & from->xkb.scroll_mask)
368 edev->xkb.modifiers |= ECORE_EVENT_LOCK_SCROLL;
369 if (mask & from->xkb.num_mask)
370 edev->xkb.modifiers |= ECORE_EVENT_LOCK_NUM;
371 if (mask & from->xkb.caps_mask)
372 edev->xkb.modifiers |= ECORE_EVENT_LOCK_CAPS;
373 if (mask & from->xkb.altgr_mask)
374 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALTGR;
378 _device_modifiers_update(E_Input_Evdev *edev)
383 edev->xkb.modifiers = 0;
385 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
386 _device_modifiers_update_device(edev, edev);
389 EINA_LIST_FOREACH(edev->seat->devices, l, ed)
391 if (!(ed->caps & E_INPUT_SEAT_KEYBOARD)) continue;
392 _device_modifiers_update_device(edev, ed);
399 _device_remapped_key_get(E_Input_Evdev *edev, int code)
403 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, code);
404 if (!edev->key_remap_enabled) return code;
405 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->key_remap_hash, code);
407 ret = eina_hash_find(edev->key_remap_hash, &code);
409 if (ret) code = (int)(intptr_t)ret;
415 e_input_evdev_get_e_device(const char *path, Ecore_Device_Class clas)
417 const GList *dev_list = NULL;
419 E_Device *dev = NULL;
420 const char *identifier;
422 if (!path) return NULL;
424 dev_list = e_device_list_get();
425 if (!dev_list) return NULL;
432 identifier = e_device_identifier_get(dev);
433 if (!identifier) continue;
434 if ((e_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
443 EINTERN Ecore_Device *
444 e_input_evdev_get_ecore_device(const char *path, Ecore_Device_Class clas)
446 const Eina_List *dev_list = NULL;
448 Ecore_Device *dev = NULL;
449 const char *identifier;
451 if (!path) return NULL;
453 dev_list = ecore_device_list();
454 if (!dev_list) return NULL;
455 EINA_LIST_FOREACH(dev_list, l, dev)
458 identifier = ecore_device_identifier_get(dev);
459 if (!identifier) continue;
460 if ((ecore_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
467 _e_input_event_mouse_move_cb_free(void *data EINA_UNUSED, void *event)
469 Ecore_Event_Mouse_Move *ev = event;
471 if (ev->dev) ecore_device_unref(ev->dev);
477 _e_input_event_mouse_relative_move_cb_free(void *data EINA_UNUSED, void *event)
479 Ecore_Event_Mouse_Relative_Move *ev = event;
481 if (ev->dev) ecore_device_unref(ev->dev);
487 _e_input_event_mouse_wheel_cb_free(void *data EINA_UNUSED, void *event)
489 Ecore_Event_Mouse_Wheel *ev = event;
491 if (ev->dev) ecore_device_unref(ev->dev);
497 _e_input_event_mouse_button_cb_free(void *data EINA_UNUSED, void *event)
499 Ecore_Event_Mouse_Button *ev = event;
501 if (ev->dev) ecore_device_unref(ev->dev);
507 _e_input_event_key_cb_free(void *data EINA_UNUSED, void *event)
509 Ecore_Event_Key *ev = event;
511 if (e_input_thread_mode_get())
513 if (ev->dev) g_object_unref(ev->dev);
517 if (ev->dev) ecore_device_unref(ev->dev);
520 if (ev->data) E_FREE(ev->data);
526 _device_handle_key(struct libinput_device *device, struct libinput_event_keyboard *event)
529 E_Input_Backend *input;
531 uint32_t code, nsyms;
532 const xkb_keysym_t *syms;
533 enum libinput_key_state state;
535 xkb_keysym_t sym = XKB_KEY_NoSymbol;
536 char key[256] = {0, }, keyname[256] = {0, }, compose_buffer[256] = {0, };
538 char *tmp = NULL, *compose = NULL;
539 E_Keyrouter_Event_Data *key_data;
540 Ecore_Device *ecore_dev = NULL, *data;
541 E_Device *e_dev = NULL, *e_dev_data;
542 Eina_List *l = NULL, *l_next = NULL;
544 E_Comp_Config *comp_conf = NULL;
545 int *pressed_keycode = NULL, *idata = NULL;
546 Eina_Bool dup_found = EINA_FALSE;
547 const char *device_name = NULL;
548 Ecore_Device_Subclass device_subclas = ECORE_DEVICE_SUBCLASS_NONE;
550 if (!(edev = libinput_device_get_user_data(device)))
555 if (!(input = edev->seat->input))
560 if (!e_input_thread_mode_get())
562 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
563 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
565 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
567 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_KEYBOARD)
576 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
577 ecore_dev = edev->ecore_dev;
582 ERR("Failed to get source ecore device from event !\n");
586 device_name = ecore_device_name_get(ecore_dev);
587 device_subclas = ecore_device_subclass_get(ecore_dev);
591 if (edev->e_dev) e_dev = edev->e_dev;
592 else if (edev->e_dev_list && g_list_length(edev->e_dev_list) > 0)
594 glist = edev->e_dev_list;
597 e_dev_data = glist->data;
598 if (e_device_class_get(e_dev_data) == ECORE_DEVICE_CLASS_KEYBOARD)
604 glist = g_list_next(glist);
609 edev->e_dev = e_input_evdev_get_e_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
615 ERR("Failed to get source e device from event !\n");
619 device_name = e_device_name_get(e_dev);
620 device_subclas = e_device_subclass_get(e_dev);
623 timestamp = libinput_event_keyboard_get_time(event);
624 code = libinput_event_keyboard_get_key(event);
625 code = _device_remapped_key_get(edev, code + 8);
626 state = libinput_event_keyboard_get_key_state(event);
627 key_count = libinput_event_keyboard_get_seat_key_count(event);
629 if (state == LIBINPUT_KEY_STATE_PRESSED)
631 if ((edev->seat->dev->blocked & E_INPUT_SEAT_KEYBOARD) ||
632 (edev->seat->dev->server_blocked & E_INPUT_SEAT_KEYBOARD))
634 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
635 ELOGF("Key", "Press (keycode: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
636 code, device_name, blocked_client,
637 edev->seat->dev->server_blocked);
641 /* FIXME: Currently to maintain press/release event pair during input block,
642 * used Eina_List and this is method used in devicemgr module.
643 * But we need to consider which way is better to maintain key press/release pair.
646 EINA_LIST_FOREACH(edev->xkb.pressed_keys, l, idata)
650 dup_found = EINA_TRUE;
656 pressed_keycode = E_NEW(int, 1);
657 EINA_SAFETY_ON_NULL_RETURN(pressed_keycode);
658 *pressed_keycode = code;
660 edev->xkb.pressed_keys = eina_list_append(edev->xkb.pressed_keys, pressed_keycode);
665 dup_found = EINA_FALSE;
666 EINA_LIST_FOREACH_SAFE(edev->xkb.pressed_keys, l, l_next, idata)
670 edev->xkb.pressed_keys = eina_list_remove_list(edev->xkb.pressed_keys, l);
672 dup_found = EINA_TRUE;
678 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
679 ELOGF("Key", "Release (keycode: %d, device: %s) is blocked by %p", NULL,
680 code, device_name, blocked_client);
685 /* ignore key events that are not seat wide state changes */
686 if (((state == LIBINPUT_KEY_STATE_PRESSED) && (key_count != 1)) ||
687 ((state == LIBINPUT_KEY_STATE_RELEASED) && (key_count != 0)))
692 e_input_keyboard_grab_key_cb func = e_input_keyboard_grab_key_handler_get();
695 if (e_devicemgr_keyboard_grab_subtype_is_grabbed(device_subclas))
697 if (!e_input_thread_mode_get())
698 func(code, state, timestamp, ecore_dev);
700 func(code, state, timestamp, e_dev);
705 g_mutex_lock(&edev->xkb.state_mutex);
706 xkb_state_update_key(edev->xkb.state, code,
707 (state ? XKB_KEY_DOWN : XKB_KEY_UP));
709 /* get the keysym for this code */
710 nsyms = xkb_key_get_syms(edev->xkb.state, code, &syms);
711 g_mutex_unlock(&edev->xkb.state_mutex);
713 if (nsyms == 1) sym = syms[0];
715 /* If no keysym was found, name it "Keycode-NNN" */
716 if (sym == XKB_KEY_NoSymbol)
717 snprintf(key, sizeof(key), "Keycode-%u", code);
720 /* get the keyname for this sym */
721 xkb_keysym_get_name(sym, key, sizeof(key));
726 /* If no keyname was found, name it "Keycode-NNN" */
727 snprintf(keyname, sizeof(keyname), "Keycode-%u", code);
731 memcpy(keyname, key, sizeof(keyname));
734 /* if shift is active, we need to transform the key to lower */
735 g_mutex_lock(&edev->xkb.keymap_mutex);
736 g_mutex_lock(&edev->xkb.state_mutex);
737 if (xkb_state_mod_index_is_active(edev->xkb.state,
738 xkb_map_mod_get_index(edev->xkb.keymap,
740 XKB_STATE_MODS_EFFECTIVE))
742 if (keyname[0] != '\0')
743 keyname[0] = tolower(keyname[0]);
745 g_mutex_unlock(&edev->xkb.keymap_mutex);
746 g_mutex_unlock(&edev->xkb.state_mutex);
748 if (_device_keysym_translate(sym, edev->xkb.modifiers,
749 compose_buffer, sizeof(compose_buffer)))
751 compose = eina_str_convert("ISO8859-1", "UTF-8", compose_buffer);
754 ERR("E Input cannot convert input key string '%s' to UTF-8. "
755 "Is Eina built with iconv support?", compose_buffer);
761 if (!compose) compose = compose_buffer;
763 e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) +
764 ((compose[0] != '\0') ? strlen(compose) : 0) + 3);
770 key_data = E_NEW(E_Keyrouter_Event_Data, 1);
778 e->keyname = (char *)(e + 1);
779 e->key = e->keyname + strlen(keyname) + 1;
780 e->compose = strlen(compose) ? e->key + strlen(key) + 1 : NULL;
781 e->string = e->compose;
783 strncpy((char *)e->keyname, keyname, strlen(keyname));
784 strncpy((char *)e->key, key, strlen(key));
785 if (strlen(compose)) strncpy((char *)e->compose, compose, strlen(compose));
787 e->window = (Ecore_Window)input->dev->window;
788 e->event_window = (Ecore_Window)input->dev->window;
789 e->root_window = (Ecore_Window)input->dev->window;
790 e->timestamp = timestamp;
795 _device_modifiers_update(edev);
797 e->modifiers = edev->xkb.modifiers;
799 comp_conf = e_comp_config_get();
801 if (comp_conf && comp_conf->input_log_enable)
802 ELOGF("Key", "%s (keyname: %s, keycode: %d, timestamp: %u, device: %s)", NULL, state?"Press":"Release", e->keyname, e->keycode, e->timestamp, device_name);
804 if (e_config->key_input_ttrace_enable)
806 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));
807 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));
810 _e_input_key_event_list_add(e);
812 if (e_input_thread_mode_get())
814 e->dev = (Eo *)g_object_ref(e_dev);
815 e_input_event_add(input->event_source, state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
819 e->dev = ecore_device_ref(ecore_dev);
820 ecore_event_add(state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
823 if (e_config->key_input_ttrace_enable)
826 ELOGF("INPUT", "ECORE_EVENT_KEY|E|", NULL);
833 _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event)
835 E_Input_Backend *input;
836 Ecore_Event_Mouse_Move *ev;
837 Ecore_Device *ecore_dev = NULL, *data, *detent_data = NULL;
839 int x = 0, y = 0, w = 0, h = 0;
841 if (!(input = edev->seat->input)) return;
843 ecore_thread_main_loop_begin();
845 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
846 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
848 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
850 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
855 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
860 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
862 ecore_dev = detent_data;
867 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
868 ecore_dev = edev->ecore_dev;
873 ERR("Failed to get source ecore device from event !\n");
876 else if ((detent_data == ecore_dev) || e_devicemgr_detent_is_detent(ecore_device_name_get(ecore_dev)))
878 /* Do not process detent device's move events. */
882 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
884 _device_configured_size_get(edev, &x, &y, &w, &h);
886 if (edev->seat->ptr.ix < x)
887 edev->seat->ptr.dx = edev->seat->ptr.ix = x;
888 else if (edev->seat->ptr.ix >= (x + w))
889 edev->seat->ptr.dx = edev->seat->ptr.ix = (x + w - 1);
891 if (edev->seat->ptr.iy < y)
892 edev->seat->ptr.dy = edev->seat->ptr.iy = y;
893 else if (edev->seat->ptr.iy >= (y + h))
894 edev->seat->ptr.dy = edev->seat->ptr.iy = (y + h - 1);
896 edev->mouse.dx = edev->seat->ptr.dx;
897 edev->mouse.dy = edev->seat->ptr.dy;
899 ev->window = (Ecore_Window)input->dev->window;
900 ev->event_window = (Ecore_Window)input->dev->window;
901 ev->root_window = (Ecore_Window)input->dev->window;
902 if (event) ev->timestamp = libinput_event_pointer_get_time(event);
905 _device_modifiers_update(edev);
906 ev->modifiers = edev->xkb.modifiers;
908 ev->x = edev->seat->ptr.ix;
909 ev->y = edev->seat->ptr.iy;
913 ev->multi.device = edev->mt_slot;
914 ev->multi.radius = 1;
915 ev->multi.radius_x = 1;
916 ev->multi.radius_y = 1;
917 ev->multi.pressure = 1.0;
918 ev->multi.angle = 0.0;
921 ev->multi.root.x = ev->x;
922 ev->multi.root.y = ev->y;
924 ev->dev = ecore_device_ref(ecore_dev);
926 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
929 ecore_thread_main_loop_end();
933 _e_input_pointer_motion_post(E_Input_Evdev *edev)
935 _device_pointer_motion(edev, NULL);
939 _device_pointer_relative_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event, double dx[2], double dy[2])
941 E_Input_Backend *input;
942 Ecore_Event_Mouse_Relative_Move *ev;
943 Ecore_Device *ecore_dev = NULL, *data, *detent_data = NULL;
945 E_Comp_Config *comp_conf;
947 if (!(input = edev->seat->input)) return;
949 ecore_thread_main_loop_begin();
951 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
952 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
954 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
956 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
961 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
966 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
968 ecore_dev = detent_data;
973 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
974 ecore_dev = edev->ecore_dev;
979 ERR("Failed to get source ecore device from event !\n");
982 else if ((detent_data == ecore_dev) || e_devicemgr_detent_is_detent(ecore_device_name_get(ecore_dev)))
984 /* Do not process detent device's move events. */
988 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Relative_Move)))) return;
990 ev->window = (Ecore_Window)input->dev->window;
991 ev->event_window = (Ecore_Window)input->dev->window;
992 if (event) ev->timestamp = libinput_event_pointer_get_time(event);
994 ev->modifiers = edev->xkb.modifiers;
998 ev->dx_unaccel = (int)dx[1];
999 ev->dy_unaccel = (int)dy[1];
1001 ev->dev = ecore_device_ref(ecore_dev);
1003 comp_conf = e_comp_config_get();
1004 if (comp_conf && comp_conf->input_log_enable)
1005 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));
1007 ecore_event_add(ECORE_EVENT_MOUSE_RELATIVE_MOVE, ev, _e_input_event_mouse_relative_move_cb_free, NULL);
1010 ecore_thread_main_loop_end();
1014 _device_pointer_motion_send(E_Input_Evdev *edev, struct libinput_event_pointer *event, double dx[2], double dy[2])
1016 e_input_relative_motion_cb func = e_input_relative_motion_handler_get();
1019 //func(dx, dy, time_us);
1020 _device_pointer_relative_motion(edev, event, dx, dy);
1024 double seat_dx, seat_dy, temp;
1025 if (edev->disable_acceleration)
1036 if (edev->seat->ptr.swap)
1042 if (edev->seat->ptr.invert_x)
1044 if (edev->seat->ptr.invert_y)
1047 edev->seat->ptr.dx += seat_dx;
1048 edev->seat->ptr.dy += seat_dy;
1050 edev->mouse.dx = edev->seat->ptr.dx;
1051 edev->mouse.dy = edev->seat->ptr.dy;
1053 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
1054 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
1059 edev->seat->ptr.ix = edev->seat->ptr.dx;
1060 edev->seat->ptr.iy = edev->seat->ptr.dy;
1062 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1063 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1068 _device_pointer_motion(edev, event);
1073 _device_handle_pointer_motion(struct libinput_device *device, struct libinput_event_pointer *event)
1075 E_Input_Evdev *edev;
1076 double delta_x[2]; /* delta_x[0] for accelerated, delta_x[1] for unaccelerated */
1077 double delta_y[2]; /* delta_y[0] for accelerated, delta_y[1] for unaccelerated */
1079 if (!(edev = libinput_device_get_user_data(device)))
1084 delta_x[0] = libinput_event_pointer_get_dx(event);
1085 delta_x[1] = libinput_event_pointer_get_dx_unaccelerated(event);
1086 delta_y[0] = libinput_event_pointer_get_dy(event);
1087 delta_y[1] = libinput_event_pointer_get_dy_unaccelerated(event);
1089 _device_pointer_motion_send(edev, event, &delta_x[0], &delta_y[0]);
1093 _device_handle_pointer_motion_absolute(struct libinput_device *device, struct libinput_event_pointer *event)
1095 E_Input_Evdev *edev;
1098 if (!(edev = libinput_device_get_user_data(device)))
1103 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
1105 edev->mouse.dx = edev->seat->ptr.dx =
1106 libinput_event_pointer_get_absolute_x_transformed(event, w);
1107 edev->mouse.dy = edev->seat->ptr.dy =
1108 libinput_event_pointer_get_absolute_y_transformed(event, h);
1110 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
1111 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
1116 edev->seat->ptr.ix = edev->seat->ptr.dx;
1117 edev->seat->ptr.iy = edev->seat->ptr.dy;
1119 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1120 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1125 _device_pointer_motion(edev, event);
1129 _device_handle_button(struct libinput_device *device, struct libinput_event_pointer *event)
1131 E_Input_Evdev *edev;
1132 E_Input_Backend *input;
1133 Ecore_Event_Mouse_Button *ev;
1134 enum libinput_button_state state;
1135 uint32_t button, timestamp;
1136 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1138 E_Comp_Config *comp_conf = NULL;
1140 if (!(edev = libinput_device_get_user_data(device)))
1144 if (!(input = edev->seat->input))
1149 ecore_thread_main_loop_begin();
1151 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1152 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1154 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1156 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1161 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1166 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1168 ecore_dev = detent_data;
1173 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1174 ecore_dev = edev->ecore_dev;
1179 ERR("Failed to get source ecore device from event !\n");
1183 state = libinput_event_pointer_get_button_state(event);
1184 button = libinput_event_pointer_get_button(event);
1185 timestamp = libinput_event_pointer_get_time(event);
1187 button = ((button & 0x00F) + 1);
1188 if (button == 3) button = 2;
1189 else if (button == 2) button = 3;
1191 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
1195 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1196 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1199 ELOGF("Mouse", "Button Press (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
1200 button, ecore_device_name_get(ecore_dev), blocked_client,
1201 edev->seat->dev->server_blocked);
1206 edev->mouse.pressed_button |= (1 << button);
1211 if (!(edev->mouse.pressed_button & (1 << button)))
1213 ELOGF("Mouse", "Button Release (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
1214 button, ecore_device_name_get(ecore_dev), blocked_client,
1215 edev->seat->dev->server_blocked);
1218 edev->mouse.pressed_button &= ~(1 << button);
1221 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button))))
1226 ev->window = (Ecore_Window)input->dev->window;
1227 ev->event_window = (Ecore_Window)input->dev->window;
1228 ev->root_window = (Ecore_Window)input->dev->window;
1229 ev->timestamp = timestamp;
1230 ev->same_screen = 1;
1232 _device_modifiers_update(edev);
1233 ev->modifiers = edev->xkb.modifiers;
1235 ev->x = edev->seat->ptr.ix;
1236 ev->y = edev->seat->ptr.iy;
1240 ev->multi.device = edev->mt_slot;
1241 ev->multi.radius = 1;
1242 ev->multi.radius_x = 1;
1243 ev->multi.radius_y = 1;
1244 ev->multi.pressure = 1.0;
1245 ev->multi.angle = 0.0;
1246 ev->multi.x = ev->x;
1247 ev->multi.y = ev->y;
1248 ev->multi.root.x = ev->x;
1249 ev->multi.root.y = ev->y;
1250 ev->dev = ecore_device_ref(ecore_dev);
1254 unsigned int current;
1256 current = timestamp;
1257 edev->mouse.did_double = EINA_FALSE;
1258 edev->mouse.did_triple = EINA_FALSE;
1260 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1261 (button == edev->mouse.prev_button))
1263 edev->mouse.did_double = EINA_TRUE;
1264 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1265 (button == edev->mouse.last_button))
1267 edev->mouse.did_triple = EINA_TRUE;
1268 edev->mouse.prev = 0;
1269 edev->mouse.last = 0;
1274 edev->mouse.last = edev->mouse.prev;
1275 edev->mouse.prev = current;
1276 edev->mouse.last_button = edev->mouse.prev_button;
1277 edev->mouse.prev_button = button;
1280 ev->buttons = button;
1282 if (edev->mouse.did_double)
1283 ev->double_click = 1;
1284 if (edev->mouse.did_triple)
1285 ev->triple_click = 1;
1287 comp_conf = e_comp_config_get();
1288 if (comp_conf && comp_conf->input_log_enable)
1289 ELOGF("Mouse", "Button %s (btn: %d, device: %s)", NULL, state?"Press":"Release", button, ecore_device_name_get(ev->dev));
1292 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, _e_input_event_mouse_button_cb_free, NULL);
1294 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, _e_input_event_mouse_button_cb_free, NULL);
1297 ecore_thread_main_loop_end();
1300 #if !LIBINPUT_HAVE_SCROLL_VALUE_V120
1302 _axis_value_get(struct libinput_event_pointer *pointer_event, enum libinput_pointer_axis axis)
1304 enum libinput_pointer_axis_source source;
1305 double value = 0.0, value_discrete = 0.0;
1307 E_Comp_Config *comp_conf = NULL;
1309 comp_conf = e_comp_config_get();
1310 source = libinput_event_pointer_get_axis_source(pointer_event);
1313 case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL:
1314 value_discrete = libinput_event_pointer_get_axis_value_discrete(pointer_event, axis);
1315 value = libinput_event_pointer_get_axis_value(pointer_event, axis);
1316 if (comp_conf && comp_conf->input_log_enable)
1318 ELOGF("Axis", "SOURCE_WHEEL discrete: %lf (cf. value: %lf)", NULL, value_discrete, value);
1320 ret = (int)value_discrete;
1322 case LIBINPUT_POINTER_AXIS_SOURCE_FINGER:
1323 case LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS:
1324 value = libinput_event_pointer_get_axis_value(pointer_event, axis);
1325 if (comp_conf && comp_conf->input_log_enable)
1327 ELOGF("Axis", "SOURCE_FINGER/CONTINUOUS value: %lf", NULL, value);
1329 if (value >= E_INPUT_FINGER_SCROLL_THRESHOLD)
1331 else if (value <= E_INPUT_FINGER_SCROLL_THRESHOLD * (-1))
1344 _device_handle_axis(struct libinput_device *device, struct libinput_event_pointer *event)
1346 E_Input_Evdev *edev;
1347 E_Input_Backend *input;
1348 Ecore_Event_Mouse_Wheel *ev;
1350 enum libinput_pointer_axis axis;
1351 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1353 E_Comp_Config *comp_conf = NULL;
1354 int direction = 0, z = 0;
1356 if (!(edev = libinput_device_get_user_data(device)))
1360 if (!(input = edev->seat->input))
1365 ecore_thread_main_loop_begin();
1367 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1368 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1370 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1372 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1377 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1382 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1384 ecore_dev = detent_data;
1389 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1390 ecore_dev = edev->ecore_dev;
1395 ERR("Failed to get source ecore device from event !\n");
1399 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1400 if (libinput_event_pointer_has_axis(event, axis))
1401 z = _axis_value_get(event, axis);
1403 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1404 if (libinput_event_pointer_has_axis(event, axis))
1407 z = _axis_value_get(event, axis);
1412 ELOGF("Mouse", "Axis event is ignored since it has zero value", NULL);
1416 comp_conf = e_comp_config_get();
1417 if (comp_conf && comp_conf->e_wheel_click_angle)
1419 z = (int)(z * comp_conf->e_wheel_click_angle);
1422 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1423 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1425 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
1428 ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1429 direction, z, blocked_client, edev->seat->dev->server_blocked);
1431 ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1432 direction, z, blocked_client, edev->seat->dev->server_blocked);
1437 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1442 timestamp = libinput_event_pointer_get_time(event);
1444 ev->window = (Ecore_Window)input->dev->window;
1445 ev->event_window = (Ecore_Window)input->dev->window;
1446 ev->root_window = (Ecore_Window)input->dev->window;
1447 ev->timestamp = timestamp;
1448 ev->same_screen = 1;
1450 _device_modifiers_update(edev);
1451 ev->modifiers = edev->xkb.modifiers;
1453 ev->x = edev->seat->ptr.ix;
1454 ev->y = edev->seat->ptr.iy;
1458 ev->direction = direction;
1460 if (comp_conf && comp_conf->input_log_enable)
1463 ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1465 ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1469 ev->dev = ecore_device_ref(ecore_dev);
1470 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1473 ecore_thread_main_loop_end();
1477 #if LIBINPUT_HAVE_SCROLL_VALUE_V120
1479 _scroll_value_get(struct libinput_event_pointer *pointer_event, enum libinput_pointer_axis axis, E_Input_Axis_Source source)
1482 double value_v120 = 0.0;
1484 E_Comp_Config *comp_conf = NULL;
1486 comp_conf = e_comp_config_get();
1489 case E_INPUT_AXIS_SOURCE_WHEEL:
1490 value_v120 = libinput_event_pointer_get_scroll_value_v120(pointer_event, axis);
1491 value = libinput_event_pointer_get_scroll_value(pointer_event, axis);
1492 if (comp_conf && comp_conf->input_log_enable)
1494 ELOGF("Scroll", "SOURCE_WHEEL value_v120: %lf (cf. value: %lf)", NULL, value_v120, value);
1496 if (((int)value_v120 % E_INPUT_POINTER_AXIS_DISCRETE_STEP) != 0)
1498 ERR("Wheel movements should be multiples (or fractions) of 120!\n");
1503 ret = value_v120 / E_INPUT_POINTER_AXIS_DISCRETE_STEP;
1506 case E_INPUT_AXIS_SOURCE_FINGER:
1507 case E_INPUT_AXIS_SOURCE_CONTINUOUS:
1508 value = libinput_event_pointer_get_scroll_value(pointer_event, axis);
1509 if (comp_conf && comp_conf->input_log_enable)
1511 ELOGF("Scroll", "SOURCE_FINGER/CONTINUOUS value: %lf", NULL, value);
1513 if (value >= E_INPUT_FINGER_SCROLL_THRESHOLD)
1515 else if (value <= E_INPUT_FINGER_SCROLL_THRESHOLD * (-1))
1528 _device_handle_axis_v120(struct libinput_device *device, struct libinput_event_pointer *event, E_Input_Axis_Source source)
1530 E_Input_Evdev *edev;
1531 E_Input_Backend *input;
1532 Ecore_Event_Mouse_Wheel *ev;
1534 enum libinput_pointer_axis axis;
1535 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1537 E_Comp_Config *comp_conf = NULL;
1538 int direction = 0, z = 0;
1540 if (!(edev = libinput_device_get_user_data(device)))
1544 if (!(input = edev->seat->input))
1549 ecore_thread_main_loop_begin();
1551 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1552 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1554 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1556 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1561 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1566 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1568 ecore_dev = detent_data;
1573 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1574 ecore_dev = edev->ecore_dev;
1579 ERR("Failed to get source ecore device from event !\n");
1583 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1584 if (libinput_event_pointer_has_axis(event, axis))
1585 z = _scroll_value_get(event, axis, source);
1587 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1588 if (libinput_event_pointer_has_axis(event, axis))
1591 z = _scroll_value_get(event, axis, source);
1596 ELOGF("Mouse", "Scroll event is ignored since it has zero value", NULL);
1600 comp_conf = e_comp_config_get();
1601 if (comp_conf && comp_conf->e_wheel_click_angle)
1603 z = (int)(z * comp_conf->e_wheel_click_angle);
1606 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1607 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1609 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
1611 ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1612 direction, z, blocked_client, edev->seat->dev->server_blocked);
1614 ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1615 direction, z, blocked_client, edev->seat->dev->server_blocked);
1620 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1625 timestamp = libinput_event_pointer_get_time(event);
1627 ev->window = (Ecore_Window)input->dev->window;
1628 ev->event_window = (Ecore_Window)input->dev->window;
1629 ev->root_window = (Ecore_Window)input->dev->window;
1630 ev->timestamp = timestamp;
1631 ev->same_screen = 1;
1633 _device_modifiers_update(edev);
1634 ev->modifiers = edev->xkb.modifiers;
1636 ev->x = edev->seat->ptr.ix;
1637 ev->y = edev->seat->ptr.iy;
1641 ev->direction = direction;
1643 if (comp_conf && comp_conf->input_log_enable)
1646 ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1648 ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1651 ev->dev = ecore_device_ref(ecore_dev);
1652 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1655 ecore_thread_main_loop_end();
1660 _device_handle_touch_event_send(E_Input_Evdev *edev, struct libinput_event_touch *event, int state)
1662 E_Input_Backend *input;
1663 Ecore_Event_Mouse_Button *ev;
1664 uint32_t timestamp, button = 0;
1665 Ecore_Device *ecore_dev = NULL, *data;
1669 if (!(input = edev->seat->input)) return;
1671 ecore_thread_main_loop_begin();
1673 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1674 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1676 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1678 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1687 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1688 ecore_dev = edev->ecore_dev;
1693 ERR("Failed to get source ecore device from event !\n");
1697 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) goto end;
1699 timestamp = libinput_event_touch_get_time(event);
1701 ev->window = (Ecore_Window)input->dev->window;
1702 ev->event_window = (Ecore_Window)input->dev->window;
1703 ev->root_window = (Ecore_Window)input->dev->window;
1704 ev->timestamp = timestamp;
1705 ev->same_screen = 1;
1707 _device_modifiers_update(edev);
1708 ev->modifiers = edev->xkb.modifiers;
1710 ev->x = edev->seat->ptr.ix;
1711 ev->y = edev->seat->ptr.iy;
1715 ev->multi.device = edev->mt_slot;
1716 ev->multi.radius = 1;
1717 ev->multi.radius_x = 1;
1718 ev->multi.radius_y = 1;
1719 ev->multi.pressure = 1.0;
1720 ev->multi.angle = 0.0;
1721 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1722 if (libinput_event_get_type(libinput_event_touch_get_base_event(event))
1723 == LIBINPUT_EVENT_TOUCH_DOWN)
1725 if (libinput_event_touch_has_minor(event))
1726 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1727 if (libinput_event_touch_has_major(event))
1728 ev->multi.radius_y = libinput_event_touch_get_major(event);
1729 if (libinput_event_touch_has_pressure(event))
1730 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1731 if (libinput_event_touch_has_orientation(event))
1732 ev->multi.angle = libinput_event_touch_get_orientation(event);
1735 ev->multi.x = ev->x;
1736 ev->multi.y = ev->y;
1737 ev->multi.root.x = ev->x;
1738 ev->multi.root.y = ev->y;
1739 ev->dev = ecore_device_ref(ecore_dev);
1741 if (state == ECORE_EVENT_MOUSE_BUTTON_DOWN)
1743 unsigned int current;
1745 current = timestamp;
1746 edev->mouse.did_double = EINA_FALSE;
1747 edev->mouse.did_triple = EINA_FALSE;
1749 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1750 (button == edev->mouse.prev_button))
1752 edev->mouse.did_double = EINA_TRUE;
1753 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1754 (button == edev->mouse.last_button))
1756 edev->mouse.did_triple = EINA_TRUE;
1757 edev->mouse.prev = 0;
1758 edev->mouse.last = 0;
1763 edev->mouse.last = edev->mouse.prev;
1764 edev->mouse.prev = current;
1765 edev->mouse.last_button = edev->mouse.prev_button;
1766 edev->mouse.prev_button = button;
1767 edev->touch.pressed |= (1 << ev->multi.device);
1771 edev->touch.pressed &= ~(1 << ev->multi.device);
1774 ev->buttons = ((button & 0x00F) + 1);
1776 if (edev->mouse.did_double)
1777 ev->double_click = 1;
1778 if (edev->mouse.did_triple)
1779 ev->triple_click = 1;
1781 ecore_event_add(state, ev, _e_input_event_mouse_button_cb_free, NULL);
1784 ecore_thread_main_loop_end();
1788 _device_handle_touch_motion_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1790 E_Input_Backend *input;
1791 Ecore_Event_Mouse_Move *ev;
1792 Ecore_Device *ecore_dev = NULL, *data;
1796 if (!(input = edev->seat->input)) return;
1798 ecore_thread_main_loop_begin();
1800 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1801 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1803 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1805 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1814 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1815 ecore_dev = edev->ecore_dev;
1820 ERR("Failed to get source ecore device from event !\n");
1824 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) goto end;
1826 ev->window = (Ecore_Window)input->dev->window;
1827 ev->event_window = (Ecore_Window)input->dev->window;
1828 ev->root_window = (Ecore_Window)input->dev->window;
1829 ev->timestamp = libinput_event_touch_get_time(event);
1830 ev->same_screen = 1;
1832 _device_modifiers_update(edev);
1833 ev->modifiers = edev->xkb.modifiers;
1835 ev->x = edev->seat->ptr.ix;
1836 ev->y = edev->seat->ptr.iy;
1840 ev->multi.device = edev->mt_slot;
1841 ev->multi.radius = 1;
1842 ev->multi.radius_x = 1;
1843 ev->multi.radius_y = 1;
1844 ev->multi.pressure = 1.0;
1845 ev->multi.angle = 0.0;
1846 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1847 if (libinput_event_touch_has_minor(event))
1848 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1849 if (libinput_event_touch_has_major(event))
1850 ev->multi.radius_y = libinput_event_touch_get_major(event);
1851 if (libinput_event_touch_has_pressure(event))
1852 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1853 if (libinput_event_touch_has_orientation(event))
1854 ev->multi.angle = libinput_event_touch_get_orientation(event);
1856 ev->multi.x = ev->x;
1857 ev->multi.y = ev->y;
1858 ev->multi.root.x = ev->x;
1859 ev->multi.root.y = ev->y;
1860 ev->dev = ecore_device_ref(ecore_dev);
1862 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
1865 ecore_thread_main_loop_end();
1869 _device_handle_touch_cancel_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1871 E_Input_Backend *input;
1872 Ecore_Event_Mouse_Button *ev;
1873 uint32_t timestamp, button = 0;
1874 Ecore_Device *ecore_dev = NULL, *data;
1878 if (!(input = edev->seat->input)) return;
1880 ecore_thread_main_loop_begin();
1882 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1883 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1885 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1887 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1896 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1897 ecore_dev = edev->ecore_dev;
1902 ERR("Failed to get source ecore device from event !\n");
1906 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) goto end;
1908 timestamp = libinput_event_touch_get_time(event);
1910 ev->window = (Ecore_Window)input->dev->window;
1911 ev->event_window = (Ecore_Window)input->dev->window;
1912 ev->root_window = (Ecore_Window)input->dev->window;
1913 ev->timestamp = timestamp;
1914 ev->same_screen = 1;
1916 ev->x = edev->seat->ptr.ix;
1917 ev->y = edev->seat->ptr.iy;
1921 ev->multi.device = edev->mt_slot;
1922 ev->multi.radius = 1;
1923 ev->multi.radius_x = 1;
1924 ev->multi.radius_y = 1;
1925 ev->multi.pressure = 1.0;
1926 ev->multi.angle = 0.0;
1927 ev->multi.x = ev->x;
1928 ev->multi.y = ev->y;
1929 ev->multi.root.x = ev->x;
1930 ev->multi.root.y = ev->y;
1932 edev->touch.pressed &= ~(1 << ev->multi.device);
1934 ev->buttons = ((button & 0x00F) + 1);
1935 ev->dev = ecore_device_ref(ecore_dev);
1937 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev, _e_input_event_mouse_button_cb_free, NULL);
1940 ecore_thread_main_loop_end();
1944 _device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, int *w, int *h)
1946 E_Output *output = NULL;
1948 EINA_SAFETY_ON_NULL_RETURN(edev);
1950 if (!edev->output_configured)
1952 if (edev->output_name)
1954 output = e_output_find(edev->output_name);
1957 edev->mouse.minx = output->config.geom.x;
1958 edev->mouse.miny = output->config.geom.y;
1959 edev->mouse.maxw = output->config.geom.w;
1960 edev->mouse.maxh = output->config.geom.h;
1961 if (edev->caps & E_INPUT_SEAT_POINTER)
1963 edev->seat->ptr.dx = (double)(edev->mouse.maxw / 2);
1964 edev->seat->ptr.dy = (double)(edev->mouse.maxh / 2);
1965 edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
1966 edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
1967 edev->mouse.dx = edev->seat->ptr.dx;
1968 edev->mouse.dy = edev->seat->ptr.dy;
1973 edev->output_configured = EINA_TRUE;
1974 ELOGF("E_INPUT_EVDEV", "Device is configured by output x:%d,y:%d (w:%d, h:%d)",
1975 NULL, edev->mouse.minx, edev->mouse.miny, edev->mouse.maxw, edev->mouse.maxh);
1977 if (x) *x = edev->mouse.minx;
1978 if (y) *y = edev->mouse.miny;
1979 if (w) *w = edev->mouse.maxw;
1980 if (h) *h = edev->mouse.maxh;
1984 _device_handle_touch_down(struct libinput_device *device, struct libinput_event_touch *event)
1986 E_Input_Evdev *edev;
1987 int x = 0, y = 0, w = 0, h = 0;
1988 E_Comp_Config *comp_conf = NULL;
1990 if (!(edev = libinput_device_get_user_data(device)))
1995 _device_configured_size_get(edev, &x, &y, &w, &h);
1997 edev->mouse.dx = edev->seat->ptr.ix = edev->seat->ptr.dx =
1998 x + libinput_event_touch_get_x_transformed(event, w);
1999 edev->mouse.dy = edev->seat->ptr.iy = edev->seat->ptr.dy =
2000 y + libinput_event_touch_get_y_transformed(event, h);
2002 edev->mt_slot = libinput_event_touch_get_slot(event);
2003 if (edev->mt_slot < 0)
2005 /* FIXME: The single touch device return slot id -1
2006 * But currently we have no API to distinguish multi touch or single touch
2007 * After libinput 1.11 version, libinput provides get_touch_count API,
2008 * so we can distinguish multi touch device or single touch device.
2010 if (edev->mt_slot == -1)
2014 WRN("%d slot touch down events are not supported\n", edev->mt_slot);
2019 if (edev->mt_slot < e_input_touch_max_count_get())
2021 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
2022 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
2025 comp_conf = e_comp_config_get();
2026 if (comp_conf && comp_conf->input_log_enable)
2027 ELOGF("Touch", "Down (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2029 atomic_fetch_or(&edev->touch.raw_pressed, (1 << edev->mt_slot));
2031 if (edev->touch.blocked)
2033 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
2034 ELOGF("Touch", "Down (id: %d, x: %d, y: %d) is blocked by %p, server: 0x%x", NULL,
2035 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, blocked_client,
2036 edev->seat->dev->server_blocked);
2040 _device_handle_touch_motion_send(edev, event);
2041 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_DOWN);
2045 _device_handle_touch_motion(struct libinput_device *device, struct libinput_event_touch *event)
2047 E_Input_Evdev *edev;
2048 int x = 0, y = 0, w = 0, h = 0;
2050 if (!(edev = libinput_device_get_user_data(device)))
2055 _device_configured_size_get(edev, &x, &y, &w, &h);
2057 edev->mouse.dx = edev->seat->ptr.dx =
2058 x + libinput_event_touch_get_x_transformed(event, w);
2059 edev->mouse.dy = edev->seat->ptr.dy =
2060 y + libinput_event_touch_get_y_transformed(event, h);
2062 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
2063 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
2068 edev->seat->ptr.ix = edev->seat->ptr.dx;
2069 edev->seat->ptr.iy = edev->seat->ptr.dy;
2071 edev->mt_slot = libinput_event_touch_get_slot(event);
2072 if (edev->mt_slot < 0)
2074 /* FIXME: The single touch device return slot id -1
2075 * But currently we have no API to distinguish multi touch or single touch
2076 * After libinput 1.11 version, libinput provides get_touch_count API,
2077 * so we can distinguish multi touch device or single touch device.
2079 if (edev->mt_slot == -1)
2083 WRN("%d slot touch motion events are not supported\n", edev->mt_slot);
2088 if (edev->mt_slot < e_input_touch_max_count_get())
2090 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
2091 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
2094 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
2096 if (edev->touch.blocked)
2102 _device_handle_touch_motion_send(edev, event);
2106 _device_handle_touch_up(struct libinput_device *device, struct libinput_event_touch *event)
2108 E_Input_Evdev *edev;
2109 E_Comp_Config *comp_conf = NULL;
2111 if (!(edev = libinput_device_get_user_data(device)))
2116 edev->mt_slot = libinput_event_touch_get_slot(event);
2117 if (edev->mt_slot < 0)
2119 /* FIXME: The single touch device return slot id -1
2120 * But currently we have no API to distinguish multi touch or single touch
2121 * After libinput 1.11 version, libinput provides get_touch_count API,
2122 * so we can distinguish multi touch device or single touch device.
2124 if (edev->mt_slot == -1)
2128 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
2133 if (edev->mt_slot < e_input_touch_max_count_get())
2135 edev->mouse.dx = edev->seat->ptr.dx = edev->seat->ptr.ix =
2136 edev->touch.coords[edev->mt_slot].x;
2137 edev->mouse.dy = edev->seat->ptr.dy = edev->seat->ptr.iy =
2138 edev->touch.coords[edev->mt_slot].y;
2141 comp_conf = e_comp_config_get();
2142 if (comp_conf && comp_conf->input_log_enable)
2143 ELOGF("Touch", "Up (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2145 atomic_fetch_and(&edev->touch.raw_pressed, ~(1 << edev->mt_slot));
2147 if (edev->touch.blocked)
2149 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
2151 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
2152 ELOGF("Touch", "Up (id: %d, x: %d, y: %d) is blocked by %p, server(0x%x)", NULL,
2153 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, blocked_client,
2154 edev->seat->dev->server_blocked);
2156 if (edev->touch.raw_pressed == 0x0)
2158 edev->touch.blocked = EINA_FALSE;
2164 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_UP);
2168 _device_handle_touch_cancel(struct libinput_device *device, struct libinput_event_touch *event)
2170 E_Input_Evdev *edev;
2171 E_Comp_Config *comp_conf = NULL;
2173 if (!(edev = libinput_device_get_user_data(device)))
2178 edev->mt_slot = libinput_event_touch_get_slot(event);
2179 if (edev->mt_slot < 0)
2181 /* FIXME: The single touch device return slot id -1
2182 * But currently we have no API to distinguish multi touch or single touch
2183 * After libinput 1.11 version, libinput provides get_touch_count API,
2184 * so we can distinguish multi touch device or single touch device.
2186 if (edev->mt_slot == -1)
2190 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
2195 comp_conf = e_comp_config_get();
2196 if (comp_conf && comp_conf->input_log_enable)
2197 ELOGF("Touch", "cancel (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2199 _device_handle_touch_cancel_send(edev, event);
2204 _device_handle_touch_frame(struct libinput_device *device EINA_UNUSED, struct libinput_event_touch *event EINA_UNUSED)
2206 /* DBG("Unhandled Touch Frame Event"); */
2210 _e_input_aux_data_event_free(void *user_data EINA_UNUSED, void *ev)
2212 Ecore_Event_Axis_Update *e = (Ecore_Event_Axis_Update *)ev;
2214 if (e->axis) free(e->axis);
2215 if (e->dev) ecore_device_unref(e->dev);
2221 _device_handle_touch_aux_data(struct libinput_device *device, struct libinput_event_touch_aux_data *event)
2223 E_Input_Evdev *edev;
2224 E_Input_Backend *input;
2225 Ecore_Event_Axis_Update *ev;
2227 Ecore_Device *ecore_dev = NULL, *data;
2229 E_Comp_Config *comp_conf;
2231 ecore_thread_main_loop_begin();
2233 if (libinput_event_touch_aux_data_get_type(event) != LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM &&
2234 libinput_event_touch_aux_data_get_value(event) > 0)
2237 if (!(edev = libinput_device_get_user_data(device))) goto end;
2238 if (!(input = edev->seat->input)) goto end;
2240 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
2241 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
2243 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
2245 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
2254 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
2255 ecore_dev = edev->ecore_dev;
2260 ERR("Failed to get source ecore device from event !\n");
2264 if (!(ev = calloc(1, sizeof(Ecore_Event_Axis_Update)))) goto end;
2266 ev->window = (Ecore_Window)input->dev->window;
2267 ev->event_window = (Ecore_Window)input->dev->window;
2268 ev->root_window = (Ecore_Window)input->dev->window;
2269 ev->timestamp = libinput_event_touch_aux_data_get_time(event);
2271 axis = (Ecore_Axis *)calloc(1, sizeof(Ecore_Axis));
2274 axis->label = ECORE_AXIS_LABEL_TOUCH_PALM;
2275 axis->value = libinput_event_touch_aux_data_get_value(event);
2280 comp_conf = e_comp_config_get();
2281 if (comp_conf && comp_conf->input_log_enable)
2282 ELOGF("Touch", "Axis (label: %d, value: %lf)", NULL, axis?axis->label:-1, axis?axis->value:0.0);
2284 ev->dev = ecore_device_ref(ecore_dev);
2286 ecore_event_add(ECORE_EVENT_AXIS_UPDATE, ev, _e_input_aux_data_event_free, NULL);
2289 ecore_thread_main_loop_end();
2293 _e_input_evdev_device_create(E_Input_Seat *seat, struct libinput_device *device)
2295 E_Input_Evdev *edev;
2296 E_Input_Backend *b_input;
2297 const char *output_name;
2299 EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
2301 /* try to allocate space for new evdev */
2302 if (!(edev = calloc(1, sizeof(E_Input_Evdev)))) return NULL;
2305 edev->device = device;
2306 edev->path = eina_stringshare_printf("%s/%s", e_input_base_dir_get(), libinput_device_get_sysname(device));
2308 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
2310 edev->caps |= E_INPUT_SEAT_KEYBOARD;
2311 _device_keyboard_setup(edev);
2314 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
2316 edev->caps |= E_INPUT_SEAT_POINTER;
2318 /* TODO: make this configurable */
2319 edev->mouse.threshold = 250;
2321 b_input = seat->input;
2322 if (b_input->left_handed == EINA_TRUE)
2324 if (libinput_device_config_left_handed_set(device, 1) !=
2325 LIBINPUT_CONFIG_STATUS_SUCCESS)
2327 WRN("Failed to set left hand mode about device: %s\n",
2328 libinput_device_get_name(device));
2333 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
2336 edev->caps |= E_INPUT_SEAT_TOUCH;
2337 palm_code = libinput_device_touch_aux_data_get_code(LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM);
2338 if (libinput_device_touch_has_aux_data(device, palm_code))
2340 libinput_device_touch_set_aux_data(device, palm_code);
2343 _device_touch_count_update(edev);
2345 edev->touch.coords = calloc(1, sizeof(E_Input_Coord)*e_input_touch_max_count_get());
2347 if (!edev->touch.coords)
2348 ERR("Failed to allocate memory for touch coords !\n");
2351 output_name = libinput_device_get_output_name(device);
2354 eina_stringshare_replace(&edev->output_name, output_name);
2355 ELOGF("E_INPUT_EVDEV", "Device has output_name:%s", NULL, output_name);
2358 libinput_device_set_user_data(device, edev);
2359 libinput_device_ref(device);
2361 /* configure device */
2362 _device_configure(edev);
2368 _e_input_evdev_device_destroy(E_Input_Evdev *edev)
2371 EINA_SAFETY_ON_NULL_RETURN(edev);
2373 ecore_thread_main_loop_begin();
2375 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
2377 g_mutex_lock(&edev->xkb.state_mutex);
2378 if (edev->xkb.state) xkb_state_unref(edev->xkb.state);
2379 g_mutex_unlock(&edev->xkb.state_mutex);
2381 g_mutex_lock(&edev->xkb.keymap_mutex);
2382 if (edev->xkb.keymap) xkb_map_unref(edev->xkb.keymap);
2383 g_mutex_unlock(&edev->xkb.keymap_mutex);
2386 if (edev->ecore_dev) ecore_device_del(edev->ecore_dev);
2387 if (edev->ecore_dev_list)
2388 EINA_LIST_FREE(edev->ecore_dev_list, dev)
2390 ecore_device_del(dev);
2393 if (edev->e_dev) g_object_unref(edev->e_dev);
2394 if (edev->e_dev_list)
2396 GList *glist = edev->e_dev_list;
2400 e_dev = glist->data;
2401 g_object_unref(e_dev);
2403 glist = g_list_next(glist);
2406 if (edev->path) eina_stringshare_del(edev->path);
2407 if (edev->device) libinput_device_unref(edev->device);
2408 if (edev->key_remap_hash) eina_hash_free(edev->key_remap_hash);
2409 if (edev->touch.coords)
2411 free(edev->touch.coords);
2412 edev->touch.coords = NULL;
2414 eina_stringshare_del(edev->output_name);
2416 ecore_thread_main_loop_end();
2422 _e_input_evdev_event_process(struct libinput_event *event)
2424 struct libinput_device *device;
2425 Eina_Bool ret = EINA_TRUE;
2427 device = libinput_event_get_device(event);
2428 switch (libinput_event_get_type(event))
2430 case LIBINPUT_EVENT_KEYBOARD_KEY:
2431 _device_handle_key(device, libinput_event_get_keyboard_event(event));
2433 case LIBINPUT_EVENT_POINTER_MOTION:
2434 _device_handle_pointer_motion(device,
2435 libinput_event_get_pointer_event(event));
2437 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
2438 _device_handle_pointer_motion_absolute(device,
2439 libinput_event_get_pointer_event(event));
2441 case LIBINPUT_EVENT_POINTER_BUTTON:
2442 _device_handle_button(device, libinput_event_get_pointer_event(event));
2444 case LIBINPUT_EVENT_POINTER_AXIS:
2445 #if !LIBINPUT_HAVE_SCROLL_VALUE_V120
2446 _device_handle_axis(device, libinput_event_get_pointer_event(event));
2449 #if LIBINPUT_HAVE_SCROLL_VALUE_V120
2450 case LIBINPUT_EVENT_POINTER_SCROLL_WHEEL:
2451 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_WHEEL);
2453 case LIBINPUT_EVENT_POINTER_SCROLL_FINGER:
2454 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_FINGER);
2456 case LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS:
2457 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_CONTINUOUS);
2460 case LIBINPUT_EVENT_TOUCH_DOWN:
2461 _device_handle_touch_down(device, libinput_event_get_touch_event(event));
2463 case LIBINPUT_EVENT_TOUCH_MOTION:
2464 _device_handle_touch_motion(device,
2465 libinput_event_get_touch_event(event));
2467 case LIBINPUT_EVENT_TOUCH_UP:
2468 _device_handle_touch_up(device, libinput_event_get_touch_event(event));
2470 case LIBINPUT_EVENT_TOUCH_CANCEL:
2471 _device_handle_touch_cancel(device, libinput_event_get_touch_event(event));
2473 case LIBINPUT_EVENT_TOUCH_FRAME:
2474 _device_handle_touch_frame(device, libinput_event_get_touch_event(event));
2476 case LIBINPUT_EVENT_TOUCH_AUX_DATA:
2477 _device_handle_touch_aux_data(device, libinput_event_get_touch_aux_data(event));
2488 * @brief Set the axis size of the given device.
2490 * @param dev The device to set the axis size to.
2491 * @param w The width of the axis.
2492 * @param h The height of the axis.
2494 * This function sets set the width @p w and height @p h of the axis
2495 * of device @p dev. If @p dev is a relative input device, a width and
2496 * height must set for it. If its absolute set the ioctl correctly, if
2497 * not, unsupported device.
2500 e_input_evdev_axis_size_set(E_Input_Evdev *edev, int w, int h)
2502 const char *sysname;
2507 enum libinput_config_status status;
2509 EINA_SAFETY_ON_NULL_RETURN(edev);
2510 EINA_SAFETY_ON_TRUE_RETURN((w == 0) || (h == 0));
2512 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
2513 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
2516 sysname = libinput_device_get_sysname(edev->device);
2518 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
2519 if (eina_list_count(devices) < 1) return;
2521 EINA_LIST_FREE(devices, device)
2523 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
2525 (sscanf(vals, "%f %f %f %f %f %f",
2526 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
2533 libinput_device_config_calibration_set_matrix(edev->device, cal);
2535 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
2536 ERR("Failed to apply calibration");
2539 eina_stringshare_del(device);
2544 EINTERN const char *
2545 e_input_evdev_name_get(E_Input_Evdev *evdev)
2547 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2548 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2550 return libinput_device_get_name(evdev->device);
2553 EINTERN const char *
2554 e_input_evdev_sysname_get(E_Input_Evdev *evdev)
2556 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2557 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2559 return libinput_device_get_sysname(evdev->device);
2563 e_input_evdev_key_remap_enable(E_Input_Evdev *edev, Eina_Bool enable)
2565 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2566 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2568 edev->key_remap_enabled = enable;
2570 if (enable == EINA_FALSE && edev->key_remap_hash)
2572 eina_hash_free(edev->key_remap_hash);
2573 edev->key_remap_hash = NULL;
2580 e_input_evdev_key_remap_set(E_Input_Evdev *edev, int *from_keys, int *to_keys, int num)
2584 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2585 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2586 EINA_SAFETY_ON_NULL_RETURN_VAL(from_keys, EINA_FALSE);
2587 EINA_SAFETY_ON_NULL_RETURN_VAL(to_keys, EINA_FALSE);
2588 EINA_SAFETY_ON_TRUE_RETURN_VAL(num <= 0, EINA_FALSE);
2589 EINA_SAFETY_ON_TRUE_RETURN_VAL(!edev->key_remap_enabled, EINA_FALSE);
2591 if (edev->key_remap_hash == NULL)
2592 edev->key_remap_hash = eina_hash_int32_new(NULL);
2594 if (edev->key_remap_hash == NULL)
2596 ERR("Failed to set remap key information : creating a hash is failed.");
2600 for (i = 0; i < num ; i++)
2602 if (!from_keys[i] || !to_keys[i])
2604 ERR("Failed to set remap key information : given arguments are invalid.");
2609 for (i = 0; i < num ; i++)
2611 eina_hash_add(edev->key_remap_hash, &from_keys[i], (void *)(intptr_t)to_keys[i]);
2618 e_input_evdev_wheel_click_angle_get(E_Input_Evdev *dev)
2620 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, -1);
2621 return libinput_device_config_scroll_get_wheel_click_angle(dev->device);
2625 e_input_evdev_touch_calibration_set(E_Input_Evdev *edev, float matrix[6])
2627 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2628 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2630 if (!libinput_device_config_calibration_has_matrix(edev->device) ||
2631 !libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_TOUCH))
2634 if (libinput_device_config_calibration_set_matrix(edev->device, matrix) !=
2635 LIBINPUT_CONFIG_STATUS_SUCCESS)
2637 WRN("Failed to set input transformation about device: %s\n",
2638 libinput_device_get_name(edev->device));
2646 e_input_evdev_mouse_accel_speed_set(E_Input_Evdev *edev, double speed)
2648 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2649 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2651 if (!libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
2654 if (!libinput_device_config_accel_is_available(edev->device))
2657 if (libinput_device_config_accel_set_speed(edev->device, speed) !=
2658 LIBINPUT_CONFIG_STATUS_SUCCESS)
2660 WRN("Failed to set mouse accel about device: %s\n",
2661 libinput_device_get_name(edev->device));
2668 EINTERN unsigned int
2669 e_input_evdev_touch_pressed_get(E_Input_Evdev *edev)
2671 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, 0x0);
2673 return edev->touch.pressed;
2677 e_input_evdev_seatname_get(E_Input_Evdev *evdev)
2679 struct libinput_seat *libinput_seat;
2680 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2681 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2683 libinput_seat = libinput_device_get_seat(evdev->device);
2685 return libinput_seat_get_logical_name(libinput_seat);
2689 e_input_evdev_seatname_set(E_Input_Evdev *evdev, const char *seatname)
2691 Eina_Bool res = EINA_FALSE;
2692 E_Input_Backend *input;
2694 EINA_SAFETY_ON_NULL_RETURN_VAL(seatname, EINA_FALSE);
2695 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, EINA_FALSE);
2696 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, EINA_FALSE);
2698 if (libinput_device_set_seat_logical_name(evdev->device, seatname) == 0)
2700 input = evdev->seat->input;
2701 if (!input) return EINA_FALSE;
2703 if (libinput_dispatch(input->libinput) != 0)
2705 ERR("Failed to dispatch libinput events: %m");
2710 /* process pending events */
2711 _input_events_process(input);