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);
8 _device_calibration_set(E_Input_Evdev *edev)
13 const char *output_name;
15 output_name = libinput_device_get_output_name(edev->device);
18 E_FREE(edev->output_name);
19 edev->output_name = strdup(output_name);
20 ELOGF("E_INPUT_EVDEV", "Device has output_name:%s", NULL, output_name);
23 output = e_comp_screen_primary_output_get(e_comp->e_comp_screen);
24 e_output_size_get(output, &w, &h);
28 edev->mouse.minx = edev->mouse.miny = 0;
32 if (libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
34 edev->seat->ptr.dx = (double)(w / 2);
35 edev->seat->ptr.dy = (double)(h / 2);
36 edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
37 edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
38 edev->mouse.dx = edev->seat->ptr.dx;
39 edev->mouse.dy = edev->seat->ptr.dy;
41 if (output->config.rotation == 90 || output->config.rotation == 270)
43 temp = edev->mouse.minx;
44 edev->mouse.minx = edev->mouse.miny;
45 edev->mouse.miny = temp;
47 temp = edev->mouse.maxw;
48 edev->mouse.maxw = edev->mouse.maxh;
49 edev->mouse.maxh = temp;
55 #ifdef _F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
61 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
62 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
65 sysname = libinput_device_get_sysname(edev->device);
67 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
68 if (eina_list_count(devices) < 1) return;
70 #ifdef _F_E_INPUT_USE_WL_CALIBRATION_
72 enum libinput_config_status status;
74 EINA_LIST_FREE(devices, device)
76 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
78 (sscanf(vals, "%f %f %f %f %f %f",
79 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
86 libinput_device_config_calibration_set_matrix(edev->device, cal);
88 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
89 ERR("Failed to apply calibration");
92 eina_stringshare_del(device);
95 #endif//_F_E_INPUT_USE_WL_CALIBRATION_
96 #endif//_F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
101 _device_touch_count_update(E_Input_Evdev *edev)
103 unsigned int device_touch_count = 0;
104 static unsigned int _max_device_touch_count = 0;
106 E_Input *ei = e_input_get();
107 EINA_SAFETY_ON_NULL_RETURN(ei);
109 device_touch_count = libinput_device_touch_get_touch_count(edev->device);
111 if (_max_device_touch_count < device_touch_count)
112 _max_device_touch_count = device_touch_count;
114 if (e_config->configured_max_touch.use)
116 if (_max_device_touch_count > 0 && e_config->configured_max_touch.count > _max_device_touch_count)
118 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",
119 NULL, e_config->configured_max_touch.count, _max_device_touch_count, _max_device_touch_count);
120 ei->touch_max_count = _max_device_touch_count;
124 if (ei->touch_max_count != e_config->configured_max_touch.count)
126 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch_max_count has been updated to %d -> %d.\n",
127 NULL, ei->touch_max_count, e_config->configured_max_touch.count);
128 ei->touch_max_count = e_config->configured_max_touch.count;
134 if (ei->touch_max_count < _max_device_touch_count)
136 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch_max_count has been updated to %d -> %d.\n", NULL,
137 ei->touch_max_count, _max_device_touch_count);
138 ei->touch_max_count = _max_device_touch_count;
142 ei->touch_device_count++;
143 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch device count is %d.\n", NULL, ei->touch_device_count);
147 _device_configure(E_Input_Evdev *edev)
149 if (libinput_device_config_tap_get_finger_count(edev->device) > 0)
151 Eina_Bool tap = EINA_FALSE;
153 tap = libinput_device_config_tap_get_default_enabled(edev->device);
154 libinput_device_config_tap_set_enabled(edev->device, tap);
157 _device_calibration_set(edev);
161 _device_keyboard_setup(E_Input_Evdev *edev)
163 E_Input_Backend *input;
164 xkb_mod_index_t xkb_idx;
166 if ((!edev) || (!edev->seat)) return;
167 if (!(input = edev->seat->input)) return;
168 if (!input->dev->xkb_ctx) return;
170 /* create keymap from xkb context */
171 edev->xkb.keymap = _e_input_device_cached_keymap_get(input->dev->xkb_ctx, NULL, 0);
172 if (!edev->xkb.keymap)
174 ERR("Failed to create keymap: %m");
178 /* create xkb state */
179 if (!(edev->xkb.state = xkb_state_new(edev->xkb.keymap)))
181 ERR("Failed to create xkb state: %m");
185 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CTRL);
186 if (xkb_idx != XKB_MOD_INVALID)
187 edev->xkb.ctrl_mask = 1 << xkb_idx;
189 edev->xkb.ctrl_mask = 0;
191 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_ALT);
192 if (xkb_idx != XKB_MOD_INVALID)
193 edev->xkb.alt_mask = 1 << xkb_idx;
195 edev->xkb.alt_mask = 0;
197 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_SHIFT);
198 if (xkb_idx != XKB_MOD_INVALID)
199 edev->xkb.shift_mask = 1 << xkb_idx;
201 edev->xkb.shift_mask = 0;
203 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_LOGO);
204 if (xkb_idx != XKB_MOD_INVALID)
205 edev->xkb.win_mask = 1 << xkb_idx;
207 edev->xkb.win_mask = 0;
209 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_SCROLL);
210 if (xkb_idx != XKB_MOD_INVALID)
211 edev->xkb.scroll_mask = 1 << xkb_idx;
213 edev->xkb.scroll_mask = 0;
215 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_NUM);
216 if (xkb_idx != XKB_MOD_INVALID)
217 edev->xkb.num_mask = 1 << xkb_idx;
219 edev->xkb.num_mask = 0;
221 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CAPS);
222 if (xkb_idx != XKB_MOD_INVALID)
223 edev->xkb.caps_mask = 1 << xkb_idx;
225 edev->xkb.caps_mask = 0;
227 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, "ISO_Level3_Shift");
228 if (xkb_idx != XKB_MOD_INVALID)
229 edev->xkb.altgr_mask = 1 << xkb_idx;
231 edev->xkb.altgr_mask = 0;
235 _device_keysym_translate(xkb_keysym_t keysym, unsigned int modifiers, char *buffer, int bytes)
237 unsigned long hbytes = 0;
240 if (!keysym) return 0;
241 hbytes = (keysym >> 8);
246 (((keysym >= XKB_KEY_BackSpace) && (keysym <= XKB_KEY_Clear)) ||
247 (keysym == XKB_KEY_Return) || (keysym == XKB_KEY_Escape) ||
248 (keysym == XKB_KEY_KP_Space) || (keysym == XKB_KEY_KP_Tab) ||
249 (keysym == XKB_KEY_KP_Enter) ||
250 ((keysym >= XKB_KEY_KP_Multiply) && (keysym <= XKB_KEY_KP_9)) ||
251 (keysym == XKB_KEY_KP_Equal) || (keysym == XKB_KEY_Delete))))))
254 if (keysym == XKB_KEY_KP_Space)
255 c = (XKB_KEY_space & 0x7F);
256 else if (hbytes == 0xFF)
261 if (modifiers & ECORE_EVENT_MODIFIER_CTRL)
263 if (((c >= '@') && (c < '\177')) || c == ' ')
267 else if ((c >= '3') && (c <= '7'))
279 _device_modifiers_update_device(E_Input_Evdev *edev, E_Input_Evdev *from)
283 edev->xkb.depressed =
284 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_DEPRESSED);
286 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LATCHED);
288 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LOCKED);
290 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_EFFECTIVE);
292 mask = (edev->xkb.depressed | edev->xkb.latched);
294 if (mask & from->xkb.ctrl_mask)
295 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_CTRL;
296 if (mask & from->xkb.alt_mask)
297 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALT;
298 if (mask & from->xkb.shift_mask)
299 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
300 if (mask & from->xkb.win_mask)
301 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_WIN;
302 if (mask & from->xkb.scroll_mask)
303 edev->xkb.modifiers |= ECORE_EVENT_LOCK_SCROLL;
304 if (mask & from->xkb.num_mask)
305 edev->xkb.modifiers |= ECORE_EVENT_LOCK_NUM;
306 if (mask & from->xkb.caps_mask)
307 edev->xkb.modifiers |= ECORE_EVENT_LOCK_CAPS;
308 if (mask & from->xkb.altgr_mask)
309 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALTGR;
313 _device_modifiers_update(E_Input_Evdev *edev)
318 edev->xkb.modifiers = 0;
320 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
321 _device_modifiers_update_device(edev, edev);
324 EINA_LIST_FOREACH(edev->seat->devices, l, ed)
326 if (!(ed->caps & E_INPUT_SEAT_KEYBOARD)) continue;
327 _device_modifiers_update_device(edev, ed);
334 _device_remapped_key_get(E_Input_Evdev *edev, int code)
338 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, code);
339 if (!edev->key_remap_enabled) return code;
340 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->key_remap_hash, code);
342 ret = eina_hash_find(edev->key_remap_hash, &code);
344 if (ret) code = (int)(intptr_t)ret;
350 e_input_evdev_get_ecore_device(const char *path, Ecore_Device_Class clas)
352 const Eina_List *dev_list = NULL;
354 Ecore_Device *dev = NULL;
355 const char *identifier;
357 if (!path) return NULL;
359 dev_list = ecore_device_list();
360 if (!dev_list) return NULL;
361 EINA_LIST_FOREACH(dev_list, l, dev)
364 identifier = ecore_device_identifier_get(dev);
365 if (!identifier) continue;
366 if ((ecore_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
373 _e_input_event_mouse_move_cb_free(void *data EINA_UNUSED, void *event)
375 Ecore_Event_Mouse_Move *ev = event;
377 if (ev->dev) ecore_device_unref(ev->dev);
383 _e_input_event_mouse_wheel_cb_free(void *data EINA_UNUSED, void *event)
385 Ecore_Event_Mouse_Wheel *ev = event;
387 if (ev->dev) ecore_device_unref(ev->dev);
393 _e_input_event_mouse_button_cb_free(void *data EINA_UNUSED, void *event)
395 Ecore_Event_Mouse_Button *ev = event;
397 if (ev->dev) ecore_device_unref(ev->dev);
403 _e_input_event_key_cb_free(void *data EINA_UNUSED, void *event)
405 Ecore_Event_Key *ev = event;
407 if (ev->dev) ecore_device_unref(ev->dev);
408 if (ev->data) E_FREE(ev->data);
414 _device_handle_key(struct libinput_device *device, struct libinput_event_keyboard *event)
417 E_Input_Backend *input;
419 uint32_t code, nsyms;
420 const xkb_keysym_t *syms;
421 enum libinput_key_state state;
423 xkb_keysym_t sym = XKB_KEY_NoSymbol;
424 char key[256] = {0, }, keyname[256] = {0, }, compose_buffer[256] = {0, };
426 char *tmp = NULL, *compose = NULL;
427 E_Keyrouter_Event_Data *key_data;
428 Ecore_Device *ecore_dev = NULL, *data;
429 Eina_List *l, *l_next;
430 E_Comp_Config *comp_conf = NULL;
431 int *pressed_keycode = NULL, *idata = NULL;
432 Eina_Bool dup_found = EINA_FALSE;
434 if (!(edev = libinput_device_get_user_data(device)))
439 if (!(input = edev->seat->input))
444 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
445 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
447 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
449 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_KEYBOARD)
458 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
459 ecore_dev = edev->ecore_dev;
464 ERR("Failed to get source ecore device from event !\n");
468 timestamp = libinput_event_keyboard_get_time(event);
469 code = libinput_event_keyboard_get_key(event);
470 code = _device_remapped_key_get(edev, code + 8);
471 state = libinput_event_keyboard_get_key_state(event);
472 key_count = libinput_event_keyboard_get_seat_key_count(event);
474 if (state == LIBINPUT_KEY_STATE_PRESSED)
476 if ((edev->seat->dev->blocked & E_INPUT_SEAT_KEYBOARD) ||
477 (edev->seat->dev->server_blocked & E_INPUT_SEAT_KEYBOARD))
479 ELOGF("Key", "Press (keycode: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
480 code, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
481 edev->seat->dev->server_blocked);
485 /* FIXME: Currently to maintain press/release event pair during input block,
486 * used Eina_List and this is method used in devicemgr module.
487 * But we need to consider which way is better to maintain key press/release pair.
490 EINA_LIST_FOREACH(edev->xkb.pressed_keys, l, idata)
494 dup_found = EINA_TRUE;
500 pressed_keycode = E_NEW(int, 1);
501 EINA_SAFETY_ON_NULL_RETURN(pressed_keycode);
502 *pressed_keycode = code;
504 edev->xkb.pressed_keys = eina_list_append(edev->xkb.pressed_keys, pressed_keycode);
509 dup_found = EINA_FALSE;
510 EINA_LIST_FOREACH_SAFE(edev->xkb.pressed_keys, l, l_next, idata)
514 edev->xkb.pressed_keys = eina_list_remove_list(edev->xkb.pressed_keys, l);
516 dup_found = EINA_TRUE;
522 ELOGF("Key", "Release (keycode: %d, device: %s) is blocked by %p", NULL,
523 code, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client);
528 /* ignore key events that are not seat wide state changes */
529 if (((state == LIBINPUT_KEY_STATE_PRESSED) && (key_count != 1)) ||
530 ((state == LIBINPUT_KEY_STATE_RELEASED) && (key_count != 0)))
535 xkb_state_update_key(edev->xkb.state, code,
536 (state ? XKB_KEY_DOWN : XKB_KEY_UP));
538 /* get the keysym for this code */
539 nsyms = xkb_key_get_syms(edev->xkb.state, code, &syms);
540 if (nsyms == 1) sym = syms[0];
542 /* If no keysym was found, name it "Keycode-NNN" */
543 if (sym == XKB_KEY_NoSymbol)
544 snprintf(key, sizeof(key), "Keycode-%u", code);
547 /* get the keyname for this sym */
548 xkb_keysym_get_name(sym, key, sizeof(key));
553 /* If no keyname was found, name it "Keycode-NNN" */
554 snprintf(keyname, sizeof(keyname), "Keycode-%u", code);
558 memcpy(keyname, key, sizeof(keyname));
561 /* if shift is active, we need to transform the key to lower */
562 if (xkb_state_mod_index_is_active(edev->xkb.state,
563 xkb_map_mod_get_index(edev->xkb.keymap,
565 XKB_STATE_MODS_EFFECTIVE))
567 if (keyname[0] != '\0')
568 keyname[0] = tolower(keyname[0]);
571 if (_device_keysym_translate(sym, edev->xkb.modifiers,
572 compose_buffer, sizeof(compose_buffer)))
574 compose = eina_str_convert("ISO8859-1", "UTF-8", compose_buffer);
577 ERR("E Input cannot convert input key string '%s' to UTF-8. "
578 "Is Eina built with iconv support?", compose_buffer);
584 if (!compose) compose = compose_buffer;
586 e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) +
587 ((compose[0] != '\0') ? strlen(compose) : 0) + 3);
593 key_data = E_NEW(E_Keyrouter_Event_Data, 1);
601 e->keyname = (char *)(e + 1);
602 e->key = e->keyname + strlen(keyname) + 1;
603 e->compose = strlen(compose) ? e->key + strlen(key) + 1 : NULL;
604 e->string = e->compose;
606 strncpy((char *)e->keyname, keyname, strlen(keyname));
607 strncpy((char *)e->key, key, strlen(key));
608 if (strlen(compose)) strncpy((char *)e->compose, compose, strlen(compose));
610 e->window = (Ecore_Window)input->dev->window;
611 e->event_window = (Ecore_Window)input->dev->window;
612 e->root_window = (Ecore_Window)input->dev->window;
613 e->timestamp = timestamp;
618 _device_modifiers_update(edev);
620 e->modifiers = edev->xkb.modifiers;
621 e->dev = ecore_device_ref(ecore_dev);
623 comp_conf = e_comp_config_get();
624 if (comp_conf && comp_conf->input_log_enable)
625 ELOGF("Key", "%s (keyname: %s, keycode: %d, device: %s)", NULL, state?"Press":"Release", e->keyname, e->keycode, ecore_device_name_get(e->dev));
628 ecore_event_add(ECORE_EVENT_KEY_DOWN, e, _e_input_event_key_cb_free, NULL);
630 ecore_event_add(ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
636 _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event)
638 E_Input_Backend *input;
639 Ecore_Event_Mouse_Move *ev;
640 Ecore_Device *ecore_dev = NULL, *data, *detent_data = NULL;
642 int x = 0, y = 0, w = 0, h = 0;
644 if (!(input = edev->seat->input)) return;
646 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
647 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
649 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
651 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
656 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
661 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
663 ecore_dev = detent_data;
668 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
669 ecore_dev = edev->ecore_dev;
674 ERR("Failed to get source ecore device from event !\n");
677 else if ((detent_data == ecore_dev) || e_devicemgr_detent_is_detent(ecore_device_name_get(ecore_dev)))
679 /* Do not process detent device's move events. */
683 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
685 _device_configured_size_get(edev, &x, &y, &w, &h);
687 if (edev->seat->ptr.ix < x)
688 edev->seat->ptr.dx = edev->seat->ptr.ix = x;
689 else if (edev->seat->ptr.ix >= (x + w))
690 edev->seat->ptr.dx = edev->seat->ptr.ix = (x + w - 1);
692 if (edev->seat->ptr.iy < y)
693 edev->seat->ptr.dy = edev->seat->ptr.iy = y;
694 else if (edev->seat->ptr.iy >= (y + h))
695 edev->seat->ptr.dy = edev->seat->ptr.iy = (y + h - 1);
697 edev->mouse.dx = edev->seat->ptr.dx;
698 edev->mouse.dy = edev->seat->ptr.dy;
700 ev->window = (Ecore_Window)input->dev->window;
701 ev->event_window = (Ecore_Window)input->dev->window;
702 ev->root_window = (Ecore_Window)input->dev->window;
703 if (event) ev->timestamp = libinput_event_pointer_get_time(event);
706 _device_modifiers_update(edev);
707 ev->modifiers = edev->xkb.modifiers;
709 ev->x = edev->seat->ptr.ix;
710 ev->y = edev->seat->ptr.iy;
714 ev->multi.device = edev->mt_slot;
715 ev->multi.radius = 1;
716 ev->multi.radius_x = 1;
717 ev->multi.radius_y = 1;
718 ev->multi.pressure = 1.0;
719 ev->multi.angle = 0.0;
722 ev->multi.root.x = ev->x;
723 ev->multi.root.y = ev->y;
724 ev->dev = ecore_device_ref(ecore_dev);
726 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
730 _e_input_pointer_motion_post(E_Input_Evdev *edev)
732 _device_pointer_motion(edev, NULL);
736 _device_handle_pointer_motion(struct libinput_device *device, struct libinput_event_pointer *event)
741 if (!(edev = libinput_device_get_user_data(device)))
746 dx = libinput_event_pointer_get_dx(event);
747 dy = libinput_event_pointer_get_dy(event);
749 if (edev->seat->ptr.swap)
755 if (edev->seat->ptr.invert_x)
757 if (edev->seat->ptr.invert_y)
760 edev->seat->ptr.dx += dx;
761 edev->seat->ptr.dy += dy;
763 edev->mouse.dx = edev->seat->ptr.dx;
764 edev->mouse.dy = edev->seat->ptr.dy;
766 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
767 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
772 edev->seat->ptr.ix = edev->seat->ptr.dx;
773 edev->seat->ptr.iy = edev->seat->ptr.dy;
775 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
776 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
781 _device_pointer_motion(edev, event);
785 _device_handle_pointer_motion_absolute(struct libinput_device *device, struct libinput_event_pointer *event)
790 if (!(edev = libinput_device_get_user_data(device)))
795 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
797 edev->mouse.dx = edev->seat->ptr.dx =
798 libinput_event_pointer_get_absolute_x_transformed(event, w);
799 edev->mouse.dy = edev->seat->ptr.dy =
800 libinput_event_pointer_get_absolute_y_transformed(event, h);
802 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
803 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
808 edev->seat->ptr.ix = edev->seat->ptr.dx;
809 edev->seat->ptr.iy = edev->seat->ptr.dy;
811 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
812 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
817 _device_pointer_motion(edev, event);
821 _device_handle_button(struct libinput_device *device, struct libinput_event_pointer *event)
824 E_Input_Backend *input;
825 Ecore_Event_Mouse_Button *ev;
826 enum libinput_button_state state;
827 uint32_t button, timestamp;
828 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
830 E_Comp_Config *comp_conf = NULL;
832 if (!(edev = libinput_device_get_user_data(device)))
836 if (!(input = edev->seat->input))
841 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
842 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
844 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
846 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
851 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
856 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
858 ecore_dev = detent_data;
863 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
864 ecore_dev = edev->ecore_dev;
869 ERR("Failed to get source ecore device from event !\n");
873 state = libinput_event_pointer_get_button_state(event);
874 button = libinput_event_pointer_get_button(event);
875 timestamp = libinput_event_pointer_get_time(event);
877 button = ((button & 0x00F) + 1);
878 if (button == 3) button = 2;
879 else if (button == 2) button = 3;
883 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
884 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
886 ELOGF("Mouse", "Button Press (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
887 button, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
888 edev->seat->dev->server_blocked);
893 edev->mouse.pressed_button |= (1 << button);
898 if (!(edev->mouse.pressed_button & (1 << button)))
900 ELOGF("Mouse", "Button Release (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
901 button, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
902 edev->seat->dev->server_blocked);
905 edev->mouse.pressed_button &= ~(1 << button);
908 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button))))
913 ev->window = (Ecore_Window)input->dev->window;
914 ev->event_window = (Ecore_Window)input->dev->window;
915 ev->root_window = (Ecore_Window)input->dev->window;
916 ev->timestamp = timestamp;
919 _device_modifiers_update(edev);
920 ev->modifiers = edev->xkb.modifiers;
922 ev->x = edev->seat->ptr.ix;
923 ev->y = edev->seat->ptr.iy;
927 ev->multi.device = edev->mt_slot;
928 ev->multi.radius = 1;
929 ev->multi.radius_x = 1;
930 ev->multi.radius_y = 1;
931 ev->multi.pressure = 1.0;
932 ev->multi.angle = 0.0;
935 ev->multi.root.x = ev->x;
936 ev->multi.root.y = ev->y;
937 ev->dev = ecore_device_ref(ecore_dev);
941 unsigned int current;
944 edev->mouse.did_double = EINA_FALSE;
945 edev->mouse.did_triple = EINA_FALSE;
947 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
948 (button == edev->mouse.prev_button))
950 edev->mouse.did_double = EINA_TRUE;
951 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
952 (button == edev->mouse.last_button))
954 edev->mouse.did_triple = EINA_TRUE;
955 edev->mouse.prev = 0;
956 edev->mouse.last = 0;
961 edev->mouse.last = edev->mouse.prev;
962 edev->mouse.prev = current;
963 edev->mouse.last_button = edev->mouse.prev_button;
964 edev->mouse.prev_button = button;
967 ev->buttons = button;
969 if (edev->mouse.did_double)
970 ev->double_click = 1;
971 if (edev->mouse.did_triple)
972 ev->triple_click = 1;
974 comp_conf = e_comp_config_get();
975 if (comp_conf && comp_conf->input_log_enable)
976 ELOGF("Mouse", "Button %s (btn: %d, device: %s)", NULL, state?"Press":"Release", button, ecore_device_name_get(ev->dev));
979 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, _e_input_event_mouse_button_cb_free, NULL);
981 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, _e_input_event_mouse_button_cb_free, NULL);
985 _device_handle_axis(struct libinput_device *device, struct libinput_event_pointer *event)
988 E_Input_Backend *input;
989 Ecore_Event_Mouse_Wheel *ev;
991 enum libinput_pointer_axis axis;
992 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
994 E_Comp_Config *comp_conf = NULL;
995 int direction = 0, z = 0;
997 if (!(edev = libinput_device_get_user_data(device)))
1001 if (!(input = edev->seat->input))
1006 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1007 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1009 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1011 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1016 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1021 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1023 ecore_dev = detent_data;
1028 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1029 ecore_dev = edev->ecore_dev;
1034 ERR("Failed to get source ecore device from event !\n");
1038 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1039 if (libinput_event_pointer_has_axis(event, axis))
1040 z = libinput_event_pointer_get_axis_value_discrete(event, axis);
1042 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1043 if (libinput_event_pointer_has_axis(event, axis))
1046 z = libinput_event_pointer_get_axis_value_discrete(event, axis);
1049 comp_conf = e_comp_config_get();
1050 if (comp_conf && comp_conf->e_wheel_click_angle)
1052 z = (int)(z * comp_conf->e_wheel_click_angle);
1055 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1056 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1059 ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1060 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1062 ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1063 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1067 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1072 timestamp = libinput_event_pointer_get_time(event);
1074 ev->window = (Ecore_Window)input->dev->window;
1075 ev->event_window = (Ecore_Window)input->dev->window;
1076 ev->root_window = (Ecore_Window)input->dev->window;
1077 ev->timestamp = timestamp;
1078 ev->same_screen = 1;
1080 _device_modifiers_update(edev);
1081 ev->modifiers = edev->xkb.modifiers;
1083 ev->x = edev->seat->ptr.ix;
1084 ev->y = edev->seat->ptr.iy;
1087 ev->dev = ecore_device_ref(ecore_dev);
1090 ev->direction = direction;
1092 if (comp_conf && comp_conf->input_log_enable)
1095 ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1097 ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1100 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1104 _device_handle_touch_event_send(E_Input_Evdev *edev, struct libinput_event_touch *event, int state)
1106 E_Input_Backend *input;
1107 Ecore_Event_Mouse_Button *ev;
1108 uint32_t timestamp, button = 0;
1109 Ecore_Device *ecore_dev = NULL, *data;
1113 if (!(input = edev->seat->input)) return;
1115 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1116 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1118 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1120 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1129 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1130 ecore_dev = edev->ecore_dev;
1135 ERR("Failed to get source ecore device from event !\n");
1139 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) return;
1141 timestamp = libinput_event_touch_get_time(event);
1143 ev->window = (Ecore_Window)input->dev->window;
1144 ev->event_window = (Ecore_Window)input->dev->window;
1145 ev->root_window = (Ecore_Window)input->dev->window;
1146 ev->timestamp = timestamp;
1147 ev->same_screen = 1;
1149 _device_modifiers_update(edev);
1150 ev->modifiers = edev->xkb.modifiers;
1152 ev->x = edev->seat->ptr.ix;
1153 ev->y = edev->seat->ptr.iy;
1157 ev->multi.device = edev->mt_slot;
1158 ev->multi.radius = 1;
1159 ev->multi.radius_x = 1;
1160 ev->multi.radius_y = 1;
1161 ev->multi.pressure = 1.0;
1162 ev->multi.angle = 0.0;
1163 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1164 if (libinput_event_get_type(libinput_event_touch_get_base_event(event))
1165 == LIBINPUT_EVENT_TOUCH_DOWN)
1167 if (libinput_event_touch_has_minor(event))
1168 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1169 if (libinput_event_touch_has_major(event))
1170 ev->multi.radius_y = libinput_event_touch_get_major(event);
1171 if (libinput_event_touch_has_pressure(event))
1172 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1173 if (libinput_event_touch_has_orientation(event))
1174 ev->multi.angle = libinput_event_touch_get_orientation(event);
1177 ev->multi.x = ev->x;
1178 ev->multi.y = ev->y;
1179 ev->multi.root.x = ev->x;
1180 ev->multi.root.y = ev->y;
1181 ev->dev = ecore_device_ref(ecore_dev);
1183 if (state == ECORE_EVENT_MOUSE_BUTTON_DOWN)
1185 unsigned int current;
1187 current = timestamp;
1188 edev->mouse.did_double = EINA_FALSE;
1189 edev->mouse.did_triple = EINA_FALSE;
1191 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1192 (button == edev->mouse.prev_button))
1194 edev->mouse.did_double = EINA_TRUE;
1195 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1196 (button == edev->mouse.last_button))
1198 edev->mouse.did_triple = EINA_TRUE;
1199 edev->mouse.prev = 0;
1200 edev->mouse.last = 0;
1205 edev->mouse.last = edev->mouse.prev;
1206 edev->mouse.prev = current;
1207 edev->mouse.last_button = edev->mouse.prev_button;
1208 edev->mouse.prev_button = button;
1209 edev->touch.pressed |= (1 << ev->multi.device);
1213 edev->touch.pressed &= ~(1 << ev->multi.device);
1216 ev->buttons = ((button & 0x00F) + 1);
1218 if (edev->mouse.did_double)
1219 ev->double_click = 1;
1220 if (edev->mouse.did_triple)
1221 ev->triple_click = 1;
1223 ecore_event_add(state, ev, _e_input_event_mouse_button_cb_free, NULL);
1227 _device_handle_touch_motion_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1229 E_Input_Backend *input;
1230 Ecore_Event_Mouse_Move *ev;
1231 Ecore_Device *ecore_dev = NULL, *data;
1235 if (!(input = edev->seat->input)) return;
1237 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1238 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1240 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1242 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1251 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1252 ecore_dev = edev->ecore_dev;
1257 ERR("Failed to get source ecore device from event !\n");
1261 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
1263 ev->window = (Ecore_Window)input->dev->window;
1264 ev->event_window = (Ecore_Window)input->dev->window;
1265 ev->root_window = (Ecore_Window)input->dev->window;
1266 ev->timestamp = libinput_event_touch_get_time(event);
1267 ev->same_screen = 1;
1269 _device_modifiers_update(edev);
1270 ev->modifiers = edev->xkb.modifiers;
1272 ev->x = edev->seat->ptr.ix;
1273 ev->y = edev->seat->ptr.iy;
1277 ev->multi.device = edev->mt_slot;
1278 ev->multi.radius = 1;
1279 ev->multi.radius_x = 1;
1280 ev->multi.radius_y = 1;
1281 ev->multi.pressure = 1.0;
1282 ev->multi.angle = 0.0;
1283 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1284 if (libinput_event_touch_has_minor(event))
1285 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1286 if (libinput_event_touch_has_major(event))
1287 ev->multi.radius_y = libinput_event_touch_get_major(event);
1288 if (libinput_event_touch_has_pressure(event))
1289 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1290 if (libinput_event_touch_has_orientation(event))
1291 ev->multi.angle = libinput_event_touch_get_orientation(event);
1293 ev->multi.x = ev->x;
1294 ev->multi.y = ev->y;
1295 ev->multi.root.x = ev->x;
1296 ev->multi.root.y = ev->y;
1297 ev->dev = ecore_device_ref(ecore_dev);
1299 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
1303 _device_handle_touch_cancel_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1305 E_Input_Backend *input;
1306 Ecore_Event_Mouse_Button *ev;
1307 uint32_t timestamp, button = 0;
1308 Ecore_Device *ecore_dev = NULL, *data;
1312 if (!(input = edev->seat->input)) return;
1314 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1315 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1317 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1319 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1328 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1329 ecore_dev = edev->ecore_dev;
1334 ERR("Failed to get source ecore device from event !\n");
1338 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) return;
1340 timestamp = libinput_event_touch_get_time(event);
1342 ev->window = (Ecore_Window)input->dev->window;
1343 ev->event_window = (Ecore_Window)input->dev->window;
1344 ev->root_window = (Ecore_Window)input->dev->window;
1345 ev->timestamp = timestamp;
1346 ev->same_screen = 1;
1348 ev->x = edev->seat->ptr.ix;
1349 ev->y = edev->seat->ptr.iy;
1353 ev->multi.device = edev->mt_slot;
1354 ev->multi.radius = 1;
1355 ev->multi.radius_x = 1;
1356 ev->multi.radius_y = 1;
1357 ev->multi.pressure = 1.0;
1358 ev->multi.angle = 0.0;
1359 ev->multi.x = ev->x;
1360 ev->multi.y = ev->y;
1361 ev->multi.root.x = ev->x;
1362 ev->multi.root.y = ev->y;
1363 ev->dev = ecore_device_ref(ecore_dev);
1365 edev->touch.pressed &= ~(1 << ev->multi.device);
1367 ev->buttons = ((button & 0x00F) + 1);
1369 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev, _e_input_event_mouse_button_cb_free, NULL);
1373 _device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, int *w, int *h)
1375 E_Output *output = NULL;
1377 EINA_SAFETY_ON_NULL_RETURN(edev);
1379 if (!edev->output_configured)
1381 if (edev->output_name)
1383 output = e_output_find(edev->output_name);
1386 edev->mouse.minx = output->config.geom.x;
1387 edev->mouse.miny = output->config.geom.y;
1388 edev->mouse.maxw = output->config.geom.w;
1389 edev->mouse.maxh = output->config.geom.h;
1390 if (libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
1392 edev->seat->ptr.dx = (double)(edev->mouse.maxw / 2);
1393 edev->seat->ptr.dy = (double)(edev->mouse.maxh / 2);
1394 edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
1395 edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
1396 edev->mouse.dx = edev->seat->ptr.dx;
1397 edev->mouse.dy = edev->seat->ptr.dy;
1402 edev->output_configured = EINA_TRUE;
1403 ELOGF("E_INPUT_EVDEV", "Device is configured by output x:%d,y:%d (w:%d, h:%d)",
1404 NULL, edev->mouse.minx, edev->mouse.miny, edev->mouse.maxw, edev->mouse.maxh);
1406 if (x) *x = edev->mouse.minx;
1407 if (y) *y = edev->mouse.miny;
1408 if (w) *w = edev->mouse.maxw;
1409 if (h) *h = edev->mouse.maxh;
1413 _device_handle_touch_down(struct libinput_device *device, struct libinput_event_touch *event)
1415 E_Input_Evdev *edev;
1416 int x = 0, y = 0, w = 0, h = 0;
1417 E_Comp_Config *comp_conf = NULL;
1419 if (!(edev = libinput_device_get_user_data(device)))
1424 _device_configured_size_get(edev, &x, &y, &w, &h);
1426 edev->mouse.dx = edev->seat->ptr.ix = edev->seat->ptr.dx =
1427 x + libinput_event_touch_get_x_transformed(event, w);
1428 edev->mouse.dy = edev->seat->ptr.iy = edev->seat->ptr.dy =
1429 y + libinput_event_touch_get_y_transformed(event, h);
1431 edev->mt_slot = libinput_event_touch_get_slot(event);
1432 if (edev->mt_slot < 0)
1434 /* FIXME: The single touch device return slot id -1
1435 * But currently we have no API to distinguish multi touch or single touch
1436 * After libinput 1.11 version, libinput provides get_touch_count API,
1437 * so we can distinguish multi touch device or single touch device.
1439 if (edev->mt_slot == -1)
1443 WRN("%d slot touch down events are not supported\n", edev->mt_slot);
1448 if (edev->mt_slot < e_input_touch_max_count_get())
1450 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
1451 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
1454 comp_conf = e_comp_config_get();
1455 if (comp_conf && comp_conf->input_log_enable)
1456 ELOGF("Touch", "Down (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
1458 edev->touch.raw_pressed |= (1 << edev->mt_slot);
1460 if (edev->touch.blocked)
1462 ELOGF("Touch", "Down (id: %d, x: %d, y: %d) is blocked by %p, server: 0x%x", NULL,
1463 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, edev->seat->dev->blocked_client,
1464 edev->seat->dev->server_blocked);
1468 _device_handle_touch_motion_send(edev, event);
1469 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_DOWN);
1473 _device_handle_touch_motion(struct libinput_device *device, struct libinput_event_touch *event)
1475 E_Input_Evdev *edev;
1476 int x = 0, y = 0, w = 0, h = 0;
1478 if (!(edev = libinput_device_get_user_data(device)))
1483 _device_configured_size_get(edev, &x, &y, &w, &h);
1485 edev->mouse.dx = edev->seat->ptr.dx =
1486 x + libinput_event_touch_get_x_transformed(event, w);
1487 edev->mouse.dy = edev->seat->ptr.dy =
1488 y + libinput_event_touch_get_y_transformed(event, h);
1490 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
1491 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
1496 edev->seat->ptr.ix = edev->seat->ptr.dx;
1497 edev->seat->ptr.iy = edev->seat->ptr.dy;
1499 edev->mt_slot = libinput_event_touch_get_slot(event);
1500 if (edev->mt_slot < 0)
1502 /* FIXME: The single touch device return slot id -1
1503 * But currently we have no API to distinguish multi touch or single touch
1504 * After libinput 1.11 version, libinput provides get_touch_count API,
1505 * so we can distinguish multi touch device or single touch device.
1507 if (edev->mt_slot == -1)
1511 WRN("%d slot touch motion events are not supported\n", edev->mt_slot);
1516 if (edev->mt_slot < e_input_touch_max_count_get())
1518 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
1519 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
1522 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
1524 if (edev->touch.blocked)
1530 _device_handle_touch_motion_send(edev, event);
1534 _device_handle_touch_up(struct libinput_device *device, struct libinput_event_touch *event)
1536 E_Input_Evdev *edev;
1537 E_Comp_Config *comp_conf = NULL;
1539 if (!(edev = libinput_device_get_user_data(device)))
1544 edev->mt_slot = libinput_event_touch_get_slot(event);
1545 if (edev->mt_slot < 0)
1547 /* FIXME: The single touch device return slot id -1
1548 * But currently we have no API to distinguish multi touch or single touch
1549 * After libinput 1.11 version, libinput provides get_touch_count API,
1550 * so we can distinguish multi touch device or single touch device.
1552 if (edev->mt_slot == -1)
1556 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
1561 if (edev->mt_slot < e_input_touch_max_count_get())
1563 edev->mouse.dx = edev->seat->ptr.dx = edev->seat->ptr.ix =
1564 edev->touch.coords[edev->mt_slot].x;
1565 edev->mouse.dy = edev->seat->ptr.dy = edev->seat->ptr.iy =
1566 edev->touch.coords[edev->mt_slot].y;
1569 comp_conf = e_comp_config_get();
1570 if (comp_conf && comp_conf->input_log_enable)
1571 ELOGF("Touch", "Up (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
1573 edev->touch.raw_pressed &= ~(1 << edev->mt_slot);
1575 if (edev->touch.blocked)
1577 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
1579 ELOGF("Touch", "Up (id: %d, x: %d, y: %d) is blocked by %p, server(0x%x)", NULL,
1580 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, edev->seat->dev->blocked_client,
1581 edev->seat->dev->server_blocked);
1582 if (edev->touch.raw_pressed == 0x0)
1584 edev->touch.blocked = EINA_FALSE;
1590 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_UP);
1594 _device_handle_touch_cancel(struct libinput_device *device, struct libinput_event_touch *event)
1596 E_Input_Evdev *edev;
1597 E_Comp_Config *comp_conf = NULL;
1599 if (!(edev = libinput_device_get_user_data(device)))
1604 edev->mt_slot = libinput_event_touch_get_slot(event);
1605 if (edev->mt_slot < 0)
1607 /* FIXME: The single touch device return slot id -1
1608 * But currently we have no API to distinguish multi touch or single touch
1609 * After libinput 1.11 version, libinput provides get_touch_count API,
1610 * so we can distinguish multi touch device or single touch device.
1612 if (edev->mt_slot == -1)
1616 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
1621 comp_conf = e_comp_config_get();
1622 if (comp_conf && comp_conf->input_log_enable)
1623 ELOGF("Touch", "cancel (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
1625 _device_handle_touch_cancel_send(edev, event);
1630 _device_handle_touch_frame(struct libinput_device *device EINA_UNUSED, struct libinput_event_touch *event EINA_UNUSED)
1632 /* DBG("Unhandled Touch Frame Event"); */
1636 _e_input_aux_data_event_free(void *user_data EINA_UNUSED, void *ev)
1638 Ecore_Event_Axis_Update *e = (Ecore_Event_Axis_Update *)ev;
1640 if (e->axis) free(e->axis);
1641 if (e->dev) ecore_device_unref(e->dev);
1647 _device_handle_touch_aux_data(struct libinput_device *device, struct libinput_event_touch_aux_data *event)
1649 E_Input_Evdev *edev;
1650 E_Input_Backend *input;
1651 Ecore_Event_Axis_Update *ev;
1653 Ecore_Device *ecore_dev = NULL, *data;
1655 E_Comp_Config *comp_conf;
1657 if (libinput_event_touch_aux_data_get_type(event) != LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM &&
1658 libinput_event_touch_aux_data_get_value(event) > 0)
1661 if (!(edev = libinput_device_get_user_data(device))) goto end;
1662 if (!(input = edev->seat->input)) goto end;
1664 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1665 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1667 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1669 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1678 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1679 ecore_dev = edev->ecore_dev;
1684 ERR("Failed to get source ecore device from event !\n");
1688 if (!(ev = calloc(1, sizeof(Ecore_Event_Axis_Update))))goto end;
1690 ev->window = (Ecore_Window)input->dev->window;
1691 ev->event_window = (Ecore_Window)input->dev->window;
1692 ev->root_window = (Ecore_Window)input->dev->window;
1693 ev->timestamp = libinput_event_touch_aux_data_get_time(event);
1695 axis = (Ecore_Axis *)calloc(1, sizeof(Ecore_Axis));
1698 axis->label = ECORE_AXIS_LABEL_TOUCH_PALM;
1699 axis->value = libinput_event_touch_aux_data_get_value(event);
1703 ev->dev = ecore_device_ref(ecore_dev);
1705 comp_conf = e_comp_config_get();
1706 if (comp_conf && comp_conf->input_log_enable)
1707 ELOGF("Touch", "Axis (label: %d, value: %lf)", NULL, axis?axis->label:-1, axis?axis->value:0.0);
1709 ecore_event_add(ECORE_EVENT_AXIS_UPDATE, ev, _e_input_aux_data_event_free, NULL);
1716 _e_input_evdev_device_create(E_Input_Seat *seat, struct libinput_device *device)
1718 E_Input_Evdev *edev;
1719 E_Input_Backend *b_input;
1721 EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
1723 /* try to allocate space for new evdev */
1724 if (!(edev = calloc(1, sizeof(E_Input_Evdev)))) return NULL;
1727 edev->device = device;
1728 edev->path = eina_stringshare_printf("%s/%s", e_input_base_dir_get(), libinput_device_get_sysname(device));
1730 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
1732 edev->caps |= E_INPUT_SEAT_KEYBOARD;
1733 _device_keyboard_setup(edev);
1736 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
1738 edev->caps |= E_INPUT_SEAT_POINTER;
1740 /* TODO: make this configurable */
1741 edev->mouse.threshold = 250;
1743 b_input = seat->input;
1744 if (b_input->left_handed == EINA_TRUE)
1746 if (libinput_device_config_left_handed_set(device, 1) !=
1747 LIBINPUT_CONFIG_STATUS_SUCCESS)
1749 WRN("Failed to set left hand mode about device: %s\n",
1750 libinput_device_get_name(device));
1755 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
1758 edev->caps |= E_INPUT_SEAT_TOUCH;
1759 palm_code = libinput_device_touch_aux_data_get_code(LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM);
1760 if (libinput_device_touch_has_aux_data(device, palm_code))
1762 libinput_device_touch_set_aux_data(device, palm_code);
1765 _device_touch_count_update(edev);
1767 edev->touch.coords = calloc(1, sizeof(E_Input_Coord)*e_input_touch_max_count_get());
1769 if (!edev->touch.coords)
1770 ERR("Failed to allocate memory for touch coords !\n");
1773 libinput_device_set_user_data(device, edev);
1774 libinput_device_ref(device);
1776 /* configure device */
1777 _device_configure(edev);
1783 _e_input_evdev_device_destroy(E_Input_Evdev *edev)
1787 EINA_SAFETY_ON_NULL_RETURN(edev);
1789 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
1791 if (edev->xkb.state) xkb_state_unref(edev->xkb.state);
1792 if (edev->xkb.keymap) xkb_map_unref(edev->xkb.keymap);
1795 if (edev->ecore_dev) ecore_device_del(edev->ecore_dev);
1796 if (edev->ecore_dev_list)
1797 EINA_LIST_FREE(edev->ecore_dev_list, dev)
1799 ecore_device_del(dev);
1801 if (edev->path) eina_stringshare_del(edev->path);
1802 if (edev->device) libinput_device_unref(edev->device);
1803 if (edev->key_remap_hash) eina_hash_free(edev->key_remap_hash);
1804 if (edev->touch.coords)
1806 free(edev->touch.coords);
1807 edev->touch.coords = NULL;
1809 E_FREE(edev->output_name);
1815 _e_input_evdev_event_process(struct libinput_event *event)
1817 struct libinput_device *device;
1818 Eina_Bool ret = EINA_TRUE;
1820 device = libinput_event_get_device(event);
1821 switch (libinput_event_get_type(event))
1823 case LIBINPUT_EVENT_KEYBOARD_KEY:
1824 _device_handle_key(device, libinput_event_get_keyboard_event(event));
1826 case LIBINPUT_EVENT_POINTER_MOTION:
1827 _device_handle_pointer_motion(device,
1828 libinput_event_get_pointer_event(event));
1830 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
1831 _device_handle_pointer_motion_absolute(device,
1832 libinput_event_get_pointer_event(event));
1834 case LIBINPUT_EVENT_POINTER_BUTTON:
1835 _device_handle_button(device, libinput_event_get_pointer_event(event));
1837 case LIBINPUT_EVENT_POINTER_AXIS:
1838 _device_handle_axis(device, libinput_event_get_pointer_event(event));
1840 case LIBINPUT_EVENT_TOUCH_DOWN:
1841 _device_handle_touch_down(device, libinput_event_get_touch_event(event));
1843 case LIBINPUT_EVENT_TOUCH_MOTION:
1844 _device_handle_touch_motion(device,
1845 libinput_event_get_touch_event(event));
1847 case LIBINPUT_EVENT_TOUCH_UP:
1848 _device_handle_touch_up(device, libinput_event_get_touch_event(event));
1850 case LIBINPUT_EVENT_TOUCH_CANCEL:
1851 _device_handle_touch_cancel(device, libinput_event_get_touch_event(event));
1853 case LIBINPUT_EVENT_TOUCH_FRAME:
1854 _device_handle_touch_frame(device, libinput_event_get_touch_event(event));
1856 case LIBINPUT_EVENT_TOUCH_AUX_DATA:
1857 _device_handle_touch_aux_data(device, libinput_event_get_touch_aux_data(event));
1868 * @brief Set the axis size of the given device.
1870 * @param dev The device to set the axis size to.
1871 * @param w The width of the axis.
1872 * @param h The height of the axis.
1874 * This function sets set the width @p w and height @p h of the axis
1875 * of device @p dev. If @p dev is a relative input device, a width and
1876 * height must set for it. If its absolute set the ioctl correctly, if
1877 * not, unsupported device.
1880 e_input_evdev_axis_size_set(E_Input_Evdev *edev, int w, int h)
1882 const char *sysname;
1887 enum libinput_config_status status;
1889 EINA_SAFETY_ON_NULL_RETURN(edev);
1890 EINA_SAFETY_ON_TRUE_RETURN((w == 0) || (h == 0));
1892 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
1893 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
1896 sysname = libinput_device_get_sysname(edev->device);
1898 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
1899 if (eina_list_count(devices) < 1) return;
1901 EINA_LIST_FREE(devices, device)
1903 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
1905 (sscanf(vals, "%f %f %f %f %f %f",
1906 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
1913 libinput_device_config_calibration_set_matrix(edev->device, cal);
1915 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
1916 ERR("Failed to apply calibration");
1919 eina_stringshare_del(device);
1925 e_input_evdev_name_get(E_Input_Evdev *evdev)
1927 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
1928 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
1930 return libinput_device_get_name(evdev->device);
1933 EINTERN const char *
1934 e_input_evdev_sysname_get(E_Input_Evdev *evdev)
1936 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
1937 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
1939 return libinput_device_get_sysname(evdev->device);
1943 e_input_evdev_key_remap_enable(E_Input_Evdev *edev, Eina_Bool enable)
1945 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
1946 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
1948 edev->key_remap_enabled = enable;
1950 if (enable == EINA_FALSE && edev->key_remap_hash)
1952 eina_hash_free(edev->key_remap_hash);
1953 edev->key_remap_hash = NULL;
1960 e_input_evdev_key_remap_set(E_Input_Evdev *edev, int *from_keys, int *to_keys, int num)
1964 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
1965 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
1966 EINA_SAFETY_ON_NULL_RETURN_VAL(from_keys, EINA_FALSE);
1967 EINA_SAFETY_ON_NULL_RETURN_VAL(to_keys, EINA_FALSE);
1968 EINA_SAFETY_ON_TRUE_RETURN_VAL(num <= 0, EINA_FALSE);
1969 EINA_SAFETY_ON_TRUE_RETURN_VAL(!edev->key_remap_enabled, EINA_FALSE);
1971 if (edev->key_remap_hash == NULL)
1972 edev->key_remap_hash = eina_hash_int32_new(NULL);
1974 if (edev->key_remap_hash == NULL)
1976 ERR("Failed to set remap key information : creating a hash is failed.");
1980 for (i = 0; i < num ; i++)
1982 if (!from_keys[i] || !to_keys[i])
1984 ERR("Failed to set remap key information : given arguments are invalid.");
1989 for (i = 0; i < num ; i++)
1991 eina_hash_add(edev->key_remap_hash, &from_keys[i], (void *)(intptr_t)to_keys[i]);
1998 e_input_evdev_wheel_click_angle_get(E_Input_Evdev *dev)
2000 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, -1);
2001 return libinput_device_config_scroll_get_wheel_click_angle(dev->device);
2005 e_input_evdev_touch_calibration_set(E_Input_Evdev *edev, float matrix[6])
2007 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2008 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2010 if (!libinput_device_config_calibration_has_matrix(edev->device) ||
2011 !libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_TOUCH))
2014 if (libinput_device_config_calibration_set_matrix(edev->device, matrix) !=
2015 LIBINPUT_CONFIG_STATUS_SUCCESS)
2017 WRN("Failed to set input transformation about device: %s\n",
2018 libinput_device_get_name(edev->device));
2026 e_input_evdev_mouse_accel_speed_set(E_Input_Evdev *edev, double speed)
2028 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2029 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2031 if (!libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
2034 if (!libinput_device_config_accel_is_available(edev->device))
2037 if (libinput_device_config_accel_set_speed(edev->device, speed) !=
2038 LIBINPUT_CONFIG_STATUS_SUCCESS)
2040 WRN("Failed to set mouse accel about device: %s\n",
2041 libinput_device_get_name(edev->device));
2048 EINTERN unsigned int
2049 e_input_evdev_touch_pressed_get(E_Input_Evdev *edev)
2051 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, 0x0);
2053 return edev->touch.pressed;
2057 e_input_evdev_seatname_get(E_Input_Evdev *evdev)
2059 struct libinput_seat *libinput_seat;
2060 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2061 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2063 libinput_seat = libinput_device_get_seat(evdev->device);
2065 return libinput_seat_get_logical_name(libinput_seat);
2069 e_input_evdev_seatname_set(E_Input_Evdev *evdev, const char *seatname)
2071 Eina_Bool res = EINA_FALSE;
2072 E_Input_Backend *input;
2074 EINA_SAFETY_ON_NULL_RETURN_VAL(seatname, EINA_FALSE);
2075 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, EINA_FALSE);
2076 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, EINA_FALSE);
2078 if (libinput_device_set_seat_logical_name(evdev->device, seatname) == 0)
2080 input = evdev->seat->input;
2081 if (!input) return EINA_FALSE;
2082 if (libinput_dispatch(input->libinput) != 0)
2084 ERR("Failed to dispatch libinput events: %m");
2088 /* process pending events */
2089 _input_events_process(input);