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