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