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