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);
373 e->keyname = (char *)(e + 1);
374 e->key = e->keyname + strlen(keyname) + 1;
375 e->compose = strlen(compose) ? e->key + strlen(key) + 1 : NULL;
376 e->string = e->compose;
378 strncpy((char *)e->keyname, keyname, strlen(keyname));
379 strncpy((char *)e->key, key, strlen(key));
380 if (strlen(compose)) strncpy((char *)e->compose, compose, strlen(compose));
382 e->window = (Ecore_Window)input->dev->window;
383 e->event_window = (Ecore_Window)input->dev->window;
384 e->root_window = (Ecore_Window)input->dev->window;
385 e->timestamp = timestamp;
390 _device_modifiers_update(edev);
392 e->modifiers = edev->xkb.modifiers;
393 e->dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
396 ecore_event_add(ECORE_EVENT_KEY_DOWN, e, NULL, NULL);
398 ecore_event_add(ECORE_EVENT_KEY_UP, e, NULL, NULL);
404 _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event)
406 E_Input_Backend *input;
407 Ecore_Event_Mouse_Move *ev;
409 if (!(input = edev->seat->input)) return;
411 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
413 if (edev->seat->ptr.ix < edev->mouse.minx)
414 edev->seat->ptr.dx = edev->seat->ptr.ix = edev->mouse.minx;
415 else if (edev->seat->ptr.ix >= (edev->mouse.minx + edev->mouse.maxw))
416 edev->seat->ptr.dx = edev->seat->ptr.ix = (edev->mouse.minx + edev->mouse.maxw - 1);
418 if (edev->seat->ptr.iy < edev->mouse.miny)
419 edev->seat->ptr.dy = edev->seat->ptr.iy = edev->mouse.miny;
420 else if (edev->seat->ptr.iy >= (edev->mouse.miny + edev->mouse.maxh))
421 edev->seat->ptr.dy = edev->seat->ptr.iy = (edev->mouse.miny + edev->mouse.maxh - 1);
423 edev->mouse.dx = edev->seat->ptr.dx;
424 edev->mouse.dy = edev->seat->ptr.dy;
426 ev->window = (Ecore_Window)input->dev->window;
427 ev->event_window = (Ecore_Window)input->dev->window;
428 ev->root_window = (Ecore_Window)input->dev->window;
429 if (event) ev->timestamp = libinput_event_pointer_get_time(event);
432 _device_modifiers_update(edev);
433 ev->modifiers = edev->xkb.modifiers;
435 ev->x = edev->seat->ptr.ix;
436 ev->y = edev->seat->ptr.iy;
440 ev->multi.device = edev->mt_slot;
441 ev->multi.radius = 1;
442 ev->multi.radius_x = 1;
443 ev->multi.radius_y = 1;
444 ev->multi.pressure = 1.0;
445 ev->multi.angle = 0.0;
448 ev->multi.root.x = ev->x;
449 ev->multi.root.y = ev->y;
450 ev->dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
452 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL);
456 _e_input_pointer_motion_post(E_Input_Evdev *edev)
458 _device_pointer_motion(edev, NULL);
462 _device_handle_pointer_motion(struct libinput_device *device, struct libinput_event_pointer *event)
467 if (!(edev = libinput_device_get_user_data(device)))
472 dx = libinput_event_pointer_get_dx(event);
473 dy = libinput_event_pointer_get_dy(event);
475 if (edev->seat->ptr.swap)
481 if (edev->seat->ptr.invert_x)
483 if (edev->seat->ptr.invert_y)
486 edev->seat->ptr.dx += dx;
487 edev->seat->ptr.dy += dy;
489 edev->mouse.dx = edev->seat->ptr.dx;
490 edev->mouse.dy = edev->seat->ptr.dy;
492 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
493 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
498 edev->seat->ptr.ix = edev->seat->ptr.dx;
499 edev->seat->ptr.iy = edev->seat->ptr.dy;
501 _device_pointer_motion(edev, event);
505 _device_handle_pointer_motion_absolute(struct libinput_device *device, struct libinput_event_pointer *event)
510 if (!(edev = libinput_device_get_user_data(device)))
515 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
517 edev->mouse.dx = edev->seat->ptr.dx =
518 libinput_event_pointer_get_absolute_x_transformed(event, w);
519 edev->mouse.dy = edev->seat->ptr.dy =
520 libinput_event_pointer_get_absolute_y_transformed(event, h);
522 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
523 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
528 edev->seat->ptr.ix = edev->seat->ptr.dx;
529 edev->seat->ptr.iy = edev->seat->ptr.dy;
530 _device_pointer_motion(edev, event);
534 _device_handle_button(struct libinput_device *device, struct libinput_event_pointer *event)
537 E_Input_Backend *input;
538 Ecore_Event_Mouse_Button *ev;
539 enum libinput_button_state state;
540 uint32_t button, timestamp;
542 if (!(edev = libinput_device_get_user_data(device)))
546 if (!(input = edev->seat->input))
551 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button))))
556 state = libinput_event_pointer_get_button_state(event);
557 button = libinput_event_pointer_get_button(event);
558 timestamp = libinput_event_pointer_get_time(event);
560 button = ((button & 0x00F) + 1);
561 if (button == 3) button = 2;
562 else if (button == 2) button = 3;
564 ev->window = (Ecore_Window)input->dev->window;
565 ev->event_window = (Ecore_Window)input->dev->window;
566 ev->root_window = (Ecore_Window)input->dev->window;
567 ev->timestamp = timestamp;
570 _device_modifiers_update(edev);
571 ev->modifiers = edev->xkb.modifiers;
573 ev->x = edev->seat->ptr.ix;
574 ev->y = edev->seat->ptr.iy;
578 ev->multi.device = edev->mt_slot;
579 ev->multi.radius = 1;
580 ev->multi.radius_x = 1;
581 ev->multi.radius_y = 1;
582 ev->multi.pressure = 1.0;
583 ev->multi.angle = 0.0;
586 ev->multi.root.x = ev->x;
587 ev->multi.root.y = ev->y;
588 ev->dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
592 unsigned int current;
595 edev->mouse.did_double = EINA_FALSE;
596 edev->mouse.did_triple = EINA_FALSE;
598 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
599 (button == edev->mouse.prev_button))
601 edev->mouse.did_double = EINA_TRUE;
602 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
603 (button == edev->mouse.last_button))
605 edev->mouse.did_triple = EINA_TRUE;
606 edev->mouse.prev = 0;
607 edev->mouse.last = 0;
612 edev->mouse.last = edev->mouse.prev;
613 edev->mouse.prev = current;
614 edev->mouse.last_button = edev->mouse.prev_button;
615 edev->mouse.prev_button = button;
618 ev->buttons = button;
620 if (edev->mouse.did_double)
621 ev->double_click = 1;
622 if (edev->mouse.did_triple)
623 ev->triple_click = 1;
626 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL);
628 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL);
632 _device_handle_axis(struct libinput_device *device, struct libinput_event_pointer *event)
635 E_Input_Backend *input;
636 Ecore_Event_Mouse_Wheel *ev;
638 enum libinput_pointer_axis axis;
640 if (!(edev = libinput_device_get_user_data(device)))
644 if (!(input = edev->seat->input))
649 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
654 timestamp = libinput_event_pointer_get_time(event);
656 ev->window = (Ecore_Window)input->dev->window;
657 ev->event_window = (Ecore_Window)input->dev->window;
658 ev->root_window = (Ecore_Window)input->dev->window;
659 ev->timestamp = timestamp;
662 _device_modifiers_update(edev);
663 ev->modifiers = edev->xkb.modifiers;
665 ev->x = edev->seat->ptr.ix;
666 ev->y = edev->seat->ptr.iy;
669 ev->dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
671 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
672 if (libinput_event_pointer_has_axis(event, axis))
673 ev->z = libinput_event_pointer_get_axis_value(event, axis);
675 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
676 if (libinput_event_pointer_has_axis(event, axis))
679 ev->z = libinput_event_pointer_get_axis_value(event, axis);
682 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, NULL, NULL);
686 _device_handle_touch_event_send(E_Input_Evdev *edev, struct libinput_event_touch *event, int state)
688 E_Input_Backend *input;
689 Ecore_Event_Mouse_Button *ev;
690 uint32_t timestamp, button = 0;
693 if (!(input = edev->seat->input)) return;
695 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) return;
697 timestamp = libinput_event_touch_get_time(event);
699 ev->window = (Ecore_Window)input->dev->window;
700 ev->event_window = (Ecore_Window)input->dev->window;
701 ev->root_window = (Ecore_Window)input->dev->window;
702 ev->timestamp = timestamp;
705 _device_modifiers_update(edev);
706 ev->modifiers = edev->xkb.modifiers;
708 ev->x = edev->seat->ptr.ix;
709 ev->y = edev->seat->ptr.iy;
713 ev->multi.device = edev->mt_slot;
714 ev->multi.radius = 1;
715 ev->multi.radius_x = 1;
716 ev->multi.radius_y = 1;
717 ev->multi.pressure = 1.0;
718 ev->multi.angle = 0.0;
719 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
720 if (libinput_event_get_type(libinput_event_touch_get_base_event(event))
721 == LIBINPUT_EVENT_TOUCH_DOWN)
723 if (libinput_event_touch_has_minor(event))
724 ev->multi.radius_x = libinput_event_touch_get_minor(event);
725 if (libinput_event_touch_has_major(event))
726 ev->multi.radius_y = libinput_event_touch_get_major(event);
727 if (libinput_event_touch_has_pressure(event))
728 ev->multi.pressure = libinput_event_touch_get_pressure(event);
729 if (libinput_event_touch_has_orientation(event))
730 ev->multi.angle = libinput_event_touch_get_orientation(event);
735 ev->multi.root.x = ev->x;
736 ev->multi.root.y = ev->y;
737 ev->dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
739 if (state == ECORE_EVENT_MOUSE_BUTTON_DOWN)
741 unsigned int current;
744 edev->mouse.did_double = EINA_FALSE;
745 edev->mouse.did_triple = EINA_FALSE;
747 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
748 (button == edev->mouse.prev_button))
750 edev->mouse.did_double = EINA_TRUE;
751 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
752 (button == edev->mouse.last_button))
754 edev->mouse.did_triple = EINA_TRUE;
755 edev->mouse.prev = 0;
756 edev->mouse.last = 0;
761 edev->mouse.last = edev->mouse.prev;
762 edev->mouse.prev = current;
763 edev->mouse.last_button = edev->mouse.prev_button;
764 edev->mouse.prev_button = button;
767 ev->buttons = ((button & 0x00F) + 1);
769 if (edev->mouse.did_double)
770 ev->double_click = 1;
771 if (edev->mouse.did_triple)
772 ev->triple_click = 1;
774 ecore_event_add(state, ev, NULL, NULL);
778 _device_handle_touch_motion_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
780 E_Input_Backend *input;
781 Ecore_Event_Mouse_Move *ev;
784 if (!(input = edev->seat->input)) return;
786 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
788 ev->window = (Ecore_Window)input->dev->window;
789 ev->event_window = (Ecore_Window)input->dev->window;
790 ev->root_window = (Ecore_Window)input->dev->window;
791 ev->timestamp = libinput_event_touch_get_time(event);
794 _device_modifiers_update(edev);
795 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));