e_comp_wl_input: when pointer is locked, do not update seat->ptr.x/y. like grab
[platform/upstream/enlightenment.git] / src / bin / e_input_evdev.c
1 #include "e.h"
2 #include "e_input_private.h"
3 #include "e_device.h"
4 #include "e_keyrouter_private.h"
5 #include "e_input_event.h"
6 #include "e_devicemgr.h"
7
8 #include <glib.h>
9
10 #define G_LIST_GET_DATA(list) ((list) ? (((GList *)(list))->data) : NULL)
11
12 static void  _device_modifiers_update(E_Input_Evdev *edev);
13 static void  _device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, int *w, int *h);
14 static void  _device_output_assign(E_Input_Evdev *edev, E_Input_Seat_Capabilities cap);
15
16 void
17 _device_calibration_set(E_Input_Evdev *edev)
18 {
19    E_Output *output;
20    int w = 0, h = 0;
21    int temp;
22    E_Comp_Config *comp_conf;
23
24    if (e_comp->e_comp_screen->num_outputs > 1) //multiple outputs
25      {
26         comp_conf = e_comp_config_get();
27         if (comp_conf && (comp_conf->input_output_assign_policy == 1)) //use output-assignment policy
28           {
29              _device_output_assign(edev, E_INPUT_SEAT_POINTER);
30              _device_output_assign(edev, E_INPUT_SEAT_TOUCH);
31           }
32      }
33
34    output = e_comp_screen_primary_output_get(e_comp->e_comp_screen);
35    e_output_size_get(output, &w, &h);
36
37    if (output)
38      {
39         edev->mouse.minx = edev->mouse.miny = 0;
40         edev->mouse.maxw = w;
41         edev->mouse.maxh = h;
42
43         if (libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
44           {
45              edev->seat->ptr.dx = (double)(w / 2);
46              edev->seat->ptr.dy = (double)(h / 2);
47              edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
48              edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
49              edev->mouse.dx = edev->seat->ptr.dx;
50              edev->mouse.dy = edev->seat->ptr.dy;
51
52              if (output->config.rotation == 90 || output->config.rotation == 270)
53                {
54                   temp = edev->mouse.minx;
55                   edev->mouse.minx = edev->mouse.miny;
56                   edev->mouse.miny = temp;
57
58                   temp = edev->mouse.maxw;
59                   edev->mouse.maxw = edev->mouse.maxh;
60                   edev->mouse.maxh = temp;
61                }
62           }
63      }
64
65 //LCOV_EXCL_START
66 #ifdef _F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
67    const char *sysname;
68    float cal[6];
69    const char *device;
70    Eina_List *devices;
71
72    if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
73        (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
74      return;
75
76    sysname = libinput_device_get_sysname(edev->device);
77
78    devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
79    if (eina_list_count(devices) < 1) return;
80
81 #ifdef _F_E_INPUT_USE_WL_CALIBRATION_
82    const char *vals;
83    enum libinput_config_status status;
84
85    EINA_LIST_FREE(devices, device)
86      {
87         vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
88         if ((!vals) ||
89             (sscanf(vals, "%f %f %f %f %f %f",
90                     &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
91           goto cont;
92
93         cal[2] /= w;
94         cal[5] /= h;
95
96         status =
97           libinput_device_config_calibration_set_matrix(edev->device, cal);
98
99         if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
100           ERR("Failed to apply calibration");
101
102 cont:
103         eina_stringshare_del(device);
104         continue;
105      }
106 #endif//_F_E_INPUT_USE_WL_CALIBRATION_
107 #endif//_F_E_INPUT_ENABLE_DEVICE_CALIBRATION_
108 //LCOV_EXCL_STOP
109 }
110
111 static void
112 _device_output_assign(E_Input_Evdev *edev, E_Input_Seat_Capabilities cap)
113 {
114    int last_output_idx;
115    E_Input_Evdev *ed;
116    Eina_List *l;
117    Eina_Bool need_assign_output = EINA_FALSE;
118    const char *output_name;
119    E_Output *output;
120
121    if (!(edev->caps & cap)) return;
122    if (edev->output_name) return; //already assigned
123    if (e_comp->e_comp_screen->num_outputs <= 1) return;
124
125    last_output_idx = e_comp->e_comp_screen->num_outputs - 1;
126    EINA_LIST_FOREACH(edev->seat->devices, l, ed)
127      {
128         if (!(ed->caps & cap)) continue;
129         if (ed == edev) continue;
130         if (ed->output_name)
131           {
132              need_assign_output = EINA_FALSE;
133              break;
134           }
135           need_assign_output = EINA_TRUE;
136      }
137    if (need_assign_output)
138      {
139         output = e_output_find_by_index(last_output_idx);
140         if (!output || !output->info.connected) return;
141         output_name = e_output_output_id_get(output);
142         if (output_name) edev->output_name = eina_stringshare_add(output_name);
143         ELOGF("E_INPUT_EVDEV", "Device is assigned to output:%s", NULL, output_name);
144      }
145 }
146
147 static void
148 _device_touch_count_update(E_Input_Evdev *edev)
149 {
150    unsigned int device_touch_count = 0;
151    static unsigned int _max_device_touch_count = 0;
152
153    E_Input *ei = e_input_get();
154    EINA_SAFETY_ON_NULL_RETURN(ei);
155
156    device_touch_count = libinput_device_touch_get_touch_count(edev->device);
157
158    if (_max_device_touch_count < device_touch_count)
159      _max_device_touch_count = device_touch_count;
160
161    if (e_config->configured_max_touch.use)
162      {
163         if (_max_device_touch_count > 0 && e_config->configured_max_touch.count > _max_device_touch_count)
164           {
165              ELOGF("E_INPUT_EVDEV_TOUCH", "Touch max count(%d) must be less or equal to device's touch count(%d) !\nTouch max count has been shrinken to %d.\n",
166                          NULL, e_config->configured_max_touch.count, _max_device_touch_count, _max_device_touch_count);
167              ei->touch_max_count = _max_device_touch_count;
168           }
169         else
170           {
171              if (ei->touch_max_count != e_config->configured_max_touch.count)
172              {
173                 ELOGF("E_INPUT_EVDEV_TOUCH", "Touch_max_count has been updated to %d -> %d.\n",
174                            NULL, ei->touch_max_count, e_config->configured_max_touch.count);
175                 ei->touch_max_count = e_config->configured_max_touch.count;
176              }
177           }
178      }
179    else
180      {
181         if (ei->touch_max_count < _max_device_touch_count)
182           {
183              ELOGF("E_INPUT_EVDEV_TOUCH", "Touch_max_count has been updated to %d -> %d.\n", NULL,
184                    ei->touch_max_count, _max_device_touch_count);
185              ei->touch_max_count = _max_device_touch_count;
186           }
187      }
188
189    ei->touch_device_count++;
190    ELOGF("E_INPUT_EVDEV_TOUCH", "Touch device count is %d.\n", NULL, ei->touch_device_count);
191 }
192
193 static void
194 _device_configure(E_Input_Evdev *edev)
195 {
196    if (libinput_device_config_tap_get_finger_count(edev->device) > 0)
197      {
198         Eina_Bool tap = EINA_FALSE;
199
200         tap = libinput_device_config_tap_get_default_enabled(edev->device);
201         libinput_device_config_tap_set_enabled(edev->device, tap);
202      }
203
204    _device_calibration_set(edev);
205 }
206
207 static void
208 _device_keyboard_setup(E_Input_Evdev *edev)
209 {
210    E_Input_Backend *input;
211    xkb_mod_index_t xkb_idx;
212
213    if ((!edev) || (!edev->seat)) return;
214    if (!(input = edev->seat->input)) return;
215    if (!input->dev->xkb_ctx) return;
216
217    g_mutex_init(&edev->xkb.keymap_mutex);
218
219    /* create keymap from xkb context */
220    g_mutex_lock(&edev->xkb.keymap_mutex);
221    edev->xkb.keymap = _e_input_device_cached_keymap_get(input->dev->xkb_ctx, NULL, 0);
222    if (!edev->xkb.keymap)
223      {
224         g_mutex_unlock(&edev->xkb.keymap_mutex);
225         ERR("Failed to create keymap: %m");
226         return;
227      }
228
229    g_mutex_lock(&edev->xkb.state_mutex);
230
231    /* create xkb state */
232    if (!(edev->xkb.state = xkb_state_new(edev->xkb.keymap)))
233      {
234         g_mutex_unlock(&edev->xkb.state_mutex);
235         g_mutex_unlock(&edev->xkb.keymap_mutex);
236         ERR("Failed to create xkb state: %m");
237         return;
238      }
239
240    g_mutex_unlock(&edev->xkb.state_mutex);
241
242    xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CTRL);
243    if (xkb_idx != XKB_MOD_INVALID)
244      edev->xkb.ctrl_mask = 1 << xkb_idx;
245    else
246      edev->xkb.ctrl_mask = 0;
247
248    xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_ALT);
249    if (xkb_idx != XKB_MOD_INVALID)
250      edev->xkb.alt_mask = 1 << xkb_idx;
251    else
252      edev->xkb.alt_mask = 0;
253
254    xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_SHIFT);
255    if (xkb_idx != XKB_MOD_INVALID)
256      edev->xkb.shift_mask = 1 << xkb_idx;
257    else
258      edev->xkb.shift_mask = 0;
259
260    xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_LOGO);
261    if (xkb_idx != XKB_MOD_INVALID)
262      edev->xkb.win_mask = 1 << xkb_idx;
263    else
264      edev->xkb.win_mask = 0;
265
266    xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_SCROLL);
267    if (xkb_idx != XKB_MOD_INVALID)
268      edev->xkb.scroll_mask = 1 << xkb_idx;
269    else
270      edev->xkb.scroll_mask = 0;
271
272    xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_LED_NAME_NUM);
273    if (xkb_idx != XKB_MOD_INVALID)
274      edev->xkb.num_mask = 1 << xkb_idx;
275    else
276      edev->xkb.num_mask = 0;
277
278    xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, XKB_MOD_NAME_CAPS);
279    if (xkb_idx != XKB_MOD_INVALID)
280      edev->xkb.caps_mask = 1 << xkb_idx;
281    else
282      edev->xkb.caps_mask = 0;
283
284    xkb_idx = xkb_map_mod_get_index(edev->xkb.keymap, "ISO_Level3_Shift");
285    if (xkb_idx != XKB_MOD_INVALID)
286      edev->xkb.altgr_mask = 1 << xkb_idx;
287    else
288      edev->xkb.altgr_mask = 0;
289
290    g_mutex_unlock(&edev->xkb.keymap_mutex);
291 }
292
293 static int
294 _device_keysym_translate(xkb_keysym_t keysym, unsigned int modifiers, char *buffer, int bytes)
295 {
296    unsigned long hbytes = 0;
297    unsigned char c;
298
299    if (!keysym) return 0;
300    hbytes = (keysym >> 8);
301
302    if (!(bytes &&
303          ((hbytes == 0) ||
304           ((hbytes == 0xFF) &&
305            (((keysym >= XKB_KEY_BackSpace) && (keysym <= XKB_KEY_Clear)) ||
306             (keysym == XKB_KEY_Return) || (keysym == XKB_KEY_Escape) ||
307             (keysym == XKB_KEY_KP_Space) || (keysym == XKB_KEY_KP_Tab) ||
308             (keysym == XKB_KEY_KP_Enter) ||
309             ((keysym >= XKB_KEY_KP_Multiply) && (keysym <= XKB_KEY_KP_9)) ||
310             (keysym == XKB_KEY_KP_Equal) || (keysym == XKB_KEY_Delete))))))
311      return 0;
312
313    if (keysym == XKB_KEY_KP_Space)
314      c = (XKB_KEY_space & 0x7F);
315    else if (hbytes == 0xFF)
316      c = (keysym & 0x7F);
317    else
318      c = (keysym & 0xFF);
319
320    if (modifiers & ECORE_EVENT_MODIFIER_CTRL)
321      {
322         if (((c >= '@') && (c < '\177')) || c == ' ')
323           c &= 0x1F;
324         else if (c == '2')
325           c = '\000';
326         else if ((c >= '3') && (c <= '7'))
327           c -= ('3' - '\033');
328         else if (c == '8')
329           c = '\177';
330         else if (c == '/')
331           c = '_' & 0x1F;
332      }
333    buffer[0] = c;
334    return 1;
335 }
336
337 static void
338 _device_modifiers_update_device(E_Input_Evdev *edev, E_Input_Evdev *from)
339 {
340    xkb_mod_mask_t mask;
341
342    g_mutex_lock(&from->xkb.state_mutex);
343
344    edev->xkb.depressed =
345      xkb_state_serialize_mods(from->xkb.state, XKB_STATE_DEPRESSED);
346    edev->xkb.latched =
347      xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LATCHED);
348    edev->xkb.locked =
349      xkb_state_serialize_mods(from->xkb.state, XKB_STATE_LOCKED);
350    edev->xkb.group =
351      xkb_state_serialize_mods(from->xkb.state, XKB_STATE_EFFECTIVE);
352
353    g_mutex_unlock(&from->xkb.state_mutex);
354
355    mask = (edev->xkb.depressed | edev->xkb.latched);
356
357    if (mask & from->xkb.ctrl_mask)
358      edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_CTRL;
359    if (mask & from->xkb.alt_mask)
360      edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALT;
361    if (mask & from->xkb.shift_mask)
362      edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_SHIFT;
363    if (mask & from->xkb.win_mask)
364      edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_WIN;
365    if (mask & from->xkb.scroll_mask)
366      edev->xkb.modifiers |= ECORE_EVENT_LOCK_SCROLL;
367    if (mask & from->xkb.num_mask)
368      edev->xkb.modifiers |= ECORE_EVENT_LOCK_NUM;
369    if (mask & from->xkb.caps_mask)
370      edev->xkb.modifiers |= ECORE_EVENT_LOCK_CAPS;
371    if (mask & from->xkb.altgr_mask)
372      edev->xkb.modifiers |= ECORE_EVENT_MODIFIER_ALTGR;
373 }
374
375 static void
376 _device_modifiers_update(E_Input_Evdev *edev)
377 {
378    Eina_List *l;
379    E_Input_Evdev *ed;
380
381    edev->xkb.modifiers = 0;
382
383    if (edev->caps & E_INPUT_SEAT_KEYBOARD)
384      _device_modifiers_update_device(edev, edev);
385    else
386      {
387         EINA_LIST_FOREACH(edev->seat->devices, l, ed)
388           {
389              if (!(ed->caps & E_INPUT_SEAT_KEYBOARD)) continue;
390              _device_modifiers_update_device(edev, ed);
391           }
392      }
393
394 }
395
396 static int
397 _device_remapped_key_get(E_Input_Evdev *edev, int code)
398 {
399    void *ret = NULL;
400
401    EINA_SAFETY_ON_NULL_RETURN_VAL(edev, code);
402    if (!edev->key_remap_enabled) return code;
403    EINA_SAFETY_ON_NULL_RETURN_VAL(edev->key_remap_hash, code);
404
405    ret = eina_hash_find(edev->key_remap_hash, &code);
406
407    if (ret) code = (int)(intptr_t)ret;
408
409    return code;
410 }
411
412 EINTERN E_Device *
413 e_input_evdev_get_e_device(const char *path, Ecore_Device_Class clas)
414 {
415    const GList *dev_list = NULL;
416    const GList *l;
417    E_Device *dev = NULL;
418    const char *identifier;
419
420    if (!path) return NULL;
421
422    dev_list = e_device_list_get();
423    if (!dev_list) return NULL;
424
425    l = dev_list;
426    while (l)
427      {
428         dev = l->data;
429         if (!dev) continue;
430         identifier = e_device_identifier_get(dev);
431         if (!identifier) continue;
432         if ((e_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
433           return dev;
434
435         l = g_list_next(l);
436      }
437
438    return NULL;
439 }
440
441 EINTERN Ecore_Device *
442 e_input_evdev_get_ecore_device(const char *path, Ecore_Device_Class clas)
443 {
444    const Eina_List *dev_list = NULL;
445    const Eina_List *l;
446    Ecore_Device *dev = NULL;
447    const char *identifier;
448
449    if (!path) return NULL;
450
451    dev_list = ecore_device_list();
452    if (!dev_list) return NULL;
453    EINA_LIST_FOREACH(dev_list, l, dev)
454      {
455         if (!dev) continue;
456         identifier = ecore_device_identifier_get(dev);
457         if (!identifier) continue;
458         if ((ecore_device_class_get(dev) == clas) && !(strcmp(identifier, path)))
459           return dev;
460      }
461    return NULL;
462 }
463
464 static void
465 _e_input_event_mouse_move_cb_free(void *data EINA_UNUSED, void *event)
466 {
467    Ecore_Event_Mouse_Move *ev = event;
468
469    if (ev->dev) ecore_device_unref(ev->dev);
470
471    free(ev);
472 }
473
474 static void
475 _e_input_event_mouse_relative_move_cb_free(void *data EINA_UNUSED, void *event)
476 {
477    Ecore_Event_Mouse_Relative_Move *ev = event;
478
479    if (ev->dev) ecore_device_unref(ev->dev);
480
481    free(ev);
482 }
483
484 static void
485 _e_input_event_mouse_wheel_cb_free(void *data EINA_UNUSED, void *event)
486 {
487    Ecore_Event_Mouse_Wheel *ev = event;
488
489    if (ev->dev) ecore_device_unref(ev->dev);
490
491    free(ev);
492 }
493
494 static void
495 _e_input_event_mouse_button_cb_free(void *data EINA_UNUSED, void *event)
496 {
497    Ecore_Event_Mouse_Button *ev = event;
498
499    if (ev->dev) ecore_device_unref(ev->dev);
500
501    free(ev);
502 }
503
504 static void
505 _e_input_event_key_cb_free(void *data EINA_UNUSED, void *event)
506 {
507    Ecore_Event_Key *ev = event;
508
509    if (e_input_thread_mode_get())
510      {
511         if (ev->dev) g_object_unref(ev->dev);
512      }
513    else
514      {
515         if (ev->dev) ecore_device_unref(ev->dev);
516      }
517
518    if (ev->data) E_FREE(ev->data);
519
520    free(ev);
521 }
522
523 static void
524 _device_handle_key(struct libinput_device *device, struct libinput_event_keyboard *event)
525 {
526    E_Input_Evdev *edev;
527    E_Input_Backend *input;
528    uint32_t timestamp;
529    uint32_t code, nsyms;
530    const xkb_keysym_t *syms;
531    enum libinput_key_state state;
532    int key_count;
533    xkb_keysym_t sym = XKB_KEY_NoSymbol;
534    char key[256] = {0, }, keyname[256] = {0, }, compose_buffer[256] = {0, };
535    Ecore_Event_Key *e;
536    char *tmp = NULL, *compose = NULL;
537    E_Keyrouter_Event_Data *key_data;
538    Ecore_Device *ecore_dev = NULL, *data;
539    E_Device *e_dev = NULL, *e_dev_data;
540    Eina_List *l = NULL, *l_next = NULL;
541    GList *glist = NULL;
542    E_Comp_Config *comp_conf = NULL;
543    int *pressed_keycode = NULL, *idata = NULL;
544    Eina_Bool dup_found = EINA_FALSE;
545    const char* device_name = NULL;
546    Ecore_Device_Subclass device_subclas = ECORE_DEVICE_SUBCLASS_NONE;
547
548    if (!(edev = libinput_device_get_user_data(device)))
549      {
550         return;
551      }
552
553    if (!(input = edev->seat->input))
554      {
555         return;
556      }
557
558    if (!e_input_thread_mode_get())
559      {
560         if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
561         else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
562           {
563              EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
564                {
565                   if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_KEYBOARD)
566                     {
567                        ecore_dev = data;
568                        break;
569                     }
570                }
571           }
572         else
573           {
574              edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
575              ecore_dev = edev->ecore_dev;
576           }
577
578         if (!ecore_dev)
579           {
580              ERR("Failed to get source ecore device from event !\n");
581              return;
582           }
583
584         device_name = ecore_device_name_get(ecore_dev);
585         device_subclas = ecore_device_subclass_get(ecore_dev);
586      }
587    else
588      {
589         if (edev->e_dev) e_dev = edev->e_dev;
590         else if (edev->e_dev_list && g_list_length(edev->e_dev_list) > 0)
591           {
592              glist = edev->e_dev_list;
593              while (glist)
594                {
595                   e_dev_data = glist->data;
596                   if (e_device_class_get(e_dev_data) == ECORE_DEVICE_CLASS_KEYBOARD)
597                     {
598                        e_dev = e_dev_data;
599                        break;
600                     }
601
602                   glist = g_list_next(glist);
603                }
604           }
605         else
606           {
607              edev->e_dev = e_input_evdev_get_e_device(edev->path, ECORE_DEVICE_CLASS_KEYBOARD);
608              e_dev = edev->e_dev;
609           }
610
611         if (!e_dev)
612           {
613              ERR("Failed to get source e device from event !\n");
614              return;
615           }
616
617         device_name = e_device_name_get(e_dev);
618         device_subclas = e_device_subclass_get(e_dev);
619      }
620
621    timestamp = libinput_event_keyboard_get_time(event);
622    code = libinput_event_keyboard_get_key(event);
623    code = _device_remapped_key_get(edev, code + 8);
624    state = libinput_event_keyboard_get_key_state(event);
625    key_count = libinput_event_keyboard_get_seat_key_count(event);
626
627    if (state == LIBINPUT_KEY_STATE_PRESSED)
628      {
629         if ((edev->seat->dev->blocked & E_INPUT_SEAT_KEYBOARD) ||
630             (edev->seat->dev->server_blocked & E_INPUT_SEAT_KEYBOARD))
631           {
632              ELOGF("Key", "Press (keycode: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
633                    code, device_name, edev->seat->dev->blocked_client,
634                    edev->seat->dev->server_blocked);
635              return;
636           }
637
638         /* FIXME: Currently to maintain press/release event pair during input block,
639          *        used Eina_List and this is method used in devicemgr module.
640          *        But we need to consider which way is better to maintain key press/release pair.
641          */
642
643         EINA_LIST_FOREACH(edev->xkb.pressed_keys, l, idata)
644           {
645              if (*idata == code)
646                {
647                   dup_found = EINA_TRUE;
648                   break;
649                }
650           }
651         if (!dup_found)
652           {
653              pressed_keycode = E_NEW(int, 1);
654              EINA_SAFETY_ON_NULL_RETURN(pressed_keycode);
655              *pressed_keycode = code;
656
657              edev->xkb.pressed_keys = eina_list_append(edev->xkb.pressed_keys, pressed_keycode);
658           }
659      }
660    else
661      {
662         dup_found = EINA_FALSE;
663         EINA_LIST_FOREACH_SAFE(edev->xkb.pressed_keys, l, l_next, idata)
664           {
665              if (code == *idata)
666                {
667                   edev->xkb.pressed_keys = eina_list_remove_list(edev->xkb.pressed_keys, l);
668                   E_FREE(idata);
669                   dup_found = EINA_TRUE;
670                   break;
671                }
672           }
673         if (!dup_found)
674           {
675              ELOGF("Key", "Release (keycode: %d, device: %s) is blocked by %p", NULL,
676                    code, device_name, edev->seat->dev->blocked_client);
677              return;
678           }
679      }
680
681    /* ignore key events that are not seat wide state changes */
682    if (((state == LIBINPUT_KEY_STATE_PRESSED) && (key_count != 1)) ||
683        ((state == LIBINPUT_KEY_STATE_RELEASED) && (key_count != 0)))
684      {
685         return;
686      }
687
688    e_input_keyboard_grab_key_cb func = e_input_keyboard_grab_key_handler_get();
689    if (func)
690      {
691         if (e_devicemgr_keyboard_grab_subtype_is_grabbed(device_subclas))
692           {
693              func(code, state, timestamp);
694              return;
695           }
696      }
697
698    g_mutex_lock(&edev->xkb.state_mutex);
699    xkb_state_update_key(edev->xkb.state, code,
700                         (state ? XKB_KEY_DOWN : XKB_KEY_UP));
701
702    /* get the keysym for this code */
703    nsyms = xkb_key_get_syms(edev->xkb.state, code, &syms);
704    g_mutex_unlock(&edev->xkb.state_mutex);
705
706    if (nsyms == 1) sym = syms[0];
707
708    /* If no keysym was found, name it "Keycode-NNN" */
709    if (sym == XKB_KEY_NoSymbol)
710      snprintf(key, sizeof(key), "Keycode-%u", code);
711    else
712      {
713         /* get the keyname for this sym */
714         xkb_keysym_get_name(sym, key, sizeof(key));
715      }
716
717    if (key[0] == '\0')
718      {
719         /* If no keyname was found, name it "Keycode-NNN" */
720         snprintf(keyname, sizeof(keyname), "Keycode-%u", code);
721      }
722    else
723      {
724         memcpy(keyname, key, sizeof(keyname));
725      }
726
727    /* if shift is active, we need to transform the key to lower */
728    g_mutex_lock(&edev->xkb.keymap_mutex);
729    g_mutex_lock(&edev->xkb.state_mutex);
730    if (xkb_state_mod_index_is_active(edev->xkb.state,
731                                      xkb_map_mod_get_index(edev->xkb.keymap,
732                                      XKB_MOD_NAME_SHIFT),
733                                      XKB_STATE_MODS_EFFECTIVE))
734      {
735         if (keyname[0] != '\0')
736           keyname[0] = tolower(keyname[0]);
737      }
738    g_mutex_unlock(&edev->xkb.keymap_mutex);
739    g_mutex_unlock(&edev->xkb.state_mutex);
740
741    if (_device_keysym_translate(sym, edev->xkb.modifiers,
742                                 compose_buffer, sizeof(compose_buffer)))
743      {
744         compose = eina_str_convert("ISO8859-1", "UTF-8", compose_buffer);
745         if (!compose)
746           {
747              ERR("E Input cannot convert input key string '%s' to UTF-8. "
748                  "Is Eina built with iconv support?", compose_buffer);
749           }
750         else
751           tmp = compose;
752      }
753
754    if (!compose) compose = compose_buffer;
755
756    e = calloc(1, sizeof(Ecore_Event_Key) + strlen(key) + strlen(keyname) +
757               ((compose[0] != '\0') ? strlen(compose) : 0) + 3);
758    if (!e)
759      {
760         E_FREE(tmp);
761         return;
762      }
763    key_data = E_NEW(E_Keyrouter_Event_Data, 1);
764    if (!key_data)
765      {
766         E_FREE(tmp);
767         E_FREE(e);
768         return;
769      }
770
771    e->keyname = (char *)(e + 1);
772    e->key = e->keyname + strlen(keyname) + 1;
773    e->compose = strlen(compose) ? e->key + strlen(key) + 1 : NULL;
774    e->string = e->compose;
775
776    strncpy((char *)e->keyname, keyname, strlen(keyname));
777    strncpy((char *)e->key, key, strlen(key));
778    if (strlen(compose)) strncpy((char *)e->compose, compose, strlen(compose));
779
780    e->window = (Ecore_Window)input->dev->window;
781    e->event_window = (Ecore_Window)input->dev->window;
782    e->root_window = (Ecore_Window)input->dev->window;
783    e->timestamp = timestamp;
784    e->same_screen = 1;
785    e->keycode = code;
786    e->data = key_data;
787
788    _device_modifiers_update(edev);
789
790    e->modifiers = edev->xkb.modifiers;
791
792    comp_conf = e_comp_config_get();
793
794    if (comp_conf && comp_conf->input_log_enable)
795      ELOGF("Key", "%s (keyname: %s, keycode: %d, timestamp: %u, device: %s)", NULL, state?"Press":"Release", e->keyname, e->keycode, e->timestamp, device_name);
796
797    if (e_input_thread_mode_get())
798      {
799         e->dev = (Eo *)g_object_ref(e_dev);
800         e_input_event_add(input->event_source, state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
801      }
802    else
803      {
804         e->dev = ecore_device_ref(ecore_dev);
805         ecore_event_add(state ? ECORE_EVENT_KEY_DOWN : ECORE_EVENT_KEY_UP, e, _e_input_event_key_cb_free, NULL);
806      }
807
808    if (tmp) free(tmp);
809 }
810
811 static void
812 _device_pointer_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event)
813 {
814    E_Input_Backend *input;
815    Ecore_Event_Mouse_Move *ev;
816    Ecore_Device *ecore_dev = NULL, *data, *detent_data = NULL;
817    Eina_List *l;
818    int x = 0, y = 0, w = 0, h = 0;
819
820    if (!(input = edev->seat->input)) return;
821
822    ecore_thread_main_loop_begin();
823
824    if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
825    else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
826      {
827         EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
828           {
829              if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
830                {
831                   ecore_dev = data;
832                   break;
833                }
834              else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
835                {
836                   detent_data = data;
837                }
838           }
839         if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
840           {
841              ecore_dev = detent_data;
842           }
843      }
844    else
845      {
846         edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
847         ecore_dev = edev->ecore_dev;
848      }
849
850    if (!ecore_dev)
851      {
852         ERR("Failed to get source ecore device from event !\n");
853         goto end;
854      }
855    else if ((detent_data == ecore_dev) || e_devicemgr_detent_is_detent(ecore_device_name_get(ecore_dev)))
856      {
857         /* Do not process detent device's move events. */
858         goto end;
859      }
860
861    if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) return;
862
863    _device_configured_size_get(edev, &x, &y, &w, &h);
864
865    if (edev->seat->ptr.ix < x)
866      edev->seat->ptr.dx = edev->seat->ptr.ix = x;
867    else if (edev->seat->ptr.ix >= (x + w))
868      edev->seat->ptr.dx = edev->seat->ptr.ix = (x + w - 1);
869
870    if (edev->seat->ptr.iy < y)
871      edev->seat->ptr.dy = edev->seat->ptr.iy = y;
872    else if (edev->seat->ptr.iy >= (y + h))
873      edev->seat->ptr.dy = edev->seat->ptr.iy = (y + h - 1);
874
875    edev->mouse.dx = edev->seat->ptr.dx;
876    edev->mouse.dy = edev->seat->ptr.dy;
877
878    ev->window = (Ecore_Window)input->dev->window;
879    ev->event_window = (Ecore_Window)input->dev->window;
880    ev->root_window = (Ecore_Window)input->dev->window;
881    if (event) ev->timestamp = libinput_event_pointer_get_time(event);
882    ev->same_screen = 1;
883
884    _device_modifiers_update(edev);
885    ev->modifiers = edev->xkb.modifiers;
886
887    ev->x = edev->seat->ptr.ix;
888    ev->y = edev->seat->ptr.iy;
889    ev->root.x = ev->x;
890    ev->root.y = ev->y;
891
892    ev->multi.device = edev->mt_slot;
893    ev->multi.radius = 1;
894    ev->multi.radius_x = 1;
895    ev->multi.radius_y = 1;
896    ev->multi.pressure = 1.0;
897    ev->multi.angle = 0.0;
898    ev->multi.x = ev->x;
899    ev->multi.y = ev->y;
900    ev->multi.root.x = ev->x;
901    ev->multi.root.y = ev->y;
902
903    ev->dev = ecore_device_ref(ecore_dev);
904
905    ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
906
907 end:
908    ecore_thread_main_loop_end();
909 }
910
911 void
912 _e_input_pointer_motion_post(E_Input_Evdev *edev)
913 {
914    _device_pointer_motion(edev, NULL);
915 }
916
917 static void
918 _device_pointer_relative_motion(E_Input_Evdev *edev, struct libinput_event_pointer *event, double dx[2], double dy[2])
919 {
920    E_Input_Backend *input;
921    Ecore_Event_Mouse_Relative_Move *ev;
922    Ecore_Device *ecore_dev = NULL, *data, *detent_data = NULL;
923    Eina_List *l;
924    E_Comp_Config *comp_conf;
925
926    if (!(input = edev->seat->input)) return;
927
928    ecore_thread_main_loop_begin();
929
930    if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
931    else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
932      {
933         EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
934           {
935              if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
936                {
937                   ecore_dev = data;
938                   break;
939                }
940              else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
941                {
942                   detent_data = data;
943                }
944           }
945         if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
946           {
947              ecore_dev = detent_data;
948           }
949      }
950    else
951      {
952         edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
953         ecore_dev = edev->ecore_dev;
954      }
955
956    if (!ecore_dev)
957      {
958         ERR("Failed to get source ecore device from event !\n");
959         goto end;
960      }
961    else if ((detent_data == ecore_dev) || e_devicemgr_detent_is_detent(ecore_device_name_get(ecore_dev)))
962      {
963         /* Do not process detent device's move events. */
964         goto end;
965      }
966
967    if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Relative_Move)))) return;
968
969    ev->window = (Ecore_Window)input->dev->window;
970    ev->event_window = (Ecore_Window)input->dev->window;
971    if (event) ev->timestamp = libinput_event_pointer_get_time(event);
972
973    ev->modifiers = edev->xkb.modifiers;
974
975    ev->dx = (int)dx[0];
976    ev->dy = (int)dy[0];
977    ev->dx_unaccel = (int)dx[1];
978    ev->dy_unaccel = (int)dy[1];
979
980    ev->dev = ecore_device_ref(ecore_dev);
981
982    comp_conf = e_comp_config_get();
983    if (comp_conf && comp_conf->input_log_enable)
984      ELOGF("Mouse", "Relative Move (dx: %d, dy: %d, unaccel(%d, %d) device: %s)", NULL, ev->dx, ev->dx, ev->dx_unaccel, ev->dy_unaccel, ecore_device_name_get(ev->dev));
985
986    ecore_event_add(ECORE_EVENT_MOUSE_RELATIVE_MOVE, ev, _e_input_event_mouse_relative_move_cb_free, NULL);
987
988 end:
989    ecore_thread_main_loop_end();
990 }
991
992 static void
993 _device_pointer_motion_send(E_Input_Evdev *edev, struct libinput_event_pointer *event, double dx[2], double dy[2])
994 {
995    e_input_relative_motion_cb func = e_input_relative_motion_handler_get();
996    if (func)
997      {
998         //func(dx, dy, time_us);
999         _device_pointer_relative_motion(edev, event, dx, dy);
1000      }
1001    else
1002      {
1003         double seat_dx, seat_dy, temp;
1004         if (edev->disable_acceleration)
1005           {
1006               seat_dx = dx[1];
1007               seat_dy = dy[1];
1008           }
1009         else
1010           {
1011               seat_dx = dx[0];
1012               seat_dy = dy[0];
1013           }
1014
1015         if (edev->seat->ptr.swap)
1016           {
1017               temp = seat_dx;
1018               seat_dx = seat_dy;
1019               seat_dy = temp;
1020           }
1021         if (edev->seat->ptr.invert_x)
1022           seat_dx *= -1;
1023         if (edev->seat->ptr.invert_y)
1024           seat_dy *= -1;
1025
1026         edev->seat->ptr.dx += seat_dx;
1027         edev->seat->ptr.dy += seat_dy;
1028
1029         edev->mouse.dx = edev->seat->ptr.dx;
1030         edev->mouse.dy = edev->seat->ptr.dy;
1031
1032         if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
1033             floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
1034           {
1035               return;
1036           }
1037
1038         edev->seat->ptr.ix = edev->seat->ptr.dx;
1039         edev->seat->ptr.iy = edev->seat->ptr.dy;
1040
1041         if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1042             (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1043           {
1044               return;
1045           }
1046
1047         _device_pointer_motion(edev, event);
1048      }
1049 }
1050
1051 static void
1052 _device_handle_pointer_motion(struct libinput_device *device, struct libinput_event_pointer *event)
1053 {
1054    E_Input_Evdev *edev;
1055    double delta_x[2]; /* delta_x[0] for accelerated, delta_x[1] for unaccelerated */
1056    double delta_y[2]; /* delta_y[0] for accelerated, delta_y[1] for unaccelerated */
1057
1058    if (!(edev = libinput_device_get_user_data(device)))
1059      {
1060         return;
1061      }
1062
1063    delta_x[0] = libinput_event_pointer_get_dx(event);
1064    delta_x[1] = libinput_event_pointer_get_dx_unaccelerated(event);
1065    delta_y[0] = libinput_event_pointer_get_dy(event);
1066    delta_y[1] = libinput_event_pointer_get_dy_unaccelerated(event);
1067
1068    _device_pointer_motion_send(edev, event, &delta_x[0], &delta_y[0]);
1069 }
1070
1071 static void
1072 _device_handle_pointer_motion_absolute(struct libinput_device *device, struct libinput_event_pointer *event)
1073 {
1074    E_Input_Evdev *edev;
1075    int w = 0, h = 0;
1076
1077    if (!(edev = libinput_device_get_user_data(device)))
1078      {
1079         return;
1080      }
1081
1082    e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &w, &h);
1083
1084    edev->mouse.dx = edev->seat->ptr.dx =
1085      libinput_event_pointer_get_absolute_x_transformed(event, w);
1086    edev->mouse.dy = edev->seat->ptr.dy =
1087      libinput_event_pointer_get_absolute_y_transformed(event, h);
1088
1089    if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
1090        floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
1091      {
1092         return;
1093      }
1094
1095    edev->seat->ptr.ix = edev->seat->ptr.dx;
1096    edev->seat->ptr.iy = edev->seat->ptr.dy;
1097
1098    if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1099        (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1100      {
1101         return;
1102      }
1103
1104    _device_pointer_motion(edev, event);
1105 }
1106
1107 static void
1108 _device_handle_button(struct libinput_device *device, struct libinput_event_pointer *event)
1109 {
1110    E_Input_Evdev *edev;
1111    E_Input_Backend *input;
1112    Ecore_Event_Mouse_Button *ev;
1113    enum libinput_button_state state;
1114    uint32_t button, timestamp;
1115    Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1116    Eina_List *l;
1117    E_Comp_Config *comp_conf = NULL;
1118
1119    if (!(edev = libinput_device_get_user_data(device)))
1120      {
1121         return;
1122      }
1123    if (!(input = edev->seat->input))
1124      {
1125         return;
1126      }
1127
1128    ecore_thread_main_loop_begin();
1129
1130    if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1131    else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1132      {
1133         EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1134           {
1135              if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1136                {
1137                   ecore_dev = data;
1138                   break;
1139                }
1140              else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1141                {
1142                   detent_data = data;
1143                }
1144           }
1145         if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1146           {
1147              ecore_dev = detent_data;
1148           }
1149      }
1150    else
1151      {
1152         edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1153         ecore_dev = edev->ecore_dev;
1154      }
1155
1156    if (!ecore_dev)
1157      {
1158         ERR("Failed to get source ecore device from event !\n");
1159         goto end;
1160      }
1161
1162    state = libinput_event_pointer_get_button_state(event);
1163    button = libinput_event_pointer_get_button(event);
1164    timestamp = libinput_event_pointer_get_time(event);
1165
1166    button = ((button & 0x00F) + 1);
1167    if (button == 3) button = 2;
1168    else if (button == 2) button = 3;
1169
1170    if (state)
1171      {
1172         if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1173             (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1174           {
1175              ELOGF("Mouse", "Button Press (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
1176                    button, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
1177                    edev->seat->dev->server_blocked);
1178              goto end;
1179           }
1180         else
1181           {
1182              edev->mouse.pressed_button |= (1 << button);
1183           }
1184      }
1185    else
1186      {
1187         if (!(edev->mouse.pressed_button & (1 << button)))
1188           {
1189              ELOGF("Mouse", "Button Release (btn: %d, device: %s) is blocked by %p, server: 0x%x", NULL,
1190                    button, ecore_device_name_get(ecore_dev), edev->seat->dev->blocked_client,
1191                    edev->seat->dev->server_blocked);
1192              goto end;
1193           }
1194         edev->mouse.pressed_button &= ~(1 << button);
1195      }
1196
1197    if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button))))
1198      {
1199         goto end;
1200      }
1201
1202    ev->window = (Ecore_Window)input->dev->window;
1203    ev->event_window = (Ecore_Window)input->dev->window;
1204    ev->root_window = (Ecore_Window)input->dev->window;
1205    ev->timestamp = timestamp;
1206    ev->same_screen = 1;
1207
1208    _device_modifiers_update(edev);
1209    ev->modifiers = edev->xkb.modifiers;
1210
1211    ev->x = edev->seat->ptr.ix;
1212    ev->y = edev->seat->ptr.iy;
1213    ev->root.x = ev->x;
1214    ev->root.y = ev->y;
1215
1216    ev->multi.device = edev->mt_slot;
1217    ev->multi.radius = 1;
1218    ev->multi.radius_x = 1;
1219    ev->multi.radius_y = 1;
1220    ev->multi.pressure = 1.0;
1221    ev->multi.angle = 0.0;
1222    ev->multi.x = ev->x;
1223    ev->multi.y = ev->y;
1224    ev->multi.root.x = ev->x;
1225    ev->multi.root.y = ev->y;
1226    ev->dev = ecore_device_ref(ecore_dev);
1227
1228    if (state)
1229      {
1230         unsigned int current;
1231
1232         current = timestamp;
1233         edev->mouse.did_double = EINA_FALSE;
1234         edev->mouse.did_triple = EINA_FALSE;
1235
1236         if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1237             (button == edev->mouse.prev_button))
1238           {
1239              edev->mouse.did_double = EINA_TRUE;
1240              if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1241                  (button == edev->mouse.last_button))
1242                {
1243                   edev->mouse.did_triple = EINA_TRUE;
1244                   edev->mouse.prev = 0;
1245                   edev->mouse.last = 0;
1246                   current = 0;
1247                }
1248           }
1249
1250         edev->mouse.last = edev->mouse.prev;
1251         edev->mouse.prev = current;
1252         edev->mouse.last_button = edev->mouse.prev_button;
1253         edev->mouse.prev_button = button;
1254      }
1255
1256    ev->buttons = button;
1257
1258    if (edev->mouse.did_double)
1259      ev->double_click = 1;
1260    if (edev->mouse.did_triple)
1261      ev->triple_click = 1;
1262
1263    comp_conf = e_comp_config_get();
1264    if (comp_conf && comp_conf->input_log_enable)
1265      ELOGF("Mouse", "Button %s (btn: %d, device: %s)", NULL, state?"Press":"Release", button, ecore_device_name_get(ev->dev));
1266
1267    if (state)
1268      ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, _e_input_event_mouse_button_cb_free, NULL);
1269    else
1270      ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, _e_input_event_mouse_button_cb_free, NULL);
1271
1272 end:
1273    ecore_thread_main_loop_end();
1274 }
1275
1276 #if !LIBINPUT_HAVE_SCROLL_VALUE_V120
1277 static int
1278 _axis_value_get(struct libinput_event_pointer *pointer_event, enum libinput_pointer_axis axis)
1279 {
1280    enum libinput_pointer_axis_source source;
1281    double value = 0.0, value_discrete = 0.0;
1282    int ret = 0;
1283    E_Comp_Config *comp_conf = NULL;
1284
1285    comp_conf = e_comp_config_get();
1286    source = libinput_event_pointer_get_axis_source(pointer_event);
1287    switch (source)
1288      {
1289       case LIBINPUT_POINTER_AXIS_SOURCE_WHEEL:
1290         value_discrete = libinput_event_pointer_get_axis_value_discrete(pointer_event, axis);
1291         value = libinput_event_pointer_get_axis_value(pointer_event, axis);
1292         if (comp_conf && comp_conf->input_log_enable)
1293           {
1294              ELOGF("Axis", "SOURCE_WHEEL discrete: %lf (cf. value: %lf)", NULL, value_discrete, value);
1295           }
1296         ret = (int)value_discrete;
1297         break;
1298       case LIBINPUT_POINTER_AXIS_SOURCE_FINGER:
1299       case LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS:
1300         value = libinput_event_pointer_get_axis_value(pointer_event, axis);
1301         if (comp_conf && comp_conf->input_log_enable)
1302           {
1303              ELOGF("Axis", "SOURCE_FINGER/CONTINUOUS value: %lf", NULL, value);
1304           }
1305         if (value >= E_INPUT_FINGER_SCROLL_THRESHOLD)
1306           ret = 1;
1307         else if (value <= E_INPUT_FINGER_SCROLL_THRESHOLD * (-1))
1308           ret = -1;
1309         else
1310           ret = 0;
1311         break;
1312       default:
1313         break;
1314      }
1315
1316    return ret;
1317 }
1318
1319 static void
1320 _device_handle_axis(struct libinput_device *device, struct libinput_event_pointer *event)
1321 {
1322    E_Input_Evdev *edev;
1323    E_Input_Backend *input;
1324    Ecore_Event_Mouse_Wheel *ev;
1325    uint32_t timestamp;
1326    enum libinput_pointer_axis axis;
1327    Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1328    Eina_List *l;
1329    E_Comp_Config *comp_conf = NULL;
1330    int direction = 0, z = 0;
1331
1332    if (!(edev = libinput_device_get_user_data(device)))
1333      {
1334         return;
1335      }
1336    if (!(input = edev->seat->input))
1337      {
1338         return;
1339      }
1340
1341    ecore_thread_main_loop_begin();
1342
1343    if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1344    else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1345      {
1346         EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1347           {
1348              if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1349                {
1350                   ecore_dev = data;
1351                   break;
1352                }
1353              else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1354                {
1355                   detent_data = data;
1356                }
1357           }
1358         if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1359           {
1360              ecore_dev = detent_data;
1361           }
1362      }
1363    else
1364      {
1365         edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1366         ecore_dev = edev->ecore_dev;
1367      }
1368
1369    if (!ecore_dev)
1370      {
1371         ERR("Failed to get source ecore device from event !\n");
1372         goto end;
1373      }
1374
1375    axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1376    if (libinput_event_pointer_has_axis(event, axis))
1377      z = _axis_value_get(event, axis);
1378
1379    axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1380    if (libinput_event_pointer_has_axis(event, axis))
1381      {
1382         direction = 1;
1383         z = _axis_value_get(event, axis);
1384      }
1385
1386   if (z == 0)
1387     {
1388        ELOGF("Mouse", "Axis event is ignored since it has zero value", NULL);
1389        goto end;
1390     }
1391
1392    comp_conf = e_comp_config_get();
1393    if (comp_conf && comp_conf->e_wheel_click_angle)
1394      {
1395         z = (int)(z * comp_conf->e_wheel_click_angle);
1396      }
1397
1398    if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1399        (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1400      {
1401         if (detent_data)
1402           ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1403                 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1404         else
1405           ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1406                 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1407         goto end;
1408      }
1409
1410    if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1411      {
1412         goto end;
1413      }
1414
1415    timestamp = libinput_event_pointer_get_time(event);
1416
1417    ev->window = (Ecore_Window)input->dev->window;
1418    ev->event_window = (Ecore_Window)input->dev->window;
1419    ev->root_window = (Ecore_Window)input->dev->window;
1420    ev->timestamp = timestamp;
1421    ev->same_screen = 1;
1422
1423    _device_modifiers_update(edev);
1424    ev->modifiers = edev->xkb.modifiers;
1425
1426    ev->x = edev->seat->ptr.ix;
1427    ev->y = edev->seat->ptr.iy;
1428    ev->root.x = ev->x;
1429    ev->root.y = ev->y;
1430    ev->z = z;
1431    ev->direction = direction;
1432
1433    if (comp_conf && comp_conf->input_log_enable)
1434      {
1435         if (detent_data)
1436           ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1437         else
1438           ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1439      }
1440
1441
1442    ev->dev = ecore_device_ref(ecore_dev);
1443    ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1444
1445 end:
1446    ecore_thread_main_loop_end();
1447 }
1448 #endif
1449
1450 #if LIBINPUT_HAVE_SCROLL_VALUE_V120
1451 static int
1452 _scroll_value_get(struct libinput_event_pointer *pointer_event, enum libinput_pointer_axis axis, E_Input_Axis_Source source)
1453 {
1454    double value = 0.0;
1455    double value_v120 = 0.0;
1456    int ret;
1457    E_Comp_Config *comp_conf = NULL;
1458
1459    comp_conf = e_comp_config_get();
1460    switch (source)
1461      {
1462       case E_INPUT_AXIS_SOURCE_WHEEL:
1463         value_v120 = libinput_event_pointer_get_scroll_value_v120(pointer_event, axis);
1464         value = libinput_event_pointer_get_scroll_value(pointer_event, axis);
1465         if (comp_conf && comp_conf->input_log_enable)
1466           {
1467              ELOGF("Scroll", "SOURCE_WHEELL value_v120: %lf (cf. value: %lf)", NULL, value_v120, value);
1468           }
1469         if (((int)value_v120 % E_INPUT_POINTER_AXIS_DISCRETE_STEP) != 0)
1470           {
1471              ERR("Wheel movements should be multiples (or fractions) of 120!\n");
1472              ret = 0;
1473           }
1474         else
1475           {
1476              ret = value_v120 / E_INPUT_POINTER_AXIS_DISCRETE_STEP;
1477           }
1478         break;
1479       case E_INPUT_AXIS_SOURCE_FINGER:
1480       case E_INPUT_AXIS_SOURCE_CONTINUOUS:
1481         value = libinput_event_pointer_get_scroll_value(pointer_event, axis);
1482         if (comp_conf && comp_conf->input_log_enable)
1483           {
1484              ELOGF("Scroll", "SOURCE_FINGER/CONTINUOUS value: %lf", NULL, value);
1485           }
1486         if (value >= E_INPUT_FINGER_SCROLL_THRESHOLD)
1487           ret = 1;
1488         else if (value <= E_INPUT_FINGER_SCROLL_THRESHOLD * (-1))
1489           ret = -1;
1490         else
1491           ret = 0;
1492         break;
1493       default:
1494         break;
1495      }
1496
1497    return ret;
1498 }
1499
1500 static void
1501 _device_handle_axis_v120(struct libinput_device *device, struct libinput_event_pointer *event, E_Input_Axis_Source source)
1502 {
1503    E_Input_Evdev *edev;
1504    E_Input_Backend *input;
1505    Ecore_Event_Mouse_Wheel *ev;
1506    uint32_t timestamp;
1507    enum libinput_pointer_axis axis;
1508    Ecore_Device *ecore_dev = NULL, *detent_data = NULL, *data;
1509    Eina_List *l;
1510    E_Comp_Config *comp_conf = NULL;
1511    int direction = 0, z = 0;
1512
1513    if (!(edev = libinput_device_get_user_data(device)))
1514      {
1515         return;
1516      }
1517    if (!(input = edev->seat->input))
1518      {
1519         return;
1520      }
1521
1522    ecore_thread_main_loop_begin();
1523
1524    if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1525    else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1526      {
1527         EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1528           {
1529              if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_MOUSE)
1530                {
1531                   ecore_dev = data;
1532                   break;
1533                }
1534              else if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_NONE)
1535                {
1536                   detent_data = data;
1537                }
1538           }
1539         if (!ecore_dev && e_devicemgr_detent_is_detent(libinput_device_get_name(edev->device)))
1540           {
1541              ecore_dev = detent_data;
1542           }
1543      }
1544    else
1545      {
1546         edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_MOUSE);
1547         ecore_dev = edev->ecore_dev;
1548      }
1549
1550    if (!ecore_dev)
1551      {
1552         ERR("Failed to get source ecore device from event !\n");
1553         goto end;
1554      }
1555
1556    axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
1557    if (libinput_event_pointer_has_axis(event, axis))
1558      z = _scroll_value_get(event, axis, source);
1559
1560    axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
1561    if (libinput_event_pointer_has_axis(event, axis))
1562      {
1563         direction = 1;
1564         z = _scroll_value_get(event, axis, source);
1565      }
1566
1567    if (z == 0)
1568      {
1569         ELOGF("Mouse", "Scroll event is ignored since it has zero value", NULL);
1570         goto end;
1571      }
1572
1573    comp_conf = e_comp_config_get();
1574    if (comp_conf && comp_conf->e_wheel_click_angle)
1575      {
1576         z = (int)(z * comp_conf->e_wheel_click_angle);
1577      }
1578
1579    if ((edev->seat->dev->blocked & E_INPUT_SEAT_POINTER) ||
1580        (edev->seat->dev->server_blocked & E_INPUT_SEAT_POINTER))
1581      {
1582         if (detent_data)
1583           ELOGF("Mouse", "Detent (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1584                 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1585         else
1586           ELOGF("Mouse", "Wheel (direction: %d, value: %d) is blocked by %p, server: 0x%x", NULL,
1587                 direction, z, edev->seat->dev->blocked_client, edev->seat->dev->server_blocked);
1588         goto end;
1589      }
1590
1591    if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Wheel))))
1592      {
1593         goto end;
1594      }
1595
1596    timestamp = libinput_event_pointer_get_time(event);
1597
1598    ev->window = (Ecore_Window)input->dev->window;
1599    ev->event_window = (Ecore_Window)input->dev->window;
1600    ev->root_window = (Ecore_Window)input->dev->window;
1601    ev->timestamp = timestamp;
1602    ev->same_screen = 1;
1603
1604    _device_modifiers_update(edev);
1605    ev->modifiers = edev->xkb.modifiers;
1606
1607    ev->x = edev->seat->ptr.ix;
1608    ev->y = edev->seat->ptr.iy;
1609    ev->root.x = ev->x;
1610    ev->root.y = ev->y;
1611    ev->z = z;
1612    ev->direction = direction;
1613
1614    if (comp_conf && comp_conf->input_log_enable)
1615      {
1616         if (detent_data)
1617           ELOGF("Mouse", "Detent (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1618         else
1619           ELOGF("Mouse", "Wheel (direction: %d, value: %d)", NULL, ev->direction, ev->z);
1620      }
1621
1622    ev->dev = ecore_device_ref(ecore_dev);
1623    ecore_event_add(ECORE_EVENT_MOUSE_WHEEL, ev, _e_input_event_mouse_wheel_cb_free, NULL);
1624
1625 end:
1626    ecore_thread_main_loop_end();
1627 }
1628 #endif
1629
1630 static void
1631 _device_handle_touch_event_send(E_Input_Evdev *edev, struct libinput_event_touch *event, int state)
1632 {
1633    E_Input_Backend *input;
1634    Ecore_Event_Mouse_Button *ev;
1635    uint32_t timestamp, button = 0;
1636    Ecore_Device *ecore_dev = NULL, *data;
1637    Eina_List *l;
1638
1639    if (!edev) return;
1640    if (!(input = edev->seat->input)) return;
1641
1642    ecore_thread_main_loop_begin();
1643
1644    if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1645    else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1646      {
1647         EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1648           {
1649              if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1650                {
1651                   ecore_dev = data;
1652                   break;
1653                }
1654           }
1655      }
1656    else
1657      {
1658         edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1659         ecore_dev = edev->ecore_dev;
1660      }
1661
1662    if (!ecore_dev)
1663      {
1664         ERR("Failed to get source ecore device from event !\n");
1665         goto end;
1666      }
1667
1668    if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) goto end;
1669
1670    timestamp = libinput_event_touch_get_time(event);
1671
1672    ev->window = (Ecore_Window)input->dev->window;
1673    ev->event_window = (Ecore_Window)input->dev->window;
1674    ev->root_window = (Ecore_Window)input->dev->window;
1675    ev->timestamp = timestamp;
1676    ev->same_screen = 1;
1677
1678    _device_modifiers_update(edev);
1679    ev->modifiers = edev->xkb.modifiers;
1680
1681    ev->x = edev->seat->ptr.ix;
1682    ev->y = edev->seat->ptr.iy;
1683    ev->root.x = ev->x;
1684    ev->root.y = ev->y;
1685
1686    ev->multi.device = edev->mt_slot;
1687    ev->multi.radius = 1;
1688    ev->multi.radius_x = 1;
1689    ev->multi.radius_y = 1;
1690    ev->multi.pressure = 1.0;
1691    ev->multi.angle = 0.0;
1692 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1693    if (libinput_event_get_type(libinput_event_touch_get_base_event(event))
1694        == LIBINPUT_EVENT_TOUCH_DOWN)
1695      {
1696         if (libinput_event_touch_has_minor(event))
1697           ev->multi.radius_x = libinput_event_touch_get_minor(event);
1698         if (libinput_event_touch_has_major(event))
1699           ev->multi.radius_y = libinput_event_touch_get_major(event);
1700         if (libinput_event_touch_has_pressure(event))
1701           ev->multi.pressure = libinput_event_touch_get_pressure(event);
1702         if (libinput_event_touch_has_orientation(event))
1703           ev->multi.angle = libinput_event_touch_get_orientation(event);
1704      }
1705 #endif
1706    ev->multi.x = ev->x;
1707    ev->multi.y = ev->y;
1708    ev->multi.root.x = ev->x;
1709    ev->multi.root.y = ev->y;
1710    ev->dev = ecore_device_ref(ecore_dev);
1711
1712    if (state == ECORE_EVENT_MOUSE_BUTTON_DOWN)
1713      {
1714         unsigned int current;
1715
1716         current = timestamp;
1717         edev->mouse.did_double = EINA_FALSE;
1718         edev->mouse.did_triple = EINA_FALSE;
1719
1720         if (((current - edev->mouse.prev) <= edev->mouse.threshold) &&
1721             (button == edev->mouse.prev_button))
1722           {
1723              edev->mouse.did_double = EINA_TRUE;
1724              if (((current - edev->mouse.last) <= (2 * edev->mouse.threshold)) &&
1725                  (button == edev->mouse.last_button))
1726                {
1727                   edev->mouse.did_triple = EINA_TRUE;
1728                   edev->mouse.prev = 0;
1729                   edev->mouse.last = 0;
1730                   current = 0;
1731                }
1732           }
1733
1734         edev->mouse.last = edev->mouse.prev;
1735         edev->mouse.prev = current;
1736         edev->mouse.last_button = edev->mouse.prev_button;
1737         edev->mouse.prev_button = button;
1738         edev->touch.pressed |= (1 << ev->multi.device);
1739      }
1740    else
1741      {
1742         edev->touch.pressed &= ~(1 << ev->multi.device);
1743      }
1744
1745    ev->buttons = ((button & 0x00F) + 1);
1746
1747    if (edev->mouse.did_double)
1748      ev->double_click = 1;
1749    if (edev->mouse.did_triple)
1750      ev->triple_click = 1;
1751
1752    ecore_event_add(state, ev, _e_input_event_mouse_button_cb_free, NULL);
1753
1754 end:
1755    ecore_thread_main_loop_end();
1756 }
1757
1758 static void
1759 _device_handle_touch_motion_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1760 {
1761    E_Input_Backend *input;
1762    Ecore_Event_Mouse_Move *ev;
1763    Ecore_Device *ecore_dev = NULL, *data;
1764    Eina_List *l;
1765
1766    if (!edev) return;
1767    if (!(input = edev->seat->input)) return;
1768
1769    ecore_thread_main_loop_begin();
1770
1771    if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1772    else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1773      {
1774         EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1775           {
1776              if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1777                {
1778                   ecore_dev = data;
1779                   break;
1780                }
1781           }
1782      }
1783    else
1784      {
1785         edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1786         ecore_dev = edev->ecore_dev;
1787      }
1788
1789    if (!ecore_dev)
1790      {
1791         ERR("Failed to get source ecore device from event !\n");
1792         goto end;
1793      }
1794
1795    if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)))) goto end;
1796
1797    ev->window = (Ecore_Window)input->dev->window;
1798    ev->event_window = (Ecore_Window)input->dev->window;
1799    ev->root_window = (Ecore_Window)input->dev->window;
1800    ev->timestamp = libinput_event_touch_get_time(event);
1801    ev->same_screen = 1;
1802
1803    _device_modifiers_update(edev);
1804    ev->modifiers = edev->xkb.modifiers;
1805
1806    ev->x = edev->seat->ptr.ix;
1807    ev->y = edev->seat->ptr.iy;
1808    ev->root.x = ev->x;
1809    ev->root.y = ev->y;
1810
1811    ev->multi.device = edev->mt_slot;
1812    ev->multi.radius = 1;
1813    ev->multi.radius_x = 1;
1814    ev->multi.radius_y = 1;
1815    ev->multi.pressure = 1.0;
1816    ev->multi.angle = 0.0;
1817 #if LIBINPUT_SUPPORT_EXTRA_TOUCH_EVENT
1818    if (libinput_event_touch_has_minor(event))
1819      ev->multi.radius_x = libinput_event_touch_get_minor(event);
1820    if (libinput_event_touch_has_major(event))
1821      ev->multi.radius_y = libinput_event_touch_get_major(event);
1822    if (libinput_event_touch_has_pressure(event))
1823      ev->multi.pressure = libinput_event_touch_get_pressure(event);
1824    if (libinput_event_touch_has_orientation(event))
1825      ev->multi.angle = libinput_event_touch_get_orientation(event);
1826 #endif
1827    ev->multi.x = ev->x;
1828    ev->multi.y = ev->y;
1829    ev->multi.root.x = ev->x;
1830    ev->multi.root.y = ev->y;
1831    ev->dev = ecore_device_ref(ecore_dev);
1832
1833    ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, _e_input_event_mouse_move_cb_free, NULL);
1834
1835 end:
1836    ecore_thread_main_loop_end();
1837 }
1838
1839 static void
1840 _device_handle_touch_cancel_send(E_Input_Evdev *edev, struct libinput_event_touch *event)
1841 {
1842    E_Input_Backend *input;
1843    Ecore_Event_Mouse_Button *ev;
1844    uint32_t timestamp, button = 0;
1845    Ecore_Device *ecore_dev = NULL, *data;
1846    Eina_List *l;
1847
1848    if (!edev) return;
1849    if (!(input = edev->seat->input)) return;
1850
1851    ecore_thread_main_loop_begin();
1852
1853    if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
1854    else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
1855      {
1856         EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
1857           {
1858              if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
1859                {
1860                   ecore_dev = data;
1861                   break;
1862                }
1863           }
1864      }
1865    else
1866      {
1867         edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
1868         ecore_dev = edev->ecore_dev;
1869      }
1870
1871    if (!ecore_dev)
1872      {
1873         ERR("Failed to get source ecore device from event !\n");
1874         goto end;
1875      }
1876
1877    if (!(ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)))) goto end;
1878
1879    timestamp = libinput_event_touch_get_time(event);
1880
1881    ev->window = (Ecore_Window)input->dev->window;
1882    ev->event_window = (Ecore_Window)input->dev->window;
1883    ev->root_window = (Ecore_Window)input->dev->window;
1884    ev->timestamp = timestamp;
1885    ev->same_screen = 1;
1886
1887    ev->x = edev->seat->ptr.ix;
1888    ev->y = edev->seat->ptr.iy;
1889    ev->root.x = ev->x;
1890    ev->root.y = ev->y;
1891
1892    ev->multi.device = edev->mt_slot;
1893    ev->multi.radius = 1;
1894    ev->multi.radius_x = 1;
1895    ev->multi.radius_y = 1;
1896    ev->multi.pressure = 1.0;
1897    ev->multi.angle = 0.0;
1898    ev->multi.x = ev->x;
1899    ev->multi.y = ev->y;
1900    ev->multi.root.x = ev->x;
1901    ev->multi.root.y = ev->y;
1902
1903    edev->touch.pressed &= ~(1 << ev->multi.device);
1904
1905    ev->buttons = ((button & 0x00F) + 1);
1906    ev->dev = ecore_device_ref(ecore_dev);
1907
1908    ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_CANCEL, ev, _e_input_event_mouse_button_cb_free, NULL);
1909
1910 end:
1911    ecore_thread_main_loop_end();
1912 }
1913
1914 static void
1915 _device_configured_size_get(E_Input_Evdev *edev, int *x, int *y, int *w, int *h)
1916 {
1917    E_Output *output = NULL;
1918
1919    EINA_SAFETY_ON_NULL_RETURN(edev);
1920
1921    if (!edev->output_configured)
1922      {
1923         if (edev->output_name)
1924           {
1925              output = e_output_find(edev->output_name);
1926              if (output)
1927                {
1928                   edev->mouse.minx = output->config.geom.x;
1929                   edev->mouse.miny = output->config.geom.y;
1930                   edev->mouse.maxw = output->config.geom.w;
1931                   edev->mouse.maxh = output->config.geom.h;
1932                   if (libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
1933                     {
1934                        edev->seat->ptr.dx = (double)(edev->mouse.maxw / 2);
1935                        edev->seat->ptr.dy = (double)(edev->mouse.maxh / 2);
1936                        edev->seat->ptr.ix = (int)edev->seat->ptr.dx;
1937                        edev->seat->ptr.iy = (int)edev->seat->ptr.dy;
1938                        edev->mouse.dx = edev->seat->ptr.dx;
1939                        edev->mouse.dy = edev->seat->ptr.dy;
1940                     }
1941                }
1942           }
1943
1944           edev->output_configured = EINA_TRUE;
1945           ELOGF("E_INPUT_EVDEV", "Device is configured by output x:%d,y:%d (w:%d, h:%d)",
1946                 NULL, edev->mouse.minx, edev->mouse.miny, edev->mouse.maxw, edev->mouse.maxh);
1947      }
1948    if (x) *x = edev->mouse.minx;
1949    if (y) *y = edev->mouse.miny;
1950    if (w) *w = edev->mouse.maxw;
1951    if (h) *h = edev->mouse.maxh;
1952 }
1953
1954 static void
1955 _device_handle_touch_down(struct libinput_device *device, struct libinput_event_touch *event)
1956 {
1957    E_Input_Evdev *edev;
1958    int x = 0, y = 0, w = 0, h = 0;
1959    E_Comp_Config *comp_conf = NULL;
1960
1961    if (!(edev = libinput_device_get_user_data(device)))
1962      {
1963         return;
1964      }
1965
1966    _device_configured_size_get(edev, &x, &y, &w, &h);
1967
1968    edev->mouse.dx = edev->seat->ptr.ix = edev->seat->ptr.dx =
1969      x + libinput_event_touch_get_x_transformed(event, w);
1970    edev->mouse.dy = edev->seat->ptr.iy = edev->seat->ptr.dy =
1971      y + libinput_event_touch_get_y_transformed(event, h);
1972
1973    edev->mt_slot = libinput_event_touch_get_slot(event);
1974    if (edev->mt_slot < 0)
1975      {
1976         /* FIXME: The single touch device return slot id -1
1977          *        But currently we have no API to distinguish multi touch or single touch
1978          *        After libinput 1.11 version, libinput provides get_touch_count API,
1979          *        so we can distinguish multi touch device or single touch device.
1980          */
1981         if (edev->mt_slot == -1)
1982           edev->mt_slot = 0;
1983         else
1984           {
1985              WRN("%d slot touch down events are not supported\n", edev->mt_slot);
1986              return;
1987           }
1988      }
1989
1990    if (edev->mt_slot < e_input_touch_max_count_get())
1991      {
1992         edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
1993         edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
1994      }
1995
1996    comp_conf = e_comp_config_get();
1997    if (comp_conf && comp_conf->input_log_enable)
1998      ELOGF("Touch", "Down (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
1999
2000    edev->touch.raw_pressed |= (1 << edev->mt_slot);
2001
2002    if (edev->touch.blocked)
2003      {
2004         ELOGF("Touch", "Down (id: %d, x: %d, y: %d) is blocked by %p, server: 0x%x", NULL,
2005               edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, edev->seat->dev->blocked_client,
2006               edev->seat->dev->server_blocked);
2007         return;
2008      }
2009
2010    _device_handle_touch_motion_send(edev, event);
2011    _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_DOWN);
2012 }
2013
2014 static void
2015 _device_handle_touch_motion(struct libinput_device *device, struct libinput_event_touch *event)
2016 {
2017    E_Input_Evdev *edev;
2018    int x = 0, y = 0, w = 0, h = 0;
2019
2020    if (!(edev = libinput_device_get_user_data(device)))
2021      {
2022         return;
2023      }
2024
2025    _device_configured_size_get(edev, &x, &y, &w, &h);
2026
2027    edev->mouse.dx = edev->seat->ptr.dx =
2028      x + libinput_event_touch_get_x_transformed(event, w);
2029    edev->mouse.dy = edev->seat->ptr.dy =
2030      y + libinput_event_touch_get_y_transformed(event, h);
2031
2032    if (floor(edev->seat->ptr.dx) == edev->seat->ptr.ix &&
2033        floor(edev->seat->ptr.dy) == edev->seat->ptr.iy)
2034      {
2035         return;
2036      }
2037
2038    edev->seat->ptr.ix = edev->seat->ptr.dx;
2039    edev->seat->ptr.iy = edev->seat->ptr.dy;
2040
2041    edev->mt_slot = libinput_event_touch_get_slot(event);
2042    if (edev->mt_slot < 0)
2043      {
2044         /* FIXME: The single touch device return slot id -1
2045          *        But currently we have no API to distinguish multi touch or single touch
2046          *        After libinput 1.11 version, libinput provides get_touch_count API,
2047          *        so we can distinguish multi touch device or single touch device.
2048          */
2049         if (edev->mt_slot == -1)
2050           edev->mt_slot = 0;
2051         else
2052           {
2053              WRN("%d slot touch motion events are not supported\n", edev->mt_slot);
2054              return;
2055           }
2056      }
2057
2058    if (edev->mt_slot < e_input_touch_max_count_get())
2059      {
2060         edev->touch.coords[edev->mt_slot].x = edev->seat->ptr.ix;
2061         edev->touch.coords[edev->mt_slot].y = edev->seat->ptr.iy;
2062      }
2063
2064    if (!(edev->touch.pressed & (1 << edev->mt_slot)))
2065      {
2066         if (edev->touch.blocked)
2067           {
2068              return;
2069           }
2070      }
2071
2072    _device_handle_touch_motion_send(edev, event);
2073 }
2074
2075 static void
2076 _device_handle_touch_up(struct libinput_device *device, struct libinput_event_touch *event)
2077 {
2078    E_Input_Evdev *edev;
2079    E_Comp_Config *comp_conf = NULL;
2080
2081    if (!(edev = libinput_device_get_user_data(device)))
2082      {
2083         return;
2084      }
2085
2086    edev->mt_slot = libinput_event_touch_get_slot(event);
2087    if (edev->mt_slot < 0)
2088      {
2089         /* FIXME: The single touch device return slot id -1
2090          *        But currently we have no API to distinguish multi touch or single touch
2091          *        After libinput 1.11 version, libinput provides get_touch_count API,
2092          *        so we can distinguish multi touch device or single touch device.
2093          */
2094         if (edev->mt_slot == -1)
2095           edev->mt_slot = 0;
2096         else
2097           {
2098              WRN("%d slot touch up events are not supported\n", edev->mt_slot);
2099              return;
2100           }
2101      }
2102
2103    if (edev->mt_slot < e_input_touch_max_count_get())
2104      {
2105         edev->mouse.dx = edev->seat->ptr.dx = edev->seat->ptr.ix =
2106           edev->touch.coords[edev->mt_slot].x;
2107         edev->mouse.dy = edev->seat->ptr.dy = edev->seat->ptr.iy =
2108           edev->touch.coords[edev->mt_slot].y;
2109      }
2110
2111    comp_conf = e_comp_config_get();
2112    if (comp_conf && comp_conf->input_log_enable)
2113      ELOGF("Touch", "Up (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2114
2115    edev->touch.raw_pressed &= ~(1 << edev->mt_slot);
2116
2117    if (edev->touch.blocked)
2118      {
2119         if (!(edev->touch.pressed & (1 << edev->mt_slot)))
2120           {
2121              ELOGF("Touch", "Up (id: %d, x: %d, y: %d) is blocked by %p, server(0x%x)", NULL,
2122                    edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy, edev->seat->dev->blocked_client,
2123                    edev->seat->dev->server_blocked);
2124              if (edev->touch.raw_pressed == 0x0)
2125                {
2126                   edev->touch.blocked = EINA_FALSE;
2127                }
2128              return;
2129           }
2130      }
2131
2132    _device_handle_touch_event_send(edev, event, ECORE_EVENT_MOUSE_BUTTON_UP);
2133 }
2134
2135 static void
2136 _device_handle_touch_cancel(struct libinput_device *device, struct libinput_event_touch *event)
2137 {
2138    E_Input_Evdev *edev;
2139    E_Comp_Config *comp_conf = NULL;
2140
2141    if (!(edev = libinput_device_get_user_data(device)))
2142      {
2143         return;
2144      }
2145
2146    edev->mt_slot = libinput_event_touch_get_slot(event);
2147    if (edev->mt_slot < 0)
2148      {
2149         /* FIXME: The single touch device return slot id -1
2150          *        But currently we have no API to distinguish multi touch or single touch
2151          *        After libinput 1.11 version, libinput provides get_touch_count API,
2152          *        so we can distinguish multi touch device or single touch device.
2153          */
2154         if (edev->mt_slot == -1)
2155           edev->mt_slot = 0;
2156         else
2157           {
2158              WRN("%d slot touch up events are not supported\n", edev->mt_slot);
2159              return;
2160           }
2161      }
2162
2163    comp_conf = e_comp_config_get();
2164    if (comp_conf && comp_conf->input_log_enable)
2165      ELOGF("Touch", "cancel (id: %d, x: %d, y: %d)", NULL, edev->mt_slot, edev->seat->ptr.ix, edev->seat->ptr.iy);
2166
2167    _device_handle_touch_cancel_send(edev, event);
2168 }
2169
2170
2171 static void
2172 _device_handle_touch_frame(struct libinput_device *device EINA_UNUSED, struct libinput_event_touch *event EINA_UNUSED)
2173 {
2174    /* DBG("Unhandled Touch Frame Event"); */
2175 }
2176
2177 static void
2178 _e_input_aux_data_event_free(void *user_data EINA_UNUSED, void *ev)
2179 {
2180    Ecore_Event_Axis_Update *e = (Ecore_Event_Axis_Update *)ev;
2181
2182    if (e->axis) free(e->axis);
2183    if (e->dev) ecore_device_unref(e->dev);
2184
2185    free(e);
2186 }
2187
2188 static void
2189 _device_handle_touch_aux_data(struct libinput_device *device, struct libinput_event_touch_aux_data *event)
2190 {
2191    E_Input_Evdev *edev;
2192    E_Input_Backend *input;
2193    Ecore_Event_Axis_Update *ev;
2194    Ecore_Axis *axis;
2195    Ecore_Device *ecore_dev = NULL, *data;
2196    Eina_List *l;
2197    E_Comp_Config *comp_conf;
2198
2199    ecore_thread_main_loop_begin();
2200
2201    if (libinput_event_touch_aux_data_get_type(event) != LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM &&
2202        libinput_event_touch_aux_data_get_value(event) > 0)
2203       goto end;
2204
2205    if (!(edev = libinput_device_get_user_data(device))) goto end;
2206    if (!(input = edev->seat->input)) goto end;
2207
2208    if (edev->ecore_dev) ecore_dev = edev->ecore_dev;
2209    else if (edev->ecore_dev_list && eina_list_count(edev->ecore_dev_list) > 0)
2210      {
2211         EINA_LIST_FOREACH(edev->ecore_dev_list, l, data)
2212           {
2213              if (ecore_device_class_get(data) == ECORE_DEVICE_CLASS_TOUCH)
2214                {
2215                   ecore_dev = data;
2216                   break;
2217                }
2218           }
2219      }
2220    else
2221      {
2222         edev->ecore_dev = e_input_evdev_get_ecore_device(edev->path, ECORE_DEVICE_CLASS_TOUCH);
2223         ecore_dev = edev->ecore_dev;
2224      }
2225
2226    if (!ecore_dev)
2227      {
2228         ERR("Failed to get source ecore device from event !\n");
2229         goto end;
2230      }
2231
2232    if (!(ev = calloc(1, sizeof(Ecore_Event_Axis_Update)))) goto end;
2233
2234    ev->window = (Ecore_Window)input->dev->window;
2235    ev->event_window = (Ecore_Window)input->dev->window;
2236    ev->root_window = (Ecore_Window)input->dev->window;
2237    ev->timestamp = libinput_event_touch_aux_data_get_time(event);
2238
2239    axis = (Ecore_Axis *)calloc(1, sizeof(Ecore_Axis));
2240    if (axis)
2241      {
2242         axis->label = ECORE_AXIS_LABEL_TOUCH_PALM;
2243         axis->value = libinput_event_touch_aux_data_get_value(event);
2244         ev->naxis = 1;
2245      }
2246    ev->axis = axis;
2247
2248    comp_conf = e_comp_config_get();
2249    if (comp_conf && comp_conf->input_log_enable)
2250      ELOGF("Touch", "Axis (label: %d, value: %lf)", NULL, axis?axis->label:-1, axis?axis->value:0.0);
2251
2252    ev->dev = ecore_device_ref(ecore_dev);
2253
2254    ecore_event_add(ECORE_EVENT_AXIS_UPDATE, ev, _e_input_aux_data_event_free, NULL);
2255
2256 end:
2257    ecore_thread_main_loop_end();
2258 }
2259
2260 E_Input_Evdev *
2261 _e_input_evdev_device_create(E_Input_Seat *seat, struct libinput_device *device)
2262 {
2263    E_Input_Evdev *edev;
2264    E_Input_Backend *b_input;
2265    const char *output_name;
2266
2267    EINA_SAFETY_ON_NULL_RETURN_VAL(seat, NULL);
2268
2269    /* try to allocate space for new evdev */
2270    if (!(edev = calloc(1, sizeof(E_Input_Evdev)))) return NULL;
2271
2272    edev->seat = seat;
2273    edev->device = device;
2274    edev->path = eina_stringshare_printf("%s/%s", e_input_base_dir_get(), libinput_device_get_sysname(device));
2275
2276    if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_KEYBOARD))
2277      {
2278         edev->caps |= E_INPUT_SEAT_KEYBOARD;
2279         _device_keyboard_setup(edev);
2280      }
2281
2282    if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_POINTER))
2283      {
2284         edev->caps |= E_INPUT_SEAT_POINTER;
2285
2286         /* TODO: make this configurable */
2287         edev->mouse.threshold = 250;
2288
2289         b_input = seat->input;
2290         if (b_input->left_handed == EINA_TRUE)
2291           {
2292              if (libinput_device_config_left_handed_set(device, 1) !=
2293                  LIBINPUT_CONFIG_STATUS_SUCCESS)
2294                {
2295                   WRN("Failed to set left hand mode about device: %s\n",
2296                       libinput_device_get_name(device));
2297                }
2298           }
2299      }
2300
2301    if (libinput_device_has_capability(device, LIBINPUT_DEVICE_CAP_TOUCH))
2302      {
2303         int palm_code;
2304         edev->caps |= E_INPUT_SEAT_TOUCH;
2305         palm_code = libinput_device_touch_aux_data_get_code(LIBINPUT_TOUCH_AUX_DATA_TYPE_PALM);
2306         if (libinput_device_touch_has_aux_data(device, palm_code))
2307           {
2308              libinput_device_touch_set_aux_data(device, palm_code);
2309           }
2310
2311         _device_touch_count_update(edev);
2312
2313         edev->touch.coords = calloc(1, sizeof(E_Input_Coord)*e_input_touch_max_count_get());
2314
2315         if  (!edev->touch.coords)
2316           ERR("Failed to allocate memory for touch coords !\n");
2317      }
2318
2319    output_name = libinput_device_get_output_name(device);
2320    if (output_name)
2321      {
2322         eina_stringshare_replace(&edev->output_name, output_name);
2323         ELOGF("E_INPUT_EVDEV", "Device has output_name:%s", NULL, output_name);
2324      }
2325
2326    libinput_device_set_user_data(device, edev);
2327    libinput_device_ref(device);
2328
2329    /* configure device */
2330    _device_configure(edev);
2331
2332    return edev;
2333 }
2334
2335 void
2336 _e_input_evdev_device_destroy(E_Input_Evdev *edev)
2337 {
2338    Ecore_Device *dev;
2339
2340    EINA_SAFETY_ON_NULL_RETURN(edev);
2341
2342    ecore_thread_main_loop_begin();
2343
2344    if (edev->caps & E_INPUT_SEAT_KEYBOARD)
2345      {
2346         g_mutex_lock(&edev->xkb.state_mutex);
2347         if (edev->xkb.state) xkb_state_unref(edev->xkb.state);
2348         g_mutex_unlock(&edev->xkb.state_mutex);
2349
2350         g_mutex_lock(&edev->xkb.keymap_mutex);
2351         if (edev->xkb.keymap) xkb_map_unref(edev->xkb.keymap);
2352         g_mutex_unlock(&edev->xkb.keymap_mutex);
2353      }
2354
2355    if (edev->ecore_dev) ecore_device_del(edev->ecore_dev);
2356    if (edev->ecore_dev_list)
2357      EINA_LIST_FREE(edev->ecore_dev_list, dev)
2358        {
2359           ecore_device_del(dev);
2360        }
2361
2362    if (edev->e_dev) g_object_unref(edev->e_dev);
2363    if (edev->e_dev_list)
2364      {
2365         GList *glist = edev->e_dev_list;
2366         E_Device *e_dev;
2367         while (glist)
2368           {
2369              e_dev = glist->data;
2370              g_object_unref(e_dev);
2371
2372              glist = g_list_next(glist);
2373           }
2374      }
2375    if (edev->path) eina_stringshare_del(edev->path);
2376    if (edev->device) libinput_device_unref(edev->device);
2377    if (edev->key_remap_hash) eina_hash_free(edev->key_remap_hash);
2378    if (edev->touch.coords)
2379      {
2380         free(edev->touch.coords);
2381         edev->touch.coords = NULL;
2382      }
2383    eina_stringshare_del(edev->output_name);
2384
2385    ecore_thread_main_loop_end();
2386
2387    free(edev);
2388 }
2389
2390 Eina_Bool
2391 _e_input_evdev_event_process(struct libinput_event *event)
2392 {
2393    struct libinput_device *device;
2394    Eina_Bool ret = EINA_TRUE;
2395
2396    device = libinput_event_get_device(event);
2397    switch (libinput_event_get_type(event))
2398      {
2399       case LIBINPUT_EVENT_KEYBOARD_KEY:
2400         _device_handle_key(device, libinput_event_get_keyboard_event(event));
2401         break;
2402       case LIBINPUT_EVENT_POINTER_MOTION:
2403         _device_handle_pointer_motion(device,
2404                                       libinput_event_get_pointer_event(event));
2405         break;
2406       case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE:
2407         _device_handle_pointer_motion_absolute(device,
2408                                                libinput_event_get_pointer_event(event));
2409         break;
2410       case LIBINPUT_EVENT_POINTER_BUTTON:
2411         _device_handle_button(device, libinput_event_get_pointer_event(event));
2412         break;
2413       case LIBINPUT_EVENT_POINTER_AXIS:
2414 #if !LIBINPUT_HAVE_SCROLL_VALUE_V120
2415         _device_handle_axis(device, libinput_event_get_pointer_event(event));
2416 #endif
2417         break;
2418 #if LIBINPUT_HAVE_SCROLL_VALUE_V120
2419       case LIBINPUT_EVENT_POINTER_SCROLL_WHEEL:
2420         _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_WHEEL);
2421         break;
2422       case LIBINPUT_EVENT_POINTER_SCROLL_FINGER:
2423         _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_FINGER);
2424         break;
2425       case LIBINPUT_EVENT_POINTER_SCROLL_CONTINUOUS:
2426         _device_handle_axis_v120(device, libinput_event_get_pointer_event(event), E_INPUT_AXIS_SOURCE_CONTINUOUS);
2427         break;
2428 #endif
2429       case LIBINPUT_EVENT_TOUCH_DOWN:
2430         _device_handle_touch_down(device, libinput_event_get_touch_event(event));
2431         break;
2432       case LIBINPUT_EVENT_TOUCH_MOTION:
2433         _device_handle_touch_motion(device,
2434                                     libinput_event_get_touch_event(event));
2435         break;
2436       case LIBINPUT_EVENT_TOUCH_UP:
2437         _device_handle_touch_up(device, libinput_event_get_touch_event(event));
2438         break;
2439       case LIBINPUT_EVENT_TOUCH_CANCEL:
2440         _device_handle_touch_cancel(device, libinput_event_get_touch_event(event));
2441         break;
2442       case LIBINPUT_EVENT_TOUCH_FRAME:
2443         _device_handle_touch_frame(device, libinput_event_get_touch_event(event));
2444         break;
2445       case LIBINPUT_EVENT_TOUCH_AUX_DATA:
2446         _device_handle_touch_aux_data(device, libinput_event_get_touch_aux_data(event));
2447         break;
2448       default:
2449         ret = EINA_FALSE;
2450         break;
2451      }
2452
2453    return ret;
2454 }
2455
2456 /**
2457  * @brief Set the axis size of the given device.
2458  *
2459  * @param dev The device to set the axis size to.
2460  * @param w The width of the axis.
2461  * @param h The height of the axis.
2462  *
2463  * This function sets set the width @p w and height @p h of the axis
2464  * of device @p dev. If @p dev is a relative input device, a width and
2465  * height must set for it. If its absolute set the ioctl correctly, if
2466  * not, unsupported device.
2467  */
2468 EINTERN void
2469 e_input_evdev_axis_size_set(E_Input_Evdev *edev, int w, int h)
2470 {
2471    const char *sysname;
2472    float cal[6];
2473    const char *device;
2474    Eina_List *devices;
2475    const char *vals;
2476    enum libinput_config_status status;
2477
2478    EINA_SAFETY_ON_NULL_RETURN(edev);
2479    EINA_SAFETY_ON_TRUE_RETURN((w == 0) || (h == 0));
2480
2481    if ((!libinput_device_config_calibration_has_matrix(edev->device)) ||
2482        (libinput_device_config_calibration_get_default_matrix(edev->device, cal) != 0))
2483      return;
2484
2485    sysname = libinput_device_get_sysname(edev->device);
2486
2487    devices = eeze_udev_find_by_subsystem_sysname("input", sysname);
2488    if (eina_list_count(devices) < 1) return;
2489
2490    EINA_LIST_FREE(devices, device)
2491      {
2492         vals = eeze_udev_syspath_get_property(device, "WL_CALIBRATION");
2493         if ((!vals) ||
2494             (sscanf(vals, "%f %f %f %f %f %f",
2495                     &cal[0], &cal[1], &cal[2], &cal[3], &cal[4], &cal[5]) != 6))
2496           goto cont;
2497
2498         cal[2] /= w;
2499         cal[5] /= h;
2500
2501         status =
2502           libinput_device_config_calibration_set_matrix(edev->device, cal);
2503
2504         if (status != LIBINPUT_CONFIG_STATUS_SUCCESS)
2505           ERR("Failed to apply calibration");
2506
2507 cont:
2508         eina_stringshare_del(device);
2509         continue;
2510      }
2511 }
2512
2513 EINTERN const char *
2514 e_input_evdev_name_get(E_Input_Evdev *evdev)
2515 {
2516    EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2517    EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2518
2519    return libinput_device_get_name(evdev->device);
2520 }
2521
2522 EINTERN const char *
2523 e_input_evdev_sysname_get(E_Input_Evdev *evdev)
2524 {
2525    EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2526    EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2527
2528    return libinput_device_get_sysname(evdev->device);
2529 }
2530
2531 EINTERN Eina_Bool
2532 e_input_evdev_key_remap_enable(E_Input_Evdev *edev, Eina_Bool enable)
2533 {
2534    EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2535    EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2536
2537    edev->key_remap_enabled = enable;
2538
2539    if (enable == EINA_FALSE && edev->key_remap_hash)
2540      {
2541         eina_hash_free(edev->key_remap_hash);
2542         edev->key_remap_hash = NULL;
2543      }
2544
2545    return EINA_TRUE;
2546 }
2547
2548 EINTERN Eina_Bool
2549 e_input_evdev_key_remap_set(E_Input_Evdev *edev, int *from_keys, int *to_keys, int num)
2550 {
2551    int i;
2552
2553    EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2554    EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2555    EINA_SAFETY_ON_NULL_RETURN_VAL(from_keys, EINA_FALSE);
2556    EINA_SAFETY_ON_NULL_RETURN_VAL(to_keys, EINA_FALSE);
2557    EINA_SAFETY_ON_TRUE_RETURN_VAL(num <= 0, EINA_FALSE);
2558    EINA_SAFETY_ON_TRUE_RETURN_VAL(!edev->key_remap_enabled, EINA_FALSE);
2559
2560    if (edev->key_remap_hash == NULL)
2561      edev->key_remap_hash = eina_hash_int32_new(NULL);
2562
2563    if (edev->key_remap_hash == NULL)
2564      {
2565         ERR("Failed to set remap key information : creating a hash is failed.");
2566         return EINA_FALSE;
2567      }
2568
2569    for (i = 0; i < num ; i++)
2570      {
2571         if (!from_keys[i] || !to_keys[i])
2572           {
2573              ERR("Failed to set remap key information : given arguments are invalid.");
2574              return EINA_FALSE;
2575           }
2576      }
2577
2578    for (i = 0; i < num ; i++)
2579      {
2580         eina_hash_add(edev->key_remap_hash, &from_keys[i], (void *)(intptr_t)to_keys[i]);
2581      }
2582
2583    return EINA_TRUE;
2584 }
2585
2586 EINTERN int
2587 e_input_evdev_wheel_click_angle_get(E_Input_Evdev *dev)
2588 {
2589    EINA_SAFETY_ON_NULL_RETURN_VAL(dev, -1);
2590    return libinput_device_config_scroll_get_wheel_click_angle(dev->device);
2591 }
2592
2593 EINTERN Eina_Bool
2594 e_input_evdev_touch_calibration_set(E_Input_Evdev *edev, float matrix[6])
2595 {
2596    EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2597    EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2598
2599    if (!libinput_device_config_calibration_has_matrix(edev->device) ||
2600        !libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_TOUCH))
2601      return EINA_FALSE;
2602
2603    if (libinput_device_config_calibration_set_matrix(edev->device, matrix) !=
2604        LIBINPUT_CONFIG_STATUS_SUCCESS)
2605      {
2606         WRN("Failed to set input transformation about device: %s\n",
2607             libinput_device_get_name(edev->device));
2608         return EINA_FALSE;
2609      }
2610
2611    return EINA_TRUE;
2612 }
2613
2614 EINTERN Eina_Bool
2615 e_input_evdev_mouse_accel_speed_set(E_Input_Evdev *edev, double speed)
2616 {
2617    EINA_SAFETY_ON_NULL_RETURN_VAL(edev, EINA_FALSE);
2618    EINA_SAFETY_ON_NULL_RETURN_VAL(edev->device, EINA_FALSE);
2619
2620    if (!libinput_device_has_capability(edev->device, LIBINPUT_DEVICE_CAP_POINTER))
2621      return EINA_FALSE;
2622
2623    if (!libinput_device_config_accel_is_available(edev->device))
2624      return EINA_FALSE;
2625
2626    if (libinput_device_config_accel_set_speed(edev->device, speed) !=
2627        LIBINPUT_CONFIG_STATUS_SUCCESS)
2628      {
2629         WRN("Failed to set mouse accel about device: %s\n",
2630             libinput_device_get_name(edev->device));
2631         return EINA_FALSE;
2632      }
2633
2634    return EINA_TRUE;
2635 }
2636
2637 EINTERN unsigned int
2638 e_input_evdev_touch_pressed_get(E_Input_Evdev *edev)
2639 {
2640    EINA_SAFETY_ON_NULL_RETURN_VAL(edev, 0x0);
2641
2642    return edev->touch.pressed;
2643 }
2644
2645 const char *
2646 e_input_evdev_seatname_get(E_Input_Evdev *evdev)
2647 {
2648    struct libinput_seat *libinput_seat;
2649    EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, NULL);
2650    EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, NULL);
2651
2652    libinput_seat = libinput_device_get_seat(evdev->device);
2653
2654    return libinput_seat_get_logical_name(libinput_seat);
2655 }
2656
2657 Eina_Bool
2658 e_input_evdev_seatname_set(E_Input_Evdev *evdev, const char *seatname)
2659 {
2660    Eina_Bool res = EINA_FALSE;
2661    E_Input_Backend *input;
2662
2663    EINA_SAFETY_ON_NULL_RETURN_VAL(seatname, EINA_FALSE);
2664    EINA_SAFETY_ON_NULL_RETURN_VAL(evdev, EINA_FALSE);
2665    EINA_SAFETY_ON_NULL_RETURN_VAL(evdev->device, EINA_FALSE);
2666
2667    if (libinput_device_set_seat_logical_name(evdev->device, seatname) == 0)
2668      {
2669         input = evdev->seat->input;
2670         if (!input) return EINA_FALSE;
2671         if (libinput_dispatch(input->libinput) != 0)
2672           {
2673              ERR("Failed to dispatch libinput events: %m");
2674              return EINA_FALSE;
2675           }
2676
2677         /* process pending events */
2678         _input_events_process(input);
2679         res = EINA_TRUE;
2680      }
2681
2682    return res;
2683 }