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))
93 udev_device_unref(udev_device);
96 udev_device_unref(udev_device);
98 ELOGF("E_INPUT_EVDEV", "calibration_set cal[%lf %lf %lf %lf %lf %lf] (%d x %d)",
99 NULL, cal[0], cal[1], cal[2], cal[3], cal[4], cal[5], w, h);
102 libinput_device_config_calibration_set_matrix(edev->device, cal);
104 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
105 ERR("Failed to apply calibration");
106 #endif//_F_E_INPUT_USE_WL_CALIBRATION_
107 #endif//_F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
112 _device_output_assign(E_Input_Evdev *edev, E_Input_Seat_Capabilities cap)
117 Eina_Bool need_assign_output = EINA_FALSE;
118 const char *output_name;
121 if (!(edev->caps & cap)) return;
122 if (edev->output_name) return; //already assigned
123 if (e_comp->e_comp_screen->num_outputs <= 1) return;
125 last_output_idx = e_comp->e_comp_screen->num_outputs - 1;
126 EINA_LIST_FOREACH(edev->seat->devices, l, ed)
128 if (!(ed->caps & cap)) continue;
129 if (ed == edev) continue;
132 need_assign_output = EINA_FALSE;
135 need_assign_output = EINA_TRUE;
137 if (need_assign_output)
139 output = e_output_find_by_index(last_output_idx);
140 if (!output || !output->info.connected) return;
141 output_name = e_output_output_id_get(output);
142 if (output_name) edev->output_name = eina_stringshare_add(output_name);
143 ELOGF("E_INPUT_EVDEV", "Device is assigned to output:%s", NULL, output_name);
148 _device_touch_count_update(E_Input_Evdev *edev)
150 unsigned int device_touch_count = 0;
151 static unsigned int _max_device_touch_count = 0;
153 E_Input *ei = e_input_get();
154 EINA_SAFETY_ON_NULL_RETURN(ei);
156 device_touch_count = libinput_device_touch_get_touch_count(edev->device);
158 if (_max_device_touch_count < device_touch_count)
159 _max_device_touch_count = device_touch_count;
161 if (e_config->configured_max_touch.use)
163 if (_max_device_touch_count > 0 && e_config->configured_max_touch.count > _max_device_touch_count)
165 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",
166 NULL, e_config->configured_max_touch.count, _max_device_touch_count, _max_device_touch_count);
167 ei->touch_max_count = _max_device_touch_count;
171 if (ei->touch_max_count != e_config->configured_max_touch.count)
173 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch_max_count has been updated to %d -> %d.\n",
174 NULL, ei->touch_max_count, e_config->configured_max_touch.count);
175 ei->touch_max_count = e_config->configured_max_touch.count;
181 if (ei->touch_max_count < _max_device_touch_count)
183 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch_max_count has been updated to %d -> %d.\n", NULL,
184 ei->touch_max_count, _max_device_touch_count);
185 ei->touch_max_count = _max_device_touch_count;
189 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch max count is %d.\n", NULL, ei->touch_max_count);
193 _device_configure(E_Input_Evdev *edev)
195 if (libinput_device_config_tap_get_finger_count(edev->device) > 0)
197 Eina_Bool tap = EINA_FALSE;
199 tap = libinput_device_config_tap_get_default_enabled(edev->device);
200 libinput_device_config_tap_set_enabled(edev->device, tap);
203 _device_calibration_set(edev);
207 _device_keyboard_setup(E_Input_Evdev *edev)
209 E_Input_Backend *input;
210 xkb_mod_index_t xkb_idx;
212 if ((!edev) || (!edev->seat)) return;
213 if (!(input = edev->seat->input)) return;
214 if (!input->dev->xkb_ctx) return;
216 /* create keymap from xkb context */
217 edev->xkb.keymap = _e_input_device_cached_keymap_get(input->dev->xkb_ctx, NULL, 0);
218 if (!edev->xkb.keymap)
220 ERR("Failed to create keymap: %m");
224 /* create xkb state */
225 if (!(edev->xkb.state = xkb_state_new(edev->xkb.keymap)))
227 ERR("Failed to create xkb state: %m");
231 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CTRL);
232 if (xkb_idx != XKB_MOD_INVALID)
233 edev->xkb.ctrl_mask = 1 << xkb_idx;
235 edev->xkb.ctrl_mask = 0;
237 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_ALT);
238 if (xkb_idx != XKB_MOD_INVALID)
239 edev->xkb.alt_mask = 1 << xkb_idx;
241 edev->xkb.alt_mask = 0;
243 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_SHIFT);
244 if (xkb_idx != XKB_MOD_INVALID)
245 edev->xkb.shift_mask = 1 << xkb_idx;
247 edev->xkb.shift_mask = 0;
249 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_LOGO);
250 if (xkb_idx != XKB_MOD_INVALID)
251 edev->xkb.win_mask = 1 << xkb_idx;
253 edev->xkb.win_mask = 0;
255 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_SCROLL);
256 if (xkb_idx != XKB_MOD_INVALID)
257 edev->xkb.scroll_mask = 1 << xkb_idx;
259 edev->xkb.scroll_mask = 0;
261 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_NUM);
262 if (xkb_idx != XKB_MOD_INVALID)
263 edev->xkb.num_mask = 1 << xkb_idx;
265 edev->xkb.num_mask = 0;
267 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CAPS);
268 if (xkb_idx != XKB_MOD_INVALID)
269 edev->xkb.caps_mask = 1 << xkb_idx;
271 edev->xkb.caps_mask = 0;
273 xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, "ISO_Level3_Shift");
274 if (xkb_idx != XKB_MOD_INVALID)
275 edev->xkb.altgr_mask = 1 << xkb_idx;
277 edev->xkb.altgr_mask = 0;
281 _device_keysym_translate(xkb_keysym_t keysym, unsigned int modifiers, char *buffer, int bytes)
283 unsigned long hbytes = 0;
286 if (!keysym) return 0;
287 hbytes = (keysym >> 8);
292 (((keysym >= XKB_KEY_BackSpace) && (keysym <= XKB_KEY_Clear)) ||
293 (keysym == XKB_KEY_Return) || (keysym == XKB_KEY_Escape) ||
294 (keysym == XKB_KEY_KP_Space) || (keysym == XKB_KEY_KP_Tab) ||
295 (keysym == XKB_KEY_KP_Enter) ||
296 ((keysym >= XKB_KEY_KP_Multiply) && (keysym <= XKB_KEY_KP_9)) ||
297 (keysym == XKB_KEY_KP_Equal) || (keysym == XKB_KEY_Delete))))))
300 if (keysym == XKB_KEY_KP_Space)
301 c = (XKB_KEY_space & 0x7F);
302 else if (hbytes == 0xFF)
307 if (modifiers & ECORE_EVENT_MODIFIER_CTRL)
309 if (((c >= '@') && (c < '\177')) || c == ' ')
313 else if ((c >= '3') && (c <= '7'))
325 _device_modifiers_update_device(E_Input_Evdev *edev, E_Input_Evdev *from)
329 edev->xkb.depressed =
330 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_DEPRESSED);
332 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LATCHED);
334 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LOCKED);
336 xkb_state_serialize_mods(from->xkb.state, XKB_STATE_EFFECTIVE);
338 mask = (edev->xkb.depressed | edev->xkb.latched);
340 if (mask & from->xkb.ctrl_mask)
341 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_CTRL;
342 if (mask & from->xkb.alt_mask)
343 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALT;
344 if (mask & from->xkb.shift_mask)
345 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
346 if (mask & from->xkb.win_mask)
347 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_WIN;
348 if (mask & from->xkb.scroll_mask)
349 edev->xkb.modifiers |= ECORE_EVENT_LOCK_SCROLL;
350 if (mask & from->xkb.num_mask)
351 edev->xkb.modifiers |= ECORE_EVENT_LOCK_NUM;
352 if (mask & from->xkb.caps_mask)
353 edev->xkb.modifiers |= ECORE_EVENT_LOCK_CAPS;
354 if (mask & from->xkb.altgr_mask)
355 edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALTGR;
359 _device_modifiers_update(E_Input_Evdev *edev)
364 edev->xkb.modifiers = 0;
366 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
367 _device_modifiers_update_device(edev, edev);
370 EINA_LIST_FOREACH(edev->seat->devices, l, ed)
372 if (!(ed->caps & E_INPUT_SEAT_KEYBOARD)) continue;
373 _device_modifiers_update_device(edev, ed);
380 _device_remapped_key_get(E_Input_Evdev *edev, int code)
384 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, code);
385 if (!edev->key_remap_enabled) return code;
386 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->key_remap_hash, code);
388 ret = eina_hash_find(edev->key_remap_hash, &code);
390 if (ret) code = (int)(intptr_t)ret;
396 e_input_evdev_get_e_device(const char *path, Ecore_Device_Class clas)
398 const GList *dev_list = NULL;
400 E_Device *dev = NULL;
401 const char *identifier;
403 if (!path) return NULL;
405 dev_list = e_device_list_get();
406 if (!dev_list) return NULL;
413 identifier = e_device_identifier_get(dev);
414 if (!identifier) continue;
415 if ((e_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
424 EINTERN Ecore_Device *
425 e_input_evdev_get_ecore_device(const char *path, Ecore_Device_Class clas)
427 const Eina_List *dev_list = NULL;
429 Ecore_Device *dev = NULL;
430 const char *identifier;
432 if (!path) return NULL;
434 dev_list = ecore_device_list();
435 if (!dev_list) return NULL;
436 EINA_LIST_FOREACH(dev_list, l, dev)
439 identifier = ecore_device_identifier_get(dev);
440 if (!identifier) continue;
441 if ((ecore_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
448 _e_input_event_mouse_move_cb_free(void *data EINA_UNUSED, void *event)
450 Ecore_Event_Mouse_Move *ev = event;
452 if (ev->dev) ecore_device_unref(ev->dev);
458 _e_input_event_mouse_relative_move_cb_free(void *data EINA_UNUSED, void *event)
460 Ecore_Event_Mouse_Relative_Move *ev = event;
462 if (ev->dev) ecore_device_unref(ev->dev);
468 _e_input_event_mouse_wheel_cb_free(void *data EINA_UNUSED, void *event)
470 Ecore_Event_Mouse_Wheel *ev = event;
472 if (ev->dev) ecore_device_unref(ev->dev);
478 _e_input_event_mouse_button_cb_free(void *data EINA_UNUSED, void *event)
480 Ecore_Event_Mouse_Button *ev = event;
482 if (ev->dev) ecore_device_unref(ev->dev);
488 _e_input_event_key_cb_free(void *data EINA_UNUSED, void *event)
490 Ecore_Event_Key *ev = event;
492 if (e_input_thread_mode_get())
494 if (ev->dev) g_object_unref(ev->dev);
498 if (ev->dev) ecore_device_unref(ev->dev);
501 if (ev->data) E_FREE(ev->data);
507 _device_handle_key(struct libinput_device *device, struct libinput_event_keyboard *event)
510 E_Input_Backend *input;
512 uint32_t code, nsyms;
513 const xkb_keysym_t *syms;
514 enum libinput_key_state state;
516 xkb_keysym_t sym = XKB_KEY_NoSymbol;
517 char key[256] = {0, }, keyname[256] = {0, }, compose_buffer[256] = {0, };
519 char *tmp = NULL, *compose = NULL;
520 E_Keyrouter_Event_Data *key_data;
521 Ecore_Device *ecore_dev = NULL, *data;
522 E_Device *e_dev = NULL, *e_dev_data;
523 Eina_List *l = NULL, *l_next = NULL;
525 E_Comp_Config *comp_conf = NULL;
526 int *pressed_keycode = NULL, *idata = NULL;
527 Eina_Bool dup_found = EINA_FALSE;
528 const char *device_name = NULL;
529 Ecore_Device_Subclass device_subclas = ECORE_DEVICE_SUBCLASS_NONE;
531 if (!(edev = libinput_device_get_user_data(device)))
536 if (!(input = edev->seat->input))
541 if (!e_input_thread_mode_get())
543 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
544 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
546 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
548 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_KEYBOARD)
557 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
558 ecore_dev = edev->ecore_dev;
563 ERR("Failed to get source ecore device from event !\n");
567 device_name = ecore_device_name_get(ecore_dev);
568 device_subclas = ecore_device_subclass_get(ecore_dev);
572 if (edev->e_dev) e_dev = edev->e_dev;
573 else if (edev->e_dev_list && g_list_length(edev->e_dev_list) > 0)
575 glist = edev->e_dev_list;
578 e_dev_data = glist->data;
579 if (e_device_class_get(e_dev_data) == ECORE_DEVICE_CLASS_KEYBOARD)
585 glist = g_list_next(glist);
590 edev->e_dev = e_input_evdev_get_e_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
596 ERR("Failed to get source e device from event !\n");
600 device_name = e_device_name_get(e_dev);
601 device_subclas = e_device_subclass_get(e_dev);
604 timestamp = libinput_event_keyboard_get_time(event);
605 code = libinput_event_keyboard_get_key(event);
606 code = _device_remapped_key_get(edev, code + 8);
607 state = libinput_event_keyboard_get_key_state(event);
608 key_count = libinput_event_keyboard_get_seat_key_count(event);
610 if (state == LIBINPUT_KEY_STATE_PRESSED)
612 if ((edev->seat->dev->blocked & E_INPUT_SEAT_KEYBOARD) ||
613 (edev->seat->dev->server_blocked & E_INPUT_SEAT_KEYBOARD))
615 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
616 ELOGF("Key", "Press (keycode: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
617 code, device_name, blocked_client,
618 edev->seat->dev->server_blocked);
622 /* FIXME: Currently to maintain press/release event pair during input block,
623 * used Eina_List and this is method used in devicemgr module.
624 * But we need to consider which way is better to maintain key press/release pair.
627 EINA_LIST_FOREACH(edev->xkb.pressed_keys, l, idata)
631 dup_found = EINA_TRUE;
637 pressed_keycode = E_NEW(int, 1);
638 EINA_SAFETY_ON_NULL_RETURN(pressed_keycode);
639 *pressed_keycode = code;
641 edev->xkb.pressed_keys = eina_list_append(edev->xkb.pressed_keys, pressed_keycode);
646 dup_found = EINA_FALSE;
647 EINA_LIST_FOREACH_SAFE(edev->xkb.pressed_keys, l, l_next, idata)
651 edev->xkb.pressed_keys = eina_list_remove_list(edev->xkb.pressed_keys, l);
653 dup_found = EINA_TRUE;
659 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
660 ELOGF("Key", "Release (keycode: %d, device: %s) is blocked by %p", NULL,
661 code, device_name, blocked_client);
666 /* ignore key events that are not seat wide state changes */
667 if (((state == LIBINPUT_KEY_STATE_PRESSED) && (key_count != 1)) ||
668 ((state == LIBINPUT_KEY_STATE_RELEASED) && (key_count != 0)))
673 e_input_keyboard_grab_key_cb func = e_input_keyboard_grab_key_handler_get();
676 if (e_devicemgr_keyboard_grab_subtype_is_grabbed(device_subclas))
678 if (!e_input_thread_mode_get())
679 func(code, state, timestamp, ecore_dev);
681 func(code, state, timestamp, e_dev);
686 xkb_state_update_key(edev->xkb.state, code,
687 (state ? XKB_KEY_DOWN : XKB_KEY_UP));
689 /* get the keysym for this code */
690 nsyms = xkb_key_get_syms(edev->xkb.state, code, &syms);
692 if (nsyms == 1) sym = syms[0];
694 /* If no keysym was found, name it "Keycode-NNN" */
695 if (sym == XKB_KEY_NoSymbol)
696 snprintf(key, sizeof(key), "Keycode-%u", code);
699 /* get the keyname for this sym */
700 xkb_keysym_get_name(sym, key, sizeof(key));
705 /* If no keyname was found, name it "Keycode-NNN" */
706 snprintf(keyname, sizeof(keyname), "Keycode-%u", code);
710 memcpy(keyname, key, sizeof(keyname));
713 /* if shift is active, we need to transform the key to lower */
714 if (xkb_state_mod_index_is_active(edev->xkb.state,
715 xkb_map_mod_get_index(edev->xkb.keymap,
717 XKB_STATE_MODS_EFFECTIVE))
719 if (keyname[0] != '\0')
720 keyname[0] = tolower(keyname[0]);
723 if (_device_keysym_translate(sym, edev->xkb.modifiers,
724 compose_buffer, sizeof(compose_buffer)))
726 compose = eina_str_convert("ISO8859-1", "UTF-8", compose_buffer);
729 ERR("E Input cannot convert input key string '%s' to UTF-8. "
730 "Is Eina built with iconv support?", compose_buffer);
736 if (!compose) compose = compose_buffer;
738 e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) +
739 ((compose[0] != '\0') ? strlen(compose) : 0) + 3);
745 key_data = E_NEW(E_Keyrouter_Event_Data, 1);
753 e->keyname = (char *)(e + 1);
754 e->key = e->keyname + strlen(keyname) + 1;
755 e->compose = strlen(compose) ? e->key + strlen(key) + 1 : NULL;
756 e->string = e->compose;
758 strncpy((char *)e->keyname, keyname, strlen(keyname));
759 strncpy((char *)e->key, key, strlen(key));
760 if (strlen(compose)) strncpy((char *)e->compose, compose, strlen(compose));
762 e->window = (Ecore_Window)input->dev->window;
763 e->event_window = (Ecore_Window)input->dev->window;
764 e->root_window = (Ecore_Window)input->dev->window;
765 e->timestamp = timestamp;
770 _device_modifiers_update(edev);
772 e->modifiers = edev->xkb.modifiers;
774 comp_conf = e_comp_config_get();
776 if (comp_conf && comp_conf->input_log_enable)
777 ELOGF("Key", "%s (keyname: %s, keycode: %d, timestamp: %u, device: %s)", NULL, state?"Press":"Release", e->keyname, e->keycode, e->timestamp, device_name);
779 if (e_config->key_input_ttrace_enable)
781 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));
782 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));
785 _e_input_key_event_list_add(e);
787 if (e_input_thread_mode_get())
789 e->dev = (Eo *)g_object_ref(e_dev);
790 e_input_event_add(input->event_source, state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
794 e->dev = ecore_device_ref(ecore_dev);
795 ecore_event_add(state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
798 if (e_config->key_input_ttrace_enable)
801 ELOGF("INPUT", "ECORE_EVENT_KEY|E|", NULL);
808 _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event)
810 E_Input_Backend *input;
811 Ecore_Event_Mouse_Move *ev;
812 Ecore_Device *ecore_dev = NULL, *data, *detent_data = NULL;
814 int x = 0, y = 0, w = 0, h = 0;
816 if (!(input = edev->seat->input)) return;
818 ecore_thread_main_loop_begin();
820 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
821 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
823 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
825 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
830 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
835 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
837 ecore_dev = detent_data;
842 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
843 ecore_dev = edev->ecore_dev;
848 ERR("Failed to get source ecore device from event !\n");
851 else if ((detent_data == ecore_dev) || e_devicemgr_detent_is_detent(ecore_device_name_get(ecore_dev)))
853 /* Do not process detent device's move events. */
857 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
859 _device_configured_size_get(edev, &x, &y, &w, &h);
861 if (edev->seat->ptr.ix < x)
862 edev->seat->ptr.dx = edev->seat->ptr.ix = x;
863 else if (edev->seat->ptr.ix >= (x + w))
864 edev->seat->ptr.dx = edev->seat->ptr.ix = (x + w - 1);
866 if (edev->seat->ptr.iy < y)
867 edev->seat->ptr.dy = edev->seat->ptr.iy = y;
868 else if (edev->seat->ptr.iy >= (y + h))
869 edev->seat->ptr.dy = edev->seat->ptr.iy = (y + h - 1);
871 edev->mouse.dx = edev->seat->ptr.dx;
872 edev->mouse.dy = edev->seat->ptr.dy;
874 ev->window = (Ecore_Window)input->dev->window;
875 ev->event_window = (Ecore_Window)input->dev->window;
876 ev->root_window = (Ecore_Window)input->dev->window;
877 if (event) ev->timestamp = libinput_event_pointer_get_time(event);
880 _device_modifiers_update(edev);
881 ev->modifiers = edev->xkb.modifiers;
883 ev->x = edev->seat->ptr.ix;
884 ev->y = edev->seat->ptr.iy;
888 ev->multi.device = edev->mt_slot;
889 ev->multi.radius = 1;
890 ev->multi.radius_x = 1;
891 ev->multi.radius_y = 1;
892 ev->multi.pressure = 1.0;
893 ev->multi.angle = 0.0;
896 ev->multi.root.x = ev->x;
897 ev->multi.root.y = ev->y;
899 ev->dev = ecore_device_ref(ecore_dev);
901 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
904 ecore_thread_main_loop_end();
908 _e_input_pointer_motion_post(E_Input_Evdev *edev)
910 _device_pointer_motion(edev, NULL);
914 _device_pointer_relative_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event, double dx[2], double dy[2])
916 E_Input_Backend *input;
917 Ecore_Event_Mouse_Relative_Move *ev;
918 Ecore_Device *ecore_dev = NULL, *data, *detent_data = NULL;
920 E_Comp_Config *comp_conf;
922 if (!(input = edev->seat->input)) return;
924 ecore_thread_main_loop_begin();
926 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
927 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
929 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
931 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
936 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
941 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
943 ecore_dev = detent_data;
948 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
949 ecore_dev = edev->ecore_dev;
954 ERR("Failed to get source ecore device from event !\n");
957 else if ((detent_data == ecore_dev) || e_devicemgr_detent_is_detent(ecore_device_name_get(ecore_dev)))
959 /* Do not process detent device's move events. */
963 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Relative_Move)))) return;
965 ev->window = (Ecore_Window)input->dev->window;
966 ev->event_window = (Ecore_Window)input->dev->window;
967 if (event) ev->timestamp = libinput_event_pointer_get_time(event);
969 ev->modifiers = edev->xkb.modifiers;
973 ev->dx_unaccel = (int)dx[1];
974 ev->dy_unaccel = (int)dy[1];
976 ev->dev = ecore_device_ref(ecore_dev);
978 comp_conf = e_comp_config_get();
979 if (comp_conf && comp_conf->input_log_enable)
980 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));
982 ecore_event_add(ECORE_EVENT_MOUSE_RELATIVE_MOVE, ev, _e_input_event_mouse_relative_move_cb_free, NULL);
985 ecore_thread_main_loop_end();
989 _device_pointer_motion_send(E_Input_Evdev *edev, struct libinput_event_pointer *event, double dx[2], double dy[2])
991 e_input_relative_motion_cb func = e_input_relative_motion_handler_get();
994 //func(dx, dy, time_us);
995 _device_pointer_relative_motion(edev, event, dx, dy);
999 double seat_dx, seat_dy, temp;
1000 if (edev->disable_acceleration)
1011 if (edev->seat->ptr.swap)
1017 if (edev->seat->ptr.invert_x)
1019 if (edev->seat->ptr.invert_y)
1022 edev->seat->ptr.dx += seat_dx;
1023 edev->seat->ptr.dy += seat_dy;
1025 edev->mouse.dx = edev->seat->ptr.dx;
1026 edev->mouse.dy = edev->seat->ptr.dy;
1028 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
1029 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
1034 edev->seat->ptr.ix = edev->seat->ptr.dx;
1035 edev->seat->ptr.iy = edev->seat->ptr.dy;
1037 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1038 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1043 _device_pointer_motion(edev, event);
1048 _device_handle_pointer_motion(struct libinput_device *device, struct libinput_event_pointer *event)
1050 E_Input_Evdev *edev;
1051 double delta_x[2]; /* delta_x[0] for accelerated, delta_x[1] for unaccelerated */
1052 double delta_y[2]; /* delta_y[0] for accelerated, delta_y[1] for unaccelerated */
1054 if (!(edev = libinput_device_get_user_data(device)))
1059 delta_x[0] = libinput_event_pointer_get_dx(event);
1060 delta_x[1] = libinput_event_pointer_get_dx_unaccelerated(event);
1061 delta_y[0] = libinput_event_pointer_get_dy(event);
1062 delta_y[1] = libinput_event_pointer_get_dy_unaccelerated(event);
1064 _device_pointer_motion_send(edev, event, &delta_x[0], &delta_y[0]);
1068 _device_handle_pointer_motion_absolute(struct libinput_device *device, struct libinput_event_pointer *event)
1070 E_Input_Evdev *edev;
1073 if (!(edev = libinput_device_get_user_data(device)))
1078 e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
1080 edev->mouse.dx = edev->seat->ptr.dx =
1081 libinput_event_pointer_get_absolute_x_transformed(event, w);
1082 edev->mouse.dy = edev->seat->ptr.dy =
1083 libinput_event_pointer_get_absolute_y_transformed(event, h);
1085 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
1086 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
1091 edev->seat->ptr.ix = edev->seat->ptr.dx;
1092 edev->seat->ptr.iy = edev->seat->ptr.dy;
1094 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1095 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1100 _device_pointer_motion(edev, event);
1104 _device_handle_button(struct libinput_device *device, struct libinput_event_pointer *event)
1106 E_Input_Evdev *edev;
1107 E_Input_Backend *input;
1108 Ecore_Event_Mouse_Button *ev;
1109 enum libinput_button_state state;
1110 uint32_t button, timestamp;
1111 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1113 E_Comp_Config *comp_conf = NULL;
1115 if (!(edev = libinput_device_get_user_data(device)))
1119 if (!(input = edev->seat->input))
1124 ecore_thread_main_loop_begin();
1126 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1127 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1129 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1131 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1136 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1141 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1143 ecore_dev = detent_data;
1148 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1149 ecore_dev = edev->ecore_dev;
1154 ERR("Failed to get source ecore device from event !\n");
1158 state = libinput_event_pointer_get_button_state(event);
1159 button = libinput_event_pointer_get_button(event);
1160 timestamp = libinput_event_pointer_get_time(event);
1162 button = ((button & 0x00F) + 1);
1163 if (button == 3) button = 2;
1164 else if (button == 2) button = 3;
1166 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
1170 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1171 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1174 ELOGF("Mouse", "Button Press (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
1175 button, ecore_device_name_get(ecore_dev), blocked_client,
1176 edev->seat->dev->server_blocked);
1181 edev->mouse.pressed_button |= (1 << button);
1186 if (!(edev->mouse.pressed_button & (1 << button)))
1188 ELOGF("Mouse", "Button Release (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
1189 button, ecore_device_name_get(ecore_dev), blocked_client,
1190 edev->seat->dev->server_blocked);
1193 edev->mouse.pressed_button &= ~(1 << button);
1196 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button))))
1201 ev->window = (Ecore_Window)input->dev->window;
1202 ev->event_window = (Ecore_Window)input->dev->window;
1203 ev->root_window = (Ecore_Window)input->dev->window;
1204 ev->timestamp = timestamp;
1205 ev->same_screen = 1;
1207 _device_modifiers_update(edev);
1208 ev->modifiers = edev->xkb.modifiers;
1210 ev->x = edev->seat->ptr.ix;
1211 ev->y = edev->seat->ptr.iy;
1215 ev->multi.device = edev->mt_slot;
1216 ev->multi.radius = 1;
1217 ev->multi.radius_x = 1;
1218 ev->multi.radius_y = 1;
1219 ev->multi.pressure = 1.0;
1220 ev->multi.angle = 0.0;
1221 ev->multi.x = ev->x;
1222 ev->multi.y = ev->y;
1223 ev->multi.root.x = ev->x;
1224 ev->multi.root.y = ev->y;
1225 ev->dev = ecore_device_ref(ecore_dev);
1229 unsigned int current;
1231 current = timestamp;
1232 edev->mouse.did_double = EINA_FALSE;
1233 edev->mouse.did_triple = EINA_FALSE;
1235 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1236 (button == edev->mouse.prev_button))
1238 edev->mouse.did_double = EINA_TRUE;
1239 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1240 (button == edev->mouse.last_button))
1242 edev->mouse.did_triple = EINA_TRUE;
1243 edev->mouse.prev = 0;
1244 edev->mouse.last = 0;
1249 edev->mouse.last = edev->mouse.prev;
1250 edev->mouse.prev = current;
1251 edev->mouse.last_button = edev->mouse.prev_button;
1252 edev->mouse.prev_button = button;
1255 ev->buttons = button;
1257 if (edev->mouse.did_double)
1258 ev->double_click = 1;
1259 if (edev->mouse.did_triple)
1260 ev->triple_click = 1;
1262 comp_conf = e_comp_config_get();
1263 if (comp_conf && comp_conf->input_log_enable)
1264 ELOGF("Mouse", "Button %s (btn: %d, device: %s)", NULL, state?"Press":"Release", button, ecore_device_name_get(ev->dev));
1267 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, _e_input_event_mouse_button_cb_free, NULL);
1269 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, _e_input_event_mouse_button_cb_free, NULL);
1272 ecore_thread_main_loop_end();
1275 #if !LIBINPUT_HAVE_SCROLL_VALUE_V120
1277 _axis_value_get(struct libinput_event_pointer *pointer_event, enum libinput_pointer_axis axis)
1279 enum libinput_pointer_axis_source source;
1280 double value = 0.0, value_discrete = 0.0;
1282 E_Comp_Config *comp_conf = NULL;
1284 comp_conf = e_comp_config_get();
1285 source = libinput_event_pointer_get_axis_source(pointer_event);
1288 case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL:
1289 value_discrete = libinput_event_pointer_get_axis_value_discrete(pointer_event, axis);
1290 value = libinput_event_pointer_get_axis_value(pointer_event, axis);
1291 if (comp_conf && comp_conf->input_log_enable)
1293 ELOGF("Axis", "SOURCE_WHEEL discrete: %lf (cf. value: %lf)", NULL, value_discrete, value);
1295 ret = (int)value_discrete;
1297 case LIBINPUT_POINTER_AXIS_SOURCE_FINGER:
1298 case LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS:
1299 value = libinput_event_pointer_get_axis_value(pointer_event, axis);
1300 if (comp_conf && comp_conf->input_log_enable)
1302 ELOGF("Axis", "SOURCE_FINGER/CONTINUOUS value: %lf", NULL, value);
1304 if (value >= E_INPUT_FINGER_SCROLL_THRESHOLD)
1306 else if (value <= E_INPUT_FINGER_SCROLL_THRESHOLD * (-1))
1319 _device_handle_axis(struct libinput_device *device, struct libinput_event_pointer *event)
1321 E_Input_Evdev *edev;
1322 E_Input_Backend *input;
1323 Ecore_Event_Mouse_Wheel *ev;
1325 enum libinput_pointer_axis axis;
1326 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1328 E_Comp_Config *comp_conf = NULL;
1329 int direction = 0, z = 0;
1331 if (!(edev = libinput_device_get_user_data(device)))
1335 if (!(input = edev->seat->input))
1340 ecore_thread_main_loop_begin();
1342 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1343 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1345 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1347 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1352 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1357 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1359 ecore_dev = detent_data;
1364 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1365 ecore_dev = edev->ecore_dev;
1370 ERR("Failed to get source ecore device from event !\n");
1374 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1375 if (libinput_event_pointer_has_axis(event, axis))
1376 z = _axis_value_get(event, axis);
1378 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1379 if (libinput_event_pointer_has_axis(event, axis))
1382 z = _axis_value_get(event, axis);
1387 ELOGF("Mouse", "Axis event is ignored since it has zero value", NULL);
1391 comp_conf = e_comp_config_get();
1392 if (comp_conf && comp_conf->e_wheel_click_angle)
1394 z = (int)(z * comp_conf->e_wheel_click_angle);
1397 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1398 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1400 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
1403 ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1404 direction, z, blocked_client, edev->seat->dev->server_blocked);
1406 ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1407 direction, z, blocked_client, edev->seat->dev->server_blocked);
1412 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1417 timestamp = libinput_event_pointer_get_time(event);
1419 ev->window = (Ecore_Window)input->dev->window;
1420 ev->event_window = (Ecore_Window)input->dev->window;
1421 ev->root_window = (Ecore_Window)input->dev->window;
1422 ev->timestamp = timestamp;
1423 ev->same_screen = 1;
1425 _device_modifiers_update(edev);
1426 ev->modifiers = edev->xkb.modifiers;
1428 ev->x = edev->seat->ptr.ix;
1429 ev->y = edev->seat->ptr.iy;
1433 ev->direction = direction;
1435 if (comp_conf && comp_conf->input_log_enable)
1438 ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1440 ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1444 ev->dev = ecore_device_ref(ecore_dev);
1445 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1448 ecore_thread_main_loop_end();
1452 #if LIBINPUT_HAVE_SCROLL_VALUE_V120
1454 _scroll_value_get(struct libinput_event_pointer *pointer_event, enum libinput_pointer_axis axis, E_Input_Axis_Source source)
1457 double value_v120 = 0.0;
1459 E_Comp_Config *comp_conf = NULL;
1461 comp_conf = e_comp_config_get();
1464 case E_INPUT_AXIS_SOURCE_WHEEL:
1465 value_v120 = libinput_event_pointer_get_scroll_value_v120(pointer_event, axis);
1466 value = libinput_event_pointer_get_scroll_value(pointer_event, axis);
1467 if (comp_conf && comp_conf->input_log_enable)
1469 ELOGF("Scroll", "SOURCE_WHEEL value_v120: %lf (cf. value: %lf)", NULL, value_v120, value);
1471 if (((int)value_v120 % E_INPUT_POINTER_AXIS_DISCRETE_STEP) != 0)
1473 ERR("Wheel movements should be multiples (or fractions) of 120!\n");
1478 ret = value_v120 / E_INPUT_POINTER_AXIS_DISCRETE_STEP;
1481 case E_INPUT_AXIS_SOURCE_FINGER:
1482 case E_INPUT_AXIS_SOURCE_CONTINUOUS:
1483 value = libinput_event_pointer_get_scroll_value(pointer_event, axis);
1484 if (comp_conf && comp_conf->input_log_enable)
1486 ELOGF("Scroll", "SOURCE_FINGER/CONTINUOUS value: %lf", NULL, value);
1488 if (value >= E_INPUT_FINGER_SCROLL_THRESHOLD)
1490 else if (value <= E_INPUT_FINGER_SCROLL_THRESHOLD * (-1))
1503 _device_handle_axis_v120(struct libinput_device *device, struct libinput_event_pointer *event, E_Input_Axis_Source source)
1505 E_Input_Evdev *edev;
1506 E_Input_Backend *input;
1507 Ecore_Event_Mouse_Wheel *ev;
1509 enum libinput_pointer_axis axis;
1510 Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1512 E_Comp_Config *comp_conf = NULL;
1513 int direction = 0, z = 0;
1515 if (!(edev = libinput_device_get_user_data(device)))
1519 if (!(input = edev->seat->input))
1524 ecore_thread_main_loop_begin();
1526 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1527 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1529 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1531 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1536 else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1541 if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1543 ecore_dev = detent_data;
1548 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1549 ecore_dev = edev->ecore_dev;
1554 ERR("Failed to get source ecore device from event !\n");
1558 axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1559 if (libinput_event_pointer_has_axis(event, axis))
1560 z = _scroll_value_get(event, axis, source);
1562 axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1563 if (libinput_event_pointer_has_axis(event, axis))
1566 z = _scroll_value_get(event, axis, source);
1571 ELOGF("Mouse", "Scroll event is ignored since it has zero value", NULL);
1575 comp_conf = e_comp_config_get();
1576 if (comp_conf && comp_conf->e_wheel_click_angle)
1578 z = (int)(z * comp_conf->e_wheel_click_angle);
1581 if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1582 (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1584 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
1586 ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1587 direction, z, blocked_client, edev->seat->dev->server_blocked);
1589 ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1590 direction, z, blocked_client, edev->seat->dev->server_blocked);
1595 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1600 timestamp = libinput_event_pointer_get_time(event);
1602 ev->window = (Ecore_Window)input->dev->window;
1603 ev->event_window = (Ecore_Window)input->dev->window;
1604 ev->root_window = (Ecore_Window)input->dev->window;
1605 ev->timestamp = timestamp;
1606 ev->same_screen = 1;
1608 _device_modifiers_update(edev);
1609 ev->modifiers = edev->xkb.modifiers;
1611 ev->x = edev->seat->ptr.ix;
1612 ev->y = edev->seat->ptr.iy;
1616 ev->direction = direction;
1618 if (comp_conf && comp_conf->input_log_enable)
1621 ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1623 ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1626 ev->dev = ecore_device_ref(ecore_dev);
1627 ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1630 ecore_thread_main_loop_end();
1635 _device_handle_touch_event_send(E_Input_Evdev *edev, struct libinput_event_touch *event, int state)
1637 E_Input_Backend *input;
1638 Ecore_Event_Mouse_Button *ev;
1639 uint32_t timestamp, button = 0;
1640 Ecore_Device *ecore_dev = NULL, *data;
1644 if (!(input = edev->seat->input)) return;
1646 ecore_thread_main_loop_begin();
1648 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1649 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1651 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1653 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1662 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1663 ecore_dev = edev->ecore_dev;
1668 ERR("Failed to get source ecore device from event !\n");
1672 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) goto end;
1674 timestamp = libinput_event_touch_get_time(event);
1676 ev->window = (Ecore_Window)input->dev->window;
1677 ev->event_window = (Ecore_Window)input->dev->window;
1678 ev->root_window = (Ecore_Window)input->dev->window;
1679 ev->timestamp = timestamp;
1680 ev->same_screen = 1;
1682 _device_modifiers_update(edev);
1683 ev->modifiers = edev->xkb.modifiers;
1685 ev->x = edev->seat->ptr.ix;
1686 ev->y = edev->seat->ptr.iy;
1690 ev->multi.device = edev->mt_slot;
1691 ev->multi.radius = 1;
1692 ev->multi.radius_x = 1;
1693 ev->multi.radius_y = 1;
1694 ev->multi.pressure = 1.0;
1695 ev->multi.angle = 0.0;
1696 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1697 if (libinput_event_get_type(libinput_event_touch_get_base_event(event))
1698 == LIBINPUT_EVENT_TOUCH_DOWN)
1700 if (libinput_event_touch_has_minor(event))
1701 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1702 if (libinput_event_touch_has_major(event))
1703 ev->multi.radius_y = libinput_event_touch_get_major(event);
1704 if (libinput_event_touch_has_pressure(event))
1705 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1706 if (libinput_event_touch_has_orientation(event))
1707 ev->multi.angle = libinput_event_touch_get_orientation(event);
1710 ev->multi.x = ev->x;
1711 ev->multi.y = ev->y;
1712 ev->multi.root.x = ev->x;
1713 ev->multi.root.y = ev->y;
1714 ev->dev = ecore_device_ref(ecore_dev);
1716 if (state == ECORE_EVENT_MOUSE_BUTTON_DOWN)
1718 unsigned int current;
1720 current = timestamp;
1721 edev->mouse.did_double = EINA_FALSE;
1722 edev->mouse.did_triple = EINA_FALSE;
1724 if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1725 (button == edev->mouse.prev_button))
1727 edev->mouse.did_double = EINA_TRUE;
1728 if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1729 (button == edev->mouse.last_button))
1731 edev->mouse.did_triple = EINA_TRUE;
1732 edev->mouse.prev = 0;
1733 edev->mouse.last = 0;
1738 edev->mouse.last = edev->mouse.prev;
1739 edev->mouse.prev = current;
1740 edev->mouse.last_button = edev->mouse.prev_button;
1741 edev->mouse.prev_button = button;
1742 edev->touch.pressed |= (1 << ev->multi.device);
1746 edev->touch.pressed &= ~(1 << ev->multi.device);
1749 ev->buttons = ((button & 0x00F) + 1);
1751 if (edev->mouse.did_double)
1752 ev->double_click = 1;
1753 if (edev->mouse.did_triple)
1754 ev->triple_click = 1;
1756 ecore_event_add(state, ev, _e_input_event_mouse_button_cb_free, NULL);
1759 ecore_thread_main_loop_end();
1763 _device_handle_touch_motion_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1765 E_Input_Backend *input;
1766 Ecore_Event_Mouse_Move *ev;
1767 Ecore_Device *ecore_dev = NULL, *data;
1771 if (!(input = edev->seat->input)) return;
1773 ecore_thread_main_loop_begin();
1775 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1776 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1778 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1780 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1789 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1790 ecore_dev = edev->ecore_dev;
1795 ERR("Failed to get source ecore device from event !\n");
1799 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) goto end;
1801 ev->window = (Ecore_Window)input->dev->window;
1802 ev->event_window = (Ecore_Window)input->dev->window;
1803 ev->root_window = (Ecore_Window)input->dev->window;
1804 ev->timestamp = libinput_event_touch_get_time(event);
1805 ev->same_screen = 1;
1807 _device_modifiers_update(edev);
1808 ev->modifiers = edev->xkb.modifiers;
1810 ev->x = edev->seat->ptr.ix;
1811 ev->y = edev->seat->ptr.iy;
1815 ev->multi.device = edev->mt_slot;
1816 ev->multi.radius = 1;
1817 ev->multi.radius_x = 1;
1818 ev->multi.radius_y = 1;
1819 ev->multi.pressure = 1.0;
1820 ev->multi.angle = 0.0;
1821 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1822 if (libinput_event_touch_has_minor(event))
1823 ev->multi.radius_x = libinput_event_touch_get_minor(event);
1824 if (libinput_event_touch_has_major(event))
1825 ev->multi.radius_y = libinput_event_touch_get_major(event);
1826 if (libinput_event_touch_has_pressure(event))
1827 ev->multi.pressure = libinput_event_touch_get_pressure(event);
1828 if (libinput_event_touch_has_orientation(event))
1829 ev->multi.angle = libinput_event_touch_get_orientation(event);
1831 ev->multi.x = ev->x;
1832 ev->multi.y = ev->y;
1833 ev->multi.root.x = ev->x;
1834 ev->multi.root.y = ev->y;
1835 ev->dev = ecore_device_ref(ecore_dev);
1837 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
1840 ecore_thread_main_loop_end();
1844 _device_handle_touch_cancel_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1846 E_Input_Backend *input;
1847 Ecore_Event_Mouse_Button *ev;
1848 uint32_t timestamp, button = 0;
1849 Ecore_Device *ecore_dev = NULL, *data;
1853 if (!(input = edev->seat->input)) return;
1855 ecore_thread_main_loop_begin();
1857 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1858 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1860 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1862 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1871 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1872 ecore_dev = edev->ecore_dev;
1877 ERR("Failed to get source ecore device from event !\n");
1881 if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) goto end;
1883 timestamp = libinput_event_touch_get_time(event);
1885 ev->window = (Ecore_Window)input->dev->window;
1886 ev->event_window = (Ecore_Window)input->dev->window;
1887 ev->root_window = (Ecore_Window)input->dev->window;
1888 ev->timestamp = timestamp;
1889 ev->same_screen = 1;
1891 ev->x = edev->seat->ptr.ix;
1892 ev->y = edev->seat->ptr.iy;
1896 ev->multi.device = edev->mt_slot;
1897 ev->multi.radius = 1;
1898 ev->multi.radius_x = 1;
1899 ev->multi.radius_y = 1;
1900 ev->multi.pressure = 1.0;
1901 ev->multi.angle = 0.0;
1902 ev->multi.x = ev->x;
1903 ev->multi.y = ev->y;
1904 ev->multi.root.x = ev->x;
1905 ev->multi.root.y = ev->y;
1907 edev->touch.pressed &= ~(1 << ev->multi.device);
1909 ev->buttons = ((button & 0x00F) + 1);
1910 ev->dev = ecore_device_ref(ecore_dev);
1912 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev, _e_input_event_mouse_button_cb_free, NULL);
1915 ecore_thread_main_loop_end();
1919 _device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, int *w, int *h)
1921 E_Output *output = NULL;
1923 EINA_SAFETY_ON_NULL_RETURN(edev);
1925 if (!edev->output_configured)
1927 if (edev->output_name)
1929 output = e_output_find(edev->output_name);
1932 edev->mouse.minx = output->config.geom.x;
1933 edev->mouse.miny = output->config.geom.y;
1934 edev->mouse.maxw = output->config.geom.w;
1935 edev->mouse.maxh = output->config.geom.h;
1936 if (edev->caps & E_INPUT_SEAT_POINTER)
1938 edev->seat->ptr.dx = (double)(edev->mouse.maxw / 2);
1939 edev->seat->ptr.dy = (double)(edev->mouse.maxh / 2);
1940 edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
1941 edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
1942 edev->mouse.dx = edev->seat->ptr.dx;
1943 edev->mouse.dy = edev->seat->ptr.dy;
1948 edev->output_configured = EINA_TRUE;
1949 ELOGF("E_INPUT_EVDEV", "Device is configured by output x:%d,y:%d (w:%d, h:%d)",
1950 NULL, edev->mouse.minx, edev->mouse.miny, edev->mouse.maxw, edev->mouse.maxh);
1952 if (x) *x = edev->mouse.minx;
1953 if (y) *y = edev->mouse.miny;
1954 if (w) *w = edev->mouse.maxw;
1955 if (h) *h = edev->mouse.maxh;
1959 _device_handle_touch_down(struct libinput_device *device, struct libinput_event_touch *event)
1961 E_Input_Evdev *edev;
1962 int x = 0, y = 0, w = 0, h = 0;
1963 E_Comp_Config *comp_conf = NULL;
1965 if (!(edev = libinput_device_get_user_data(device)))
1970 _device_configured_size_get(edev, &x, &y, &w, &h);
1972 edev->mouse.dx = edev->seat->ptr.ix = edev->seat->ptr.dx =
1973 x + libinput_event_touch_get_x_transformed(event, w);
1974 edev->mouse.dy = edev->seat->ptr.iy = edev->seat->ptr.dy =
1975 y + libinput_event_touch_get_y_transformed(event, h);
1977 edev->mt_slot = libinput_event_touch_get_slot(event);
1978 if (edev->mt_slot < 0)
1980 /* FIXME: The single touch device return slot id -1
1981 * But currently we have no API to distinguish multi touch or single touch
1982 * After libinput 1.11 version, libinput provides get_touch_count API,
1983 * so we can distinguish multi touch device or single touch device.
1985 if (edev->mt_slot == -1)
1989 WRN("%d slot touch down events are not supported\n", edev->mt_slot);
1994 if (edev->mt_slot < e_input_touch_max_count_get())
1996 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
1997 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
2000 comp_conf = e_comp_config_get();
2001 if (comp_conf && comp_conf->input_log_enable)
2002 ELOGF("Touch", "Down (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2004 atomic_fetch_or(&edev->touch.raw_pressed, (1 << edev->mt_slot));
2006 if (edev->touch.blocked)
2008 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
2009 ELOGF("Touch", "Down (id: %d, x: %d, y: %d) is blocked by %p, server: 0x%x", NULL,
2010 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, blocked_client,
2011 edev->seat->dev->server_blocked);
2015 _device_handle_touch_motion_send(edev, event);
2016 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_DOWN);
2020 _device_handle_touch_motion(struct libinput_device *device, struct libinput_event_touch *event)
2022 E_Input_Evdev *edev;
2023 int x = 0, y = 0, w = 0, h = 0;
2025 if (!(edev = libinput_device_get_user_data(device)))
2030 _device_configured_size_get(edev, &x, &y, &w, &h);
2032 edev->mouse.dx = edev->seat->ptr.dx =
2033 x + libinput_event_touch_get_x_transformed(event, w);
2034 edev->mouse.dy = edev->seat->ptr.dy =
2035 y + libinput_event_touch_get_y_transformed(event, h);
2037 if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
2038 floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
2043 edev->seat->ptr.ix = edev->seat->ptr.dx;
2044 edev->seat->ptr.iy = edev->seat->ptr.dy;
2046 edev->mt_slot = libinput_event_touch_get_slot(event);
2047 if (edev->mt_slot < 0)
2049 /* FIXME: The single touch device return slot id -1
2050 * But currently we have no API to distinguish multi touch or single touch
2051 * After libinput 1.11 version, libinput provides get_touch_count API,
2052 * so we can distinguish multi touch device or single touch device.
2054 if (edev->mt_slot == -1)
2058 WRN("%d slot touch motion events are not supported\n", edev->mt_slot);
2063 if (edev->mt_slot < e_input_touch_max_count_get())
2065 edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
2066 edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
2069 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
2071 if (edev->touch.blocked)
2077 _device_handle_touch_motion_send(edev, event);
2081 _device_handle_touch_up(struct libinput_device *device, struct libinput_event_touch *event)
2083 E_Input_Evdev *edev;
2084 E_Comp_Config *comp_conf = NULL;
2086 if (!(edev = libinput_device_get_user_data(device)))
2091 edev->mt_slot = libinput_event_touch_get_slot(event);
2092 if (edev->mt_slot < 0)
2094 /* FIXME: The single touch device return slot id -1
2095 * But currently we have no API to distinguish multi touch or single touch
2096 * After libinput 1.11 version, libinput provides get_touch_count API,
2097 * so we can distinguish multi touch device or single touch device.
2099 if (edev->mt_slot == -1)
2103 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
2108 if (edev->mt_slot < e_input_touch_max_count_get())
2110 edev->mouse.dx = edev->seat->ptr.dx = edev->seat->ptr.ix =
2111 edev->touch.coords[edev->mt_slot].x;
2112 edev->mouse.dy = edev->seat->ptr.dy = edev->seat->ptr.iy =
2113 edev->touch.coords[edev->mt_slot].y;
2116 comp_conf = e_comp_config_get();
2117 if (comp_conf && comp_conf->input_log_enable)
2118 ELOGF("Touch", "Up (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2120 atomic_fetch_and(&edev->touch.raw_pressed, ~(1 << edev->mt_slot));
2122 if (edev->touch.blocked)
2124 if (!(edev->touch.pressed & (1 << edev->mt_slot)))
2126 void *blocked_client = atomic_load(&edev->seat->dev->blocked_client);
2127 ELOGF("Touch", "Up (id: %d, x: %d, y: %d) is blocked by %p, server(0x%x)", NULL,
2128 edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, blocked_client,
2129 edev->seat->dev->server_blocked);
2131 if (edev->touch.raw_pressed == 0x0)
2133 edev->touch.blocked = EINA_FALSE;
2139 _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_UP);
2143 _device_handle_touch_cancel(struct libinput_device *device, struct libinput_event_touch *event)
2145 E_Input_Evdev *edev;
2146 E_Comp_Config *comp_conf = NULL;
2148 if (!(edev = libinput_device_get_user_data(device)))
2153 edev->mt_slot = libinput_event_touch_get_slot(event);
2154 if (edev->mt_slot < 0)
2156 /* FIXME: The single touch device return slot id -1
2157 * But currently we have no API to distinguish multi touch or single touch
2158 * After libinput 1.11 version, libinput provides get_touch_count API,
2159 * so we can distinguish multi touch device or single touch device.
2161 if (edev->mt_slot == -1)
2165 WRN("%d slot touch up events are not supported\n", edev->mt_slot);
2170 comp_conf = e_comp_config_get();
2171 if (comp_conf && comp_conf->input_log_enable)
2172 ELOGF("Touch", "cancel (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2174 _device_handle_touch_cancel_send(edev, event);
2179 _device_handle_touch_frame(struct libinput_device *device EINA_UNUSED, struct libinput_event_touch *event EINA_UNUSED)
2181 /* DBG("Unhandled Touch Frame Event"); */
2185 _e_input_aux_data_event_free(void *user_data EINA_UNUSED, void *ev)
2187 Ecore_Event_Axis_Update *e = (Ecore_Event_Axis_Update *)ev;
2189 if (e->axis) free(e->axis);
2190 if (e->dev) ecore_device_unref(e->dev);
2196 _device_handle_touch_aux_data(struct libinput_device *device, struct libinput_event_touch_aux_data *event)
2198 E_Input_Evdev *edev;
2199 E_Input_Backend *input;
2200 Ecore_Event_Axis_Update *ev;
2202 Ecore_Device *ecore_dev = NULL, *data;
2204 E_Comp_Config *comp_conf;
2206 ecore_thread_main_loop_begin();
2208 if (libinput_event_touch_aux_data_get_type(event) != LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM &&
2209 libinput_event_touch_aux_data_get_value(event) > 0)
2212 if (!(edev = libinput_device_get_user_data(device))) goto end;
2213 if (!(input = edev->seat->input)) goto end;
2215 if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
2216 else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
2218 EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
2220 if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
2229 edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
2230 ecore_dev = edev->ecore_dev;
2235 ERR("Failed to get source ecore device from event !\n");
2239 if (!(ev = calloc(1, sizeof(Ecore_Event_Axis_Update)))) goto end;
2241 ev->window = (Ecore_Window)input->dev->window;
2242 ev->event_window = (Ecore_Window)input->dev->window;
2243 ev->root_window = (Ecore_Window)input->dev->window;
2244 ev->timestamp = libinput_event_touch_aux_data_get_time(event);
2246 axis = (Ecore_Axis *)calloc(1, sizeof(Ecore_Axis));
2249 axis->label = ECORE_AXIS_LABEL_TOUCH_PALM;
2250 axis->value = libinput_event_touch_aux_data_get_value(event);
2255 comp_conf = e_comp_config_get();
2256 if (comp_conf && comp_conf->input_log_enable)
2257 ELOGF("Touch", "Axis (label: %d, value: %lf)", NULL, axis?axis->label:-1, axis?axis->value:0.0);
2259 ev->dev = ecore_device_ref(ecore_dev);
2261 ecore_event_add(ECORE_EVENT_AXIS_UPDATE, ev, _e_input_aux_data_event_free, NULL);
2264 ecore_thread_main_loop_end();
2268 _e_input_evdev_device_create(E_Input_Seat *seat, struct libinput_device *device)
2270 E_Input_Evdev *edev;
2271 E_Input_Backend *b_input;
2272 const char *output_name;
2274 EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
2276 /* try to allocate space for new evdev */
2277 if (!(edev = calloc(1, sizeof(E_Input_Evdev)))) return NULL;
2280 edev->device = device;
2281 edev->path = eina_stringshare_printf("%s/%s", e_input_base_dir_get(), libinput_device_get_sysname(device));
2283 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
2285 edev->caps |= E_INPUT_SEAT_KEYBOARD;
2286 _device_keyboard_setup(edev);
2289 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
2291 edev->caps |= E_INPUT_SEAT_POINTER;
2293 /* TODO: make this configurable */
2294 edev->mouse.threshold = 250;
2296 b_input = seat->input;
2297 if (b_input->left_handed == EINA_TRUE)
2299 if (libinput_device_config_left_handed_set(device, 1) !=
2300 LIBINPUT_CONFIG_STATUS_SUCCESS)
2302 WRN("Failed to set left hand mode about device: %s\n",
2303 libinput_device_get_name(device));
2308 if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
2311 edev->caps |= E_INPUT_SEAT_TOUCH;
2312 palm_code = libinput_device_touch_aux_data_get_code(LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM);
2313 if (libinput_device_touch_has_aux_data(device, palm_code))
2315 libinput_device_touch_set_aux_data(device, palm_code);
2318 _device_touch_count_update(edev);
2320 edev->touch.coords = calloc(1, sizeof(E_Input_Coord)*e_input_touch_max_count_get());
2322 if (!edev->touch.coords)
2323 ERR("Failed to allocate memory for touch coords !\n");
2326 output_name = libinput_device_get_output_name(device);
2329 eina_stringshare_replace(&edev->output_name, output_name);
2330 ELOGF("E_INPUT_EVDEV", "Device has output_name:%s", NULL, output_name);
2333 libinput_device_set_user_data(device, edev);
2334 libinput_device_ref(device);
2336 /* configure device */
2337 _device_configure(edev);
2343 _e_input_evdev_device_destroy(E_Input_Evdev *edev)
2346 EINA_SAFETY_ON_NULL_RETURN(edev);
2348 ecore_thread_main_loop_begin();
2350 if (edev->caps & E_INPUT_SEAT_KEYBOARD)
2352 if (edev->xkb.state) xkb_state_unref(edev->xkb.state);
2354 if (edev->xkb.keymap) xkb_map_unref(edev->xkb.keymap);
2357 if (edev->ecore_dev) ecore_device_del(edev->ecore_dev);
2358 if (edev->ecore_dev_list)
2359 EINA_LIST_FREE(edev->ecore_dev_list, dev)
2361 ecore_device_del(dev);
2364 if (edev->e_dev) g_object_unref(edev->e_dev);
2365 if (edev->e_dev_list)
2367 GList *glist = edev->e_dev_list;
2371 e_dev = glist->data;
2372 g_object_unref(e_dev);
2374 glist = g_list_next(glist);
2377 if (edev->path) eina_stringshare_del(edev->path);
2378 if (edev->device) libinput_device_unref(edev->device);
2379 if (edev->key_remap_hash) eina_hash_free(edev->key_remap_hash);
2380 if (edev->touch.coords)
2382 free(edev->touch.coords);
2383 edev->touch.coords = NULL;
2385 eina_stringshare_del(edev->output_name);
2387 ecore_thread_main_loop_end();
2393 _e_input_evdev_event_process(struct libinput_event *event)
2395 struct libinput_device *device;
2396 Eina_Bool ret = EINA_TRUE;
2398 device = libinput_event_get_device(event);
2399 switch (libinput_event_get_type(event))
2401 case LIBINPUT_EVENT_KEYBOARD_KEY:
2402 _device_handle_key(device, libinput_event_get_keyboard_event(event));
2404 case LIBINPUT_EVENT_POINTER_MOTION:
2405 _device_handle_pointer_motion(device,
2406 libinput_event_get_pointer_event(event));
2408 case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
2409 _device_handle_pointer_motion_absolute(device,
2410 libinput_event_get_pointer_event(event));
2412 case LIBINPUT_EVENT_POINTER_BUTTON:
2413 _device_handle_button(device, libinput_event_get_pointer_event(event));
2415 case LIBINPUT_EVENT_POINTER_AXIS:
2416 #if !LIBINPUT_HAVE_SCROLL_VALUE_V120
2417 _device_handle_axis(device, libinput_event_get_pointer_event(event));
2420 #if LIBINPUT_HAVE_SCROLL_VALUE_V120
2421 case LIBINPUT_EVENT_POINTER_SCROLL_WHEEL:
2422 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_WHEEL);
2424 case LIBINPUT_EVENT_POINTER_SCROLL_FINGER:
2425 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_FINGER);
2427 case LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS:
2428 _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_CONTINUOUS);
2431 case LIBINPUT_EVENT_TOUCH_DOWN:
2432 _device_handle_touch_down(device, libinput_event_get_touch_event(event));
2434 case LIBINPUT_EVENT_TOUCH_MOTION:
2435 _device_handle_touch_motion(device,
2436 libinput_event_get_touch_event(event));
2438 case LIBINPUT_EVENT_TOUCH_UP:
2439 _device_handle_touch_up(device, libinput_event_get_touch_event(event));
2441 case LIBINPUT_EVENT_TOUCH_CANCEL:
2442 _device_handle_touch_cancel(device, libinput_event_get_touch_event(event));
2444 case LIBINPUT_EVENT_TOUCH_FRAME:
2445 _device_handle_touch_frame(device, libinput_event_get_touch_event(event));
2447 case LIBINPUT_EVENT_TOUCH_AUX_DATA:
2448 _device_handle_touch_aux_data(device, libinput_event_get_touch_aux_data(event));
2459 * @brief Set the axis size of the given device.
2461 * @param dev The device to set the axis size to.
2462 * @param w The width of the axis.
2463 * @param h The height of the axis.
2465 * This function sets set the width @p w and height @p h of the axis
2466 * of device @p dev. If @p dev is a relative input device, a width and
2467 * height must set for it. If its absolute set the ioctl correctly, if
2468 * not, unsupported device.
2471 e_input_evdev_axis_size_set(E_Input_Evdev *edev, int w, int h)
2475 enum libinput_config_status status;
2476 struct udev_device *udev_device = NULL;
2478 EINA_SAFETY_ON_NULL_RETURN(edev);
2479 EINA_SAFETY_ON_TRUE_RETURN((w == 0) || (h == 0));
2481 if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
2482 (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
2485 udev_device = libinput_device_get_udev_device(edev->device);
2488 ERR("no udev_device");
2492 vals = udev_device_get_property_value(udev_device, "WL_CALIBRATION");
2494 (sscanf(vals, "%f %f %f %f %f %f",
2495 &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
2497 udev_device_unref(udev_device);
2500 udev_device_unref(udev_device);
2502 ELOGF("E_INPUT_EVDEV", "axis_size_set cal[%lf %lf %lf %lf %lf %lf] (%d x %d)",
2503 NULL, cal[0], cal[1], cal[2], cal[3], cal[4], cal[5], w, h);
2509 libinput_device_config_calibration_set_matrix(edev->device, cal);
2511 if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
2512 ERR("Failed to apply calibration");
2515 EINTERN const char *
2516 e_input_evdev_name_get(E_Input_Evdev *evdev)
2518 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2519 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2521 return libinput_device_get_name(evdev->device);
2524 EINTERN const char *
2525 e_input_evdev_sysname_get(E_Input_Evdev *evdev)
2527 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2528 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2530 return libinput_device_get_sysname(evdev->device);
2534 e_input_evdev_key_remap_enable(E_Input_Evdev *edev, Eina_Bool enable)
2536 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2537 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2539 edev->key_remap_enabled = enable;
2541 if (enable == EINA_FALSE && edev->key_remap_hash)
2543 eina_hash_free(edev->key_remap_hash);
2544 edev->key_remap_hash = NULL;
2551 e_input_evdev_key_remap_set(E_Input_Evdev *edev, int *from_keys, int *to_keys, int num)
2555 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2556 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2557 EINA_SAFETY_ON_NULL_RETURN_VAL(from_keys, EINA_FALSE);
2558 EINA_SAFETY_ON_NULL_RETURN_VAL(to_keys, EINA_FALSE);
2559 EINA_SAFETY_ON_TRUE_RETURN_VAL(num <= 0, EINA_FALSE);
2560 EINA_SAFETY_ON_TRUE_RETURN_VAL(!edev->key_remap_enabled, EINA_FALSE);
2562 if (edev->key_remap_hash == NULL)
2563 edev->key_remap_hash = eina_hash_int32_new(NULL);
2565 if (edev->key_remap_hash == NULL)
2567 ERR("Failed to set remap key information : creating a hash is failed.");
2571 for (i = 0; i < num ; i++)
2573 if (!from_keys[i] || !to_keys[i])
2575 ERR("Failed to set remap key information : given arguments are invalid.");
2580 for (i = 0; i < num ; i++)
2582 eina_hash_add(edev->key_remap_hash, &from_keys[i], (void *)(intptr_t)to_keys[i]);
2589 e_input_evdev_wheel_click_angle_get(E_Input_Evdev *dev)
2591 EINA_SAFETY_ON_NULL_RETURN_VAL(dev, -1);
2592 return libinput_device_config_scroll_get_wheel_click_angle(dev->device);
2596 e_input_evdev_touch_calibration_set(E_Input_Evdev *edev, float matrix[6])
2598 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2599 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2601 if (!libinput_device_config_calibration_has_matrix(edev->device) ||
2602 !libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_TOUCH))
2605 if (libinput_device_config_calibration_set_matrix(edev->device, matrix) !=
2606 LIBINPUT_CONFIG_STATUS_SUCCESS)
2608 WRN("Failed to set input transformation about device: %s\n",
2609 libinput_device_get_name(edev->device));
2617 e_input_evdev_mouse_accel_speed_set(E_Input_Evdev *edev, double speed)
2619 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2620 EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2622 if (!libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
2625 if (!libinput_device_config_accel_is_available(edev->device))
2628 if (libinput_device_config_accel_set_speed(edev->device, speed) !=
2629 LIBINPUT_CONFIG_STATUS_SUCCESS)
2631 WRN("Failed to set mouse accel about device: %s\n",
2632 libinput_device_get_name(edev->device));
2639 EINTERN unsigned int
2640 e_input_evdev_touch_pressed_get(E_Input_Evdev *edev)
2642 EINA_SAFETY_ON_NULL_RETURN_VAL(edev, 0x0);
2644 return edev->touch.pressed;
2648 e_input_evdev_seatname_get(E_Input_Evdev *evdev)
2650 struct libinput_seat *libinput_seat;
2651 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2652 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2654 libinput_seat = libinput_device_get_seat(evdev->device);
2656 return libinput_seat_get_logical_name(libinput_seat);
2660 e_input_evdev_seatname_set(E_Input_Evdev *evdev, const char *seatname)
2662 Eina_Bool res = EINA_FALSE;
2663 E_Input_Backend *input;
2665 EINA_SAFETY_ON_NULL_RETURN_VAL(seatname, EINA_FALSE);
2666 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, EINA_FALSE);
2667 EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, EINA_FALSE);
2669 if (libinput_device_set_seat_logical_name(evdev->device, seatname) == 0)
2671 input = evdev->seat->input;
2672 if (!input) return EINA_FALSE;
2674 if (libinput_dispatch(input->libinput) != 0)
2676 ERR("Failed to dispatch libinput events: %m");
2681 /* process pending events */
2682 _input_events_process(input);