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;
50 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
51 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
54 sysname = libinput_device_get_sysname(edev->device);
56 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
57 if (eina_list_count(devices) < 1) return;
59 EINA_LIST_FREE(devices, device)
61 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
63 (sscanf(vals, "%f %f %f %f %f %f",
64 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
71 libinput_device_config_calibration_set_matrix(edev->device, cal);
73 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
74 ERR("Failed to apply calibration");
77 eina_stringshare_del(device);
83 _device_configure(E_Input_Evdev *edev)
85 if (libinput_device_config_tap_get_finger_count(edev->device) > 0)
87 Eina_Bool tap = EINA_FALSE;
89 tap = libinput_device_config_tap_get_default_enabled(edev->device);
90 libinput_device_config_tap_set_enabled(edev->device, tap);
93 _device_calibration_set(edev);
97 _device_keyboard_setup(E_Input_Evdev *edev)
99 E_Input_Backend *input;
101 if ((!edev) || (!edev->seat)) return;
102 if (!(input = edev->seat->input)) return;
103 if (!input->dev->xkb_ctx) return;
105 /* create keymap from xkb context */
106 edev->xkb.keymap = _e_input_device_cached_keymap_get(input->dev->xkb_ctx, NULL, 0);
107 if (!edev->xkb.keymap)
109 ERR("Failed to create keymap: %m");
113 /* create xkb state */
114 if (!(edev->xkb.state = xkb_state_new(edev->xkb.keymap)))
116 ERR("Failed to create xkb state: %m");
120 edev->xkb.ctrl_mask =
121 1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CTRL);
123 1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_ALT);
124 edev->xkb.shift_mask =
125 1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_SHIFT);
127 1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_LOGO);
128 edev->xkb.scroll_mask =
129 1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_SCROLL);
131 1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_NUM);
132 edev->xkb.caps_mask =
133 1 << xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CAPS);
134 edev->xkb.altgr_mask =
135 1 << xkb_map_mod_get_index(edev->xkb.keymap, "ISO_Level3_Shift");
139 _device_keysym_translate(xkb_keysym_t keysym, unsigned int modifiers, char *buffer, int bytes)
141 unsigned long hbytes = 0;
144 if (!keysym) return 0;
145 hbytes = (keysym >> 8);
150 (((keysym >= XKB_KEY_BackSpace) && (keysym <= XKB_KEY_Clear)) ||
151 (keysym == XKB_KEY_Return) || (keysym == XKB_KEY_Escape) ||
152 (keysym == XKB_KEY_KP_Space) || (keysym == XKB_KEY_KP_Tab) ||
153 (keysym == XKB_KEY_KP_Enter) ||
154 ((keysym >= XKB_KEY_KP_Multiply) && (keysym <= XKB_KEY_KP_9)) ||
155 (keysym == XKB_KEY_KP_Equal) || (keysym == XKB_KEY_Delete))))))
158 if (keysym == XKB_KEY_KP_Space)
159 c = (XKB_KEY_space & 0x7F);
160 else if (hbytes == 0xFF)
165 if (modifiers & ECORE_EVENT_MODIFIER_CTRL)
167 if (((c >= '@') && (c < '\177')) || c == ' ')
171 else if ((c >= '3') && (c <= '7'))
183 _device_modifiers_update_device(E_Input_Evdev *edev, E_Input_Evdev *from)
187 edev->xkb.depressed =
188 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_DEPRESSED);
190 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LATCHED);
192 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LOCKED);
194 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_EFFECTIVE);
196 mask = (edev->xkb.depressed | edev->xkb.latched);
198 if (mask & from->xkb.ctrl_mask)
199 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_CTRL;
200 if (mask & from->xkb.alt_mask)
201 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALT;
202 if (mask & from->xkb.shift_mask)
203 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
204 if (mask & from->xkb.win_mask)
205 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_WIN;
206 if (mask & from->xkb.scroll_mask)
207 edev->xkb.modifiers |= ECORE_EVENT_LOCK_SCROLL;
208 if (mask & from->xkb.num_mask)
209 edev->xkb.modifiers |= ECORE_EVENT_LOCK_NUM;
210 if (mask & from->xkb.caps_mask)
211 edev->xkb.modifiers |= ECORE_EVENT_LOCK_CAPS;
212 if (mask & from->xkb.altgr_mask)
213 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALTGR;
217 _device_modifiers_update(E_Input_Evdev *edev)
219 edev->xkb.modifiers = 0;
221 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
222 _device_modifiers_update_device(edev, edev);
228 EINA_LIST_FOREACH(edev->seat->devices, l, ed)
230 if (!(ed->caps & E_INPUT_SEAT_KEYBOARD)) continue;
231 _device_modifiers_update_device(edev, ed);
238 _device_remapped_key_get(E_Input_Evdev *edev, int code)
242 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, code);
243 if (!edev->key_remap_enabled) return code;
244 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->key_remap_hash, code);
246 ret = eina_hash_find(edev->key_remap_hash, &code);
248 if (ret) code = (int)(intptr_t)ret;
254 e_input_evdev_get_ecore_device(const char *path, Ecore_Device_Class clas)
256 const Eina_List *dev_list = NULL;
258 Ecore_Device *dev = NULL;
259 const char *identifier;
261 if (!path) return NULL;
263 dev_list = ecore_device_list();
264 if (!dev_list) return NULL;
265 EINA_LIST_FOREACH(dev_list, l, dev)
268 identifier = ecore_device_identifier_get(dev);
269 if (!identifier) continue;
270 if ((ecore_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
277 _device_handle_key(struct libinput_device *device, struct libinput_event_keyboard *event)
280 E_Input_Backend *input;
282 uint32_t code, nsyms;
283 const xkb_keysym_t *syms;
284 enum libinput_key_state state;
286 xkb_keysym_t sym = XKB_KEY_NoSymbol;
287 char key[256], keyname[256], compose_buffer[256];
289 char *tmp = NULL, *compose = NULL;
291 if (!(edev = libinput_device_get_user_data(device)))
296 if (!(input = edev->seat->input))
301 timestamp = libinput_event_keyboard_get_time(event);
302 code = libinput_event_keyboard_get_key(event);
303 code = _device_remapped_key_get(edev, code) + 8;
304 state = libinput_event_keyboard_get_key_state(event);
305 key_count = libinput_event_keyboard_get_seat_key_count(event);
307 /* ignore key events that are not seat wide state changes */
308 if (((state == LIBINPUT_KEY_STATE_PRESSED) && (key_count != 1)) ||
309 ((state == LIBINPUT_KEY_STATE_RELEASED) && (key_count != 0)))
314 xkb_state_update_key(edev->xkb.state, code,
315 (state ? XKB_KEY_DOWN : XKB_KEY_UP));
317 /* get the keysym for this code */
318 nsyms = xkb_key_get_syms(edev->xkb.state, code, &syms);
319 if (nsyms == 1) sym = syms[0];
321 /* get the keyname for this sym */
322 memset(key, 0, sizeof(key));
323 xkb_keysym_get_name(sym, key, sizeof(key));
325 memset(keyname, 0, sizeof(keyname));
326 memcpy(keyname, key, sizeof(keyname));
328 if (keyname[0] == '\0')
329 snprintf(keyname, sizeof(keyname), "Keycode-%u", code);
331 /* if shift is active, we need to transform the key to lower */
332 if (xkb_state_mod_index_is_active(edev->xkb.state,
333 xkb_map_mod_get_index(edev->xkb.keymap,
335 XKB_STATE_MODS_EFFECTIVE))
337 if (keyname[0] != '\0')
338 keyname[0] = tolower(keyname[0]);
341 memset(compose_buffer, 0, sizeof(compose_buffer));
342 if (_device_keysym_translate(sym, edev->xkb.modifiers,
343 compose_buffer, sizeof(compose_buffer)))
345 compose = eina_str_convert("ISO8859-1", "UTF-8", compose_buffer);
348 ERR("E Input cannot convert input key string '%s' to UTF-8. "
349 "Is Eina built with iconv support?", compose_buffer);
355 if (!compose) compose = compose_buffer;
357 e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) +
358 ((compose[0] != '\0') ? strlen(compose) : 0) + 3);
364 e->keyname = (char *)(e + 1);
365 e->key = e->keyname + strlen(keyname) + 1;
366 e->compose = strlen(compose) ? e->key + strlen(key) + 1 : NULL;
367 e->string = e->compose;
369 strncpy((char *)e->keyname, keyname, strlen(keyname));
370 strncpy((char *)e->key, key, strlen(key));
371 if (strlen(compose)) strncpy((char *)e->compose, compose, strlen(compose));
373 e->window = (Ecore_Window)input->dev->window;
374 e->event_window = (Ecore_Window)input->dev->window;
375 e->root_window = (Ecore_Window)input->dev->window;
376 e->timestamp = timestamp;
381 _device_modifiers_update(edev);
383 e->modifiers = edev->xkb.modifiers;
384 e->dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
387 ecore_event_add(ECORE_EVENT_KEY_DOWN, e, NULL, NULL);
389 ecore_event_add(ECORE_EVENT_KEY_UP, e, NULL, NULL);
395 _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event)
397 E_Input_Backend *input;
398 Ecore_Event_Mouse_Move *ev;
400 if (!(input = edev->seat->input)) return;
402 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
404 if (edev->seat->ptr.ix < edev->mouse.minx)
405 edev->seat->ptr.dx = edev->seat->ptr.ix = edev->mouse.minx;
406 else if (edev->seat->ptr.ix >= (edev->mouse.minx + edev->mouse.maxw))
407 edev->seat->ptr.dx = edev->seat->ptr.ix = (edev->mouse.minx + edev->mouse.maxw - 1);
409 if (edev->seat->ptr.iy < edev->mouse.miny)
410 edev->seat->ptr.dy = edev->seat->ptr.iy = edev->mouse.miny;
411 else if (edev->seat->ptr.iy >= (edev->mouse.miny + edev->mouse.maxh))
412 edev->seat->ptr.dy = edev->seat->ptr.iy = (edev->mouse.miny + edev->mouse.maxh - 1);
414 edev->mouse.dx = edev->seat->ptr.dx;
415 edev->mouse.dy = edev->seat->ptr.dy;
417 ev->window = (Ecore_Window)input->dev->window;
418 ev->event_window = (Ecore_Window)input->dev->window;
419 ev->root_window = (Ecore_Window)input->dev->window;
420 if (event) ev->timestamp = libinput_event_pointer_get_time(event);
423 _device_modifiers_update(edev);
424 ev->modifiers = edev->xkb.modifiers;
426 ev->x = edev->seat->ptr.ix;
427 ev->y = edev->seat->ptr.iy;
431 ev->multi.device = edev->mt_slot;
432 ev->multi.radius = 1;
433 ev->multi.radius_x = 1;
434 ev->multi.radius_y = 1;
435 ev->multi.pressure = 1.0;
436 ev->multi.angle = 0.0;
439 ev->multi.root.x = ev->x;
440 ev->multi.root.y = ev->y;
441 ev->dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
443 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL);
447 _e_input_pointer_motion_post(E_Input_Evdev *edev)
449 _device_pointer_motion(edev, NULL);
453 _device_handle_pointer_motion(struct libinput_device *device, struct libinput_event_pointer *event)
458 if (!(edev = libinput_device_get_user_data(device)))
463 dx = libinput_event_pointer_get_dx(event);
464 dy = libinput_event_pointer_get_dy(event);
466 if (edev->seat->ptr.swap)
472 if (edev->seat->ptr.invert_x)
474 if (edev->seat->ptr.invert_y)
477 edev->seat->ptr.dx += dx;
478 edev->seat->ptr.dy += dy;
480 edev->mouse.dx = edev->seat->ptr.dx;
481 edev->mouse.dy = edev->seat->ptr.dy;
483 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
484 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
489 edev->seat->ptr.ix = edev->seat->ptr.dx;
490 edev->seat->ptr.iy = edev->seat->ptr.dy;
492 _device_pointer_motion(edev, event);
496 _device_handle_pointer_motion_absolute(struct libinput_device *device, struct libinput_event_pointer *event)
501 if (!(edev = libinput_device_get_user_data(device)))
506 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
508 edev->mouse.dx = edev->seat->ptr.dx =
509 libinput_event_pointer_get_absolute_x_transformed(event, w);
510 edev->mouse.dy = edev->seat->ptr.dy =
511 libinput_event_pointer_get_absolute_y_transformed(event, h);
513 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
514 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
519 edev->seat->ptr.ix = edev->seat->ptr.dx;
520 edev->seat->ptr.iy = edev->seat->ptr.dy;
521 _device_pointer_motion(edev, event);
525 _device_handle_button(struct libinput_device *device, struct libinput_event_pointer *event)
528 E_Input_Backend *input;
529 Ecore_Event_Mouse_Button *ev;
530 enum libinput_button_state state;
531 uint32_t button, timestamp;
533 if (!(edev = libinput_device_get_user_data(device)))
537 if (!(input = edev->seat->input))
542 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button))))
547 state = libinput_event_pointer_get_button_state(event);
548 button = libinput_event_pointer_get_button(event);
549 timestamp = libinput_event_pointer_get_time(event);
551 button = ((button & 0x00F) + 1);
552 if (button == 3) button = 2;
553 else if (button == 2) button = 3;
555 ev->window = (Ecore_Window)input->dev->window;
556 ev->event_window = (Ecore_Window)input->dev->window;
557 ev->root_window = (Ecore_Window)input->dev->window;
558 ev->timestamp = timestamp;
561 _device_modifiers_update(edev);
562 ev->modifiers = edev->xkb.modifiers;
564 ev->x = edev->seat->ptr.ix;
565 ev->y = edev->seat->ptr.iy;
569 ev->multi.device = edev->mt_slot;
570 ev->multi.radius = 1;
571 ev->multi.radius_x = 1;
572 ev->multi.radius_y = 1;
573 ev->multi.pressure = 1.0;
574 ev->multi.angle = 0.0;
577 ev->multi.root.x = ev->x;
578 ev->multi.root.y = ev->y;
579 ev->dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
583 unsigned int current;
586 edev->mouse.did_double = EINA_FALSE;
587 edev->mouse.did_triple = EINA_FALSE;
589 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
590 (button == edev->mouse.prev_button))
592 edev->mouse.did_double = EINA_TRUE;
593 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
594 (button == edev->mouse.last_button))
596 edev->mouse.did_triple = EINA_TRUE;
597 edev->mouse.prev = 0;
598 edev->mouse.last = 0;
603 edev->mouse.last = edev->mouse.prev;
604 edev->mouse.prev = current;
605 edev->mouse.last_button = edev->mouse.prev_button;
606 edev->mouse.prev_button = button;
609 ev->buttons = button;
611 if (edev->mouse.did_double)
612 ev->double_click = 1;
613 if (edev->mouse.did_triple)
614 ev->triple_click = 1;
617 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL);
619 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL);
623 _device_handle_axis(struct libinput_device *device, struct libinput_event_pointer *event)
626 E_Input_Backend *input;
627 Ecore_Event_Mouse_Wheel *ev;
629 enum libinput_pointer_axis axis;
631 if (!(edev = libinput_device_get_user_data(device)))
635 if (!(input = edev->seat->input))
640 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
645 timestamp = libinput_event_pointer_get_time(event);
647 ev->window = (Ecore_Window)input->dev->window;
648 ev->event_window = (Ecore_Window)input->dev->window;
649 ev->root_window = (Ecore_Window)input->dev->window;
650 ev->timestamp = timestamp;
653 _device_modifiers_update(edev);
654 ev->modifiers = edev->xkb.modifiers;
656 ev->x = edev->seat->ptr.ix;
657 ev->y = edev->seat->ptr.iy;
660 ev->dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
662 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
663 if (libinput_event_pointer_has_axis(event, axis))
664 ev->z = libinput_event_pointer_get_axis_value(event, axis);
666 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
667 if (libinput_event_pointer_has_axis(event, axis))
670 ev->z = libinput_event_pointer_get_axis_value(event, axis);
673 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, NULL, NULL);
677 _device_handle_touch_event_send(E_Input_Evdev *edev, struct libinput_event_touch *event, int state)
679 E_Input_Backend *input;
680 Ecore_Event_Mouse_Button *ev;
681 uint32_t timestamp, button = 0;
684 if (!(input = edev->seat->input)) return;
686 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) return;
688 timestamp = libinput_event_touch_get_time(event);
690 ev->window = (Ecore_Window)input->dev->window;
691 ev->event_window = (Ecore_Window)input->dev->window;
692 ev->root_window = (Ecore_Window)input->dev->window;
693 ev->timestamp = timestamp;
696 _device_modifiers_update(edev);
697 ev->modifiers = edev->xkb.modifiers;
699 ev->x = edev->seat->ptr.ix;
700 ev->y = edev->seat->ptr.iy;
704 ev->multi.device = edev->mt_slot;
705 ev->multi.radius = 1;
706 ev->multi.radius_x = 1;
707 ev->multi.radius_y = 1;
708 ev->multi.pressure = 1.0;
709 ev->multi.angle = 0.0;
710 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
711 if (libinput_event_get_type(libinput_event_touch_get_base_event(event))
712 == LIBINPUT_EVENT_TOUCH_DOWN)
714 if (libinput_event_touch_has_minor(event))
715 ev->multi.radius_x = libinput_event_touch_get_minor(event);
716 if (libinput_event_touch_has_major(event))
717 ev->multi.radius_y = libinput_event_touch_get_major(event);
718 if (libinput_event_touch_has_pressure(event))
719 ev->multi.pressure = libinput_event_touch_get_pressure(event);
720 if (libinput_event_touch_has_orientation(event))
721 ev->multi.angle = libinput_event_touch_get_orientation(event);
726 ev->multi.root.x = ev->x;
727 ev->multi.root.y = ev->y;
728 ev->dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
730 if (state == ECORE_EVENT_MOUSE_BUTTON_DOWN)
732 unsigned int current;
735 edev->mouse.did_double = EINA_FALSE;
736 edev->mouse.did_triple = EINA_FALSE;
738 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
739 (button == edev->mouse.prev_button))
741 edev->mouse.did_double = EINA_TRUE;
742 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
743 (button == edev->mouse.last_button))
745 edev->mouse.did_triple = EINA_TRUE;
746 edev->mouse.prev = 0;
747 edev->mouse.last = 0;
752 edev->mouse.last = edev->mouse.prev;
753 edev->mouse.prev = current;
754 edev->mouse.last_button = edev->mouse.prev_button;
755 edev->mouse.prev_button = button;
758 ev->buttons = ((button & 0x00F) + 1);
760 if (edev->mouse.did_double)
761 ev->double_click = 1;
762 if (edev->mouse.did_triple)
763 ev->triple_click = 1;
765 ecore_event_add(state, ev, NULL, NULL);
769 _device_handle_touch_motion_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
771 E_Input_Backend *input;
772 Ecore_Event_Mouse_Move *ev;
775 if (!(input = edev->seat->input)) return;
777 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
779 ev->window = (Ecore_Window)input->dev->window;
780 ev->event_window = (Ecore_Window)input->dev->window;
781 ev->root_window = (Ecore_Window)input->dev->window;
782 ev->timestamp = libinput_event_touch_get_time(event);
785 _device_modifiers_update(edev);
786 ev->modifiers = edev->xkb.modifiers;
789 ev->x = edev->seat->ptr.ix;
790 ev->y = edev->seat->ptr.iy;
794 ev->multi.device = edev->mt_slot;
795 ev->multi.radius = 1;
796 ev->multi.radius_x = 1;
797 ev->multi.radius_y = 1;
798 ev->multi.pressure = 1.0;
799 ev->multi.angle = 0.0;
800 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
801 if (libinput_event_touch_has_minor(event))
802 ev->multi.radius_x = libinput_event_touch_get_minor(event);
803 if (libinput_event_touch_has_major(event))
804 ev->multi.radius_y = libinput_event_touch_get_major(event);
805 if (libinput_event_touch_has_pressure(event))
806 ev->multi.pressure = libinput_event_touch_get_pressure(event);
807 if (libinput_event_touch_has_orientation(event))
808 ev->multi.angle = libinput_event_touch_get_orientation(event);
812 ev->multi.root.x = ev->x;
813 ev->multi.root.y = ev->y;
814 ev->dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
816 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL);
820 _device_handle_touch_down(struct libinput_device *device, struct libinput_event_touch *event)
825 if (!(edev = libinput_device_get_user_data(device)))
830 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
832 edev->mouse.dx = edev->seat->ptr.ix = edev->seat->ptr.dx =
833 libinput_event_touch_get_x_transformed(event, w);
834 edev->mouse.dy = edev->seat->ptr.iy = edev->seat->ptr.dy =
835 libinput_event_touch_get_y_transformed(event, h);
837 edev->mt_slot = libinput_event_touch_get_slot(event);
839 _device_handle_touch_motion_send(edev, event);
840 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_DOWN);
844 _device_handle_touch_motion(struct libinput_device *device, struct libinput_event_touch *event)
849 if (!(edev = libinput_device_get_user_data(device)))
854 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
856 edev->mouse.dx = edev->seat->ptr.dx =
857 libinput_event_touch_get_x_transformed(event, w);
858 edev->mouse.dy = edev->seat->ptr.dy =
859 libinput_event_touch_get_y_transformed(event, h);
861 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
862 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
867 edev->seat->ptr.ix = edev->seat->ptr.dx;
868 edev->seat->ptr.iy = edev->seat->ptr.dy;
870 edev->mt_slot = libinput_event_touch_get_slot(event);
872 _device_handle_touch_motion_send(edev, event);
876 _device_handle_touch_up(struct libinput_device *device, struct libinput_event_touch *event)
880 if (!(edev = libinput_device_get_user_data(device)))
885 edev->mt_slot = libinput_event_touch_get_slot(event);
886 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_UP);
890 _device_handle_touch_frame(struct libinput_device *device EINA_UNUSED, struct libinput_event_touch *event EINA_UNUSED)
892 /* DBG("Unhandled Touch Frame Event"); */
896 _e_input_aux_data_event_free(void *user_data EINA_UNUSED, void *ev)
898 Ecore_Event_Axis_Update *e = (Ecore_Event_Axis_Update *)ev;
905 _device_handle_touch_aux_data(struct libinput_device *device, struct libinput_event_touch_aux_data *event)
908 E_Input_Backend *input;
909 Ecore_Event_Axis_Update *ev;
912 if (libinput_event_touch_aux_data_get_type(event) != LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM &&
913 libinput_event_touch_aux_data_get_value(event) > 0)
916 if (!(edev = libinput_device_get_user_data(device))) goto end;
917 if (!(input = edev->seat->input)) goto end;
918 if (!(ev = calloc(1, sizeof(Ecore_Event_Axis_Update))))goto end;
920 ev->window = (Ecore_Window)input->dev->window;
921 ev->event_window = (Ecore_Window)input->dev->window;
922 ev->root_window = (Ecore_Window)input->dev->window;
923 ev->timestamp = libinput_event_touch_aux_data_get_time(event);
925 axis = (Ecore_Axis *)calloc(1, sizeof(Ecore_Axis));
928 axis->label = ECORE_AXIS_LABEL_TOUCH_PALM;
929 axis->value = libinput_event_touch_aux_data_get_value(event);
934 ecore_event_add(ECORE_EVENT_AXIS_UPDATE, ev, _e_input_aux_data_event_free, NULL);
941 _e_input_evdev_device_create(E_Input_Seat *seat, struct libinput_device *device)
945 E_Input_Backend *b_input;
947 EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
949 /* try to allocate space for new evdev */
950 if (!(edev = calloc(1, sizeof(E_Input_Evdev)))) return NULL;
953 edev->device = device;
954 edev->path = eina_stringshare_add(libinput_device_get_sysname(device));
959 devices = eeze_udev_find_by_filter("input", NULL, edev->path);
960 if (eina_list_count(devices) >= 1)
963 const char *dev, *name;
965 EINA_LIST_FOREACH(devices, l, dev)
967 name = eeze_udev_syspath_get_devname(dev);
968 if (name && strstr(name, edev->path))
970 eina_stringshare_replace(&edev->path, eeze_udev_syspath_get_devpath(dev));
975 EINA_LIST_FREE(devices, dev)
976 eina_stringshare_del(dev);
980 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
982 edev->caps |= E_INPUT_SEAT_KEYBOARD;
983 _device_keyboard_setup(edev);
986 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
988 edev->caps |= E_INPUT_SEAT_POINTER;
990 /* TODO: make this configurable */
991 edev->mouse.threshold = 250;
993 b_input = seat->input;
994 if (b_input->left_handed == EINA_TRUE)
996 if (libinput_device_config_left_handed_set(device, 1) !=
997 LIBINPUT_CONFIG_STATUS_SUCCESS)
999 WRN("Failed to set left hand mode about device: %s\n",
1000 libinput_device_get_name(device));
1005 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
1008 edev->caps |= E_INPUT_SEAT_TOUCH;
1009 palm_code = libinput_device_touch_aux_data_get_code(LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM);
1010 if (libinput_device_touch_has_aux_data(device, palm_code))
1012 libinput_device_touch_set_aux_data(device, palm_code);
1016 libinput_device_set_user_data(device, edev);
1017 libinput_device_ref(device);
1019 /* configure device */
1020 _device_configure(edev);
1026 _e_input_evdev_device_destroy(E_Input_Evdev *edev)
1028 EINA_SAFETY_ON_NULL_RETURN(edev);
1030 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
1032 if (edev->xkb.state) xkb_state_unref(edev->xkb.state);
1033 if (edev->xkb.keymap) xkb_map_unref(edev->xkb.keymap);
1036 if (edev->path) eina_stringshare_del(edev->path);
1037 if (edev->device) libinput_device_unref(edev->device);
1038 if (edev->key_remap_hash) eina_hash_free(edev->key_remap_hash);
1044 _e_input_evdev_event_process(struct libinput_event *event)
1046 struct libinput_device *device;
1047 Eina_Bool ret = EINA_TRUE;
1049 device = libinput_event_get_device(event);
1050 switch (libinput_event_get_type(event))
1052 case LIBINPUT_EVENT_KEYBOARD_KEY:
1053 _device_handle_key(device, libinput_event_get_keyboard_event(event));
1055 case LIBINPUT_EVENT_POINTER_MOTION:
1056 _device_handle_pointer_motion(device,
1057 libinput_event_get_pointer_event(event));
1059 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
1060 _device_handle_pointer_motion_absolute(device,
1061 libinput_event_get_pointer_event(event));
1063 case LIBINPUT_EVENT_POINTER_BUTTON:
1064 _device_handle_button(device, libinput_event_get_pointer_event(event));
1066 case LIBINPUT_EVENT_POINTER_AXIS:
1067 _device_handle_axis(device, libinput_event_get_pointer_event(event));
1069 case LIBINPUT_EVENT_TOUCH_DOWN:
1070 _device_handle_touch_down(device, libinput_event_get_touch_event(event));
1072 case LIBINPUT_EVENT_TOUCH_MOTION:
1073 _device_handle_touch_motion(device,
1074 libinput_event_get_touch_event(event));
1076 case LIBINPUT_EVENT_TOUCH_UP:
1077 _device_handle_touch_up(device, libinput_event_get_touch_event(event));
1079 case LIBINPUT_EVENT_TOUCH_FRAME:
1080 _device_handle_touch_frame(device, libinput_event_get_touch_event(event));
1082 case LIBINPUT_EVENT_TOUCH_AUX_DATA:
1083 _device_handle_touch_aux_data(device, libinput_event_get_touch_aux_data(event));
1094 * @brief Set the axis size of the given device.
1096 * @param dev The device to set the axis size to.
1097 * @param w The width of the axis.
1098 * @param h The height of the axis.
1100 * This function sets set the width @p w and height @p h of the axis
1101 * of device @p dev. If @p dev is a relative input device, a width and
1102 * height must set for it. If its absolute set the ioctl correctly, if
1103 * not, unsupported device.
1106 e_input_evdev_axis_size_set(E_Input_Evdev *edev, int w, int h)
1108 const char *sysname;
1113 enum libinput_config_status status;
1115 EINA_SAFETY_ON_NULL_RETURN(edev);
1116 EINA_SAFETY_ON_TRUE_RETURN((w == 0) || (h == 0));
1118 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
1119 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
1122 sysname = libinput_device_get_sysname(edev->device);
1124 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
1125 if (eina_list_count(devices) < 1) return;
1127 EINA_LIST_FREE(devices, device)
1129 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
1131 (sscanf(vals, "%f %f %f %f %f %f",
1132 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
1139 libinput_device_config_calibration_set_matrix(edev->device, cal);
1141 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
1142 ERR("Failed to apply calibration");
1145 eina_stringshare_del(device);
1151 e_input_evdev_name_get(E_Input_Evdev *evdev)
1153 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
1154 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
1156 return libinput_device_get_name(evdev->device);
1159 EINTERN const char *
1160 e_input_evdev_sysname_get(E_Input_Evdev *evdev)
1162 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
1163 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
1165 return libinput_device_get_sysname(evdev->device);
1169 e_input_evdev_key_remap_enable(E_Input_Evdev *edev, Eina_Bool enable)
1171 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
1172 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
1174 edev->key_remap_enabled = enable;
1176 if (enable == EINA_FALSE && edev->key_remap_hash)
1178 eina_hash_free(edev->key_remap_hash);
1179 edev->key_remap_hash = NULL;
1186 e_input_evdev_key_remap_set(E_Input_Evdev *edev, int *from_keys, int *to_keys, int num)
1190 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
1191 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
1192 EINA_SAFETY_ON_NULL_RETURN_VAL(from_keys, EINA_FALSE);
1193 EINA_SAFETY_ON_NULL_RETURN_VAL(to_keys, EINA_FALSE);
1194 EINA_SAFETY_ON_TRUE_RETURN_VAL(num <= 0, EINA_FALSE);
1195 EINA_SAFETY_ON_TRUE_RETURN_VAL(!edev->key_remap_enabled, EINA_FALSE);
1197 if (edev->key_remap_hash == NULL)
1198 edev->key_remap_hash = eina_hash_int32_new(NULL);
1200 if (edev->key_remap_hash == NULL)
1202 ERR("Failed to set remap key information : creating a hash is failed.");
1206 for (i = 0; i < num ; i++)
1208 if (!from_keys[i] || !to_keys[i])
1210 ERR("Failed to set remap key information : given arguments are invalid.");
1215 for (i = 0; i < num ; i++)
1217 eina_hash_add(edev->key_remap_hash, &from_keys[i], (void *)(intptr_t)to_keys[i]);
1224 e_input_evdev_wheel_click_angle_get(E_Input_Evdev *dev)
1226 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, -1);
1227 return libinput_device_config_scroll_get_wheel_click_angle(dev->device);
1231 e_input_evdev_touch_calibration_set(E_Input_Evdev *edev, float matrix[6])
1233 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
1234 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
1236 if (!libinput_device_config_calibration_has_matrix(edev->device) ||
1237 !libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_TOUCH))
1240 if (libinput_device_config_calibration_set_matrix(edev->device, matrix) !=
1241 LIBINPUT_CONFIG_STATUS_SUCCESS)
1243 WRN("Failed to set input transformation about device: %s\n",
1244 libinput_device_get_name(edev->device));