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