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