2 #include "e_input_private.h"
4 static void _device_modifiers_update(E_Input_Evdev *edev);
7 _device_calibration_set(E_Input_Evdev *edev)
13 output = e_comp_screen_primary_output_get(e_comp->e_comp_screen);
14 e_output_size_get(output, &w, &h);
18 edev->mouse.minx = edev->mouse.miny = 0;
22 if (libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
24 edev->seat->ptr.dx = (double)(w / 2);
25 edev->seat->ptr.dy = (double)(h / 2);
26 edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
27 edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
28 edev->mouse.dx = edev->seat->ptr.dx;
29 edev->mouse.dy = edev->seat->ptr.dy;
31 if (output->config.rotation == 90 || output->config.rotation == 270)
33 temp = edev->mouse.minx;
34 edev->mouse.minx = edev->mouse.miny;
35 edev->mouse.miny = temp;
37 temp = edev->mouse.maxw;
38 edev->mouse.maxw = edev->mouse.maxh;
39 edev->mouse.maxh = temp;
45 #ifdef _F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
51 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
52 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
55 sysname = libinput_device_get_sysname(edev->device);
57 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
58 if (eina_list_count(devices) < 1) return;
60 #ifdef _F_E_INPUT_USE_WL_CALIBRATION_
62 enum libinput_config_status status;
64 EINA_LIST_FREE(devices, device)
66 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
68 (sscanf(vals, "%f %f %f %f %f %f",
69 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
76 libinput_device_config_calibration_set_matrix(edev->device, cal);
78 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
79 ERR("Failed to apply calibration");
82 eina_stringshare_del(device);
85 #endif//_F_E_INPUT_USE_WL_CALIBRATION_
86 #endif//_F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
91 _device_configure(E_Input_Evdev *edev)
93 if (libinput_device_config_tap_get_finger_count(edev->device) > 0)
95 Eina_Bool tap = EINA_FALSE;
97 tap = libinput_device_config_tap_get_default_enabled(edev->device);
98 libinput_device_config_tap_set_enabled(edev->device, tap);
101 _device_calibration_set(edev);
105 _device_keyboard_setup(E_Input_Evdev *edev)
107 E_Input_Backend *input;
108 xkb_mod_index_t xkb_idx;
110 if ((!edev) || (!edev->seat)) return;
111 if (!(input = edev->seat->input)) return;
112 if (!input->dev->xkb_ctx) return;
114 /* create keymap from xkb context */
115 edev->xkb.keymap = _e_input_device_cached_keymap_get(input->dev->xkb_ctx, NULL, 0);
116 if (!edev->xkb.keymap)
118 ERR("Failed to create keymap: %m");
122 /* create xkb state */
123 if (!(edev->xkb.state = xkb_state_new(edev->xkb.keymap)))
125 ERR("Failed to create xkb state: %m");
129 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CTRL);
130 if (xkb_idx != XKB_MOD_INVALID)
131 edev->xkb.ctrl_mask = 1 << xkb_idx;
133 edev->xkb.ctrl_mask = 0;
135 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_ALT);
136 if (xkb_idx != XKB_MOD_INVALID)
137 edev->xkb.alt_mask = 1 << xkb_idx;
139 edev->xkb.alt_mask = 0;
141 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_SHIFT);
142 if (xkb_idx != XKB_MOD_INVALID)
143 edev->xkb.shift_mask = 1 << xkb_idx;
145 edev->xkb.shift_mask = 0;
147 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_LOGO);
148 if (xkb_idx != XKB_MOD_INVALID)
149 edev->xkb.win_mask = 1 << xkb_idx;
151 edev->xkb.win_mask = 0;
153 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_SCROLL);
154 if (xkb_idx != XKB_MOD_INVALID)
155 edev->xkb.scroll_mask = 1 << xkb_idx;
157 edev->xkb.scroll_mask = 0;
159 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_NUM);
160 if (xkb_idx != XKB_MOD_INVALID)
161 edev->xkb.num_mask = 1 << xkb_idx;
163 edev->xkb.num_mask = 0;
165 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CAPS);
166 if (xkb_idx != XKB_MOD_INVALID)
167 edev->xkb.caps_mask = 1 << xkb_idx;
169 edev->xkb.caps_mask = 0;
171 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, "ISO_Level3_Shift");
172 if (xkb_idx != XKB_MOD_INVALID)
173 edev->xkb.altgr_mask = 1 << xkb_idx;
175 edev->xkb.altgr_mask = 0;
179 _device_keysym_translate(xkb_keysym_t keysym, unsigned int modifiers, char *buffer, int bytes)
181 unsigned long hbytes = 0;
184 if (!keysym) return 0;
185 hbytes = (keysym >> 8);
190 (((keysym >= XKB_KEY_BackSpace) && (keysym <= XKB_KEY_Clear)) ||
191 (keysym == XKB_KEY_Return) || (keysym == XKB_KEY_Escape) ||
192 (keysym == XKB_KEY_KP_Space) || (keysym == XKB_KEY_KP_Tab) ||
193 (keysym == XKB_KEY_KP_Enter) ||
194 ((keysym >= XKB_KEY_KP_Multiply) && (keysym <= XKB_KEY_KP_9)) ||
195 (keysym == XKB_KEY_KP_Equal) || (keysym == XKB_KEY_Delete))))))
198 if (keysym == XKB_KEY_KP_Space)
199 c = (XKB_KEY_space & 0x7F);
200 else if (hbytes == 0xFF)
205 if (modifiers & ECORE_EVENT_MODIFIER_CTRL)
207 if (((c >= '@') && (c < '\177')) || c == ' ')
211 else if ((c >= '3') && (c <= '7'))
223 _device_modifiers_update_device(E_Input_Evdev *edev, E_Input_Evdev *from)
227 edev->xkb.depressed =
228 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_DEPRESSED);
230 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LATCHED);
232 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LOCKED);
234 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_EFFECTIVE);
236 mask = (edev->xkb.depressed | edev->xkb.latched);
238 if (mask & from->xkb.ctrl_mask)
239 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_CTRL;
240 if (mask & from->xkb.alt_mask)
241 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALT;
242 if (mask & from->xkb.shift_mask)
243 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
244 if (mask & from->xkb.win_mask)
245 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_WIN;
246 if (mask & from->xkb.scroll_mask)
247 edev->xkb.modifiers |= ECORE_EVENT_LOCK_SCROLL;
248 if (mask & from->xkb.num_mask)
249 edev->xkb.modifiers |= ECORE_EVENT_LOCK_NUM;
250 if (mask & from->xkb.caps_mask)
251 edev->xkb.modifiers |= ECORE_EVENT_LOCK_CAPS;
252 if (mask & from->xkb.altgr_mask)
253 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALTGR;
257 _device_modifiers_update(E_Input_Evdev *edev)
262 edev->xkb.modifiers = 0;
264 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
265 _device_modifiers_update_device(edev, edev);
268 EINA_LIST_FOREACH(edev->seat->devices, l, ed)
270 if (!(ed->caps & E_INPUT_SEAT_KEYBOARD)) continue;
271 _device_modifiers_update_device(edev, ed);
278 _device_remapped_key_get(E_Input_Evdev *edev, int code)
282 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, code);
283 if (!edev->key_remap_enabled) return code;
284 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->key_remap_hash, code);
286 ret = eina_hash_find(edev->key_remap_hash, &code);
288 if (ret) code = (int)(intptr_t)ret;
294 e_input_evdev_get_ecore_device(const char *path, Ecore_Device_Class clas)
296 const Eina_List *dev_list = NULL;
298 Ecore_Device *dev = NULL;
299 const char *identifier;
301 if (!path) return NULL;
303 dev_list = ecore_device_list();
304 if (!dev_list) return NULL;
305 EINA_LIST_FOREACH(dev_list, l, dev)
308 identifier = ecore_device_identifier_get(dev);
309 if (!identifier) continue;
310 if ((ecore_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
317 _e_input_event_mouse_move_cb_free(void *data EINA_UNUSED, void *event)
319 Ecore_Event_Mouse_Move *ev = event;
321 if (ev->dev) ecore_device_unref(ev->dev);
327 _e_input_event_mouse_wheel_cb_free(void *data EINA_UNUSED, void *event)
329 Ecore_Event_Mouse_Wheel *ev = event;
331 if (ev->dev) ecore_device_unref(ev->dev);
337 _e_input_event_mouse_button_cb_free(void *data EINA_UNUSED, void *event)
339 Ecore_Event_Mouse_Button *ev = event;
341 if (ev->dev) ecore_device_unref(ev->dev);
347 _e_input_event_key_cb_free(void *data EINA_UNUSED, void *event)
349 Ecore_Event_Key *ev = event;
351 if (ev->dev) ecore_device_unref(ev->dev);
352 if (ev->data) E_FREE(ev->data);
358 _device_handle_key(struct libinput_device *device, struct libinput_event_keyboard *event)
361 E_Input_Backend *input;
363 uint32_t code, nsyms;
364 const xkb_keysym_t *syms;
365 enum libinput_key_state state;
367 xkb_keysym_t sym = XKB_KEY_NoSymbol;
368 char key[256] = {0, }, keyname[256] = {0, }, compose_buffer[256] = {0, };
370 char *tmp = NULL, *compose = NULL;
371 E_Keyrouter_Event_Data *key_data;
372 Ecore_Device *ecore_dev = NULL, *data;
373 Eina_List *l, *l_next;
374 E_Comp_Config *comp_conf = NULL;
375 int *pressed_keycode = NULL, *idata = NULL;
376 Eina_Bool dup_found = EINA_FALSE;
378 if (!(edev = libinput_device_get_user_data(device)))
383 if (!(input = edev->seat->input))
388 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
389 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
391 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
393 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_KEYBOARD)
402 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
403 ecore_dev = edev->ecore_dev;
408 ERR("Failed to get source ecore device from event !\n");
412 timestamp = libinput_event_keyboard_get_time(event);
413 code = libinput_event_keyboard_get_key(event);
414 code = _device_remapped_key_get(edev, code + 8);
415 state = libinput_event_keyboard_get_key_state(event);
416 key_count = libinput_event_keyboard_get_seat_key_count(event);
418 if (state == LIBINPUT_KEY_STATE_PRESSED)
420 if ((edev->seat->dev->blocked & E_INPUT_SEAT_KEYBOARD) ||
421 (edev->seat->dev->server_blocked & E_INPUT_SEAT_KEYBOARD))
423 ELOGF("Key", "Press (keycode: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
424 code, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
425 edev->seat->dev->server_blocked);
429 /* FIXME: Currently to maintain press/release event pair during input block,
430 * used Eina_List and this is method used in devicemgr module.
431 * But we need to consider which way is better to maintain key press/release pair.
434 EINA_LIST_FOREACH(edev->xkb.pressed_keys, l, idata)
438 dup_found = EINA_TRUE;
444 pressed_keycode = E_NEW(int, 1);
445 EINA_SAFETY_ON_NULL_RETURN(pressed_keycode);
446 *pressed_keycode = code;
448 edev->xkb.pressed_keys = eina_list_append(edev->xkb.pressed_keys, pressed_keycode);
453 dup_found = EINA_FALSE;
454 EINA_LIST_FOREACH_SAFE(edev->xkb.pressed_keys, l, l_next, idata)
458 edev->xkb.pressed_keys = eina_list_remove_list(edev->xkb.pressed_keys, l);
460 dup_found = EINA_TRUE;
466 ELOGF("Key", "Release (keycode: %d, device: %s) is blocked by %p", NULL,
467 code, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client);
472 /* ignore key events that are not seat wide state changes */
473 if (((state == LIBINPUT_KEY_STATE_PRESSED) && (key_count != 1)) ||
474 ((state == LIBINPUT_KEY_STATE_RELEASED) && (key_count != 0)))
479 xkb_state_update_key(edev->xkb.state, code,
480 (state ? XKB_KEY_DOWN : XKB_KEY_UP));
482 /* get the keysym for this code */
483 nsyms = xkb_key_get_syms(edev->xkb.state, code, &syms);
484 if (nsyms == 1) sym = syms[0];
486 /* If no keysym was found, name it "Keycode-NNN" */
487 if (sym == XKB_KEY_NoSymbol)
488 snprintf(key, sizeof(key), "Keycode-%u", code);
491 /* get the keyname for this sym */
492 xkb_keysym_get_name(sym, key, sizeof(key));
497 /* If no keyname was found, name it "Keycode-NNN" */
498 snprintf(keyname, sizeof(keyname), "Keycode-%u", code);
502 memcpy(keyname, key, sizeof(keyname));
505 /* if shift is active, we need to transform the key to lower */
506 if (xkb_state_mod_index_is_active(edev->xkb.state,
507 xkb_map_mod_get_index(edev->xkb.keymap,
509 XKB_STATE_MODS_EFFECTIVE))
511 if (keyname[0] != '\0')
512 keyname[0] = tolower(keyname[0]);
515 if (_device_keysym_translate(sym, edev->xkb.modifiers,
516 compose_buffer, sizeof(compose_buffer)))
518 compose = eina_str_convert("ISO8859-1", "UTF-8", compose_buffer);
521 ERR("E Input cannot convert input key string '%s' to UTF-8. "
522 "Is Eina built with iconv support?", compose_buffer);
528 if (!compose) compose = compose_buffer;
530 e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) +
531 ((compose[0] != '\0') ? strlen(compose) : 0) + 3);
537 key_data = E_NEW(E_Keyrouter_Event_Data, 1);
545 e->keyname = (char *)(e + 1);
546 e->key = e->keyname + strlen(keyname) + 1;
547 e->compose = strlen(compose) ? e->key + strlen(key) + 1 : NULL;
548 e->string = e->compose;
550 strncpy((char *)e->keyname, keyname, strlen(keyname));
551 strncpy((char *)e->key, key, strlen(key));
552 if (strlen(compose)) strncpy((char *)e->compose, compose, strlen(compose));
554 e->window = (Ecore_Window)input->dev->window;
555 e->event_window = (Ecore_Window)input->dev->window;
556 e->root_window = (Ecore_Window)input->dev->window;
557 e->timestamp = timestamp;
562 _device_modifiers_update(edev);
564 e->modifiers = edev->xkb.modifiers;
565 e->dev = ecore_device_ref(ecore_dev);
567 comp_conf = e_comp_config_get();
568 if (comp_conf && comp_conf->input_log_enable)
569 ELOGF("Key", "%s (keyname: %s, keycode: %d, device: %s)", NULL, state?"Press":"Release", e->keyname, e->keycode, ecore_device_name_get(e->dev));
572 ecore_event_add(ECORE_EVENT_KEY_DOWN, e, _e_input_event_key_cb_free, NULL);
574 ecore_event_add(ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
580 _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event)
582 E_Input_Backend *input;
583 Ecore_Event_Mouse_Move *ev;
584 Ecore_Device *ecore_dev = NULL, *data, *detent_data = NULL;
587 if (!(input = edev->seat->input)) return;
589 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
590 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
592 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
594 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
599 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
604 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
606 ecore_dev = detent_data;
611 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
612 ecore_dev = edev->ecore_dev;
617 ERR("Failed to get source ecore device from event !\n");
620 else if ((detent_data == ecore_dev) || e_devicemgr_detent_is_detent(ecore_device_name_get(ecore_dev)))
622 /* Do not process detent device's move events. */
626 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
628 if (edev->seat->ptr.ix < edev->mouse.minx)
629 edev->seat->ptr.dx = edev->seat->ptr.ix = edev->mouse.minx;
630 else if (edev->seat->ptr.ix >= (edev->mouse.minx + edev->mouse.maxw))
631 edev->seat->ptr.dx = edev->seat->ptr.ix = (edev->mouse.minx + edev->mouse.maxw - 1);
633 if (edev->seat->ptr.iy < edev->mouse.miny)
634 edev->seat->ptr.dy = edev->seat->ptr.iy = edev->mouse.miny;
635 else if (edev->seat->ptr.iy >= (edev->mouse.miny + edev->mouse.maxh))
636 edev->seat->ptr.dy = edev->seat->ptr.iy = (edev->mouse.miny + edev->mouse.maxh - 1);
638 edev->mouse.dx = edev->seat->ptr.dx;
639 edev->mouse.dy = edev->seat->ptr.dy;
641 ev->window = (Ecore_Window)input->dev->window;
642 ev->event_window = (Ecore_Window)input->dev->window;
643 ev->root_window = (Ecore_Window)input->dev->window;
644 if (event) ev->timestamp = libinput_event_pointer_get_time(event);
647 _device_modifiers_update(edev);
648 ev->modifiers = edev->xkb.modifiers;
650 ev->x = edev->seat->ptr.ix;
651 ev->y = edev->seat->ptr.iy;
655 ev->multi.device = edev->mt_slot;
656 ev->multi.radius = 1;
657 ev->multi.radius_x = 1;
658 ev->multi.radius_y = 1;
659 ev->multi.pressure = 1.0;
660 ev->multi.angle = 0.0;
663 ev->multi.root.x = ev->x;
664 ev->multi.root.y = ev->y;
665 ev->dev = ecore_device_ref(ecore_dev);
667 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
671 _e_input_pointer_motion_post(E_Input_Evdev *edev)
673 _device_pointer_motion(edev, NULL);
677 _device_handle_pointer_motion(struct libinput_device *device, struct libinput_event_pointer *event)
682 if (!(edev = libinput_device_get_user_data(device)))
687 dx = libinput_event_pointer_get_dx(event);
688 dy = libinput_event_pointer_get_dy(event);
690 if (edev->seat->ptr.swap)
696 if (edev->seat->ptr.invert_x)
698 if (edev->seat->ptr.invert_y)
701 edev->seat->ptr.dx += dx;
702 edev->seat->ptr.dy += dy;
704 edev->mouse.dx = edev->seat->ptr.dx;
705 edev->mouse.dy = edev->seat->ptr.dy;
707 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
708 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
713 edev->seat->ptr.ix = edev->seat->ptr.dx;
714 edev->seat->ptr.iy = edev->seat->ptr.dy;
716 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
717 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
722 _device_pointer_motion(edev, event);
726 _device_handle_pointer_motion_absolute(struct libinput_device *device, struct libinput_event_pointer *event)
731 if (!(edev = libinput_device_get_user_data(device)))
736 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
738 edev->mouse.dx = edev->seat->ptr.dx =
739 libinput_event_pointer_get_absolute_x_transformed(event, w);
740 edev->mouse.dy = edev->seat->ptr.dy =
741 libinput_event_pointer_get_absolute_y_transformed(event, h);
743 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
744 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
749 edev->seat->ptr.ix = edev->seat->ptr.dx;
750 edev->seat->ptr.iy = edev->seat->ptr.dy;
752 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
753 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
758 _device_pointer_motion(edev, event);
762 _device_handle_button(struct libinput_device *device, struct libinput_event_pointer *event)
765 E_Input_Backend *input;
766 Ecore_Event_Mouse_Button *ev;
767 enum libinput_button_state state;
768 uint32_t button, timestamp;
769 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
771 E_Comp_Config *comp_conf = NULL;
773 if (!(edev = libinput_device_get_user_data(device)))
777 if (!(input = edev->seat->input))
782 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
783 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
785 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
787 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
792 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
797 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
799 ecore_dev = detent_data;
804 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
805 ecore_dev = edev->ecore_dev;
810 ERR("Failed to get source ecore device from event !\n");
814 state = libinput_event_pointer_get_button_state(event);
815 button = libinput_event_pointer_get_button(event);
816 timestamp = libinput_event_pointer_get_time(event);
818 button = ((button & 0x00F) + 1);
819 if (button == 3) button = 2;
820 else if (button == 2) button = 3;
824 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
825 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
827 ELOGF("Mouse", "Button Press (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
828 button, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
829 edev->seat->dev->server_blocked);
834 edev->mouse.pressed_button |= (1 << button);
839 if (!(edev->mouse.pressed_button & (1 << button)))
841 ELOGF("Mouse", "Button Release (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
842 button, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
843 edev->seat->dev->server_blocked);
846 edev->mouse.pressed_button &= ~(1 << button);
849 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button))))
854 ev->window = (Ecore_Window)input->dev->window;
855 ev->event_window = (Ecore_Window)input->dev->window;
856 ev->root_window = (Ecore_Window)input->dev->window;
857 ev->timestamp = timestamp;
860 _device_modifiers_update(edev);
861 ev->modifiers = edev->xkb.modifiers;
863 ev->x = edev->seat->ptr.ix;
864 ev->y = edev->seat->ptr.iy;
868 ev->multi.device = edev->mt_slot;
869 ev->multi.radius = 1;
870 ev->multi.radius_x = 1;
871 ev->multi.radius_y = 1;
872 ev->multi.pressure = 1.0;
873 ev->multi.angle = 0.0;
876 ev->multi.root.x = ev->x;
877 ev->multi.root.y = ev->y;
878 ev->dev = ecore_device_ref(ecore_dev);
882 unsigned int current;
885 edev->mouse.did_double = EINA_FALSE;
886 edev->mouse.did_triple = EINA_FALSE;
888 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
889 (button == edev->mouse.prev_button))
891 edev->mouse.did_double = EINA_TRUE;
892 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
893 (button == edev->mouse.last_button))
895 edev->mouse.did_triple = EINA_TRUE;
896 edev->mouse.prev = 0;
897 edev->mouse.last = 0;
902 edev->mouse.last = edev->mouse.prev;
903 edev->mouse.prev = current;
904 edev->mouse.last_button = edev->mouse.prev_button;
905 edev->mouse.prev_button = button;
908 ev->buttons = button;
910 if (edev->mouse.did_double)
911 ev->double_click = 1;
912 if (edev->mouse.did_triple)
913 ev->triple_click = 1;
915 comp_conf = e_comp_config_get();
916 if (comp_conf && comp_conf->input_log_enable)
917 ELOGF("Mouse", "Button %s (btn: %d, device: %s)", NULL, state?"Press":"Release", button, ecore_device_name_get(ev->dev));
920 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, _e_input_event_mouse_button_cb_free, NULL);
922 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, _e_input_event_mouse_button_cb_free, NULL);
926 _device_handle_axis(struct libinput_device *device, struct libinput_event_pointer *event)
929 E_Input_Backend *input;
930 Ecore_Event_Mouse_Wheel *ev;
932 enum libinput_pointer_axis axis;
933 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
935 E_Comp_Config *comp_conf = NULL;
936 int direction = 0, z = 0;
938 if (!(edev = libinput_device_get_user_data(device)))
942 if (!(input = edev->seat->input))
947 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
948 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
950 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
952 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
957 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
962 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
964 ecore_dev = detent_data;
969 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
970 ecore_dev = edev->ecore_dev;
975 ERR("Failed to get source ecore device from event !\n");
979 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
980 if (libinput_event_pointer_has_axis(event, axis))
981 z = libinput_event_pointer_get_axis_value(event, axis);
983 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
984 if (libinput_event_pointer_has_axis(event, axis))
987 z = libinput_event_pointer_get_axis_value(event, axis);
990 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
991 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
994 ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
995 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
997 ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
998 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1002 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1007 timestamp = libinput_event_pointer_get_time(event);
1009 ev->window = (Ecore_Window)input->dev->window;
1010 ev->event_window = (Ecore_Window)input->dev->window;
1011 ev->root_window = (Ecore_Window)input->dev->window;
1012 ev->timestamp = timestamp;
1013 ev->same_screen = 1;
1015 _device_modifiers_update(edev);
1016 ev->modifiers = edev->xkb.modifiers;
1018 ev->x = edev->seat->ptr.ix;
1019 ev->y = edev->seat->ptr.iy;
1022 ev->dev = ecore_device_ref(ecore_dev);
1025 ev->direction = direction;
1027 comp_conf = e_comp_config_get();
1028 if (comp_conf && comp_conf->input_log_enable)
1031 ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1033 ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1036 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1040 _device_handle_touch_event_send(E_Input_Evdev *edev, struct libinput_event_touch *event, int state)
1042 E_Input_Backend *input;
1043 Ecore_Event_Mouse_Button *ev;
1044 uint32_t timestamp, button = 0;
1045 Ecore_Device *ecore_dev = NULL, *data;
1049 if (!(input = edev->seat->input)) return;
1051 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1052 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1054 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1056 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1065 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1066 ecore_dev = edev->ecore_dev;
1071 ERR("Failed to get source ecore device from event !\n");
1075 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) return;
1077 timestamp = libinput_event_touch_get_time(event);
1079 ev->window = (Ecore_Window)input->dev->window;
1080 ev->event_window = (Ecore_Window)input->dev->window;
1081 ev->root_window = (Ecore_Window)input->dev->window;
1082 ev->timestamp = timestamp;
1083 ev->same_screen = 1;
1085 _device_modifiers_update(edev);
1086 ev->modifiers = edev->xkb.modifiers;
1088 ev->x = edev->seat->ptr.ix;
1089 ev->y = edev->seat->ptr.iy;
1093 ev->multi.device = edev->mt_slot;
1094 ev->multi.radius = 1;
1095 ev->multi.radius_x = 1;
1096 ev->multi.radius_y = 1;
1097 ev->multi.pressure = 1.0;
1098 ev->multi.angle = 0.0;
1099 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1100 if (libinput_event_get_type(libinput_event_touch_get_base_event(event))
1101 == LIBINPUT_EVENT_TOUCH_DOWN)
1103 if (libinput_event_touch_has_minor(event))
1104 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1105 if (libinput_event_touch_has_major(event))
1106 ev->multi.radius_y = libinput_event_touch_get_major(event);
1107 if (libinput_event_touch_has_pressure(event))
1108 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1109 if (libinput_event_touch_has_orientation(event))
1110 ev->multi.angle = libinput_event_touch_get_orientation(event);
1113 ev->multi.x = ev->x;
1114 ev->multi.y = ev->y;
1115 ev->multi.root.x = ev->x;
1116 ev->multi.root.y = ev->y;
1117 ev->dev = ecore_device_ref(ecore_dev);
1119 if (state == ECORE_EVENT_MOUSE_BUTTON_DOWN)
1121 unsigned int current;
1123 current = timestamp;
1124 edev->mouse.did_double = EINA_FALSE;
1125 edev->mouse.did_triple = EINA_FALSE;
1127 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1128 (button == edev->mouse.prev_button))
1130 edev->mouse.did_double = EINA_TRUE;
1131 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1132 (button == edev->mouse.last_button))
1134 edev->mouse.did_triple = EINA_TRUE;
1135 edev->mouse.prev = 0;
1136 edev->mouse.last = 0;
1141 edev->mouse.last = edev->mouse.prev;
1142 edev->mouse.prev = current;
1143 edev->mouse.last_button = edev->mouse.prev_button;
1144 edev->mouse.prev_button = button;
1145 edev->touch.pressed |= (1 << ev->multi.device);
1149 edev->touch.pressed &= ~(1 << ev->multi.device);
1152 ev->buttons = ((button & 0x00F) + 1);
1154 if (edev->mouse.did_double)
1155 ev->double_click = 1;
1156 if (edev->mouse.did_triple)
1157 ev->triple_click = 1;
1159 ecore_event_add(state, ev, _e_input_event_mouse_button_cb_free, NULL);
1163 _device_handle_touch_motion_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1165 E_Input_Backend *input;
1166 Ecore_Event_Mouse_Move *ev;
1167 Ecore_Device *ecore_dev = NULL, *data;
1171 if (!(input = edev->seat->input)) return;
1173 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1174 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1176 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1178 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1187 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1188 ecore_dev = edev->ecore_dev;
1193 ERR("Failed to get source ecore device from event !\n");
1197 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
1199 ev->window = (Ecore_Window)input->dev->window;
1200 ev->event_window = (Ecore_Window)input->dev->window;
1201 ev->root_window = (Ecore_Window)input->dev->window;
1202 ev->timestamp = libinput_event_touch_get_time(event);
1203 ev->same_screen = 1;
1205 _device_modifiers_update(edev);
1206 ev->modifiers = edev->xkb.modifiers;
1208 ev->x = edev->seat->ptr.ix;
1209 ev->y = edev->seat->ptr.iy;
1213 ev->multi.device = edev->mt_slot;
1214 ev->multi.radius = 1;
1215 ev->multi.radius_x = 1;
1216 ev->multi.radius_y = 1;
1217 ev->multi.pressure = 1.0;
1218 ev->multi.angle = 0.0;
1219 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1220 if (libinput_event_touch_has_minor(event))
1221 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1222 if (libinput_event_touch_has_major(event))
1223 ev->multi.radius_y = libinput_event_touch_get_major(event);
1224 if (libinput_event_touch_has_pressure(event))
1225 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1226 if (libinput_event_touch_has_orientation(event))
1227 ev->multi.angle = libinput_event_touch_get_orientation(event);
1229 ev->multi.x = ev->x;
1230 ev->multi.y = ev->y;
1231 ev->multi.root.x = ev->x;
1232 ev->multi.root.y = ev->y;
1233 ev->dev = ecore_device_ref(ecore_dev);
1235 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
1239 _device_handle_touch_down(struct libinput_device *device, struct libinput_event_touch *event)
1241 E_Input_Evdev *edev;
1243 E_Comp_Config *comp_conf = NULL;
1245 if (!(edev = libinput_device_get_user_data(device)))
1250 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
1252 edev->mouse.dx = edev->seat->ptr.ix = edev->seat->ptr.dx =
1253 libinput_event_touch_get_x_transformed(event, w);
1254 edev->mouse.dy = edev->seat->ptr.iy = edev->seat->ptr.dy =
1255 libinput_event_touch_get_y_transformed(event, h);
1257 edev->mt_slot = libinput_event_touch_get_slot(event);
1258 if (edev->mt_slot < 0)
1260 /* FIXME: The single touch device return slot id -1
1261 * But currently we have no API to distinguish multi touch or single touch
1262 * After libinput 1.11 version, libinput provides get_touch_count API,
1263 * so we can distinguish multi touch device or single touch device.
1265 if (edev->mt_slot == -1)
1269 WRN("%d slot touch down events are not supported\n", edev->mt_slot);
1274 if (edev->mt_slot < E_INPUT_MAX_SLOTS)
1276 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
1277 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
1280 comp_conf = e_comp_config_get();
1281 if (comp_conf && comp_conf->input_log_enable)
1282 ELOGF("Touch", "Down (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
1284 edev->touch.raw_pressed |= (1 << edev->mt_slot);
1286 if (edev->touch.blocked)
1288 ELOGF("Touch", "Down (id: %d, x: %d, y: %d) is blocked by %p, server: 0x%x", NULL,
1289 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, edev->seat->dev->blocked_client,
1290 edev->seat->dev->server_blocked);
1294 _device_handle_touch_motion_send(edev, event);
1295 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_DOWN);
1299 _device_handle_touch_motion(struct libinput_device *device, struct libinput_event_touch *event)
1301 E_Input_Evdev *edev;
1304 if (!(edev = libinput_device_get_user_data(device)))
1309 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
1311 edev->mouse.dx = edev->seat->ptr.dx =
1312 libinput_event_touch_get_x_transformed(event, w);
1313 edev->mouse.dy = edev->seat->ptr.dy =
1314 libinput_event_touch_get_y_transformed(event, h);
1316 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
1317 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
1322 edev->seat->ptr.ix = edev->seat->ptr.dx;
1323 edev->seat->ptr.iy = edev->seat->ptr.dy;
1325 edev->mt_slot = libinput_event_touch_get_slot(event);
1326 if (edev->mt_slot < 0)
1328 /* FIXME: The single touch device return slot id -1
1329 * But currently we have no API to distinguish multi touch or single touch
1330 * After libinput 1.11 version, libinput provides get_touch_count API,
1331 * so we can distinguish multi touch device or single touch device.
1333 if (edev->mt_slot == -1)
1337 WRN("%d slot touch motion events are not supported\n", edev->mt_slot);
1342 if (edev->mt_slot < E_INPUT_MAX_SLOTS)
1344 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
1345 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
1348 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
1350 if (edev->touch.blocked)
1356 _device_handle_touch_motion_send(edev, event);
1360 _device_handle_touch_up(struct libinput_device *device, struct libinput_event_touch *event)
1362 E_Input_Evdev *edev;
1363 E_Comp_Config *comp_conf = NULL;
1365 if (!(edev = libinput_device_get_user_data(device)))
1370 edev->mt_slot = libinput_event_touch_get_slot(event);
1371 if (edev->mt_slot < 0)
1373 /* FIXME: The single touch device return slot id -1
1374 * But currently we have no API to distinguish multi touch or single touch
1375 * After libinput 1.11 version, libinput provides get_touch_count API,
1376 * so we can distinguish multi touch device or single touch device.
1378 if (edev->mt_slot == -1)
1382 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
1387 if (edev->mt_slot < E_INPUT_MAX_SLOTS)
1389 edev->mouse.dx = edev->seat->ptr.dx = edev->seat->ptr.ix =
1390 edev->touch.coords[edev->mt_slot].x;
1391 edev->mouse.dy = edev->seat->ptr.dy = edev->seat->ptr.iy =
1392 edev->touch.coords[edev->mt_slot].y;
1395 comp_conf = e_comp_config_get();
1396 if (comp_conf && comp_conf->input_log_enable)
1397 ELOGF("Touch", "Up (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
1399 edev->touch.raw_pressed &= ~(1 << edev->mt_slot);
1401 if (edev->touch.blocked)
1403 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
1405 ELOGF("Touch", "Up (id: %d, x: %d, y: %d) is blocked by %p, server(0x%x)", NULL,
1406 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, edev->seat->dev->blocked_client,
1407 edev->seat->dev->server_blocked);
1408 if (edev->touch.raw_pressed == 0x0)
1410 edev->touch.blocked = EINA_FALSE;
1416 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_UP);
1420 _device_handle_touch_frame(struct libinput_device *device EINA_UNUSED, struct libinput_event_touch *event EINA_UNUSED)
1422 /* DBG("Unhandled Touch Frame Event"); */
1426 _e_input_aux_data_event_free(void *user_data EINA_UNUSED, void *ev)
1428 Ecore_Event_Axis_Update *e = (Ecore_Event_Axis_Update *)ev;
1430 if (e->axis) free(e->axis);
1431 if (e->dev) ecore_device_unref(e->dev);
1437 _device_handle_touch_aux_data(struct libinput_device *device, struct libinput_event_touch_aux_data *event)
1439 E_Input_Evdev *edev;
1440 E_Input_Backend *input;
1441 Ecore_Event_Axis_Update *ev;
1443 Ecore_Device *ecore_dev = NULL, *data;
1445 E_Comp_Config *comp_conf;
1447 if (libinput_event_touch_aux_data_get_type(event) != LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM &&
1448 libinput_event_touch_aux_data_get_value(event) > 0)
1451 if (!(edev = libinput_device_get_user_data(device))) goto end;
1452 if (!(input = edev->seat->input)) goto end;
1454 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1455 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1457 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1459 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1468 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1469 ecore_dev = edev->ecore_dev;
1474 ERR("Failed to get source ecore device from event !\n");
1478 if (!(ev = calloc(1, sizeof(Ecore_Event_Axis_Update))))goto end;
1480 ev->window = (Ecore_Window)input->dev->window;
1481 ev->event_window = (Ecore_Window)input->dev->window;
1482 ev->root_window = (Ecore_Window)input->dev->window;
1483 ev->timestamp = libinput_event_touch_aux_data_get_time(event);
1485 axis = (Ecore_Axis *)calloc(1, sizeof(Ecore_Axis));
1488 axis->label = ECORE_AXIS_LABEL_TOUCH_PALM;
1489 axis->value = libinput_event_touch_aux_data_get_value(event);
1493 ev->dev = ecore_device_ref(ecore_dev);
1495 comp_conf = e_comp_config_get();
1496 if (comp_conf && comp_conf->input_log_enable)
1497 ELOGF("Touch", "Axis (label: %d, value: %lf)", NULL, axis?axis->label:-1, axis?axis->value:0.0);
1499 ecore_event_add(ECORE_EVENT_AXIS_UPDATE, ev, _e_input_aux_data_event_free, NULL);
1506 _e_input_evdev_device_create(E_Input_Seat *seat, struct libinput_device *device)
1508 E_Input_Evdev *edev;
1509 E_Input_Backend *b_input;
1511 EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
1513 /* try to allocate space for new evdev */
1514 if (!(edev = calloc(1, sizeof(E_Input_Evdev)))) return NULL;
1517 edev->device = device;
1518 edev->path = eina_stringshare_printf("%s/%s", e_input_base_dir_get(), libinput_device_get_sysname(device));
1520 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
1522 edev->caps |= E_INPUT_SEAT_KEYBOARD;
1523 _device_keyboard_setup(edev);
1526 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
1528 edev->caps |= E_INPUT_SEAT_POINTER;
1530 /* TODO: make this configurable */
1531 edev->mouse.threshold = 250;
1533 b_input = seat->input;
1534 if (b_input->left_handed == EINA_TRUE)
1536 if (libinput_device_config_left_handed_set(device, 1) !=
1537 LIBINPUT_CONFIG_STATUS_SUCCESS)
1539 WRN("Failed to set left hand mode about device: %s\n",
1540 libinput_device_get_name(device));
1545 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
1548 edev->caps |= E_INPUT_SEAT_TOUCH;
1549 palm_code = libinput_device_touch_aux_data_get_code(LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM);
1550 if (libinput_device_touch_has_aux_data(device, palm_code))
1552 libinput_device_touch_set_aux_data(device, palm_code);
1556 libinput_device_set_user_data(device, edev);
1557 libinput_device_ref(device);
1559 /* configure device */
1560 _device_configure(edev);
1566 _e_input_evdev_device_destroy(E_Input_Evdev *edev)
1570 EINA_SAFETY_ON_NULL_RETURN(edev);
1572 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
1574 if (edev->xkb.state) xkb_state_unref(edev->xkb.state);
1575 if (edev->xkb.keymap) xkb_map_unref(edev->xkb.keymap);
1578 if (edev->ecore_dev) ecore_device_del(edev->ecore_dev);
1579 if (edev->ecore_dev_list)
1580 EINA_LIST_FREE(edev->ecore_dev_list, dev)
1582 ecore_device_del(dev);
1584 if (edev->path) eina_stringshare_del(edev->path);
1585 if (edev->device) libinput_device_unref(edev->device);
1586 if (edev->key_remap_hash) eina_hash_free(edev->key_remap_hash);
1592 _e_input_evdev_event_process(struct libinput_event *event)
1594 struct libinput_device *device;
1595 Eina_Bool ret = EINA_TRUE;
1597 device = libinput_event_get_device(event);
1598 switch (libinput_event_get_type(event))
1600 case LIBINPUT_EVENT_KEYBOARD_KEY:
1601 _device_handle_key(device, libinput_event_get_keyboard_event(event));
1603 case LIBINPUT_EVENT_POINTER_MOTION:
1604 _device_handle_pointer_motion(device,
1605 libinput_event_get_pointer_event(event));
1607 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
1608 _device_handle_pointer_motion_absolute(device,
1609 libinput_event_get_pointer_event(event));
1611 case LIBINPUT_EVENT_POINTER_BUTTON:
1612 _device_handle_button(device, libinput_event_get_pointer_event(event));
1614 case LIBINPUT_EVENT_POINTER_AXIS:
1615 _device_handle_axis(device, libinput_event_get_pointer_event(event));
1617 case LIBINPUT_EVENT_TOUCH_DOWN:
1618 _device_handle_touch_down(device, libinput_event_get_touch_event(event));
1620 case LIBINPUT_EVENT_TOUCH_MOTION:
1621 _device_handle_touch_motion(device,
1622 libinput_event_get_touch_event(event));
1624 case LIBINPUT_EVENT_TOUCH_UP:
1625 _device_handle_touch_up(device, libinput_event_get_touch_event(event));
1627 case LIBINPUT_EVENT_TOUCH_FRAME:
1628 _device_handle_touch_frame(device, libinput_event_get_touch_event(event));
1630 case LIBINPUT_EVENT_TOUCH_AUX_DATA:
1631 _device_handle_touch_aux_data(device, libinput_event_get_touch_aux_data(event));
1642 * @brief Set the axis size of the given device.
1644 * @param dev The device to set the axis size to.
1645 * @param w The width of the axis.
1646 * @param h The height of the axis.
1648 * This function sets set the width @p w and height @p h of the axis
1649 * of device @p dev. If @p dev is a relative input device, a width and
1650 * height must set for it. If its absolute set the ioctl correctly, if
1651 * not, unsupported device.
1654 e_input_evdev_axis_size_set(E_Input_Evdev *edev, int w, int h)
1656 const char *sysname;
1661 enum libinput_config_status status;
1663 EINA_SAFETY_ON_NULL_RETURN(edev);
1664 EINA_SAFETY_ON_TRUE_RETURN((w == 0) || (h == 0));
1666 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
1667 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
1670 sysname = libinput_device_get_sysname(edev->device);
1672 devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
1673 if (eina_list_count(devices) < 1) return;
1675 EINA_LIST_FREE(devices, device)
1677 vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
1679 (sscanf(vals, "%f %f %f %f %f %f",
1680 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
1687 libinput_device_config_calibration_set_matrix(edev->device, cal);
1689 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
1690 ERR("Failed to apply calibration");
1693 eina_stringshare_del(device);
1699 e_input_evdev_name_get(E_Input_Evdev *evdev)
1701 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
1702 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
1704 return libinput_device_get_name(evdev->device);
1707 EINTERN const char *
1708 e_input_evdev_sysname_get(E_Input_Evdev *evdev)
1710 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
1711 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
1713 return libinput_device_get_sysname(evdev->device);
1717 e_input_evdev_key_remap_enable(E_Input_Evdev *edev, Eina_Bool enable)
1719 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
1720 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
1722 edev->key_remap_enabled = enable;
1724 if (enable == EINA_FALSE && edev->key_remap_hash)
1726 eina_hash_free(edev->key_remap_hash);
1727 edev->key_remap_hash = NULL;
1734 e_input_evdev_key_remap_set(E_Input_Evdev *edev, int *from_keys, int *to_keys, int num)
1738 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
1739 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
1740 EINA_SAFETY_ON_NULL_RETURN_VAL(from_keys, EINA_FALSE);
1741 EINA_SAFETY_ON_NULL_RETURN_VAL(to_keys, EINA_FALSE);
1742 EINA_SAFETY_ON_TRUE_RETURN_VAL(num <= 0, EINA_FALSE);
1743 EINA_SAFETY_ON_TRUE_RETURN_VAL(!edev->key_remap_enabled, EINA_FALSE);
1745 if (edev->key_remap_hash == NULL)
1746 edev->key_remap_hash = eina_hash_int32_new(NULL);
1748 if (edev->key_remap_hash == NULL)
1750 ERR("Failed to set remap key information : creating a hash is failed.");
1754 for (i = 0; i < num ; i++)
1756 if (!from_keys[i] || !to_keys[i])
1758 ERR("Failed to set remap key information : given arguments are invalid.");
1763 for (i = 0; i < num ; i++)
1765 eina_hash_add(edev->key_remap_hash, &from_keys[i], (void *)(intptr_t)to_keys[i]);
1772 e_input_evdev_wheel_click_angle_get(E_Input_Evdev *dev)
1774 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, -1);
1775 return libinput_device_config_scroll_get_wheel_click_angle(dev->device);
1779 e_input_evdev_touch_calibration_set(E_Input_Evdev *edev, float matrix[6])
1781 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
1782 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
1784 if (!libinput_device_config_calibration_has_matrix(edev->device) ||
1785 !libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_TOUCH))
1788 if (libinput_device_config_calibration_set_matrix(edev->device, matrix) !=
1789 LIBINPUT_CONFIG_STATUS_SUCCESS)
1791 WRN("Failed to set input transformation about device: %s\n",
1792 libinput_device_get_name(edev->device));
1800 e_input_evdev_mouse_accel_speed_set(E_Input_Evdev *edev, double speed)
1802 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
1803 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
1805 if (!libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
1808 if (!libinput_device_config_accel_is_available(edev->device))
1811 if (libinput_device_config_accel_set_speed(edev->device, speed) !=
1812 LIBINPUT_CONFIG_STATUS_SUCCESS)
1814 WRN("Failed to set mouse accel about device: %s\n",
1815 libinput_device_get_name(edev->device));
1822 EINTERN unsigned int
1823 e_input_evdev_touch_pressed_get(E_Input_Evdev *edev)
1825 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, 0x0);
1827 return edev->touch.pressed;