1 #include "e_input_intern.h"
2 #include "e_input_log.h"
3 #include "e_input_event.h"
4 #include "e_keyrouter_intern.h"
5 #include "e_devicemgr_intern.h"
6 #include "e_device_intern.h"
7 #include "e_comp_screen_intern.h"
8 #include "e_output_intern.h"
13 #define G_LIST_GET_DATA(list) ((list) ? (((GList *)(list))->data) : NULL)
15 static void _device_modifiers_update(E_Input_Evdev *edev);
16 static void _device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, int *w, int *h);
17 static void _device_output_assign(E_Input_Evdev *edev, E_Input_Seat_Capabilities cap);
20 _device_calibration_set(E_Input_Evdev *edev)
25 E_Comp_Config *comp_conf;
27 if (e_comp->e_comp_screen->num_outputs > 1) //multiple outputs
29 comp_conf = e_comp_config_get();
30 if (comp_conf && (comp_conf->input_output_assign_policy == 1)) //use output-assignment policy
32 _device_output_assign(edev, E_INPUT_SEAT_POINTER);
33 _device_output_assign(edev, E_INPUT_SEAT_TOUCH);
37 output = e_comp_screen_primary_output_get(e_comp->e_comp_screen);
38 e_output_size_get(output, &w, &h);
42 edev->mouse.minx = edev->mouse.miny = 0;
46 if (edev->caps & E_INPUT_SEAT_POINTER)
48 edev->seat->ptr.dx = (double)(w / 2);
49 edev->seat->ptr.dy = (double)(h / 2);
50 edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
51 edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
52 edev->mouse.dx = edev->seat->ptr.dx;
53 edev->mouse.dy = edev->seat->ptr.dy;
55 if (output->config.rotation == 90 || output->config.rotation == 270)
57 temp = edev->mouse.minx;
58 edev->mouse.minx = edev->mouse.miny;
59 edev->mouse.miny = temp;
61 temp = edev->mouse.maxw;
62 edev->mouse.maxw = edev->mouse.maxh;
63 edev->mouse.maxh = temp;
69 #ifdef _F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
72 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
73 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
76 #ifdef _F_E_INPUT_USE_WL_CALIBRATION_
78 enum libinput_config_status status;
79 struct udev_device *udev_device = NULL;
81 udev_device = libinput_device_get_udev_device(edev->device);
84 ERR("no udev_device");
88 vals = udev_device_get_property_value(udev_device, "WL_CALIBRATION");
90 (sscanf(vals, "%f %f %f %f %f %f",
91 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
94 ELOGF("E_INPUT_EVDEV", "calibration_set cal[%lf %lf %lf %lf %lf %lf] (%d x %d)",
95 NULL, cal[0], cal[1], cal[2], cal[3], cal[4], cal[5], w, h);
100 libinput_device_config_calibration_set_matrix(edev->device, cal);
102 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
103 ERR("Failed to apply calibration");
104 #endif//_F_E_INPUT_USE_WL_CALIBRATION_
105 #endif//_F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
110 _device_output_assign(E_Input_Evdev *edev, E_Input_Seat_Capabilities cap)
115 Eina_Bool need_assign_output = EINA_FALSE;
116 const char *output_name;
119 if (!(edev->caps & cap)) return;
120 if (edev->output_name) return; //already assigned
121 if (e_comp->e_comp_screen->num_outputs <= 1) return;
123 last_output_idx = e_comp->e_comp_screen->num_outputs - 1;
124 EINA_LIST_FOREACH(edev->seat->devices, l, ed)
126 if (!(ed->caps & cap)) continue;
127 if (ed == edev) continue;
130 need_assign_output = EINA_FALSE;
133 need_assign_output = EINA_TRUE;
135 if (need_assign_output)
137 output = e_output_find_by_index(last_output_idx);
138 if (!output || !output->info.connected) return;
139 output_name = e_output_output_id_get(output);
140 if (output_name) edev->output_name = eina_stringshare_add(output_name);
141 ELOGF("E_INPUT_EVDEV", "Device is assigned to output:%s", NULL, output_name);
146 _device_touch_count_update(E_Input_Evdev *edev)
148 unsigned int device_touch_count = 0;
149 static unsigned int _max_device_touch_count = 0;
151 E_Input *ei = e_input_get();
152 EINA_SAFETY_ON_NULL_RETURN(ei);
154 device_touch_count = libinput_device_touch_get_touch_count(edev->device);
156 if (_max_device_touch_count < device_touch_count)
157 _max_device_touch_count = device_touch_count;
159 if (e_config->configured_max_touch.use)
161 if (_max_device_touch_count > 0 && e_config->configured_max_touch.count > _max_device_touch_count)
163 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch max count(%d) must be less or equal to device's touch count(%d) !\nTouch max count has been shrinken to %d.\n",
164 NULL, e_config->configured_max_touch.count, _max_device_touch_count, _max_device_touch_count);
165 ei->touch_max_count = _max_device_touch_count;
169 if (ei->touch_max_count != e_config->configured_max_touch.count)
171 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch_max_count has been updated to %d -> %d.\n",
172 NULL, ei->touch_max_count, e_config->configured_max_touch.count);
173 ei->touch_max_count = e_config->configured_max_touch.count;
179 if (ei->touch_max_count < _max_device_touch_count)
181 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch_max_count has been updated to %d -> %d.\n", NULL,
182 ei->touch_max_count, _max_device_touch_count);
183 ei->touch_max_count = _max_device_touch_count;
187 ei->touch_device_count++;
188 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch device count is %d.\n", NULL, ei->touch_device_count);
192 _device_configure(E_Input_Evdev *edev)
194 if (libinput_device_config_tap_get_finger_count(edev->device) > 0)
196 Eina_Bool tap = EINA_FALSE;
198 tap = libinput_device_config_tap_get_default_enabled(edev->device);
199 libinput_device_config_tap_set_enabled(edev->device, tap);
202 _device_calibration_set(edev);
206 _device_keyboard_setup(E_Input_Evdev *edev)
208 E_Input_Backend *input;
209 xkb_mod_index_t xkb_idx;
211 if ((!edev) || (!edev->seat)) return;
212 if (!(input = edev->seat->input)) return;
213 if (!input->dev->xkb_ctx) return;
215 /* create keymap from xkb context */
216 edev->xkb.keymap = _e_input_device_cached_keymap_get(input->dev->xkb_ctx, NULL, 0);
217 if (!edev->xkb.keymap)
219 ERR("Failed to create keymap: %m");
223 /* create xkb state */
224 if (!(edev->xkb.state = xkb_state_new(edev->xkb.keymap)))
226 ERR("Failed to create xkb state: %m");
230 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CTRL);
231 if (xkb_idx != XKB_MOD_INVALID)
232 edev->xkb.ctrl_mask = 1 << xkb_idx;
234 edev->xkb.ctrl_mask = 0;
236 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_ALT);
237 if (xkb_idx != XKB_MOD_INVALID)
238 edev->xkb.alt_mask = 1 << xkb_idx;
240 edev->xkb.alt_mask = 0;
242 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_SHIFT);
243 if (xkb_idx != XKB_MOD_INVALID)
244 edev->xkb.shift_mask = 1 << xkb_idx;
246 edev->xkb.shift_mask = 0;
248 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_LOGO);
249 if (xkb_idx != XKB_MOD_INVALID)
250 edev->xkb.win_mask = 1 << xkb_idx;
252 edev->xkb.win_mask = 0;
254 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_SCROLL);
255 if (xkb_idx != XKB_MOD_INVALID)
256 edev->xkb.scroll_mask = 1 << xkb_idx;
258 edev->xkb.scroll_mask = 0;
260 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_NUM);
261 if (xkb_idx != XKB_MOD_INVALID)
262 edev->xkb.num_mask = 1 << xkb_idx;
264 edev->xkb.num_mask = 0;
266 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CAPS);
267 if (xkb_idx != XKB_MOD_INVALID)
268 edev->xkb.caps_mask = 1 << xkb_idx;
270 edev->xkb.caps_mask = 0;
272 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, "ISO_Level3_Shift");
273 if (xkb_idx != XKB_MOD_INVALID)
274 edev->xkb.altgr_mask = 1 << xkb_idx;
276 edev->xkb.altgr_mask = 0;
280 _device_keysym_translate(xkb_keysym_t keysym, unsigned int modifiers, char *buffer, int bytes)
282 unsigned long hbytes = 0;
285 if (!keysym) return 0;
286 hbytes = (keysym >> 8);
291 (((keysym >= XKB_KEY_BackSpace) && (keysym <= XKB_KEY_Clear)) ||
292 (keysym == XKB_KEY_Return) || (keysym == XKB_KEY_Escape) ||
293 (keysym == XKB_KEY_KP_Space) || (keysym == XKB_KEY_KP_Tab) ||
294 (keysym == XKB_KEY_KP_Enter) ||
295 ((keysym >= XKB_KEY_KP_Multiply) && (keysym <= XKB_KEY_KP_9)) ||
296 (keysym == XKB_KEY_KP_Equal) || (keysym == XKB_KEY_Delete))))))
299 if (keysym == XKB_KEY_KP_Space)
300 c = (XKB_KEY_space & 0x7F);
301 else if (hbytes == 0xFF)
306 if (modifiers & ECORE_EVENT_MODIFIER_CTRL)
308 if (((c >= '@') && (c < '\177')) || c == ' ')
312 else if ((c >= '3') && (c <= '7'))
324 _device_modifiers_update_device(E_Input_Evdev *edev, E_Input_Evdev *from)
328 edev->xkb.depressed =
329 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_DEPRESSED);
331 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LATCHED);
333 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LOCKED);
335 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_EFFECTIVE);
337 mask = (edev->xkb.depressed | edev->xkb.latched);
339 if (mask & from->xkb.ctrl_mask)
340 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_CTRL;
341 if (mask & from->xkb.alt_mask)
342 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALT;
343 if (mask & from->xkb.shift_mask)
344 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
345 if (mask & from->xkb.win_mask)
346 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_WIN;
347 if (mask & from->xkb.scroll_mask)
348 edev->xkb.modifiers |= ECORE_EVENT_LOCK_SCROLL;
349 if (mask & from->xkb.num_mask)
350 edev->xkb.modifiers |= ECORE_EVENT_LOCK_NUM;
351 if (mask & from->xkb.caps_mask)
352 edev->xkb.modifiers |= ECORE_EVENT_LOCK_CAPS;
353 if (mask & from->xkb.altgr_mask)
354 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALTGR;
358 _device_modifiers_update(E_Input_Evdev *edev)
363 edev->xkb.modifiers = 0;
365 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
366 _device_modifiers_update_device(edev, edev);
369 EINA_LIST_FOREACH(edev->seat->devices, l, ed)
371 if (!(ed->caps & E_INPUT_SEAT_KEYBOARD)) continue;
372 _device_modifiers_update_device(edev, ed);
379 _device_remapped_key_get(E_Input_Evdev *edev, int code)
383 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, code);
384 if (!edev->key_remap_enabled) return code;
385 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->key_remap_hash, code);
387 ret = eina_hash_find(edev->key_remap_hash, &code);
389 if (ret) code = (int)(intptr_t)ret;
395 e_input_evdev_get_e_device(const char *path, Ecore_Device_Class clas)
397 const GList *dev_list = NULL;
399 E_Device *dev = NULL;
400 const char *identifier;
402 if (!path) return NULL;
404 dev_list = e_device_list_get();
405 if (!dev_list) return NULL;
412 identifier = e_device_identifier_get(dev);
413 if (!identifier) continue;
414 if ((e_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
423 EINTERN Ecore_Device *
424 e_input_evdev_get_ecore_device(const char *path, Ecore_Device_Class clas)
426 const Eina_List *dev_list = NULL;
428 Ecore_Device *dev = NULL;
429 const char *identifier;
431 if (!path) return NULL;
433 dev_list = ecore_device_list();
434 if (!dev_list) return NULL;
435 EINA_LIST_FOREACH(dev_list, l, dev)
438 identifier = ecore_device_identifier_get(dev);
439 if (!identifier) continue;
440 if ((ecore_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
447 _e_input_event_mouse_move_cb_free(void *data EINA_UNUSED, void *event)
449 Ecore_Event_Mouse_Move *ev = event;
451 if (ev->dev) ecore_device_unref(ev->dev);
457 _e_input_event_mouse_relative_move_cb_free(void *data EINA_UNUSED, void *event)
459 Ecore_Event_Mouse_Relative_Move *ev = event;
461 if (ev->dev) ecore_device_unref(ev->dev);
467 _e_input_event_mouse_wheel_cb_free(void *data EINA_UNUSED, void *event)
469 Ecore_Event_Mouse_Wheel *ev = event;
471 if (ev->dev) ecore_device_unref(ev->dev);
477 _e_input_event_mouse_button_cb_free(void *data EINA_UNUSED, void *event)
479 Ecore_Event_Mouse_Button *ev = event;
481 if (ev->dev) ecore_device_unref(ev->dev);
487 _e_input_event_key_cb_free(void *data EINA_UNUSED, void *event)
489 Ecore_Event_Key *ev = event;
491 if (e_input_thread_mode_get())
493 if (ev->dev) g_object_unref(ev->dev);
497 if (ev->dev) ecore_device_unref(ev->dev);
500 if (ev->data) E_FREE(ev->data);
506 _device_handle_key(struct libinput_device *device, struct libinput_event_keyboard *event)
509 E_Input_Backend *input;
511 uint32_t code, nsyms;
512 const xkb_keysym_t *syms;
513 enum libinput_key_state state;
515 xkb_keysym_t sym = XKB_KEY_NoSymbol;
516 char key[256] = {0, }, keyname[256] = {0, }, compose_buffer[256] = {0, };
518 char *tmp = NULL, *compose = NULL;
519 E_Keyrouter_Event_Data *key_data;
520 Ecore_Device *ecore_dev = NULL, *data;
521 E_Device *e_dev = NULL, *e_dev_data;
522 Eina_List *l = NULL, *l_next = NULL;
524 E_Comp_Config *comp_conf = NULL;
525 int *pressed_keycode = NULL, *idata = NULL;
526 Eina_Bool dup_found = EINA_FALSE;
527 const char *device_name = NULL;
528 Ecore_Device_Subclass device_subclas = ECORE_DEVICE_SUBCLASS_NONE;
530 if (!(edev = libinput_device_get_user_data(device)))
535 if (!(input = edev->seat->input))
540 if (!e_input_thread_mode_get())
542 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
543 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
545 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
547 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_KEYBOARD)
556 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
557 ecore_dev = edev->ecore_dev;
562 ERR("Failed to get source ecore device from event !\n");
566 device_name = ecore_device_name_get(ecore_dev);
567 device_subclas = ecore_device_subclass_get(ecore_dev);
571 if (edev->e_dev) e_dev = edev->e_dev;
572 else if (edev->e_dev_list && g_list_length(edev->e_dev_list) > 0)
574 glist = edev->e_dev_list;
577 e_dev_data = glist->data;
578 if (e_device_class_get(e_dev_data) == ECORE_DEVICE_CLASS_KEYBOARD)
584 glist = g_list_next(glist);
589 edev->e_dev = e_input_evdev_get_e_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
595 ERR("Failed to get source e device from event !\n");
599 device_name = e_device_name_get(e_dev);
600 device_subclas = e_device_subclass_get(e_dev);
603 timestamp = libinput_event_keyboard_get_time(event);
604 code = libinput_event_keyboard_get_key(event);
605 code = _device_remapped_key_get(edev, code + 8);
606 state = libinput_event_keyboard_get_key_state(event);
607 key_count = libinput_event_keyboard_get_seat_key_count(event);
609 if (state == LIBINPUT_KEY_STATE_PRESSED)
611 if ((edev->seat->dev->blocked & E_INPUT_SEAT_KEYBOARD) ||
612 (edev->seat->dev->server_blocked & E_INPUT_SEAT_KEYBOARD))
614 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
615 ELOGF("Key", "Press (keycode: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
616 code, device_name, blocked_client,
617 edev->seat->dev->server_blocked);
621 /* FIXME: Currently to maintain press/release event pair during input block,
622 * used Eina_List and this is method used in devicemgr module.
623 * But we need to consider which way is better to maintain key press/release pair.
626 EINA_LIST_FOREACH(edev->xkb.pressed_keys, l, idata)
630 dup_found = EINA_TRUE;
636 pressed_keycode = E_NEW(int, 1);
637 EINA_SAFETY_ON_NULL_RETURN(pressed_keycode);
638 *pressed_keycode = code;
640 edev->xkb.pressed_keys = eina_list_append(edev->xkb.pressed_keys, pressed_keycode);
645 dup_found = EINA_FALSE;
646 EINA_LIST_FOREACH_SAFE(edev->xkb.pressed_keys, l, l_next, idata)
650 edev->xkb.pressed_keys = eina_list_remove_list(edev->xkb.pressed_keys, l);
652 dup_found = EINA_TRUE;
658 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
659 ELOGF("Key", "Release (keycode: %d, device: %s) is blocked by %p", NULL,
660 code, device_name, blocked_client);
665 /* ignore key events that are not seat wide state changes */
666 if (((state == LIBINPUT_KEY_STATE_PRESSED) && (key_count != 1)) ||
667 ((state == LIBINPUT_KEY_STATE_RELEASED) && (key_count != 0)))
672 e_input_keyboard_grab_key_cb func = e_input_keyboard_grab_key_handler_get();
675 if (e_devicemgr_keyboard_grab_subtype_is_grabbed(device_subclas))
677 if (!e_input_thread_mode_get())
678 func(code, state, timestamp, ecore_dev);
680 func(code, state, timestamp, e_dev);
685 xkb_state_update_key(edev->xkb.state, code,
686 (state ? XKB_KEY_DOWN : XKB_KEY_UP));
688 /* get the keysym for this code */
689 nsyms = xkb_key_get_syms(edev->xkb.state, code, &syms);
691 if (nsyms == 1) sym = syms[0];
693 /* If no keysym was found, name it "Keycode-NNN" */
694 if (sym == XKB_KEY_NoSymbol)
695 snprintf(key, sizeof(key), "Keycode-%u", code);
698 /* get the keyname for this sym */
699 xkb_keysym_get_name(sym, key, sizeof(key));
704 /* If no keyname was found, name it "Keycode-NNN" */
705 snprintf(keyname, sizeof(keyname), "Keycode-%u", code);
709 memcpy(keyname, key, sizeof(keyname));
712 /* if shift is active, we need to transform the key to lower */
713 if (xkb_state_mod_index_is_active(edev->xkb.state,
714 xkb_map_mod_get_index(edev->xkb.keymap,
716 XKB_STATE_MODS_EFFECTIVE))
718 if (keyname[0] != '\0')
719 keyname[0] = tolower(keyname[0]);
722 if (_device_keysym_translate(sym, edev->xkb.modifiers,
723 compose_buffer, sizeof(compose_buffer)))
725 compose = eina_str_convert("ISO8859-1", "UTF-8", compose_buffer);
728 ERR("E Input cannot convert input key string '%s' to UTF-8. "
729 "Is Eina built with iconv support?", compose_buffer);
735 if (!compose) compose = compose_buffer;
737 e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) +
738 ((compose[0] != '\0') ? strlen(compose) : 0) + 3);
744 key_data = E_NEW(E_Keyrouter_Event_Data, 1);
752 e->keyname = (char *)(e + 1);
753 e->key = e->keyname + strlen(keyname) + 1;
754 e->compose = strlen(compose) ? e->key + strlen(key) + 1 : NULL;
755 e->string = e->compose;
757 strncpy((char *)e->keyname, keyname, strlen(keyname));
758 strncpy((char *)e->key, key, strlen(key));
759 if (strlen(compose)) strncpy((char *)e->compose, compose, strlen(compose));
761 e->window = (Ecore_Window)input->dev->window;
762 e->event_window = (Ecore_Window)input->dev->window;
763 e->root_window = (Ecore_Window)input->dev->window;
764 e->timestamp = timestamp;
769 _device_modifiers_update(edev);
771 e->modifiers = edev->xkb.modifiers;
773 comp_conf = e_comp_config_get();
775 if (comp_conf && comp_conf->input_log_enable)
776 ELOGF("Key", "%s (keyname: %s, keycode: %d, timestamp: %u, device: %s)", NULL, state?"Press":"Release", e->keyname, e->keycode, e->timestamp, device_name);
778 if (e_config->key_input_ttrace_enable)
780 TRACE_INPUT_BEGIN(ECORE_EVENT_KEY:%s:%s:%u:%lld, state ? "PRESS" : "RELEASE", e->keyname, timestamp, (long long unsigned int)libinput_event_keyboard_get_time_usec(event));
781 ELOGF("INPUT", "ECORE_EVENT_KEY:%s:%s:%u:%lld|B|", NULL, state ? "PRESS" : "RELEASE", e->keyname, timestamp, (long long unsigned int)libinput_event_keyboard_get_time_usec(event));
784 _e_input_key_event_list_add(e);
786 if (e_input_thread_mode_get())
788 e->dev = (Eo *)g_object_ref(e_dev);
789 e_input_event_add(input->event_source, state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
793 e->dev = ecore_device_ref(ecore_dev);
794 ecore_event_add(state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
797 if (e_config->key_input_ttrace_enable)
800 ELOGF("INPUT", "ECORE_EVENT_KEY|E|", NULL);
807 _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event)
809 E_Input_Backend *input;
810 Ecore_Event_Mouse_Move *ev;
811 Ecore_Device *ecore_dev = NULL, *data, *detent_data = NULL;
813 int x = 0, y = 0, w = 0, h = 0;
815 if (!(input = edev->seat->input)) return;
817 ecore_thread_main_loop_begin();
819 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
820 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
822 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
824 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
829 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
834 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
836 ecore_dev = detent_data;
841 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
842 ecore_dev = edev->ecore_dev;
847 ERR("Failed to get source ecore device from event !\n");
850 else if ((detent_data == ecore_dev) || e_devicemgr_detent_is_detent(ecore_device_name_get(ecore_dev)))
852 /* Do not process detent device's move events. */
856 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
858 _device_configured_size_get(edev, &x, &y, &w, &h);
860 if (edev->seat->ptr.ix < x)
861 edev->seat->ptr.dx = edev->seat->ptr.ix = x;
862 else if (edev->seat->ptr.ix >= (x + w))
863 edev->seat->ptr.dx = edev->seat->ptr.ix = (x + w - 1);
865 if (edev->seat->ptr.iy < y)
866 edev->seat->ptr.dy = edev->seat->ptr.iy = y;
867 else if (edev->seat->ptr.iy >= (y + h))
868 edev->seat->ptr.dy = edev->seat->ptr.iy = (y + h - 1);
870 edev->mouse.dx = edev->seat->ptr.dx;
871 edev->mouse.dy = edev->seat->ptr.dy;
873 ev->window = (Ecore_Window)input->dev->window;
874 ev->event_window = (Ecore_Window)input->dev->window;
875 ev->root_window = (Ecore_Window)input->dev->window;
876 if (event) ev->timestamp = libinput_event_pointer_get_time(event);
879 _device_modifiers_update(edev);
880 ev->modifiers = edev->xkb.modifiers;
882 ev->x = edev->seat->ptr.ix;
883 ev->y = edev->seat->ptr.iy;
887 ev->multi.device = edev->mt_slot;
888 ev->multi.radius = 1;
889 ev->multi.radius_x = 1;
890 ev->multi.radius_y = 1;
891 ev->multi.pressure = 1.0;
892 ev->multi.angle = 0.0;
895 ev->multi.root.x = ev->x;
896 ev->multi.root.y = ev->y;
898 ev->dev = ecore_device_ref(ecore_dev);
900 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
903 ecore_thread_main_loop_end();
907 _e_input_pointer_motion_post(E_Input_Evdev *edev)
909 _device_pointer_motion(edev, NULL);
913 _device_pointer_relative_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event, double dx[2], double dy[2])
915 E_Input_Backend *input;
916 Ecore_Event_Mouse_Relative_Move *ev;
917 Ecore_Device *ecore_dev = NULL, *data, *detent_data = NULL;
919 E_Comp_Config *comp_conf;
921 if (!(input = edev->seat->input)) return;
923 ecore_thread_main_loop_begin();
925 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
926 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
928 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
930 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
935 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
940 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
942 ecore_dev = detent_data;
947 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
948 ecore_dev = edev->ecore_dev;
953 ERR("Failed to get source ecore device from event !\n");
956 else if ((detent_data == ecore_dev) || e_devicemgr_detent_is_detent(ecore_device_name_get(ecore_dev)))
958 /* Do not process detent device's move events. */
962 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Relative_Move)))) return;
964 ev->window = (Ecore_Window)input->dev->window;
965 ev->event_window = (Ecore_Window)input->dev->window;
966 if (event) ev->timestamp = libinput_event_pointer_get_time(event);
968 ev->modifiers = edev->xkb.modifiers;
972 ev->dx_unaccel = (int)dx[1];
973 ev->dy_unaccel = (int)dy[1];
975 ev->dev = ecore_device_ref(ecore_dev);
977 comp_conf = e_comp_config_get();
978 if (comp_conf && comp_conf->input_log_enable)
979 ELOGF("Mouse", "Relative Move (time: %d, dx: %d, dy: %d, unaccel(%d, %d) device: %s)", NULL, ev->timestamp, ev->dx, ev->dy, ev->dx_unaccel, ev->dy_unaccel, ecore_device_name_get(ev->dev));
981 ecore_event_add(ECORE_EVENT_MOUSE_RELATIVE_MOVE, ev, _e_input_event_mouse_relative_move_cb_free, NULL);
984 ecore_thread_main_loop_end();
988 _device_pointer_motion_send(E_Input_Evdev *edev, struct libinput_event_pointer *event, double dx[2], double dy[2])
990 e_input_relative_motion_cb func = e_input_relative_motion_handler_get();
993 //func(dx, dy, time_us);
994 _device_pointer_relative_motion(edev, event, dx, dy);
998 double seat_dx, seat_dy, temp;
999 if (edev->disable_acceleration)
1010 if (edev->seat->ptr.swap)
1016 if (edev->seat->ptr.invert_x)
1018 if (edev->seat->ptr.invert_y)
1021 edev->seat->ptr.dx += seat_dx;
1022 edev->seat->ptr.dy += seat_dy;
1024 edev->mouse.dx = edev->seat->ptr.dx;
1025 edev->mouse.dy = edev->seat->ptr.dy;
1027 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
1028 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
1033 edev->seat->ptr.ix = edev->seat->ptr.dx;
1034 edev->seat->ptr.iy = edev->seat->ptr.dy;
1036 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1037 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1042 _device_pointer_motion(edev, event);
1047 _device_handle_pointer_motion(struct libinput_device *device, struct libinput_event_pointer *event)
1049 E_Input_Evdev *edev;
1050 double delta_x[2]; /* delta_x[0] for accelerated, delta_x[1] for unaccelerated */
1051 double delta_y[2]; /* delta_y[0] for accelerated, delta_y[1] for unaccelerated */
1053 if (!(edev = libinput_device_get_user_data(device)))
1058 delta_x[0] = libinput_event_pointer_get_dx(event);
1059 delta_x[1] = libinput_event_pointer_get_dx_unaccelerated(event);
1060 delta_y[0] = libinput_event_pointer_get_dy(event);
1061 delta_y[1] = libinput_event_pointer_get_dy_unaccelerated(event);
1063 _device_pointer_motion_send(edev, event, &delta_x[0], &delta_y[0]);
1067 _device_handle_pointer_motion_absolute(struct libinput_device *device, struct libinput_event_pointer *event)
1069 E_Input_Evdev *edev;
1072 if (!(edev = libinput_device_get_user_data(device)))
1077 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
1079 edev->mouse.dx = edev->seat->ptr.dx =
1080 libinput_event_pointer_get_absolute_x_transformed(event, w);
1081 edev->mouse.dy = edev->seat->ptr.dy =
1082 libinput_event_pointer_get_absolute_y_transformed(event, h);
1084 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
1085 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
1090 edev->seat->ptr.ix = edev->seat->ptr.dx;
1091 edev->seat->ptr.iy = edev->seat->ptr.dy;
1093 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1094 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1099 _device_pointer_motion(edev, event);
1103 _device_handle_button(struct libinput_device *device, struct libinput_event_pointer *event)
1105 E_Input_Evdev *edev;
1106 E_Input_Backend *input;
1107 Ecore_Event_Mouse_Button *ev;
1108 enum libinput_button_state state;
1109 uint32_t button, timestamp;
1110 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1112 E_Comp_Config *comp_conf = NULL;
1114 if (!(edev = libinput_device_get_user_data(device)))
1118 if (!(input = edev->seat->input))
1123 ecore_thread_main_loop_begin();
1125 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1126 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1128 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1130 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1135 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1140 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1142 ecore_dev = detent_data;
1147 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1148 ecore_dev = edev->ecore_dev;
1153 ERR("Failed to get source ecore device from event !\n");
1157 state = libinput_event_pointer_get_button_state(event);
1158 button = libinput_event_pointer_get_button(event);
1159 timestamp = libinput_event_pointer_get_time(event);
1161 button = ((button & 0x00F) + 1);
1162 if (button == 3) button = 2;
1163 else if (button == 2) button = 3;
1165 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
1169 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1170 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1173 ELOGF("Mouse", "Button Press (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
1174 button, ecore_device_name_get(ecore_dev), blocked_client,
1175 edev->seat->dev->server_blocked);
1180 edev->mouse.pressed_button |= (1 << button);
1185 if (!(edev->mouse.pressed_button & (1 << button)))
1187 ELOGF("Mouse", "Button Release (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
1188 button, ecore_device_name_get(ecore_dev), blocked_client,
1189 edev->seat->dev->server_blocked);
1192 edev->mouse.pressed_button &= ~(1 << button);
1195 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button))))
1200 ev->window = (Ecore_Window)input->dev->window;
1201 ev->event_window = (Ecore_Window)input->dev->window;
1202 ev->root_window = (Ecore_Window)input->dev->window;
1203 ev->timestamp = timestamp;
1204 ev->same_screen = 1;
1206 _device_modifiers_update(edev);
1207 ev->modifiers = edev->xkb.modifiers;
1209 ev->x = edev->seat->ptr.ix;
1210 ev->y = edev->seat->ptr.iy;
1214 ev->multi.device = edev->mt_slot;
1215 ev->multi.radius = 1;
1216 ev->multi.radius_x = 1;
1217 ev->multi.radius_y = 1;
1218 ev->multi.pressure = 1.0;
1219 ev->multi.angle = 0.0;
1220 ev->multi.x = ev->x;
1221 ev->multi.y = ev->y;
1222 ev->multi.root.x = ev->x;
1223 ev->multi.root.y = ev->y;
1224 ev->dev = ecore_device_ref(ecore_dev);
1228 unsigned int current;
1230 current = timestamp;
1231 edev->mouse.did_double = EINA_FALSE;
1232 edev->mouse.did_triple = EINA_FALSE;
1234 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1235 (button == edev->mouse.prev_button))
1237 edev->mouse.did_double = EINA_TRUE;
1238 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1239 (button == edev->mouse.last_button))
1241 edev->mouse.did_triple = EINA_TRUE;
1242 edev->mouse.prev = 0;
1243 edev->mouse.last = 0;
1248 edev->mouse.last = edev->mouse.prev;
1249 edev->mouse.prev = current;
1250 edev->mouse.last_button = edev->mouse.prev_button;
1251 edev->mouse.prev_button = button;
1254 ev->buttons = button;
1256 if (edev->mouse.did_double)
1257 ev->double_click = 1;
1258 if (edev->mouse.did_triple)
1259 ev->triple_click = 1;
1261 comp_conf = e_comp_config_get();
1262 if (comp_conf && comp_conf->input_log_enable)
1263 ELOGF("Mouse", "Button %s (btn: %d, device: %s)", NULL, state?"Press":"Release", button, ecore_device_name_get(ev->dev));
1266 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, _e_input_event_mouse_button_cb_free, NULL);
1268 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, _e_input_event_mouse_button_cb_free, NULL);
1271 ecore_thread_main_loop_end();
1274 #if !LIBINPUT_HAVE_SCROLL_VALUE_V120
1276 _axis_value_get(struct libinput_event_pointer *pointer_event, enum libinput_pointer_axis axis)
1278 enum libinput_pointer_axis_source source;
1279 double value = 0.0, value_discrete = 0.0;
1281 E_Comp_Config *comp_conf = NULL;
1283 comp_conf = e_comp_config_get();
1284 source = libinput_event_pointer_get_axis_source(pointer_event);
1287 case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL:
1288 value_discrete = libinput_event_pointer_get_axis_value_discrete(pointer_event, axis);
1289 value = libinput_event_pointer_get_axis_value(pointer_event, axis);
1290 if (comp_conf && comp_conf->input_log_enable)
1292 ELOGF("Axis", "SOURCE_WHEEL discrete: %lf (cf. value: %lf)", NULL, value_discrete, value);
1294 ret = (int)value_discrete;
1296 case LIBINPUT_POINTER_AXIS_SOURCE_FINGER:
1297 case LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS:
1298 value = libinput_event_pointer_get_axis_value(pointer_event, axis);
1299 if (comp_conf && comp_conf->input_log_enable)
1301 ELOGF("Axis", "SOURCE_FINGER/CONTINUOUS value: %lf", NULL, value);
1303 if (value >= E_INPUT_FINGER_SCROLL_THRESHOLD)
1305 else if (value <= E_INPUT_FINGER_SCROLL_THRESHOLD * (-1))
1318 _device_handle_axis(struct libinput_device *device, struct libinput_event_pointer *event)
1320 E_Input_Evdev *edev;
1321 E_Input_Backend *input;
1322 Ecore_Event_Mouse_Wheel *ev;
1324 enum libinput_pointer_axis axis;
1325 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1327 E_Comp_Config *comp_conf = NULL;
1328 int direction = 0, z = 0;
1330 if (!(edev = libinput_device_get_user_data(device)))
1334 if (!(input = edev->seat->input))
1339 ecore_thread_main_loop_begin();
1341 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1342 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1344 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1346 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1351 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1356 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1358 ecore_dev = detent_data;
1363 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1364 ecore_dev = edev->ecore_dev;
1369 ERR("Failed to get source ecore device from event !\n");
1373 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1374 if (libinput_event_pointer_has_axis(event, axis))
1375 z = _axis_value_get(event, axis);
1377 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1378 if (libinput_event_pointer_has_axis(event, axis))
1381 z = _axis_value_get(event, axis);
1386 ELOGF("Mouse", "Axis event is ignored since it has zero value", NULL);
1390 comp_conf = e_comp_config_get();
1391 if (comp_conf && comp_conf->e_wheel_click_angle)
1393 z = (int)(z * comp_conf->e_wheel_click_angle);
1396 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1397 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1399 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
1402 ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1403 direction, z, blocked_client, edev->seat->dev->server_blocked);
1405 ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1406 direction, z, blocked_client, edev->seat->dev->server_blocked);
1411 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1416 timestamp = libinput_event_pointer_get_time(event);
1418 ev->window = (Ecore_Window)input->dev->window;
1419 ev->event_window = (Ecore_Window)input->dev->window;
1420 ev->root_window = (Ecore_Window)input->dev->window;
1421 ev->timestamp = timestamp;
1422 ev->same_screen = 1;
1424 _device_modifiers_update(edev);
1425 ev->modifiers = edev->xkb.modifiers;
1427 ev->x = edev->seat->ptr.ix;
1428 ev->y = edev->seat->ptr.iy;
1432 ev->direction = direction;
1434 if (comp_conf && comp_conf->input_log_enable)
1437 ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1439 ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1443 ev->dev = ecore_device_ref(ecore_dev);
1444 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1447 ecore_thread_main_loop_end();
1451 #if LIBINPUT_HAVE_SCROLL_VALUE_V120
1453 _scroll_value_get(struct libinput_event_pointer *pointer_event, enum libinput_pointer_axis axis, E_Input_Axis_Source source)
1456 double value_v120 = 0.0;
1458 E_Comp_Config *comp_conf = NULL;
1460 comp_conf = e_comp_config_get();
1463 case E_INPUT_AXIS_SOURCE_WHEEL:
1464 value_v120 = libinput_event_pointer_get_scroll_value_v120(pointer_event, axis);
1465 value = libinput_event_pointer_get_scroll_value(pointer_event, axis);
1466 if (comp_conf && comp_conf->input_log_enable)
1468 ELOGF("Scroll", "SOURCE_WHEEL value_v120: %lf (cf. value: %lf)", NULL, value_v120, value);
1470 if (((int)value_v120 % E_INPUT_POINTER_AXIS_DISCRETE_STEP) != 0)
1472 ERR("Wheel movements should be multiples (or fractions) of 120!\n");
1477 ret = value_v120 / E_INPUT_POINTER_AXIS_DISCRETE_STEP;
1480 case E_INPUT_AXIS_SOURCE_FINGER:
1481 case E_INPUT_AXIS_SOURCE_CONTINUOUS:
1482 value = libinput_event_pointer_get_scroll_value(pointer_event, axis);
1483 if (comp_conf && comp_conf->input_log_enable)
1485 ELOGF("Scroll", "SOURCE_FINGER/CONTINUOUS value: %lf", NULL, value);
1487 if (value >= E_INPUT_FINGER_SCROLL_THRESHOLD)
1489 else if (value <= E_INPUT_FINGER_SCROLL_THRESHOLD * (-1))
1502 _device_handle_axis_v120(struct libinput_device *device, struct libinput_event_pointer *event, E_Input_Axis_Source source)
1504 E_Input_Evdev *edev;
1505 E_Input_Backend *input;
1506 Ecore_Event_Mouse_Wheel *ev;
1508 enum libinput_pointer_axis axis;
1509 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1511 E_Comp_Config *comp_conf = NULL;
1512 int direction = 0, z = 0;
1514 if (!(edev = libinput_device_get_user_data(device)))
1518 if (!(input = edev->seat->input))
1523 ecore_thread_main_loop_begin();
1525 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1526 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1528 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1530 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1535 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1540 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1542 ecore_dev = detent_data;
1547 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1548 ecore_dev = edev->ecore_dev;
1553 ERR("Failed to get source ecore device from event !\n");
1557 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1558 if (libinput_event_pointer_has_axis(event, axis))
1559 z = _scroll_value_get(event, axis, source);
1561 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1562 if (libinput_event_pointer_has_axis(event, axis))
1565 z = _scroll_value_get(event, axis, source);
1570 ELOGF("Mouse", "Scroll event is ignored since it has zero value", NULL);
1574 comp_conf = e_comp_config_get();
1575 if (comp_conf && comp_conf->e_wheel_click_angle)
1577 z = (int)(z * comp_conf->e_wheel_click_angle);
1580 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1581 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1583 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
1585 ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1586 direction, z, blocked_client, edev->seat->dev->server_blocked);
1588 ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1589 direction, z, blocked_client, edev->seat->dev->server_blocked);
1594 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1599 timestamp = libinput_event_pointer_get_time(event);
1601 ev->window = (Ecore_Window)input->dev->window;
1602 ev->event_window = (Ecore_Window)input->dev->window;
1603 ev->root_window = (Ecore_Window)input->dev->window;
1604 ev->timestamp = timestamp;
1605 ev->same_screen = 1;
1607 _device_modifiers_update(edev);
1608 ev->modifiers = edev->xkb.modifiers;
1610 ev->x = edev->seat->ptr.ix;
1611 ev->y = edev->seat->ptr.iy;
1615 ev->direction = direction;
1617 if (comp_conf && comp_conf->input_log_enable)
1620 ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1622 ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1625 ev->dev = ecore_device_ref(ecore_dev);
1626 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1629 ecore_thread_main_loop_end();
1634 _device_handle_touch_event_send(E_Input_Evdev *edev, struct libinput_event_touch *event, int state)
1636 E_Input_Backend *input;
1637 Ecore_Event_Mouse_Button *ev;
1638 uint32_t timestamp, button = 0;
1639 Ecore_Device *ecore_dev = NULL, *data;
1643 if (!(input = edev->seat->input)) return;
1645 ecore_thread_main_loop_begin();
1647 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1648 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1650 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1652 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1661 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1662 ecore_dev = edev->ecore_dev;
1667 ERR("Failed to get source ecore device from event !\n");
1671 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) goto end;
1673 timestamp = libinput_event_touch_get_time(event);
1675 ev->window = (Ecore_Window)input->dev->window;
1676 ev->event_window = (Ecore_Window)input->dev->window;
1677 ev->root_window = (Ecore_Window)input->dev->window;
1678 ev->timestamp = timestamp;
1679 ev->same_screen = 1;
1681 _device_modifiers_update(edev);
1682 ev->modifiers = edev->xkb.modifiers;
1684 ev->x = edev->seat->ptr.ix;
1685 ev->y = edev->seat->ptr.iy;
1689 ev->multi.device = edev->mt_slot;
1690 ev->multi.radius = 1;
1691 ev->multi.radius_x = 1;
1692 ev->multi.radius_y = 1;
1693 ev->multi.pressure = 1.0;
1694 ev->multi.angle = 0.0;
1695 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1696 if (libinput_event_get_type(libinput_event_touch_get_base_event(event))
1697 == LIBINPUT_EVENT_TOUCH_DOWN)
1699 if (libinput_event_touch_has_minor(event))
1700 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1701 if (libinput_event_touch_has_major(event))
1702 ev->multi.radius_y = libinput_event_touch_get_major(event);
1703 if (libinput_event_touch_has_pressure(event))
1704 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1705 if (libinput_event_touch_has_orientation(event))
1706 ev->multi.angle = libinput_event_touch_get_orientation(event);
1709 ev->multi.x = ev->x;
1710 ev->multi.y = ev->y;
1711 ev->multi.root.x = ev->x;
1712 ev->multi.root.y = ev->y;
1713 ev->dev = ecore_device_ref(ecore_dev);
1715 if (state == ECORE_EVENT_MOUSE_BUTTON_DOWN)
1717 unsigned int current;
1719 current = timestamp;
1720 edev->mouse.did_double = EINA_FALSE;
1721 edev->mouse.did_triple = EINA_FALSE;
1723 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1724 (button == edev->mouse.prev_button))
1726 edev->mouse.did_double = EINA_TRUE;
1727 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1728 (button == edev->mouse.last_button))
1730 edev->mouse.did_triple = EINA_TRUE;
1731 edev->mouse.prev = 0;
1732 edev->mouse.last = 0;
1737 edev->mouse.last = edev->mouse.prev;
1738 edev->mouse.prev = current;
1739 edev->mouse.last_button = edev->mouse.prev_button;
1740 edev->mouse.prev_button = button;
1741 edev->touch.pressed |= (1 << ev->multi.device);
1745 edev->touch.pressed &= ~(1 << ev->multi.device);
1748 ev->buttons = ((button & 0x00F) + 1);
1750 if (edev->mouse.did_double)
1751 ev->double_click = 1;
1752 if (edev->mouse.did_triple)
1753 ev->triple_click = 1;
1755 ecore_event_add(state, ev, _e_input_event_mouse_button_cb_free, NULL);
1758 ecore_thread_main_loop_end();
1762 _device_handle_touch_motion_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1764 E_Input_Backend *input;
1765 Ecore_Event_Mouse_Move *ev;
1766 Ecore_Device *ecore_dev = NULL, *data;
1770 if (!(input = edev->seat->input)) return;
1772 ecore_thread_main_loop_begin();
1774 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1775 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1777 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1779 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1788 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1789 ecore_dev = edev->ecore_dev;
1794 ERR("Failed to get source ecore device from event !\n");
1798 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) goto end;
1800 ev->window = (Ecore_Window)input->dev->window;
1801 ev->event_window = (Ecore_Window)input->dev->window;
1802 ev->root_window = (Ecore_Window)input->dev->window;
1803 ev->timestamp = libinput_event_touch_get_time(event);
1804 ev->same_screen = 1;
1806 _device_modifiers_update(edev);
1807 ev->modifiers = edev->xkb.modifiers;
1809 ev->x = edev->seat->ptr.ix;
1810 ev->y = edev->seat->ptr.iy;
1814 ev->multi.device = edev->mt_slot;
1815 ev->multi.radius = 1;
1816 ev->multi.radius_x = 1;
1817 ev->multi.radius_y = 1;
1818 ev->multi.pressure = 1.0;
1819 ev->multi.angle = 0.0;
1820 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1821 if (libinput_event_touch_has_minor(event))
1822 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1823 if (libinput_event_touch_has_major(event))
1824 ev->multi.radius_y = libinput_event_touch_get_major(event);
1825 if (libinput_event_touch_has_pressure(event))
1826 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1827 if (libinput_event_touch_has_orientation(event))
1828 ev->multi.angle = libinput_event_touch_get_orientation(event);
1830 ev->multi.x = ev->x;
1831 ev->multi.y = ev->y;
1832 ev->multi.root.x = ev->x;
1833 ev->multi.root.y = ev->y;
1834 ev->dev = ecore_device_ref(ecore_dev);
1836 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
1839 ecore_thread_main_loop_end();
1843 _device_handle_touch_cancel_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1845 E_Input_Backend *input;
1846 Ecore_Event_Mouse_Button *ev;
1847 uint32_t timestamp, button = 0;
1848 Ecore_Device *ecore_dev = NULL, *data;
1852 if (!(input = edev->seat->input)) return;
1854 ecore_thread_main_loop_begin();
1856 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1857 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1859 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1861 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1870 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1871 ecore_dev = edev->ecore_dev;
1876 ERR("Failed to get source ecore device from event !\n");
1880 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) goto end;
1882 timestamp = libinput_event_touch_get_time(event);
1884 ev->window = (Ecore_Window)input->dev->window;
1885 ev->event_window = (Ecore_Window)input->dev->window;
1886 ev->root_window = (Ecore_Window)input->dev->window;
1887 ev->timestamp = timestamp;
1888 ev->same_screen = 1;
1890 ev->x = edev->seat->ptr.ix;
1891 ev->y = edev->seat->ptr.iy;
1895 ev->multi.device = edev->mt_slot;
1896 ev->multi.radius = 1;
1897 ev->multi.radius_x = 1;
1898 ev->multi.radius_y = 1;
1899 ev->multi.pressure = 1.0;
1900 ev->multi.angle = 0.0;
1901 ev->multi.x = ev->x;
1902 ev->multi.y = ev->y;
1903 ev->multi.root.x = ev->x;
1904 ev->multi.root.y = ev->y;
1906 edev->touch.pressed &= ~(1 << ev->multi.device);
1908 ev->buttons = ((button & 0x00F) + 1);
1909 ev->dev = ecore_device_ref(ecore_dev);
1911 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev, _e_input_event_mouse_button_cb_free, NULL);
1914 ecore_thread_main_loop_end();
1918 _device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, int *w, int *h)
1920 E_Output *output = NULL;
1922 EINA_SAFETY_ON_NULL_RETURN(edev);
1924 if (!edev->output_configured)
1926 if (edev->output_name)
1928 output = e_output_find(edev->output_name);
1931 edev->mouse.minx = output->config.geom.x;
1932 edev->mouse.miny = output->config.geom.y;
1933 edev->mouse.maxw = output->config.geom.w;
1934 edev->mouse.maxh = output->config.geom.h;
1935 if (edev->caps & E_INPUT_SEAT_POINTER)
1937 edev->seat->ptr.dx = (double)(edev->mouse.maxw / 2);
1938 edev->seat->ptr.dy = (double)(edev->mouse.maxh / 2);
1939 edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
1940 edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
1941 edev->mouse.dx = edev->seat->ptr.dx;
1942 edev->mouse.dy = edev->seat->ptr.dy;
1947 edev->output_configured = EINA_TRUE;
1948 ELOGF("E_INPUT_EVDEV", "Device is configured by output x:%d,y:%d (w:%d, h:%d)",
1949 NULL, edev->mouse.minx, edev->mouse.miny, edev->mouse.maxw, edev->mouse.maxh);
1951 if (x) *x = edev->mouse.minx;
1952 if (y) *y = edev->mouse.miny;
1953 if (w) *w = edev->mouse.maxw;
1954 if (h) *h = edev->mouse.maxh;
1958 _device_handle_touch_down(struct libinput_device *device, struct libinput_event_touch *event)
1960 E_Input_Evdev *edev;
1961 int x = 0, y = 0, w = 0, h = 0;
1962 E_Comp_Config *comp_conf = NULL;
1964 if (!(edev = libinput_device_get_user_data(device)))
1969 _device_configured_size_get(edev, &x, &y, &w, &h);
1971 edev->mouse.dx = edev->seat->ptr.ix = edev->seat->ptr.dx =
1972 x + libinput_event_touch_get_x_transformed(event, w);
1973 edev->mouse.dy = edev->seat->ptr.iy = edev->seat->ptr.dy =
1974 y + libinput_event_touch_get_y_transformed(event, h);
1976 edev->mt_slot = libinput_event_touch_get_slot(event);
1977 if (edev->mt_slot < 0)
1979 /* FIXME: The single touch device return slot id -1
1980 * But currently we have no API to distinguish multi touch or single touch
1981 * After libinput 1.11 version, libinput provides get_touch_count API,
1982 * so we can distinguish multi touch device or single touch device.
1984 if (edev->mt_slot == -1)
1988 WRN("%d slot touch down events are not supported\n", edev->mt_slot);
1993 if (edev->mt_slot < e_input_touch_max_count_get())
1995 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
1996 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
1999 comp_conf = e_comp_config_get();
2000 if (comp_conf && comp_conf->input_log_enable)
2001 ELOGF("Touch", "Down (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2003 atomic_fetch_or(&edev->touch.raw_pressed, (1 << edev->mt_slot));
2005 if (edev->touch.blocked)
2007 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
2008 ELOGF("Touch", "Down (id: %d, x: %d, y: %d) is blocked by %p, server: 0x%x", NULL,
2009 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, blocked_client,
2010 edev->seat->dev->server_blocked);
2014 _device_handle_touch_motion_send(edev, event);
2015 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_DOWN);
2019 _device_handle_touch_motion(struct libinput_device *device, struct libinput_event_touch *event)
2021 E_Input_Evdev *edev;
2022 int x = 0, y = 0, w = 0, h = 0;
2024 if (!(edev = libinput_device_get_user_data(device)))
2029 _device_configured_size_get(edev, &x, &y, &w, &h);
2031 edev->mouse.dx = edev->seat->ptr.dx =
2032 x + libinput_event_touch_get_x_transformed(event, w);
2033 edev->mouse.dy = edev->seat->ptr.dy =
2034 y + libinput_event_touch_get_y_transformed(event, h);
2036 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
2037 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
2042 edev->seat->ptr.ix = edev->seat->ptr.dx;
2043 edev->seat->ptr.iy = edev->seat->ptr.dy;
2045 edev->mt_slot = libinput_event_touch_get_slot(event);
2046 if (edev->mt_slot < 0)
2048 /* FIXME: The single touch device return slot id -1
2049 * But currently we have no API to distinguish multi touch or single touch
2050 * After libinput 1.11 version, libinput provides get_touch_count API,
2051 * so we can distinguish multi touch device or single touch device.
2053 if (edev->mt_slot == -1)
2057 WRN("%d slot touch motion events are not supported\n", edev->mt_slot);
2062 if (edev->mt_slot < e_input_touch_max_count_get())
2064 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
2065 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
2068 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
2070 if (edev->touch.blocked)
2076 _device_handle_touch_motion_send(edev, event);
2080 _device_handle_touch_up(struct libinput_device *device, struct libinput_event_touch *event)
2082 E_Input_Evdev *edev;
2083 E_Comp_Config *comp_conf = NULL;
2085 if (!(edev = libinput_device_get_user_data(device)))
2090 edev->mt_slot = libinput_event_touch_get_slot(event);
2091 if (edev->mt_slot < 0)
2093 /* FIXME: The single touch device return slot id -1
2094 * But currently we have no API to distinguish multi touch or single touch
2095 * After libinput 1.11 version, libinput provides get_touch_count API,
2096 * so we can distinguish multi touch device or single touch device.
2098 if (edev->mt_slot == -1)
2102 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
2107 if (edev->mt_slot < e_input_touch_max_count_get())
2109 edev->mouse.dx = edev->seat->ptr.dx = edev->seat->ptr.ix =
2110 edev->touch.coords[edev->mt_slot].x;
2111 edev->mouse.dy = edev->seat->ptr.dy = edev->seat->ptr.iy =
2112 edev->touch.coords[edev->mt_slot].y;
2115 comp_conf = e_comp_config_get();
2116 if (comp_conf && comp_conf->input_log_enable)
2117 ELOGF("Touch", "Up (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2119 atomic_fetch_and(&edev->touch.raw_pressed, ~(1 << edev->mt_slot));
2121 if (edev->touch.blocked)
2123 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
2125 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
2126 ELOGF("Touch", "Up (id: %d, x: %d, y: %d) is blocked by %p, server(0x%x)", NULL,
2127 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, blocked_client,
2128 edev->seat->dev->server_blocked);
2130 if (edev->touch.raw_pressed == 0x0)
2132 edev->touch.blocked = EINA_FALSE;
2138 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_UP);
2142 _device_handle_touch_cancel(struct libinput_device *device, struct libinput_event_touch *event)
2144 E_Input_Evdev *edev;
2145 E_Comp_Config *comp_conf = NULL;
2147 if (!(edev = libinput_device_get_user_data(device)))
2152 edev->mt_slot = libinput_event_touch_get_slot(event);
2153 if (edev->mt_slot < 0)
2155 /* FIXME: The single touch device return slot id -1
2156 * But currently we have no API to distinguish multi touch or single touch
2157 * After libinput 1.11 version, libinput provides get_touch_count API,
2158 * so we can distinguish multi touch device or single touch device.
2160 if (edev->mt_slot == -1)
2164 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
2169 comp_conf = e_comp_config_get();
2170 if (comp_conf && comp_conf->input_log_enable)
2171 ELOGF("Touch", "cancel (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2173 _device_handle_touch_cancel_send(edev, event);
2178 _device_handle_touch_frame(struct libinput_device *device EINA_UNUSED, struct libinput_event_touch *event EINA_UNUSED)
2180 /* DBG("Unhandled Touch Frame Event"); */
2184 _e_input_aux_data_event_free(void *user_data EINA_UNUSED, void *ev)
2186 Ecore_Event_Axis_Update *e = (Ecore_Event_Axis_Update *)ev;
2188 if (e->axis) free(e->axis);
2189 if (e->dev) ecore_device_unref(e->dev);
2195 _device_handle_touch_aux_data(struct libinput_device *device, struct libinput_event_touch_aux_data *event)
2197 E_Input_Evdev *edev;
2198 E_Input_Backend *input;
2199 Ecore_Event_Axis_Update *ev;
2201 Ecore_Device *ecore_dev = NULL, *data;
2203 E_Comp_Config *comp_conf;
2205 ecore_thread_main_loop_begin();
2207 if (libinput_event_touch_aux_data_get_type(event) != LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM &&
2208 libinput_event_touch_aux_data_get_value(event) > 0)
2211 if (!(edev = libinput_device_get_user_data(device))) goto end;
2212 if (!(input = edev->seat->input)) goto end;
2214 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
2215 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
2217 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
2219 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
2228 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
2229 ecore_dev = edev->ecore_dev;
2234 ERR("Failed to get source ecore device from event !\n");
2238 if (!(ev = calloc(1, sizeof(Ecore_Event_Axis_Update)))) goto end;
2240 ev->window = (Ecore_Window)input->dev->window;
2241 ev->event_window = (Ecore_Window)input->dev->window;
2242 ev->root_window = (Ecore_Window)input->dev->window;
2243 ev->timestamp = libinput_event_touch_aux_data_get_time(event);
2245 axis = (Ecore_Axis *)calloc(1, sizeof(Ecore_Axis));
2248 axis->label = ECORE_AXIS_LABEL_TOUCH_PALM;
2249 axis->value = libinput_event_touch_aux_data_get_value(event);
2254 comp_conf = e_comp_config_get();
2255 if (comp_conf && comp_conf->input_log_enable)
2256 ELOGF("Touch", "Axis (label: %d, value: %lf)", NULL, axis?axis->label:-1, axis?axis->value:0.0);
2258 ev->dev = ecore_device_ref(ecore_dev);
2260 ecore_event_add(ECORE_EVENT_AXIS_UPDATE, ev, _e_input_aux_data_event_free, NULL);
2263 ecore_thread_main_loop_end();
2267 _e_input_evdev_device_create(E_Input_Seat *seat, struct libinput_device *device)
2269 E_Input_Evdev *edev;
2270 E_Input_Backend *b_input;
2271 const char *output_name;
2273 EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
2275 /* try to allocate space for new evdev */
2276 if (!(edev = calloc(1, sizeof(E_Input_Evdev)))) return NULL;
2279 edev->device = device;
2280 edev->path = eina_stringshare_printf("%s/%s", e_input_base_dir_get(), libinput_device_get_sysname(device));
2282 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
2284 edev->caps |= E_INPUT_SEAT_KEYBOARD;
2285 _device_keyboard_setup(edev);
2288 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
2290 edev->caps |= E_INPUT_SEAT_POINTER;
2292 /* TODO: make this configurable */
2293 edev->mouse.threshold = 250;
2295 b_input = seat->input;
2296 if (b_input->left_handed == EINA_TRUE)
2298 if (libinput_device_config_left_handed_set(device, 1) !=
2299 LIBINPUT_CONFIG_STATUS_SUCCESS)
2301 WRN("Failed to set left hand mode about device: %s\n",
2302 libinput_device_get_name(device));
2307 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
2310 edev->caps |= E_INPUT_SEAT_TOUCH;
2311 palm_code = libinput_device_touch_aux_data_get_code(LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM);
2312 if (libinput_device_touch_has_aux_data(device, palm_code))
2314 libinput_device_touch_set_aux_data(device, palm_code);
2317 _device_touch_count_update(edev);
2319 edev->touch.coords = calloc(1, sizeof(E_Input_Coord)*e_input_touch_max_count_get());
2321 if (!edev->touch.coords)
2322 ERR("Failed to allocate memory for touch coords !\n");
2325 output_name = libinput_device_get_output_name(device);
2328 eina_stringshare_replace(&edev->output_name, output_name);
2329 ELOGF("E_INPUT_EVDEV", "Device has output_name:%s", NULL, output_name);
2332 libinput_device_set_user_data(device, edev);
2333 libinput_device_ref(device);
2335 /* configure device */
2336 _device_configure(edev);
2342 _e_input_evdev_device_destroy(E_Input_Evdev *edev)
2345 EINA_SAFETY_ON_NULL_RETURN(edev);
2347 ecore_thread_main_loop_begin();
2349 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
2351 if (edev->xkb.state) xkb_state_unref(edev->xkb.state);
2353 if (edev->xkb.keymap) xkb_map_unref(edev->xkb.keymap);
2356 if (edev->ecore_dev) ecore_device_del(edev->ecore_dev);
2357 if (edev->ecore_dev_list)
2358 EINA_LIST_FREE(edev->ecore_dev_list, dev)
2360 ecore_device_del(dev);
2363 if (edev->e_dev) g_object_unref(edev->e_dev);
2364 if (edev->e_dev_list)
2366 GList *glist = edev->e_dev_list;
2370 e_dev = glist->data;
2371 g_object_unref(e_dev);
2373 glist = g_list_next(glist);
2376 if (edev->path) eina_stringshare_del(edev->path);
2377 if (edev->device) libinput_device_unref(edev->device);
2378 if (edev->key_remap_hash) eina_hash_free(edev->key_remap_hash);
2379 if (edev->touch.coords)
2381 free(edev->touch.coords);
2382 edev->touch.coords = NULL;
2384 eina_stringshare_del(edev->output_name);
2386 ecore_thread_main_loop_end();
2392 _e_input_evdev_event_process(struct libinput_event *event)
2394 struct libinput_device *device;
2395 Eina_Bool ret = EINA_TRUE;
2397 device = libinput_event_get_device(event);
2398 switch (libinput_event_get_type(event))
2400 case LIBINPUT_EVENT_KEYBOARD_KEY:
2401 _device_handle_key(device, libinput_event_get_keyboard_event(event));
2403 case LIBINPUT_EVENT_POINTER_MOTION:
2404 _device_handle_pointer_motion(device,
2405 libinput_event_get_pointer_event(event));
2407 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
2408 _device_handle_pointer_motion_absolute(device,
2409 libinput_event_get_pointer_event(event));
2411 case LIBINPUT_EVENT_POINTER_BUTTON:
2412 _device_handle_button(device, libinput_event_get_pointer_event(event));
2414 case LIBINPUT_EVENT_POINTER_AXIS:
2415 #if !LIBINPUT_HAVE_SCROLL_VALUE_V120
2416 _device_handle_axis(device, libinput_event_get_pointer_event(event));
2419 #if LIBINPUT_HAVE_SCROLL_VALUE_V120
2420 case LIBINPUT_EVENT_POINTER_SCROLL_WHEEL:
2421 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_WHEEL);
2423 case LIBINPUT_EVENT_POINTER_SCROLL_FINGER:
2424 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_FINGER);
2426 case LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS:
2427 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_CONTINUOUS);
2430 case LIBINPUT_EVENT_TOUCH_DOWN:
2431 _device_handle_touch_down(device, libinput_event_get_touch_event(event));
2433 case LIBINPUT_EVENT_TOUCH_MOTION:
2434 _device_handle_touch_motion(device,
2435 libinput_event_get_touch_event(event));
2437 case LIBINPUT_EVENT_TOUCH_UP:
2438 _device_handle_touch_up(device, libinput_event_get_touch_event(event));
2440 case LIBINPUT_EVENT_TOUCH_CANCEL:
2441 _device_handle_touch_cancel(device, libinput_event_get_touch_event(event));
2443 case LIBINPUT_EVENT_TOUCH_FRAME:
2444 _device_handle_touch_frame(device, libinput_event_get_touch_event(event));
2446 case LIBINPUT_EVENT_TOUCH_AUX_DATA:
2447 _device_handle_touch_aux_data(device, libinput_event_get_touch_aux_data(event));
2458 * @brief Set the axis size of the given device.
2460 * @param dev The device to set the axis size to.
2461 * @param w The width of the axis.
2462 * @param h The height of the axis.
2464 * This function sets set the width @p w and height @p h of the axis
2465 * of device @p dev. If @p dev is a relative input device, a width and
2466 * height must set for it. If its absolute set the ioctl correctly, if
2467 * not, unsupported device.
2470 e_input_evdev_axis_size_set(E_Input_Evdev *edev, int w, int h)
2474 enum libinput_config_status status;
2475 struct udev_device *udev_device = NULL;
2477 EINA_SAFETY_ON_NULL_RETURN(edev);
2478 EINA_SAFETY_ON_TRUE_RETURN((w == 0) || (h == 0));
2480 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
2481 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
2484 udev_device = libinput_device_get_udev_device(edev->device);
2487 ERR("no udev_device");
2491 vals = udev_device_get_property_value(udev_device, "WL_CALIBRATION");
2493 (sscanf(vals, "%f %f %f %f %f %f",
2494 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
2497 ELOGF("E_INPUT_EVDEV", "axis_size_set cal[%lf %lf %lf %lf %lf %lf] (%d x %d)",
2498 NULL, cal[0], cal[1], cal[2], cal[3], cal[4], cal[5], w, h);
2504 libinput_device_config_calibration_set_matrix(edev->device, cal);
2506 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
2507 ERR("Failed to apply calibration");
2510 EINTERN const char *
2511 e_input_evdev_name_get(E_Input_Evdev *evdev)
2513 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2514 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2516 return libinput_device_get_name(evdev->device);
2519 EINTERN const char *
2520 e_input_evdev_sysname_get(E_Input_Evdev *evdev)
2522 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2523 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2525 return libinput_device_get_sysname(evdev->device);
2529 e_input_evdev_key_remap_enable(E_Input_Evdev *edev, Eina_Bool enable)
2531 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2532 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2534 edev->key_remap_enabled = enable;
2536 if (enable == EINA_FALSE && edev->key_remap_hash)
2538 eina_hash_free(edev->key_remap_hash);
2539 edev->key_remap_hash = NULL;
2546 e_input_evdev_key_remap_set(E_Input_Evdev *edev, int *from_keys, int *to_keys, int num)
2550 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2551 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2552 EINA_SAFETY_ON_NULL_RETURN_VAL(from_keys, EINA_FALSE);
2553 EINA_SAFETY_ON_NULL_RETURN_VAL(to_keys, EINA_FALSE);
2554 EINA_SAFETY_ON_TRUE_RETURN_VAL(num <= 0, EINA_FALSE);
2555 EINA_SAFETY_ON_TRUE_RETURN_VAL(!edev->key_remap_enabled, EINA_FALSE);
2557 if (edev->key_remap_hash == NULL)
2558 edev->key_remap_hash = eina_hash_int32_new(NULL);
2560 if (edev->key_remap_hash == NULL)
2562 ERR("Failed to set remap key information : creating a hash is failed.");
2566 for (i = 0; i < num ; i++)
2568 if (!from_keys[i] || !to_keys[i])
2570 ERR("Failed to set remap key information : given arguments are invalid.");
2575 for (i = 0; i < num ; i++)
2577 eina_hash_add(edev->key_remap_hash, &from_keys[i], (void *)(intptr_t)to_keys[i]);
2584 e_input_evdev_wheel_click_angle_get(E_Input_Evdev *dev)
2586 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, -1);
2587 return libinput_device_config_scroll_get_wheel_click_angle(dev->device);
2591 e_input_evdev_touch_calibration_set(E_Input_Evdev *edev, float matrix[6])
2593 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2594 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2596 if (!libinput_device_config_calibration_has_matrix(edev->device) ||
2597 !libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_TOUCH))
2600 if (libinput_device_config_calibration_set_matrix(edev->device, matrix) !=
2601 LIBINPUT_CONFIG_STATUS_SUCCESS)
2603 WRN("Failed to set input transformation about device: %s\n",
2604 libinput_device_get_name(edev->device));
2612 e_input_evdev_mouse_accel_speed_set(E_Input_Evdev *edev, double speed)
2614 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2615 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2617 if (!libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
2620 if (!libinput_device_config_accel_is_available(edev->device))
2623 if (libinput_device_config_accel_set_speed(edev->device, speed) !=
2624 LIBINPUT_CONFIG_STATUS_SUCCESS)
2626 WRN("Failed to set mouse accel about device: %s\n",
2627 libinput_device_get_name(edev->device));
2634 EINTERN unsigned int
2635 e_input_evdev_touch_pressed_get(E_Input_Evdev *edev)
2637 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, 0x0);
2639 return edev->touch.pressed;
2643 e_input_evdev_seatname_get(E_Input_Evdev *evdev)
2645 struct libinput_seat *libinput_seat;
2646 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2647 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2649 libinput_seat = libinput_device_get_seat(evdev->device);
2651 return libinput_seat_get_logical_name(libinput_seat);
2655 e_input_evdev_seatname_set(E_Input_Evdev *evdev, const char *seatname)
2657 Eina_Bool res = EINA_FALSE;
2658 E_Input_Backend *input;
2660 EINA_SAFETY_ON_NULL_RETURN_VAL(seatname, EINA_FALSE);
2661 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, EINA_FALSE);
2662 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, EINA_FALSE);
2664 if (libinput_device_set_seat_logical_name(evdev->device, seatname) == 0)
2666 input = evdev->seat->input;
2667 if (!input) return EINA_FALSE;
2669 if (libinput_dispatch(input->libinput) != 0)
2671 ERR("Failed to dispatch libinput events: %m");
2676 /* process pending events */
2677 _input_events_process(input);