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;
109 if ((!edev) || (!edev->seat)) return;
110 if (!(input = edev->seat->input)) return;
111 if (!input->dev->xkb_ctx) return;
113 /* create keymap from xkb context */
114 edev->xkb.keymap = _e_input_device_cached_keymap_get(input->dev->xkb_ctx, NULL, 0);
115 if (!edev->xkb.keymap)
117 ERR("Failed to create keymap: %m");
121 /* create xkb state */
122 if (!(edev->xkb.state = xkb_state_new(edev->xkb.keymap)))
124 ERR("Failed to create xkb state: %m");
128 edev->xkb.ctrl_mask =
129 1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CTRL);
131 1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_ALT);
132 edev->xkb.shift_mask =
133 1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_SHIFT);
135 1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_LOGO);
136 edev->xkb.scroll_mask =
137 1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_SCROLL);
139 1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_NUM);
140 edev->xkb.caps_mask =
141 1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CAPS);
142 edev->xkb.altgr_mask =
143 1 << xkb_map_mod_get_index(edev->xkb.keymap, "ISO_Level3_Shift");
147 _device_keysym_translate(xkb_keysym_t keysym, unsigned int modifiers, char *buffer, int bytes)
149 unsigned long hbytes = 0;
152 if (!keysym) return 0;
153 hbytes = (keysym >> 8);
158 (((keysym >= XKB_KEY_BackSpace) && (keysym <= XKB_KEY_Clear)) ||
159 (keysym == XKB_KEY_Return) || (keysym == XKB_KEY_Escape) ||
160 (keysym == XKB_KEY_KP_Space) || (keysym == XKB_KEY_KP_Tab) ||
161 (keysym == XKB_KEY_KP_Enter) ||
162 ((keysym >= XKB_KEY_KP_Multiply) && (keysym <= XKB_KEY_KP_9)) ||
163 (keysym == XKB_KEY_KP_Equal) || (keysym == XKB_KEY_Delete))))))
166 if (keysym == XKB_KEY_KP_Space)
167 c = (XKB_KEY_space & 0x7F);
168 else if (hbytes == 0xFF)
173 if (modifiers & ECORE_EVENT_MODIFIER_CTRL)
175 if (((c >= '@') && (c < '\177')) || c == ' ')
179 else if ((c >= '3') && (c <= '7'))
191 _device_modifiers_update_device(E_Input_Evdev *edev, E_Input_Evdev *from)
195 edev->xkb.depressed =
196 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_DEPRESSED);
198 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LATCHED);
200 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LOCKED);
202 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_EFFECTIVE);
204 mask = (edev->xkb.depressed | edev->xkb.latched);
206 if (mask & from->xkb.ctrl_mask)
207 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_CTRL;
208 if (mask & from->xkb.alt_mask)
209 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALT;
210 if (mask & from->xkb.shift_mask)
211 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
212 if (mask & from->xkb.win_mask)
213 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_WIN;
214 if (mask & from->xkb.scroll_mask)
215 edev->xkb.modifiers |= ECORE_EVENT_LOCK_SCROLL;
216 if (mask & from->xkb.num_mask)
217 edev->xkb.modifiers |= ECORE_EVENT_LOCK_NUM;
218 if (mask & from->xkb.caps_mask)
219 edev->xkb.modifiers |= ECORE_EVENT_LOCK_CAPS;
220 if (mask & from->xkb.altgr_mask)
221 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALTGR;
225 _device_modifiers_update(E_Input_Evdev *edev)
230 edev->xkb.modifiers = 0;
232 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
233 _device_modifiers_update_device(edev, edev);
236 EINA_LIST_FOREACH(edev->seat->devices, l, ed)
238 if (!(ed->caps & E_INPUT_SEAT_KEYBOARD)) continue;
239 _device_modifiers_update_device(edev, ed);
246 _device_remapped_key_get(E_Input_Evdev *edev, int code)
250 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, code);
251 if (!edev->key_remap_enabled) return code;
252 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->key_remap_hash, code);
254 ret = eina_hash_find(edev->key_remap_hash, &code);
256 if (ret) code = (int)(intptr_t)ret;
262 e_input_evdev_get_ecore_device(const char *path, Ecore_Device_Class clas)
264 const Eina_List *dev_list = NULL;
266 Ecore_Device *dev = NULL;
267 const char *identifier;
269 if (!path) return NULL;
271 dev_list = ecore_device_list();
272 if (!dev_list) return NULL;
273 EINA_LIST_FOREACH(dev_list, l, dev)
276 identifier = ecore_device_identifier_get(dev);
277 if (!identifier) continue;
278 if ((ecore_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
285 _device_handle_key(struct libinput_device *device, struct libinput_event_keyboard *event)
288 E_Input_Backend *input;
290 uint32_t code, nsyms;
291 const xkb_keysym_t *syms;
292 enum libinput_key_state state;
294 xkb_keysym_t sym = XKB_KEY_NoSymbol;
295 char key[256], keyname[256], compose_buffer[256];
297 char *tmp = NULL, *compose = NULL;
299 if (!(edev = libinput_device_get_user_data(device)))
304 if (!(input = edev->seat->input))
309 timestamp = libinput_event_keyboard_get_time(event);
310 code = libinput_event_keyboard_get_key(event);
311 code = _device_remapped_key_get(edev, code) + 8;
312 state = libinput_event_keyboard_get_key_state(event);
313 key_count = libinput_event_keyboard_get_seat_key_count(event);
315 /* ignore key events that are not seat wide state changes */
316 if (((state == LIBINPUT_KEY_STATE_PRESSED) && (key_count != 1)) ||
317 ((state == LIBINPUT_KEY_STATE_RELEASED) && (key_count != 0)))
322 xkb_state_update_key(edev->xkb.state, code,
323 (state ? XKB_KEY_DOWN : XKB_KEY_UP));
325 /* get the keysym for this code */
326 nsyms = xkb_key_get_syms(edev->xkb.state, code, &syms);
327 if (nsyms == 1) sym = syms[0];
329 /* get the keyname for this sym */
330 memset(key, 0, sizeof(key));
331 xkb_keysym_get_name(sym, key, sizeof(key));
333 memset(keyname, 0, sizeof(keyname));
334 memcpy(keyname, key, sizeof(keyname));
336 if (keyname[0] == '\0')
337 snprintf(keyname, sizeof(keyname), "Keycode-%u", code);
339 /* if shift is active, we need to transform the key to lower */
340 if (xkb_state_mod_index_is_active(edev->xkb.state,
341 xkb_map_mod_get_index(edev->xkb.keymap,
343 XKB_STATE_MODS_EFFECTIVE))
345 if (keyname[0] != '\0')
346 keyname[0] = tolower(keyname[0]);
349 memset(compose_buffer, 0, sizeof(compose_buffer));
350 if (_device_keysym_translate(sym, edev->xkb.modifiers,
351 compose_buffer, sizeof(compose_buffer)))
353 compose = eina_str_convert("ISO8859-1", "UTF-8", compose_buffer);
356 ERR("E Input cannot convert input key string '%s' to UTF-8. "
357 "Is Eina built with iconv support?", compose_buffer);
363 if (!compose) compose = compose_buffer;
365 e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) +
366 ((compose[0] != '\0') ? strlen(compose) : 0) + 3);
372 e->keyname = (char *)(e + 1);
373 e->key = e->keyname + strlen(keyname) + 1;
374 e->compose = strlen(compose) ? e->key + strlen(key) + 1 : NULL;
375 e->string = e->compose;
377 strncpy((char *)e->keyname, keyname, strlen(keyname));
378 strncpy((char *)e->key, key, strlen(key));
379 if (strlen(compose)) strncpy((char *)e->compose, compose, strlen(compose));
381 e->window = (Ecore_Window)input->dev->window;
382 e->event_window = (Ecore_Window)input->dev->window;
383 e->root_window = (Ecore_Window)input->dev->window;
384 e->timestamp = timestamp;
389 _device_modifiers_update(edev);
391 e->modifiers = edev->xkb.modifiers;
392 e->dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
395 ecore_event_add(ECORE_EVENT_KEY_DOWN, e, NULL, NULL);
397 ecore_event_add(ECORE_EVENT_KEY_UP, e, NULL, NULL);
403 _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event)
405 E_Input_Backend *input;
406 Ecore_Event_Mouse_Move *ev;
408 if (!(input = edev->seat->input)) return;
410 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
412 if (edev->seat->ptr.ix < edev->mouse.minx)
413 edev->seat->ptr.dx = edev->seat->ptr.ix = edev->mouse.minx;
414 else if (edev->seat->ptr.ix >= (edev->mouse.minx + edev->mouse.maxw))
415 edev->seat->ptr.dx = edev->seat->ptr.ix = (edev->mouse.minx + edev->mouse.maxw - 1);
417 if (edev->seat->ptr.iy < edev->mouse.miny)
418 edev->seat->ptr.dy = edev->seat->ptr.iy = edev->mouse.miny;
419 else if (edev->seat->ptr.iy >= (edev->mouse.miny + edev->mouse.maxh))
420 edev->seat->ptr.dy = edev->seat->ptr.iy = (edev->mouse.miny + edev->mouse.maxh - 1);
422 edev->mouse.dx = edev->seat->ptr.dx;
423 edev->mouse.dy = edev->seat->ptr.dy;
425 ev->window = (Ecore_Window)input->dev->window;
426 ev->event_window = (Ecore_Window)input->dev->window;
427 ev->root_window = (Ecore_Window)input->dev->window;
428 if (event) ev->timestamp = libinput_event_pointer_get_time(event);
431 _device_modifiers_update(edev);
432 ev->modifiers = edev->xkb.modifiers;
434 ev->x = edev->seat->ptr.ix;
435 ev->y = edev->seat->ptr.iy;
439 ev->multi.device = edev->mt_slot;
440 ev->multi.radius = 1;
441 ev->multi.radius_x = 1;
442 ev->multi.radius_y = 1;
443 ev->multi.pressure = 1.0;
444 ev->multi.angle = 0.0;
447 ev->multi.root.x = ev->x;
448 ev->multi.root.y = ev->y;
449 ev->dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
451 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL);
455 _e_input_pointer_motion_post(E_Input_Evdev *edev)
457 _device_pointer_motion(edev, NULL);
461 _device_handle_pointer_motion(struct libinput_device *device, struct libinput_event_pointer *event)
466 if (!(edev = libinput_device_get_user_data(device)))
471 dx = libinput_event_pointer_get_dx(event);
472 dy = libinput_event_pointer_get_dy(event);
474 if (edev->seat->ptr.swap)
480 if (edev->seat->ptr.invert_x)
482 if (edev->seat->ptr.invert_y)
485 edev->seat->ptr.dx += dx;
486 edev->seat->ptr.dy += dy;
488 edev->mouse.dx = edev->seat->ptr.dx;
489 edev->mouse.dy = edev->seat->ptr.dy;
491 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
492 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
497 edev->seat->ptr.ix = edev->seat->ptr.dx;
498 edev->seat->ptr.iy = edev->seat->ptr.dy;
500 _device_pointer_motion(edev, event);
504 _device_handle_pointer_motion_absolute(struct libinput_device *device, struct libinput_event_pointer *event)
509 if (!(edev = libinput_device_get_user_data(device)))
514 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
516 edev->mouse.dx = edev->seat->ptr.dx =
517 libinput_event_pointer_get_absolute_x_transformed(event, w);
518 edev->mouse.dy = edev->seat->ptr.dy =
519 libinput_event_pointer_get_absolute_y_transformed(event, h);
521 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
522 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
527 edev->seat->ptr.ix = edev->seat->ptr.dx;
528 edev->seat->ptr.iy = edev->seat->ptr.dy;
529 _device_pointer_motion(edev, event);
533 _device_handle_button(struct libinput_device *device, struct libinput_event_pointer *event)
536 E_Input_Backend *input;
537 Ecore_Event_Mouse_Button *ev;
538 enum libinput_button_state state;
539 uint32_t button, timestamp;
541 if (!(edev = libinput_device_get_user_data(device)))
545 if (!(input = edev->seat->input))
550 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button))))
555 state = libinput_event_pointer_get_button_state(event);
556 button = libinput_event_pointer_get_button(event);
557 timestamp = libinput_event_pointer_get_time(event);
559 button = ((button & 0x00F) + 1);
560 if (button == 3) button = 2;
561 else if (button == 2) button = 3;
563 ev->window = (Ecore_Window)input->dev->window;
564 ev->event_window = (Ecore_Window)input->dev->window;
565 ev->root_window = (Ecore_Window)input->dev->window;
566 ev->timestamp = timestamp;
569 _device_modifiers_update(edev);
570 ev->modifiers = edev->xkb.modifiers;
572 ev->x = edev->seat->ptr.ix;
573 ev->y = edev->seat->ptr.iy;
577 ev->multi.device = edev->mt_slot;
578 ev->multi.radius = 1;
579 ev->multi.radius_x = 1;
580 ev->multi.radius_y = 1;
581 ev->multi.pressure = 1.0;
582 ev->multi.angle = 0.0;
585 ev->multi.root.x = ev->x;
586 ev->multi.root.y = ev->y;
587 ev->dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
591 unsigned int current;
594 edev->mouse.did_double = EINA_FALSE;
595 edev->mouse.did_triple = EINA_FALSE;
597 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
598 (button == edev->mouse.prev_button))
600 edev->mouse.did_double = EINA_TRUE;
601 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
602 (button == edev->mouse.last_button))
604 edev->mouse.did_triple = EINA_TRUE;
605 edev->mouse.prev = 0;
606 edev->mouse.last = 0;
611 edev->mouse.last = edev->mouse.prev;
612 edev->mouse.prev = current;
613 edev->mouse.last_button = edev->mouse.prev_button;
614 edev->mouse.prev_button = button;
617 ev->buttons = button;
619 if (edev->mouse.did_double)
620 ev->double_click = 1;
621 if (edev->mouse.did_triple)
622 ev->triple_click = 1;
625 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL);
627 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL);
631 _device_handle_axis(struct libinput_device *device, struct libinput_event_pointer *event)
634 E_Input_Backend *input;
635 Ecore_Event_Mouse_Wheel *ev;
637 enum libinput_pointer_axis axis;
639 if (!(edev = libinput_device_get_user_data(device)))
643 if (!(input = edev->seat->input))
648 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
653 timestamp = libinput_event_pointer_get_time(event);
655 ev->window = (Ecore_Window)input->dev->window;
656 ev->event_window = (Ecore_Window)input->dev->window;
657 ev->root_window = (Ecore_Window)input->dev->window;
658 ev->timestamp = timestamp;
661 _device_modifiers_update(edev);
662 ev->modifiers = edev->xkb.modifiers;
664 ev->x = edev->seat->ptr.ix;
665 ev->y = edev->seat->ptr.iy;
668 ev->dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
670 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
671 if (libinput_event_pointer_has_axis(event, axis))
672 ev->z = libinput_event_pointer_get_axis_value(event, axis);
674 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
675 if (libinput_event_pointer_has_axis(event, axis))
678 ev->z = libinput_event_pointer_get_axis_value(event, axis);
681 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, NULL, NULL);
685 _device_handle_touch_event_send(E_Input_Evdev *edev, struct libinput_event_touch *event, int state)
687 E_Input_Backend *input;
688 Ecore_Event_Mouse_Button *ev;
689 uint32_t timestamp, button = 0;
692 if (!(input = edev->seat->input)) return;
694 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) return;
696 timestamp = libinput_event_touch_get_time(event);
698 ev->window = (Ecore_Window)input->dev->window;
699 ev->event_window = (Ecore_Window)input->dev->window;
700 ev->root_window = (Ecore_Window)input->dev->window;
701 ev->timestamp = timestamp;
704 _device_modifiers_update(edev);
705 ev->modifiers = edev->xkb.modifiers;
707 ev->x = edev->seat->ptr.ix;
708 ev->y = edev->seat->ptr.iy;
712 ev->multi.device = edev->mt_slot;
713 ev->multi.radius = 1;
714 ev->multi.radius_x = 1;
715 ev->multi.radius_y = 1;
716 ev->multi.pressure = 1.0;
717 ev->multi.angle = 0.0;
718 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
719 if (libinput_event_get_type(libinput_event_touch_get_base_event(event))
720 == LIBINPUT_EVENT_TOUCH_DOWN)
722 if (libinput_event_touch_has_minor(event))
723 ev->multi.radius_x = libinput_event_touch_get_minor(event);
724 if (libinput_event_touch_has_major(event))
725 ev->multi.radius_y = libinput_event_touch_get_major(event);
726 if (libinput_event_touch_has_pressure(event))
727 ev->multi.pressure = libinput_event_touch_get_pressure(event);
728 if (libinput_event_touch_has_orientation(event))
729 ev->multi.angle = libinput_event_touch_get_orientation(event);
734 ev->multi.root.x = ev->x;
735 ev->multi.root.y = ev->y;
736 ev->dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
738 if (state == ECORE_EVENT_MOUSE_BUTTON_DOWN)
740 unsigned int current;
743 edev->mouse.did_double = EINA_FALSE;
744 edev->mouse.did_triple = EINA_FALSE;
746 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
747 (button == edev->mouse.prev_button))
749 edev->mouse.did_double = EINA_TRUE;
750 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
751 (button == edev->mouse.last_button))
753 edev->mouse.did_triple = EINA_TRUE;
754 edev->mouse.prev = 0;
755 edev->mouse.last = 0;
760 edev->mouse.last = edev->mouse.prev;
761 edev->mouse.prev = current;
762 edev->mouse.last_button = edev->mouse.prev_button;
763 edev->mouse.prev_button = button;
766 ev->buttons = ((button & 0x00F) + 1);
768 if (edev->mouse.did_double)
769 ev->double_click = 1;
770 if (edev->mouse.did_triple)
771 ev->triple_click = 1;
773 ecore_event_add(state, ev, NULL, NULL);
777 _device_handle_touch_motion_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
779 E_Input_Backend *input;
780 Ecore_Event_Mouse_Move *ev;
783 if (!(input = edev->seat->input)) return;
785 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
787 ev->window = (Ecore_Window)input->dev->window;
788 ev->event_window = (Ecore_Window)input->dev->window;
789 ev->root_window = (Ecore_Window)input->dev->window;
790 ev->timestamp = libinput_event_touch_get_time(event);
793 _device_modifiers_update(edev);
794 ev->modifiers = edev->xkb.modifiers;
797 ev->x = edev->seat->ptr.ix;
798 ev->y = edev->seat->ptr.iy;
802 ev->multi.device = edev->mt_slot;
803 ev->multi.radius = 1;
804 ev->multi.radius_x = 1;
805 ev->multi.radius_y = 1;
806 ev->multi.pressure = 1.0;
807 ev->multi.angle = 0.0;
808 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
809 if (libinput_event_touch_has_minor(event))
810 ev->multi.radius_x = libinput_event_touch_get_minor(event);
811 if (libinput_event_touch_has_major(event))
812 ev->multi.radius_y = libinput_event_touch_get_major(event);
813 if (libinput_event_touch_has_pressure(event))
814 ev->multi.pressure = libinput_event_touch_get_pressure(event);
815 if (libinput_event_touch_has_orientation(event))
816 ev->multi.angle = libinput_event_touch_get_orientation(event);
820 ev->multi.root.x = ev->x;
821 ev->multi.root.y = ev->y;
822 ev->dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
824 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL);
828 _device_handle_touch_down(struct libinput_device *device, struct libinput_event_touch *event)
833 if (!(edev = libinput_device_get_user_data(device)))
838 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
840 edev->mouse.dx = edev->seat->ptr.ix = edev->seat->ptr.dx =
841 libinput_event_touch_get_x_transformed(event, w);
842 edev->mouse.dy = edev->seat->ptr.iy = edev->seat->ptr.dy =
843 libinput_event_touch_get_y_transformed(event, h);
845 edev->mt_slot = libinput_event_touch_get_slot(event);
847 _device_handle_touch_motion_send(edev, event);
848 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_DOWN);
852 _device_handle_touch_motion(struct libinput_device *device, struct libinput_event_touch *event)
857 if (!(edev = libinput_device_get_user_data(device)))
862 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
864 edev->mouse.dx = edev->seat->ptr.dx =
865 libinput_event_touch_get_x_transformed(event, w);
866 edev->mouse.dy = edev->seat->ptr.dy =
867 libinput_event_touch_get_y_transformed(event, h);
869 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
870 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
875 edev->seat->ptr.ix = edev->seat->ptr.dx;
876 edev->seat->ptr.iy = edev->seat->ptr.dy;
878 edev->mt_slot = libinput_event_touch_get_slot(event);
880 _device_handle_touch_motion_send(edev, event);
884 _device_handle_touch_up(struct libinput_device *device, struct libinput_event_touch *event)
888 if (!(edev = libinput_device_get_user_data(device)))
893 edev->mt_slot = libinput_event_touch_get_slot(event);
894 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_UP);
898 _device_handle_touch_frame(struct libinput_device *device EINA_UNUSED, struct libinput_event_touch *event EINA_UNUSED)
900 /* DBG("Unhandled Touch Frame Event"); */
904 _e_input_aux_data_event_free(void *user_data EINA_UNUSED, void *ev)
906 Ecore_Event_Axis_Update *e = (Ecore_Event_Axis_Update *)ev;
913 _device_handle_touch_aux_data(struct libinput_device *device, struct libinput_event_touch_aux_data *event)
916 E_Input_Backend *input;
917 Ecore_Event_Axis_Update *ev;
920 if (libinput_event_touch_aux_data_get_type(event) != LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM &&
921 libinput_event_touch_aux_data_get_value(event) > 0)
924 if (!(edev = libinput_device_get_user_data(device))) goto end;
925 if (!(input = edev->seat->input)) goto end;
926 if (!(ev = calloc(1, sizeof(Ecore_Event_Axis_Update))))goto end;
928 ev->window = (Ecore_Window)input->dev->window;
929 ev->event_window = (Ecore_Window)input->dev->window;
930 ev->root_window = (Ecore_Window)input->dev->window;
931 ev->timestamp = libinput_event_touch_aux_data_get_time(event);
933 axis = (Ecore_Axis *)calloc(1, sizeof(Ecore_Axis));
936 axis->label = ECORE_AXIS_LABEL_TOUCH_PALM;
937 axis->value = libinput_event_touch_aux_data_get_value(event);
942 ecore_event_add(ECORE_EVENT_AXIS_UPDATE, ev, _e_input_aux_data_event_free, NULL);
949 _e_input_evdev_device_create(E_Input_Seat *seat, struct libinput_device *device)
952 E_Input_Backend *b_input;
954 EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
956 /* try to allocate space for new evdev */
957 if (!(edev = calloc(1, sizeof(E_Input_Evdev)))) return NULL;
960 edev->device = device;
961 edev->path = eina_stringshare_printf("%s/%s", e_input_base_dir_get(), libinput_device_get_sysname(device));
964 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
966 edev->caps |= E_INPUT_SEAT_KEYBOARD;
967 _device_keyboard_setup(edev);
970 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
972 edev->caps |= E_INPUT_SEAT_POINTER;
974 /* TODO: make this configurable */
975 edev->mouse.threshold = 250;
977 b_input = seat->input;
978 if (b_input->left_handed == EINA_TRUE)
980 if (libinput_device_config_left_handed_set(device, 1) !=
981 LIBINPUT_CONFIG_STATUS_SUCCESS)
983 WRN("Failed to set left hand mode about device: %s\n",
984 libinput_device_get_name(device));
989 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
992 edev->caps |= E_INPUT_SEAT_TOUCH;
993 palm_code = libinput_device_touch_aux_data_get_code(LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM);
994 if (libinput_device_touch_has_aux_data(device, palm_code))
996 libinput_device_touch_set_aux_data(device, palm_code);
1000 libinput_device_set_user_data(device, edev);
1001 libinput_device_ref(device);
1003 /* configure device */
1004 _device_configure(edev);
1010 _e_input_evdev_device_destroy(E_Input_Evdev *edev)
1012 EINA_SAFETY_ON_NULL_RETURN(edev);
1014 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
1016 if (edev->xkb.state) xkb_state_unref(edev->xkb.state);
1017 if (edev->xkb.keymap) xkb_map_unref(edev->xkb.keymap);
1020 if (edev->path) eina_stringshare_del(edev->path);
1021 if (edev->device) libinput_device_unref(edev->device);
1022 if (edev->key_remap_hash) eina_hash_free(edev->key_remap_hash);
1028 _e_input_evdev_event_process(struct libinput_event *event)
1030 struct libinput_device *device;
1031 Eina_Bool ret = EINA_TRUE;
1033 device = libinput_event_get_device(event);
1034 switch (libinput_event_get_type(event))
1036 case LIBINPUT_EVENT_KEYBOARD_KEY:
1037 _device_handle_key(device, libinput_event_get_keyboard_event(event));
1039 case LIBINPUT_EVENT_POINTER_MOTION:
1040 _device_handle_pointer_motion(device,
1041 libinput_event_get_pointer_event(event));
1043 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
1044 _device_handle_pointer_motion_absolute(device,
1045 libinput_event_get_pointer_event(event));
1047 case LIBINPUT_EVENT_POINTER_BUTTON:
1048 _device_handle_button(device, libinput_event_get_pointer_event(event));
1050 case LIBINPUT_EVENT_POINTER_AXIS:
1051 _device_handle_axis(device, libinput_event_get_pointer_event(event));
1053 case LIBINPUT_EVENT_TOUCH_DOWN:
1054 _device_handle_touch_down(device, libinput_event_get_touch_event(event));
1056 case LIBINPUT_EVENT_TOUCH_MOTION:
1057 _device_handle_touch_motion(device,
1058 libinput_event_get_touch_event(event));
1060 case LIBINPUT_EVENT_TOUCH_UP:
1061 _device_handle_touch_up(device, libinput_event_get_touch_event(event));
1063 case LIBINPUT_EVENT_TOUCH_FRAME:
1064 _device_handle_touch_frame(device, libinput_event_get_touch_event(event));
1066 case LIBINPUT_EVENT_TOUCH_AUX_DATA:
1067 _device_handle_touch_aux_data(device, libinput_event_get_touch_aux_data(event));
1078 * @brief Set the axis size of the given device.
1080 * @param dev The device to set the axis size to.
1081 * @param w The width of the axis.
1082 * @param h The height of the axis.
1084 * This function sets set the width @p w and height @p h of the axis
1085 * of device @p dev. If @p dev is a relative input device, a width and
1086 * height must set for it. If its absolute set the ioctl correctly, if
1087 * not, unsupported device.
1090 e_input_evdev_axis_size_set(E_Input_Evdev *edev, int w, int h)
1092 const char *sysname;
1097 enum libinput_config_status status;
1099 EINA_SAFETY_ON_NULL_RETURN(edev);
1100 EINA_SAFETY_ON_TRUE_RETURN((w == 0) || (h == 0));
1102 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
1103 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
1106 sysname = libinput_device_get_sysname(edev->device);
1108 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
1109 if (eina_list_count(devices) < 1) return;
1111 EINA_LIST_FREE(devices, device)
1113 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
1115 (sscanf(vals, "%f %f %f %f %f %f",
1116 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
1123 libinput_device_config_calibration_set_matrix(edev->device, cal);
1125 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
1126 ERR("Failed to apply calibration");
1129 eina_stringshare_del(device);
1135 e_input_evdev_name_get(E_Input_Evdev *evdev)
1137 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
1138 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
1140 return libinput_device_get_name(evdev->device);
1143 EINTERN const char *
1144 e_input_evdev_sysname_get(E_Input_Evdev *evdev)
1146 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
1147 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
1149 return libinput_device_get_sysname(evdev->device);
1153 e_input_evdev_key_remap_enable(E_Input_Evdev *edev, Eina_Bool enable)
1155 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
1156 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
1158 edev->key_remap_enabled = enable;
1160 if (enable == EINA_FALSE && edev->key_remap_hash)
1162 eina_hash_free(edev->key_remap_hash);
1163 edev->key_remap_hash = NULL;
1170 e_input_evdev_key_remap_set(E_Input_Evdev *edev, int *from_keys, int *to_keys, int num)
1174 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
1175 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
1176 EINA_SAFETY_ON_NULL_RETURN_VAL(from_keys, EINA_FALSE);
1177 EINA_SAFETY_ON_NULL_RETURN_VAL(to_keys, EINA_FALSE);
1178 EINA_SAFETY_ON_TRUE_RETURN_VAL(num <= 0, EINA_FALSE);
1179 EINA_SAFETY_ON_TRUE_RETURN_VAL(!edev->key_remap_enabled, EINA_FALSE);
1181 if (edev->key_remap_hash == NULL)
1182 edev->key_remap_hash = eina_hash_int32_new(NULL);
1184 if (edev->key_remap_hash == NULL)
1186 ERR("Failed to set remap key information : creating a hash is failed.");
1190 for (i = 0; i < num ; i++)
1192 if (!from_keys[i] || !to_keys[i])
1194 ERR("Failed to set remap key information : given arguments are invalid.");
1199 for (i = 0; i < num ; i++)
1201 eina_hash_add(edev->key_remap_hash, &from_keys[i], (void *)(intptr_t)to_keys[i]);
1208 e_input_evdev_wheel_click_angle_get(E_Input_Evdev *dev)
1210 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, -1);
1211 return libinput_device_config_scroll_get_wheel_click_angle(dev->device);
1215 e_input_evdev_touch_calibration_set(E_Input_Evdev *edev, float matrix[6])
1217 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
1218 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
1220 if (!libinput_device_config_calibration_has_matrix(edev->device) ||
1221 !libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_TOUCH))
1224 if (libinput_device_config_calibration_set_matrix(edev->device, matrix) !=
1225 LIBINPUT_CONFIG_STATUS_SUCCESS)
1227 WRN("Failed to set input transformation about device: %s\n",
1228 libinput_device_get_name(edev->device));