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