2 #include "e_input_private.h"
4 static void _device_modifiers_update(E_Input_Evdev *edev);
7 _device_calibration_set(E_Input_Evdev *edev)
13 output = e_comp_screen_primary_output_get(e_comp->e_comp_screen);
14 e_output_size_get(output, &w, &h);
18 edev->mouse.minx = edev->mouse.miny = 0;
22 if (libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
24 edev->seat->ptr.dx = (double)(w / 2);
25 edev->seat->ptr.dy = (double)(h / 2);
26 edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
27 edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
28 edev->mouse.dx = edev->seat->ptr.dx;
29 edev->mouse.dy = edev->seat->ptr.dy;
31 if (output->config.rotation == 90 || output->config.rotation == 270)
33 temp = edev->mouse.minx;
34 edev->mouse.minx = edev->mouse.miny;
35 edev->mouse.miny = temp;
37 temp = edev->mouse.maxw;
38 edev->mouse.maxw = edev->mouse.maxh;
39 edev->mouse.maxh = temp;
45 #ifdef _F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
51 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
52 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
55 sysname = libinput_device_get_sysname(edev->device);
57 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
58 if (eina_list_count(devices) < 1) return;
60 #ifdef _F_E_INPUT_USE_WL_CALIBRATION_
62 enum libinput_config_status status;
64 EINA_LIST_FREE(devices, device)
66 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
68 (sscanf(vals, "%f %f %f %f %f %f",
69 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
76 libinput_device_config_calibration_set_matrix(edev->device, cal);
78 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
79 ERR("Failed to apply calibration");
82 eina_stringshare_del(device);
85 #endif//_F_E_INPUT_USE_WL_CALIBRATION_
86 #endif//_F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
91 _device_configure(E_Input_Evdev *edev)
93 if (libinput_device_config_tap_get_finger_count(edev->device) > 0)
95 Eina_Bool tap = EINA_FALSE;
97 tap = libinput_device_config_tap_get_default_enabled(edev->device);
98 libinput_device_config_tap_set_enabled(edev->device, tap);
101 _device_calibration_set(edev);
105 _device_keyboard_setup(E_Input_Evdev *edev)
107 E_Input_Backend *input;
108 xkb_mod_index_t xkb_idx;
110 if ((!edev) || (!edev->seat)) return;
111 if (!(input = edev->seat->input)) return;
112 if (!input->dev->xkb_ctx) return;
114 /* create keymap from xkb context */
115 edev->xkb.keymap = _e_input_device_cached_keymap_get(input->dev->xkb_ctx, NULL, 0);
116 if (!edev->xkb.keymap)
118 ERR("Failed to create keymap: %m");
122 /* create xkb state */
123 if (!(edev->xkb.state = xkb_state_new(edev->xkb.keymap)))
125 ERR("Failed to create xkb state: %m");
129 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CTRL);
130 if (xkb_idx != XKB_MOD_INVALID)
131 edev->xkb.ctrl_mask = 1 << xkb_idx;
133 edev->xkb.ctrl_mask = 0;
135 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_ALT);
136 if (xkb_idx != XKB_MOD_INVALID)
137 edev->xkb.alt_mask = 1 << xkb_idx;
139 edev->xkb.alt_mask = 0;
141 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_SHIFT);
142 if (xkb_idx != XKB_MOD_INVALID)
143 edev->xkb.shift_mask = 1 << xkb_idx;
145 edev->xkb.shift_mask = 0;
147 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_LOGO);
148 if (xkb_idx != XKB_MOD_INVALID)
149 edev->xkb.win_mask = 1 << xkb_idx;
151 edev->xkb.win_mask = 0;
153 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_SCROLL);
154 if (xkb_idx != XKB_MOD_INVALID)
155 edev->xkb.scroll_mask = 1 << xkb_idx;
157 edev->xkb.scroll_mask = 0;
159 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_NUM);
160 if (xkb_idx != XKB_MOD_INVALID)
161 edev->xkb.num_mask = 1 << xkb_idx;
163 edev->xkb.num_mask = 0;
165 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CAPS);
166 if (xkb_idx != XKB_MOD_INVALID)
167 edev->xkb.caps_mask = 1 << xkb_idx;
169 edev->xkb.caps_mask = 0;
171 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, "ISO_Level3_Shift");
172 if (xkb_idx != XKB_MOD_INVALID)
173 edev->xkb.altgr_mask = 1 << xkb_idx;
175 edev->xkb.altgr_mask = 0;
179 _device_keysym_translate(xkb_keysym_t keysym, unsigned int modifiers, char *buffer, int bytes)
181 unsigned long hbytes = 0;
184 if (!keysym) return 0;
185 hbytes = (keysym >> 8);
190 (((keysym >= XKB_KEY_BackSpace) && (keysym <= XKB_KEY_Clear)) ||
191 (keysym == XKB_KEY_Return) || (keysym == XKB_KEY_Escape) ||
192 (keysym == XKB_KEY_KP_Space) || (keysym == XKB_KEY_KP_Tab) ||
193 (keysym == XKB_KEY_KP_Enter) ||
194 ((keysym >= XKB_KEY_KP_Multiply) && (keysym <= XKB_KEY_KP_9)) ||
195 (keysym == XKB_KEY_KP_Equal) || (keysym == XKB_KEY_Delete))))))
198 if (keysym == XKB_KEY_KP_Space)
199 c = (XKB_KEY_space & 0x7F);
200 else if (hbytes == 0xFF)
205 if (modifiers & ECORE_EVENT_MODIFIER_CTRL)
207 if (((c >= '@') && (c < '\177')) || c == ' ')
211 else if ((c >= '3') && (c <= '7'))
223 _device_modifiers_update_device(E_Input_Evdev *edev, E_Input_Evdev *from)
227 edev->xkb.depressed =
228 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_DEPRESSED);
230 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LATCHED);
232 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LOCKED);
234 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_EFFECTIVE);
236 mask = (edev->xkb.depressed | edev->xkb.latched);
238 if (mask & from->xkb.ctrl_mask)
239 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_CTRL;
240 if (mask & from->xkb.alt_mask)
241 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALT;
242 if (mask & from->xkb.shift_mask)
243 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
244 if (mask & from->xkb.win_mask)
245 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_WIN;
246 if (mask & from->xkb.scroll_mask)
247 edev->xkb.modifiers |= ECORE_EVENT_LOCK_SCROLL;
248 if (mask & from->xkb.num_mask)
249 edev->xkb.modifiers |= ECORE_EVENT_LOCK_NUM;
250 if (mask & from->xkb.caps_mask)
251 edev->xkb.modifiers |= ECORE_EVENT_LOCK_CAPS;
252 if (mask & from->xkb.altgr_mask)
253 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALTGR;
257 _device_modifiers_update(E_Input_Evdev *edev)
262 edev->xkb.modifiers = 0;
264 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
265 _device_modifiers_update_device(edev, edev);
268 EINA_LIST_FOREACH(edev->seat->devices, l, ed)
270 if (!(ed->caps & E_INPUT_SEAT_KEYBOARD)) continue;
271 _device_modifiers_update_device(edev, ed);
278 _device_remapped_key_get(E_Input_Evdev *edev, int code)
282 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, code);
283 if (!edev->key_remap_enabled) return code;
284 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->key_remap_hash, code);
286 ret = eina_hash_find(edev->key_remap_hash, &code);
288 if (ret) code = (int)(intptr_t)ret;
294 e_input_evdev_get_ecore_device(const char *path, Ecore_Device_Class clas)
296 const Eina_List *dev_list = NULL;
298 Ecore_Device *dev = NULL;
299 const char *identifier;
301 if (!path) return NULL;
303 dev_list = ecore_device_list();
304 if (!dev_list) return NULL;
305 EINA_LIST_FOREACH(dev_list, l, dev)
308 identifier = ecore_device_identifier_get(dev);
309 if (!identifier) continue;
310 if ((ecore_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
317 _e_input_event_mouse_move_cb_free(void *data EINA_UNUSED, void *event)
319 Ecore_Event_Mouse_Move *ev = event;
321 if (ev->dev) ecore_device_unref(ev->dev);
327 _e_input_event_mouse_wheel_cb_free(void *data EINA_UNUSED, void *event)
329 Ecore_Event_Mouse_Wheel *ev = event;
331 if (ev->dev) ecore_device_unref(ev->dev);
337 _e_input_event_mouse_button_cb_free(void *data EINA_UNUSED, void *event)
339 Ecore_Event_Mouse_Button *ev = event;
341 if (ev->dev) ecore_device_unref(ev->dev);
347 _e_input_event_key_cb_free(void *data EINA_UNUSED, void *event)
349 Ecore_Event_Key *ev = event;
351 if (ev->dev) ecore_device_unref(ev->dev);
357 _device_handle_key(struct libinput_device *device, struct libinput_event_keyboard *event)
360 E_Input_Backend *input;
362 uint32_t code, nsyms;
363 const xkb_keysym_t *syms;
364 enum libinput_key_state state;
366 xkb_keysym_t sym = XKB_KEY_NoSymbol;
367 char key[256], keyname[256], compose_buffer[256];
369 char *tmp = NULL, *compose = NULL;
371 if (!(edev = libinput_device_get_user_data(device)))
376 if (!(input = edev->seat->input))
381 if (!edev->ecore_dev)
382 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
384 if (!edev->ecore_dev)
386 ERR("Failed to get source ecore device from event !\n");
390 timestamp = libinput_event_keyboard_get_time(event);
391 code = libinput_event_keyboard_get_key(event);
392 code = _device_remapped_key_get(edev, code) + 8;
393 state = libinput_event_keyboard_get_key_state(event);
394 key_count = libinput_event_keyboard_get_seat_key_count(event);
396 /* ignore key events that are not seat wide state changes */
397 if (((state == LIBINPUT_KEY_STATE_PRESSED) && (key_count != 1)) ||
398 ((state == LIBINPUT_KEY_STATE_RELEASED) && (key_count != 0)))
403 xkb_state_update_key(edev->xkb.state, code,
404 (state ? XKB_KEY_DOWN : XKB_KEY_UP));
406 /* get the keysym for this code */
407 nsyms = xkb_key_get_syms(edev->xkb.state, code, &syms);
408 if (nsyms == 1) sym = syms[0];
410 /* get the keyname for this sym */
411 memset(key, 0, sizeof(key));
412 xkb_keysym_get_name(sym, key, sizeof(key));
414 memset(keyname, 0, sizeof(keyname));
415 memcpy(keyname, key, sizeof(keyname));
417 if (keyname[0] == '\0')
418 snprintf(keyname, sizeof(keyname), "Keycode-%u", code);
420 /* if shift is active, we need to transform the key to lower */
421 if (xkb_state_mod_index_is_active(edev->xkb.state,
422 xkb_map_mod_get_index(edev->xkb.keymap,
424 XKB_STATE_MODS_EFFECTIVE))
426 if (keyname[0] != '\0')
427 keyname[0] = tolower(keyname[0]);
430 memset(compose_buffer, 0, sizeof(compose_buffer));
431 if (_device_keysym_translate(sym, edev->xkb.modifiers,
432 compose_buffer, sizeof(compose_buffer)))
434 compose = eina_str_convert("ISO8859-1", "UTF-8", compose_buffer);
437 ERR("E Input cannot convert input key string '%s' to UTF-8. "
438 "Is Eina built with iconv support?", compose_buffer);
444 if (!compose) compose = compose_buffer;
446 e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) +
447 ((compose[0] != '\0') ? strlen(compose) : 0) + 3);
454 e->keyname = (char *)(e + 1);
455 e->key = e->keyname + strlen(keyname) + 1;
456 e->compose = strlen(compose) ? e->key + strlen(key) + 1 : NULL;
457 e->string = e->compose;
459 strncpy((char *)e->keyname, keyname, strlen(keyname));
460 strncpy((char *)e->key, key, strlen(key));
461 if (strlen(compose)) strncpy((char *)e->compose, compose, strlen(compose));
463 e->window = (Ecore_Window)input->dev->window;
464 e->event_window = (Ecore_Window)input->dev->window;
465 e->root_window = (Ecore_Window)input->dev->window;
466 e->timestamp = timestamp;
471 _device_modifiers_update(edev);
473 e->modifiers = edev->xkb.modifiers;
474 e->dev = ecore_device_ref(edev->ecore_dev);
477 ecore_event_add(ECORE_EVENT_KEY_DOWN, e, _e_input_event_key_cb_free, NULL);
479 ecore_event_add(ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
485 _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event)
487 E_Input_Backend *input;
488 Ecore_Event_Mouse_Move *ev;
490 if (!(input = edev->seat->input)) return;
492 if (!edev->ecore_dev)
493 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
495 if (!edev->ecore_dev)
497 ERR("Failed to get source ecore device from event !\n");
501 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
503 if (edev->seat->ptr.ix < edev->mouse.minx)
504 edev->seat->ptr.dx = edev->seat->ptr.ix = edev->mouse.minx;
505 else if (edev->seat->ptr.ix >= (edev->mouse.minx + edev->mouse.maxw))
506 edev->seat->ptr.dx = edev->seat->ptr.ix = (edev->mouse.minx + edev->mouse.maxw - 1);
508 if (edev->seat->ptr.iy < edev->mouse.miny)
509 edev->seat->ptr.dy = edev->seat->ptr.iy = edev->mouse.miny;
510 else if (edev->seat->ptr.iy >= (edev->mouse.miny + edev->mouse.maxh))
511 edev->seat->ptr.dy = edev->seat->ptr.iy = (edev->mouse.miny + edev->mouse.maxh - 1);
513 edev->mouse.dx = edev->seat->ptr.dx;
514 edev->mouse.dy = edev->seat->ptr.dy;
516 ev->window = (Ecore_Window)input->dev->window;
517 ev->event_window = (Ecore_Window)input->dev->window;
518 ev->root_window = (Ecore_Window)input->dev->window;
519 if (event) ev->timestamp = libinput_event_pointer_get_time(event);
522 _device_modifiers_update(edev);
523 ev->modifiers = edev->xkb.modifiers;
525 ev->x = edev->seat->ptr.ix;
526 ev->y = edev->seat->ptr.iy;
530 ev->multi.device = edev->mt_slot;
531 ev->multi.radius = 1;
532 ev->multi.radius_x = 1;
533 ev->multi.radius_y = 1;
534 ev->multi.pressure = 1.0;
535 ev->multi.angle = 0.0;
538 ev->multi.root.x = ev->x;
539 ev->multi.root.y = ev->y;
540 ev->dev = ecore_device_ref(edev->ecore_dev);
542 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
546 _e_input_pointer_motion_post(E_Input_Evdev *edev)
548 _device_pointer_motion(edev, NULL);
552 _device_handle_pointer_motion(struct libinput_device *device, struct libinput_event_pointer *event)
557 if (!(edev = libinput_device_get_user_data(device)))
562 dx = libinput_event_pointer_get_dx(event);
563 dy = libinput_event_pointer_get_dy(event);
565 if (edev->seat->ptr.swap)
571 if (edev->seat->ptr.invert_x)
573 if (edev->seat->ptr.invert_y)
576 edev->seat->ptr.dx += dx;
577 edev->seat->ptr.dy += dy;
579 edev->mouse.dx = edev->seat->ptr.dx;
580 edev->mouse.dy = edev->seat->ptr.dy;
582 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
583 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
588 edev->seat->ptr.ix = edev->seat->ptr.dx;
589 edev->seat->ptr.iy = edev->seat->ptr.dy;
591 _device_pointer_motion(edev, event);
595 _device_handle_pointer_motion_absolute(struct libinput_device *device, struct libinput_event_pointer *event)
600 if (!(edev = libinput_device_get_user_data(device)))
605 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
607 edev->mouse.dx = edev->seat->ptr.dx =
608 libinput_event_pointer_get_absolute_x_transformed(event, w);
609 edev->mouse.dy = edev->seat->ptr.dy =
610 libinput_event_pointer_get_absolute_y_transformed(event, h);
612 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
613 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
618 edev->seat->ptr.ix = edev->seat->ptr.dx;
619 edev->seat->ptr.iy = edev->seat->ptr.dy;
620 _device_pointer_motion(edev, event);
624 _device_handle_button(struct libinput_device *device, struct libinput_event_pointer *event)
627 E_Input_Backend *input;
628 Ecore_Event_Mouse_Button *ev;
629 enum libinput_button_state state;
630 uint32_t button, timestamp;
632 if (!(edev = libinput_device_get_user_data(device)))
636 if (!(input = edev->seat->input))
641 if (!edev->ecore_dev)
642 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
644 if (!edev->ecore_dev)
646 ERR("Failed to get source ecore device from event !\n");
650 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button))))
655 state = libinput_event_pointer_get_button_state(event);
656 button = libinput_event_pointer_get_button(event);
657 timestamp = libinput_event_pointer_get_time(event);
659 button = ((button & 0x00F) + 1);
660 if (button == 3) button = 2;
661 else if (button == 2) button = 3;
663 ev->window = (Ecore_Window)input->dev->window;
664 ev->event_window = (Ecore_Window)input->dev->window;
665 ev->root_window = (Ecore_Window)input->dev->window;
666 ev->timestamp = timestamp;
669 _device_modifiers_update(edev);
670 ev->modifiers = edev->xkb.modifiers;
672 ev->x = edev->seat->ptr.ix;
673 ev->y = edev->seat->ptr.iy;
677 ev->multi.device = edev->mt_slot;
678 ev->multi.radius = 1;
679 ev->multi.radius_x = 1;
680 ev->multi.radius_y = 1;
681 ev->multi.pressure = 1.0;
682 ev->multi.angle = 0.0;
685 ev->multi.root.x = ev->x;
686 ev->multi.root.y = ev->y;
687 ev->dev = ecore_device_ref(edev->ecore_dev);
691 unsigned int current;
694 edev->mouse.did_double = EINA_FALSE;
695 edev->mouse.did_triple = EINA_FALSE;
697 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
698 (button == edev->mouse.prev_button))
700 edev->mouse.did_double = EINA_TRUE;
701 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
702 (button == edev->mouse.last_button))
704 edev->mouse.did_triple = EINA_TRUE;
705 edev->mouse.prev = 0;
706 edev->mouse.last = 0;
711 edev->mouse.last = edev->mouse.prev;
712 edev->mouse.prev = current;
713 edev->mouse.last_button = edev->mouse.prev_button;
714 edev->mouse.prev_button = button;
717 ev->buttons = button;
719 if (edev->mouse.did_double)
720 ev->double_click = 1;
721 if (edev->mouse.did_triple)
722 ev->triple_click = 1;
725 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, _e_input_event_mouse_button_cb_free, NULL);
727 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, _e_input_event_mouse_button_cb_free, NULL);
731 _device_handle_axis(struct libinput_device *device, struct libinput_event_pointer *event)
734 E_Input_Backend *input;
735 Ecore_Event_Mouse_Wheel *ev;
737 enum libinput_pointer_axis axis;
739 if (!(edev = libinput_device_get_user_data(device)))
743 if (!(input = edev->seat->input))
748 if (!edev->ecore_dev)
749 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
751 if (!edev->ecore_dev)
753 ERR("Failed to get source ecore device from event !\n");
757 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
762 timestamp = libinput_event_pointer_get_time(event);
764 ev->window = (Ecore_Window)input->dev->window;
765 ev->event_window = (Ecore_Window)input->dev->window;
766 ev->root_window = (Ecore_Window)input->dev->window;
767 ev->timestamp = timestamp;
770 _device_modifiers_update(edev);
771 ev->modifiers = edev->xkb.modifiers;
773 ev->x = edev->seat->ptr.ix;
774 ev->y = edev->seat->ptr.iy;
777 ev->dev = ecore_device_ref(edev->ecore_dev);
779 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
780 if (libinput_event_pointer_has_axis(event, axis))
781 ev->z = libinput_event_pointer_get_axis_value(event, axis);
783 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
784 if (libinput_event_pointer_has_axis(event, axis))
787 ev->z = libinput_event_pointer_get_axis_value(event, axis);
790 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
794 _device_handle_touch_event_send(E_Input_Evdev *edev, struct libinput_event_touch *event, int state)
796 E_Input_Backend *input;
797 Ecore_Event_Mouse_Button *ev;
798 uint32_t timestamp, button = 0;
801 if (!(input = edev->seat->input)) return;
803 if (!edev->ecore_dev)
804 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
806 if (!edev->ecore_dev)
808 ERR("Failed to get source ecore device from event !\n");
812 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) return;
814 timestamp = libinput_event_touch_get_time(event);
816 ev->window = (Ecore_Window)input->dev->window;
817 ev->event_window = (Ecore_Window)input->dev->window;
818 ev->root_window = (Ecore_Window)input->dev->window;
819 ev->timestamp = timestamp;
822 _device_modifiers_update(edev);
823 ev->modifiers = edev->xkb.modifiers;
825 ev->x = edev->seat->ptr.ix;
826 ev->y = edev->seat->ptr.iy;
830 ev->multi.device = edev->mt_slot;
831 ev->multi.radius = 1;
832 ev->multi.radius_x = 1;
833 ev->multi.radius_y = 1;
834 ev->multi.pressure = 1.0;
835 ev->multi.angle = 0.0;
836 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
837 if (libinput_event_get_type(libinput_event_touch_get_base_event(event))
838 == LIBINPUT_EVENT_TOUCH_DOWN)
840 if (libinput_event_touch_has_minor(event))
841 ev->multi.radius_x = libinput_event_touch_get_minor(event);
842 if (libinput_event_touch_has_major(event))
843 ev->multi.radius_y = libinput_event_touch_get_major(event);
844 if (libinput_event_touch_has_pressure(event))
845 ev->multi.pressure = libinput_event_touch_get_pressure(event);
846 if (libinput_event_touch_has_orientation(event))
847 ev->multi.angle = libinput_event_touch_get_orientation(event);
852 ev->multi.root.x = ev->x;
853 ev->multi.root.y = ev->y;
854 ev->dev = ecore_device_ref(edev->ecore_dev);
856 if (state == ECORE_EVENT_MOUSE_BUTTON_DOWN)
858 unsigned int current;
861 edev->mouse.did_double = EINA_FALSE;
862 edev->mouse.did_triple = EINA_FALSE;
864 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
865 (button == edev->mouse.prev_button))
867 edev->mouse.did_double = EINA_TRUE;
868 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
869 (button == edev->mouse.last_button))
871 edev->mouse.did_triple = EINA_TRUE;
872 edev->mouse.prev = 0;
873 edev->mouse.last = 0;
878 edev->mouse.last = edev->mouse.prev;
879 edev->mouse.prev = current;
880 edev->mouse.last_button = edev->mouse.prev_button;
881 edev->mouse.prev_button = button;
884 ev->buttons = ((button & 0x00F) + 1);
886 if (edev->mouse.did_double)
887 ev->double_click = 1;
888 if (edev->mouse.did_triple)
889 ev->triple_click = 1;
891 ecore_event_add(state, ev, _e_input_event_mouse_button_cb_free, NULL);
895 _device_handle_touch_motion_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
897 E_Input_Backend *input;
898 Ecore_Event_Mouse_Move *ev;
901 if (!(input = edev->seat->input)) return;
903 if (!edev->ecore_dev)
904 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
906 if (!edev->ecore_dev)
908 ERR("Failed to get source ecore device from event !\n");
912 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
914 ev->window = (Ecore_Window)input->dev->window;
915 ev->event_window = (Ecore_Window)input->dev->window;
916 ev->root_window = (Ecore_Window)input->dev->window;
917 ev->timestamp = libinput_event_touch_get_time(event);
920 _device_modifiers_update(edev);
921 ev->modifiers = edev->xkb.modifiers;
923 ev->x = edev->seat->ptr.ix;
924 ev->y = edev->seat->ptr.iy;
928 ev->multi.device = edev->mt_slot;
929 ev->multi.radius = 1;
930 ev->multi.radius_x = 1;
931 ev->multi.radius_y = 1;
932 ev->multi.pressure = 1.0;
933 ev->multi.angle = 0.0;
934 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
935 if (libinput_event_touch_has_minor(event))
936 ev->multi.radius_x = libinput_event_touch_get_minor(event);
937 if (libinput_event_touch_has_major(event))
938 ev->multi.radius_y = libinput_event_touch_get_major(event);
939 if (libinput_event_touch_has_pressure(event))
940 ev->multi.pressure = libinput_event_touch_get_pressure(event);
941 if (libinput_event_touch_has_orientation(event))
942 ev->multi.angle = libinput_event_touch_get_orientation(event);
946 ev->multi.root.x = ev->x;
947 ev->multi.root.y = ev->y;
948 ev->dev = ecore_device_ref(edev->ecore_dev);
950 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
954 _device_handle_touch_down(struct libinput_device *device, struct libinput_event_touch *event)
959 if (!(edev = libinput_device_get_user_data(device)))
964 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
966 edev->mouse.dx = edev->seat->ptr.ix = edev->seat->ptr.dx =
967 libinput_event_touch_get_x_transformed(event, w);
968 edev->mouse.dy = edev->seat->ptr.iy = edev->seat->ptr.dy =
969 libinput_event_touch_get_y_transformed(event, h);
971 edev->mt_slot = libinput_event_touch_get_slot(event);
973 _device_handle_touch_motion_send(edev, event);
974 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_DOWN);
978 _device_handle_touch_motion(struct libinput_device *device, struct libinput_event_touch *event)
983 if (!(edev = libinput_device_get_user_data(device)))
988 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
990 edev->mouse.dx = edev->seat->ptr.dx =
991 libinput_event_touch_get_x_transformed(event, w);
992 edev->mouse.dy = edev->seat->ptr.dy =
993 libinput_event_touch_get_y_transformed(event, h);
995 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
996 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
1001 edev->seat->ptr.ix = edev->seat->ptr.dx;
1002 edev->seat->ptr.iy = edev->seat->ptr.dy;
1004 edev->mt_slot = libinput_event_touch_get_slot(event);
1006 _device_handle_touch_motion_send(edev, event);
1010 _device_handle_touch_up(struct libinput_device *device, struct libinput_event_touch *event)
1012 E_Input_Evdev *edev;
1014 if (!(edev = libinput_device_get_user_data(device)))
1019 edev->mt_slot = libinput_event_touch_get_slot(event);
1020 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_UP);
1024 _device_handle_touch_frame(struct libinput_device *device EINA_UNUSED, struct libinput_event_touch *event EINA_UNUSED)
1026 /* DBG("Unhandled Touch Frame Event"); */
1030 _e_input_aux_data_event_free(void *user_data EINA_UNUSED, void *ev)
1032 Ecore_Event_Axis_Update *e = (Ecore_Event_Axis_Update *)ev;
1034 if (e->axis) free(e->axis);
1035 if (e->dev) ecore_device_unref(e->dev);
1041 _device_handle_touch_aux_data(struct libinput_device *device, struct libinput_event_touch_aux_data *event)
1043 E_Input_Evdev *edev;
1044 E_Input_Backend *input;
1045 Ecore_Event_Axis_Update *ev;
1048 if (libinput_event_touch_aux_data_get_type(event) != LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM &&
1049 libinput_event_touch_aux_data_get_value(event) > 0)
1052 if (!(edev = libinput_device_get_user_data(device))) goto end;
1053 if (!(input = edev->seat->input)) goto end;
1055 if (!edev->ecore_dev)
1056 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1058 if (!edev->ecore_dev)
1060 ERR("Failed to get source ecore device from event !\n");
1064 if (!(ev = calloc(1, sizeof(Ecore_Event_Axis_Update))))goto end;
1066 ev->window = (Ecore_Window)input->dev->window;
1067 ev->event_window = (Ecore_Window)input->dev->window;
1068 ev->root_window = (Ecore_Window)input->dev->window;
1069 ev->timestamp = libinput_event_touch_aux_data_get_time(event);
1071 axis = (Ecore_Axis *)calloc(1, sizeof(Ecore_Axis));
1074 axis->label = ECORE_AXIS_LABEL_TOUCH_PALM;
1075 axis->value = libinput_event_touch_aux_data_get_value(event);
1079 ev->dev = ecore_device_ref(edev->ecore_dev);
1081 ecore_event_add(ECORE_EVENT_AXIS_UPDATE, ev, _e_input_aux_data_event_free, NULL);
1088 _e_input_evdev_device_create(E_Input_Seat *seat, struct libinput_device *device)
1090 E_Input_Evdev *edev;
1091 E_Input_Backend *b_input;
1093 EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
1095 /* try to allocate space for new evdev */
1096 if (!(edev = calloc(1, sizeof(E_Input_Evdev)))) return NULL;
1099 edev->device = device;
1100 edev->path = eina_stringshare_printf("%s/%s", e_input_base_dir_get(), libinput_device_get_sysname(device));
1103 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
1105 edev->caps |= E_INPUT_SEAT_KEYBOARD;
1106 _device_keyboard_setup(edev);
1109 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
1111 edev->caps |= E_INPUT_SEAT_POINTER;
1113 /* TODO: make this configurable */
1114 edev->mouse.threshold = 250;
1116 b_input = seat->input;
1117 if (b_input->left_handed == EINA_TRUE)
1119 if (libinput_device_config_left_handed_set(device, 1) !=
1120 LIBINPUT_CONFIG_STATUS_SUCCESS)
1122 WRN("Failed to set left hand mode about device: %s\n",
1123 libinput_device_get_name(device));
1128 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
1131 edev->caps |= E_INPUT_SEAT_TOUCH;
1132 palm_code = libinput_device_touch_aux_data_get_code(LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM);
1133 if (libinput_device_touch_has_aux_data(device, palm_code))
1135 libinput_device_touch_set_aux_data(device, palm_code);
1139 libinput_device_set_user_data(device, edev);
1140 libinput_device_ref(device);
1142 /* configure device */
1143 _device_configure(edev);
1149 _e_input_evdev_device_destroy(E_Input_Evdev *edev)
1151 EINA_SAFETY_ON_NULL_RETURN(edev);
1153 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
1155 if (edev->xkb.state) xkb_state_unref(edev->xkb.state);
1156 if (edev->xkb.keymap) xkb_map_unref(edev->xkb.keymap);
1159 if (edev->ecore_dev) ecore_device_del(edev->ecore_dev);
1160 if (edev->path) eina_stringshare_del(edev->path);
1161 if (edev->device) libinput_device_unref(edev->device);
1162 if (edev->key_remap_hash) eina_hash_free(edev->key_remap_hash);
1168 _e_input_evdev_event_process(struct libinput_event *event)
1170 struct libinput_device *device;
1171 Eina_Bool ret = EINA_TRUE;
1173 device = libinput_event_get_device(event);
1174 switch (libinput_event_get_type(event))
1176 case LIBINPUT_EVENT_KEYBOARD_KEY:
1177 _device_handle_key(device, libinput_event_get_keyboard_event(event));
1179 case LIBINPUT_EVENT_POINTER_MOTION:
1180 _device_handle_pointer_motion(device,
1181 libinput_event_get_pointer_event(event));
1183 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
1184 _device_handle_pointer_motion_absolute(device,
1185 libinput_event_get_pointer_event(event));
1187 case LIBINPUT_EVENT_POINTER_BUTTON:
1188 _device_handle_button(device, libinput_event_get_pointer_event(event));
1190 case LIBINPUT_EVENT_POINTER_AXIS:
1191 _device_handle_axis(device, libinput_event_get_pointer_event(event));
1193 case LIBINPUT_EVENT_TOUCH_DOWN:
1194 _device_handle_touch_down(device, libinput_event_get_touch_event(event));
1196 case LIBINPUT_EVENT_TOUCH_MOTION:
1197 _device_handle_touch_motion(device,
1198 libinput_event_get_touch_event(event));
1200 case LIBINPUT_EVENT_TOUCH_UP:
1201 _device_handle_touch_up(device, libinput_event_get_touch_event(event));
1203 case LIBINPUT_EVENT_TOUCH_FRAME:
1204 _device_handle_touch_frame(device, libinput_event_get_touch_event(event));
1206 case LIBINPUT_EVENT_TOUCH_AUX_DATA:
1207 _device_handle_touch_aux_data(device, libinput_event_get_touch_aux_data(event));
1218 * @brief Set the axis size of the given device.
1220 * @param dev The device to set the axis size to.
1221 * @param w The width of the axis.
1222 * @param h The height of the axis.
1224 * This function sets set the width @p w and height @p h of the axis
1225 * of device @p dev. If @p dev is a relative input device, a width and
1226 * height must set for it. If its absolute set the ioctl correctly, if
1227 * not, unsupported device.
1230 e_input_evdev_axis_size_set(E_Input_Evdev *edev, int w, int h)
1232 const char *sysname;
1237 enum libinput_config_status status;
1239 EINA_SAFETY_ON_NULL_RETURN(edev);
1240 EINA_SAFETY_ON_TRUE_RETURN((w == 0) || (h == 0));
1242 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
1243 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
1246 sysname = libinput_device_get_sysname(edev->device);
1248 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
1249 if (eina_list_count(devices) < 1) return;
1251 EINA_LIST_FREE(devices, device)
1253 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
1255 (sscanf(vals, "%f %f %f %f %f %f",
1256 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
1263 libinput_device_config_calibration_set_matrix(edev->device, cal);
1265 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
1266 ERR("Failed to apply calibration");
1269 eina_stringshare_del(device);
1275 e_input_evdev_name_get(E_Input_Evdev *evdev)
1277 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
1278 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
1280 return libinput_device_get_name(evdev->device);
1283 EINTERN const char *
1284 e_input_evdev_sysname_get(E_Input_Evdev *evdev)
1286 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
1287 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
1289 return libinput_device_get_sysname(evdev->device);
1293 e_input_evdev_key_remap_enable(E_Input_Evdev *edev, Eina_Bool enable)
1295 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
1296 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
1298 edev->key_remap_enabled = enable;
1300 if (enable == EINA_FALSE && edev->key_remap_hash)
1302 eina_hash_free(edev->key_remap_hash);
1303 edev->key_remap_hash = NULL;
1310 e_input_evdev_key_remap_set(E_Input_Evdev *edev, int *from_keys, int *to_keys, int num)
1314 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
1315 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
1316 EINA_SAFETY_ON_NULL_RETURN_VAL(from_keys, EINA_FALSE);
1317 EINA_SAFETY_ON_NULL_RETURN_VAL(to_keys, EINA_FALSE);
1318 EINA_SAFETY_ON_TRUE_RETURN_VAL(num <= 0, EINA_FALSE);
1319 EINA_SAFETY_ON_TRUE_RETURN_VAL(!edev->key_remap_enabled, EINA_FALSE);
1321 if (edev->key_remap_hash == NULL)
1322 edev->key_remap_hash = eina_hash_int32_new(NULL);
1324 if (edev->key_remap_hash == NULL)
1326 ERR("Failed to set remap key information : creating a hash is failed.");
1330 for (i = 0; i < num ; i++)
1332 if (!from_keys[i] || !to_keys[i])
1334 ERR("Failed to set remap key information : given arguments are invalid.");
1339 for (i = 0; i < num ; i++)
1341 eina_hash_add(edev->key_remap_hash, &from_keys[i], (void *)(intptr_t)to_keys[i]);
1348 e_input_evdev_wheel_click_angle_get(E_Input_Evdev *dev)
1350 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, -1);
1351 return libinput_device_config_scroll_get_wheel_click_angle(dev->device);
1355 e_input_evdev_touch_calibration_set(E_Input_Evdev *edev, float matrix[6])
1357 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
1358 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
1360 if (!libinput_device_config_calibration_has_matrix(edev->device) ||
1361 !libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_TOUCH))
1364 if (libinput_device_config_calibration_set_matrix(edev->device, matrix) !=
1365 LIBINPUT_CONFIG_STATUS_SUCCESS)
1367 WRN("Failed to set input transformation about device: %s\n",
1368 libinput_device_get_name(edev->device));