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