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