2 #include "e_input_private.h"
4 #include "e_keyrouter_private.h"
5 #include "e_input_event.h"
6 #include "e_devicemgr.h"
10 #define G_LIST_GET_DATA(list) ((list) ? (((GList *)(list))->data) : NULL)
12 static void _device_modifiers_update(E_Input_Evdev *edev);
13 static void _device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, int *w, int *h);
14 static void _device_output_assign(E_Input_Evdev *edev, E_Input_Seat_Capabilities cap);
17 _device_calibration_set(E_Input_Evdev *edev)
22 E_Comp_Config *comp_conf;
24 if (e_comp->e_comp_screen->num_outputs > 1) //multiple outputs
26 comp_conf = e_comp_config_get();
27 if (comp_conf && (comp_conf->input_output_assign_policy == 1)) //use output-assignment policy
29 _device_output_assign(edev, E_INPUT_SEAT_POINTER);
30 _device_output_assign(edev, E_INPUT_SEAT_TOUCH);
34 output = e_comp_screen_primary_output_get(e_comp->e_comp_screen);
35 e_output_size_get(output, &w, &h);
39 edev->mouse.minx = edev->mouse.miny = 0;
43 if (libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
45 edev->seat->ptr.dx = (double)(w / 2);
46 edev->seat->ptr.dy = (double)(h / 2);
47 edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
48 edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
49 edev->mouse.dx = edev->seat->ptr.dx;
50 edev->mouse.dy = edev->seat->ptr.dy;
52 if (output->config.rotation == 90 || output->config.rotation == 270)
54 temp = edev->mouse.minx;
55 edev->mouse.minx = edev->mouse.miny;
56 edev->mouse.miny = temp;
58 temp = edev->mouse.maxw;
59 edev->mouse.maxw = edev->mouse.maxh;
60 edev->mouse.maxh = temp;
66 #ifdef _F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
72 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
73 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
76 sysname = libinput_device_get_sysname(edev->device);
78 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
79 if (eina_list_count(devices) < 1) return;
81 #ifdef _F_E_INPUT_USE_WL_CALIBRATION_
83 enum libinput_config_status status;
85 EINA_LIST_FREE(devices, device)
87 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
89 (sscanf(vals, "%f %f %f %f %f %f",
90 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
97 libinput_device_config_calibration_set_matrix(edev->device, cal);
99 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
100 ERR("Failed to apply calibration");
103 eina_stringshare_del(device);
106 #endif//_F_E_INPUT_USE_WL_CALIBRATION_
107 #endif//_F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
112 _device_output_assign(E_Input_Evdev *edev, E_Input_Seat_Capabilities cap)
117 Eina_Bool need_assign_output = EINA_FALSE;
118 const char *output_name;
121 if (!(edev->caps & cap)) return;
122 if (edev->output_name) return; //already assigned
123 if (e_comp->e_comp_screen->num_outputs <= 1) return;
125 last_output_idx = e_comp->e_comp_screen->num_outputs - 1;
126 EINA_LIST_FOREACH(edev->seat->devices, l, ed)
128 if (!(ed->caps & cap)) continue;
129 if (ed == edev) continue;
132 need_assign_output = EINA_FALSE;
135 need_assign_output = EINA_TRUE;
137 if (need_assign_output)
139 output = e_output_find_by_index(last_output_idx);
140 if (!output || !output->info.connected) return;
141 output_name = e_output_output_id_get(output);
142 if (output_name) edev->output_name = eina_stringshare_add(output_name);
143 ELOGF("E_INPUT_EVDEV", "Device is assigned to output:%s", NULL, output_name);
148 _device_touch_count_update(E_Input_Evdev *edev)
150 unsigned int device_touch_count = 0;
151 static unsigned int _max_device_touch_count = 0;
153 E_Input *ei = e_input_get();
154 EINA_SAFETY_ON_NULL_RETURN(ei);
156 device_touch_count = libinput_device_touch_get_touch_count(edev->device);
158 if (_max_device_touch_count < device_touch_count)
159 _max_device_touch_count = device_touch_count;
161 if (e_config->configured_max_touch.use)
163 if (_max_device_touch_count > 0 && e_config->configured_max_touch.count > _max_device_touch_count)
165 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",
166 NULL, e_config->configured_max_touch.count, _max_device_touch_count, _max_device_touch_count);
167 ei->touch_max_count = _max_device_touch_count;
171 if (ei->touch_max_count != e_config->configured_max_touch.count)
173 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch_max_count has been updated to %d -> %d.\n",
174 NULL, ei->touch_max_count, e_config->configured_max_touch.count);
175 ei->touch_max_count = e_config->configured_max_touch.count;
181 if (ei->touch_max_count < _max_device_touch_count)
183 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch_max_count has been updated to %d -> %d.\n", NULL,
184 ei->touch_max_count, _max_device_touch_count);
185 ei->touch_max_count = _max_device_touch_count;
189 ei->touch_device_count++;
190 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch device count is %d.\n", NULL, ei->touch_device_count);
194 _device_configure(E_Input_Evdev *edev)
196 if (libinput_device_config_tap_get_finger_count(edev->device) > 0)
198 Eina_Bool tap = EINA_FALSE;
200 tap = libinput_device_config_tap_get_default_enabled(edev->device);
201 libinput_device_config_tap_set_enabled(edev->device, tap);
204 _device_calibration_set(edev);
208 _device_keyboard_setup(E_Input_Evdev *edev)
210 E_Input_Backend *input;
211 xkb_mod_index_t xkb_idx;
213 if ((!edev) || (!edev->seat)) return;
214 if (!(input = edev->seat->input)) return;
215 if (!input->dev->xkb_ctx) return;
217 g_mutex_init(&edev->xkb.keymap_mutex);
219 /* create keymap from xkb context */
220 g_mutex_lock(&edev->xkb.keymap_mutex);
221 edev->xkb.keymap = _e_input_device_cached_keymap_get(input->dev->xkb_ctx, NULL, 0);
222 if (!edev->xkb.keymap)
224 g_mutex_unlock(&edev->xkb.keymap_mutex);
225 ERR("Failed to create keymap: %m");
229 g_mutex_lock(&edev->xkb.state_mutex);
231 /* create xkb state */
232 if (!(edev->xkb.state = xkb_state_new(edev->xkb.keymap)))
234 g_mutex_unlock(&edev->xkb.state_mutex);
235 g_mutex_unlock(&edev->xkb.keymap_mutex);
236 ERR("Failed to create xkb state: %m");
240 g_mutex_unlock(&edev->xkb.state_mutex);
242 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CTRL);
243 if (xkb_idx != XKB_MOD_INVALID)
244 edev->xkb.ctrl_mask = 1 << xkb_idx;
246 edev->xkb.ctrl_mask = 0;
248 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_ALT);
249 if (xkb_idx != XKB_MOD_INVALID)
250 edev->xkb.alt_mask = 1 << xkb_idx;
252 edev->xkb.alt_mask = 0;
254 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_SHIFT);
255 if (xkb_idx != XKB_MOD_INVALID)
256 edev->xkb.shift_mask = 1 << xkb_idx;
258 edev->xkb.shift_mask = 0;
260 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_LOGO);
261 if (xkb_idx != XKB_MOD_INVALID)
262 edev->xkb.win_mask = 1 << xkb_idx;
264 edev->xkb.win_mask = 0;
266 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_SCROLL);
267 if (xkb_idx != XKB_MOD_INVALID)
268 edev->xkb.scroll_mask = 1 << xkb_idx;
270 edev->xkb.scroll_mask = 0;
272 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_NUM);
273 if (xkb_idx != XKB_MOD_INVALID)
274 edev->xkb.num_mask = 1 << xkb_idx;
276 edev->xkb.num_mask = 0;
278 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CAPS);
279 if (xkb_idx != XKB_MOD_INVALID)
280 edev->xkb.caps_mask = 1 << xkb_idx;
282 edev->xkb.caps_mask = 0;
284 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, "ISO_Level3_Shift");
285 if (xkb_idx != XKB_MOD_INVALID)
286 edev->xkb.altgr_mask = 1 << xkb_idx;
288 edev->xkb.altgr_mask = 0;
290 g_mutex_unlock(&edev->xkb.keymap_mutex);
294 _device_keysym_translate(xkb_keysym_t keysym, unsigned int modifiers, char *buffer, int bytes)
296 unsigned long hbytes = 0;
299 if (!keysym) return 0;
300 hbytes = (keysym >> 8);
305 (((keysym >= XKB_KEY_BackSpace) && (keysym <= XKB_KEY_Clear)) ||
306 (keysym == XKB_KEY_Return) || (keysym == XKB_KEY_Escape) ||
307 (keysym == XKB_KEY_KP_Space) || (keysym == XKB_KEY_KP_Tab) ||
308 (keysym == XKB_KEY_KP_Enter) ||
309 ((keysym >= XKB_KEY_KP_Multiply) && (keysym <= XKB_KEY_KP_9)) ||
310 (keysym == XKB_KEY_KP_Equal) || (keysym == XKB_KEY_Delete))))))
313 if (keysym == XKB_KEY_KP_Space)
314 c = (XKB_KEY_space & 0x7F);
315 else if (hbytes == 0xFF)
320 if (modifiers & ECORE_EVENT_MODIFIER_CTRL)
322 if (((c >= '@') && (c < '\177')) || c == ' ')
326 else if ((c >= '3') && (c <= '7'))
338 _device_modifiers_update_device(E_Input_Evdev *edev, E_Input_Evdev *from)
342 g_mutex_lock(&from->xkb.state_mutex);
344 edev->xkb.depressed =
345 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_DEPRESSED);
347 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LATCHED);
349 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LOCKED);
351 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_EFFECTIVE);
353 g_mutex_unlock(&from->xkb.state_mutex);
355 mask = (edev->xkb.depressed | edev->xkb.latched);
357 if (mask & from->xkb.ctrl_mask)
358 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_CTRL;
359 if (mask & from->xkb.alt_mask)
360 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALT;
361 if (mask & from->xkb.shift_mask)
362 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
363 if (mask & from->xkb.win_mask)
364 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_WIN;
365 if (mask & from->xkb.scroll_mask)
366 edev->xkb.modifiers |= ECORE_EVENT_LOCK_SCROLL;
367 if (mask & from->xkb.num_mask)
368 edev->xkb.modifiers |= ECORE_EVENT_LOCK_NUM;
369 if (mask & from->xkb.caps_mask)
370 edev->xkb.modifiers |= ECORE_EVENT_LOCK_CAPS;
371 if (mask & from->xkb.altgr_mask)
372 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALTGR;
376 _device_modifiers_update(E_Input_Evdev *edev)
381 edev->xkb.modifiers = 0;
383 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
384 _device_modifiers_update_device(edev, edev);
387 EINA_LIST_FOREACH(edev->seat->devices, l, ed)
389 if (!(ed->caps & E_INPUT_SEAT_KEYBOARD)) continue;
390 _device_modifiers_update_device(edev, ed);
397 _device_remapped_key_get(E_Input_Evdev *edev, int code)
401 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, code);
402 if (!edev->key_remap_enabled) return code;
403 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->key_remap_hash, code);
405 ret = eina_hash_find(edev->key_remap_hash, &code);
407 if (ret) code = (int)(intptr_t)ret;
413 e_input_evdev_get_e_device(const char *path, Ecore_Device_Class clas)
415 const GList *dev_list = NULL;
417 E_Device *dev = NULL;
418 const char *identifier;
420 if (!path) return NULL;
422 dev_list = e_device_list_get();
423 if (!dev_list) return NULL;
430 identifier = e_device_identifier_get(dev);
431 if (!identifier) continue;
432 if ((e_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
441 EINTERN Ecore_Device *
442 e_input_evdev_get_ecore_device(const char *path, Ecore_Device_Class clas)
444 const Eina_List *dev_list = NULL;
446 Ecore_Device *dev = NULL;
447 const char *identifier;
449 if (!path) return NULL;
451 dev_list = ecore_device_list();
452 if (!dev_list) return NULL;
453 EINA_LIST_FOREACH(dev_list, l, dev)
456 identifier = ecore_device_identifier_get(dev);
457 if (!identifier) continue;
458 if ((ecore_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
465 _e_input_event_mouse_move_cb_free(void *data EINA_UNUSED, void *event)
467 Ecore_Event_Mouse_Move *ev = event;
469 if (ev->dev) ecore_device_unref(ev->dev);
475 _e_input_event_mouse_relative_move_cb_free(void *data EINA_UNUSED, void *event)
477 Ecore_Event_Mouse_Relative_Move *ev = event;
479 if (ev->dev) ecore_device_unref(ev->dev);
485 _e_input_event_mouse_wheel_cb_free(void *data EINA_UNUSED, void *event)
487 Ecore_Event_Mouse_Wheel *ev = event;
489 if (ev->dev) ecore_device_unref(ev->dev);
495 _e_input_event_mouse_button_cb_free(void *data EINA_UNUSED, void *event)
497 Ecore_Event_Mouse_Button *ev = event;
499 if (ev->dev) ecore_device_unref(ev->dev);
505 _e_input_event_key_cb_free(void *data EINA_UNUSED, void *event)
507 Ecore_Event_Key *ev = event;
509 if (e_input_thread_mode_get())
511 if (ev->dev) g_object_unref(ev->dev);
515 if (ev->dev) ecore_device_unref(ev->dev);
518 if (ev->data) E_FREE(ev->data);
524 _device_handle_key(struct libinput_device *device, struct libinput_event_keyboard *event)
527 E_Input_Backend *input;
529 uint32_t code, nsyms;
530 const xkb_keysym_t *syms;
531 enum libinput_key_state state;
533 xkb_keysym_t sym = XKB_KEY_NoSymbol;
534 char key[256] = {0, }, keyname[256] = {0, }, compose_buffer[256] = {0, };
536 char *tmp = NULL, *compose = NULL;
537 E_Keyrouter_Event_Data *key_data;
538 Ecore_Device *ecore_dev = NULL, *data;
539 E_Device *e_dev = NULL, *e_dev_data;
540 Eina_List *l = NULL, *l_next = NULL;
542 E_Comp_Config *comp_conf = NULL;
543 int *pressed_keycode = NULL, *idata = NULL;
544 Eina_Bool dup_found = EINA_FALSE;
545 const char* device_name = NULL;
546 Ecore_Device_Subclass device_subclas = ECORE_DEVICE_SUBCLASS_NONE;
548 if (!(edev = libinput_device_get_user_data(device)))
553 if (!(input = edev->seat->input))
558 if (!e_input_thread_mode_get())
560 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
561 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
563 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
565 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_KEYBOARD)
574 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
575 ecore_dev = edev->ecore_dev;
580 ERR("Failed to get source ecore device from event !\n");
584 device_name = ecore_device_name_get(ecore_dev);
585 device_subclas = ecore_device_subclass_get(ecore_dev);
589 if (edev->e_dev) e_dev = edev->e_dev;
590 else if (edev->e_dev_list && g_list_length(edev->e_dev_list) > 0)
592 glist = edev->e_dev_list;
595 e_dev_data = glist->data;
596 if (e_device_class_get(e_dev_data) == ECORE_DEVICE_CLASS_KEYBOARD)
602 glist = g_list_next(glist);
607 edev->e_dev = e_input_evdev_get_e_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
613 ERR("Failed to get source e device from event !\n");
617 device_name = e_device_name_get(e_dev);
618 device_subclas = e_device_subclass_get(e_dev);
621 timestamp = libinput_event_keyboard_get_time(event);
622 code = libinput_event_keyboard_get_key(event);
623 code = _device_remapped_key_get(edev, code + 8);
624 state = libinput_event_keyboard_get_key_state(event);
625 key_count = libinput_event_keyboard_get_seat_key_count(event);
627 if (state == LIBINPUT_KEY_STATE_PRESSED)
629 if ((edev->seat->dev->blocked & E_INPUT_SEAT_KEYBOARD) ||
630 (edev->seat->dev->server_blocked & E_INPUT_SEAT_KEYBOARD))
632 g_mutex_lock(&edev->seat->dev->blocked_client_mutex);
633 ELOGF("Key", "Press (keycode: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
634 code, device_name, edev->seat->dev->blocked_client,
635 edev->seat->dev->server_blocked);
636 g_mutex_unlock(&edev->seat->dev->blocked_client_mutex);
640 /* FIXME: Currently to maintain press/release event pair during input block,
641 * used Eina_List and this is method used in devicemgr module.
642 * But we need to consider which way is better to maintain key press/release pair.
645 EINA_LIST_FOREACH(edev->xkb.pressed_keys, l, idata)
649 dup_found = EINA_TRUE;
655 pressed_keycode = E_NEW(int, 1);
656 EINA_SAFETY_ON_NULL_RETURN(pressed_keycode);
657 *pressed_keycode = code;
659 edev->xkb.pressed_keys = eina_list_append(edev->xkb.pressed_keys, pressed_keycode);
664 dup_found = EINA_FALSE;
665 EINA_LIST_FOREACH_SAFE(edev->xkb.pressed_keys, l, l_next, idata)
669 edev->xkb.pressed_keys = eina_list_remove_list(edev->xkb.pressed_keys, l);
671 dup_found = EINA_TRUE;
677 g_mutex_lock(&edev->seat->dev->blocked_client_mutex);
678 ELOGF("Key", "Release (keycode: %d, device: %s) is blocked by %p", NULL,
679 code, device_name, edev->seat->dev->blocked_client);
680 g_mutex_unlock(&edev->seat->dev->blocked_client_mutex);
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 func(code, state, timestamp);
702 g_mutex_lock(&edev->xkb.state_mutex);
703 xkb_state_update_key(edev->xkb.state, code,
704 (state ? XKB_KEY_DOWN : XKB_KEY_UP));
706 /* get the keysym for this code */
707 nsyms = xkb_key_get_syms(edev->xkb.state, code, &syms);
708 g_mutex_unlock(&edev->xkb.state_mutex);
710 if (nsyms == 1) sym = syms[0];
712 /* If no keysym was found, name it "Keycode-NNN" */
713 if (sym == XKB_KEY_NoSymbol)
714 snprintf(key, sizeof(key), "Keycode-%u", code);
717 /* get the keyname for this sym */
718 xkb_keysym_get_name(sym, key, sizeof(key));
723 /* If no keyname was found, name it "Keycode-NNN" */
724 snprintf(keyname, sizeof(keyname), "Keycode-%u", code);
728 memcpy(keyname, key, sizeof(keyname));
731 /* if shift is active, we need to transform the key to lower */
732 g_mutex_lock(&edev->xkb.keymap_mutex);
733 g_mutex_lock(&edev->xkb.state_mutex);
734 if (xkb_state_mod_index_is_active(edev->xkb.state,
735 xkb_map_mod_get_index(edev->xkb.keymap,
737 XKB_STATE_MODS_EFFECTIVE))
739 if (keyname[0] != '\0')
740 keyname[0] = tolower(keyname[0]);
742 g_mutex_unlock(&edev->xkb.keymap_mutex);
743 g_mutex_unlock(&edev->xkb.state_mutex);
745 if (_device_keysym_translate(sym, edev->xkb.modifiers,
746 compose_buffer, sizeof(compose_buffer)))
748 compose = eina_str_convert("ISO8859-1", "UTF-8", compose_buffer);
751 ERR("E Input cannot convert input key string '%s' to UTF-8. "
752 "Is Eina built with iconv support?", compose_buffer);
758 if (!compose) compose = compose_buffer;
760 e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) +
761 ((compose[0] != '\0') ? strlen(compose) : 0) + 3);
767 key_data = E_NEW(E_Keyrouter_Event_Data, 1);
775 e->keyname = (char *)(e + 1);
776 e->key = e->keyname + strlen(keyname) + 1;
777 e->compose = strlen(compose) ? e->key + strlen(key) + 1 : NULL;
778 e->string = e->compose;
780 strncpy((char *)e->keyname, keyname, strlen(keyname));
781 strncpy((char *)e->key, key, strlen(key));
782 if (strlen(compose)) strncpy((char *)e->compose, compose, strlen(compose));
784 e->window = (Ecore_Window)input->dev->window;
785 e->event_window = (Ecore_Window)input->dev->window;
786 e->root_window = (Ecore_Window)input->dev->window;
787 e->timestamp = timestamp;
792 _device_modifiers_update(edev);
794 e->modifiers = edev->xkb.modifiers;
796 comp_conf = e_comp_config_get();
798 if (comp_conf && comp_conf->input_log_enable)
799 ELOGF("Key", "%s (keyname: %s, keycode: %d, timestamp: %u, device: %s)", NULL, state?"Press":"Release", e->keyname, e->keycode, e->timestamp, device_name);
801 if (e_input_thread_mode_get())
803 e->dev = (Eo *)g_object_ref(e_dev);
804 e_input_event_add(input->event_source, state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
808 e->dev = ecore_device_ref(ecore_dev);
809 ecore_event_add(state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
816 _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event)
818 E_Input_Backend *input;
819 Ecore_Event_Mouse_Move *ev;
820 Ecore_Device *ecore_dev = NULL, *data, *detent_data = NULL;
822 int x = 0, y = 0, w = 0, h = 0;
824 if (!(input = edev->seat->input)) return;
826 ecore_thread_main_loop_begin();
828 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
829 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
831 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
833 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
838 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
843 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
845 ecore_dev = detent_data;
850 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
851 ecore_dev = edev->ecore_dev;
856 ERR("Failed to get source ecore device from event !\n");
859 else if ((detent_data == ecore_dev) || e_devicemgr_detent_is_detent(ecore_device_name_get(ecore_dev)))
861 /* Do not process detent device's move events. */
865 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
867 _device_configured_size_get(edev, &x, &y, &w, &h);
869 if (edev->seat->ptr.ix < x)
870 edev->seat->ptr.dx = edev->seat->ptr.ix = x;
871 else if (edev->seat->ptr.ix >= (x + w))
872 edev->seat->ptr.dx = edev->seat->ptr.ix = (x + w - 1);
874 if (edev->seat->ptr.iy < y)
875 edev->seat->ptr.dy = edev->seat->ptr.iy = y;
876 else if (edev->seat->ptr.iy >= (y + h))
877 edev->seat->ptr.dy = edev->seat->ptr.iy = (y + h - 1);
879 edev->mouse.dx = edev->seat->ptr.dx;
880 edev->mouse.dy = edev->seat->ptr.dy;
882 ev->window = (Ecore_Window)input->dev->window;
883 ev->event_window = (Ecore_Window)input->dev->window;
884 ev->root_window = (Ecore_Window)input->dev->window;
885 if (event) ev->timestamp = libinput_event_pointer_get_time(event);
888 _device_modifiers_update(edev);
889 ev->modifiers = edev->xkb.modifiers;
891 ev->x = edev->seat->ptr.ix;
892 ev->y = edev->seat->ptr.iy;
896 ev->multi.device = edev->mt_slot;
897 ev->multi.radius = 1;
898 ev->multi.radius_x = 1;
899 ev->multi.radius_y = 1;
900 ev->multi.pressure = 1.0;
901 ev->multi.angle = 0.0;
904 ev->multi.root.x = ev->x;
905 ev->multi.root.y = ev->y;
907 ev->dev = ecore_device_ref(ecore_dev);
909 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
912 ecore_thread_main_loop_end();
916 _e_input_pointer_motion_post(E_Input_Evdev *edev)
918 _device_pointer_motion(edev, NULL);
922 _device_pointer_relative_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event, double dx[2], double dy[2])
924 E_Input_Backend *input;
925 Ecore_Event_Mouse_Relative_Move *ev;
926 Ecore_Device *ecore_dev = NULL, *data, *detent_data = NULL;
928 E_Comp_Config *comp_conf;
930 if (!(input = edev->seat->input)) return;
932 ecore_thread_main_loop_begin();
934 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
935 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
937 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
939 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
944 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
949 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
951 ecore_dev = detent_data;
956 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
957 ecore_dev = edev->ecore_dev;
962 ERR("Failed to get source ecore device from event !\n");
965 else if ((detent_data == ecore_dev) || e_devicemgr_detent_is_detent(ecore_device_name_get(ecore_dev)))
967 /* Do not process detent device's move events. */
971 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Relative_Move)))) return;
973 ev->window = (Ecore_Window)input->dev->window;
974 ev->event_window = (Ecore_Window)input->dev->window;
975 if (event) ev->timestamp = libinput_event_pointer_get_time(event);
977 ev->modifiers = edev->xkb.modifiers;
981 ev->dx_unaccel = (int)dx[1];
982 ev->dy_unaccel = (int)dy[1];
984 ev->dev = ecore_device_ref(ecore_dev);
986 comp_conf = e_comp_config_get();
987 if (comp_conf && comp_conf->input_log_enable)
988 ELOGF("Mouse", "Relative Move (dx: %d, dy: %d, unaccel(%d, %d) device: %s)", NULL, ev->dx, ev->dx, ev->dx_unaccel, ev->dy_unaccel, ecore_device_name_get(ev->dev));
990 ecore_event_add(ECORE_EVENT_MOUSE_RELATIVE_MOVE, ev, _e_input_event_mouse_relative_move_cb_free, NULL);
993 ecore_thread_main_loop_end();
997 _device_pointer_motion_send(E_Input_Evdev *edev, struct libinput_event_pointer *event, double dx[2], double dy[2])
999 e_input_relative_motion_cb func = e_input_relative_motion_handler_get();
1002 //func(dx, dy, time_us);
1003 _device_pointer_relative_motion(edev, event, dx, dy);
1007 double seat_dx, seat_dy, temp;
1008 if (edev->disable_acceleration)
1019 if (edev->seat->ptr.swap)
1025 if (edev->seat->ptr.invert_x)
1027 if (edev->seat->ptr.invert_y)
1030 edev->seat->ptr.dx += seat_dx;
1031 edev->seat->ptr.dy += seat_dy;
1033 edev->mouse.dx = edev->seat->ptr.dx;
1034 edev->mouse.dy = edev->seat->ptr.dy;
1036 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
1037 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
1042 edev->seat->ptr.ix = edev->seat->ptr.dx;
1043 edev->seat->ptr.iy = edev->seat->ptr.dy;
1045 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1046 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1051 _device_pointer_motion(edev, event);
1056 _device_handle_pointer_motion(struct libinput_device *device, struct libinput_event_pointer *event)
1058 E_Input_Evdev *edev;
1059 double delta_x[2]; /* delta_x[0] for accelerated, delta_x[1] for unaccelerated */
1060 double delta_y[2]; /* delta_y[0] for accelerated, delta_y[1] for unaccelerated */
1062 if (!(edev = libinput_device_get_user_data(device)))
1067 delta_x[0] = libinput_event_pointer_get_dx(event);
1068 delta_x[1] = libinput_event_pointer_get_dx_unaccelerated(event);
1069 delta_y[0] = libinput_event_pointer_get_dy(event);
1070 delta_y[1] = libinput_event_pointer_get_dy_unaccelerated(event);
1072 _device_pointer_motion_send(edev, event, &delta_x[0], &delta_y[0]);
1076 _device_handle_pointer_motion_absolute(struct libinput_device *device, struct libinput_event_pointer *event)
1078 E_Input_Evdev *edev;
1081 if (!(edev = libinput_device_get_user_data(device)))
1086 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
1088 edev->mouse.dx = edev->seat->ptr.dx =
1089 libinput_event_pointer_get_absolute_x_transformed(event, w);
1090 edev->mouse.dy = edev->seat->ptr.dy =
1091 libinput_event_pointer_get_absolute_y_transformed(event, h);
1093 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
1094 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
1099 edev->seat->ptr.ix = edev->seat->ptr.dx;
1100 edev->seat->ptr.iy = edev->seat->ptr.dy;
1102 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1103 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1108 _device_pointer_motion(edev, event);
1112 _device_handle_button(struct libinput_device *device, struct libinput_event_pointer *event)
1114 E_Input_Evdev *edev;
1115 E_Input_Backend *input;
1116 Ecore_Event_Mouse_Button *ev;
1117 enum libinput_button_state state;
1118 uint32_t button, timestamp;
1119 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1121 E_Comp_Config *comp_conf = NULL;
1123 if (!(edev = libinput_device_get_user_data(device)))
1127 if (!(input = edev->seat->input))
1132 ecore_thread_main_loop_begin();
1134 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1135 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1137 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1139 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1144 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1149 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1151 ecore_dev = detent_data;
1156 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1157 ecore_dev = edev->ecore_dev;
1162 ERR("Failed to get source ecore device from event !\n");
1166 state = libinput_event_pointer_get_button_state(event);
1167 button = libinput_event_pointer_get_button(event);
1168 timestamp = libinput_event_pointer_get_time(event);
1170 button = ((button & 0x00F) + 1);
1171 if (button == 3) button = 2;
1172 else if (button == 2) button = 3;
1176 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1177 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1179 g_mutex_lock(&edev->seat->dev->blocked_client_mutex);
1180 ELOGF("Mouse", "Button Press (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
1181 button, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
1182 edev->seat->dev->server_blocked);
1183 g_mutex_unlock(&edev->seat->dev->blocked_client_mutex);
1188 edev->mouse.pressed_button |= (1 << button);
1193 if (!(edev->mouse.pressed_button & (1 << button)))
1195 g_mutex_lock(&edev->seat->dev->blocked_client_mutex);
1196 ELOGF("Mouse", "Button Release (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
1197 button, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
1198 edev->seat->dev->server_blocked);
1199 g_mutex_unlock(&edev->seat->dev->blocked_client_mutex);
1202 edev->mouse.pressed_button &= ~(1 << button);
1205 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button))))
1210 ev->window = (Ecore_Window)input->dev->window;
1211 ev->event_window = (Ecore_Window)input->dev->window;
1212 ev->root_window = (Ecore_Window)input->dev->window;
1213 ev->timestamp = timestamp;
1214 ev->same_screen = 1;
1216 _device_modifiers_update(edev);
1217 ev->modifiers = edev->xkb.modifiers;
1219 ev->x = edev->seat->ptr.ix;
1220 ev->y = edev->seat->ptr.iy;
1224 ev->multi.device = edev->mt_slot;
1225 ev->multi.radius = 1;
1226 ev->multi.radius_x = 1;
1227 ev->multi.radius_y = 1;
1228 ev->multi.pressure = 1.0;
1229 ev->multi.angle = 0.0;
1230 ev->multi.x = ev->x;
1231 ev->multi.y = ev->y;
1232 ev->multi.root.x = ev->x;
1233 ev->multi.root.y = ev->y;
1234 ev->dev = ecore_device_ref(ecore_dev);
1238 unsigned int current;
1240 current = timestamp;
1241 edev->mouse.did_double = EINA_FALSE;
1242 edev->mouse.did_triple = EINA_FALSE;
1244 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1245 (button == edev->mouse.prev_button))
1247 edev->mouse.did_double = EINA_TRUE;
1248 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1249 (button == edev->mouse.last_button))
1251 edev->mouse.did_triple = EINA_TRUE;
1252 edev->mouse.prev = 0;
1253 edev->mouse.last = 0;
1258 edev->mouse.last = edev->mouse.prev;
1259 edev->mouse.prev = current;
1260 edev->mouse.last_button = edev->mouse.prev_button;
1261 edev->mouse.prev_button = button;
1264 ev->buttons = button;
1266 if (edev->mouse.did_double)
1267 ev->double_click = 1;
1268 if (edev->mouse.did_triple)
1269 ev->triple_click = 1;
1271 comp_conf = e_comp_config_get();
1272 if (comp_conf && comp_conf->input_log_enable)
1273 ELOGF("Mouse", "Button %s (btn: %d, device: %s)", NULL, state?"Press":"Release", button, ecore_device_name_get(ev->dev));
1276 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, _e_input_event_mouse_button_cb_free, NULL);
1278 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, _e_input_event_mouse_button_cb_free, NULL);
1281 ecore_thread_main_loop_end();
1284 #if !LIBINPUT_HAVE_SCROLL_VALUE_V120
1286 _axis_value_get(struct libinput_event_pointer *pointer_event, enum libinput_pointer_axis axis)
1288 enum libinput_pointer_axis_source source;
1289 double value = 0.0, value_discrete = 0.0;
1291 E_Comp_Config *comp_conf = NULL;
1293 comp_conf = e_comp_config_get();
1294 source = libinput_event_pointer_get_axis_source(pointer_event);
1297 case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL:
1298 value_discrete = libinput_event_pointer_get_axis_value_discrete(pointer_event, axis);
1299 value = libinput_event_pointer_get_axis_value(pointer_event, axis);
1300 if (comp_conf && comp_conf->input_log_enable)
1302 ELOGF("Axis", "SOURCE_WHEEL discrete: %lf (cf. value: %lf)", NULL, value_discrete, value);
1304 ret = (int)value_discrete;
1306 case LIBINPUT_POINTER_AXIS_SOURCE_FINGER:
1307 case LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS:
1308 value = libinput_event_pointer_get_axis_value(pointer_event, axis);
1309 if (comp_conf && comp_conf->input_log_enable)
1311 ELOGF("Axis", "SOURCE_FINGER/CONTINUOUS value: %lf", NULL, value);
1313 if (value >= E_INPUT_FINGER_SCROLL_THRESHOLD)
1315 else if (value <= E_INPUT_FINGER_SCROLL_THRESHOLD * (-1))
1328 _device_handle_axis(struct libinput_device *device, struct libinput_event_pointer *event)
1330 E_Input_Evdev *edev;
1331 E_Input_Backend *input;
1332 Ecore_Event_Mouse_Wheel *ev;
1334 enum libinput_pointer_axis axis;
1335 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1337 E_Comp_Config *comp_conf = NULL;
1338 int direction = 0, z = 0;
1340 if (!(edev = libinput_device_get_user_data(device)))
1344 if (!(input = edev->seat->input))
1349 ecore_thread_main_loop_begin();
1351 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1352 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1354 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1356 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1361 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1366 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1368 ecore_dev = detent_data;
1373 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1374 ecore_dev = edev->ecore_dev;
1379 ERR("Failed to get source ecore device from event !\n");
1383 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1384 if (libinput_event_pointer_has_axis(event, axis))
1385 z = _axis_value_get(event, axis);
1387 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1388 if (libinput_event_pointer_has_axis(event, axis))
1391 z = _axis_value_get(event, axis);
1396 ELOGF("Mouse", "Axis event is ignored since it has zero value", NULL);
1400 comp_conf = e_comp_config_get();
1401 if (comp_conf && comp_conf->e_wheel_click_angle)
1403 z = (int)(z * comp_conf->e_wheel_click_angle);
1406 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1407 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1409 g_mutex_lock(&edev->seat->dev->blocked_client_mutex);
1412 ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1413 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1415 ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1416 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1418 g_mutex_unlock(&edev->seat->dev->blocked_client_mutex);
1422 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1427 timestamp = libinput_event_pointer_get_time(event);
1429 ev->window = (Ecore_Window)input->dev->window;
1430 ev->event_window = (Ecore_Window)input->dev->window;
1431 ev->root_window = (Ecore_Window)input->dev->window;
1432 ev->timestamp = timestamp;
1433 ev->same_screen = 1;
1435 _device_modifiers_update(edev);
1436 ev->modifiers = edev->xkb.modifiers;
1438 ev->x = edev->seat->ptr.ix;
1439 ev->y = edev->seat->ptr.iy;
1443 ev->direction = direction;
1445 if (comp_conf && comp_conf->input_log_enable)
1448 ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1450 ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1454 ev->dev = ecore_device_ref(ecore_dev);
1455 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1458 ecore_thread_main_loop_end();
1462 #if LIBINPUT_HAVE_SCROLL_VALUE_V120
1464 _scroll_value_get(struct libinput_event_pointer *pointer_event, enum libinput_pointer_axis axis, E_Input_Axis_Source source)
1467 double value_v120 = 0.0;
1469 E_Comp_Config *comp_conf = NULL;
1471 comp_conf = e_comp_config_get();
1474 case E_INPUT_AXIS_SOURCE_WHEEL:
1475 value_v120 = libinput_event_pointer_get_scroll_value_v120(pointer_event, axis);
1476 value = libinput_event_pointer_get_scroll_value(pointer_event, axis);
1477 if (comp_conf && comp_conf->input_log_enable)
1479 ELOGF("Scroll", "SOURCE_WHEELL value_v120: %lf (cf. value: %lf)", NULL, value_v120, value);
1481 if (((int)value_v120 % E_INPUT_POINTER_AXIS_DISCRETE_STEP) != 0)
1483 ERR("Wheel movements should be multiples (or fractions) of 120!\n");
1488 ret = value_v120 / E_INPUT_POINTER_AXIS_DISCRETE_STEP;
1491 case E_INPUT_AXIS_SOURCE_FINGER:
1492 case E_INPUT_AXIS_SOURCE_CONTINUOUS:
1493 value = libinput_event_pointer_get_scroll_value(pointer_event, axis);
1494 if (comp_conf && comp_conf->input_log_enable)
1496 ELOGF("Scroll", "SOURCE_FINGER/CONTINUOUS value: %lf", NULL, value);
1498 if (value >= E_INPUT_FINGER_SCROLL_THRESHOLD)
1500 else if (value <= E_INPUT_FINGER_SCROLL_THRESHOLD * (-1))
1513 _device_handle_axis_v120(struct libinput_device *device, struct libinput_event_pointer *event, E_Input_Axis_Source source)
1515 E_Input_Evdev *edev;
1516 E_Input_Backend *input;
1517 Ecore_Event_Mouse_Wheel *ev;
1519 enum libinput_pointer_axis axis;
1520 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1522 E_Comp_Config *comp_conf = NULL;
1523 int direction = 0, z = 0;
1525 if (!(edev = libinput_device_get_user_data(device)))
1529 if (!(input = edev->seat->input))
1534 ecore_thread_main_loop_begin();
1536 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1537 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1539 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1541 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1546 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1551 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1553 ecore_dev = detent_data;
1558 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1559 ecore_dev = edev->ecore_dev;
1564 ERR("Failed to get source ecore device from event !\n");
1568 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1569 if (libinput_event_pointer_has_axis(event, axis))
1570 z = _scroll_value_get(event, axis, source);
1572 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1573 if (libinput_event_pointer_has_axis(event, axis))
1576 z = _scroll_value_get(event, axis, source);
1581 ELOGF("Mouse", "Scroll event is ignored since it has zero value", NULL);
1585 comp_conf = e_comp_config_get();
1586 if (comp_conf && comp_conf->e_wheel_click_angle)
1588 z = (int)(z * comp_conf->e_wheel_click_angle);
1591 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1592 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1594 g_mutex_lock(&edev->seat->dev->blocked_client_mutex);
1596 ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1597 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1599 ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1600 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1602 g_mutex_unlock(&edev->seat->dev->blocked_client_mutex);
1606 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1611 timestamp = libinput_event_pointer_get_time(event);
1613 ev->window = (Ecore_Window)input->dev->window;
1614 ev->event_window = (Ecore_Window)input->dev->window;
1615 ev->root_window = (Ecore_Window)input->dev->window;
1616 ev->timestamp = timestamp;
1617 ev->same_screen = 1;
1619 _device_modifiers_update(edev);
1620 ev->modifiers = edev->xkb.modifiers;
1622 ev->x = edev->seat->ptr.ix;
1623 ev->y = edev->seat->ptr.iy;
1627 ev->direction = direction;
1629 if (comp_conf && comp_conf->input_log_enable)
1632 ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1634 ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1637 ev->dev = ecore_device_ref(ecore_dev);
1638 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1641 ecore_thread_main_loop_end();
1646 _device_handle_touch_event_send(E_Input_Evdev *edev, struct libinput_event_touch *event, int state)
1648 E_Input_Backend *input;
1649 Ecore_Event_Mouse_Button *ev;
1650 uint32_t timestamp, button = 0;
1651 Ecore_Device *ecore_dev = NULL, *data;
1655 if (!(input = edev->seat->input)) return;
1657 ecore_thread_main_loop_begin();
1659 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1660 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1662 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1664 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1673 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1674 ecore_dev = edev->ecore_dev;
1679 ERR("Failed to get source ecore device from event !\n");
1683 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) goto end;
1685 timestamp = libinput_event_touch_get_time(event);
1687 ev->window = (Ecore_Window)input->dev->window;
1688 ev->event_window = (Ecore_Window)input->dev->window;
1689 ev->root_window = (Ecore_Window)input->dev->window;
1690 ev->timestamp = timestamp;
1691 ev->same_screen = 1;
1693 _device_modifiers_update(edev);
1694 ev->modifiers = edev->xkb.modifiers;
1696 ev->x = edev->seat->ptr.ix;
1697 ev->y = edev->seat->ptr.iy;
1701 ev->multi.device = edev->mt_slot;
1702 ev->multi.radius = 1;
1703 ev->multi.radius_x = 1;
1704 ev->multi.radius_y = 1;
1705 ev->multi.pressure = 1.0;
1706 ev->multi.angle = 0.0;
1707 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1708 if (libinput_event_get_type(libinput_event_touch_get_base_event(event))
1709 == LIBINPUT_EVENT_TOUCH_DOWN)
1711 if (libinput_event_touch_has_minor(event))
1712 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1713 if (libinput_event_touch_has_major(event))
1714 ev->multi.radius_y = libinput_event_touch_get_major(event);
1715 if (libinput_event_touch_has_pressure(event))
1716 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1717 if (libinput_event_touch_has_orientation(event))
1718 ev->multi.angle = libinput_event_touch_get_orientation(event);
1721 ev->multi.x = ev->x;
1722 ev->multi.y = ev->y;
1723 ev->multi.root.x = ev->x;
1724 ev->multi.root.y = ev->y;
1725 ev->dev = ecore_device_ref(ecore_dev);
1727 if (state == ECORE_EVENT_MOUSE_BUTTON_DOWN)
1729 unsigned int current;
1731 current = timestamp;
1732 edev->mouse.did_double = EINA_FALSE;
1733 edev->mouse.did_triple = EINA_FALSE;
1735 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1736 (button == edev->mouse.prev_button))
1738 edev->mouse.did_double = EINA_TRUE;
1739 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1740 (button == edev->mouse.last_button))
1742 edev->mouse.did_triple = EINA_TRUE;
1743 edev->mouse.prev = 0;
1744 edev->mouse.last = 0;
1749 edev->mouse.last = edev->mouse.prev;
1750 edev->mouse.prev = current;
1751 edev->mouse.last_button = edev->mouse.prev_button;
1752 edev->mouse.prev_button = button;
1753 edev->touch.pressed |= (1 << ev->multi.device);
1757 edev->touch.pressed &= ~(1 << ev->multi.device);
1760 ev->buttons = ((button & 0x00F) + 1);
1762 if (edev->mouse.did_double)
1763 ev->double_click = 1;
1764 if (edev->mouse.did_triple)
1765 ev->triple_click = 1;
1767 ecore_event_add(state, ev, _e_input_event_mouse_button_cb_free, NULL);
1770 ecore_thread_main_loop_end();
1774 _device_handle_touch_motion_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1776 E_Input_Backend *input;
1777 Ecore_Event_Mouse_Move *ev;
1778 Ecore_Device *ecore_dev = NULL, *data;
1782 if (!(input = edev->seat->input)) return;
1784 ecore_thread_main_loop_begin();
1786 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1787 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1789 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1791 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1800 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1801 ecore_dev = edev->ecore_dev;
1806 ERR("Failed to get source ecore device from event !\n");
1810 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) goto end;
1812 ev->window = (Ecore_Window)input->dev->window;
1813 ev->event_window = (Ecore_Window)input->dev->window;
1814 ev->root_window = (Ecore_Window)input->dev->window;
1815 ev->timestamp = libinput_event_touch_get_time(event);
1816 ev->same_screen = 1;
1818 _device_modifiers_update(edev);
1819 ev->modifiers = edev->xkb.modifiers;
1821 ev->x = edev->seat->ptr.ix;
1822 ev->y = edev->seat->ptr.iy;
1826 ev->multi.device = edev->mt_slot;
1827 ev->multi.radius = 1;
1828 ev->multi.radius_x = 1;
1829 ev->multi.radius_y = 1;
1830 ev->multi.pressure = 1.0;
1831 ev->multi.angle = 0.0;
1832 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1833 if (libinput_event_touch_has_minor(event))
1834 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1835 if (libinput_event_touch_has_major(event))
1836 ev->multi.radius_y = libinput_event_touch_get_major(event);
1837 if (libinput_event_touch_has_pressure(event))
1838 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1839 if (libinput_event_touch_has_orientation(event))
1840 ev->multi.angle = libinput_event_touch_get_orientation(event);
1842 ev->multi.x = ev->x;
1843 ev->multi.y = ev->y;
1844 ev->multi.root.x = ev->x;
1845 ev->multi.root.y = ev->y;
1846 ev->dev = ecore_device_ref(ecore_dev);
1848 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
1851 ecore_thread_main_loop_end();
1855 _device_handle_touch_cancel_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1857 E_Input_Backend *input;
1858 Ecore_Event_Mouse_Button *ev;
1859 uint32_t timestamp, button = 0;
1860 Ecore_Device *ecore_dev = NULL, *data;
1864 if (!(input = edev->seat->input)) return;
1866 ecore_thread_main_loop_begin();
1868 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1869 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1871 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1873 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1882 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1883 ecore_dev = edev->ecore_dev;
1888 ERR("Failed to get source ecore device from event !\n");
1892 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) goto end;
1894 timestamp = libinput_event_touch_get_time(event);
1896 ev->window = (Ecore_Window)input->dev->window;
1897 ev->event_window = (Ecore_Window)input->dev->window;
1898 ev->root_window = (Ecore_Window)input->dev->window;
1899 ev->timestamp = timestamp;
1900 ev->same_screen = 1;
1902 ev->x = edev->seat->ptr.ix;
1903 ev->y = edev->seat->ptr.iy;
1907 ev->multi.device = edev->mt_slot;
1908 ev->multi.radius = 1;
1909 ev->multi.radius_x = 1;
1910 ev->multi.radius_y = 1;
1911 ev->multi.pressure = 1.0;
1912 ev->multi.angle = 0.0;
1913 ev->multi.x = ev->x;
1914 ev->multi.y = ev->y;
1915 ev->multi.root.x = ev->x;
1916 ev->multi.root.y = ev->y;
1918 edev->touch.pressed &= ~(1 << ev->multi.device);
1920 ev->buttons = ((button & 0x00F) + 1);
1921 ev->dev = ecore_device_ref(ecore_dev);
1923 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev, _e_input_event_mouse_button_cb_free, NULL);
1926 ecore_thread_main_loop_end();
1930 _device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, int *w, int *h)
1932 E_Output *output = NULL;
1934 EINA_SAFETY_ON_NULL_RETURN(edev);
1936 if (!edev->output_configured)
1938 if (edev->output_name)
1940 output = e_output_find(edev->output_name);
1943 edev->mouse.minx = output->config.geom.x;
1944 edev->mouse.miny = output->config.geom.y;
1945 edev->mouse.maxw = output->config.geom.w;
1946 edev->mouse.maxh = output->config.geom.h;
1947 if (libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
1949 edev->seat->ptr.dx = (double)(edev->mouse.maxw / 2);
1950 edev->seat->ptr.dy = (double)(edev->mouse.maxh / 2);
1951 edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
1952 edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
1953 edev->mouse.dx = edev->seat->ptr.dx;
1954 edev->mouse.dy = edev->seat->ptr.dy;
1959 edev->output_configured = EINA_TRUE;
1960 ELOGF("E_INPUT_EVDEV", "Device is configured by output x:%d,y:%d (w:%d, h:%d)",
1961 NULL, edev->mouse.minx, edev->mouse.miny, edev->mouse.maxw, edev->mouse.maxh);
1963 if (x) *x = edev->mouse.minx;
1964 if (y) *y = edev->mouse.miny;
1965 if (w) *w = edev->mouse.maxw;
1966 if (h) *h = edev->mouse.maxh;
1970 _device_handle_touch_down(struct libinput_device *device, struct libinput_event_touch *event)
1972 E_Input_Evdev *edev;
1973 int x = 0, y = 0, w = 0, h = 0;
1974 E_Comp_Config *comp_conf = NULL;
1976 if (!(edev = libinput_device_get_user_data(device)))
1981 _device_configured_size_get(edev, &x, &y, &w, &h);
1983 edev->mouse.dx = edev->seat->ptr.ix = edev->seat->ptr.dx =
1984 x + libinput_event_touch_get_x_transformed(event, w);
1985 edev->mouse.dy = edev->seat->ptr.iy = edev->seat->ptr.dy =
1986 y + libinput_event_touch_get_y_transformed(event, h);
1988 edev->mt_slot = libinput_event_touch_get_slot(event);
1989 if (edev->mt_slot < 0)
1991 /* FIXME: The single touch device return slot id -1
1992 * But currently we have no API to distinguish multi touch or single touch
1993 * After libinput 1.11 version, libinput provides get_touch_count API,
1994 * so we can distinguish multi touch device or single touch device.
1996 if (edev->mt_slot == -1)
2000 WRN("%d slot touch down events are not supported\n", edev->mt_slot);
2005 if (edev->mt_slot < e_input_touch_max_count_get())
2007 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
2008 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
2011 comp_conf = e_comp_config_get();
2012 if (comp_conf && comp_conf->input_log_enable)
2013 ELOGF("Touch", "Down (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2015 g_mutex_lock(&edev->touch.raw_pressed_mutex);
2016 edev->touch.raw_pressed |= (1 << edev->mt_slot);
2017 g_mutex_unlock(&edev->touch.raw_pressed_mutex);
2019 g_mutex_lock(&edev->touch.blocked_mutex);
2020 if (edev->touch.blocked)
2022 g_mutex_lock(&edev->seat->dev->blocked_client_mutex);
2023 ELOGF("Touch", "Down (id: %d, x: %d, y: %d) is blocked by %p, server: 0x%x", NULL,
2024 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, edev->seat->dev->blocked_client,
2025 edev->seat->dev->server_blocked);
2026 g_mutex_unlock(&edev->seat->dev->blocked_client_mutex);
2027 g_mutex_unlock(&edev->touch.blocked_mutex);
2031 g_mutex_unlock(&edev->touch.blocked_mutex);
2033 _device_handle_touch_motion_send(edev, event);
2034 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_DOWN);
2038 _device_handle_touch_motion(struct libinput_device *device, struct libinput_event_touch *event)
2040 E_Input_Evdev *edev;
2041 int x = 0, y = 0, w = 0, h = 0;
2043 if (!(edev = libinput_device_get_user_data(device)))
2048 _device_configured_size_get(edev, &x, &y, &w, &h);
2050 edev->mouse.dx = edev->seat->ptr.dx =
2051 x + libinput_event_touch_get_x_transformed(event, w);
2052 edev->mouse.dy = edev->seat->ptr.dy =
2053 y + libinput_event_touch_get_y_transformed(event, h);
2055 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
2056 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
2061 edev->seat->ptr.ix = edev->seat->ptr.dx;
2062 edev->seat->ptr.iy = edev->seat->ptr.dy;
2064 edev->mt_slot = libinput_event_touch_get_slot(event);
2065 if (edev->mt_slot < 0)
2067 /* FIXME: The single touch device return slot id -1
2068 * But currently we have no API to distinguish multi touch or single touch
2069 * After libinput 1.11 version, libinput provides get_touch_count API,
2070 * so we can distinguish multi touch device or single touch device.
2072 if (edev->mt_slot == -1)
2076 WRN("%d slot touch motion events are not supported\n", edev->mt_slot);
2081 if (edev->mt_slot < e_input_touch_max_count_get())
2083 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
2084 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
2087 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
2089 g_mutex_lock(&edev->touch.blocked_mutex);
2090 if (edev->touch.blocked)
2092 g_mutex_unlock(&edev->touch.blocked_mutex);
2095 g_mutex_unlock(&edev->touch.blocked_mutex);
2098 _device_handle_touch_motion_send(edev, event);
2102 _device_handle_touch_up(struct libinput_device *device, struct libinput_event_touch *event)
2104 E_Input_Evdev *edev;
2105 E_Comp_Config *comp_conf = NULL;
2107 if (!(edev = libinput_device_get_user_data(device)))
2112 edev->mt_slot = libinput_event_touch_get_slot(event);
2113 if (edev->mt_slot < 0)
2115 /* FIXME: The single touch device return slot id -1
2116 * But currently we have no API to distinguish multi touch or single touch
2117 * After libinput 1.11 version, libinput provides get_touch_count API,
2118 * so we can distinguish multi touch device or single touch device.
2120 if (edev->mt_slot == -1)
2124 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
2129 if (edev->mt_slot < e_input_touch_max_count_get())
2131 edev->mouse.dx = edev->seat->ptr.dx = edev->seat->ptr.ix =
2132 edev->touch.coords[edev->mt_slot].x;
2133 edev->mouse.dy = edev->seat->ptr.dy = edev->seat->ptr.iy =
2134 edev->touch.coords[edev->mt_slot].y;
2137 comp_conf = e_comp_config_get();
2138 if (comp_conf && comp_conf->input_log_enable)
2139 ELOGF("Touch", "Up (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2141 g_mutex_lock(&edev->touch.raw_pressed_mutex);
2142 edev->touch.raw_pressed &= ~(1 << edev->mt_slot);
2143 g_mutex_unlock(&edev->touch.raw_pressed_mutex);
2145 g_mutex_lock(&edev->touch.blocked_mutex);
2146 if (edev->touch.blocked)
2148 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
2150 g_mutex_lock(&edev->seat->dev->blocked_client_mutex);
2151 ELOGF("Touch", "Up (id: %d, x: %d, y: %d) is blocked by %p, server(0x%x)", NULL,
2152 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, edev->seat->dev->blocked_client,
2153 edev->seat->dev->server_blocked);
2154 g_mutex_unlock(&edev->seat->dev->blocked_client_mutex);
2156 g_mutex_lock(&edev->touch.raw_pressed_mutex);
2157 if (edev->touch.raw_pressed == 0x0)
2159 edev->touch.blocked = EINA_FALSE;
2161 g_mutex_unlock(&edev->touch.raw_pressed_mutex);
2162 g_mutex_unlock(&edev->touch.blocked_mutex);
2167 g_mutex_unlock(&edev->touch.blocked_mutex);
2168 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_UP);
2172 _device_handle_touch_cancel(struct libinput_device *device, struct libinput_event_touch *event)
2174 E_Input_Evdev *edev;
2175 E_Comp_Config *comp_conf = NULL;
2177 if (!(edev = libinput_device_get_user_data(device)))
2182 edev->mt_slot = libinput_event_touch_get_slot(event);
2183 if (edev->mt_slot < 0)
2185 /* FIXME: The single touch device return slot id -1
2186 * But currently we have no API to distinguish multi touch or single touch
2187 * After libinput 1.11 version, libinput provides get_touch_count API,
2188 * so we can distinguish multi touch device or single touch device.
2190 if (edev->mt_slot == -1)
2194 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
2199 comp_conf = e_comp_config_get();
2200 if (comp_conf && comp_conf->input_log_enable)
2201 ELOGF("Touch", "cancel (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2203 _device_handle_touch_cancel_send(edev, event);
2208 _device_handle_touch_frame(struct libinput_device *device EINA_UNUSED, struct libinput_event_touch *event EINA_UNUSED)
2210 /* DBG("Unhandled Touch Frame Event"); */
2214 _e_input_aux_data_event_free(void *user_data EINA_UNUSED, void *ev)
2216 Ecore_Event_Axis_Update *e = (Ecore_Event_Axis_Update *)ev;
2218 if (e->axis) free(e->axis);
2219 if (e->dev) ecore_device_unref(e->dev);
2225 _device_handle_touch_aux_data(struct libinput_device *device, struct libinput_event_touch_aux_data *event)
2227 E_Input_Evdev *edev;
2228 E_Input_Backend *input;
2229 Ecore_Event_Axis_Update *ev;
2231 Ecore_Device *ecore_dev = NULL, *data;
2233 E_Comp_Config *comp_conf;
2235 ecore_thread_main_loop_begin();
2237 if (libinput_event_touch_aux_data_get_type(event) != LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM &&
2238 libinput_event_touch_aux_data_get_value(event) > 0)
2241 if (!(edev = libinput_device_get_user_data(device))) goto end;
2242 if (!(input = edev->seat->input)) goto end;
2244 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
2245 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
2247 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
2249 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
2258 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
2259 ecore_dev = edev->ecore_dev;
2264 ERR("Failed to get source ecore device from event !\n");
2268 if (!(ev = calloc(1, sizeof(Ecore_Event_Axis_Update)))) goto end;
2270 ev->window = (Ecore_Window)input->dev->window;
2271 ev->event_window = (Ecore_Window)input->dev->window;
2272 ev->root_window = (Ecore_Window)input->dev->window;
2273 ev->timestamp = libinput_event_touch_aux_data_get_time(event);
2275 axis = (Ecore_Axis *)calloc(1, sizeof(Ecore_Axis));
2278 axis->label = ECORE_AXIS_LABEL_TOUCH_PALM;
2279 axis->value = libinput_event_touch_aux_data_get_value(event);
2284 comp_conf = e_comp_config_get();
2285 if (comp_conf && comp_conf->input_log_enable)
2286 ELOGF("Touch", "Axis (label: %d, value: %lf)", NULL, axis?axis->label:-1, axis?axis->value:0.0);
2288 ev->dev = ecore_device_ref(ecore_dev);
2290 ecore_event_add(ECORE_EVENT_AXIS_UPDATE, ev, _e_input_aux_data_event_free, NULL);
2293 ecore_thread_main_loop_end();
2297 _e_input_evdev_device_create(E_Input_Seat *seat, struct libinput_device *device)
2299 E_Input_Evdev *edev;
2300 E_Input_Backend *b_input;
2301 const char *output_name;
2303 EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
2305 /* try to allocate space for new evdev */
2306 if (!(edev = calloc(1, sizeof(E_Input_Evdev)))) return NULL;
2309 edev->device = device;
2310 edev->path = eina_stringshare_printf("%s/%s", e_input_base_dir_get(), libinput_device_get_sysname(device));
2312 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
2314 edev->caps |= E_INPUT_SEAT_KEYBOARD;
2315 _device_keyboard_setup(edev);
2318 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
2320 edev->caps |= E_INPUT_SEAT_POINTER;
2322 /* TODO: make this configurable */
2323 edev->mouse.threshold = 250;
2325 b_input = seat->input;
2326 if (b_input->left_handed == EINA_TRUE)
2328 if (libinput_device_config_left_handed_set(device, 1) !=
2329 LIBINPUT_CONFIG_STATUS_SUCCESS)
2331 WRN("Failed to set left hand mode about device: %s\n",
2332 libinput_device_get_name(device));
2337 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
2340 edev->caps |= E_INPUT_SEAT_TOUCH;
2341 palm_code = libinput_device_touch_aux_data_get_code(LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM);
2342 if (libinput_device_touch_has_aux_data(device, palm_code))
2344 libinput_device_touch_set_aux_data(device, palm_code);
2347 _device_touch_count_update(edev);
2349 g_mutex_init(&edev->touch.raw_pressed_mutex);
2350 g_mutex_init(&edev->touch.blocked_mutex);
2351 edev->touch.coords = calloc(1, sizeof(E_Input_Coord)*e_input_touch_max_count_get());
2353 if (!edev->touch.coords)
2354 ERR("Failed to allocate memory for touch coords !\n");
2357 output_name = libinput_device_get_output_name(device);
2360 eina_stringshare_replace(&edev->output_name, output_name);
2361 ELOGF("E_INPUT_EVDEV", "Device has output_name:%s", NULL, output_name);
2364 libinput_device_set_user_data(device, edev);
2365 libinput_device_ref(device);
2367 /* configure device */
2368 _device_configure(edev);
2374 _e_input_evdev_device_destroy(E_Input_Evdev *edev)
2378 EINA_SAFETY_ON_NULL_RETURN(edev);
2380 ecore_thread_main_loop_begin();
2382 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
2384 g_mutex_lock(&edev->xkb.state_mutex);
2385 if (edev->xkb.state) xkb_state_unref(edev->xkb.state);
2386 g_mutex_unlock(&edev->xkb.state_mutex);
2388 g_mutex_lock(&edev->xkb.keymap_mutex);
2389 if (edev->xkb.keymap) xkb_map_unref(edev->xkb.keymap);
2390 g_mutex_unlock(&edev->xkb.keymap_mutex);
2393 if (edev->ecore_dev) ecore_device_del(edev->ecore_dev);
2394 if (edev->ecore_dev_list)
2395 EINA_LIST_FREE(edev->ecore_dev_list, dev)
2397 ecore_device_del(dev);
2400 if (edev->e_dev) g_object_unref(edev->e_dev);
2401 if (edev->e_dev_list)
2403 GList *glist = edev->e_dev_list;
2407 e_dev = glist->data;
2408 g_object_unref(e_dev);
2410 glist = g_list_next(glist);
2413 if (edev->path) eina_stringshare_del(edev->path);
2414 if (edev->device) libinput_device_unref(edev->device);
2415 if (edev->key_remap_hash) eina_hash_free(edev->key_remap_hash);
2416 if (edev->touch.coords)
2418 free(edev->touch.coords);
2419 edev->touch.coords = NULL;
2421 g_mutex_clear(&edev->touch.raw_pressed_mutex);
2422 g_mutex_clear(&edev->touch.blocked_mutex);
2423 eina_stringshare_del(edev->output_name);
2425 ecore_thread_main_loop_end();
2431 _e_input_evdev_event_process(struct libinput_event *event)
2433 struct libinput_device *device;
2434 Eina_Bool ret = EINA_TRUE;
2436 device = libinput_event_get_device(event);
2437 switch (libinput_event_get_type(event))
2439 case LIBINPUT_EVENT_KEYBOARD_KEY:
2440 _device_handle_key(device, libinput_event_get_keyboard_event(event));
2442 case LIBINPUT_EVENT_POINTER_MOTION:
2443 _device_handle_pointer_motion(device,
2444 libinput_event_get_pointer_event(event));
2446 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
2447 _device_handle_pointer_motion_absolute(device,
2448 libinput_event_get_pointer_event(event));
2450 case LIBINPUT_EVENT_POINTER_BUTTON:
2451 _device_handle_button(device, libinput_event_get_pointer_event(event));
2453 case LIBINPUT_EVENT_POINTER_AXIS:
2454 #if !LIBINPUT_HAVE_SCROLL_VALUE_V120
2455 _device_handle_axis(device, libinput_event_get_pointer_event(event));
2458 #if LIBINPUT_HAVE_SCROLL_VALUE_V120
2459 case LIBINPUT_EVENT_POINTER_SCROLL_WHEEL:
2460 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_WHEEL);
2462 case LIBINPUT_EVENT_POINTER_SCROLL_FINGER:
2463 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_FINGER);
2465 case LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS:
2466 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_CONTINUOUS);
2469 case LIBINPUT_EVENT_TOUCH_DOWN:
2470 _device_handle_touch_down(device, libinput_event_get_touch_event(event));
2472 case LIBINPUT_EVENT_TOUCH_MOTION:
2473 _device_handle_touch_motion(device,
2474 libinput_event_get_touch_event(event));
2476 case LIBINPUT_EVENT_TOUCH_UP:
2477 _device_handle_touch_up(device, libinput_event_get_touch_event(event));
2479 case LIBINPUT_EVENT_TOUCH_CANCEL:
2480 _device_handle_touch_cancel(device, libinput_event_get_touch_event(event));
2482 case LIBINPUT_EVENT_TOUCH_FRAME:
2483 _device_handle_touch_frame(device, libinput_event_get_touch_event(event));
2485 case LIBINPUT_EVENT_TOUCH_AUX_DATA:
2486 _device_handle_touch_aux_data(device, libinput_event_get_touch_aux_data(event));
2497 * @brief Set the axis size of the given device.
2499 * @param dev The device to set the axis size to.
2500 * @param w The width of the axis.
2501 * @param h The height of the axis.
2503 * This function sets set the width @p w and height @p h of the axis
2504 * of device @p dev. If @p dev is a relative input device, a width and
2505 * height must set for it. If its absolute set the ioctl correctly, if
2506 * not, unsupported device.
2509 e_input_evdev_axis_size_set(E_Input_Evdev *edev, int w, int h)
2511 const char *sysname;
2516 enum libinput_config_status status;
2518 EINA_SAFETY_ON_NULL_RETURN(edev);
2519 EINA_SAFETY_ON_TRUE_RETURN((w == 0) || (h == 0));
2521 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
2522 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
2525 sysname = libinput_device_get_sysname(edev->device);
2527 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
2528 if (eina_list_count(devices) < 1) return;
2530 EINA_LIST_FREE(devices, device)
2532 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
2534 (sscanf(vals, "%f %f %f %f %f %f",
2535 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
2542 libinput_device_config_calibration_set_matrix(edev->device, cal);
2544 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
2545 ERR("Failed to apply calibration");
2548 eina_stringshare_del(device);
2553 EINTERN const char *
2554 e_input_evdev_name_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_name(evdev->device);
2562 EINTERN const char *
2563 e_input_evdev_sysname_get(E_Input_Evdev *evdev)
2565 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2566 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2568 return libinput_device_get_sysname(evdev->device);
2572 e_input_evdev_key_remap_enable(E_Input_Evdev *edev, Eina_Bool enable)
2574 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2575 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2577 edev->key_remap_enabled = enable;
2579 if (enable == EINA_FALSE && edev->key_remap_hash)
2581 eina_hash_free(edev->key_remap_hash);
2582 edev->key_remap_hash = NULL;
2589 e_input_evdev_key_remap_set(E_Input_Evdev *edev, int *from_keys, int *to_keys, int num)
2593 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2594 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2595 EINA_SAFETY_ON_NULL_RETURN_VAL(from_keys, EINA_FALSE);
2596 EINA_SAFETY_ON_NULL_RETURN_VAL(to_keys, EINA_FALSE);
2597 EINA_SAFETY_ON_TRUE_RETURN_VAL(num <= 0, EINA_FALSE);
2598 EINA_SAFETY_ON_TRUE_RETURN_VAL(!edev->key_remap_enabled, EINA_FALSE);
2600 if (edev->key_remap_hash == NULL)
2601 edev->key_remap_hash = eina_hash_int32_new(NULL);
2603 if (edev->key_remap_hash == NULL)
2605 ERR("Failed to set remap key information : creating a hash is failed.");
2609 for (i = 0; i < num ; i++)
2611 if (!from_keys[i] || !to_keys[i])
2613 ERR("Failed to set remap key information : given arguments are invalid.");
2618 for (i = 0; i < num ; i++)
2620 eina_hash_add(edev->key_remap_hash, &from_keys[i], (void *)(intptr_t)to_keys[i]);
2627 e_input_evdev_wheel_click_angle_get(E_Input_Evdev *dev)
2629 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, -1);
2630 return libinput_device_config_scroll_get_wheel_click_angle(dev->device);
2634 e_input_evdev_touch_calibration_set(E_Input_Evdev *edev, float matrix[6])
2636 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2637 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2639 if (!libinput_device_config_calibration_has_matrix(edev->device) ||
2640 !libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_TOUCH))
2643 if (libinput_device_config_calibration_set_matrix(edev->device, matrix) !=
2644 LIBINPUT_CONFIG_STATUS_SUCCESS)
2646 WRN("Failed to set input transformation about device: %s\n",
2647 libinput_device_get_name(edev->device));
2655 e_input_evdev_mouse_accel_speed_set(E_Input_Evdev *edev, double speed)
2657 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2658 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2660 if (!libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
2663 if (!libinput_device_config_accel_is_available(edev->device))
2666 if (libinput_device_config_accel_set_speed(edev->device, speed) !=
2667 LIBINPUT_CONFIG_STATUS_SUCCESS)
2669 WRN("Failed to set mouse accel about device: %s\n",
2670 libinput_device_get_name(edev->device));
2677 EINTERN unsigned int
2678 e_input_evdev_touch_pressed_get(E_Input_Evdev *edev)
2680 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, 0x0);
2682 return edev->touch.pressed;
2686 e_input_evdev_seatname_get(E_Input_Evdev *evdev)
2688 struct libinput_seat *libinput_seat;
2689 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2690 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2692 libinput_seat = libinput_device_get_seat(evdev->device);
2694 return libinput_seat_get_logical_name(libinput_seat);
2698 e_input_evdev_seatname_set(E_Input_Evdev *evdev, const char *seatname)
2700 Eina_Bool res = EINA_FALSE;
2701 E_Input_Backend *input;
2703 EINA_SAFETY_ON_NULL_RETURN_VAL(seatname, EINA_FALSE);
2704 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, EINA_FALSE);
2705 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, EINA_FALSE);
2707 if (libinput_device_set_seat_logical_name(evdev->device, seatname) == 0)
2709 input = evdev->seat->input;
2710 if (!input) return EINA_FALSE;
2711 if (libinput_dispatch(input->libinput) != 0)
2713 ERR("Failed to dispatch libinput events: %m");
2717 /* process pending events */
2718 _input_events_process(input);