1 #include "e_input_intern.h"
2 #include "e_input_log.h"
3 #include "e_input_event.h"
4 #include "e_keyrouter_intern.h"
5 #include "e_devicemgr_intern.h"
6 #include "e_device_intern.h"
7 #include "e_comp_screen_intern.h"
8 #include "e_output_intern.h"
13 #define G_LIST_GET_DATA(list) ((list) ? (((GList *)(list))->data) : NULL)
15 static void _device_modifiers_update(E_Input_Evdev *edev);
16 static void _device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, int *w, int *h);
17 static void _device_output_assign(E_Input_Evdev *edev, E_Input_Seat_Capabilities cap);
20 _device_calibration_set(E_Input_Evdev *edev)
25 E_Comp_Config *comp_conf;
27 if (e_comp->e_comp_screen->num_outputs > 1) //multiple outputs
29 comp_conf = e_comp_config_get();
30 if (comp_conf && (comp_conf->input_output_assign_policy == 1)) //use output-assignment policy
32 _device_output_assign(edev, E_INPUT_SEAT_POINTER);
33 _device_output_assign(edev, E_INPUT_SEAT_TOUCH);
37 output = e_comp_screen_primary_output_get(e_comp->e_comp_screen);
38 e_output_size_get(output, &w, &h);
42 edev->mouse.minx = edev->mouse.miny = 0;
46 if (edev->caps & E_INPUT_SEAT_POINTER)
48 edev->seat->ptr.dx = (double)(w / 2);
49 edev->seat->ptr.dy = (double)(h / 2);
50 edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
51 edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
52 edev->mouse.dx = edev->seat->ptr.dx;
53 edev->mouse.dy = edev->seat->ptr.dy;
55 if (output->config.rotation == 90 || output->config.rotation == 270)
57 temp = edev->mouse.minx;
58 edev->mouse.minx = edev->mouse.miny;
59 edev->mouse.miny = temp;
61 temp = edev->mouse.maxw;
62 edev->mouse.maxw = edev->mouse.maxh;
63 edev->mouse.maxh = temp;
69 #ifdef _F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
72 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
73 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
76 #ifdef _F_E_INPUT_USE_WL_CALIBRATION_
78 enum libinput_config_status status;
79 struct udev_device *udev_device = NULL;
81 udev_device = libinput_device_get_udev_device(edev->device);
84 ERR("no udev_device");
88 vals = udev_device_get_property_value(udev_device, "WL_CALIBRATION");
90 (sscanf(vals, "%f %f %f %f %f %f",
91 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
93 udev_device_unref(udev_device);
96 udev_device_unref(udev_device);
98 ELOGF("E_INPUT_EVDEV", "calibration_set cal[%lf %lf %lf %lf %lf %lf] (%d x %d)",
99 NULL, cal[0], cal[1], cal[2], cal[3], cal[4], cal[5], w, h);
104 libinput_device_config_calibration_set_matrix(edev->device, cal);
106 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
107 ERR("Failed to apply calibration");
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 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch max count is %d.\n", NULL, ei->touch_max_count);
195 _device_configure(E_Input_Evdev *edev)
197 if (libinput_device_config_tap_get_finger_count(edev->device) > 0)
199 Eina_Bool tap = EINA_FALSE;
201 tap = libinput_device_config_tap_get_default_enabled(edev->device);
202 libinput_device_config_tap_set_enabled(edev->device, tap);
205 _device_calibration_set(edev);
209 _device_keyboard_setup(E_Input_Evdev *edev)
211 E_Input_Backend *input;
212 xkb_mod_index_t xkb_idx;
214 if ((!edev) || (!edev->seat)) return;
215 if (!(input = edev->seat->input)) return;
216 if (!input->dev->xkb_ctx) return;
218 /* create keymap from xkb context */
219 edev->xkb.keymap = _e_input_device_cached_keymap_get(input->dev->xkb_ctx, NULL, 0);
220 if (!edev->xkb.keymap)
222 ERR("Failed to create keymap: %m");
226 /* create xkb state */
227 if (!(edev->xkb.state = xkb_state_new(edev->xkb.keymap)))
229 ERR("Failed to create xkb state: %m");
233 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CTRL);
234 if (xkb_idx != XKB_MOD_INVALID)
235 edev->xkb.ctrl_mask = 1 << xkb_idx;
237 edev->xkb.ctrl_mask = 0;
239 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_ALT);
240 if (xkb_idx != XKB_MOD_INVALID)
241 edev->xkb.alt_mask = 1 << xkb_idx;
243 edev->xkb.alt_mask = 0;
245 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_SHIFT);
246 if (xkb_idx != XKB_MOD_INVALID)
247 edev->xkb.shift_mask = 1 << xkb_idx;
249 edev->xkb.shift_mask = 0;
251 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_LOGO);
252 if (xkb_idx != XKB_MOD_INVALID)
253 edev->xkb.win_mask = 1 << xkb_idx;
255 edev->xkb.win_mask = 0;
257 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_SCROLL);
258 if (xkb_idx != XKB_MOD_INVALID)
259 edev->xkb.scroll_mask = 1 << xkb_idx;
261 edev->xkb.scroll_mask = 0;
263 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_NUM);
264 if (xkb_idx != XKB_MOD_INVALID)
265 edev->xkb.num_mask = 1 << xkb_idx;
267 edev->xkb.num_mask = 0;
269 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CAPS);
270 if (xkb_idx != XKB_MOD_INVALID)
271 edev->xkb.caps_mask = 1 << xkb_idx;
273 edev->xkb.caps_mask = 0;
275 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, "ISO_Level3_Shift");
276 if (xkb_idx != XKB_MOD_INVALID)
277 edev->xkb.altgr_mask = 1 << xkb_idx;
279 edev->xkb.altgr_mask = 0;
283 _device_keysym_translate(xkb_keysym_t keysym, unsigned int modifiers, char *buffer, int bytes)
285 unsigned long hbytes = 0;
288 if (!keysym) return 0;
289 hbytes = (keysym >> 8);
294 (((keysym >= XKB_KEY_BackSpace) && (keysym <= XKB_KEY_Clear)) ||
295 (keysym == XKB_KEY_Return) || (keysym == XKB_KEY_Escape) ||
296 (keysym == XKB_KEY_KP_Space) || (keysym == XKB_KEY_KP_Tab) ||
297 (keysym == XKB_KEY_KP_Enter) ||
298 ((keysym >= XKB_KEY_KP_Multiply) && (keysym <= XKB_KEY_KP_9)) ||
299 (keysym == XKB_KEY_KP_Equal) || (keysym == XKB_KEY_Delete))))))
302 if (keysym == XKB_KEY_KP_Space)
303 c = (XKB_KEY_space & 0x7F);
304 else if (hbytes == 0xFF)
309 if (modifiers & ECORE_EVENT_MODIFIER_CTRL)
311 if (((c >= '@') && (c < '\177')) || c == ' ')
315 else if ((c >= '3') && (c <= '7'))
327 _device_modifiers_update_device(E_Input_Evdev *edev, E_Input_Evdev *from)
331 edev->xkb.depressed =
332 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_DEPRESSED);
334 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LATCHED);
336 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LOCKED);
338 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_EFFECTIVE);
340 mask = (edev->xkb.depressed | edev->xkb.latched);
342 if (mask & from->xkb.ctrl_mask)
343 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_CTRL;
344 if (mask & from->xkb.alt_mask)
345 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALT;
346 if (mask & from->xkb.shift_mask)
347 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
348 if (mask & from->xkb.win_mask)
349 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_WIN;
350 if (mask & from->xkb.scroll_mask)
351 edev->xkb.modifiers |= ECORE_EVENT_LOCK_SCROLL;
352 if (mask & from->xkb.num_mask)
353 edev->xkb.modifiers |= ECORE_EVENT_LOCK_NUM;
354 if (mask & from->xkb.caps_mask)
355 edev->xkb.modifiers |= ECORE_EVENT_LOCK_CAPS;
356 if (mask & from->xkb.altgr_mask)
357 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALTGR;
361 _device_modifiers_update(E_Input_Evdev *edev)
366 edev->xkb.modifiers = 0;
368 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
369 _device_modifiers_update_device(edev, edev);
372 EINA_LIST_FOREACH(edev->seat->devices, l, ed)
374 if (!(ed->caps & E_INPUT_SEAT_KEYBOARD)) continue;
375 _device_modifiers_update_device(edev, ed);
382 _device_remapped_key_get(E_Input_Evdev *edev, int code)
386 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, code);
387 if (!edev->key_remap_enabled) return code;
388 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->key_remap_hash, code);
390 ret = eina_hash_find(edev->key_remap_hash, &code);
392 if (ret) code = (int)(intptr_t)ret;
398 e_input_evdev_get_e_device(const char *path, Ecore_Device_Class clas)
400 const GList *dev_list = NULL;
402 E_Device *dev = NULL;
403 const char *identifier;
405 if (!path) return NULL;
407 dev_list = e_device_list_get();
408 if (!dev_list) return NULL;
415 identifier = e_device_identifier_get(dev);
416 if (!identifier) continue;
417 if ((e_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
426 EINTERN Ecore_Device *
427 e_input_evdev_get_ecore_device(const char *path, Ecore_Device_Class clas)
429 const Eina_List *dev_list = NULL;
431 Ecore_Device *dev = NULL;
432 const char *identifier;
434 if (!path) return NULL;
436 dev_list = ecore_device_list();
437 if (!dev_list) return NULL;
438 EINA_LIST_FOREACH(dev_list, l, dev)
441 identifier = ecore_device_identifier_get(dev);
442 if (!identifier) continue;
443 if ((ecore_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
450 _e_input_event_mouse_move_cb_free(void *data EINA_UNUSED, void *event)
452 Ecore_Event_Mouse_Move *ev = event;
454 if (ev->dev) ecore_device_unref(ev->dev);
460 _e_input_event_mouse_relative_move_cb_free(void *data EINA_UNUSED, void *event)
462 Ecore_Event_Mouse_Relative_Move *ev = event;
464 if (ev->dev) ecore_device_unref(ev->dev);
470 _e_input_event_mouse_wheel_cb_free(void *data EINA_UNUSED, void *event)
472 Ecore_Event_Mouse_Wheel *ev = event;
474 if (ev->dev) ecore_device_unref(ev->dev);
480 _e_input_event_mouse_button_cb_free(void *data EINA_UNUSED, void *event)
482 Ecore_Event_Mouse_Button *ev = event;
484 if (ev->dev) ecore_device_unref(ev->dev);
490 _e_input_event_key_cb_free(void *data EINA_UNUSED, void *event)
492 Ecore_Event_Key *ev = event;
494 if (e_input_thread_mode_get())
496 if (ev->dev) g_object_unref(ev->dev);
500 if (ev->dev) ecore_device_unref(ev->dev);
503 if (ev->data) E_FREE(ev->data);
509 _device_handle_key(struct libinput_device *device, struct libinput_event_keyboard *event)
512 E_Input_Backend *input;
514 uint32_t code, nsyms;
515 const xkb_keysym_t *syms;
516 enum libinput_key_state state;
518 xkb_keysym_t sym = XKB_KEY_NoSymbol;
519 char key[256] = {0, }, keyname[256] = {0, }, compose_buffer[256] = {0, };
521 char *tmp = NULL, *compose = NULL;
522 E_Keyrouter_Event_Data *key_data;
523 Ecore_Device *ecore_dev = NULL, *data;
524 E_Device *e_dev = NULL, *e_dev_data;
525 Eina_List *l = NULL, *l_next = NULL;
527 E_Comp_Config *comp_conf = NULL;
528 int *pressed_keycode = NULL, *idata = NULL;
529 Eina_Bool dup_found = EINA_FALSE;
530 const char *device_name = NULL;
531 Ecore_Device_Subclass device_subclas = ECORE_DEVICE_SUBCLASS_NONE;
533 if (!(edev = libinput_device_get_user_data(device)))
538 if (!(input = edev->seat->input))
543 if (!e_input_thread_mode_get())
545 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
546 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
548 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
550 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_KEYBOARD)
559 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
560 ecore_dev = edev->ecore_dev;
565 ERR("Failed to get source ecore device from event !\n");
569 device_name = ecore_device_name_get(ecore_dev);
570 device_subclas = ecore_device_subclass_get(ecore_dev);
574 if (edev->e_dev) e_dev = edev->e_dev;
575 else if (edev->e_dev_list && g_list_length(edev->e_dev_list) > 0)
577 glist = edev->e_dev_list;
580 e_dev_data = glist->data;
581 if (e_device_class_get(e_dev_data) == ECORE_DEVICE_CLASS_KEYBOARD)
587 glist = g_list_next(glist);
592 edev->e_dev = e_input_evdev_get_e_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
598 ERR("Failed to get source e device from event !\n");
602 device_name = e_device_name_get(e_dev);
603 device_subclas = e_device_subclass_get(e_dev);
606 timestamp = libinput_event_keyboard_get_time(event);
607 code = libinput_event_keyboard_get_key(event);
608 code = _device_remapped_key_get(edev, code + 8);
609 state = libinput_event_keyboard_get_key_state(event);
610 key_count = libinput_event_keyboard_get_seat_key_count(event);
612 if (state == LIBINPUT_KEY_STATE_PRESSED)
614 if ((edev->seat->dev->blocked & E_INPUT_SEAT_KEYBOARD) ||
615 (edev->seat->dev->server_blocked & E_INPUT_SEAT_KEYBOARD))
617 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
618 ELOGF("Key", "Press (keycode: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
619 code, device_name, blocked_client,
620 edev->seat->dev->server_blocked);
624 /* FIXME: Currently to maintain press/release event pair during input block,
625 * used Eina_List and this is method used in devicemgr module.
626 * But we need to consider which way is better to maintain key press/release pair.
629 EINA_LIST_FOREACH(edev->xkb.pressed_keys, l, idata)
633 dup_found = EINA_TRUE;
639 pressed_keycode = E_NEW(int, 1);
640 EINA_SAFETY_ON_NULL_RETURN(pressed_keycode);
641 *pressed_keycode = code;
643 edev->xkb.pressed_keys = eina_list_append(edev->xkb.pressed_keys, pressed_keycode);
648 dup_found = EINA_FALSE;
649 EINA_LIST_FOREACH_SAFE(edev->xkb.pressed_keys, l, l_next, idata)
653 edev->xkb.pressed_keys = eina_list_remove_list(edev->xkb.pressed_keys, l);
655 dup_found = EINA_TRUE;
661 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
662 ELOGF("Key", "Release (keycode: %d, device: %s) is blocked by %p", NULL,
663 code, device_name, blocked_client);
668 /* ignore key events that are not seat wide state changes */
669 if (((state == LIBINPUT_KEY_STATE_PRESSED) && (key_count != 1)) ||
670 ((state == LIBINPUT_KEY_STATE_RELEASED) && (key_count != 0)))
675 e_input_keyboard_grab_key_cb func = e_input_keyboard_grab_key_handler_get();
678 if (e_devicemgr_keyboard_grab_subtype_is_grabbed(device_subclas))
680 if (!e_input_thread_mode_get())
681 func(code, state, timestamp, ecore_dev);
683 func(code, state, timestamp, e_dev);
688 xkb_state_update_key(edev->xkb.state, code,
689 (state ? XKB_KEY_DOWN : XKB_KEY_UP));
691 /* get the keysym for this code */
692 nsyms = xkb_key_get_syms(edev->xkb.state, code, &syms);
694 if (nsyms == 1) sym = syms[0];
696 /* If no keysym was found, name it "Keycode-NNN" */
697 if (sym == XKB_KEY_NoSymbol)
698 snprintf(key, sizeof(key), "Keycode-%u", code);
701 /* get the keyname for this sym */
702 xkb_keysym_get_name(sym, key, sizeof(key));
707 /* If no keyname was found, name it "Keycode-NNN" */
708 snprintf(keyname, sizeof(keyname), "Keycode-%u", code);
712 memcpy(keyname, key, sizeof(keyname));
715 /* if shift is active, we need to transform the key to lower */
716 if (xkb_state_mod_index_is_active(edev->xkb.state,
717 xkb_map_mod_get_index(edev->xkb.keymap,
719 XKB_STATE_MODS_EFFECTIVE))
721 if (keyname[0] != '\0')
722 keyname[0] = tolower(keyname[0]);
725 if (_device_keysym_translate(sym, edev->xkb.modifiers,
726 compose_buffer, sizeof(compose_buffer)))
728 compose = eina_str_convert("ISO8859-1", "UTF-8", compose_buffer);
731 ERR("E Input cannot convert input key string '%s' to UTF-8. "
732 "Is Eina built with iconv support?", compose_buffer);
738 if (!compose) compose = compose_buffer;
740 e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) +
741 ((compose[0] != '\0') ? strlen(compose) : 0) + 3);
747 key_data = E_NEW(E_Keyrouter_Event_Data, 1);
755 e->keyname = (char *)(e + 1);
756 e->key = e->keyname + strlen(keyname) + 1;
757 e->compose = strlen(compose) ? e->key + strlen(key) + 1 : NULL;
758 e->string = e->compose;
760 strncpy((char *)e->keyname, keyname, strlen(keyname));
761 strncpy((char *)e->key, key, strlen(key));
762 if (strlen(compose)) strncpy((char *)e->compose, compose, strlen(compose));
764 e->window = (Ecore_Window)input->dev->window;
765 e->event_window = (Ecore_Window)input->dev->window;
766 e->root_window = (Ecore_Window)input->dev->window;
767 e->timestamp = timestamp;
772 _device_modifiers_update(edev);
774 e->modifiers = edev->xkb.modifiers;
776 comp_conf = e_comp_config_get();
778 if (comp_conf && comp_conf->input_log_enable)
779 ELOGF("Key", "%s (keyname: %s, keycode: %d, timestamp: %u, device: %s)", NULL, state?"Press":"Release", e->keyname, e->keycode, e->timestamp, device_name);
781 if (e_config->key_input_ttrace_enable)
783 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));
784 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));
787 _e_input_key_event_list_add(e);
789 if (e_input_thread_mode_get())
791 e->dev = (Eo *)g_object_ref(e_dev);
792 e_input_event_add(input->event_source, state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
796 e->dev = ecore_device_ref(ecore_dev);
797 ecore_event_add(state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
800 if (e_config->key_input_ttrace_enable)
803 ELOGF("INPUT", "ECORE_EVENT_KEY|E|", NULL);
810 _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event)
812 E_Input_Backend *input;
813 Ecore_Event_Mouse_Move *ev;
814 Ecore_Device *ecore_dev = NULL, *data, *detent_data = NULL;
816 int x = 0, y = 0, w = 0, h = 0;
818 if (!(input = edev->seat->input)) return;
820 ecore_thread_main_loop_begin();
822 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
823 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
825 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
827 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
832 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
837 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
839 ecore_dev = detent_data;
844 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
845 ecore_dev = edev->ecore_dev;
850 ERR("Failed to get source ecore device from event !\n");
853 else if ((detent_data == ecore_dev) || e_devicemgr_detent_is_detent(ecore_device_name_get(ecore_dev)))
855 /* Do not process detent device's move events. */
859 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
861 _device_configured_size_get(edev, &x, &y, &w, &h);
863 if (edev->seat->ptr.ix < x)
864 edev->seat->ptr.dx = edev->seat->ptr.ix = x;
865 else if (edev->seat->ptr.ix >= (x + w))
866 edev->seat->ptr.dx = edev->seat->ptr.ix = (x + w - 1);
868 if (edev->seat->ptr.iy < y)
869 edev->seat->ptr.dy = edev->seat->ptr.iy = y;
870 else if (edev->seat->ptr.iy >= (y + h))
871 edev->seat->ptr.dy = edev->seat->ptr.iy = (y + h - 1);
873 edev->mouse.dx = edev->seat->ptr.dx;
874 edev->mouse.dy = edev->seat->ptr.dy;
876 ev->window = (Ecore_Window)input->dev->window;
877 ev->event_window = (Ecore_Window)input->dev->window;
878 ev->root_window = (Ecore_Window)input->dev->window;
879 if (event) ev->timestamp = libinput_event_pointer_get_time(event);
882 _device_modifiers_update(edev);
883 ev->modifiers = edev->xkb.modifiers;
885 ev->x = edev->seat->ptr.ix;
886 ev->y = edev->seat->ptr.iy;
890 ev->multi.device = edev->mt_slot;
891 ev->multi.radius = 1;
892 ev->multi.radius_x = 1;
893 ev->multi.radius_y = 1;
894 ev->multi.pressure = 1.0;
895 ev->multi.angle = 0.0;
898 ev->multi.root.x = ev->x;
899 ev->multi.root.y = ev->y;
901 ev->dev = ecore_device_ref(ecore_dev);
903 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
906 ecore_thread_main_loop_end();
910 _e_input_pointer_motion_post(E_Input_Evdev *edev)
912 _device_pointer_motion(edev, NULL);
916 _device_pointer_relative_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event, double dx[2], double dy[2])
918 E_Input_Backend *input;
919 Ecore_Event_Mouse_Relative_Move *ev;
920 Ecore_Device *ecore_dev = NULL, *data, *detent_data = NULL;
922 E_Comp_Config *comp_conf;
924 if (!(input = edev->seat->input)) return;
926 ecore_thread_main_loop_begin();
928 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
929 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
931 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
933 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
938 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
943 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
945 ecore_dev = detent_data;
950 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
951 ecore_dev = edev->ecore_dev;
956 ERR("Failed to get source ecore device from event !\n");
959 else if ((detent_data == ecore_dev) || e_devicemgr_detent_is_detent(ecore_device_name_get(ecore_dev)))
961 /* Do not process detent device's move events. */
965 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Relative_Move)))) return;
967 ev->window = (Ecore_Window)input->dev->window;
968 ev->event_window = (Ecore_Window)input->dev->window;
969 if (event) ev->timestamp = libinput_event_pointer_get_time(event);
971 ev->modifiers = edev->xkb.modifiers;
975 ev->dx_unaccel = (int)dx[1];
976 ev->dy_unaccel = (int)dy[1];
978 ev->dev = ecore_device_ref(ecore_dev);
980 comp_conf = e_comp_config_get();
981 if (comp_conf && comp_conf->input_log_enable)
982 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));
984 ecore_event_add(ECORE_EVENT_MOUSE_RELATIVE_MOVE, ev, _e_input_event_mouse_relative_move_cb_free, NULL);
987 ecore_thread_main_loop_end();
991 _device_pointer_motion_send(E_Input_Evdev *edev, struct libinput_event_pointer *event, double dx[2], double dy[2])
993 e_input_relative_motion_cb func = e_input_relative_motion_handler_get();
996 //func(dx, dy, time_us);
997 _device_pointer_relative_motion(edev, event, dx, dy);
1001 double seat_dx, seat_dy, temp;
1002 if (edev->disable_acceleration)
1013 if (edev->seat->ptr.swap)
1019 if (edev->seat->ptr.invert_x)
1021 if (edev->seat->ptr.invert_y)
1024 edev->seat->ptr.dx += seat_dx;
1025 edev->seat->ptr.dy += seat_dy;
1027 edev->mouse.dx = edev->seat->ptr.dx;
1028 edev->mouse.dy = edev->seat->ptr.dy;
1030 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
1031 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
1036 edev->seat->ptr.ix = edev->seat->ptr.dx;
1037 edev->seat->ptr.iy = edev->seat->ptr.dy;
1039 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1040 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1045 _device_pointer_motion(edev, event);
1050 _device_handle_pointer_motion(struct libinput_device *device, struct libinput_event_pointer *event)
1052 E_Input_Evdev *edev;
1053 double delta_x[2]; /* delta_x[0] for accelerated, delta_x[1] for unaccelerated */
1054 double delta_y[2]; /* delta_y[0] for accelerated, delta_y[1] for unaccelerated */
1056 if (!(edev = libinput_device_get_user_data(device)))
1061 delta_x[0] = libinput_event_pointer_get_dx(event);
1062 delta_x[1] = libinput_event_pointer_get_dx_unaccelerated(event);
1063 delta_y[0] = libinput_event_pointer_get_dy(event);
1064 delta_y[1] = libinput_event_pointer_get_dy_unaccelerated(event);
1066 _device_pointer_motion_send(edev, event, &delta_x[0], &delta_y[0]);
1070 _device_handle_pointer_motion_absolute(struct libinput_device *device, struct libinput_event_pointer *event)
1072 E_Input_Evdev *edev;
1075 if (!(edev = libinput_device_get_user_data(device)))
1080 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
1082 edev->mouse.dx = edev->seat->ptr.dx =
1083 libinput_event_pointer_get_absolute_x_transformed(event, w);
1084 edev->mouse.dy = edev->seat->ptr.dy =
1085 libinput_event_pointer_get_absolute_y_transformed(event, h);
1087 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
1088 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
1093 edev->seat->ptr.ix = edev->seat->ptr.dx;
1094 edev->seat->ptr.iy = edev->seat->ptr.dy;
1096 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1097 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1102 _device_pointer_motion(edev, event);
1106 _device_handle_button(struct libinput_device *device, struct libinput_event_pointer *event)
1108 E_Input_Evdev *edev;
1109 E_Input_Backend *input;
1110 Ecore_Event_Mouse_Button *ev;
1111 enum libinput_button_state state;
1112 uint32_t button, timestamp;
1113 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1115 E_Comp_Config *comp_conf = NULL;
1117 if (!(edev = libinput_device_get_user_data(device)))
1121 if (!(input = edev->seat->input))
1126 ecore_thread_main_loop_begin();
1128 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1129 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1131 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1133 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1138 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1143 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1145 ecore_dev = detent_data;
1150 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1151 ecore_dev = edev->ecore_dev;
1156 ERR("Failed to get source ecore device from event !\n");
1160 state = libinput_event_pointer_get_button_state(event);
1161 button = libinput_event_pointer_get_button(event);
1162 timestamp = libinput_event_pointer_get_time(event);
1164 button = ((button & 0x00F) + 1);
1165 if (button == 3) button = 2;
1166 else if (button == 2) button = 3;
1168 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
1172 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1173 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1176 ELOGF("Mouse", "Button Press (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
1177 button, ecore_device_name_get(ecore_dev), blocked_client,
1178 edev->seat->dev->server_blocked);
1183 edev->mouse.pressed_button |= (1 << button);
1188 if (!(edev->mouse.pressed_button & (1 << button)))
1190 ELOGF("Mouse", "Button Release (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
1191 button, ecore_device_name_get(ecore_dev), blocked_client,
1192 edev->seat->dev->server_blocked);
1195 edev->mouse.pressed_button &= ~(1 << button);
1198 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button))))
1203 ev->window = (Ecore_Window)input->dev->window;
1204 ev->event_window = (Ecore_Window)input->dev->window;
1205 ev->root_window = (Ecore_Window)input->dev->window;
1206 ev->timestamp = timestamp;
1207 ev->same_screen = 1;
1209 _device_modifiers_update(edev);
1210 ev->modifiers = edev->xkb.modifiers;
1212 ev->x = edev->seat->ptr.ix;
1213 ev->y = edev->seat->ptr.iy;
1217 ev->multi.device = edev->mt_slot;
1218 ev->multi.radius = 1;
1219 ev->multi.radius_x = 1;
1220 ev->multi.radius_y = 1;
1221 ev->multi.pressure = 1.0;
1222 ev->multi.angle = 0.0;
1223 ev->multi.x = ev->x;
1224 ev->multi.y = ev->y;
1225 ev->multi.root.x = ev->x;
1226 ev->multi.root.y = ev->y;
1227 ev->dev = ecore_device_ref(ecore_dev);
1231 unsigned int current;
1233 current = timestamp;
1234 edev->mouse.did_double = EINA_FALSE;
1235 edev->mouse.did_triple = EINA_FALSE;
1237 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1238 (button == edev->mouse.prev_button))
1240 edev->mouse.did_double = EINA_TRUE;
1241 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1242 (button == edev->mouse.last_button))
1244 edev->mouse.did_triple = EINA_TRUE;
1245 edev->mouse.prev = 0;
1246 edev->mouse.last = 0;
1251 edev->mouse.last = edev->mouse.prev;
1252 edev->mouse.prev = current;
1253 edev->mouse.last_button = edev->mouse.prev_button;
1254 edev->mouse.prev_button = button;
1257 ev->buttons = button;
1259 if (edev->mouse.did_double)
1260 ev->double_click = 1;
1261 if (edev->mouse.did_triple)
1262 ev->triple_click = 1;
1264 comp_conf = e_comp_config_get();
1265 if (comp_conf && comp_conf->input_log_enable)
1266 ELOGF("Mouse", "Button %s (btn: %d, device: %s)", NULL, state?"Press":"Release", button, ecore_device_name_get(ev->dev));
1269 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, _e_input_event_mouse_button_cb_free, NULL);
1271 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, _e_input_event_mouse_button_cb_free, NULL);
1274 ecore_thread_main_loop_end();
1277 #if !LIBINPUT_HAVE_SCROLL_VALUE_V120
1279 _axis_value_get(struct libinput_event_pointer *pointer_event, enum libinput_pointer_axis axis)
1281 enum libinput_pointer_axis_source source;
1282 double value = 0.0, value_discrete = 0.0;
1284 E_Comp_Config *comp_conf = NULL;
1286 comp_conf = e_comp_config_get();
1287 source = libinput_event_pointer_get_axis_source(pointer_event);
1290 case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL:
1291 value_discrete = libinput_event_pointer_get_axis_value_discrete(pointer_event, axis);
1292 value = libinput_event_pointer_get_axis_value(pointer_event, axis);
1293 if (comp_conf && comp_conf->input_log_enable)
1295 ELOGF("Axis", "SOURCE_WHEEL discrete: %lf (cf. value: %lf)", NULL, value_discrete, value);
1297 ret = (int)value_discrete;
1299 case LIBINPUT_POINTER_AXIS_SOURCE_FINGER:
1300 case LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS:
1301 value = libinput_event_pointer_get_axis_value(pointer_event, axis);
1302 if (comp_conf && comp_conf->input_log_enable)
1304 ELOGF("Axis", "SOURCE_FINGER/CONTINUOUS value: %lf", NULL, value);
1306 if (value >= E_INPUT_FINGER_SCROLL_THRESHOLD)
1308 else if (value <= E_INPUT_FINGER_SCROLL_THRESHOLD * (-1))
1321 _device_handle_axis(struct libinput_device *device, struct libinput_event_pointer *event)
1323 E_Input_Evdev *edev;
1324 E_Input_Backend *input;
1325 Ecore_Event_Mouse_Wheel *ev;
1327 enum libinput_pointer_axis axis;
1328 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1330 E_Comp_Config *comp_conf = NULL;
1331 int direction = 0, z = 0;
1333 if (!(edev = libinput_device_get_user_data(device)))
1337 if (!(input = edev->seat->input))
1342 ecore_thread_main_loop_begin();
1344 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1345 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1347 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1349 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1354 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1359 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1361 ecore_dev = detent_data;
1366 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1367 ecore_dev = edev->ecore_dev;
1372 ERR("Failed to get source ecore device from event !\n");
1376 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1377 if (libinput_event_pointer_has_axis(event, axis))
1378 z = _axis_value_get(event, axis);
1380 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1381 if (libinput_event_pointer_has_axis(event, axis))
1384 z = _axis_value_get(event, axis);
1389 ELOGF("Mouse", "Axis event is ignored since it has zero value", NULL);
1393 comp_conf = e_comp_config_get();
1394 if (comp_conf && comp_conf->e_wheel_click_angle)
1396 z = (int)(z * comp_conf->e_wheel_click_angle);
1399 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1400 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1402 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
1405 ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1406 direction, z, blocked_client, edev->seat->dev->server_blocked);
1408 ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1409 direction, z, blocked_client, edev->seat->dev->server_blocked);
1414 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1419 timestamp = libinput_event_pointer_get_time(event);
1421 ev->window = (Ecore_Window)input->dev->window;
1422 ev->event_window = (Ecore_Window)input->dev->window;
1423 ev->root_window = (Ecore_Window)input->dev->window;
1424 ev->timestamp = timestamp;
1425 ev->same_screen = 1;
1427 _device_modifiers_update(edev);
1428 ev->modifiers = edev->xkb.modifiers;
1430 ev->x = edev->seat->ptr.ix;
1431 ev->y = edev->seat->ptr.iy;
1435 ev->direction = direction;
1437 if (comp_conf && comp_conf->input_log_enable)
1440 ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1442 ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1446 ev->dev = ecore_device_ref(ecore_dev);
1447 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1450 ecore_thread_main_loop_end();
1454 #if LIBINPUT_HAVE_SCROLL_VALUE_V120
1456 _scroll_value_get(struct libinput_event_pointer *pointer_event, enum libinput_pointer_axis axis, E_Input_Axis_Source source)
1459 double value_v120 = 0.0;
1461 E_Comp_Config *comp_conf = NULL;
1463 comp_conf = e_comp_config_get();
1466 case E_INPUT_AXIS_SOURCE_WHEEL:
1467 value_v120 = libinput_event_pointer_get_scroll_value_v120(pointer_event, axis);
1468 value = libinput_event_pointer_get_scroll_value(pointer_event, axis);
1469 if (comp_conf && comp_conf->input_log_enable)
1471 ELOGF("Scroll", "SOURCE_WHEEL value_v120: %lf (cf. value: %lf)", NULL, value_v120, value);
1473 if (((int)value_v120 % E_INPUT_POINTER_AXIS_DISCRETE_STEP) != 0)
1475 ERR("Wheel movements should be multiples (or fractions) of 120!\n");
1480 ret = value_v120 / E_INPUT_POINTER_AXIS_DISCRETE_STEP;
1483 case E_INPUT_AXIS_SOURCE_FINGER:
1484 case E_INPUT_AXIS_SOURCE_CONTINUOUS:
1485 value = libinput_event_pointer_get_scroll_value(pointer_event, axis);
1486 if (comp_conf && comp_conf->input_log_enable)
1488 ELOGF("Scroll", "SOURCE_FINGER/CONTINUOUS value: %lf", NULL, value);
1490 if (value >= E_INPUT_FINGER_SCROLL_THRESHOLD)
1492 else if (value <= E_INPUT_FINGER_SCROLL_THRESHOLD * (-1))
1505 _device_handle_axis_v120(struct libinput_device *device, struct libinput_event_pointer *event, E_Input_Axis_Source source)
1507 E_Input_Evdev *edev;
1508 E_Input_Backend *input;
1509 Ecore_Event_Mouse_Wheel *ev;
1511 enum libinput_pointer_axis axis;
1512 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1514 E_Comp_Config *comp_conf = NULL;
1515 int direction = 0, z = 0;
1517 if (!(edev = libinput_device_get_user_data(device)))
1521 if (!(input = edev->seat->input))
1526 ecore_thread_main_loop_begin();
1528 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1529 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1531 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1533 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1538 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1543 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1545 ecore_dev = detent_data;
1550 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1551 ecore_dev = edev->ecore_dev;
1556 ERR("Failed to get source ecore device from event !\n");
1560 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1561 if (libinput_event_pointer_has_axis(event, axis))
1562 z = _scroll_value_get(event, axis, source);
1564 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1565 if (libinput_event_pointer_has_axis(event, axis))
1568 z = _scroll_value_get(event, axis, source);
1573 ELOGF("Mouse", "Scroll event is ignored since it has zero value", NULL);
1577 comp_conf = e_comp_config_get();
1578 if (comp_conf && comp_conf->e_wheel_click_angle)
1580 z = (int)(z * comp_conf->e_wheel_click_angle);
1583 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1584 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1586 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
1588 ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1589 direction, z, blocked_client, edev->seat->dev->server_blocked);
1591 ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1592 direction, z, blocked_client, edev->seat->dev->server_blocked);
1597 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1602 timestamp = libinput_event_pointer_get_time(event);
1604 ev->window = (Ecore_Window)input->dev->window;
1605 ev->event_window = (Ecore_Window)input->dev->window;
1606 ev->root_window = (Ecore_Window)input->dev->window;
1607 ev->timestamp = timestamp;
1608 ev->same_screen = 1;
1610 _device_modifiers_update(edev);
1611 ev->modifiers = edev->xkb.modifiers;
1613 ev->x = edev->seat->ptr.ix;
1614 ev->y = edev->seat->ptr.iy;
1618 ev->direction = direction;
1620 if (comp_conf && comp_conf->input_log_enable)
1623 ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1625 ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1628 ev->dev = ecore_device_ref(ecore_dev);
1629 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1632 ecore_thread_main_loop_end();
1637 _device_handle_touch_event_send(E_Input_Evdev *edev, struct libinput_event_touch *event, int state)
1639 E_Input_Backend *input;
1640 Ecore_Event_Mouse_Button *ev;
1641 uint32_t timestamp, button = 0;
1642 Ecore_Device *ecore_dev = NULL, *data;
1646 if (!(input = edev->seat->input)) return;
1648 ecore_thread_main_loop_begin();
1650 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1651 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1653 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1655 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1664 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1665 ecore_dev = edev->ecore_dev;
1670 ERR("Failed to get source ecore device from event !\n");
1674 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) goto end;
1676 timestamp = libinput_event_touch_get_time(event);
1678 ev->window = (Ecore_Window)input->dev->window;
1679 ev->event_window = (Ecore_Window)input->dev->window;
1680 ev->root_window = (Ecore_Window)input->dev->window;
1681 ev->timestamp = timestamp;
1682 ev->same_screen = 1;
1684 _device_modifiers_update(edev);
1685 ev->modifiers = edev->xkb.modifiers;
1687 ev->x = edev->seat->ptr.ix;
1688 ev->y = edev->seat->ptr.iy;
1692 ev->multi.device = edev->mt_slot;
1693 ev->multi.radius = 1;
1694 ev->multi.radius_x = 1;
1695 ev->multi.radius_y = 1;
1696 ev->multi.pressure = 1.0;
1697 ev->multi.angle = 0.0;
1698 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1699 if (libinput_event_get_type(libinput_event_touch_get_base_event(event))
1700 == LIBINPUT_EVENT_TOUCH_DOWN)
1702 if (libinput_event_touch_has_minor(event))
1703 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1704 if (libinput_event_touch_has_major(event))
1705 ev->multi.radius_y = libinput_event_touch_get_major(event);
1706 if (libinput_event_touch_has_pressure(event))
1707 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1708 if (libinput_event_touch_has_orientation(event))
1709 ev->multi.angle = libinput_event_touch_get_orientation(event);
1712 ev->multi.x = ev->x;
1713 ev->multi.y = ev->y;
1714 ev->multi.root.x = ev->x;
1715 ev->multi.root.y = ev->y;
1716 ev->dev = ecore_device_ref(ecore_dev);
1718 if (state == ECORE_EVENT_MOUSE_BUTTON_DOWN)
1720 unsigned int current;
1722 current = timestamp;
1723 edev->mouse.did_double = EINA_FALSE;
1724 edev->mouse.did_triple = EINA_FALSE;
1726 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1727 (button == edev->mouse.prev_button))
1729 edev->mouse.did_double = EINA_TRUE;
1730 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1731 (button == edev->mouse.last_button))
1733 edev->mouse.did_triple = EINA_TRUE;
1734 edev->mouse.prev = 0;
1735 edev->mouse.last = 0;
1740 edev->mouse.last = edev->mouse.prev;
1741 edev->mouse.prev = current;
1742 edev->mouse.last_button = edev->mouse.prev_button;
1743 edev->mouse.prev_button = button;
1744 edev->touch.pressed |= (1 << ev->multi.device);
1748 edev->touch.pressed &= ~(1 << ev->multi.device);
1751 ev->buttons = ((button & 0x00F) + 1);
1753 if (edev->mouse.did_double)
1754 ev->double_click = 1;
1755 if (edev->mouse.did_triple)
1756 ev->triple_click = 1;
1758 ecore_event_add(state, ev, _e_input_event_mouse_button_cb_free, NULL);
1761 ecore_thread_main_loop_end();
1765 _device_handle_touch_motion_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1767 E_Input_Backend *input;
1768 Ecore_Event_Mouse_Move *ev;
1769 Ecore_Device *ecore_dev = NULL, *data;
1773 if (!(input = edev->seat->input)) return;
1775 ecore_thread_main_loop_begin();
1777 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1778 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1780 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1782 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1791 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1792 ecore_dev = edev->ecore_dev;
1797 ERR("Failed to get source ecore device from event !\n");
1801 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) goto end;
1803 ev->window = (Ecore_Window)input->dev->window;
1804 ev->event_window = (Ecore_Window)input->dev->window;
1805 ev->root_window = (Ecore_Window)input->dev->window;
1806 ev->timestamp = libinput_event_touch_get_time(event);
1807 ev->same_screen = 1;
1809 _device_modifiers_update(edev);
1810 ev->modifiers = edev->xkb.modifiers;
1812 ev->x = edev->seat->ptr.ix;
1813 ev->y = edev->seat->ptr.iy;
1817 ev->multi.device = edev->mt_slot;
1818 ev->multi.radius = 1;
1819 ev->multi.radius_x = 1;
1820 ev->multi.radius_y = 1;
1821 ev->multi.pressure = 1.0;
1822 ev->multi.angle = 0.0;
1823 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1824 if (libinput_event_touch_has_minor(event))
1825 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1826 if (libinput_event_touch_has_major(event))
1827 ev->multi.radius_y = libinput_event_touch_get_major(event);
1828 if (libinput_event_touch_has_pressure(event))
1829 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1830 if (libinput_event_touch_has_orientation(event))
1831 ev->multi.angle = libinput_event_touch_get_orientation(event);
1833 ev->multi.x = ev->x;
1834 ev->multi.y = ev->y;
1835 ev->multi.root.x = ev->x;
1836 ev->multi.root.y = ev->y;
1837 ev->dev = ecore_device_ref(ecore_dev);
1839 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
1842 ecore_thread_main_loop_end();
1846 _device_handle_touch_cancel_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1848 E_Input_Backend *input;
1849 Ecore_Event_Mouse_Button *ev;
1850 uint32_t timestamp, button = 0;
1851 Ecore_Device *ecore_dev = NULL, *data;
1855 if (!(input = edev->seat->input)) return;
1857 ecore_thread_main_loop_begin();
1859 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1860 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1862 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1864 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1873 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1874 ecore_dev = edev->ecore_dev;
1879 ERR("Failed to get source ecore device from event !\n");
1883 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) goto end;
1885 timestamp = libinput_event_touch_get_time(event);
1887 ev->window = (Ecore_Window)input->dev->window;
1888 ev->event_window = (Ecore_Window)input->dev->window;
1889 ev->root_window = (Ecore_Window)input->dev->window;
1890 ev->timestamp = timestamp;
1891 ev->same_screen = 1;
1893 ev->x = edev->seat->ptr.ix;
1894 ev->y = edev->seat->ptr.iy;
1898 ev->multi.device = edev->mt_slot;
1899 ev->multi.radius = 1;
1900 ev->multi.radius_x = 1;
1901 ev->multi.radius_y = 1;
1902 ev->multi.pressure = 1.0;
1903 ev->multi.angle = 0.0;
1904 ev->multi.x = ev->x;
1905 ev->multi.y = ev->y;
1906 ev->multi.root.x = ev->x;
1907 ev->multi.root.y = ev->y;
1909 edev->touch.pressed &= ~(1 << ev->multi.device);
1911 ev->buttons = ((button & 0x00F) + 1);
1912 ev->dev = ecore_device_ref(ecore_dev);
1914 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev, _e_input_event_mouse_button_cb_free, NULL);
1917 ecore_thread_main_loop_end();
1921 _device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, int *w, int *h)
1923 E_Output *output = NULL;
1925 EINA_SAFETY_ON_NULL_RETURN(edev);
1927 if (!edev->output_configured)
1929 if (edev->output_name)
1931 output = e_output_find(edev->output_name);
1934 edev->mouse.minx = output->config.geom.x;
1935 edev->mouse.miny = output->config.geom.y;
1936 edev->mouse.maxw = output->config.geom.w;
1937 edev->mouse.maxh = output->config.geom.h;
1938 if (edev->caps & E_INPUT_SEAT_POINTER)
1940 edev->seat->ptr.dx = (double)(edev->mouse.maxw / 2);
1941 edev->seat->ptr.dy = (double)(edev->mouse.maxh / 2);
1942 edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
1943 edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
1944 edev->mouse.dx = edev->seat->ptr.dx;
1945 edev->mouse.dy = edev->seat->ptr.dy;
1950 edev->output_configured = EINA_TRUE;
1951 ELOGF("E_INPUT_EVDEV", "Device is configured by output x:%d,y:%d (w:%d, h:%d)",
1952 NULL, edev->mouse.minx, edev->mouse.miny, edev->mouse.maxw, edev->mouse.maxh);
1954 if (x) *x = edev->mouse.minx;
1955 if (y) *y = edev->mouse.miny;
1956 if (w) *w = edev->mouse.maxw;
1957 if (h) *h = edev->mouse.maxh;
1961 _device_handle_touch_down(struct libinput_device *device, struct libinput_event_touch *event)
1963 E_Input_Evdev *edev;
1964 int x = 0, y = 0, w = 0, h = 0;
1965 E_Comp_Config *comp_conf = NULL;
1967 if (!(edev = libinput_device_get_user_data(device)))
1972 _device_configured_size_get(edev, &x, &y, &w, &h);
1974 edev->mouse.dx = edev->seat->ptr.ix = edev->seat->ptr.dx =
1975 x + libinput_event_touch_get_x_transformed(event, w);
1976 edev->mouse.dy = edev->seat->ptr.iy = edev->seat->ptr.dy =
1977 y + libinput_event_touch_get_y_transformed(event, h);
1979 edev->mt_slot = libinput_event_touch_get_slot(event);
1980 if (edev->mt_slot < 0)
1982 /* FIXME: The single touch device return slot id -1
1983 * But currently we have no API to distinguish multi touch or single touch
1984 * After libinput 1.11 version, libinput provides get_touch_count API,
1985 * so we can distinguish multi touch device or single touch device.
1987 if (edev->mt_slot == -1)
1991 WRN("%d slot touch down events are not supported\n", edev->mt_slot);
1996 if (edev->mt_slot < e_input_touch_max_count_get())
1998 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
1999 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
2002 comp_conf = e_comp_config_get();
2003 if (comp_conf && comp_conf->input_log_enable)
2004 ELOGF("Touch", "Down (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2006 atomic_fetch_or(&edev->touch.raw_pressed, (1 << edev->mt_slot));
2008 if (edev->touch.blocked)
2010 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
2011 ELOGF("Touch", "Down (id: %d, x: %d, y: %d) is blocked by %p, server: 0x%x", NULL,
2012 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, blocked_client,
2013 edev->seat->dev->server_blocked);
2017 _device_handle_touch_motion_send(edev, event);
2018 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_DOWN);
2022 _device_handle_touch_motion(struct libinput_device *device, struct libinput_event_touch *event)
2024 E_Input_Evdev *edev;
2025 int x = 0, y = 0, w = 0, h = 0;
2027 if (!(edev = libinput_device_get_user_data(device)))
2032 _device_configured_size_get(edev, &x, &y, &w, &h);
2034 edev->mouse.dx = edev->seat->ptr.dx =
2035 x + libinput_event_touch_get_x_transformed(event, w);
2036 edev->mouse.dy = edev->seat->ptr.dy =
2037 y + libinput_event_touch_get_y_transformed(event, h);
2039 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
2040 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
2045 edev->seat->ptr.ix = edev->seat->ptr.dx;
2046 edev->seat->ptr.iy = edev->seat->ptr.dy;
2048 edev->mt_slot = libinput_event_touch_get_slot(event);
2049 if (edev->mt_slot < 0)
2051 /* FIXME: The single touch device return slot id -1
2052 * But currently we have no API to distinguish multi touch or single touch
2053 * After libinput 1.11 version, libinput provides get_touch_count API,
2054 * so we can distinguish multi touch device or single touch device.
2056 if (edev->mt_slot == -1)
2060 WRN("%d slot touch motion events are not supported\n", edev->mt_slot);
2065 if (edev->mt_slot < e_input_touch_max_count_get())
2067 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
2068 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
2071 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
2073 if (edev->touch.blocked)
2079 _device_handle_touch_motion_send(edev, event);
2083 _device_handle_touch_up(struct libinput_device *device, struct libinput_event_touch *event)
2085 E_Input_Evdev *edev;
2086 E_Comp_Config *comp_conf = NULL;
2088 if (!(edev = libinput_device_get_user_data(device)))
2093 edev->mt_slot = libinput_event_touch_get_slot(event);
2094 if (edev->mt_slot < 0)
2096 /* FIXME: The single touch device return slot id -1
2097 * But currently we have no API to distinguish multi touch or single touch
2098 * After libinput 1.11 version, libinput provides get_touch_count API,
2099 * so we can distinguish multi touch device or single touch device.
2101 if (edev->mt_slot == -1)
2105 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
2110 if (edev->mt_slot < e_input_touch_max_count_get())
2112 edev->mouse.dx = edev->seat->ptr.dx = edev->seat->ptr.ix =
2113 edev->touch.coords[edev->mt_slot].x;
2114 edev->mouse.dy = edev->seat->ptr.dy = edev->seat->ptr.iy =
2115 edev->touch.coords[edev->mt_slot].y;
2118 comp_conf = e_comp_config_get();
2119 if (comp_conf && comp_conf->input_log_enable)
2120 ELOGF("Touch", "Up (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2122 atomic_fetch_and(&edev->touch.raw_pressed, ~(1 << edev->mt_slot));
2124 if (edev->touch.blocked)
2126 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
2128 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
2129 ELOGF("Touch", "Up (id: %d, x: %d, y: %d) is blocked by %p, server(0x%x)", NULL,
2130 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, blocked_client,
2131 edev->seat->dev->server_blocked);
2133 if (edev->touch.raw_pressed == 0x0)
2135 edev->touch.blocked = EINA_FALSE;
2141 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_UP);
2145 _device_handle_touch_cancel(struct libinput_device *device, struct libinput_event_touch *event)
2147 E_Input_Evdev *edev;
2148 E_Comp_Config *comp_conf = NULL;
2150 if (!(edev = libinput_device_get_user_data(device)))
2155 edev->mt_slot = libinput_event_touch_get_slot(event);
2156 if (edev->mt_slot < 0)
2158 /* FIXME: The single touch device return slot id -1
2159 * But currently we have no API to distinguish multi touch or single touch
2160 * After libinput 1.11 version, libinput provides get_touch_count API,
2161 * so we can distinguish multi touch device or single touch device.
2163 if (edev->mt_slot == -1)
2167 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
2172 comp_conf = e_comp_config_get();
2173 if (comp_conf && comp_conf->input_log_enable)
2174 ELOGF("Touch", "cancel (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2176 _device_handle_touch_cancel_send(edev, event);
2181 _device_handle_touch_frame(struct libinput_device *device EINA_UNUSED, struct libinput_event_touch *event EINA_UNUSED)
2183 /* DBG("Unhandled Touch Frame Event"); */
2187 _e_input_aux_data_event_free(void *user_data EINA_UNUSED, void *ev)
2189 Ecore_Event_Axis_Update *e = (Ecore_Event_Axis_Update *)ev;
2191 if (e->axis) free(e->axis);
2192 if (e->dev) ecore_device_unref(e->dev);
2198 _device_handle_touch_aux_data(struct libinput_device *device, struct libinput_event_touch_aux_data *event)
2200 E_Input_Evdev *edev;
2201 E_Input_Backend *input;
2202 Ecore_Event_Axis_Update *ev;
2204 Ecore_Device *ecore_dev = NULL, *data;
2206 E_Comp_Config *comp_conf;
2208 ecore_thread_main_loop_begin();
2210 if (libinput_event_touch_aux_data_get_type(event) != LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM &&
2211 libinput_event_touch_aux_data_get_value(event) > 0)
2214 if (!(edev = libinput_device_get_user_data(device))) goto end;
2215 if (!(input = edev->seat->input)) goto end;
2217 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
2218 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
2220 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
2222 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
2231 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
2232 ecore_dev = edev->ecore_dev;
2237 ERR("Failed to get source ecore device from event !\n");
2241 if (!(ev = calloc(1, sizeof(Ecore_Event_Axis_Update)))) goto end;
2243 ev->window = (Ecore_Window)input->dev->window;
2244 ev->event_window = (Ecore_Window)input->dev->window;
2245 ev->root_window = (Ecore_Window)input->dev->window;
2246 ev->timestamp = libinput_event_touch_aux_data_get_time(event);
2248 axis = (Ecore_Axis *)calloc(1, sizeof(Ecore_Axis));
2251 axis->label = ECORE_AXIS_LABEL_TOUCH_PALM;
2252 axis->value = libinput_event_touch_aux_data_get_value(event);
2257 comp_conf = e_comp_config_get();
2258 if (comp_conf && comp_conf->input_log_enable)
2259 ELOGF("Touch", "Axis (label: %d, value: %lf)", NULL, axis?axis->label:-1, axis?axis->value:0.0);
2261 ev->dev = ecore_device_ref(ecore_dev);
2263 ecore_event_add(ECORE_EVENT_AXIS_UPDATE, ev, _e_input_aux_data_event_free, NULL);
2266 ecore_thread_main_loop_end();
2270 _e_input_evdev_device_create(E_Input_Seat *seat, struct libinput_device *device)
2272 E_Input_Evdev *edev;
2273 E_Input_Backend *b_input;
2274 const char *output_name;
2276 EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
2278 /* try to allocate space for new evdev */
2279 if (!(edev = calloc(1, sizeof(E_Input_Evdev)))) return NULL;
2282 edev->device = device;
2283 edev->path = eina_stringshare_printf("%s/%s", e_input_base_dir_get(), libinput_device_get_sysname(device));
2285 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
2287 edev->caps |= E_INPUT_SEAT_KEYBOARD;
2288 _device_keyboard_setup(edev);
2291 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
2293 edev->caps |= E_INPUT_SEAT_POINTER;
2295 /* TODO: make this configurable */
2296 edev->mouse.threshold = 250;
2298 b_input = seat->input;
2299 if (b_input->left_handed == EINA_TRUE)
2301 if (libinput_device_config_left_handed_set(device, 1) !=
2302 LIBINPUT_CONFIG_STATUS_SUCCESS)
2304 WRN("Failed to set left hand mode about device: %s\n",
2305 libinput_device_get_name(device));
2310 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
2313 edev->caps |= E_INPUT_SEAT_TOUCH;
2314 palm_code = libinput_device_touch_aux_data_get_code(LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM);
2315 if (libinput_device_touch_has_aux_data(device, palm_code))
2317 libinput_device_touch_set_aux_data(device, palm_code);
2320 _device_touch_count_update(edev);
2322 edev->touch.coords = calloc(1, sizeof(E_Input_Coord)*e_input_touch_max_count_get());
2324 if (!edev->touch.coords)
2325 ERR("Failed to allocate memory for touch coords !\n");
2328 output_name = libinput_device_get_output_name(device);
2331 eina_stringshare_replace(&edev->output_name, output_name);
2332 ELOGF("E_INPUT_EVDEV", "Device has output_name:%s", NULL, output_name);
2335 libinput_device_set_user_data(device, edev);
2336 libinput_device_ref(device);
2338 /* configure device */
2339 _device_configure(edev);
2345 _e_input_evdev_device_destroy(E_Input_Evdev *edev)
2348 EINA_SAFETY_ON_NULL_RETURN(edev);
2350 ecore_thread_main_loop_begin();
2352 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
2354 if (edev->xkb.state) xkb_state_unref(edev->xkb.state);
2356 if (edev->xkb.keymap) xkb_map_unref(edev->xkb.keymap);
2359 if (edev->ecore_dev) ecore_device_del(edev->ecore_dev);
2360 if (edev->ecore_dev_list)
2361 EINA_LIST_FREE(edev->ecore_dev_list, dev)
2363 ecore_device_del(dev);
2366 if (edev->e_dev) g_object_unref(edev->e_dev);
2367 if (edev->e_dev_list)
2369 GList *glist = edev->e_dev_list;
2373 e_dev = glist->data;
2374 g_object_unref(e_dev);
2376 glist = g_list_next(glist);
2379 if (edev->path) eina_stringshare_del(edev->path);
2380 if (edev->device) libinput_device_unref(edev->device);
2381 if (edev->key_remap_hash) eina_hash_free(edev->key_remap_hash);
2382 if (edev->touch.coords)
2384 free(edev->touch.coords);
2385 edev->touch.coords = NULL;
2387 eina_stringshare_del(edev->output_name);
2389 ecore_thread_main_loop_end();
2395 _e_input_evdev_event_process(struct libinput_event *event)
2397 struct libinput_device *device;
2398 Eina_Bool ret = EINA_TRUE;
2400 device = libinput_event_get_device(event);
2401 switch (libinput_event_get_type(event))
2403 case LIBINPUT_EVENT_KEYBOARD_KEY:
2404 _device_handle_key(device, libinput_event_get_keyboard_event(event));
2406 case LIBINPUT_EVENT_POINTER_MOTION:
2407 _device_handle_pointer_motion(device,
2408 libinput_event_get_pointer_event(event));
2410 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
2411 _device_handle_pointer_motion_absolute(device,
2412 libinput_event_get_pointer_event(event));
2414 case LIBINPUT_EVENT_POINTER_BUTTON:
2415 _device_handle_button(device, libinput_event_get_pointer_event(event));
2417 case LIBINPUT_EVENT_POINTER_AXIS:
2418 #if !LIBINPUT_HAVE_SCROLL_VALUE_V120
2419 _device_handle_axis(device, libinput_event_get_pointer_event(event));
2422 #if LIBINPUT_HAVE_SCROLL_VALUE_V120
2423 case LIBINPUT_EVENT_POINTER_SCROLL_WHEEL:
2424 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_WHEEL);
2426 case LIBINPUT_EVENT_POINTER_SCROLL_FINGER:
2427 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_FINGER);
2429 case LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS:
2430 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_CONTINUOUS);
2433 case LIBINPUT_EVENT_TOUCH_DOWN:
2434 _device_handle_touch_down(device, libinput_event_get_touch_event(event));
2436 case LIBINPUT_EVENT_TOUCH_MOTION:
2437 _device_handle_touch_motion(device,
2438 libinput_event_get_touch_event(event));
2440 case LIBINPUT_EVENT_TOUCH_UP:
2441 _device_handle_touch_up(device, libinput_event_get_touch_event(event));
2443 case LIBINPUT_EVENT_TOUCH_CANCEL:
2444 _device_handle_touch_cancel(device, libinput_event_get_touch_event(event));
2446 case LIBINPUT_EVENT_TOUCH_FRAME:
2447 _device_handle_touch_frame(device, libinput_event_get_touch_event(event));
2449 case LIBINPUT_EVENT_TOUCH_AUX_DATA:
2450 _device_handle_touch_aux_data(device, libinput_event_get_touch_aux_data(event));
2461 * @brief Set the axis size of the given device.
2463 * @param dev The device to set the axis size to.
2464 * @param w The width of the axis.
2465 * @param h The height of the axis.
2467 * This function sets set the width @p w and height @p h of the axis
2468 * of device @p dev. If @p dev is a relative input device, a width and
2469 * height must set for it. If its absolute set the ioctl correctly, if
2470 * not, unsupported device.
2473 e_input_evdev_axis_size_set(E_Input_Evdev *edev, int w, int h)
2477 enum libinput_config_status status;
2478 struct udev_device *udev_device = NULL;
2480 EINA_SAFETY_ON_NULL_RETURN(edev);
2481 EINA_SAFETY_ON_TRUE_RETURN((w == 0) || (h == 0));
2483 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
2484 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
2487 udev_device = libinput_device_get_udev_device(edev->device);
2490 ERR("no udev_device");
2494 vals = udev_device_get_property_value(udev_device, "WL_CALIBRATION");
2496 (sscanf(vals, "%f %f %f %f %f %f",
2497 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
2499 udev_device_unref(udev_device);
2502 udev_device_unref(udev_device);
2504 ELOGF("E_INPUT_EVDEV", "axis_size_set cal[%lf %lf %lf %lf %lf %lf] (%d x %d)",
2505 NULL, cal[0], cal[1], cal[2], cal[3], cal[4], cal[5], w, h);
2511 libinput_device_config_calibration_set_matrix(edev->device, cal);
2513 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
2514 ERR("Failed to apply calibration");
2517 EINTERN const char *
2518 e_input_evdev_name_get(E_Input_Evdev *evdev)
2520 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2521 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2523 return libinput_device_get_name(evdev->device);
2526 EINTERN const char *
2527 e_input_evdev_sysname_get(E_Input_Evdev *evdev)
2529 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2530 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2532 return libinput_device_get_sysname(evdev->device);
2536 e_input_evdev_key_remap_enable(E_Input_Evdev *edev, Eina_Bool enable)
2538 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2539 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2541 edev->key_remap_enabled = enable;
2543 if (enable == EINA_FALSE && edev->key_remap_hash)
2545 eina_hash_free(edev->key_remap_hash);
2546 edev->key_remap_hash = NULL;
2553 e_input_evdev_key_remap_set(E_Input_Evdev *edev, int *from_keys, int *to_keys, int num)
2557 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2558 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2559 EINA_SAFETY_ON_NULL_RETURN_VAL(from_keys, EINA_FALSE);
2560 EINA_SAFETY_ON_NULL_RETURN_VAL(to_keys, EINA_FALSE);
2561 EINA_SAFETY_ON_TRUE_RETURN_VAL(num <= 0, EINA_FALSE);
2562 EINA_SAFETY_ON_TRUE_RETURN_VAL(!edev->key_remap_enabled, EINA_FALSE);
2564 if (edev->key_remap_hash == NULL)
2565 edev->key_remap_hash = eina_hash_int32_new(NULL);
2567 if (edev->key_remap_hash == NULL)
2569 ERR("Failed to set remap key information : creating a hash is failed.");
2573 for (i = 0; i < num ; i++)
2575 if (!from_keys[i] || !to_keys[i])
2577 ERR("Failed to set remap key information : given arguments are invalid.");
2582 for (i = 0; i < num ; i++)
2584 eina_hash_add(edev->key_remap_hash, &from_keys[i], (void *)(intptr_t)to_keys[i]);
2591 e_input_evdev_wheel_click_angle_get(E_Input_Evdev *dev)
2593 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, -1);
2594 return libinput_device_config_scroll_get_wheel_click_angle(dev->device);
2598 e_input_evdev_touch_calibration_set(E_Input_Evdev *edev, float matrix[6])
2600 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2601 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2603 if (!libinput_device_config_calibration_has_matrix(edev->device) ||
2604 !libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_TOUCH))
2607 if (libinput_device_config_calibration_set_matrix(edev->device, matrix) !=
2608 LIBINPUT_CONFIG_STATUS_SUCCESS)
2610 WRN("Failed to set input transformation about device: %s\n",
2611 libinput_device_get_name(edev->device));
2619 e_input_evdev_mouse_accel_speed_set(E_Input_Evdev *edev, double speed)
2621 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2622 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2624 if (!libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
2627 if (!libinput_device_config_accel_is_available(edev->device))
2630 if (libinput_device_config_accel_set_speed(edev->device, speed) !=
2631 LIBINPUT_CONFIG_STATUS_SUCCESS)
2633 WRN("Failed to set mouse accel about device: %s\n",
2634 libinput_device_get_name(edev->device));
2641 EINTERN unsigned int
2642 e_input_evdev_touch_pressed_get(E_Input_Evdev *edev)
2644 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, 0x0);
2646 return edev->touch.pressed;
2650 e_input_evdev_seatname_get(E_Input_Evdev *evdev)
2652 struct libinput_seat *libinput_seat;
2653 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2654 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2656 libinput_seat = libinput_device_get_seat(evdev->device);
2658 return libinput_seat_get_logical_name(libinput_seat);
2662 e_input_evdev_seatname_set(E_Input_Evdev *evdev, const char *seatname)
2664 Eina_Bool res = EINA_FALSE;
2665 E_Input_Backend *input;
2667 EINA_SAFETY_ON_NULL_RETURN_VAL(seatname, EINA_FALSE);
2668 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, EINA_FALSE);
2669 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, EINA_FALSE);
2671 if (libinput_device_set_seat_logical_name(evdev->device, seatname) == 0)
2673 input = evdev->seat->input;
2674 if (!input) return EINA_FALSE;
2676 if (libinput_dispatch(input->libinput) != 0)
2678 ERR("Failed to dispatch libinput events: %m");
2683 /* process pending events */
2684 _input_events_process(input);