2 #include "e_input_private.h"
4 static void _device_modifiers_update(E_Input_Evdev *edev);
7 _device_calibration_set(E_Input_Evdev *edev)
14 enum libinput_config_status status;
19 output = e_comp_screen_primary_output_get(e_comp->e_comp_screen);
20 e_output_size_get(output, &w, &h);
24 edev->mouse.minx = edev->mouse.miny = 0;
28 if (libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
30 edev->seat->ptr.dx = (double)(w / 2);
31 edev->seat->ptr.dy = (double)(h / 2);
32 edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
33 edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
34 edev->mouse.dx = edev->seat->ptr.dx;
35 edev->mouse.dy = edev->seat->ptr.dy;
37 if (output->config.rotation == 90 || output->config.rotation == 270)
39 temp = edev->mouse.minx;
40 edev->mouse.minx = edev->mouse.miny;
41 edev->mouse.miny = temp;
43 temp = edev->mouse.maxw;
44 edev->mouse.maxw = edev->mouse.maxh;
45 edev->mouse.maxh = temp;
51 #ifdef _F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
52 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
53 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
56 sysname = libinput_device_get_sysname(edev->device);
58 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
59 if (eina_list_count(devices) < 1) return;
61 #ifdef _F_E_INPUT_USE_WL_CALIBRATION_
62 EINA_LIST_FREE(devices, device)
64 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
66 (sscanf(vals, "%f %f %f %f %f %f",
67 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
74 libinput_device_config_calibration_set_matrix(edev->device, cal);
76 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
77 ERR("Failed to apply calibration");
80 eina_stringshare_del(device);
83 #endif//_F_E_INPUT_USE_WL_CALIBRATION_
84 #endif//_F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
89 _device_configure(E_Input_Evdev *edev)
91 if (libinput_device_config_tap_get_finger_count(edev->device) > 0)
93 Eina_Bool tap = EINA_FALSE;
95 tap = libinput_device_config_tap_get_default_enabled(edev->device);
96 libinput_device_config_tap_set_enabled(edev->device, tap);
99 _device_calibration_set(edev);
103 _device_keyboard_setup(E_Input_Evdev *edev)
105 E_Input_Backend *input;
107 if ((!edev) || (!edev->seat)) return;
108 if (!(input = edev->seat->input)) return;
109 if (!input->dev->xkb_ctx) return;
111 /* create keymap from xkb context */
112 edev->xkb.keymap = _e_input_device_cached_keymap_get(input->dev->xkb_ctx, NULL, 0);
113 if (!edev->xkb.keymap)
115 ERR("Failed to create keymap: %m");
119 /* create xkb state */
120 if (!(edev->xkb.state = xkb_state_new(edev->xkb.keymap)))
122 ERR("Failed to create xkb state: %m");
126 edev->xkb.ctrl_mask =
127 1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CTRL);
129 1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_ALT);
130 edev->xkb.shift_mask =
131 1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_SHIFT);
133 1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_LOGO);
134 edev->xkb.scroll_mask =
135 1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_SCROLL);
137 1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_NUM);
138 edev->xkb.caps_mask =
139 1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CAPS);
140 edev->xkb.altgr_mask =
141 1 << xkb_map_mod_get_index(edev->xkb.keymap, "ISO_Level3_Shift");
145 _device_keysym_translate(xkb_keysym_t keysym, unsigned int modifiers, char *buffer, int bytes)
147 unsigned long hbytes = 0;
150 if (!keysym) return 0;
151 hbytes = (keysym >> 8);
156 (((keysym >= XKB_KEY_BackSpace) && (keysym <= XKB_KEY_Clear)) ||
157 (keysym == XKB_KEY_Return) || (keysym == XKB_KEY_Escape) ||
158 (keysym == XKB_KEY_KP_Space) || (keysym == XKB_KEY_KP_Tab) ||
159 (keysym == XKB_KEY_KP_Enter) ||
160 ((keysym >= XKB_KEY_KP_Multiply) && (keysym <= XKB_KEY_KP_9)) ||
161 (keysym == XKB_KEY_KP_Equal) || (keysym == XKB_KEY_Delete))))))
164 if (keysym == XKB_KEY_KP_Space)
165 c = (XKB_KEY_space & 0x7F);
166 else if (hbytes == 0xFF)
171 if (modifiers & ECORE_EVENT_MODIFIER_CTRL)
173 if (((c >= '@') && (c < '\177')) || c == ' ')
177 else if ((c >= '3') && (c <= '7'))
189 _device_modifiers_update_device(E_Input_Evdev *edev, E_Input_Evdev *from)
193 edev->xkb.depressed =
194 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_DEPRESSED);
196 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LATCHED);
198 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LOCKED);
200 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_EFFECTIVE);
202 mask = (edev->xkb.depressed | edev->xkb.latched);
204 if (mask & from->xkb.ctrl_mask)
205 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_CTRL;
206 if (mask & from->xkb.alt_mask)
207 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALT;
208 if (mask & from->xkb.shift_mask)
209 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
210 if (mask & from->xkb.win_mask)
211 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_WIN;
212 if (mask & from->xkb.scroll_mask)
213 edev->xkb.modifiers |= ECORE_EVENT_LOCK_SCROLL;
214 if (mask & from->xkb.num_mask)
215 edev->xkb.modifiers |= ECORE_EVENT_LOCK_NUM;
216 if (mask & from->xkb.caps_mask)
217 edev->xkb.modifiers |= ECORE_EVENT_LOCK_CAPS;
218 if (mask & from->xkb.altgr_mask)
219 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALTGR;
223 _device_modifiers_update(E_Input_Evdev *edev)
225 edev->xkb.modifiers = 0;
227 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
228 _device_modifiers_update_device(edev, edev);
234 EINA_LIST_FOREACH(edev->seat->devices, l, ed)
236 if (!(ed->caps & E_INPUT_SEAT_KEYBOARD)) continue;
237 _device_modifiers_update_device(edev, ed);
244 _device_remapped_key_get(E_Input_Evdev *edev, int code)
248 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, code);
249 if (!edev->key_remap_enabled) return code;
250 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->key_remap_hash, code);
252 ret = eina_hash_find(edev->key_remap_hash, &code);
254 if (ret) code = (int)(intptr_t)ret;
260 e_input_evdev_get_ecore_device(const char *path, Ecore_Device_Class clas)
262 const Eina_List *dev_list = NULL;
264 Ecore_Device *dev = NULL;
265 const char *identifier;
267 if (!path) return NULL;
269 dev_list = ecore_device_list();
270 if (!dev_list) return NULL;
271 EINA_LIST_FOREACH(dev_list, l, dev)
274 identifier = ecore_device_identifier_get(dev);
275 if (!identifier) continue;
276 if ((ecore_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
283 _device_handle_key(struct libinput_device *device, struct libinput_event_keyboard *event)
286 E_Input_Backend *input;
288 uint32_t code, nsyms;
289 const xkb_keysym_t *syms;
290 enum libinput_key_state state;
292 xkb_keysym_t sym = XKB_KEY_NoSymbol;
293 char key[256], keyname[256], compose_buffer[256];
295 char *tmp = NULL, *compose = NULL;
297 if (!(edev = libinput_device_get_user_data(device)))
302 if (!(input = edev->seat->input))
307 timestamp = libinput_event_keyboard_get_time(event);
308 code = libinput_event_keyboard_get_key(event);
309 code = _device_remapped_key_get(edev, code) + 8;
310 state = libinput_event_keyboard_get_key_state(event);
311 key_count = libinput_event_keyboard_get_seat_key_count(event);
313 /* ignore key events that are not seat wide state changes */
314 if (((state == LIBINPUT_KEY_STATE_PRESSED) && (key_count != 1)) ||
315 ((state == LIBINPUT_KEY_STATE_RELEASED) && (key_count != 0)))
320 xkb_state_update_key(edev->xkb.state, code,
321 (state ? XKB_KEY_DOWN : XKB_KEY_UP));
323 /* get the keysym for this code */
324 nsyms = xkb_key_get_syms(edev->xkb.state, code, &syms);
325 if (nsyms == 1) sym = syms[0];
327 /* get the keyname for this sym */
328 memset(key, 0, sizeof(key));
329 xkb_keysym_get_name(sym, key, sizeof(key));
331 memset(keyname, 0, sizeof(keyname));
332 memcpy(keyname, key, sizeof(keyname));
334 if (keyname[0] == '\0')
335 snprintf(keyname, sizeof(keyname), "Keycode-%u", code);
337 /* if shift is active, we need to transform the key to lower */
338 if (xkb_state_mod_index_is_active(edev->xkb.state,
339 xkb_map_mod_get_index(edev->xkb.keymap,
341 XKB_STATE_MODS_EFFECTIVE))
343 if (keyname[0] != '\0')
344 keyname[0] = tolower(keyname[0]);
347 memset(compose_buffer, 0, sizeof(compose_buffer));
348 if (_device_keysym_translate(sym, edev->xkb.modifiers,
349 compose_buffer, sizeof(compose_buffer)))
351 compose = eina_str_convert("ISO8859-1", "UTF-8", compose_buffer);
354 ERR("E Input cannot convert input key string '%s' to UTF-8. "
355 "Is Eina built with iconv support?", compose_buffer);
361 if (!compose) compose = compose_buffer;
363 e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) +
364 ((compose[0] != '\0') ? strlen(compose) : 0) + 3);
370 e->keyname = (char *)(e + 1);
371 e->key = e->keyname + strlen(keyname) + 1;
372 e->compose = strlen(compose) ? e->key + strlen(key) + 1 : NULL;
373 e->string = e->compose;
375 strncpy((char *)e->keyname, keyname, strlen(keyname));
376 strncpy((char *)e->key, key, strlen(key));
377 if (strlen(compose)) strncpy((char *)e->compose, compose, strlen(compose));
379 e->window = (Ecore_Window)input->dev->window;
380 e->event_window = (Ecore_Window)input->dev->window;
381 e->root_window = (Ecore_Window)input->dev->window;
382 e->timestamp = timestamp;
387 _device_modifiers_update(edev);
389 e->modifiers = edev->xkb.modifiers;
390 e->dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
393 ecore_event_add(ECORE_EVENT_KEY_DOWN, e, NULL, NULL);
395 ecore_event_add(ECORE_EVENT_KEY_UP, e, NULL, NULL);
401 _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event)
403 E_Input_Backend *input;
404 Ecore_Event_Mouse_Move *ev;
406 if (!(input = edev->seat->input)) return;
408 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
410 if (edev->seat->ptr.ix < edev->mouse.minx)
411 edev->seat->ptr.dx = edev->seat->ptr.ix = edev->mouse.minx;
412 else if (edev->seat->ptr.ix >= (edev->mouse.minx + edev->mouse.maxw))
413 edev->seat->ptr.dx = edev->seat->ptr.ix = (edev->mouse.minx + edev->mouse.maxw - 1);
415 if (edev->seat->ptr.iy < edev->mouse.miny)
416 edev->seat->ptr.dy = edev->seat->ptr.iy = edev->mouse.miny;
417 else if (edev->seat->ptr.iy >= (edev->mouse.miny + edev->mouse.maxh))
418 edev->seat->ptr.dy = edev->seat->ptr.iy = (edev->mouse.miny + edev->mouse.maxh - 1);
420 edev->mouse.dx = edev->seat->ptr.dx;
421 edev->mouse.dy = edev->seat->ptr.dy;
423 ev->window = (Ecore_Window)input->dev->window;
424 ev->event_window = (Ecore_Window)input->dev->window;
425 ev->root_window = (Ecore_Window)input->dev->window;
426 if (event) ev->timestamp = libinput_event_pointer_get_time(event);
429 _device_modifiers_update(edev);
430 ev->modifiers = edev->xkb.modifiers;
432 ev->x = edev->seat->ptr.ix;
433 ev->y = edev->seat->ptr.iy;
437 ev->multi.device = edev->mt_slot;
438 ev->multi.radius = 1;
439 ev->multi.radius_x = 1;
440 ev->multi.radius_y = 1;
441 ev->multi.pressure = 1.0;
442 ev->multi.angle = 0.0;
445 ev->multi.root.x = ev->x;
446 ev->multi.root.y = ev->y;
447 ev->dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
449 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL);
453 _e_input_pointer_motion_post(E_Input_Evdev *edev)
455 _device_pointer_motion(edev, NULL);
459 _device_handle_pointer_motion(struct libinput_device *device, struct libinput_event_pointer *event)
464 if (!(edev = libinput_device_get_user_data(device)))
469 dx = libinput_event_pointer_get_dx(event);
470 dy = libinput_event_pointer_get_dy(event);
472 if (edev->seat->ptr.swap)
478 if (edev->seat->ptr.invert_x)
480 if (edev->seat->ptr.invert_y)
483 edev->seat->ptr.dx += dx;
484 edev->seat->ptr.dy += dy;
486 edev->mouse.dx = edev->seat->ptr.dx;
487 edev->mouse.dy = edev->seat->ptr.dy;
489 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
490 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
495 edev->seat->ptr.ix = edev->seat->ptr.dx;
496 edev->seat->ptr.iy = edev->seat->ptr.dy;
498 _device_pointer_motion(edev, event);
502 _device_handle_pointer_motion_absolute(struct libinput_device *device, struct libinput_event_pointer *event)
507 if (!(edev = libinput_device_get_user_data(device)))
512 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
514 edev->mouse.dx = edev->seat->ptr.dx =
515 libinput_event_pointer_get_absolute_x_transformed(event, w);
516 edev->mouse.dy = edev->seat->ptr.dy =
517 libinput_event_pointer_get_absolute_y_transformed(event, h);
519 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
520 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
525 edev->seat->ptr.ix = edev->seat->ptr.dx;
526 edev->seat->ptr.iy = edev->seat->ptr.dy;
527 _device_pointer_motion(edev, event);
531 _device_handle_button(struct libinput_device *device, struct libinput_event_pointer *event)
534 E_Input_Backend *input;
535 Ecore_Event_Mouse_Button *ev;
536 enum libinput_button_state state;
537 uint32_t button, timestamp;
539 if (!(edev = libinput_device_get_user_data(device)))
543 if (!(input = edev->seat->input))
548 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button))))
553 state = libinput_event_pointer_get_button_state(event);
554 button = libinput_event_pointer_get_button(event);
555 timestamp = libinput_event_pointer_get_time(event);
557 button = ((button & 0x00F) + 1);
558 if (button == 3) button = 2;
559 else if (button == 2) button = 3;
561 ev->window = (Ecore_Window)input->dev->window;
562 ev->event_window = (Ecore_Window)input->dev->window;
563 ev->root_window = (Ecore_Window)input->dev->window;
564 ev->timestamp = timestamp;
567 _device_modifiers_update(edev);
568 ev->modifiers = edev->xkb.modifiers;
570 ev->x = edev->seat->ptr.ix;
571 ev->y = edev->seat->ptr.iy;
575 ev->multi.device = edev->mt_slot;
576 ev->multi.radius = 1;
577 ev->multi.radius_x = 1;
578 ev->multi.radius_y = 1;
579 ev->multi.pressure = 1.0;
580 ev->multi.angle = 0.0;
583 ev->multi.root.x = ev->x;
584 ev->multi.root.y = ev->y;
585 ev->dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
589 unsigned int current;
592 edev->mouse.did_double = EINA_FALSE;
593 edev->mouse.did_triple = EINA_FALSE;
595 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
596 (button == edev->mouse.prev_button))
598 edev->mouse.did_double = EINA_TRUE;
599 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
600 (button == edev->mouse.last_button))
602 edev->mouse.did_triple = EINA_TRUE;
603 edev->mouse.prev = 0;
604 edev->mouse.last = 0;
609 edev->mouse.last = edev->mouse.prev;
610 edev->mouse.prev = current;
611 edev->mouse.last_button = edev->mouse.prev_button;
612 edev->mouse.prev_button = button;
615 ev->buttons = button;
617 if (edev->mouse.did_double)
618 ev->double_click = 1;
619 if (edev->mouse.did_triple)
620 ev->triple_click = 1;
623 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL);
625 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL);
629 _device_handle_axis(struct libinput_device *device, struct libinput_event_pointer *event)
632 E_Input_Backend *input;
633 Ecore_Event_Mouse_Wheel *ev;
635 enum libinput_pointer_axis axis;
637 if (!(edev = libinput_device_get_user_data(device)))
641 if (!(input = edev->seat->input))
646 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
651 timestamp = libinput_event_pointer_get_time(event);
653 ev->window = (Ecore_Window)input->dev->window;
654 ev->event_window = (Ecore_Window)input->dev->window;
655 ev->root_window = (Ecore_Window)input->dev->window;
656 ev->timestamp = timestamp;
659 _device_modifiers_update(edev);
660 ev->modifiers = edev->xkb.modifiers;
662 ev->x = edev->seat->ptr.ix;
663 ev->y = edev->seat->ptr.iy;
666 ev->dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
668 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
669 if (libinput_event_pointer_has_axis(event, axis))
670 ev->z = libinput_event_pointer_get_axis_value(event, axis);
672 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
673 if (libinput_event_pointer_has_axis(event, axis))
676 ev->z = libinput_event_pointer_get_axis_value(event, axis);
679 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, NULL, NULL);
683 _device_handle_touch_event_send(E_Input_Evdev *edev, struct libinput_event_touch *event, int state)
685 E_Input_Backend *input;
686 Ecore_Event_Mouse_Button *ev;
687 uint32_t timestamp, button = 0;
690 if (!(input = edev->seat->input)) return;
692 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) return;
694 timestamp = libinput_event_touch_get_time(event);
696 ev->window = (Ecore_Window)input->dev->window;
697 ev->event_window = (Ecore_Window)input->dev->window;
698 ev->root_window = (Ecore_Window)input->dev->window;
699 ev->timestamp = timestamp;
702 _device_modifiers_update(edev);
703 ev->modifiers = edev->xkb.modifiers;
705 ev->x = edev->seat->ptr.ix;
706 ev->y = edev->seat->ptr.iy;
710 ev->multi.device = edev->mt_slot;
711 ev->multi.radius = 1;
712 ev->multi.radius_x = 1;
713 ev->multi.radius_y = 1;
714 ev->multi.pressure = 1.0;
715 ev->multi.angle = 0.0;
716 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
717 if (libinput_event_get_type(libinput_event_touch_get_base_event(event))
718 == LIBINPUT_EVENT_TOUCH_DOWN)
720 if (libinput_event_touch_has_minor(event))
721 ev->multi.radius_x = libinput_event_touch_get_minor(event);
722 if (libinput_event_touch_has_major(event))
723 ev->multi.radius_y = libinput_event_touch_get_major(event);
724 if (libinput_event_touch_has_pressure(event))
725 ev->multi.pressure = libinput_event_touch_get_pressure(event);
726 if (libinput_event_touch_has_orientation(event))
727 ev->multi.angle = libinput_event_touch_get_orientation(event);
732 ev->multi.root.x = ev->x;
733 ev->multi.root.y = ev->y;
734 ev->dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
736 if (state == ECORE_EVENT_MOUSE_BUTTON_DOWN)
738 unsigned int current;
741 edev->mouse.did_double = EINA_FALSE;
742 edev->mouse.did_triple = EINA_FALSE;
744 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
745 (button == edev->mouse.prev_button))
747 edev->mouse.did_double = EINA_TRUE;
748 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
749 (button == edev->mouse.last_button))
751 edev->mouse.did_triple = EINA_TRUE;
752 edev->mouse.prev = 0;
753 edev->mouse.last = 0;
758 edev->mouse.last = edev->mouse.prev;
759 edev->mouse.prev = current;
760 edev->mouse.last_button = edev->mouse.prev_button;
761 edev->mouse.prev_button = button;
764 ev->buttons = ((button & 0x00F) + 1);
766 if (edev->mouse.did_double)
767 ev->double_click = 1;
768 if (edev->mouse.did_triple)
769 ev->triple_click = 1;
771 ecore_event_add(state, ev, NULL, NULL);
775 _device_handle_touch_motion_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
777 E_Input_Backend *input;
778 Ecore_Event_Mouse_Move *ev;
781 if (!(input = edev->seat->input)) return;
783 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
785 ev->window = (Ecore_Window)input->dev->window;
786 ev->event_window = (Ecore_Window)input->dev->window;
787 ev->root_window = (Ecore_Window)input->dev->window;
788 ev->timestamp = libinput_event_touch_get_time(event);
791 _device_modifiers_update(edev);
792 ev->modifiers = edev->xkb.modifiers;
795 ev->x = edev->seat->ptr.ix;
796 ev->y = edev->seat->ptr.iy;
800 ev->multi.device = edev->mt_slot;
801 ev->multi.radius = 1;
802 ev->multi.radius_x = 1;
803 ev->multi.radius_y = 1;
804 ev->multi.pressure = 1.0;
805 ev->multi.angle = 0.0;
806 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
807 if (libinput_event_touch_has_minor(event))
808 ev->multi.radius_x = libinput_event_touch_get_minor(event);
809 if (libinput_event_touch_has_major(event))
810 ev->multi.radius_y = libinput_event_touch_get_major(event);
811 if (libinput_event_touch_has_pressure(event))
812 ev->multi.pressure = libinput_event_touch_get_pressure(event);
813 if (libinput_event_touch_has_orientation(event))
814 ev->multi.angle = libinput_event_touch_get_orientation(event);
818 ev->multi.root.x = ev->x;
819 ev->multi.root.y = ev->y;
820 ev->dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
822 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL);
826 _device_handle_touch_down(struct libinput_device *device, struct libinput_event_touch *event)
831 if (!(edev = libinput_device_get_user_data(device)))
836 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
838 edev->mouse.dx = edev->seat->ptr.ix = edev->seat->ptr.dx =
839 libinput_event_touch_get_x_transformed(event, w);
840 edev->mouse.dy = edev->seat->ptr.iy = edev->seat->ptr.dy =
841 libinput_event_touch_get_y_transformed(event, h);
843 edev->mt_slot = libinput_event_touch_get_slot(event);
845 _device_handle_touch_motion_send(edev, event);
846 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_DOWN);
850 _device_handle_touch_motion(struct libinput_device *device, struct libinput_event_touch *event)
855 if (!(edev = libinput_device_get_user_data(device)))
860 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
862 edev->mouse.dx = edev->seat->ptr.dx =
863 libinput_event_touch_get_x_transformed(event, w);
864 edev->mouse.dy = edev->seat->ptr.dy =
865 libinput_event_touch_get_y_transformed(event, h);
867 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
868 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
873 edev->seat->ptr.ix = edev->seat->ptr.dx;
874 edev->seat->ptr.iy = edev->seat->ptr.dy;
876 edev->mt_slot = libinput_event_touch_get_slot(event);
878 _device_handle_touch_motion_send(edev, event);
882 _device_handle_touch_up(struct libinput_device *device, struct libinput_event_touch *event)
886 if (!(edev = libinput_device_get_user_data(device)))
891 edev->mt_slot = libinput_event_touch_get_slot(event);
892 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_UP);
896 _device_handle_touch_frame(struct libinput_device *device EINA_UNUSED, struct libinput_event_touch *event EINA_UNUSED)
898 /* DBG("Unhandled Touch Frame Event"); */
902 _e_input_aux_data_event_free(void *user_data EINA_UNUSED, void *ev)
904 Ecore_Event_Axis_Update *e = (Ecore_Event_Axis_Update *)ev;
911 _device_handle_touch_aux_data(struct libinput_device *device, struct libinput_event_touch_aux_data *event)
914 E_Input_Backend *input;
915 Ecore_Event_Axis_Update *ev;
918 if (libinput_event_touch_aux_data_get_type(event) != LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM &&
919 libinput_event_touch_aux_data_get_value(event) > 0)
922 if (!(edev = libinput_device_get_user_data(device))) goto end;
923 if (!(input = edev->seat->input)) goto end;
924 if (!(ev = calloc(1, sizeof(Ecore_Event_Axis_Update))))goto end;
926 ev->window = (Ecore_Window)input->dev->window;
927 ev->event_window = (Ecore_Window)input->dev->window;
928 ev->root_window = (Ecore_Window)input->dev->window;
929 ev->timestamp = libinput_event_touch_aux_data_get_time(event);
931 axis = (Ecore_Axis *)calloc(1, sizeof(Ecore_Axis));
934 axis->label = ECORE_AXIS_LABEL_TOUCH_PALM;
935 axis->value = libinput_event_touch_aux_data_get_value(event);
940 ecore_event_add(ECORE_EVENT_AXIS_UPDATE, ev, _e_input_aux_data_event_free, NULL);
947 _e_input_evdev_device_create(E_Input_Seat *seat, struct libinput_device *device)
951 E_Input_Backend *b_input;
953 EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
955 /* try to allocate space for new evdev */
956 if (!(edev = calloc(1, sizeof(E_Input_Evdev)))) return NULL;
959 edev->device = device;
960 edev->path = eina_stringshare_printf("%s/%s", e_input_base_dir_get(), libinput_device_get_sysname(device));
963 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
965 edev->caps |= E_INPUT_SEAT_KEYBOARD;
966 _device_keyboard_setup(edev);
969 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
971 edev->caps |= E_INPUT_SEAT_POINTER;
973 /* TODO: make this configurable */
974 edev->mouse.threshold = 250;
976 b_input = seat->input;
977 if (b_input->left_handed == EINA_TRUE)
979 if (libinput_device_config_left_handed_set(device, 1) !=
980 LIBINPUT_CONFIG_STATUS_SUCCESS)
982 WRN("Failed to set left hand mode about device: %s\n",
983 libinput_device_get_name(device));
988 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
991 edev->caps |= E_INPUT_SEAT_TOUCH;
992 palm_code = libinput_device_touch_aux_data_get_code(LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM);
993 if (libinput_device_touch_has_aux_data(device, palm_code))
995 libinput_device_touch_set_aux_data(device, palm_code);
999 libinput_device_set_user_data(device, edev);
1000 libinput_device_ref(device);
1002 /* configure device */
1003 _device_configure(edev);
1009 _e_input_evdev_device_destroy(E_Input_Evdev *edev)
1011 EINA_SAFETY_ON_NULL_RETURN(edev);
1013 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
1015 if (edev->xkb.state) xkb_state_unref(edev->xkb.state);
1016 if (edev->xkb.keymap) xkb_map_unref(edev->xkb.keymap);
1019 if (edev->path) eina_stringshare_del(edev->path);
1020 if (edev->device) libinput_device_unref(edev->device);
1021 if (edev->key_remap_hash) eina_hash_free(edev->key_remap_hash);
1027 _e_input_evdev_event_process(struct libinput_event *event)
1029 struct libinput_device *device;
1030 Eina_Bool ret = EINA_TRUE;
1032 device = libinput_event_get_device(event);
1033 switch (libinput_event_get_type(event))
1035 case LIBINPUT_EVENT_KEYBOARD_KEY:
1036 _device_handle_key(device, libinput_event_get_keyboard_event(event));
1038 case LIBINPUT_EVENT_POINTER_MOTION:
1039 _device_handle_pointer_motion(device,
1040 libinput_event_get_pointer_event(event));
1042 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
1043 _device_handle_pointer_motion_absolute(device,
1044 libinput_event_get_pointer_event(event));
1046 case LIBINPUT_EVENT_POINTER_BUTTON:
1047 _device_handle_button(device, libinput_event_get_pointer_event(event));
1049 case LIBINPUT_EVENT_POINTER_AXIS:
1050 _device_handle_axis(device, libinput_event_get_pointer_event(event));
1052 case LIBINPUT_EVENT_TOUCH_DOWN:
1053 _device_handle_touch_down(device, libinput_event_get_touch_event(event));
1055 case LIBINPUT_EVENT_TOUCH_MOTION:
1056 _device_handle_touch_motion(device,
1057 libinput_event_get_touch_event(event));
1059 case LIBINPUT_EVENT_TOUCH_UP:
1060 _device_handle_touch_up(device, libinput_event_get_touch_event(event));
1062 case LIBINPUT_EVENT_TOUCH_FRAME:
1063 _device_handle_touch_frame(device, libinput_event_get_touch_event(event));
1065 case LIBINPUT_EVENT_TOUCH_AUX_DATA:
1066 _device_handle_touch_aux_data(device, libinput_event_get_touch_aux_data(event));
1077 * @brief Set the axis size of the given device.
1079 * @param dev The device to set the axis size to.
1080 * @param w The width of the axis.
1081 * @param h The height of the axis.
1083 * This function sets set the width @p w and height @p h of the axis
1084 * of device @p dev. If @p dev is a relative input device, a width and
1085 * height must set for it. If its absolute set the ioctl correctly, if
1086 * not, unsupported device.
1089 e_input_evdev_axis_size_set(E_Input_Evdev *edev, int w, int h)
1091 const char *sysname;
1096 enum libinput_config_status status;
1098 EINA_SAFETY_ON_NULL_RETURN(edev);
1099 EINA_SAFETY_ON_TRUE_RETURN((w == 0) || (h == 0));
1101 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
1102 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
1105 sysname = libinput_device_get_sysname(edev->device);
1107 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
1108 if (eina_list_count(devices) < 1) return;
1110 EINA_LIST_FREE(devices, device)
1112 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
1114 (sscanf(vals, "%f %f %f %f %f %f",
1115 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
1122 libinput_device_config_calibration_set_matrix(edev->device, cal);
1124 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
1125 ERR("Failed to apply calibration");
1128 eina_stringshare_del(device);
1134 e_input_evdev_name_get(E_Input_Evdev *evdev)
1136 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
1137 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
1139 return libinput_device_get_name(evdev->device);
1142 EINTERN const char *
1143 e_input_evdev_sysname_get(E_Input_Evdev *evdev)
1145 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
1146 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
1148 return libinput_device_get_sysname(evdev->device);
1152 e_input_evdev_key_remap_enable(E_Input_Evdev *edev, Eina_Bool enable)
1154 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
1155 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
1157 edev->key_remap_enabled = enable;
1159 if (enable == EINA_FALSE && edev->key_remap_hash)
1161 eina_hash_free(edev->key_remap_hash);
1162 edev->key_remap_hash = NULL;
1169 e_input_evdev_key_remap_set(E_Input_Evdev *edev, int *from_keys, int *to_keys, int num)
1173 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
1174 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
1175 EINA_SAFETY_ON_NULL_RETURN_VAL(from_keys, EINA_FALSE);
1176 EINA_SAFETY_ON_NULL_RETURN_VAL(to_keys, EINA_FALSE);
1177 EINA_SAFETY_ON_TRUE_RETURN_VAL(num <= 0, EINA_FALSE);
1178 EINA_SAFETY_ON_TRUE_RETURN_VAL(!edev->key_remap_enabled, EINA_FALSE);
1180 if (edev->key_remap_hash == NULL)
1181 edev->key_remap_hash = eina_hash_int32_new(NULL);
1183 if (edev->key_remap_hash == NULL)
1185 ERR("Failed to set remap key information : creating a hash is failed.");
1189 for (i = 0; i < num ; i++)
1191 if (!from_keys[i] || !to_keys[i])
1193 ERR("Failed to set remap key information : given arguments are invalid.");
1198 for (i = 0; i < num ; i++)
1200 eina_hash_add(edev->key_remap_hash, &from_keys[i], (void *)(intptr_t)to_keys[i]);
1207 e_input_evdev_wheel_click_angle_get(E_Input_Evdev *dev)
1209 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, -1);
1210 return libinput_device_config_scroll_get_wheel_click_angle(dev->device);
1214 e_input_evdev_touch_calibration_set(E_Input_Evdev *edev, float matrix[6])
1216 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
1217 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
1219 if (!libinput_device_config_calibration_has_matrix(edev->device) ||
1220 !libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_TOUCH))
1223 if (libinput_device_config_calibration_set_matrix(edev->device, matrix) !=
1224 LIBINPUT_CONFIG_STATUS_SUCCESS)
1226 WRN("Failed to set input transformation about device: %s\n",
1227 libinput_device_get_name(edev->device));