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