2 #include "e_input_private.h"
4 static void _device_modifiers_update(E_Input_Evdev *edev);
5 static void _device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, int *w, int *h);
6 static void _device_output_assign(E_Input_Evdev *edev, E_Input_Seat_Capabilities cap);
9 _device_calibration_set(E_Input_Evdev *edev)
14 E_Comp_Config *comp_conf;
16 if (e_comp->e_comp_screen->num_outputs > 1) //multiple outputs
18 comp_conf = e_comp_config_get();
19 if (comp_conf && (comp_conf->input_output_assign_policy == 1)) //use output-assignment policy
21 _device_output_assign(edev, E_INPUT_SEAT_POINTER);
22 _device_output_assign(edev, E_INPUT_SEAT_TOUCH);
26 output = e_comp_screen_primary_output_get(e_comp->e_comp_screen);
27 e_output_size_get(output, &w, &h);
31 edev->mouse.minx = edev->mouse.miny = 0;
35 if (libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
37 edev->seat->ptr.dx = (double)(w / 2);
38 edev->seat->ptr.dy = (double)(h / 2);
39 edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
40 edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
41 edev->mouse.dx = edev->seat->ptr.dx;
42 edev->mouse.dy = edev->seat->ptr.dy;
44 if (output->config.rotation == 90 || output->config.rotation == 270)
46 temp = edev->mouse.minx;
47 edev->mouse.minx = edev->mouse.miny;
48 edev->mouse.miny = temp;
50 temp = edev->mouse.maxw;
51 edev->mouse.maxw = edev->mouse.maxh;
52 edev->mouse.maxh = temp;
58 #ifdef _F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
64 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
65 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
68 sysname = libinput_device_get_sysname(edev->device);
70 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
71 if (eina_list_count(devices) < 1) return;
73 #ifdef _F_E_INPUT_USE_WL_CALIBRATION_
75 enum libinput_config_status status;
77 EINA_LIST_FREE(devices, device)
79 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
81 (sscanf(vals, "%f %f %f %f %f %f",
82 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
89 libinput_device_config_calibration_set_matrix(edev->device, cal);
91 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
92 ERR("Failed to apply calibration");
95 eina_stringshare_del(device);
98 #endif//_F_E_INPUT_USE_WL_CALIBRATION_
99 #endif//_F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
104 _device_output_assign(E_Input_Evdev *edev, E_Input_Seat_Capabilities cap)
109 Eina_Bool need_assign_output = EINA_FALSE;
110 const char *output_name;
113 if (!(edev->caps & cap)) return;
114 if (edev->output_name) return; //already assigned
115 if (e_comp->e_comp_screen->num_outputs <= 1) return;
117 last_output_idx = e_comp->e_comp_screen->num_outputs - 1;
118 EINA_LIST_FOREACH(edev->seat->devices, l, ed)
120 if (!(ed->caps & cap)) continue;
121 if (ed == edev) continue;
124 need_assign_output = EINA_FALSE;
127 need_assign_output = EINA_TRUE;
129 if (need_assign_output)
131 output = e_output_find_by_index(last_output_idx);
132 if (!output->info.connected) return;
133 output_name = e_output_output_id_get(output);
134 if (output_name) edev->output_name = eina_stringshare_add(output_name);
135 ELOGF("E_INPUT_EVDEV", "Device is assigned to output:%s", NULL, output_name);
140 _device_touch_count_update(E_Input_Evdev *edev)
142 unsigned int device_touch_count = 0;
143 static unsigned int _max_device_touch_count = 0;
145 E_Input *ei = e_input_get();
146 EINA_SAFETY_ON_NULL_RETURN(ei);
148 device_touch_count = libinput_device_touch_get_touch_count(edev->device);
150 if (_max_device_touch_count < device_touch_count)
151 _max_device_touch_count = device_touch_count;
153 if (e_config->configured_max_touch.use)
155 if (_max_device_touch_count > 0 && e_config->configured_max_touch.count > _max_device_touch_count)
157 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",
158 NULL, e_config->configured_max_touch.count, _max_device_touch_count, _max_device_touch_count);
159 ei->touch_max_count = _max_device_touch_count;
163 if (ei->touch_max_count != e_config->configured_max_touch.count)
165 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch_max_count has been updated to %d -> %d.\n",
166 NULL, ei->touch_max_count, e_config->configured_max_touch.count);
167 ei->touch_max_count = e_config->configured_max_touch.count;
173 if (ei->touch_max_count < _max_device_touch_count)
175 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch_max_count has been updated to %d -> %d.\n", NULL,
176 ei->touch_max_count, _max_device_touch_count);
177 ei->touch_max_count = _max_device_touch_count;
181 ei->touch_device_count++;
182 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch device count is %d.\n", NULL, ei->touch_device_count);
186 _device_configure(E_Input_Evdev *edev)
188 if (libinput_device_config_tap_get_finger_count(edev->device) > 0)
190 Eina_Bool tap = EINA_FALSE;
192 tap = libinput_device_config_tap_get_default_enabled(edev->device);
193 libinput_device_config_tap_set_enabled(edev->device, tap);
196 _device_calibration_set(edev);
200 _device_keyboard_setup(E_Input_Evdev *edev)
202 E_Input_Backend *input;
203 xkb_mod_index_t xkb_idx;
205 if ((!edev) || (!edev->seat)) return;
206 if (!(input = edev->seat->input)) return;
207 if (!input->dev->xkb_ctx) return;
209 /* create keymap from xkb context */
210 edev->xkb.keymap = _e_input_device_cached_keymap_get(input->dev->xkb_ctx, NULL, 0);
211 if (!edev->xkb.keymap)
213 ERR("Failed to create keymap: %m");
217 /* create xkb state */
218 if (!(edev->xkb.state = xkb_state_new(edev->xkb.keymap)))
220 ERR("Failed to create xkb state: %m");
224 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CTRL);
225 if (xkb_idx != XKB_MOD_INVALID)
226 edev->xkb.ctrl_mask = 1 << xkb_idx;
228 edev->xkb.ctrl_mask = 0;
230 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_ALT);
231 if (xkb_idx != XKB_MOD_INVALID)
232 edev->xkb.alt_mask = 1 << xkb_idx;
234 edev->xkb.alt_mask = 0;
236 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_SHIFT);
237 if (xkb_idx != XKB_MOD_INVALID)
238 edev->xkb.shift_mask = 1 << xkb_idx;
240 edev->xkb.shift_mask = 0;
242 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_LOGO);
243 if (xkb_idx != XKB_MOD_INVALID)
244 edev->xkb.win_mask = 1 << xkb_idx;
246 edev->xkb.win_mask = 0;
248 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_SCROLL);
249 if (xkb_idx != XKB_MOD_INVALID)
250 edev->xkb.scroll_mask = 1 << xkb_idx;
252 edev->xkb.scroll_mask = 0;
254 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_NUM);
255 if (xkb_idx != XKB_MOD_INVALID)
256 edev->xkb.num_mask = 1 << xkb_idx;
258 edev->xkb.num_mask = 0;
260 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CAPS);
261 if (xkb_idx != XKB_MOD_INVALID)
262 edev->xkb.caps_mask = 1 << xkb_idx;
264 edev->xkb.caps_mask = 0;
266 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, "ISO_Level3_Shift");
267 if (xkb_idx != XKB_MOD_INVALID)
268 edev->xkb.altgr_mask = 1 << xkb_idx;
270 edev->xkb.altgr_mask = 0;
274 _device_keysym_translate(xkb_keysym_t keysym, unsigned int modifiers, char *buffer, int bytes)
276 unsigned long hbytes = 0;
279 if (!keysym) return 0;
280 hbytes = (keysym >> 8);
285 (((keysym >= XKB_KEY_BackSpace) && (keysym <= XKB_KEY_Clear)) ||
286 (keysym == XKB_KEY_Return) || (keysym == XKB_KEY_Escape) ||
287 (keysym == XKB_KEY_KP_Space) || (keysym == XKB_KEY_KP_Tab) ||
288 (keysym == XKB_KEY_KP_Enter) ||
289 ((keysym >= XKB_KEY_KP_Multiply) && (keysym <= XKB_KEY_KP_9)) ||
290 (keysym == XKB_KEY_KP_Equal) || (keysym == XKB_KEY_Delete))))))
293 if (keysym == XKB_KEY_KP_Space)
294 c = (XKB_KEY_space & 0x7F);
295 else if (hbytes == 0xFF)
300 if (modifiers & ECORE_EVENT_MODIFIER_CTRL)
302 if (((c >= '@') && (c < '\177')) || c == ' ')
306 else if ((c >= '3') && (c <= '7'))
318 _device_modifiers_update_device(E_Input_Evdev *edev, E_Input_Evdev *from)
322 edev->xkb.depressed =
323 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_DEPRESSED);
325 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LATCHED);
327 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LOCKED);
329 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_EFFECTIVE);
331 mask = (edev->xkb.depressed | edev->xkb.latched);
333 if (mask & from->xkb.ctrl_mask)
334 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_CTRL;
335 if (mask & from->xkb.alt_mask)
336 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALT;
337 if (mask & from->xkb.shift_mask)
338 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
339 if (mask & from->xkb.win_mask)
340 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_WIN;
341 if (mask & from->xkb.scroll_mask)
342 edev->xkb.modifiers |= ECORE_EVENT_LOCK_SCROLL;
343 if (mask & from->xkb.num_mask)
344 edev->xkb.modifiers |= ECORE_EVENT_LOCK_NUM;
345 if (mask & from->xkb.caps_mask)
346 edev->xkb.modifiers |= ECORE_EVENT_LOCK_CAPS;
347 if (mask & from->xkb.altgr_mask)
348 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALTGR;
352 _device_modifiers_update(E_Input_Evdev *edev)
357 edev->xkb.modifiers = 0;
359 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
360 _device_modifiers_update_device(edev, edev);
363 EINA_LIST_FOREACH(edev->seat->devices, l, ed)
365 if (!(ed->caps & E_INPUT_SEAT_KEYBOARD)) continue;
366 _device_modifiers_update_device(edev, ed);
373 _device_remapped_key_get(E_Input_Evdev *edev, int code)
377 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, code);
378 if (!edev->key_remap_enabled) return code;
379 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->key_remap_hash, code);
381 ret = eina_hash_find(edev->key_remap_hash, &code);
383 if (ret) code = (int)(intptr_t)ret;
389 e_input_evdev_get_ecore_device(const char *path, Ecore_Device_Class clas)
391 const Eina_List *dev_list = NULL;
393 Ecore_Device *dev = NULL;
394 const char *identifier;
396 if (!path) return NULL;
398 dev_list = ecore_device_list();
399 if (!dev_list) return NULL;
400 EINA_LIST_FOREACH(dev_list, l, dev)
403 identifier = ecore_device_identifier_get(dev);
404 if (!identifier) continue;
405 if ((ecore_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
412 _e_input_event_mouse_move_cb_free(void *data EINA_UNUSED, void *event)
414 Ecore_Event_Mouse_Move *ev = event;
416 if (ev->dev) ecore_device_unref(ev->dev);
422 _e_input_event_mouse_wheel_cb_free(void *data EINA_UNUSED, void *event)
424 Ecore_Event_Mouse_Wheel *ev = event;
426 if (ev->dev) ecore_device_unref(ev->dev);
432 _e_input_event_mouse_button_cb_free(void *data EINA_UNUSED, void *event)
434 Ecore_Event_Mouse_Button *ev = event;
436 if (ev->dev) ecore_device_unref(ev->dev);
442 _e_input_event_key_cb_free(void *data EINA_UNUSED, void *event)
444 Ecore_Event_Key *ev = event;
446 if (ev->dev) ecore_device_unref(ev->dev);
447 if (ev->data) E_FREE(ev->data);
453 _device_handle_key(struct libinput_device *device, struct libinput_event_keyboard *event)
456 E_Input_Backend *input;
458 uint32_t code, nsyms;
459 const xkb_keysym_t *syms;
460 enum libinput_key_state state;
462 xkb_keysym_t sym = XKB_KEY_NoSymbol;
463 char key[256] = {0, }, keyname[256] = {0, }, compose_buffer[256] = {0, };
465 char *tmp = NULL, *compose = NULL;
466 E_Keyrouter_Event_Data *key_data;
467 Ecore_Device *ecore_dev = NULL, *data;
468 Eina_List *l, *l_next;
469 E_Comp_Config *comp_conf = NULL;
470 int *pressed_keycode = NULL, *idata = NULL;
471 Eina_Bool dup_found = EINA_FALSE;
473 if (!(edev = libinput_device_get_user_data(device)))
478 if (!(input = edev->seat->input))
483 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
484 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
486 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
488 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_KEYBOARD)
497 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
498 ecore_dev = edev->ecore_dev;
503 ERR("Failed to get source ecore device from event !\n");
507 timestamp = libinput_event_keyboard_get_time(event);
508 code = libinput_event_keyboard_get_key(event);
509 code = _device_remapped_key_get(edev, code + 8);
510 state = libinput_event_keyboard_get_key_state(event);
511 key_count = libinput_event_keyboard_get_seat_key_count(event);
513 if (state == LIBINPUT_KEY_STATE_PRESSED)
515 if ((edev->seat->dev->blocked & E_INPUT_SEAT_KEYBOARD) ||
516 (edev->seat->dev->server_blocked & E_INPUT_SEAT_KEYBOARD))
518 ELOGF("Key", "Press (keycode: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
519 code, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
520 edev->seat->dev->server_blocked);
524 /* FIXME: Currently to maintain press/release event pair during input block,
525 * used Eina_List and this is method used in devicemgr module.
526 * But we need to consider which way is better to maintain key press/release pair.
529 EINA_LIST_FOREACH(edev->xkb.pressed_keys, l, idata)
533 dup_found = EINA_TRUE;
539 pressed_keycode = E_NEW(int, 1);
540 EINA_SAFETY_ON_NULL_RETURN(pressed_keycode);
541 *pressed_keycode = code;
543 edev->xkb.pressed_keys = eina_list_append(edev->xkb.pressed_keys, pressed_keycode);
548 dup_found = EINA_FALSE;
549 EINA_LIST_FOREACH_SAFE(edev->xkb.pressed_keys, l, l_next, idata)
553 edev->xkb.pressed_keys = eina_list_remove_list(edev->xkb.pressed_keys, l);
555 dup_found = EINA_TRUE;
561 ELOGF("Key", "Release (keycode: %d, device: %s) is blocked by %p", NULL,
562 code, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client);
567 /* ignore key events that are not seat wide state changes */
568 if (((state == LIBINPUT_KEY_STATE_PRESSED) && (key_count != 1)) ||
569 ((state == LIBINPUT_KEY_STATE_RELEASED) && (key_count != 0)))
574 xkb_state_update_key(edev->xkb.state, code,
575 (state ? XKB_KEY_DOWN : XKB_KEY_UP));
577 /* get the keysym for this code */
578 nsyms = xkb_key_get_syms(edev->xkb.state, code, &syms);
579 if (nsyms == 1) sym = syms[0];
581 /* If no keysym was found, name it "Keycode-NNN" */
582 if (sym == XKB_KEY_NoSymbol)
583 snprintf(key, sizeof(key), "Keycode-%u", code);
586 /* get the keyname for this sym */
587 xkb_keysym_get_name(sym, key, sizeof(key));
592 /* If no keyname was found, name it "Keycode-NNN" */
593 snprintf(keyname, sizeof(keyname), "Keycode-%u", code);
597 memcpy(keyname, key, sizeof(keyname));
600 /* if shift is active, we need to transform the key to lower */
601 if (xkb_state_mod_index_is_active(edev->xkb.state,
602 xkb_map_mod_get_index(edev->xkb.keymap,
604 XKB_STATE_MODS_EFFECTIVE))
606 if (keyname[0] != '\0')
607 keyname[0] = tolower(keyname[0]);
610 if (_device_keysym_translate(sym, edev->xkb.modifiers,
611 compose_buffer, sizeof(compose_buffer)))
613 compose = eina_str_convert("ISO8859-1", "UTF-8", compose_buffer);
616 ERR("E Input cannot convert input key string '%s' to UTF-8. "
617 "Is Eina built with iconv support?", compose_buffer);
623 if (!compose) compose = compose_buffer;
625 e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) +
626 ((compose[0] != '\0') ? strlen(compose) : 0) + 3);
632 key_data = E_NEW(E_Keyrouter_Event_Data, 1);
640 e->keyname = (char *)(e + 1);
641 e->key = e->keyname + strlen(keyname) + 1;
642 e->compose = strlen(compose) ? e->key + strlen(key) + 1 : NULL;
643 e->string = e->compose;
645 strncpy((char *)e->keyname, keyname, strlen(keyname));
646 strncpy((char *)e->key, key, strlen(key));
647 if (strlen(compose)) strncpy((char *)e->compose, compose, strlen(compose));
649 e->window = (Ecore_Window)input->dev->window;
650 e->event_window = (Ecore_Window)input->dev->window;
651 e->root_window = (Ecore_Window)input->dev->window;
652 e->timestamp = timestamp;
657 _device_modifiers_update(edev);
659 e->modifiers = edev->xkb.modifiers;
660 e->dev = ecore_device_ref(ecore_dev);
662 comp_conf = e_comp_config_get();
663 if (comp_conf && comp_conf->input_log_enable)
664 ELOGF("Key", "%s (keyname: %s, keycode: %d, device: %s)", NULL, state?"Press":"Release", e->keyname, e->keycode, ecore_device_name_get(e->dev));
667 ecore_event_add(ECORE_EVENT_KEY_DOWN, e, _e_input_event_key_cb_free, NULL);
669 ecore_event_add(ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
675 _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event)
677 E_Input_Backend *input;
678 Ecore_Event_Mouse_Move *ev;
679 Ecore_Device *ecore_dev = NULL, *data, *detent_data = NULL;
681 int x = 0, y = 0, w = 0, h = 0;
683 if (!(input = edev->seat->input)) return;
685 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
686 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
688 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
690 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
695 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
700 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
702 ecore_dev = detent_data;
707 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
708 ecore_dev = edev->ecore_dev;
713 ERR("Failed to get source ecore device from event !\n");
716 else if ((detent_data == ecore_dev) || e_devicemgr_detent_is_detent(ecore_device_name_get(ecore_dev)))
718 /* Do not process detent device's move events. */
722 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
724 _device_configured_size_get(edev, &x, &y, &w, &h);
726 if (edev->seat->ptr.ix < x)
727 edev->seat->ptr.dx = edev->seat->ptr.ix = x;
728 else if (edev->seat->ptr.ix >= (x + w))
729 edev->seat->ptr.dx = edev->seat->ptr.ix = (x + w - 1);
731 if (edev->seat->ptr.iy < y)
732 edev->seat->ptr.dy = edev->seat->ptr.iy = y;
733 else if (edev->seat->ptr.iy >= (y + h))
734 edev->seat->ptr.dy = edev->seat->ptr.iy = (y + h - 1);
736 edev->mouse.dx = edev->seat->ptr.dx;
737 edev->mouse.dy = edev->seat->ptr.dy;
739 ev->window = (Ecore_Window)input->dev->window;
740 ev->event_window = (Ecore_Window)input->dev->window;
741 ev->root_window = (Ecore_Window)input->dev->window;
742 if (event) ev->timestamp = libinput_event_pointer_get_time(event);
745 _device_modifiers_update(edev);
746 ev->modifiers = edev->xkb.modifiers;
748 ev->x = edev->seat->ptr.ix;
749 ev->y = edev->seat->ptr.iy;
753 ev->multi.device = edev->mt_slot;
754 ev->multi.radius = 1;
755 ev->multi.radius_x = 1;
756 ev->multi.radius_y = 1;
757 ev->multi.pressure = 1.0;
758 ev->multi.angle = 0.0;
761 ev->multi.root.x = ev->x;
762 ev->multi.root.y = ev->y;
763 ev->dev = ecore_device_ref(ecore_dev);
765 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
769 _e_input_pointer_motion_post(E_Input_Evdev *edev)
771 _device_pointer_motion(edev, NULL);
775 _device_handle_pointer_motion(struct libinput_device *device, struct libinput_event_pointer *event)
780 if (!(edev = libinput_device_get_user_data(device)))
785 dx = libinput_event_pointer_get_dx(event);
786 dy = libinput_event_pointer_get_dy(event);
788 if (edev->seat->ptr.swap)
794 if (edev->seat->ptr.invert_x)
796 if (edev->seat->ptr.invert_y)
799 edev->seat->ptr.dx += dx;
800 edev->seat->ptr.dy += dy;
802 edev->mouse.dx = edev->seat->ptr.dx;
803 edev->mouse.dy = edev->seat->ptr.dy;
805 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
806 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
811 edev->seat->ptr.ix = edev->seat->ptr.dx;
812 edev->seat->ptr.iy = edev->seat->ptr.dy;
814 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
815 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
820 _device_pointer_motion(edev, event);
824 _device_handle_pointer_motion_absolute(struct libinput_device *device, struct libinput_event_pointer *event)
829 if (!(edev = libinput_device_get_user_data(device)))
834 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
836 edev->mouse.dx = edev->seat->ptr.dx =
837 libinput_event_pointer_get_absolute_x_transformed(event, w);
838 edev->mouse.dy = edev->seat->ptr.dy =
839 libinput_event_pointer_get_absolute_y_transformed(event, h);
841 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
842 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
847 edev->seat->ptr.ix = edev->seat->ptr.dx;
848 edev->seat->ptr.iy = edev->seat->ptr.dy;
850 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
851 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
856 _device_pointer_motion(edev, event);
860 _device_handle_button(struct libinput_device *device, struct libinput_event_pointer *event)
863 E_Input_Backend *input;
864 Ecore_Event_Mouse_Button *ev;
865 enum libinput_button_state state;
866 uint32_t button, timestamp;
867 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
869 E_Comp_Config *comp_conf = NULL;
871 if (!(edev = libinput_device_get_user_data(device)))
875 if (!(input = edev->seat->input))
880 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
881 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
883 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
885 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
890 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
895 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
897 ecore_dev = detent_data;
902 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
903 ecore_dev = edev->ecore_dev;
908 ERR("Failed to get source ecore device from event !\n");
912 state = libinput_event_pointer_get_button_state(event);
913 button = libinput_event_pointer_get_button(event);
914 timestamp = libinput_event_pointer_get_time(event);
916 button = ((button & 0x00F) + 1);
917 if (button == 3) button = 2;
918 else if (button == 2) button = 3;
922 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
923 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
925 ELOGF("Mouse", "Button Press (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
926 button, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
927 edev->seat->dev->server_blocked);
932 edev->mouse.pressed_button |= (1 << button);
937 if (!(edev->mouse.pressed_button & (1 << button)))
939 ELOGF("Mouse", "Button Release (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
940 button, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
941 edev->seat->dev->server_blocked);
944 edev->mouse.pressed_button &= ~(1 << button);
947 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button))))
952 ev->window = (Ecore_Window)input->dev->window;
953 ev->event_window = (Ecore_Window)input->dev->window;
954 ev->root_window = (Ecore_Window)input->dev->window;
955 ev->timestamp = timestamp;
958 _device_modifiers_update(edev);
959 ev->modifiers = edev->xkb.modifiers;
961 ev->x = edev->seat->ptr.ix;
962 ev->y = edev->seat->ptr.iy;
966 ev->multi.device = edev->mt_slot;
967 ev->multi.radius = 1;
968 ev->multi.radius_x = 1;
969 ev->multi.radius_y = 1;
970 ev->multi.pressure = 1.0;
971 ev->multi.angle = 0.0;
974 ev->multi.root.x = ev->x;
975 ev->multi.root.y = ev->y;
976 ev->dev = ecore_device_ref(ecore_dev);
980 unsigned int current;
983 edev->mouse.did_double = EINA_FALSE;
984 edev->mouse.did_triple = EINA_FALSE;
986 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
987 (button == edev->mouse.prev_button))
989 edev->mouse.did_double = EINA_TRUE;
990 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
991 (button == edev->mouse.last_button))
993 edev->mouse.did_triple = EINA_TRUE;
994 edev->mouse.prev = 0;
995 edev->mouse.last = 0;
1000 edev->mouse.last = edev->mouse.prev;
1001 edev->mouse.prev = current;
1002 edev->mouse.last_button = edev->mouse.prev_button;
1003 edev->mouse.prev_button = button;
1006 ev->buttons = button;
1008 if (edev->mouse.did_double)
1009 ev->double_click = 1;
1010 if (edev->mouse.did_triple)
1011 ev->triple_click = 1;
1013 comp_conf = e_comp_config_get();
1014 if (comp_conf && comp_conf->input_log_enable)
1015 ELOGF("Mouse", "Button %s (btn: %d, device: %s)", NULL, state?"Press":"Release", button, ecore_device_name_get(ev->dev));
1018 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, _e_input_event_mouse_button_cb_free, NULL);
1020 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, _e_input_event_mouse_button_cb_free, NULL);
1024 _device_handle_axis(struct libinput_device *device, struct libinput_event_pointer *event)
1026 E_Input_Evdev *edev;
1027 E_Input_Backend *input;
1028 Ecore_Event_Mouse_Wheel *ev;
1030 enum libinput_pointer_axis axis;
1031 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1033 E_Comp_Config *comp_conf = NULL;
1034 int direction = 0, z = 0;
1036 if (!(edev = libinput_device_get_user_data(device)))
1040 if (!(input = edev->seat->input))
1045 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1046 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1048 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1050 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1055 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1060 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1062 ecore_dev = detent_data;
1067 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1068 ecore_dev = edev->ecore_dev;
1073 ERR("Failed to get source ecore device from event !\n");
1077 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1078 if (libinput_event_pointer_has_axis(event, axis))
1079 z = libinput_event_pointer_get_axis_value_discrete(event, axis);
1081 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1082 if (libinput_event_pointer_has_axis(event, axis))
1085 z = libinput_event_pointer_get_axis_value_discrete(event, axis);
1088 comp_conf = e_comp_config_get();
1089 if (comp_conf && comp_conf->e_wheel_click_angle)
1091 z = (int)(z * comp_conf->e_wheel_click_angle);
1094 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1095 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1098 ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1099 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1101 ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1102 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1106 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1111 timestamp = libinput_event_pointer_get_time(event);
1113 ev->window = (Ecore_Window)input->dev->window;
1114 ev->event_window = (Ecore_Window)input->dev->window;
1115 ev->root_window = (Ecore_Window)input->dev->window;
1116 ev->timestamp = timestamp;
1117 ev->same_screen = 1;
1119 _device_modifiers_update(edev);
1120 ev->modifiers = edev->xkb.modifiers;
1122 ev->x = edev->seat->ptr.ix;
1123 ev->y = edev->seat->ptr.iy;
1126 ev->dev = ecore_device_ref(ecore_dev);
1129 ev->direction = direction;
1131 if (comp_conf && comp_conf->input_log_enable)
1134 ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1136 ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1139 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1143 _device_handle_touch_event_send(E_Input_Evdev *edev, struct libinput_event_touch *event, int state)
1145 E_Input_Backend *input;
1146 Ecore_Event_Mouse_Button *ev;
1147 uint32_t timestamp, button = 0;
1148 Ecore_Device *ecore_dev = NULL, *data;
1152 if (!(input = edev->seat->input)) return;
1154 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1155 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1157 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1159 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1168 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1169 ecore_dev = edev->ecore_dev;
1174 ERR("Failed to get source ecore device from event !\n");
1178 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) return;
1180 timestamp = libinput_event_touch_get_time(event);
1182 ev->window = (Ecore_Window)input->dev->window;
1183 ev->event_window = (Ecore_Window)input->dev->window;
1184 ev->root_window = (Ecore_Window)input->dev->window;
1185 ev->timestamp = timestamp;
1186 ev->same_screen = 1;
1188 _device_modifiers_update(edev);
1189 ev->modifiers = edev->xkb.modifiers;
1191 ev->x = edev->seat->ptr.ix;
1192 ev->y = edev->seat->ptr.iy;
1196 ev->multi.device = edev->mt_slot;
1197 ev->multi.radius = 1;
1198 ev->multi.radius_x = 1;
1199 ev->multi.radius_y = 1;
1200 ev->multi.pressure = 1.0;
1201 ev->multi.angle = 0.0;
1202 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1203 if (libinput_event_get_type(libinput_event_touch_get_base_event(event))
1204 == LIBINPUT_EVENT_TOUCH_DOWN)
1206 if (libinput_event_touch_has_minor(event))
1207 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1208 if (libinput_event_touch_has_major(event))
1209 ev->multi.radius_y = libinput_event_touch_get_major(event);
1210 if (libinput_event_touch_has_pressure(event))
1211 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1212 if (libinput_event_touch_has_orientation(event))
1213 ev->multi.angle = libinput_event_touch_get_orientation(event);
1216 ev->multi.x = ev->x;
1217 ev->multi.y = ev->y;
1218 ev->multi.root.x = ev->x;
1219 ev->multi.root.y = ev->y;
1220 ev->dev = ecore_device_ref(ecore_dev);
1222 if (state == ECORE_EVENT_MOUSE_BUTTON_DOWN)
1224 unsigned int current;
1226 current = timestamp;
1227 edev->mouse.did_double = EINA_FALSE;
1228 edev->mouse.did_triple = EINA_FALSE;
1230 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1231 (button == edev->mouse.prev_button))
1233 edev->mouse.did_double = EINA_TRUE;
1234 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1235 (button == edev->mouse.last_button))
1237 edev->mouse.did_triple = EINA_TRUE;
1238 edev->mouse.prev = 0;
1239 edev->mouse.last = 0;
1244 edev->mouse.last = edev->mouse.prev;
1245 edev->mouse.prev = current;
1246 edev->mouse.last_button = edev->mouse.prev_button;
1247 edev->mouse.prev_button = button;
1248 edev->touch.pressed |= (1 << ev->multi.device);
1252 edev->touch.pressed &= ~(1 << ev->multi.device);
1255 ev->buttons = ((button & 0x00F) + 1);
1257 if (edev->mouse.did_double)
1258 ev->double_click = 1;
1259 if (edev->mouse.did_triple)
1260 ev->triple_click = 1;
1262 ecore_event_add(state, ev, _e_input_event_mouse_button_cb_free, NULL);
1266 _device_handle_touch_motion_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1268 E_Input_Backend *input;
1269 Ecore_Event_Mouse_Move *ev;
1270 Ecore_Device *ecore_dev = NULL, *data;
1274 if (!(input = edev->seat->input)) return;
1276 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1277 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1279 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1281 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1290 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1291 ecore_dev = edev->ecore_dev;
1296 ERR("Failed to get source ecore device from event !\n");
1300 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
1302 ev->window = (Ecore_Window)input->dev->window;
1303 ev->event_window = (Ecore_Window)input->dev->window;
1304 ev->root_window = (Ecore_Window)input->dev->window;
1305 ev->timestamp = libinput_event_touch_get_time(event);
1306 ev->same_screen = 1;
1308 _device_modifiers_update(edev);
1309 ev->modifiers = edev->xkb.modifiers;
1311 ev->x = edev->seat->ptr.ix;
1312 ev->y = edev->seat->ptr.iy;
1316 ev->multi.device = edev->mt_slot;
1317 ev->multi.radius = 1;
1318 ev->multi.radius_x = 1;
1319 ev->multi.radius_y = 1;
1320 ev->multi.pressure = 1.0;
1321 ev->multi.angle = 0.0;
1322 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1323 if (libinput_event_touch_has_minor(event))
1324 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1325 if (libinput_event_touch_has_major(event))
1326 ev->multi.radius_y = libinput_event_touch_get_major(event);
1327 if (libinput_event_touch_has_pressure(event))
1328 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1329 if (libinput_event_touch_has_orientation(event))
1330 ev->multi.angle = libinput_event_touch_get_orientation(event);
1332 ev->multi.x = ev->x;
1333 ev->multi.y = ev->y;
1334 ev->multi.root.x = ev->x;
1335 ev->multi.root.y = ev->y;
1336 ev->dev = ecore_device_ref(ecore_dev);
1338 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
1342 _device_handle_touch_cancel_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1344 E_Input_Backend *input;
1345 Ecore_Event_Mouse_Button *ev;
1346 uint32_t timestamp, button = 0;
1347 Ecore_Device *ecore_dev = NULL, *data;
1351 if (!(input = edev->seat->input)) return;
1353 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1354 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1356 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1358 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1367 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1368 ecore_dev = edev->ecore_dev;
1373 ERR("Failed to get source ecore device from event !\n");
1377 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) return;
1379 timestamp = libinput_event_touch_get_time(event);
1381 ev->window = (Ecore_Window)input->dev->window;
1382 ev->event_window = (Ecore_Window)input->dev->window;
1383 ev->root_window = (Ecore_Window)input->dev->window;
1384 ev->timestamp = timestamp;
1385 ev->same_screen = 1;
1387 ev->x = edev->seat->ptr.ix;
1388 ev->y = edev->seat->ptr.iy;
1392 ev->multi.device = edev->mt_slot;
1393 ev->multi.radius = 1;
1394 ev->multi.radius_x = 1;
1395 ev->multi.radius_y = 1;
1396 ev->multi.pressure = 1.0;
1397 ev->multi.angle = 0.0;
1398 ev->multi.x = ev->x;
1399 ev->multi.y = ev->y;
1400 ev->multi.root.x = ev->x;
1401 ev->multi.root.y = ev->y;
1402 ev->dev = ecore_device_ref(ecore_dev);
1404 edev->touch.pressed &= ~(1 << ev->multi.device);
1406 ev->buttons = ((button & 0x00F) + 1);
1408 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev, _e_input_event_mouse_button_cb_free, NULL);
1412 _device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, int *w, int *h)
1414 E_Output *output = NULL;
1416 EINA_SAFETY_ON_NULL_RETURN(edev);
1418 if (!edev->output_configured)
1420 if (edev->output_name)
1422 output = e_output_find(edev->output_name);
1425 edev->mouse.minx = output->config.geom.x;
1426 edev->mouse.miny = output->config.geom.y;
1427 edev->mouse.maxw = output->config.geom.w;
1428 edev->mouse.maxh = output->config.geom.h;
1429 if (libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
1431 edev->seat->ptr.dx = (double)(edev->mouse.maxw / 2);
1432 edev->seat->ptr.dy = (double)(edev->mouse.maxh / 2);
1433 edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
1434 edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
1435 edev->mouse.dx = edev->seat->ptr.dx;
1436 edev->mouse.dy = edev->seat->ptr.dy;
1441 edev->output_configured = EINA_TRUE;
1442 ELOGF("E_INPUT_EVDEV", "Device is configured by output x:%d,y:%d (w:%d, h:%d)",
1443 NULL, edev->mouse.minx, edev->mouse.miny, edev->mouse.maxw, edev->mouse.maxh);
1445 if (x) *x = edev->mouse.minx;
1446 if (y) *y = edev->mouse.miny;
1447 if (w) *w = edev->mouse.maxw;
1448 if (h) *h = edev->mouse.maxh;
1452 _device_handle_touch_down(struct libinput_device *device, struct libinput_event_touch *event)
1454 E_Input_Evdev *edev;
1455 int x = 0, y = 0, w = 0, h = 0;
1456 E_Comp_Config *comp_conf = NULL;
1458 if (!(edev = libinput_device_get_user_data(device)))
1463 _device_configured_size_get(edev, &x, &y, &w, &h);
1465 edev->mouse.dx = edev->seat->ptr.ix = edev->seat->ptr.dx =
1466 x + libinput_event_touch_get_x_transformed(event, w);
1467 edev->mouse.dy = edev->seat->ptr.iy = edev->seat->ptr.dy =
1468 y + libinput_event_touch_get_y_transformed(event, h);
1470 edev->mt_slot = libinput_event_touch_get_slot(event);
1471 if (edev->mt_slot < 0)
1473 /* FIXME: The single touch device return slot id -1
1474 * But currently we have no API to distinguish multi touch or single touch
1475 * After libinput 1.11 version, libinput provides get_touch_count API,
1476 * so we can distinguish multi touch device or single touch device.
1478 if (edev->mt_slot == -1)
1482 WRN("%d slot touch down events are not supported\n", edev->mt_slot);
1487 if (edev->mt_slot < e_input_touch_max_count_get())
1489 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
1490 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
1493 comp_conf = e_comp_config_get();
1494 if (comp_conf && comp_conf->input_log_enable)
1495 ELOGF("Touch", "Down (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
1497 edev->touch.raw_pressed |= (1 << edev->mt_slot);
1499 if (edev->touch.blocked)
1501 ELOGF("Touch", "Down (id: %d, x: %d, y: %d) is blocked by %p, server: 0x%x", NULL,
1502 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, edev->seat->dev->blocked_client,
1503 edev->seat->dev->server_blocked);
1507 _device_handle_touch_motion_send(edev, event);
1508 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_DOWN);
1512 _device_handle_touch_motion(struct libinput_device *device, struct libinput_event_touch *event)
1514 E_Input_Evdev *edev;
1515 int x = 0, y = 0, w = 0, h = 0;
1517 if (!(edev = libinput_device_get_user_data(device)))
1522 _device_configured_size_get(edev, &x, &y, &w, &h);
1524 edev->mouse.dx = edev->seat->ptr.dx =
1525 x + libinput_event_touch_get_x_transformed(event, w);
1526 edev->mouse.dy = edev->seat->ptr.dy =
1527 y + libinput_event_touch_get_y_transformed(event, h);
1529 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
1530 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
1535 edev->seat->ptr.ix = edev->seat->ptr.dx;
1536 edev->seat->ptr.iy = edev->seat->ptr.dy;
1538 edev->mt_slot = libinput_event_touch_get_slot(event);
1539 if (edev->mt_slot < 0)
1541 /* FIXME: The single touch device return slot id -1
1542 * But currently we have no API to distinguish multi touch or single touch
1543 * After libinput 1.11 version, libinput provides get_touch_count API,
1544 * so we can distinguish multi touch device or single touch device.
1546 if (edev->mt_slot == -1)
1550 WRN("%d slot touch motion events are not supported\n", edev->mt_slot);
1555 if (edev->mt_slot < e_input_touch_max_count_get())
1557 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
1558 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
1561 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
1563 if (edev->touch.blocked)
1569 _device_handle_touch_motion_send(edev, event);
1573 _device_handle_touch_up(struct libinput_device *device, struct libinput_event_touch *event)
1575 E_Input_Evdev *edev;
1576 E_Comp_Config *comp_conf = NULL;
1578 if (!(edev = libinput_device_get_user_data(device)))
1583 edev->mt_slot = libinput_event_touch_get_slot(event);
1584 if (edev->mt_slot < 0)
1586 /* FIXME: The single touch device return slot id -1
1587 * But currently we have no API to distinguish multi touch or single touch
1588 * After libinput 1.11 version, libinput provides get_touch_count API,
1589 * so we can distinguish multi touch device or single touch device.
1591 if (edev->mt_slot == -1)
1595 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
1600 if (edev->mt_slot < e_input_touch_max_count_get())
1602 edev->mouse.dx = edev->seat->ptr.dx = edev->seat->ptr.ix =
1603 edev->touch.coords[edev->mt_slot].x;
1604 edev->mouse.dy = edev->seat->ptr.dy = edev->seat->ptr.iy =
1605 edev->touch.coords[edev->mt_slot].y;
1608 comp_conf = e_comp_config_get();
1609 if (comp_conf && comp_conf->input_log_enable)
1610 ELOGF("Touch", "Up (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
1612 edev->touch.raw_pressed &= ~(1 << edev->mt_slot);
1614 if (edev->touch.blocked)
1616 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
1618 ELOGF("Touch", "Up (id: %d, x: %d, y: %d) is blocked by %p, server(0x%x)", NULL,
1619 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, edev->seat->dev->blocked_client,
1620 edev->seat->dev->server_blocked);
1621 if (edev->touch.raw_pressed == 0x0)
1623 edev->touch.blocked = EINA_FALSE;
1629 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_UP);
1633 _device_handle_touch_cancel(struct libinput_device *device, struct libinput_event_touch *event)
1635 E_Input_Evdev *edev;
1636 E_Comp_Config *comp_conf = NULL;
1638 if (!(edev = libinput_device_get_user_data(device)))
1643 edev->mt_slot = libinput_event_touch_get_slot(event);
1644 if (edev->mt_slot < 0)
1646 /* FIXME: The single touch device return slot id -1
1647 * But currently we have no API to distinguish multi touch or single touch
1648 * After libinput 1.11 version, libinput provides get_touch_count API,
1649 * so we can distinguish multi touch device or single touch device.
1651 if (edev->mt_slot == -1)
1655 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
1660 comp_conf = e_comp_config_get();
1661 if (comp_conf && comp_conf->input_log_enable)
1662 ELOGF("Touch", "cancel (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
1664 _device_handle_touch_cancel_send(edev, event);
1669 _device_handle_touch_frame(struct libinput_device *device EINA_UNUSED, struct libinput_event_touch *event EINA_UNUSED)
1671 /* DBG("Unhandled Touch Frame Event"); */
1675 _e_input_aux_data_event_free(void *user_data EINA_UNUSED, void *ev)
1677 Ecore_Event_Axis_Update *e = (Ecore_Event_Axis_Update *)ev;
1679 if (e->axis) free(e->axis);
1680 if (e->dev) ecore_device_unref(e->dev);
1686 _device_handle_touch_aux_data(struct libinput_device *device, struct libinput_event_touch_aux_data *event)
1688 E_Input_Evdev *edev;
1689 E_Input_Backend *input;
1690 Ecore_Event_Axis_Update *ev;
1692 Ecore_Device *ecore_dev = NULL, *data;
1694 E_Comp_Config *comp_conf;
1696 if (libinput_event_touch_aux_data_get_type(event) != LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM &&
1697 libinput_event_touch_aux_data_get_value(event) > 0)
1700 if (!(edev = libinput_device_get_user_data(device))) goto end;
1701 if (!(input = edev->seat->input)) goto end;
1703 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1704 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1706 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1708 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1717 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1718 ecore_dev = edev->ecore_dev;
1723 ERR("Failed to get source ecore device from event !\n");
1727 if (!(ev = calloc(1, sizeof(Ecore_Event_Axis_Update))))goto end;
1729 ev->window = (Ecore_Window)input->dev->window;
1730 ev->event_window = (Ecore_Window)input->dev->window;
1731 ev->root_window = (Ecore_Window)input->dev->window;
1732 ev->timestamp = libinput_event_touch_aux_data_get_time(event);
1734 axis = (Ecore_Axis *)calloc(1, sizeof(Ecore_Axis));
1737 axis->label = ECORE_AXIS_LABEL_TOUCH_PALM;
1738 axis->value = libinput_event_touch_aux_data_get_value(event);
1742 ev->dev = ecore_device_ref(ecore_dev);
1744 comp_conf = e_comp_config_get();
1745 if (comp_conf && comp_conf->input_log_enable)
1746 ELOGF("Touch", "Axis (label: %d, value: %lf)", NULL, axis?axis->label:-1, axis?axis->value:0.0);
1748 ecore_event_add(ECORE_EVENT_AXIS_UPDATE, ev, _e_input_aux_data_event_free, NULL);
1755 _e_input_evdev_device_create(E_Input_Seat *seat, struct libinput_device *device)
1757 E_Input_Evdev *edev;
1758 E_Input_Backend *b_input;
1759 const char *output_name;
1761 EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
1763 /* try to allocate space for new evdev */
1764 if (!(edev = calloc(1, sizeof(E_Input_Evdev)))) return NULL;
1767 edev->device = device;
1768 edev->path = eina_stringshare_printf("%s/%s", e_input_base_dir_get(), libinput_device_get_sysname(device));
1770 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
1772 edev->caps |= E_INPUT_SEAT_KEYBOARD;
1773 _device_keyboard_setup(edev);
1776 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
1778 edev->caps |= E_INPUT_SEAT_POINTER;
1780 /* TODO: make this configurable */
1781 edev->mouse.threshold = 250;
1783 b_input = seat->input;
1784 if (b_input->left_handed == EINA_TRUE)
1786 if (libinput_device_config_left_handed_set(device, 1) !=
1787 LIBINPUT_CONFIG_STATUS_SUCCESS)
1789 WRN("Failed to set left hand mode about device: %s\n",
1790 libinput_device_get_name(device));
1795 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
1798 edev->caps |= E_INPUT_SEAT_TOUCH;
1799 palm_code = libinput_device_touch_aux_data_get_code(LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM);
1800 if (libinput_device_touch_has_aux_data(device, palm_code))
1802 libinput_device_touch_set_aux_data(device, palm_code);
1805 _device_touch_count_update(edev);
1807 edev->touch.coords = calloc(1, sizeof(E_Input_Coord)*e_input_touch_max_count_get());
1809 if (!edev->touch.coords)
1810 ERR("Failed to allocate memory for touch coords !\n");
1813 output_name = libinput_device_get_output_name(device);
1816 eina_stringshare_replace(&edev->output_name, output_name);
1817 ELOGF("E_INPUT_EVDEV", "Device has output_name:%s", NULL, output_name);
1820 libinput_device_set_user_data(device, edev);
1821 libinput_device_ref(device);
1823 /* configure device */
1824 _device_configure(edev);
1830 _e_input_evdev_device_destroy(E_Input_Evdev *edev)
1834 EINA_SAFETY_ON_NULL_RETURN(edev);
1836 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
1838 if (edev->xkb.state) xkb_state_unref(edev->xkb.state);
1839 if (edev->xkb.keymap) xkb_map_unref(edev->xkb.keymap);
1842 if (edev->ecore_dev) ecore_device_del(edev->ecore_dev);
1843 if (edev->ecore_dev_list)
1844 EINA_LIST_FREE(edev->ecore_dev_list, dev)
1846 ecore_device_del(dev);
1848 if (edev->path) eina_stringshare_del(edev->path);
1849 if (edev->device) libinput_device_unref(edev->device);
1850 if (edev->key_remap_hash) eina_hash_free(edev->key_remap_hash);
1851 if (edev->touch.coords)
1853 free(edev->touch.coords);
1854 edev->touch.coords = NULL;
1856 eina_stringshare_del(edev->output_name);
1862 _e_input_evdev_event_process(struct libinput_event *event)
1864 struct libinput_device *device;
1865 Eina_Bool ret = EINA_TRUE;
1867 device = libinput_event_get_device(event);
1868 switch (libinput_event_get_type(event))
1870 case LIBINPUT_EVENT_KEYBOARD_KEY:
1871 _device_handle_key(device, libinput_event_get_keyboard_event(event));
1873 case LIBINPUT_EVENT_POINTER_MOTION:
1874 _device_handle_pointer_motion(device,
1875 libinput_event_get_pointer_event(event));
1877 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
1878 _device_handle_pointer_motion_absolute(device,
1879 libinput_event_get_pointer_event(event));
1881 case LIBINPUT_EVENT_POINTER_BUTTON:
1882 _device_handle_button(device, libinput_event_get_pointer_event(event));
1884 case LIBINPUT_EVENT_POINTER_AXIS:
1885 _device_handle_axis(device, libinput_event_get_pointer_event(event));
1887 case LIBINPUT_EVENT_TOUCH_DOWN:
1888 _device_handle_touch_down(device, libinput_event_get_touch_event(event));
1890 case LIBINPUT_EVENT_TOUCH_MOTION:
1891 _device_handle_touch_motion(device,
1892 libinput_event_get_touch_event(event));
1894 case LIBINPUT_EVENT_TOUCH_UP:
1895 _device_handle_touch_up(device, libinput_event_get_touch_event(event));
1897 case LIBINPUT_EVENT_TOUCH_CANCEL:
1898 _device_handle_touch_cancel(device, libinput_event_get_touch_event(event));
1900 case LIBINPUT_EVENT_TOUCH_FRAME:
1901 _device_handle_touch_frame(device, libinput_event_get_touch_event(event));
1903 case LIBINPUT_EVENT_TOUCH_AUX_DATA:
1904 _device_handle_touch_aux_data(device, libinput_event_get_touch_aux_data(event));
1915 * @brief Set the axis size of the given device.
1917 * @param dev The device to set the axis size to.
1918 * @param w The width of the axis.
1919 * @param h The height of the axis.
1921 * This function sets set the width @p w and height @p h of the axis
1922 * of device @p dev. If @p dev is a relative input device, a width and
1923 * height must set for it. If its absolute set the ioctl correctly, if
1924 * not, unsupported device.
1927 e_input_evdev_axis_size_set(E_Input_Evdev *edev, int w, int h)
1929 const char *sysname;
1934 enum libinput_config_status status;
1936 EINA_SAFETY_ON_NULL_RETURN(edev);
1937 EINA_SAFETY_ON_TRUE_RETURN((w == 0) || (h == 0));
1939 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
1940 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
1943 sysname = libinput_device_get_sysname(edev->device);
1945 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
1946 if (eina_list_count(devices) < 1) return;
1948 EINA_LIST_FREE(devices, device)
1950 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
1952 (sscanf(vals, "%f %f %f %f %f %f",
1953 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
1960 libinput_device_config_calibration_set_matrix(edev->device, cal);
1962 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
1963 ERR("Failed to apply calibration");
1966 eina_stringshare_del(device);
1972 e_input_evdev_name_get(E_Input_Evdev *evdev)
1974 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
1975 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
1977 return libinput_device_get_name(evdev->device);
1980 EINTERN const char *
1981 e_input_evdev_sysname_get(E_Input_Evdev *evdev)
1983 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
1984 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
1986 return libinput_device_get_sysname(evdev->device);
1990 e_input_evdev_key_remap_enable(E_Input_Evdev *edev, Eina_Bool enable)
1992 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
1993 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
1995 edev->key_remap_enabled = enable;
1997 if (enable == EINA_FALSE && edev->key_remap_hash)
1999 eina_hash_free(edev->key_remap_hash);
2000 edev->key_remap_hash = NULL;
2007 e_input_evdev_key_remap_set(E_Input_Evdev *edev, int *from_keys, int *to_keys, int num)
2011 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2012 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2013 EINA_SAFETY_ON_NULL_RETURN_VAL(from_keys, EINA_FALSE);
2014 EINA_SAFETY_ON_NULL_RETURN_VAL(to_keys, EINA_FALSE);
2015 EINA_SAFETY_ON_TRUE_RETURN_VAL(num <= 0, EINA_FALSE);
2016 EINA_SAFETY_ON_TRUE_RETURN_VAL(!edev->key_remap_enabled, EINA_FALSE);
2018 if (edev->key_remap_hash == NULL)
2019 edev->key_remap_hash = eina_hash_int32_new(NULL);
2021 if (edev->key_remap_hash == NULL)
2023 ERR("Failed to set remap key information : creating a hash is failed.");
2027 for (i = 0; i < num ; i++)
2029 if (!from_keys[i] || !to_keys[i])
2031 ERR("Failed to set remap key information : given arguments are invalid.");
2036 for (i = 0; i < num ; i++)
2038 eina_hash_add(edev->key_remap_hash, &from_keys[i], (void *)(intptr_t)to_keys[i]);
2045 e_input_evdev_wheel_click_angle_get(E_Input_Evdev *dev)
2047 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, -1);
2048 return libinput_device_config_scroll_get_wheel_click_angle(dev->device);
2052 e_input_evdev_touch_calibration_set(E_Input_Evdev *edev, float matrix[6])
2054 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2055 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2057 if (!libinput_device_config_calibration_has_matrix(edev->device) ||
2058 !libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_TOUCH))
2061 if (libinput_device_config_calibration_set_matrix(edev->device, matrix) !=
2062 LIBINPUT_CONFIG_STATUS_SUCCESS)
2064 WRN("Failed to set input transformation about device: %s\n",
2065 libinput_device_get_name(edev->device));
2073 e_input_evdev_mouse_accel_speed_set(E_Input_Evdev *edev, double speed)
2075 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2076 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2078 if (!libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
2081 if (!libinput_device_config_accel_is_available(edev->device))
2084 if (libinput_device_config_accel_set_speed(edev->device, speed) !=
2085 LIBINPUT_CONFIG_STATUS_SUCCESS)
2087 WRN("Failed to set mouse accel about device: %s\n",
2088 libinput_device_get_name(edev->device));
2095 EINTERN unsigned int
2096 e_input_evdev_touch_pressed_get(E_Input_Evdev *edev)
2098 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, 0x0);
2100 return edev->touch.pressed;
2104 e_input_evdev_seatname_get(E_Input_Evdev *evdev)
2106 struct libinput_seat *libinput_seat;
2107 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2108 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2110 libinput_seat = libinput_device_get_seat(evdev->device);
2112 return libinput_seat_get_logical_name(libinput_seat);
2116 e_input_evdev_seatname_set(E_Input_Evdev *evdev, const char *seatname)
2118 Eina_Bool res = EINA_FALSE;
2119 E_Input_Backend *input;
2121 EINA_SAFETY_ON_NULL_RETURN_VAL(seatname, EINA_FALSE);
2122 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, EINA_FALSE);
2123 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, EINA_FALSE);
2125 if (libinput_device_set_seat_logical_name(evdev->device, seatname) == 0)
2127 input = evdev->seat->input;
2128 if (!input) return EINA_FALSE;
2129 if (libinput_dispatch(input->libinput) != 0)
2131 ERR("Failed to dispatch libinput events: %m");
2135 /* process pending events */
2136 _input_events_process(input);