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