e_input: fixed a build error
[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_configure(E_Input_Evdev *edev)
92 {
93    if (libinput_device_config_tap_get_finger_count(edev->device) > 0)
94      {
95         Eina_Bool tap = EINA_FALSE;
96
97         tap = libinput_device_config_tap_get_default_enabled(edev->device);
98         libinput_device_config_tap_set_enabled(edev->device, tap);
99      }
100
101    _device_calibration_set(edev);
102 }
103
104 static void
105 _device_keyboard_setup(E_Input_Evdev *edev)
106 {
107    E_Input_Backend *input;
108    xkb_mod_index_t xkb_idx;
109
110    if ((!edev) || (!edev->seat)) return;
111    if (!(input = edev->seat->input)) return;
112    if (!input->dev->xkb_ctx) return;
113
114    /* create keymap from xkb context */
115    edev->xkb.keymap = _e_input_device_cached_keymap_get(input->dev->xkb_ctx, NULL, 0);
116    if (!edev->xkb.keymap)
117      {
118         ERR("Failed to create keymap: %m");
119         return;
120      }
121
122    /* create xkb state */
123    if (!(edev->xkb.state = xkb_state_new(edev->xkb.keymap)))
124      {
125         ERR("Failed to create xkb state: %m");
126         return;
127      }
128
129    xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CTRL);
130    if (xkb_idx != XKB_MOD_INVALID)
131      edev->xkb.ctrl_mask = 1 << xkb_idx;
132    else
133      edev->xkb.ctrl_mask = 0;
134
135    xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_ALT);
136    if (xkb_idx != XKB_MOD_INVALID)
137      edev->xkb.alt_mask = 1 << xkb_idx;
138    else
139      edev->xkb.alt_mask = 0;
140
141    xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_SHIFT);
142    if (xkb_idx != XKB_MOD_INVALID)
143      edev->xkb.shift_mask = 1 << xkb_idx;
144    else
145      edev->xkb.shift_mask = 0;
146
147    xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_LOGO);
148    if (xkb_idx != XKB_MOD_INVALID)
149      edev->xkb.win_mask = 1 << xkb_idx;
150    else
151      edev->xkb.win_mask = 0;
152
153    xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_SCROLL);
154    if (xkb_idx != XKB_MOD_INVALID)
155      edev->xkb.scroll_mask = 1 << xkb_idx;
156    else
157      edev->xkb.scroll_mask = 0;
158
159    xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_NUM);
160    if (xkb_idx != XKB_MOD_INVALID)
161      edev->xkb.num_mask = 1 << xkb_idx;
162    else
163      edev->xkb.num_mask = 0;
164
165    xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CAPS);
166    if (xkb_idx != XKB_MOD_INVALID)
167      edev->xkb.caps_mask = 1 << xkb_idx;
168    else
169      edev->xkb.caps_mask = 0;
170
171    xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, "ISO_Level3_Shift");
172    if (xkb_idx != XKB_MOD_INVALID)
173      edev->xkb.altgr_mask = 1 << xkb_idx;
174    else
175      edev->xkb.altgr_mask = 0;
176 }
177
178 static int
179 _device_keysym_translate(xkb_keysym_t keysym, unsigned int modifiers, char *buffer, int bytes)
180 {
181    unsigned long hbytes = 0;
182    unsigned char c;
183
184    if (!keysym) return 0;
185    hbytes = (keysym >> 8);
186
187    if (!(bytes &&
188          ((hbytes == 0) ||
189           ((hbytes == 0xFF) &&
190            (((keysym >= XKB_KEY_BackSpace) && (keysym <= XKB_KEY_Clear)) ||
191             (keysym == XKB_KEY_Return) || (keysym == XKB_KEY_Escape) ||
192             (keysym == XKB_KEY_KP_Space) || (keysym == XKB_KEY_KP_Tab) ||
193             (keysym == XKB_KEY_KP_Enter) ||
194             ((keysym >= XKB_KEY_KP_Multiply) && (keysym <= XKB_KEY_KP_9)) ||
195             (keysym == XKB_KEY_KP_Equal) || (keysym == XKB_KEY_Delete))))))
196      return 0;
197
198    if (keysym == XKB_KEY_KP_Space)
199      c = (XKB_KEY_space & 0x7F);
200    else if (hbytes == 0xFF)
201      c = (keysym & 0x7F);
202    else
203      c = (keysym & 0xFF);
204
205    if (modifiers & ECORE_EVENT_MODIFIER_CTRL)
206      {
207         if (((c >= '@') && (c < '\177')) || c == ' ')
208           c &= 0x1F;
209         else if (c == '2')
210           c = '\000';
211         else if ((c >= '3') && (c <= '7'))
212           c -= ('3' - '\033');
213         else if (c == '8')
214           c = '\177';
215         else if (c == '/')
216           c = '_' & 0x1F;
217      }
218    buffer[0] = c;
219    return 1;
220 }
221
222 static void
223 _device_modifiers_update_device(E_Input_Evdev *edev, E_Input_Evdev *from)
224 {
225    xkb_mod_mask_t mask;
226
227    edev->xkb.depressed =
228      xkb_state_serialize_mods(from->xkb.state, XKB_STATE_DEPRESSED);
229    edev->xkb.latched =
230      xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LATCHED);
231    edev->xkb.locked =
232      xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LOCKED);
233    edev->xkb.group =
234      xkb_state_serialize_mods(from->xkb.state, XKB_STATE_EFFECTIVE);
235
236    mask = (edev->xkb.depressed | edev->xkb.latched);
237
238    if (mask & from->xkb.ctrl_mask)
239      edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_CTRL;
240    if (mask & from->xkb.alt_mask)
241      edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALT;
242    if (mask & from->xkb.shift_mask)
243      edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
244    if (mask & from->xkb.win_mask)
245      edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_WIN;
246    if (mask & from->xkb.scroll_mask)
247      edev->xkb.modifiers |= ECORE_EVENT_LOCK_SCROLL;
248    if (mask & from->xkb.num_mask)
249      edev->xkb.modifiers |= ECORE_EVENT_LOCK_NUM;
250    if (mask & from->xkb.caps_mask)
251      edev->xkb.modifiers |= ECORE_EVENT_LOCK_CAPS;
252    if (mask & from->xkb.altgr_mask)
253      edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALTGR;
254 }
255
256 static void
257 _device_modifiers_update(E_Input_Evdev *edev)
258 {
259    Eina_List *l;
260    E_Input_Evdev *ed;
261
262    edev->xkb.modifiers = 0;
263
264    if (edev->caps & E_INPUT_SEAT_KEYBOARD)
265      _device_modifiers_update_device(edev, edev);
266    else
267      {
268         EINA_LIST_FOREACH(edev->seat->devices, l, ed)
269           {
270              if (!(ed->caps & E_INPUT_SEAT_KEYBOARD)) continue;
271              _device_modifiers_update_device(edev, ed);
272           }
273      }
274
275 }
276
277 static int
278 _device_remapped_key_get(E_Input_Evdev *edev, int code)
279 {
280    void *ret = NULL;
281
282    EINA_SAFETY_ON_NULL_RETURN_VAL(edev, code);
283    if (!edev->key_remap_enabled) return code;
284    EINA_SAFETY_ON_NULL_RETURN_VAL(edev->key_remap_hash, code);
285
286    ret = eina_hash_find(edev->key_remap_hash, &code);
287
288    if (ret) code = (int)(intptr_t)ret;
289
290    return code;
291 }
292
293 E_API Evas_Device *
294 e_input_evdev_get_evas_device(const char *path, Evas_Device_Class clas)
295 {
296    const Eina_List *dev_list = NULL;
297    const Eina_List *l;
298    Evas_Device *dev = NULL;
299    const char *identifier;
300
301    if (!path) return NULL;
302
303    dev_list = evas_device_list();
304    if (!dev_list) return NULL;
305    EINA_LIST_FOREACH(dev_list, l, dev)
306      {
307         if (!dev) continue;
308         identifier = evas_device_description_get(dev);
309         if (!identifier) continue;
310         if ((evas_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
311           return dev;
312      }
313    return NULL;
314 }
315
316 static void
317 _device_handle_key(struct libinput_device *device, struct libinput_event_keyboard *event)
318 {
319    E_Input_Evdev *edev;
320    E_Input_Backend *input;
321    uint32_t timestamp;
322    uint32_t code, nsyms;
323    const xkb_keysym_t *syms;
324    enum libinput_key_state state;
325    int key_count;
326    xkb_keysym_t sym = XKB_KEY_NoSymbol;
327    char key[256], keyname[256], compose_buffer[256];
328    Ecore_Event_Key *e;
329    char *tmp = NULL, *compose = NULL;
330
331    if (!(edev = libinput_device_get_user_data(device)))
332      {
333         return;
334      }
335
336    if (!(input = edev->seat->input))
337      {
338         return;
339      }
340
341    if (!edev->evas_dev)
342      edev->evas_dev = e_input_evdev_get_evas_device(edev->path, EVAS_DEVICE_CLASS_KEYBOARD);
343
344    if (!edev->evas_dev)
345      {
346         ERR("Failed to get source evas device from event !\n");
347         return;
348      }
349
350    timestamp = libinput_event_keyboard_get_time(event);
351    code = libinput_event_keyboard_get_key(event);
352    code = _device_remapped_key_get(edev, code) + 8;
353    state = libinput_event_keyboard_get_key_state(event);
354    key_count = libinput_event_keyboard_get_seat_key_count(event);
355
356    /* ignore key events that are not seat wide state changes */
357    if (((state == LIBINPUT_KEY_STATE_PRESSED) && (key_count != 1)) ||
358        ((state == LIBINPUT_KEY_STATE_RELEASED) && (key_count != 0)))
359      {
360         return;
361      }
362
363    xkb_state_update_key(edev->xkb.state, code,
364                         (state ? XKB_KEY_DOWN : XKB_KEY_UP));
365
366    /* get the keysym for this code */
367    nsyms = xkb_key_get_syms(edev->xkb.state, code, &syms);
368    if (nsyms == 1) sym = syms[0];
369
370    /* get the keyname for this sym */
371    memset(key, 0, sizeof(key));
372    xkb_keysym_get_name(sym, key, sizeof(key));
373
374    memset(keyname, 0, sizeof(keyname));
375    memcpy(keyname, key, sizeof(keyname));
376
377    if (keyname[0] == '\0')
378      snprintf(keyname, sizeof(keyname), "Keycode-%u", code);
379
380    /* if shift is active, we need to transform the key to lower */
381    if (xkb_state_mod_index_is_active(edev->xkb.state,
382                                      xkb_map_mod_get_index(edev->xkb.keymap,
383                                      XKB_MOD_NAME_SHIFT),
384                                      XKB_STATE_MODS_EFFECTIVE))
385      {
386         if (keyname[0] != '\0')
387           keyname[0] = tolower(keyname[0]);
388      }
389
390    memset(compose_buffer, 0, sizeof(compose_buffer));
391    if (_device_keysym_translate(sym, edev->xkb.modifiers,
392                                 compose_buffer, sizeof(compose_buffer)))
393      {
394         compose = eina_str_convert("ISO8859-1", "UTF-8", compose_buffer);
395         if (!compose)
396           {
397              ERR("E Input cannot convert input key string '%s' to UTF-8. "
398                  "Is Eina built with iconv support?", compose_buffer);
399           }
400         else
401           tmp = compose;
402      }
403
404    if (!compose) compose = compose_buffer;
405
406    e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) +
407               ((compose[0] != '\0') ? strlen(compose) : 0) + 3);
408    if (!e)
409      {
410         E_FREE(tmp);
411         return;
412      }
413
414    e->keyname = (char *)(e + 1);
415    e->key = e->keyname + strlen(keyname) + 1;
416    e->compose = strlen(compose) ? e->key + strlen(key) + 1 : NULL;
417    e->string = e->compose;
418
419    strncpy((char *)e->keyname, keyname, strlen(keyname));
420    strncpy((char *)e->key, key, strlen(key));
421    if (strlen(compose)) strncpy((char *)e->compose, compose, strlen(compose));
422
423    e->window = (Ecore_Window)input->dev->window;
424    e->event_window = (Ecore_Window)input->dev->window;
425    e->root_window = (Ecore_Window)input->dev->window;
426    e->timestamp = timestamp;
427    e->same_screen = 1;
428    e->keycode = code;
429    e->data = NULL;
430
431    _device_modifiers_update(edev);
432
433    e->modifiers = edev->xkb.modifiers;
434    e->dev = edev->evas_dev;
435
436    if (state)
437      ecore_event_add(ECORE_EVENT_KEY_DOWN, e, NULL, NULL);
438    else
439      ecore_event_add(ECORE_EVENT_KEY_UP, e, NULL, NULL);
440
441    if (tmp) free(tmp);
442 }
443
444 static void
445 _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event)
446 {
447    E_Input_Backend *input;
448    Ecore_Event_Mouse_Move *ev;
449
450    if (!(input = edev->seat->input)) return;
451
452    if (!edev->evas_dev)
453      edev->evas_dev = e_input_evdev_get_evas_device(edev->path, EVAS_DEVICE_CLASS_MOUSE);
454
455    if (!edev->evas_dev)
456      {
457         ERR("Failed to get source evas device from event !\n");
458         return;
459      }
460
461    if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
462
463    if (edev->seat->ptr.ix < edev->mouse.minx)
464      edev->seat->ptr.dx = edev->seat->ptr.ix = edev->mouse.minx;
465    else if (edev->seat->ptr.ix >= (edev->mouse.minx + edev->mouse.maxw))
466      edev->seat->ptr.dx = edev->seat->ptr.ix = (edev->mouse.minx + edev->mouse.maxw - 1);
467
468    if (edev->seat->ptr.iy < edev->mouse.miny)
469      edev->seat->ptr.dy = edev->seat->ptr.iy = edev->mouse.miny;
470    else if (edev->seat->ptr.iy >= (edev->mouse.miny + edev->mouse.maxh))
471      edev->seat->ptr.dy = edev->seat->ptr.iy = (edev->mouse.miny + edev->mouse.maxh - 1);
472
473    edev->mouse.dx = edev->seat->ptr.dx;
474    edev->mouse.dy = edev->seat->ptr.dy;
475
476    ev->window = (Ecore_Window)input->dev->window;
477    ev->event_window = (Ecore_Window)input->dev->window;
478    ev->root_window = (Ecore_Window)input->dev->window;
479    if (event) ev->timestamp = libinput_event_pointer_get_time(event);
480    ev->same_screen = 1;
481
482    _device_modifiers_update(edev);
483    ev->modifiers = edev->xkb.modifiers;
484
485    ev->x = edev->seat->ptr.ix;
486    ev->y = edev->seat->ptr.iy;
487    ev->root.x = ev->x;
488    ev->root.y = ev->y;
489
490    ev->multi.device = edev->mt_slot;
491    ev->multi.radius = 1;
492    ev->multi.radius_x = 1;
493    ev->multi.radius_y = 1;
494    ev->multi.pressure = 1.0;
495    ev->multi.angle = 0.0;
496    ev->multi.x = ev->x;
497    ev->multi.y = ev->y;
498    ev->multi.root.x = ev->x;
499    ev->multi.root.y = ev->y;
500    ev->dev = edev->evas_dev;
501
502    ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL);
503 }
504
505 void
506 _e_input_pointer_motion_post(E_Input_Evdev *edev)
507 {
508    _device_pointer_motion(edev, NULL);
509 }
510
511 static void
512 _device_handle_pointer_motion(struct libinput_device *device, struct libinput_event_pointer *event)
513 {
514    E_Input_Evdev *edev;
515    double dx, dy, temp;
516
517    if (!(edev = libinput_device_get_user_data(device)))
518      {
519         return;
520      }
521
522    dx = libinput_event_pointer_get_dx(event);
523    dy = libinput_event_pointer_get_dy(event);
524
525    if (edev->seat->ptr.swap)
526      {
527          temp = dx;
528          dx = dy;
529          dy = temp;
530      }
531    if (edev->seat->ptr.invert_x)
532      dx *= -1;
533    if (edev->seat->ptr.invert_y)
534      dy *= -1;
535
536    edev->seat->ptr.dx += dx;
537    edev->seat->ptr.dy += dy;
538
539    edev->mouse.dx = edev->seat->ptr.dx;
540    edev->mouse.dy = edev->seat->ptr.dy;
541
542    if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
543        floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
544      {
545         return;
546      }
547
548    edev->seat->ptr.ix = edev->seat->ptr.dx;
549    edev->seat->ptr.iy = edev->seat->ptr.dy;
550
551   _device_pointer_motion(edev, event);
552 }
553
554 static void
555 _device_handle_pointer_motion_absolute(struct libinput_device *device, struct libinput_event_pointer *event)
556 {
557    E_Input_Evdev *edev;
558    int w = 0, h = 0;
559
560    if (!(edev = libinput_device_get_user_data(device)))
561      {
562         return;
563      }
564
565    e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
566
567    edev->mouse.dx = edev->seat->ptr.dx =
568      libinput_event_pointer_get_absolute_x_transformed(event, w);
569    edev->mouse.dy = edev->seat->ptr.dy =
570      libinput_event_pointer_get_absolute_y_transformed(event, h);
571
572    if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
573        floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
574      {
575         return;
576      }
577
578    edev->seat->ptr.ix = edev->seat->ptr.dx;
579    edev->seat->ptr.iy = edev->seat->ptr.dy;
580    _device_pointer_motion(edev, event);
581 }
582
583 static void
584 _device_handle_button(struct libinput_device *device, struct libinput_event_pointer *event)
585 {
586    E_Input_Evdev *edev;
587    E_Input_Backend *input;
588    Ecore_Event_Mouse_Button *ev;
589    enum libinput_button_state state;
590    uint32_t button, timestamp;
591
592    if (!(edev = libinput_device_get_user_data(device)))
593      {
594         return;
595      }
596    if (!(input = edev->seat->input))
597      {
598         return;
599      }
600
601    if (!edev->evas_dev)
602      edev->evas_dev = e_input_evdev_get_evas_device(edev->path, EVAS_DEVICE_CLASS_MOUSE);
603
604    if (!edev->evas_dev)
605      {
606         ERR("Failed to get source evas device from event !\n");
607         return;
608      }
609
610    if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button))))
611      {
612         return;
613      }
614
615    state = libinput_event_pointer_get_button_state(event);
616    button = libinput_event_pointer_get_button(event);
617    timestamp = libinput_event_pointer_get_time(event);
618
619    button = ((button & 0x00F) + 1);
620    if (button == 3) button = 2;
621    else if (button == 2) button = 3;
622
623    ev->window = (Ecore_Window)input->dev->window;
624    ev->event_window = (Ecore_Window)input->dev->window;
625    ev->root_window = (Ecore_Window)input->dev->window;
626    ev->timestamp = timestamp;
627    ev->same_screen = 1;
628
629    _device_modifiers_update(edev);
630    ev->modifiers = edev->xkb.modifiers;
631
632    ev->x = edev->seat->ptr.ix;
633    ev->y = edev->seat->ptr.iy;
634    ev->root.x = ev->x;
635    ev->root.y = ev->y;
636
637    ev->multi.device = edev->mt_slot;
638    ev->multi.radius = 1;
639    ev->multi.radius_x = 1;
640    ev->multi.radius_y = 1;
641    ev->multi.pressure = 1.0;
642    ev->multi.angle = 0.0;
643    ev->multi.x = ev->x;
644    ev->multi.y = ev->y;
645    ev->multi.root.x = ev->x;
646    ev->multi.root.y = ev->y;
647    ev->dev = edev->evas_dev;
648
649    if (state)
650      {
651         unsigned int current;
652
653         current = timestamp;
654         edev->mouse.did_double = EINA_FALSE;
655         edev->mouse.did_triple = EINA_FALSE;
656
657         if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
658             (button == edev->mouse.prev_button))
659           {
660              edev->mouse.did_double = EINA_TRUE;
661              if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
662                  (button == edev->mouse.last_button))
663                {
664                   edev->mouse.did_triple = EINA_TRUE;
665                   edev->mouse.prev = 0;
666                   edev->mouse.last = 0;
667                   current = 0;
668                }
669           }
670
671         edev->mouse.last = edev->mouse.prev;
672         edev->mouse.prev = current;
673         edev->mouse.last_button = edev->mouse.prev_button;
674         edev->mouse.prev_button = button;
675      }
676
677    ev->buttons = button;
678
679    if (edev->mouse.did_double)
680      ev->double_click = 1;
681    if (edev->mouse.did_triple)
682      ev->triple_click = 1;
683
684    if (state)
685      ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL);
686    else
687      ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL);
688 }
689
690 static void
691 _device_handle_axis(struct libinput_device *device, struct libinput_event_pointer *event)
692 {
693    E_Input_Evdev *edev;
694    E_Input_Backend *input;
695    Ecore_Event_Mouse_Wheel *ev;
696    uint32_t timestamp;
697    enum libinput_pointer_axis axis;
698
699    if (!(edev = libinput_device_get_user_data(device)))
700      {
701         return;
702      }
703    if (!(input = edev->seat->input))
704      {
705         return;
706      }
707
708    if (!edev->evas_dev)
709      edev->evas_dev = e_input_evdev_get_evas_device(edev->path, EVAS_DEVICE_CLASS_MOUSE);
710
711    if (!edev->evas_dev)
712      {
713         ERR("Failed to get source evas device from event !\n");
714         return;
715      }
716
717    if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
718      {
719         return;
720      }
721
722    timestamp = libinput_event_pointer_get_time(event);
723
724    ev->window = (Ecore_Window)input->dev->window;
725    ev->event_window = (Ecore_Window)input->dev->window;
726    ev->root_window = (Ecore_Window)input->dev->window;
727    ev->timestamp = timestamp;
728    ev->same_screen = 1;
729
730    _device_modifiers_update(edev);
731    ev->modifiers = edev->xkb.modifiers;
732
733    ev->x = edev->seat->ptr.ix;
734    ev->y = edev->seat->ptr.iy;
735    ev->root.x = ev->x;
736    ev->root.y = ev->y;
737    ev->dev = edev->evas_dev;
738
739    axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
740    if (libinput_event_pointer_has_axis(event, axis))
741      ev->z = libinput_event_pointer_get_axis_value(event, axis);
742
743    axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
744    if (libinput_event_pointer_has_axis(event, axis))
745      {
746         ev->direction = 1;
747         ev->z = libinput_event_pointer_get_axis_value(event, axis);
748      }
749
750    ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, NULL, NULL);
751 }
752
753 static void
754 _device_handle_touch_event_send(E_Input_Evdev *edev, struct libinput_event_touch *event, int state)
755 {
756    E_Input_Backend *input;
757    Ecore_Event_Mouse_Button *ev;
758    uint32_t timestamp, button = 0;
759
760    if (!edev) return;
761    if (!(input = edev->seat->input)) return;
762
763    if (!edev->evas_dev)
764      edev->evas_dev = e_input_evdev_get_evas_device(edev->path, EVAS_DEVICE_CLASS_TOUCH);
765
766    if (!edev->evas_dev)
767      {
768         ERR("Failed to get source evas device from event !\n");
769         return;
770      }
771
772    if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) return;
773
774    timestamp = libinput_event_touch_get_time(event);
775
776    ev->window = (Ecore_Window)input->dev->window;
777    ev->event_window = (Ecore_Window)input->dev->window;
778    ev->root_window = (Ecore_Window)input->dev->window;
779    ev->timestamp = timestamp;
780    ev->same_screen = 1;
781
782    _device_modifiers_update(edev);
783    ev->modifiers = edev->xkb.modifiers;
784
785    ev->x = edev->seat->ptr.ix;
786    ev->y = edev->seat->ptr.iy;
787    ev->root.x = ev->x;
788    ev->root.y = ev->y;
789
790    ev->multi.device = edev->mt_slot;
791    ev->multi.radius = 1;
792    ev->multi.radius_x = 1;
793    ev->multi.radius_y = 1;
794    ev->multi.pressure = 1.0;
795    ev->multi.angle = 0.0;
796 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
797    if (libinput_event_get_type(libinput_event_touch_get_base_event(event))
798        == LIBINPUT_EVENT_TOUCH_DOWN)
799      {
800         if (libinput_event_touch_has_minor(event))
801           ev->multi.radius_x = libinput_event_touch_get_minor(event);
802         if (libinput_event_touch_has_major(event))
803           ev->multi.radius_y = libinput_event_touch_get_major(event);
804         if (libinput_event_touch_has_pressure(event))
805           ev->multi.pressure = libinput_event_touch_get_pressure(event);
806         if (libinput_event_touch_has_orientation(event))
807           ev->multi.angle = libinput_event_touch_get_orientation(event);
808      }
809 #endif
810    ev->multi.x = ev->x;
811    ev->multi.y = ev->y;
812    ev->multi.root.x = ev->x;
813    ev->multi.root.y = ev->y;
814    ev->dev = edev->evas_dev;
815
816    if (state == ECORE_EVENT_MOUSE_BUTTON_DOWN)
817      {
818         unsigned int current;
819
820         current = timestamp;
821         edev->mouse.did_double = EINA_FALSE;
822         edev->mouse.did_triple = EINA_FALSE;
823
824         if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
825             (button == edev->mouse.prev_button))
826           {
827              edev->mouse.did_double = EINA_TRUE;
828              if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
829                  (button == edev->mouse.last_button))
830                {
831                   edev->mouse.did_triple = EINA_TRUE;
832                   edev->mouse.prev = 0;
833                   edev->mouse.last = 0;
834                   current = 0;
835                }
836           }
837
838         edev->mouse.last = edev->mouse.prev;
839         edev->mouse.prev = current;
840         edev->mouse.last_button = edev->mouse.prev_button;
841         edev->mouse.prev_button = button;
842      }
843
844    ev->buttons = ((button & 0x00F) + 1);
845
846    if (edev->mouse.did_double)
847      ev->double_click = 1;
848    if (edev->mouse.did_triple)
849      ev->triple_click = 1;
850
851    ecore_event_add(state, ev, NULL, NULL);
852 }
853
854 static void
855 _device_handle_touch_motion_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
856 {
857    E_Input_Backend *input;
858    Ecore_Event_Mouse_Move *ev;
859
860    if (!edev) return;
861    if (!(input = edev->seat->input)) return;
862
863    if (!edev->evas_dev)
864      edev->evas_dev = e_input_evdev_get_evas_device(edev->path, EVAS_DEVICE_CLASS_TOUCH);
865
866    if (!edev->evas_dev)
867      {
868         ERR("Failed to get source evas device from event !\n");
869         return;
870      }
871
872    if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
873
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    ev->timestamp = libinput_event_touch_get_time(event);
878    ev->same_screen = 1;
879
880    _device_modifiers_update(edev);
881    ev->modifiers = edev->xkb.modifiers;
882
883    ev->x = edev->seat->ptr.ix;
884    ev->y = edev->seat->ptr.iy;
885    ev->root.x = ev->x;
886    ev->root.y = ev->y;
887
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;
894 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
895    if (libinput_event_touch_has_minor(event))
896      ev->multi.radius_x = libinput_event_touch_get_minor(event);
897    if (libinput_event_touch_has_major(event))
898      ev->multi.radius_y = libinput_event_touch_get_major(event);
899    if (libinput_event_touch_has_pressure(event))
900      ev->multi.pressure = libinput_event_touch_get_pressure(event);
901    if (libinput_event_touch_has_orientation(event))
902      ev->multi.angle = libinput_event_touch_get_orientation(event);
903 #endif
904    ev->multi.x = ev->x;
905    ev->multi.y = ev->y;
906    ev->multi.root.x = ev->x;
907    ev->multi.root.y = ev->y;
908    ev->dev = edev->evas_dev;
909
910    ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL);
911 }
912
913 static void
914 _device_handle_touch_down(struct libinput_device *device, struct libinput_event_touch *event)
915 {
916    E_Input_Evdev *edev;
917    int w = 0, h = 0;
918
919    if (!(edev = libinput_device_get_user_data(device)))
920      {
921         return;
922      }
923
924    e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
925
926    edev->mouse.dx = edev->seat->ptr.ix = edev->seat->ptr.dx =
927      libinput_event_touch_get_x_transformed(event, w);
928    edev->mouse.dy = edev->seat->ptr.iy = edev->seat->ptr.dy =
929      libinput_event_touch_get_y_transformed(event, h);
930
931    edev->mt_slot = libinput_event_touch_get_slot(event);
932
933    _device_handle_touch_motion_send(edev, event);
934    _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_DOWN);
935 }
936
937 static void
938 _device_handle_touch_motion(struct libinput_device *device, struct libinput_event_touch *event)
939 {
940    E_Input_Evdev *edev;
941    int w = 0, h = 0;
942
943    if (!(edev = libinput_device_get_user_data(device)))
944      {
945         return;
946      }
947
948    e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
949
950    edev->mouse.dx = edev->seat->ptr.dx =
951      libinput_event_touch_get_x_transformed(event, w);
952    edev->mouse.dy = edev->seat->ptr.dy =
953      libinput_event_touch_get_y_transformed(event, h);
954
955    if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
956        floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
957      {
958         return;
959      }
960
961    edev->seat->ptr.ix = edev->seat->ptr.dx;
962    edev->seat->ptr.iy = edev->seat->ptr.dy;
963
964    edev->mt_slot = libinput_event_touch_get_slot(event);
965
966    _device_handle_touch_motion_send(edev, event);
967 }
968
969 static void
970 _device_handle_touch_up(struct libinput_device *device, struct libinput_event_touch *event)
971 {
972    E_Input_Evdev *edev;
973
974    if (!(edev = libinput_device_get_user_data(device)))
975      {
976         return;
977      }
978
979    edev->mt_slot = libinput_event_touch_get_slot(event);
980    _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_UP);
981 }
982
983 static void
984 _device_handle_touch_frame(struct libinput_device *device EINA_UNUSED, struct libinput_event_touch *event EINA_UNUSED)
985 {
986    /* DBG("Unhandled Touch Frame Event"); */
987 }
988
989 static void
990 _e_input_aux_data_event_free(void *user_data EINA_UNUSED, void *ev)
991 {
992    Ecore_Event_Axis_Update *e = (Ecore_Event_Axis_Update *)ev;
993    if (e->axis)
994      free(e->axis);
995    free(e);
996 }
997
998 static void
999 _device_handle_touch_aux_data(struct libinput_device *device, struct libinput_event_touch_aux_data *event)
1000 {
1001    E_Input_Evdev *edev;
1002    E_Input_Backend *input;
1003    Ecore_Event_Axis_Update *ev;
1004    Ecore_Axis *axis;
1005
1006    if (libinput_event_touch_aux_data_get_type(event) != LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM &&
1007        libinput_event_touch_aux_data_get_value(event) > 0)
1008       goto end;
1009
1010    if (!(edev = libinput_device_get_user_data(device))) goto end;
1011    if (!(input = edev->seat->input)) goto end;
1012
1013    if (!edev->evas_dev)
1014      edev->evas_dev = e_input_evdev_get_evas_device(edev->path, EVAS_DEVICE_CLASS_MOUSE);
1015
1016    if (!edev->evas_dev)
1017      {
1018         ERR("Failed to get source evas device from event !\n");
1019         goto end;
1020      }
1021
1022    if (!(ev = calloc(1, sizeof(Ecore_Event_Axis_Update))))goto end;
1023
1024    ev->window = (Ecore_Window)input->dev->window;
1025    ev->event_window = (Ecore_Window)input->dev->window;
1026    ev->root_window = (Ecore_Window)input->dev->window;
1027    ev->timestamp = libinput_event_touch_aux_data_get_time(event);
1028
1029    axis = (Ecore_Axis *)calloc(1, sizeof(Ecore_Axis));
1030    if (axis)
1031      {
1032         axis->label = ECORE_AXIS_LABEL_TOUCH_PALM;
1033         axis->value = libinput_event_touch_aux_data_get_value(event);
1034         ev->naxis = 1;
1035      }
1036    ev->axis = axis;
1037    ev->dev = edev->evas_dev;
1038
1039    ecore_event_add(ECORE_EVENT_AXIS_UPDATE, ev, _e_input_aux_data_event_free, NULL);
1040
1041 end:
1042    ;
1043 }
1044
1045 E_Input_Evdev *
1046 _e_input_evdev_device_create(E_Input_Seat *seat, struct libinput_device *device)
1047 {
1048    E_Input_Evdev *edev;
1049    E_Input_Backend *b_input;
1050
1051    EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
1052
1053    /* try to allocate space for new evdev */
1054    if (!(edev = calloc(1, sizeof(E_Input_Evdev)))) return NULL;
1055
1056    edev->seat = seat;
1057    edev->device = device;
1058    edev->path = eina_stringshare_printf("%s/%s", e_input_base_dir_get(), libinput_device_get_sysname(device));
1059    edev->fd = -1;
1060
1061    if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
1062      {
1063         edev->caps |= E_INPUT_SEAT_KEYBOARD;
1064         _device_keyboard_setup(edev);
1065      }
1066
1067    if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
1068      {
1069         edev->caps |= E_INPUT_SEAT_POINTER;
1070
1071         /* TODO: make this configurable */
1072         edev->mouse.threshold = 250;
1073
1074         b_input = seat->input;
1075         if (b_input->left_handed == EINA_TRUE)
1076           {
1077              if (libinput_device_config_left_handed_set(device, 1) !=
1078                  LIBINPUT_CONFIG_STATUS_SUCCESS)
1079                {
1080                   WRN("Failed to set left hand mode about device: %s\n",
1081                       libinput_device_get_name(device));
1082                }
1083           }
1084      }
1085
1086    if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
1087      {
1088         int palm_code;
1089         edev->caps |= E_INPUT_SEAT_TOUCH;
1090         palm_code = libinput_device_touch_aux_data_get_code(LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM);
1091         if (libinput_device_touch_has_aux_data(device, palm_code))
1092           {
1093              libinput_device_touch_set_aux_data(device, palm_code);
1094           }
1095      }
1096
1097    libinput_device_set_user_data(device, edev);
1098    libinput_device_ref(device);
1099
1100    /* configure device */
1101    _device_configure(edev);
1102
1103    return edev;
1104 }
1105
1106 void
1107 _e_input_evdev_device_destroy(E_Input_Evdev *edev)
1108 {
1109    EINA_SAFETY_ON_NULL_RETURN(edev);
1110
1111    if (edev->caps & E_INPUT_SEAT_KEYBOARD)
1112      {
1113         if (edev->xkb.state) xkb_state_unref(edev->xkb.state);
1114         if (edev->xkb.keymap) xkb_map_unref(edev->xkb.keymap);
1115      }
1116
1117    if (edev->evas_dev) evas_device_del(edev->evas_dev);
1118    if (edev->path) eina_stringshare_del(edev->path);
1119    if (edev->device) libinput_device_unref(edev->device);
1120    if (edev->key_remap_hash) eina_hash_free(edev->key_remap_hash);
1121
1122    free(edev);
1123 }
1124
1125 Eina_Bool
1126 _e_input_evdev_event_process(struct libinput_event *event)
1127 {
1128    struct libinput_device *device;
1129    Eina_Bool ret = EINA_TRUE;
1130
1131    device = libinput_event_get_device(event);
1132    switch (libinput_event_get_type(event))
1133      {
1134       case LIBINPUT_EVENT_KEYBOARD_KEY:
1135         _device_handle_key(device, libinput_event_get_keyboard_event(event));
1136         break;
1137       case LIBINPUT_EVENT_POINTER_MOTION:
1138         _device_handle_pointer_motion(device,
1139                                       libinput_event_get_pointer_event(event));
1140         break;
1141       case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
1142         _device_handle_pointer_motion_absolute(device,
1143                                                libinput_event_get_pointer_event(event));
1144         break;
1145       case LIBINPUT_EVENT_POINTER_BUTTON:
1146         _device_handle_button(device, libinput_event_get_pointer_event(event));
1147         break;
1148       case LIBINPUT_EVENT_POINTER_AXIS:
1149         _device_handle_axis(device, libinput_event_get_pointer_event(event));
1150         break;
1151       case LIBINPUT_EVENT_TOUCH_DOWN:
1152         _device_handle_touch_down(device, libinput_event_get_touch_event(event));
1153         break;
1154       case LIBINPUT_EVENT_TOUCH_MOTION:
1155         _device_handle_touch_motion(device,
1156                                     libinput_event_get_touch_event(event));
1157         break;
1158       case LIBINPUT_EVENT_TOUCH_UP:
1159         _device_handle_touch_up(device, libinput_event_get_touch_event(event));
1160         break;
1161       case LIBINPUT_EVENT_TOUCH_FRAME:
1162         _device_handle_touch_frame(device, libinput_event_get_touch_event(event));
1163         break;
1164       case LIBINPUT_EVENT_TOUCH_AUX_DATA:
1165         _device_handle_touch_aux_data(device, libinput_event_get_touch_aux_data(event));
1166         break;
1167       default:
1168         ret = EINA_FALSE;
1169         break;
1170      }
1171
1172    return ret;
1173 }
1174
1175 /**
1176  * @brief Set the axis size of the given device.
1177  *
1178  * @param dev The device to set the axis size to.
1179  * @param w The width of the axis.
1180  * @param h The height of the axis.
1181  *
1182  * This function sets set the width @p w and height @p h of the axis
1183  * of device @p dev. If @p dev is a relative input device, a width and
1184  * height must set for it. If its absolute set the ioctl correctly, if
1185  * not, unsupported device.
1186  */
1187 EINTERN void
1188 e_input_evdev_axis_size_set(E_Input_Evdev *edev, int w, int h)
1189 {
1190    const char *sysname;
1191    float cal[6];
1192    const char *device;
1193    Eina_List *devices;
1194    const char *vals;
1195    enum libinput_config_status status;
1196
1197    EINA_SAFETY_ON_NULL_RETURN(edev);
1198    EINA_SAFETY_ON_TRUE_RETURN((w == 0) || (h == 0));
1199
1200    if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
1201        (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
1202      return;
1203
1204    sysname = libinput_device_get_sysname(edev->device);
1205
1206    devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
1207    if (eina_list_count(devices) < 1) return;
1208
1209    EINA_LIST_FREE(devices, device)
1210      {
1211         vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
1212         if ((!vals) ||
1213             (sscanf(vals, "%f %f %f %f %f %f",
1214                     &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
1215           goto cont;
1216
1217         cal[2] /= w;
1218         cal[5] /= h;
1219
1220         status =
1221           libinput_device_config_calibration_set_matrix(edev->device, cal);
1222
1223         if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
1224           ERR("Failed to apply calibration");
1225
1226 cont:
1227         eina_stringshare_del(device);
1228         continue;
1229      }
1230 }
1231
1232 E_API const char *
1233 e_input_evdev_name_get(E_Input_Evdev *evdev)
1234 {
1235    EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
1236    EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
1237
1238    return libinput_device_get_name(evdev->device);
1239 }
1240
1241 EINTERN const char *
1242 e_input_evdev_sysname_get(E_Input_Evdev *evdev)
1243 {
1244    EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
1245    EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
1246
1247    return libinput_device_get_sysname(evdev->device);
1248 }
1249
1250 EINTERN Eina_Bool
1251 e_input_evdev_key_remap_enable(E_Input_Evdev *edev, Eina_Bool enable)
1252 {
1253    EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
1254    EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
1255
1256    edev->key_remap_enabled = enable;
1257
1258    if (enable == EINA_FALSE && edev->key_remap_hash)
1259      {
1260         eina_hash_free(edev->key_remap_hash);
1261         edev->key_remap_hash = NULL;
1262      }
1263
1264    return EINA_TRUE;
1265 }
1266
1267 EINTERN Eina_Bool
1268 e_input_evdev_key_remap_set(E_Input_Evdev *edev, int *from_keys, int *to_keys, int num)
1269 {
1270    int i;
1271
1272    EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
1273    EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
1274    EINA_SAFETY_ON_NULL_RETURN_VAL(from_keys, EINA_FALSE);
1275    EINA_SAFETY_ON_NULL_RETURN_VAL(to_keys, EINA_FALSE);
1276    EINA_SAFETY_ON_TRUE_RETURN_VAL(num <= 0, EINA_FALSE);
1277    EINA_SAFETY_ON_TRUE_RETURN_VAL(!edev->key_remap_enabled, EINA_FALSE);
1278
1279    if (edev->key_remap_hash == NULL)
1280      edev->key_remap_hash = eina_hash_int32_new(NULL);
1281
1282    if (edev->key_remap_hash == NULL)
1283      {
1284         ERR("Failed to set remap key information : creating a hash is failed.");
1285         return EINA_FALSE;
1286      }
1287
1288    for (i = 0; i < num ; i++)
1289      {
1290         if (!from_keys[i] || !to_keys[i])
1291           {
1292              ERR("Failed to set remap key information : given arguments are invalid.");
1293              return EINA_FALSE;
1294           }
1295      }
1296
1297    for (i = 0; i < num ; i++)
1298      {
1299         eina_hash_add(edev->key_remap_hash, &from_keys[i], (void *)(intptr_t)to_keys[i]);
1300      }
1301
1302    return EINA_TRUE;
1303 }
1304
1305 E_API int
1306 e_input_evdev_wheel_click_angle_get(E_Input_Evdev *dev)
1307 {
1308    EINA_SAFETY_ON_NULL_RETURN_VAL(dev, -1);
1309    return libinput_device_config_scroll_get_wheel_click_angle(dev->device);
1310 }
1311
1312 EINTERN Eina_Bool
1313 e_input_evdev_touch_calibration_set(E_Input_Evdev *edev, float matrix[6])
1314 {
1315    EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
1316    EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
1317
1318    if (!libinput_device_config_calibration_has_matrix(edev->device) ||
1319        !libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_TOUCH))
1320      return EINA_FALSE;
1321
1322    if (libinput_device_config_calibration_set_matrix(edev->device, matrix) !=
1323        LIBINPUT_CONFIG_STATUS_SUCCESS)
1324      {
1325         WRN("Failed to set input transformation about device: %s\n",
1326             libinput_device_get_name(edev->device));
1327         return EINA_FALSE;
1328      }
1329
1330    return EINA_TRUE;
1331 }
1332