e_input: support a LIBINPUT_EVENT_TOUCH_CANCEL
[platform/upstream/enlightenment.git] / src / bin / e_input_evdev.c
1 #include "e.h"
2 #include "e_input_private.h"
3
4 static void  _device_modifiers_update(E_Input_Evdev *edev);
5
6 void
7 _device_calibration_set(E_Input_Evdev *edev)
8 {
9    E_Output *output;
10    int w = 0, h = 0;
11    int temp;
12
13    output = e_comp_screen_primary_output_get(e_comp->e_comp_screen);
14    e_output_size_get(output, &w, &h);
15
16    if (output)
17      {
18         edev->mouse.minx = edev->mouse.miny = 0;
19         edev->mouse.maxw = w;
20         edev->mouse.maxh = h;
21
22         if (libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
23           {
24              edev->seat->ptr.dx = (double)(w / 2);
25              edev->seat->ptr.dy = (double)(h / 2);
26              edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
27              edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
28              edev->mouse.dx = edev->seat->ptr.dx;
29              edev->mouse.dy = edev->seat->ptr.dy;
30
31              if (output->config.rotation == 90 || output->config.rotation == 270)
32                {
33                   temp = edev->mouse.minx;
34                   edev->mouse.minx = edev->mouse.miny;
35                   edev->mouse.miny = temp;
36
37                   temp = edev->mouse.maxw;
38                   edev->mouse.maxw = edev->mouse.maxh;
39                   edev->mouse.maxh = temp;
40                }
41           }
42      }
43
44 //LCOV_EXCL_START
45 #ifdef _F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
46    const char *sysname;
47    float cal[6];
48    const char *device;
49    Eina_List *devices;
50
51    if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
52        (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
53      return;
54
55    sysname = libinput_device_get_sysname(edev->device);
56
57    devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
58    if (eina_list_count(devices) < 1) return;
59
60 #ifdef _F_E_INPUT_USE_WL_CALIBRATION_
61    const char *vals;
62    enum libinput_config_status status;
63
64    EINA_LIST_FREE(devices, device)
65      {
66         vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
67         if ((!vals) ||
68             (sscanf(vals, "%f %f %f %f %f %f",
69                     &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
70           goto cont;
71
72         cal[2] /= w;
73         cal[5] /= h;
74
75         status =
76           libinput_device_config_calibration_set_matrix(edev->device, cal);
77
78         if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
79           ERR("Failed to apply calibration");
80
81 cont:
82         eina_stringshare_del(device);
83         continue;
84      }
85 #endif//_F_E_INPUT_USE_WL_CALIBRATION_
86 #endif//_F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
87 //LCOV_EXCL_STOP
88 }
89
90 static void
91 _device_touch_count_update(E_Input_Evdev *edev)
92 {
93    unsigned int device_touch_count = 0;
94    static unsigned int _max_device_touch_count = 0;
95
96    E_Input *ei = e_input_get();
97    EINA_SAFETY_ON_NULL_RETURN(ei);
98
99    device_touch_count = libinput_device_touch_get_touch_count(edev->device);
100
101    if (_max_device_touch_count < device_touch_count)
102      _max_device_touch_count = device_touch_count;
103
104    if (e_config->configured_max_touch.use)
105      {
106         if (_max_device_touch_count > 0 && e_config->configured_max_touch.count > _max_device_touch_count)
107           {
108              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",
109                          NULL, e_config->configured_max_touch.count, _max_device_touch_count, _max_device_touch_count);
110              ei->touch_max_count = _max_device_touch_count;
111           }
112         else
113           {
114              if (ei->touch_max_count != e_config->configured_max_touch.count)
115              {
116                 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch_max_count has been updated to %d -> %d.\n",
117                            NULL, ei->touch_max_count, e_config->configured_max_touch.count);
118                 ei->touch_max_count = e_config->configured_max_touch.count;
119              }
120           }
121      }
122    else
123      {
124         if (ei->touch_max_count < _max_device_touch_count)
125           {
126              ELOGF("E_INPUT_EVDEV_TOUCH", "Touch_max_count has been updated to %d -> %d.\n", NULL,
127                    ei->touch_max_count, _max_device_touch_count);
128              ei->touch_max_count = _max_device_touch_count;
129           }
130      }
131
132    ei->touch_device_count++;
133    ELOGF("E_INPUT_EVDEV_TOUCH", "Touch device count is %d.\n", NULL, ei->touch_device_count);
134 }
135
136 static void
137 _device_configure(E_Input_Evdev *edev)
138 {
139    if (libinput_device_config_tap_get_finger_count(edev->device) > 0)
140      {
141         Eina_Bool tap = EINA_FALSE;
142
143         tap = libinput_device_config_tap_get_default_enabled(edev->device);
144         libinput_device_config_tap_set_enabled(edev->device, tap);
145      }
146
147    _device_calibration_set(edev);
148 }
149
150 static void
151 _device_keyboard_setup(E_Input_Evdev *edev)
152 {
153    E_Input_Backend *input;
154    xkb_mod_index_t xkb_idx;
155
156    if ((!edev) || (!edev->seat)) return;
157    if (!(input = edev->seat->input)) return;
158    if (!input->dev->xkb_ctx) return;
159
160    /* create keymap from xkb context */
161    edev->xkb.keymap = _e_input_device_cached_keymap_get(input->dev->xkb_ctx, NULL, 0);
162    if (!edev->xkb.keymap)
163      {
164         ERR("Failed to create keymap: %m");
165         return;
166      }
167
168    /* create xkb state */
169    if (!(edev->xkb.state = xkb_state_new(edev->xkb.keymap)))
170      {
171         ERR("Failed to create xkb state: %m");
172         return;
173      }
174
175    xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CTRL);
176    if (xkb_idx != XKB_MOD_INVALID)
177      edev->xkb.ctrl_mask = 1 << xkb_idx;
178    else
179      edev->xkb.ctrl_mask = 0;
180
181    xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_ALT);
182    if (xkb_idx != XKB_MOD_INVALID)
183      edev->xkb.alt_mask = 1 << xkb_idx;
184    else
185      edev->xkb.alt_mask = 0;
186
187    xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_SHIFT);
188    if (xkb_idx != XKB_MOD_INVALID)
189      edev->xkb.shift_mask = 1 << xkb_idx;
190    else
191      edev->xkb.shift_mask = 0;
192
193    xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_LOGO);
194    if (xkb_idx != XKB_MOD_INVALID)
195      edev->xkb.win_mask = 1 << xkb_idx;
196    else
197      edev->xkb.win_mask = 0;
198
199    xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_SCROLL);
200    if (xkb_idx != XKB_MOD_INVALID)
201      edev->xkb.scroll_mask = 1 << xkb_idx;
202    else
203      edev->xkb.scroll_mask = 0;
204
205    xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_NUM);
206    if (xkb_idx != XKB_MOD_INVALID)
207      edev->xkb.num_mask = 1 << xkb_idx;
208    else
209      edev->xkb.num_mask = 0;
210
211    xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CAPS);
212    if (xkb_idx != XKB_MOD_INVALID)
213      edev->xkb.caps_mask = 1 << xkb_idx;
214    else
215      edev->xkb.caps_mask = 0;
216
217    xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, "ISO_Level3_Shift");
218    if (xkb_idx != XKB_MOD_INVALID)
219      edev->xkb.altgr_mask = 1 << xkb_idx;
220    else
221      edev->xkb.altgr_mask = 0;
222 }
223
224 static int
225 _device_keysym_translate(xkb_keysym_t keysym, unsigned int modifiers, char *buffer, int bytes)
226 {
227    unsigned long hbytes = 0;
228    unsigned char c;
229
230    if (!keysym) return 0;
231    hbytes = (keysym >> 8);
232
233    if (!(bytes &&
234          ((hbytes == 0) ||
235           ((hbytes == 0xFF) &&
236            (((keysym >= XKB_KEY_BackSpace) && (keysym <= XKB_KEY_Clear)) ||
237             (keysym == XKB_KEY_Return) || (keysym == XKB_KEY_Escape) ||
238             (keysym == XKB_KEY_KP_Space) || (keysym == XKB_KEY_KP_Tab) ||
239             (keysym == XKB_KEY_KP_Enter) ||
240             ((keysym >= XKB_KEY_KP_Multiply) && (keysym <= XKB_KEY_KP_9)) ||
241             (keysym == XKB_KEY_KP_Equal) || (keysym == XKB_KEY_Delete))))))
242      return 0;
243
244    if (keysym == XKB_KEY_KP_Space)
245      c = (XKB_KEY_space & 0x7F);
246    else if (hbytes == 0xFF)
247      c = (keysym & 0x7F);
248    else
249      c = (keysym & 0xFF);
250
251    if (modifiers & ECORE_EVENT_MODIFIER_CTRL)
252      {
253         if (((c >= '@') && (c < '\177')) || c == ' ')
254           c &= 0x1F;
255         else if (c == '2')
256           c = '\000';
257         else if ((c >= '3') && (c <= '7'))
258           c -= ('3' - '\033');
259         else if (c == '8')
260           c = '\177';
261         else if (c == '/')
262           c = '_' & 0x1F;
263      }
264    buffer[0] = c;
265    return 1;
266 }
267
268 static void
269 _device_modifiers_update_device(E_Input_Evdev *edev, E_Input_Evdev *from)
270 {
271    xkb_mod_mask_t mask;
272
273    edev->xkb.depressed =
274      xkb_state_serialize_mods(from->xkb.state, XKB_STATE_DEPRESSED);
275    edev->xkb.latched =
276      xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LATCHED);
277    edev->xkb.locked =
278      xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LOCKED);
279    edev->xkb.group =
280      xkb_state_serialize_mods(from->xkb.state, XKB_STATE_EFFECTIVE);
281
282    mask = (edev->xkb.depressed | edev->xkb.latched);
283
284    if (mask & from->xkb.ctrl_mask)
285      edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_CTRL;
286    if (mask & from->xkb.alt_mask)
287      edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALT;
288    if (mask & from->xkb.shift_mask)
289      edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
290    if (mask & from->xkb.win_mask)
291      edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_WIN;
292    if (mask & from->xkb.scroll_mask)
293      edev->xkb.modifiers |= ECORE_EVENT_LOCK_SCROLL;
294    if (mask & from->xkb.num_mask)
295      edev->xkb.modifiers |= ECORE_EVENT_LOCK_NUM;
296    if (mask & from->xkb.caps_mask)
297      edev->xkb.modifiers |= ECORE_EVENT_LOCK_CAPS;
298    if (mask & from->xkb.altgr_mask)
299      edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALTGR;
300 }
301
302 static void
303 _device_modifiers_update(E_Input_Evdev *edev)
304 {
305    Eina_List *l;
306    E_Input_Evdev *ed;
307
308    edev->xkb.modifiers = 0;
309
310    if (edev->caps & E_INPUT_SEAT_KEYBOARD)
311      _device_modifiers_update_device(edev, edev);
312    else
313      {
314         EINA_LIST_FOREACH(edev->seat->devices, l, ed)
315           {
316              if (!(ed->caps & E_INPUT_SEAT_KEYBOARD)) continue;
317              _device_modifiers_update_device(edev, ed);
318           }
319      }
320
321 }
322
323 static int
324 _device_remapped_key_get(E_Input_Evdev *edev, int code)
325 {
326    void *ret = NULL;
327
328    EINA_SAFETY_ON_NULL_RETURN_VAL(edev, code);
329    if (!edev->key_remap_enabled) return code;
330    EINA_SAFETY_ON_NULL_RETURN_VAL(edev->key_remap_hash, code);
331
332    ret = eina_hash_find(edev->key_remap_hash, &code);
333
334    if (ret) code = (int)(intptr_t)ret;
335
336    return code;
337 }
338
339 E_API Ecore_Device *
340 e_input_evdev_get_ecore_device(const char *path, Ecore_Device_Class clas)
341 {
342    const Eina_List *dev_list = NULL;
343    const Eina_List *l;
344    Ecore_Device *dev = NULL;
345    const char *identifier;
346
347    if (!path) return NULL;
348
349    dev_list = ecore_device_list();
350    if (!dev_list) return NULL;
351    EINA_LIST_FOREACH(dev_list, l, dev)
352      {
353         if (!dev) continue;
354         identifier = ecore_device_identifier_get(dev);
355         if (!identifier) continue;
356         if ((ecore_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
357           return dev;
358      }
359    return NULL;
360 }
361
362 static void
363 _e_input_event_mouse_move_cb_free(void *data EINA_UNUSED, void *event)
364 {
365    Ecore_Event_Mouse_Move *ev = event;
366
367    if (ev->dev) ecore_device_unref(ev->dev);
368
369    free(ev);
370 }
371
372 static void
373 _e_input_event_mouse_wheel_cb_free(void *data EINA_UNUSED, void *event)
374 {
375    Ecore_Event_Mouse_Wheel *ev = event;
376
377    if (ev->dev) ecore_device_unref(ev->dev);
378
379    free(ev);
380 }
381
382 static void
383 _e_input_event_mouse_button_cb_free(void *data EINA_UNUSED, void *event)
384 {
385    Ecore_Event_Mouse_Button *ev = event;
386
387    if (ev->dev) ecore_device_unref(ev->dev);
388
389    free(ev);
390 }
391
392 static void
393 _e_input_event_key_cb_free(void *data EINA_UNUSED, void *event)
394 {
395    Ecore_Event_Key *ev = event;
396
397    if (ev->dev) ecore_device_unref(ev->dev);
398    if (ev->data) E_FREE(ev->data);
399
400    free(ev);
401 }
402
403 static void
404 _device_handle_key(struct libinput_device *device, struct libinput_event_keyboard *event)
405 {
406    E_Input_Evdev *edev;
407    E_Input_Backend *input;
408    uint32_t timestamp;
409    uint32_t code, nsyms;
410    const xkb_keysym_t *syms;
411    enum libinput_key_state state;
412    int key_count;
413    xkb_keysym_t sym = XKB_KEY_NoSymbol;
414    char key[256] = {0, }, keyname[256] = {0, }, compose_buffer[256] = {0, };
415    Ecore_Event_Key *e;
416    char *tmp = NULL, *compose = NULL;
417    E_Keyrouter_Event_Data *key_data;
418    Ecore_Device *ecore_dev = NULL, *data;
419    Eina_List *l, *l_next;
420    E_Comp_Config *comp_conf = NULL;
421    int *pressed_keycode = NULL, *idata = NULL;
422    Eina_Bool dup_found = EINA_FALSE;
423
424    if (!(edev = libinput_device_get_user_data(device)))
425      {
426         return;
427      }
428
429    if (!(input = edev->seat->input))
430      {
431         return;
432      }
433
434    if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
435    else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
436      {
437         EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
438           {
439              if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_KEYBOARD)
440                {
441                   ecore_dev = data;
442                   break;
443                }
444           }
445      }
446    else
447      {
448         edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
449         ecore_dev = edev->ecore_dev;
450      }
451
452    if (!ecore_dev)
453      {
454         ERR("Failed to get source ecore device from event !\n");
455         return;
456      }
457
458    timestamp = libinput_event_keyboard_get_time(event);
459    code = libinput_event_keyboard_get_key(event);
460    code = _device_remapped_key_get(edev, code + 8);
461    state = libinput_event_keyboard_get_key_state(event);
462    key_count = libinput_event_keyboard_get_seat_key_count(event);
463
464    if (state == LIBINPUT_KEY_STATE_PRESSED)
465      {
466         if ((edev->seat->dev->blocked & E_INPUT_SEAT_KEYBOARD) ||
467             (edev->seat->dev->server_blocked & E_INPUT_SEAT_KEYBOARD))
468           {
469              ELOGF("Key", "Press (keycode: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
470                    code, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
471                    edev->seat->dev->server_blocked);
472              return;
473           }
474
475         /* FIXME: Currently to maintain press/release event pair during input block,
476          *        used Eina_List and this is method used in devicemgr module.
477          *        But we need to consider which way is better to maintain key press/release pair.
478          */
479
480         EINA_LIST_FOREACH(edev->xkb.pressed_keys, l, idata)
481           {
482              if (*idata == code)
483                {
484                   dup_found = EINA_TRUE;
485                   break;
486                }
487           }
488         if (!dup_found)
489           {
490              pressed_keycode = E_NEW(int, 1);
491              EINA_SAFETY_ON_NULL_RETURN(pressed_keycode);
492              *pressed_keycode = code;
493
494              edev->xkb.pressed_keys = eina_list_append(edev->xkb.pressed_keys, pressed_keycode);
495           }
496      }
497    else
498      {
499         dup_found = EINA_FALSE;
500         EINA_LIST_FOREACH_SAFE(edev->xkb.pressed_keys, l, l_next, idata)
501           {
502              if (code == *idata)
503                {
504                   edev->xkb.pressed_keys = eina_list_remove_list(edev->xkb.pressed_keys, l);
505                   E_FREE(idata);
506                   dup_found = EINA_TRUE;
507                   break;
508                }
509           }
510         if (!dup_found)
511           {
512              ELOGF("Key", "Release (keycode: %d, device: %s) is blocked by %p", NULL,
513                    code, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client);
514              return;
515           }
516      }
517
518    /* ignore key events that are not seat wide state changes */
519    if (((state == LIBINPUT_KEY_STATE_PRESSED) && (key_count != 1)) ||
520        ((state == LIBINPUT_KEY_STATE_RELEASED) && (key_count != 0)))
521      {
522         return;
523      }
524
525    xkb_state_update_key(edev->xkb.state, code,
526                         (state ? XKB_KEY_DOWN : XKB_KEY_UP));
527
528    /* get the keysym for this code */
529    nsyms = xkb_key_get_syms(edev->xkb.state, code, &syms);
530    if (nsyms == 1) sym = syms[0];
531
532    /* If no keysym was found, name it "Keycode-NNN" */
533    if (sym == XKB_KEY_NoSymbol)
534      snprintf(key, sizeof(key), "Keycode-%u", code);
535    else
536      {
537         /* get the keyname for this sym */
538         xkb_keysym_get_name(sym, key, sizeof(key));
539      }
540
541    if (key[0] == '\0')
542      {
543         /* If no keyname was found, name it "Keycode-NNN" */
544         snprintf(keyname, sizeof(keyname), "Keycode-%u", code);
545      }
546    else
547      {
548         memcpy(keyname, key, sizeof(keyname));
549      }
550
551    /* if shift is active, we need to transform the key to lower */
552    if (xkb_state_mod_index_is_active(edev->xkb.state,
553                                      xkb_map_mod_get_index(edev->xkb.keymap,
554                                      XKB_MOD_NAME_SHIFT),
555                                      XKB_STATE_MODS_EFFECTIVE))
556      {
557         if (keyname[0] != '\0')
558           keyname[0] = tolower(keyname[0]);
559      }
560
561    if (_device_keysym_translate(sym, edev->xkb.modifiers,
562                                 compose_buffer, sizeof(compose_buffer)))
563      {
564         compose = eina_str_convert("ISO8859-1", "UTF-8", compose_buffer);
565         if (!compose)
566           {
567              ERR("E Input cannot convert input key string '%s' to UTF-8. "
568                  "Is Eina built with iconv support?", compose_buffer);
569           }
570         else
571           tmp = compose;
572      }
573
574    if (!compose) compose = compose_buffer;
575
576    e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) +
577               ((compose[0] != '\0') ? strlen(compose) : 0) + 3);
578    if (!e)
579      {
580         E_FREE(tmp);
581         return;
582      }
583    key_data = E_NEW(E_Keyrouter_Event_Data, 1);
584    if (!key_data)
585      {
586         E_FREE(tmp);
587         E_FREE(e);
588         return;
589      }
590
591    e->keyname = (char *)(e + 1);
592    e->key = e->keyname + strlen(keyname) + 1;
593    e->compose = strlen(compose) ? e->key + strlen(key) + 1 : NULL;
594    e->string = e->compose;
595
596    strncpy((char *)e->keyname, keyname, strlen(keyname));
597    strncpy((char *)e->key, key, strlen(key));
598    if (strlen(compose)) strncpy((char *)e->compose, compose, strlen(compose));
599
600    e->window = (Ecore_Window)input->dev->window;
601    e->event_window = (Ecore_Window)input->dev->window;
602    e->root_window = (Ecore_Window)input->dev->window;
603    e->timestamp = timestamp;
604    e->same_screen = 1;
605    e->keycode = code;
606    e->data = key_data;
607
608    _device_modifiers_update(edev);
609
610    e->modifiers = edev->xkb.modifiers;
611    e->dev = ecore_device_ref(ecore_dev);
612
613    comp_conf = e_comp_config_get();
614    if (comp_conf && comp_conf->input_log_enable)
615      ELOGF("Key", "%s (keyname: %s, keycode: %d, device: %s)", NULL, state?"Press":"Release", e->keyname, e->keycode, ecore_device_name_get(e->dev));
616
617    if (state)
618      ecore_event_add(ECORE_EVENT_KEY_DOWN, e, _e_input_event_key_cb_free, NULL);
619    else
620      ecore_event_add(ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
621
622    if (tmp) free(tmp);
623 }
624
625 static void
626 _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event)
627 {
628    E_Input_Backend *input;
629    Ecore_Event_Mouse_Move *ev;
630    Ecore_Device *ecore_dev = NULL, *data, *detent_data = NULL;
631    Eina_List *l;
632
633    if (!(input = edev->seat->input)) return;
634
635    if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
636    else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
637      {
638         EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
639           {
640              if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
641                {
642                   ecore_dev = data;
643                   break;
644                }
645              else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
646                {
647                   detent_data = data;
648                }
649           }
650         if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
651           {
652              ecore_dev = detent_data;
653           }
654      }
655    else
656      {
657         edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
658         ecore_dev = edev->ecore_dev;
659      }
660
661    if (!ecore_dev)
662      {
663         ERR("Failed to get source ecore device from event !\n");
664         return;
665      }
666    else if ((detent_data == ecore_dev) || e_devicemgr_detent_is_detent(ecore_device_name_get(ecore_dev)))
667      {
668         /* Do not process detent device's move events. */
669         return;
670      }
671
672    if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
673
674    if (edev->seat->ptr.ix < edev->mouse.minx)
675      edev->seat->ptr.dx = edev->seat->ptr.ix = edev->mouse.minx;
676    else if (edev->seat->ptr.ix >= (edev->mouse.minx + edev->mouse.maxw))
677      edev->seat->ptr.dx = edev->seat->ptr.ix = (edev->mouse.minx + edev->mouse.maxw - 1);
678
679    if (edev->seat->ptr.iy < edev->mouse.miny)
680      edev->seat->ptr.dy = edev->seat->ptr.iy = edev->mouse.miny;
681    else if (edev->seat->ptr.iy >= (edev->mouse.miny + edev->mouse.maxh))
682      edev->seat->ptr.dy = edev->seat->ptr.iy = (edev->mouse.miny + edev->mouse.maxh - 1);
683
684    edev->mouse.dx = edev->seat->ptr.dx;
685    edev->mouse.dy = edev->seat->ptr.dy;
686
687    ev->window = (Ecore_Window)input->dev->window;
688    ev->event_window = (Ecore_Window)input->dev->window;
689    ev->root_window = (Ecore_Window)input->dev->window;
690    if (event) ev->timestamp = libinput_event_pointer_get_time(event);
691    ev->same_screen = 1;
692
693    _device_modifiers_update(edev);
694    ev->modifiers = edev->xkb.modifiers;
695
696    ev->x = edev->seat->ptr.ix;
697    ev->y = edev->seat->ptr.iy;
698    ev->root.x = ev->x;
699    ev->root.y = ev->y;
700
701    ev->multi.device = edev->mt_slot;
702    ev->multi.radius = 1;
703    ev->multi.radius_x = 1;
704    ev->multi.radius_y = 1;
705    ev->multi.pressure = 1.0;
706    ev->multi.angle = 0.0;
707    ev->multi.x = ev->x;
708    ev->multi.y = ev->y;
709    ev->multi.root.x = ev->x;
710    ev->multi.root.y = ev->y;
711    ev->dev = ecore_device_ref(ecore_dev);
712
713    ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
714 }
715
716 void
717 _e_input_pointer_motion_post(E_Input_Evdev *edev)
718 {
719    _device_pointer_motion(edev, NULL);
720 }
721
722 static void
723 _device_handle_pointer_motion(struct libinput_device *device, struct libinput_event_pointer *event)
724 {
725    E_Input_Evdev *edev;
726    double dx, dy, temp;
727
728    if (!(edev = libinput_device_get_user_data(device)))
729      {
730         return;
731      }
732
733    dx = libinput_event_pointer_get_dx(event);
734    dy = libinput_event_pointer_get_dy(event);
735
736    if (edev->seat->ptr.swap)
737      {
738          temp = dx;
739          dx = dy;
740          dy = temp;
741      }
742    if (edev->seat->ptr.invert_x)
743      dx *= -1;
744    if (edev->seat->ptr.invert_y)
745      dy *= -1;
746
747    edev->seat->ptr.dx += dx;
748    edev->seat->ptr.dy += dy;
749
750    edev->mouse.dx = edev->seat->ptr.dx;
751    edev->mouse.dy = edev->seat->ptr.dy;
752
753    if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
754        floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
755      {
756         return;
757      }
758
759    edev->seat->ptr.ix = edev->seat->ptr.dx;
760    edev->seat->ptr.iy = edev->seat->ptr.dy;
761
762    if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
763        (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
764      {
765         return;
766      }
767
768   _device_pointer_motion(edev, event);
769 }
770
771 static void
772 _device_handle_pointer_motion_absolute(struct libinput_device *device, struct libinput_event_pointer *event)
773 {
774    E_Input_Evdev *edev;
775    int w = 0, h = 0;
776
777    if (!(edev = libinput_device_get_user_data(device)))
778      {
779         return;
780      }
781
782    e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
783
784    edev->mouse.dx = edev->seat->ptr.dx =
785      libinput_event_pointer_get_absolute_x_transformed(event, w);
786    edev->mouse.dy = edev->seat->ptr.dy =
787      libinput_event_pointer_get_absolute_y_transformed(event, h);
788
789    if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
790        floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
791      {
792         return;
793      }
794
795    edev->seat->ptr.ix = edev->seat->ptr.dx;
796    edev->seat->ptr.iy = edev->seat->ptr.dy;
797
798    if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
799        (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
800      {
801         return;
802      }
803
804    _device_pointer_motion(edev, event);
805 }
806
807 static void
808 _device_handle_button(struct libinput_device *device, struct libinput_event_pointer *event)
809 {
810    E_Input_Evdev *edev;
811    E_Input_Backend *input;
812    Ecore_Event_Mouse_Button *ev;
813    enum libinput_button_state state;
814    uint32_t button, timestamp;
815    Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
816    Eina_List *l;
817    E_Comp_Config *comp_conf = NULL;
818
819    if (!(edev = libinput_device_get_user_data(device)))
820      {
821         return;
822      }
823    if (!(input = edev->seat->input))
824      {
825         return;
826      }
827
828    if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
829    else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
830      {
831         EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
832           {
833              if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
834                {
835                   ecore_dev = data;
836                   break;
837                }
838              else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
839                {
840                   detent_data = data;
841                }
842           }
843         if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
844           {
845              ecore_dev = detent_data;
846           }
847      }
848    else
849      {
850         edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
851         ecore_dev = edev->ecore_dev;
852      }
853
854    if (!ecore_dev)
855      {
856         ERR("Failed to get source ecore device from event !\n");
857         return;
858      }
859
860    state = libinput_event_pointer_get_button_state(event);
861    button = libinput_event_pointer_get_button(event);
862    timestamp = libinput_event_pointer_get_time(event);
863
864    button = ((button & 0x00F) + 1);
865    if (button == 3) button = 2;
866    else if (button == 2) button = 3;
867
868    if (state)
869      {
870         if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
871             (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
872           {
873              ELOGF("Mouse", "Button Press (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
874                    button, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
875                    edev->seat->dev->server_blocked);
876              return;
877           }
878         else
879           {
880              edev->mouse.pressed_button |= (1 << button);
881           }
882      }
883    else
884      {
885         if (!(edev->mouse.pressed_button & (1 << button)))
886           {
887              ELOGF("Mouse", "Button Release (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
888                    button, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
889                    edev->seat->dev->server_blocked);
890              return;
891           }
892         edev->mouse.pressed_button &= ~(1 << button);
893      }
894
895    if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button))))
896      {
897         return;
898      }
899
900    ev->window = (Ecore_Window)input->dev->window;
901    ev->event_window = (Ecore_Window)input->dev->window;
902    ev->root_window = (Ecore_Window)input->dev->window;
903    ev->timestamp = timestamp;
904    ev->same_screen = 1;
905
906    _device_modifiers_update(edev);
907    ev->modifiers = edev->xkb.modifiers;
908
909    ev->x = edev->seat->ptr.ix;
910    ev->y = edev->seat->ptr.iy;
911    ev->root.x = ev->x;
912    ev->root.y = ev->y;
913
914    ev->multi.device = edev->mt_slot;
915    ev->multi.radius = 1;
916    ev->multi.radius_x = 1;
917    ev->multi.radius_y = 1;
918    ev->multi.pressure = 1.0;
919    ev->multi.angle = 0.0;
920    ev->multi.x = ev->x;
921    ev->multi.y = ev->y;
922    ev->multi.root.x = ev->x;
923    ev->multi.root.y = ev->y;
924    ev->dev = ecore_device_ref(ecore_dev);
925
926    if (state)
927      {
928         unsigned int current;
929
930         current = timestamp;
931         edev->mouse.did_double = EINA_FALSE;
932         edev->mouse.did_triple = EINA_FALSE;
933
934         if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
935             (button == edev->mouse.prev_button))
936           {
937              edev->mouse.did_double = EINA_TRUE;
938              if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
939                  (button == edev->mouse.last_button))
940                {
941                   edev->mouse.did_triple = EINA_TRUE;
942                   edev->mouse.prev = 0;
943                   edev->mouse.last = 0;
944                   current = 0;
945                }
946           }
947
948         edev->mouse.last = edev->mouse.prev;
949         edev->mouse.prev = current;
950         edev->mouse.last_button = edev->mouse.prev_button;
951         edev->mouse.prev_button = button;
952      }
953
954    ev->buttons = button;
955
956    if (edev->mouse.did_double)
957      ev->double_click = 1;
958    if (edev->mouse.did_triple)
959      ev->triple_click = 1;
960
961    comp_conf = e_comp_config_get();
962    if (comp_conf && comp_conf->input_log_enable)
963      ELOGF("Mouse", "Button %s (btn: %d, device: %s)", NULL, state?"Press":"Release", button, ecore_device_name_get(ev->dev));
964
965    if (state)
966      ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, _e_input_event_mouse_button_cb_free, NULL);
967    else
968      ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, _e_input_event_mouse_button_cb_free, NULL);
969 }
970
971 static void
972 _device_handle_axis(struct libinput_device *device, struct libinput_event_pointer *event)
973 {
974    E_Input_Evdev *edev;
975    E_Input_Backend *input;
976    Ecore_Event_Mouse_Wheel *ev;
977    uint32_t timestamp;
978    enum libinput_pointer_axis axis;
979    Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
980    Eina_List *l;
981    E_Comp_Config *comp_conf = NULL;
982    int direction = 0, z = 0;
983
984    if (!(edev = libinput_device_get_user_data(device)))
985      {
986         return;
987      }
988    if (!(input = edev->seat->input))
989      {
990         return;
991      }
992
993    if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
994    else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
995      {
996         EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
997           {
998              if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
999                {
1000                   ecore_dev = data;
1001                   break;
1002                }
1003              else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1004                {
1005                   detent_data = data;
1006                }
1007           }
1008         if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1009           {
1010              ecore_dev = detent_data;
1011           }
1012      }
1013    else
1014      {
1015         edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1016         ecore_dev = edev->ecore_dev;
1017      }
1018
1019    if (!ecore_dev)
1020      {
1021         ERR("Failed to get source ecore device from event !\n");
1022         return;
1023      }
1024
1025    axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1026    if (libinput_event_pointer_has_axis(event, axis))
1027      z = libinput_event_pointer_get_axis_value_discrete(event, axis);
1028
1029    axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1030    if (libinput_event_pointer_has_axis(event, axis))
1031      {
1032         direction = 1;
1033         z = libinput_event_pointer_get_axis_value_discrete(event, axis);
1034      }
1035
1036    comp_conf = e_comp_config_get();
1037    if (comp_conf && comp_conf->e_wheel_click_angle)
1038      {
1039         z = (int)(z * comp_conf->e_wheel_click_angle);
1040      }
1041
1042    if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1043        (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1044      {
1045         if (detent_data)
1046           ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1047                 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1048         else
1049           ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1050                 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1051         return;
1052      }
1053
1054    if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1055      {
1056         return;
1057      }
1058
1059    timestamp = libinput_event_pointer_get_time(event);
1060
1061    ev->window = (Ecore_Window)input->dev->window;
1062    ev->event_window = (Ecore_Window)input->dev->window;
1063    ev->root_window = (Ecore_Window)input->dev->window;
1064    ev->timestamp = timestamp;
1065    ev->same_screen = 1;
1066
1067    _device_modifiers_update(edev);
1068    ev->modifiers = edev->xkb.modifiers;
1069
1070    ev->x = edev->seat->ptr.ix;
1071    ev->y = edev->seat->ptr.iy;
1072    ev->root.x = ev->x;
1073    ev->root.y = ev->y;
1074    ev->dev = ecore_device_ref(ecore_dev);
1075
1076    ev->z = z;
1077    ev->direction = direction;
1078
1079    if (comp_conf && comp_conf->input_log_enable)
1080      {
1081         if (detent_data)
1082           ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1083         else
1084           ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1085      }
1086
1087    ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1088 }
1089
1090 static void
1091 _device_handle_touch_event_send(E_Input_Evdev *edev, struct libinput_event_touch *event, int state)
1092 {
1093    E_Input_Backend *input;
1094    Ecore_Event_Mouse_Button *ev;
1095    uint32_t timestamp, button = 0;
1096    Ecore_Device *ecore_dev = NULL, *data;
1097    Eina_List *l;
1098
1099    if (!edev) return;
1100    if (!(input = edev->seat->input)) return;
1101
1102    if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1103    else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1104      {
1105         EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1106           {
1107              if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1108                {
1109                   ecore_dev = data;
1110                   break;
1111                }
1112           }
1113      }
1114    else
1115      {
1116         edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1117         ecore_dev = edev->ecore_dev;
1118      }
1119
1120    if (!ecore_dev)
1121      {
1122         ERR("Failed to get source ecore device from event !\n");
1123         return;
1124      }
1125
1126    if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) return;
1127
1128    timestamp = libinput_event_touch_get_time(event);
1129
1130    ev->window = (Ecore_Window)input->dev->window;
1131    ev->event_window = (Ecore_Window)input->dev->window;
1132    ev->root_window = (Ecore_Window)input->dev->window;
1133    ev->timestamp = timestamp;
1134    ev->same_screen = 1;
1135
1136    _device_modifiers_update(edev);
1137    ev->modifiers = edev->xkb.modifiers;
1138
1139    ev->x = edev->seat->ptr.ix;
1140    ev->y = edev->seat->ptr.iy;
1141    ev->root.x = ev->x;
1142    ev->root.y = ev->y;
1143
1144    ev->multi.device = edev->mt_slot;
1145    ev->multi.radius = 1;
1146    ev->multi.radius_x = 1;
1147    ev->multi.radius_y = 1;
1148    ev->multi.pressure = 1.0;
1149    ev->multi.angle = 0.0;
1150 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1151    if (libinput_event_get_type(libinput_event_touch_get_base_event(event))
1152        == LIBINPUT_EVENT_TOUCH_DOWN)
1153      {
1154         if (libinput_event_touch_has_minor(event))
1155           ev->multi.radius_x = libinput_event_touch_get_minor(event);
1156         if (libinput_event_touch_has_major(event))
1157           ev->multi.radius_y = libinput_event_touch_get_major(event);
1158         if (libinput_event_touch_has_pressure(event))
1159           ev->multi.pressure = libinput_event_touch_get_pressure(event);
1160         if (libinput_event_touch_has_orientation(event))
1161           ev->multi.angle = libinput_event_touch_get_orientation(event);
1162      }
1163 #endif
1164    ev->multi.x = ev->x;
1165    ev->multi.y = ev->y;
1166    ev->multi.root.x = ev->x;
1167    ev->multi.root.y = ev->y;
1168    ev->dev = ecore_device_ref(ecore_dev);
1169
1170    if (state == ECORE_EVENT_MOUSE_BUTTON_DOWN)
1171      {
1172         unsigned int current;
1173
1174         current = timestamp;
1175         edev->mouse.did_double = EINA_FALSE;
1176         edev->mouse.did_triple = EINA_FALSE;
1177
1178         if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1179             (button == edev->mouse.prev_button))
1180           {
1181              edev->mouse.did_double = EINA_TRUE;
1182              if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1183                  (button == edev->mouse.last_button))
1184                {
1185                   edev->mouse.did_triple = EINA_TRUE;
1186                   edev->mouse.prev = 0;
1187                   edev->mouse.last = 0;
1188                   current = 0;
1189                }
1190           }
1191
1192         edev->mouse.last = edev->mouse.prev;
1193         edev->mouse.prev = current;
1194         edev->mouse.last_button = edev->mouse.prev_button;
1195         edev->mouse.prev_button = button;
1196         edev->touch.pressed |= (1 << ev->multi.device);
1197      }
1198    else
1199      {
1200         edev->touch.pressed &= ~(1 << ev->multi.device);
1201      }
1202
1203    ev->buttons = ((button & 0x00F) + 1);
1204
1205    if (edev->mouse.did_double)
1206      ev->double_click = 1;
1207    if (edev->mouse.did_triple)
1208      ev->triple_click = 1;
1209
1210    ecore_event_add(state, ev, _e_input_event_mouse_button_cb_free, NULL);
1211 }
1212
1213 static void
1214 _device_handle_touch_motion_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1215 {
1216    E_Input_Backend *input;
1217    Ecore_Event_Mouse_Move *ev;
1218    Ecore_Device *ecore_dev = NULL, *data;
1219    Eina_List *l;
1220
1221    if (!edev) return;
1222    if (!(input = edev->seat->input)) return;
1223
1224    if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1225    else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1226      {
1227         EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1228           {
1229              if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1230                {
1231                   ecore_dev = data;
1232                   break;
1233                }
1234           }
1235      }
1236    else
1237      {
1238         edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1239         ecore_dev = edev->ecore_dev;
1240      }
1241
1242    if (!ecore_dev)
1243      {
1244         ERR("Failed to get source ecore device from event !\n");
1245         return;
1246      }
1247
1248    if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
1249
1250    ev->window = (Ecore_Window)input->dev->window;
1251    ev->event_window = (Ecore_Window)input->dev->window;
1252    ev->root_window = (Ecore_Window)input->dev->window;
1253    ev->timestamp = libinput_event_touch_get_time(event);
1254    ev->same_screen = 1;
1255
1256    _device_modifiers_update(edev);
1257    ev->modifiers = edev->xkb.modifiers;
1258
1259    ev->x = edev->seat->ptr.ix;
1260    ev->y = edev->seat->ptr.iy;
1261    ev->root.x = ev->x;
1262    ev->root.y = ev->y;
1263
1264    ev->multi.device = edev->mt_slot;
1265    ev->multi.radius = 1;
1266    ev->multi.radius_x = 1;
1267    ev->multi.radius_y = 1;
1268    ev->multi.pressure = 1.0;
1269    ev->multi.angle = 0.0;
1270 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1271    if (libinput_event_touch_has_minor(event))
1272      ev->multi.radius_x = libinput_event_touch_get_minor(event);
1273    if (libinput_event_touch_has_major(event))
1274      ev->multi.radius_y = libinput_event_touch_get_major(event);
1275    if (libinput_event_touch_has_pressure(event))
1276      ev->multi.pressure = libinput_event_touch_get_pressure(event);
1277    if (libinput_event_touch_has_orientation(event))
1278      ev->multi.angle = libinput_event_touch_get_orientation(event);
1279 #endif
1280    ev->multi.x = ev->x;
1281    ev->multi.y = ev->y;
1282    ev->multi.root.x = ev->x;
1283    ev->multi.root.y = ev->y;
1284    ev->dev = ecore_device_ref(ecore_dev);
1285
1286    ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
1287 }
1288
1289 static void
1290 _device_handle_touch_cancel_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1291 {
1292    E_Input_Backend *input;
1293    Ecore_Event_Mouse_Button *ev;
1294    uint32_t timestamp, button = 0;
1295    Ecore_Device *ecore_dev = NULL, *data;
1296    Eina_List *l;
1297
1298    if (!edev) return;
1299    if (!(input = edev->seat->input)) return;
1300
1301    if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1302    else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1303      {
1304         EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1305           {
1306              if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1307                {
1308                   ecore_dev = data;
1309                   break;
1310                }
1311           }
1312      }
1313    else
1314      {
1315         edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1316         ecore_dev = edev->ecore_dev;
1317      }
1318
1319    if (!ecore_dev)
1320      {
1321         ERR("Failed to get source ecore device from event !\n");
1322         return;
1323      }
1324
1325    if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) return;
1326
1327    timestamp = libinput_event_touch_get_time(event);
1328
1329    ev->window = (Ecore_Window)input->dev->window;
1330    ev->event_window = (Ecore_Window)input->dev->window;
1331    ev->root_window = (Ecore_Window)input->dev->window;
1332    ev->timestamp = timestamp;
1333    ev->same_screen = 1;
1334
1335    ev->x = edev->seat->ptr.ix;
1336    ev->y = edev->seat->ptr.iy;
1337    ev->root.x = ev->x;
1338    ev->root.y = ev->y;
1339
1340    ev->multi.device = edev->mt_slot;
1341    ev->multi.radius = 1;
1342    ev->multi.radius_x = 1;
1343    ev->multi.radius_y = 1;
1344    ev->multi.pressure = 1.0;
1345    ev->multi.angle = 0.0;
1346    ev->multi.x = ev->x;
1347    ev->multi.y = ev->y;
1348    ev->multi.root.x = ev->x;
1349    ev->multi.root.y = ev->y;
1350    ev->dev = ecore_device_ref(ecore_dev);
1351
1352    edev->touch.pressed &= ~(1 << ev->multi.device);
1353
1354    ev->buttons = ((button & 0x00F) + 1);
1355
1356    ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev, _e_input_event_mouse_button_cb_free, NULL);
1357 }
1358
1359 static void
1360 _device_handle_touch_down(struct libinput_device *device, struct libinput_event_touch *event)
1361 {
1362    E_Input_Evdev *edev;
1363    int w = 0, h = 0;
1364    E_Comp_Config *comp_conf = NULL;
1365
1366    if (!(edev = libinput_device_get_user_data(device)))
1367      {
1368         return;
1369      }
1370
1371    e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
1372
1373    edev->mouse.dx = edev->seat->ptr.ix = edev->seat->ptr.dx =
1374      libinput_event_touch_get_x_transformed(event, w);
1375    edev->mouse.dy = edev->seat->ptr.iy = edev->seat->ptr.dy =
1376      libinput_event_touch_get_y_transformed(event, h);
1377
1378    edev->mt_slot = libinput_event_touch_get_slot(event);
1379    if (edev->mt_slot < 0)
1380      {
1381         /* FIXME: The single touch device return slot id -1
1382          *        But currently we have no API to distinguish multi touch or single touch
1383          *        After libinput 1.11 version, libinput provides get_touch_count API,
1384          *        so we can distinguish multi touch device or single touch device.
1385          */
1386         if (edev->mt_slot == -1)
1387           edev->mt_slot = 0;
1388         else
1389           {
1390              WRN("%d slot touch down events are not supported\n", edev->mt_slot);
1391              return;
1392           }
1393      }
1394
1395    if (edev->mt_slot < e_input_touch_max_count_get())
1396      {
1397         edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
1398         edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
1399      }
1400
1401    comp_conf = e_comp_config_get();
1402    if (comp_conf && comp_conf->input_log_enable)
1403      ELOGF("Touch", "Down (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
1404
1405    edev->touch.raw_pressed |= (1 << edev->mt_slot);
1406
1407    if (edev->touch.blocked)
1408      {
1409         ELOGF("Touch", "Down (id: %d, x: %d, y: %d) is blocked by %p, server: 0x%x", NULL,
1410               edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, edev->seat->dev->blocked_client,
1411               edev->seat->dev->server_blocked);
1412         return;
1413      }
1414
1415    _device_handle_touch_motion_send(edev, event);
1416    _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_DOWN);
1417 }
1418
1419 static void
1420 _device_handle_touch_motion(struct libinput_device *device, struct libinput_event_touch *event)
1421 {
1422    E_Input_Evdev *edev;
1423    int w = 0, h = 0;
1424
1425    if (!(edev = libinput_device_get_user_data(device)))
1426      {
1427         return;
1428      }
1429
1430    e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
1431
1432    edev->mouse.dx = edev->seat->ptr.dx =
1433      libinput_event_touch_get_x_transformed(event, w);
1434    edev->mouse.dy = edev->seat->ptr.dy =
1435      libinput_event_touch_get_y_transformed(event, h);
1436
1437    if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
1438        floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
1439      {
1440         return;
1441      }
1442
1443    edev->seat->ptr.ix = edev->seat->ptr.dx;
1444    edev->seat->ptr.iy = edev->seat->ptr.dy;
1445
1446    edev->mt_slot = libinput_event_touch_get_slot(event);
1447    if (edev->mt_slot < 0)
1448      {
1449         /* FIXME: The single touch device return slot id -1
1450          *        But currently we have no API to distinguish multi touch or single touch
1451          *        After libinput 1.11 version, libinput provides get_touch_count API,
1452          *        so we can distinguish multi touch device or single touch device.
1453          */
1454         if (edev->mt_slot == -1)
1455           edev->mt_slot = 0;
1456         else
1457           {
1458              WRN("%d slot touch motion events are not supported\n", edev->mt_slot);
1459              return;
1460           }
1461      }
1462
1463    if (edev->mt_slot < e_input_touch_max_count_get())
1464      {
1465         edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
1466         edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
1467      }
1468
1469    if (!(edev->touch.pressed & (1 << edev->mt_slot)))
1470      {
1471         if (edev->touch.blocked)
1472           {
1473              return;
1474           }
1475      }
1476
1477    _device_handle_touch_motion_send(edev, event);
1478 }
1479
1480 static void
1481 _device_handle_touch_up(struct libinput_device *device, struct libinput_event_touch *event)
1482 {
1483    E_Input_Evdev *edev;
1484    E_Comp_Config *comp_conf = NULL;
1485
1486    if (!(edev = libinput_device_get_user_data(device)))
1487      {
1488         return;
1489      }
1490
1491    edev->mt_slot = libinput_event_touch_get_slot(event);
1492    if (edev->mt_slot < 0)
1493      {
1494         /* FIXME: The single touch device return slot id -1
1495          *        But currently we have no API to distinguish multi touch or single touch
1496          *        After libinput 1.11 version, libinput provides get_touch_count API,
1497          *        so we can distinguish multi touch device or single touch device.
1498          */
1499         if (edev->mt_slot == -1)
1500           edev->mt_slot = 0;
1501         else
1502           {
1503              WRN("%d slot touch up events are not supported\n", edev->mt_slot);
1504              return;
1505           }
1506      }
1507
1508    if (edev->mt_slot < e_input_touch_max_count_get())
1509      {
1510         edev->mouse.dx = edev->seat->ptr.dx = edev->seat->ptr.ix =
1511           edev->touch.coords[edev->mt_slot].x;
1512         edev->mouse.dy = edev->seat->ptr.dy = edev->seat->ptr.iy =
1513           edev->touch.coords[edev->mt_slot].y;
1514      }
1515
1516    comp_conf = e_comp_config_get();
1517    if (comp_conf && comp_conf->input_log_enable)
1518      ELOGF("Touch", "Up (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
1519
1520    edev->touch.raw_pressed &= ~(1 << edev->mt_slot);
1521
1522    if (edev->touch.blocked)
1523      {
1524         if (!(edev->touch.pressed & (1 << edev->mt_slot)))
1525           {
1526              ELOGF("Touch", "Up (id: %d, x: %d, y: %d) is blocked by %p, server(0x%x)", NULL,
1527                    edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, edev->seat->dev->blocked_client,
1528                    edev->seat->dev->server_blocked);
1529              if (edev->touch.raw_pressed == 0x0)
1530                {
1531                   edev->touch.blocked = EINA_FALSE;
1532                }
1533              return;
1534           }
1535      }
1536
1537    _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_UP);
1538 }
1539
1540 static void
1541 _device_handle_touch_cancel(struct libinput_device *device, struct libinput_event_touch *event)
1542 {
1543    E_Input_Evdev *edev;
1544    E_Comp_Config *comp_conf = NULL;
1545
1546    if (!(edev = libinput_device_get_user_data(device)))
1547      {
1548         return;
1549      }
1550
1551    edev->mt_slot = libinput_event_touch_get_slot(event);
1552    if (edev->mt_slot < 0)
1553      {
1554         /* FIXME: The single touch device return slot id -1
1555          *        But currently we have no API to distinguish multi touch or single touch
1556          *        After libinput 1.11 version, libinput provides get_touch_count API,
1557          *        so we can distinguish multi touch device or single touch device.
1558          */
1559         if (edev->mt_slot == -1)
1560           edev->mt_slot = 0;
1561         else
1562           {
1563              WRN("%d slot touch up events are not supported\n", edev->mt_slot);
1564              return;
1565           }
1566      }
1567
1568    comp_conf = e_comp_config_get();
1569    if (comp_conf && comp_conf->input_log_enable)
1570      ELOGF("Touch", "cancel (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
1571
1572    _device_handle_touch_cancel_send(edev, event);
1573 }
1574
1575
1576 static void
1577 _device_handle_touch_frame(struct libinput_device *device EINA_UNUSED, struct libinput_event_touch *event EINA_UNUSED)
1578 {
1579    /* DBG("Unhandled Touch Frame Event"); */
1580 }
1581
1582 static void
1583 _e_input_aux_data_event_free(void *user_data EINA_UNUSED, void *ev)
1584 {
1585    Ecore_Event_Axis_Update *e = (Ecore_Event_Axis_Update *)ev;
1586
1587    if (e->axis) free(e->axis);
1588    if (e->dev) ecore_device_unref(e->dev);
1589
1590    free(e);
1591 }
1592
1593 static void
1594 _device_handle_touch_aux_data(struct libinput_device *device, struct libinput_event_touch_aux_data *event)
1595 {
1596    E_Input_Evdev *edev;
1597    E_Input_Backend *input;
1598    Ecore_Event_Axis_Update *ev;
1599    Ecore_Axis *axis;
1600    Ecore_Device *ecore_dev = NULL, *data;
1601    Eina_List *l;
1602    E_Comp_Config *comp_conf;
1603
1604    if (libinput_event_touch_aux_data_get_type(event) != LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM &&
1605        libinput_event_touch_aux_data_get_value(event) > 0)
1606       goto end;
1607
1608    if (!(edev = libinput_device_get_user_data(device))) goto end;
1609    if (!(input = edev->seat->input)) goto end;
1610
1611    if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1612    else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1613      {
1614         EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1615           {
1616              if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1617                {
1618                   ecore_dev = data;
1619                   break;
1620                }
1621           }
1622      }
1623    else
1624      {
1625         edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1626         ecore_dev = edev->ecore_dev;
1627      }
1628
1629    if (!ecore_dev)
1630      {
1631         ERR("Failed to get source ecore device from event !\n");
1632         goto end;
1633      }
1634
1635    if (!(ev = calloc(1, sizeof(Ecore_Event_Axis_Update))))goto end;
1636
1637    ev->window = (Ecore_Window)input->dev->window;
1638    ev->event_window = (Ecore_Window)input->dev->window;
1639    ev->root_window = (Ecore_Window)input->dev->window;
1640    ev->timestamp = libinput_event_touch_aux_data_get_time(event);
1641
1642    axis = (Ecore_Axis *)calloc(1, sizeof(Ecore_Axis));
1643    if (axis)
1644      {
1645         axis->label = ECORE_AXIS_LABEL_TOUCH_PALM;
1646         axis->value = libinput_event_touch_aux_data_get_value(event);
1647         ev->naxis = 1;
1648      }
1649    ev->axis = axis;
1650    ev->dev = ecore_device_ref(ecore_dev);
1651
1652    comp_conf = e_comp_config_get();
1653    if (comp_conf && comp_conf->input_log_enable)
1654      ELOGF("Touch", "Axis (label: %d, value: %lf)", NULL, axis?axis->label:-1, axis?axis->value:0.0);
1655
1656    ecore_event_add(ECORE_EVENT_AXIS_UPDATE, ev, _e_input_aux_data_event_free, NULL);
1657
1658 end:
1659    ;
1660 }
1661
1662 E_Input_Evdev *
1663 _e_input_evdev_device_create(E_Input_Seat *seat, struct libinput_device *device)
1664 {
1665    E_Input_Evdev *edev;
1666    E_Input_Backend *b_input;
1667
1668    EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
1669
1670    /* try to allocate space for new evdev */
1671    if (!(edev = calloc(1, sizeof(E_Input_Evdev)))) return NULL;
1672
1673    edev->seat = seat;
1674    edev->device = device;
1675    edev->path = eina_stringshare_printf("%s/%s", e_input_base_dir_get(), libinput_device_get_sysname(device));
1676
1677    if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
1678      {
1679         edev->caps |= E_INPUT_SEAT_KEYBOARD;
1680         _device_keyboard_setup(edev);
1681      }
1682
1683    if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
1684      {
1685         edev->caps |= E_INPUT_SEAT_POINTER;
1686
1687         /* TODO: make this configurable */
1688         edev->mouse.threshold = 250;
1689
1690         b_input = seat->input;
1691         if (b_input->left_handed == EINA_TRUE)
1692           {
1693              if (libinput_device_config_left_handed_set(device, 1) !=
1694                  LIBINPUT_CONFIG_STATUS_SUCCESS)
1695                {
1696                   WRN("Failed to set left hand mode about device: %s\n",
1697                       libinput_device_get_name(device));
1698                }
1699           }
1700      }
1701
1702    if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
1703      {
1704         int palm_code;
1705         edev->caps |= E_INPUT_SEAT_TOUCH;
1706         palm_code = libinput_device_touch_aux_data_get_code(LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM);
1707         if (libinput_device_touch_has_aux_data(device, palm_code))
1708           {
1709              libinput_device_touch_set_aux_data(device, palm_code);
1710           }
1711
1712         _device_touch_count_update(edev);
1713
1714         edev->touch.coords = calloc(1, sizeof(E_Input_Coord)*e_input_touch_max_count_get());
1715
1716         if  (!edev->touch.coords)
1717           ERR("Failed to allocate memory for touch coords !\n");
1718      }
1719
1720    libinput_device_set_user_data(device, edev);
1721    libinput_device_ref(device);
1722
1723    /* configure device */
1724    _device_configure(edev);
1725
1726    return edev;
1727 }
1728
1729 void
1730 _e_input_evdev_device_destroy(E_Input_Evdev *edev)
1731 {
1732    Ecore_Device *dev;
1733
1734    EINA_SAFETY_ON_NULL_RETURN(edev);
1735
1736    if (edev->caps & E_INPUT_SEAT_KEYBOARD)
1737      {
1738         if (edev->xkb.state) xkb_state_unref(edev->xkb.state);
1739         if (edev->xkb.keymap) xkb_map_unref(edev->xkb.keymap);
1740      }
1741
1742    if (edev->ecore_dev) ecore_device_del(edev->ecore_dev);
1743    if (edev->ecore_dev_list)
1744      EINA_LIST_FREE(edev->ecore_dev_list, dev)
1745        {
1746           ecore_device_del(dev);
1747        }
1748    if (edev->path) eina_stringshare_del(edev->path);
1749    if (edev->device) libinput_device_unref(edev->device);
1750    if (edev->key_remap_hash) eina_hash_free(edev->key_remap_hash);
1751    if (edev->touch.coords)
1752      {
1753         free(edev->touch.coords);
1754         edev->touch.coords = NULL;
1755      }
1756
1757    free(edev);
1758 }
1759
1760 Eina_Bool
1761 _e_input_evdev_event_process(struct libinput_event *event)
1762 {
1763    struct libinput_device *device;
1764    Eina_Bool ret = EINA_TRUE;
1765
1766    device = libinput_event_get_device(event);
1767    switch (libinput_event_get_type(event))
1768      {
1769       case LIBINPUT_EVENT_KEYBOARD_KEY:
1770         _device_handle_key(device, libinput_event_get_keyboard_event(event));
1771         break;
1772       case LIBINPUT_EVENT_POINTER_MOTION:
1773         _device_handle_pointer_motion(device,
1774                                       libinput_event_get_pointer_event(event));
1775         break;
1776       case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
1777         _device_handle_pointer_motion_absolute(device,
1778                                                libinput_event_get_pointer_event(event));
1779         break;
1780       case LIBINPUT_EVENT_POINTER_BUTTON:
1781         _device_handle_button(device, libinput_event_get_pointer_event(event));
1782         break;
1783       case LIBINPUT_EVENT_POINTER_AXIS:
1784         _device_handle_axis(device, libinput_event_get_pointer_event(event));
1785         break;
1786       case LIBINPUT_EVENT_TOUCH_DOWN:
1787         _device_handle_touch_down(device, libinput_event_get_touch_event(event));
1788         break;
1789       case LIBINPUT_EVENT_TOUCH_MOTION:
1790         _device_handle_touch_motion(device,
1791                                     libinput_event_get_touch_event(event));
1792         break;
1793       case LIBINPUT_EVENT_TOUCH_UP:
1794         _device_handle_touch_up(device, libinput_event_get_touch_event(event));
1795         break;
1796       case LIBINPUT_EVENT_TOUCH_CANCEL:
1797         _device_handle_touch_cancel(device, libinput_event_get_touch_event(event));
1798         break;
1799       case LIBINPUT_EVENT_TOUCH_FRAME:
1800         _device_handle_touch_frame(device, libinput_event_get_touch_event(event));
1801         break;
1802       case LIBINPUT_EVENT_TOUCH_AUX_DATA:
1803         _device_handle_touch_aux_data(device, libinput_event_get_touch_aux_data(event));
1804         break;
1805       default:
1806         ret = EINA_FALSE;
1807         break;
1808      }
1809
1810    return ret;
1811 }
1812
1813 /**
1814  * @brief Set the axis size of the given device.
1815  *
1816  * @param dev The device to set the axis size to.
1817  * @param w The width of the axis.
1818  * @param h The height of the axis.
1819  *
1820  * This function sets set the width @p w and height @p h of the axis
1821  * of device @p dev. If @p dev is a relative input device, a width and
1822  * height must set for it. If its absolute set the ioctl correctly, if
1823  * not, unsupported device.
1824  */
1825 EINTERN void
1826 e_input_evdev_axis_size_set(E_Input_Evdev *edev, int w, int h)
1827 {
1828    const char *sysname;
1829    float cal[6];
1830    const char *device;
1831    Eina_List *devices;
1832    const char *vals;
1833    enum libinput_config_status status;
1834
1835    EINA_SAFETY_ON_NULL_RETURN(edev);
1836    EINA_SAFETY_ON_TRUE_RETURN((w == 0) || (h == 0));
1837
1838    if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
1839        (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
1840      return;
1841
1842    sysname = libinput_device_get_sysname(edev->device);
1843
1844    devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
1845    if (eina_list_count(devices) < 1) return;
1846
1847    EINA_LIST_FREE(devices, device)
1848      {
1849         vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
1850         if ((!vals) ||
1851             (sscanf(vals, "%f %f %f %f %f %f",
1852                     &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
1853           goto cont;
1854
1855         cal[2] /= w;
1856         cal[5] /= h;
1857
1858         status =
1859           libinput_device_config_calibration_set_matrix(edev->device, cal);
1860
1861         if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
1862           ERR("Failed to apply calibration");
1863
1864 cont:
1865         eina_stringshare_del(device);
1866         continue;
1867      }
1868 }
1869
1870 E_API const char *
1871 e_input_evdev_name_get(E_Input_Evdev *evdev)
1872 {
1873    EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
1874    EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
1875
1876    return libinput_device_get_name(evdev->device);
1877 }
1878
1879 EINTERN const char *
1880 e_input_evdev_sysname_get(E_Input_Evdev *evdev)
1881 {
1882    EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
1883    EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
1884
1885    return libinput_device_get_sysname(evdev->device);
1886 }
1887
1888 EINTERN Eina_Bool
1889 e_input_evdev_key_remap_enable(E_Input_Evdev *edev, Eina_Bool enable)
1890 {
1891    EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
1892    EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
1893
1894    edev->key_remap_enabled = enable;
1895
1896    if (enable == EINA_FALSE && edev->key_remap_hash)
1897      {
1898         eina_hash_free(edev->key_remap_hash);
1899         edev->key_remap_hash = NULL;
1900      }
1901
1902    return EINA_TRUE;
1903 }
1904
1905 EINTERN Eina_Bool
1906 e_input_evdev_key_remap_set(E_Input_Evdev *edev, int *from_keys, int *to_keys, int num)
1907 {
1908    int i;
1909
1910    EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
1911    EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
1912    EINA_SAFETY_ON_NULL_RETURN_VAL(from_keys, EINA_FALSE);
1913    EINA_SAFETY_ON_NULL_RETURN_VAL(to_keys, EINA_FALSE);
1914    EINA_SAFETY_ON_TRUE_RETURN_VAL(num <= 0, EINA_FALSE);
1915    EINA_SAFETY_ON_TRUE_RETURN_VAL(!edev->key_remap_enabled, EINA_FALSE);
1916
1917    if (edev->key_remap_hash == NULL)
1918      edev->key_remap_hash = eina_hash_int32_new(NULL);
1919
1920    if (edev->key_remap_hash == NULL)
1921      {
1922         ERR("Failed to set remap key information : creating a hash is failed.");
1923         return EINA_FALSE;
1924      }
1925
1926    for (i = 0; i < num ; i++)
1927      {
1928         if (!from_keys[i] || !to_keys[i])
1929           {
1930              ERR("Failed to set remap key information : given arguments are invalid.");
1931              return EINA_FALSE;
1932           }
1933      }
1934
1935    for (i = 0; i < num ; i++)
1936      {
1937         eina_hash_add(edev->key_remap_hash, &from_keys[i], (void *)(intptr_t)to_keys[i]);
1938      }
1939
1940    return EINA_TRUE;
1941 }
1942
1943 E_API int
1944 e_input_evdev_wheel_click_angle_get(E_Input_Evdev *dev)
1945 {
1946    EINA_SAFETY_ON_NULL_RETURN_VAL(dev, -1);
1947    return libinput_device_config_scroll_get_wheel_click_angle(dev->device);
1948 }
1949
1950 EINTERN Eina_Bool
1951 e_input_evdev_touch_calibration_set(E_Input_Evdev *edev, float matrix[6])
1952 {
1953    EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
1954    EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
1955
1956    if (!libinput_device_config_calibration_has_matrix(edev->device) ||
1957        !libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_TOUCH))
1958      return EINA_FALSE;
1959
1960    if (libinput_device_config_calibration_set_matrix(edev->device, matrix) !=
1961        LIBINPUT_CONFIG_STATUS_SUCCESS)
1962      {
1963         WRN("Failed to set input transformation about device: %s\n",
1964             libinput_device_get_name(edev->device));
1965         return EINA_FALSE;
1966      }
1967
1968    return EINA_TRUE;
1969 }
1970
1971 EINTERN Eina_Bool
1972 e_input_evdev_mouse_accel_speed_set(E_Input_Evdev *edev, double speed)
1973 {
1974    EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
1975    EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
1976
1977    if (!libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
1978      return EINA_FALSE;
1979
1980    if (!libinput_device_config_accel_is_available(edev->device))
1981      return EINA_FALSE;
1982
1983    if (libinput_device_config_accel_set_speed(edev->device, speed) !=
1984        LIBINPUT_CONFIG_STATUS_SUCCESS)
1985      {
1986         WRN("Failed to set mouse accel about device: %s\n",
1987             libinput_device_get_name(edev->device));
1988         return EINA_FALSE;
1989      }
1990
1991    return EINA_TRUE;
1992 }
1993
1994 EINTERN unsigned int
1995 e_input_evdev_touch_pressed_get(E_Input_Evdev *edev)
1996 {
1997    EINA_SAFETY_ON_NULL_RETURN_VAL(edev, 0x0);
1998
1999    return edev->touch.pressed;
2000 }