e_input: change E_API to EINTERN
[platform/upstream/enlightenment.git] / src / bin / e_input_device.c
1 #include "e.h"
2 #include "e_input_private.h"
3
4 /* e_input_device private variable */
5 static Eina_List *einput_devices;
6 static E_Input_Device *e_input_device_default = NULL;
7
8 struct xkb_keymap *cached_keymap;
9 struct xkb_context *cached_context;
10
11 static int
12 _device_open_no_pending(const char *device, int flags)
13 {
14    int fd = -1;
15    struct stat s;
16
17    fd = open(device, flags | O_CLOEXEC);
18
19    if (fd < 0) return fd;
20    if (fstat(fd, &s) == -1)
21      {
22         close(fd);
23         return -1;
24      }
25
26    return fd;
27 }
28
29 /* local functions */
30 static int
31 _e_input_device_cb_open_restricted(const char *path, int flags, void *data)
32 {
33    E_Input_Backend *input = (E_Input_Backend *)data;
34    int fd = -1;
35
36    EINA_SAFETY_ON_NULL_RETURN_VAL(input, -1);
37
38    /* try to open the device */
39    fd = _device_open_no_pending(path, flags);
40
41    if (fd < 0)
42      {
43         ERR("Could not open device");
44         return -1;
45      }
46
47    return fd;
48 }
49
50 static void
51 _e_input_device_cb_close_restricted(int fd, void *data)
52 {
53    if (fd >= 0) close(fd);
54 }
55
56 const struct libinput_interface _input_interface =
57 {
58    _e_input_device_cb_open_restricted,
59    _e_input_device_cb_close_restricted,
60 };
61
62 static E_Input_Device *
63 _e_input_device_default_get(void)
64 {
65    return e_input_device_default;
66 }
67
68 struct xkb_context *
69 _e_input_device_cached_context_get(enum xkb_context_flags flags)
70 {
71    if (!cached_context)
72      return xkb_context_new(flags);
73    else
74      return xkb_context_ref(cached_context);
75 }
76
77 struct xkb_keymap *
78 _e_input_device_cached_keymap_get(struct xkb_context *ctx,
79                        const struct xkb_rule_names *names,
80                        enum xkb_keymap_compile_flags flags)
81 {
82    EINA_SAFETY_ON_NULL_RETURN_VAL(ctx, NULL);
83
84    if (!cached_keymap)
85      return xkb_map_new_from_names(ctx, names, flags);
86    else
87      return xkb_map_ref(cached_keymap);
88 }
89
90 void
91 _e_input_device_cached_context_update(struct xkb_context *ctx)
92 {
93    Eina_List *l;
94    E_Input_Device *dev;
95
96    EINA_LIST_FOREACH(einput_devices, l, dev)
97      {
98         xkb_context_unref(dev->xkb_ctx);
99         dev->xkb_ctx = xkb_context_ref(ctx);
100      }
101 }
102
103 void
104 _e_input_device_cached_keymap_update(struct xkb_keymap *map)
105 {
106    Eina_List *l, *l2, *l3;
107    E_Input_Device *dev;
108    E_Input_Seat *seat;
109    E_Input_Evdev *edev;
110
111    EINA_LIST_FOREACH(einput_devices, l, dev)
112      EINA_LIST_FOREACH(dev->seats, l2, seat)
113        EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l3, edev)
114          {
115             xkb_keymap_unref(edev->xkb.keymap);
116             edev->xkb.keymap = xkb_keymap_ref(map);
117             xkb_state_unref(edev->xkb.state);
118             edev->xkb.state = xkb_state_new(map);
119          }
120 }
121
122 EINTERN void
123 e_input_device_keyboard_cached_context_set(struct xkb_context *ctx)
124 {
125    EINA_SAFETY_ON_NULL_RETURN(ctx);
126
127    if (cached_context == ctx) return;
128
129    if (cached_context)
130      _e_input_device_cached_context_update(ctx);
131
132    cached_context = ctx;
133 }
134
135 EINTERN void
136 e_input_device_keyboard_cached_keymap_set(struct xkb_keymap *map)
137 {
138    EINA_SAFETY_ON_NULL_RETURN(map);
139
140    if (cached_keymap == map) return;
141
142    if (cached_keymap)
143       _e_input_device_cached_keymap_update(map);
144
145    cached_keymap = map;
146 }
147
148 static void
149 e_input_device_destroy(E_Input_Device *dev)
150 {
151    E_Input_Backend *input;
152    E_Input_Seat *seat;
153    E_Input_Evdev *edev;
154
155    EINA_SAFETY_ON_NULL_RETURN(dev);
156
157    EINA_LIST_FREE(dev->seats, seat)
158      {
159         EINA_LIST_FREE(seat->devices, edev)
160           {
161              libinput_device_config_send_events_set_mode(edev->device,
162                                                          LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
163              _e_input_evdev_device_destroy(edev);
164           }
165
166         if (seat->name)
167           eina_stringshare_del(seat->name);
168         free(seat);
169      }
170
171    EINA_LIST_FREE(dev->inputs, input)
172      {
173         if (input->hdlr)
174           ecore_main_fd_handler_del(input->hdlr);
175         if (input->libinput)
176           libinput_unref(input->libinput);
177         free(input);
178      }
179
180    eina_stringshare_del(dev->seat);
181    xkb_context_unref(dev->xkb_ctx);
182    eina_hash_free(dev->fd_hash);
183    dev->fd_hash = NULL;
184
185    if (dev == e_input_device_default)
186      e_input_device_default = NULL;
187
188    free(dev);
189 }
190
191 static void
192 _e_input_device_add_list(E_Input_Device *dev)
193 {
194    Eina_List *l;
195    E_Input_Device *dev_data;
196
197    EINA_LIST_FOREACH(einput_devices, l, dev_data)
198      {
199         if (dev_data == dev) return;
200      }
201
202    einput_devices = eina_list_append(einput_devices, dev);
203 }
204
205 static void
206 _e_input_device_remove_list(E_Input_Device *dev)
207 {
208    Eina_List *l, *l_next;
209    E_Input_Device *dev_data;
210
211    EINA_LIST_FOREACH_SAFE(einput_devices, l, l_next, dev_data)
212      {
213         if (dev == dev_data)
214           einput_devices = eina_list_remove_list(einput_devices, l);
215      }
216 }
217
218 EINTERN E_Input_Device *
219 e_input_device_open(void)
220 {
221    E_Input_Device *dev = NULL;
222
223    dev = (E_Input_Device *)calloc(1, sizeof(E_Input_Device));
224
225    if (!dev)
226      {
227         EINA_LOG_ERR("Failed to alloc memory for E_Input_Device\n");
228         return NULL;
229      }
230
231    dev->seat = eina_stringshare_add("seat0");
232    dev->fd_hash = eina_hash_string_superfast_new(NULL);
233
234    /* try to create xkb context */
235    if (!(dev->xkb_ctx = _e_input_device_cached_context_get(0)))
236      {
237         ERR("Failed to create xkb context: %m");
238         goto err;
239      }
240
241    if (!e_input_device_default)
242      e_input_device_default = dev;
243
244    _e_input_device_add_list(dev);
245
246    return dev;
247
248 err:
249    if (dev)
250      {
251         eina_stringshare_del(dev->seat);
252         eina_hash_free(dev->fd_hash);
253         xkb_context_unref(dev->xkb_ctx);
254         free(dev);
255      }
256
257    return NULL;
258 }
259
260 EINTERN Eina_Bool
261 e_input_device_close(E_Input_Device *dev)
262 {
263    /* check for valid device */
264    EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
265
266    _e_input_device_remove_list(dev);
267    e_input_device_destroy(dev);
268
269    return EINA_TRUE;
270 }
271
272 EINTERN void
273 e_input_device_window_set(E_Input_Device *dev, Ecore_Window window)
274 {
275    /* check for valid device */
276    EINA_SAFETY_ON_TRUE_RETURN(!dev);
277
278    /* TODO : Must update window of ecore/evas device when the given window */
279    /*        is not equal to the existing window. */
280
281    dev->window = window;
282 }
283
284 EINTERN void
285 e_input_device_pointer_xy_get(E_Input_Device *dev, int *x, int *y)
286 {
287    E_Input_Seat *seat;
288    E_Input_Evdev *edev;
289    Eina_List *l, *ll;
290
291    if (x) *x = 0;
292    if (y) *y = 0;
293
294    if (!dev)
295      dev = _e_input_device_default_get();
296
297    /* check for valid device */
298    EINA_SAFETY_ON_TRUE_RETURN(!dev);
299    EINA_LIST_FOREACH(dev->seats, l, seat)
300      {
301         EINA_LIST_FOREACH(seat->devices, ll, edev)
302           {
303              if (!(edev->caps & E_INPUT_SEAT_POINTER ||
304                    edev->caps & E_INPUT_SEAT_TOUCH))
305                continue;
306
307              if (x) *x = seat->ptr.dx;
308              if (y) *y = seat->ptr.dy;
309
310              return;
311           }
312      }
313 }
314
315 E_API Eina_Bool
316 e_input_device_pointer_warp(E_Input_Device *dev, int x, int y)
317 {
318    E_Input_Seat *seat;
319    E_Input_Evdev *edev, *warp_dev;
320    Eina_List *l, *ll;
321    Eina_Bool found = EINA_FALSE;
322    char *device_name = NULL, *device_path = NULL;
323
324    if (!dev)
325      dev = _e_input_device_default_get();
326
327    if (e_devicemgr && e_devicemgr->last_device_ptr)
328      {
329         device_name = (char *)e_devicemgr->last_device_ptr->name;
330         device_path = (char *)e_devicemgr->last_device_ptr->identifier;
331      }
332
333    /* check for valid device */
334    EINA_SAFETY_ON_TRUE_RETURN_VAL(!dev, EINA_FALSE);
335    EINA_LIST_FOREACH(dev->seats, l, seat)
336      {
337         warp_dev = NULL;
338         EINA_LIST_FOREACH(seat->devices, ll, edev)
339           {
340              if (!libinput_device_has_capability(edev->device,
341                                                  LIBINPUT_DEVICE_CAP_POINTER))
342                continue;
343
344              if (!e_util_strcmp(libinput_device_get_name(edev->device), device_name) &&
345                  !e_util_strcmp(edev->path, device_path))
346                {
347                   warp_dev = edev;
348                   break;
349                }
350
351              if (!warp_dev) warp_dev = edev;
352           }
353
354         if (warp_dev)
355           {
356              seat->ptr.dx = seat->ptr.ix = x;
357              seat->ptr.dy = seat->ptr.iy = y;
358              _e_input_pointer_motion_post(warp_dev);
359
360              found = EINA_TRUE;
361           }
362      }
363
364    if (found)
365      return EINA_TRUE;
366
367    return EINA_FALSE;
368 }
369
370 EINTERN Eina_Bool
371 e_input_device_pointer_left_handed_set(E_Input_Device *dev, Eina_Bool left_handed)
372 {
373    E_Input_Seat *seat = NULL;
374    E_Input_Evdev *edev = NULL;
375    Eina_List *l = NULL, *l2 = NULL;
376
377    EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
378    EINA_SAFETY_ON_NULL_RETURN_VAL(dev->seats, EINA_FALSE);
379
380    if (dev->left_handed == left_handed)
381      return EINA_TRUE;
382    dev->left_handed = left_handed;
383
384    EINA_LIST_FOREACH(dev->seats, l, seat)
385      {
386         EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
387           {
388              if (libinput_device_has_capability(edev->device,
389                                                 LIBINPUT_DEVICE_CAP_POINTER))
390                {
391                   if (libinput_device_config_left_handed_set(edev->device, (int)left_handed) !=
392                       LIBINPUT_CONFIG_STATUS_SUCCESS)
393                     {
394                        WRN("Failed to set left hand mode about device: %s\n",
395                            libinput_device_get_name(edev->device));
396                        continue;
397                     }
398                }
399           }
400      }
401    return EINA_TRUE;
402 }
403
404
405 EINTERN Eina_Bool
406 e_input_device_pointer_rotation_set(E_Input_Device *dev, int rotation)
407 {
408    E_Input_Seat *seat = NULL;
409    Eina_List *l = NULL;
410
411    EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
412    EINA_SAFETY_ON_NULL_RETURN_VAL(dev->seats, EINA_FALSE);
413
414    if ((rotation % 90 != 0) || (rotation / 90 > 3) || (rotation < 0)) return EINA_FALSE;
415
416    EINA_LIST_FOREACH(dev->seats, l, seat)
417      {
418         switch (rotation)
419           {
420            case 90:
421               seat->ptr.swap = EINA_TRUE;
422               seat->ptr.invert_x = EINA_FALSE;
423               seat->ptr.invert_y = EINA_TRUE;
424               break;
425            case 180:
426               seat->ptr.swap = EINA_FALSE;
427               seat->ptr.invert_x = EINA_TRUE;
428               seat->ptr.invert_y = EINA_TRUE;
429               break;
430            case 270:
431               seat->ptr.swap = EINA_TRUE;
432               seat->ptr.invert_x = EINA_TRUE;
433               seat->ptr.invert_y = EINA_FALSE;
434                 break;
435            case 0:
436               seat->ptr.swap = EINA_FALSE;
437               seat->ptr.invert_x = EINA_FALSE;
438               seat->ptr.invert_y = EINA_FALSE;
439               break;
440            default:
441               break;
442           }
443      }
444    return EINA_TRUE;
445 }
446
447 EINTERN void
448 e_input_device_rotation_set(E_Input_Device *dev, unsigned int rotation)
449 {
450    E_Input_Seat *seat = NULL;
451    E_Input_Evdev *edev = NULL;
452    Eina_List *l = NULL, *l2 = NULL;
453    int temp;
454
455    EINA_SAFETY_ON_NULL_RETURN(dev);
456    EINA_SAFETY_ON_NULL_RETURN(dev->seats);
457
458    EINA_LIST_FOREACH(dev->seats, l, seat)
459      {
460         EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
461           {
462              if (libinput_device_has_capability(edev->device,
463                                       LIBINPUT_DEVICE_CAP_POINTER))
464                {
465                   edev->mouse.minx = edev->mouse.miny = 0;
466                   e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen),
467                                        &edev->mouse.maxw, &edev->mouse.maxh);
468
469                   if (rotation == 90 || rotation == 270)
470                     {
471                        temp = edev->mouse.minx;
472                        edev->mouse.minx = edev->mouse.miny;
473                        edev->mouse.miny = temp;
474
475                        temp = edev->mouse.maxw;
476                        edev->mouse.maxw = edev->mouse.maxh;
477                        edev->mouse.maxh = temp;
478                     }
479                }
480           }
481      }
482 }
483
484 static void
485 _e_input_device_touch_matrix_identify(float result[6])
486 {
487    result[0] = 1.0;
488    result[1] = 0.0;
489    result[2] = 0.0;
490    result[3] = 0.0;
491    result[4] = 1.0;
492    result[5] = 0.0;
493 }
494
495 static void
496 _e_input_device_touch_matrix_mulifly(float result[6], float m1[6], float m2[6])
497 {
498    result[0] = m1[0] * m2 [0] + m1[1] * m2[3];
499    result[1] = m1[0] * m2 [1] + m1[1] * m2[4];
500    result[2] = m1[0] * m2 [2] + m1[1] * m2[5] + m1[2];
501    result[3] = m1[3] * m2 [0] + m1[4] * m2[3];
502    result[4] = m1[3] * m2 [1] + m1[4] * m2[4];
503    result[5] = m1[3] * m2 [2] + m1[4] * m2[5] + m1[5];
504 }
505
506 static void
507 _e_input_device_touch_matrix_rotation_get(float result[6], int degree, float w, float h)
508 {
509    if (w == 0.0) w = 1.0;
510    if (h == 0.0) h = 1.0;
511
512    switch (degree)
513      {
514         case 90:
515           result[0] = 0.0;
516           result[1] = -h/w;
517           result[2] = h/w;
518           result[3] = w/h;
519           result[4] = 0.0;
520           result[5] = 0.0;
521           break;
522         case 180:
523           result[0] = -1.0;
524           result[1] = 0.0;
525           result[2] = 1.0;
526           result[3] = 0.0;
527           result[4] = -1.0;
528           result[5] = 1.0;
529           break;
530         case 270:
531           result[0] = 0.0;
532           result[1] = h/w;
533           result[2] = 0.0;
534           result[3] = -w/h;
535           result[4] = 0.0;
536           result[5] = w/h;
537           break;
538         case 0:
539           _e_input_device_touch_matrix_identify(result);
540           break;
541         default:
542           WRN("Please input valid angle(%d)\n", degree);
543      }
544 }
545
546 static void
547 _e_input_device_touch_matrix_translate_get(float result[6], float x, float y, float w, float h, float default_w, float default_h)
548 {
549    if (default_w == 0.0) default_w = 1.0;
550    if (default_h == 0.0) default_h = 1.0;
551
552    result[0] = w / default_w;
553    result[4] = h / default_h;
554    result[2] = x / default_w;
555    result[5] = y / default_h;
556 }
557
558 EINTERN Eina_Bool
559 e_input_device_touch_rotation_set(E_Input_Device *dev, unsigned int rotation)
560 {
561    E_Input_Seat *seat = NULL;
562    E_Input_Evdev *edev = NULL;
563    Eina_List *l = NULL, *l2 = NULL;
564    float mat_translate[6] = {0.0, }, mat_rotation[6] = {0.0, }, result[6] = {0.0, };
565    float default_w = 0.0, default_h = 0.0;
566    Eina_Bool res = EINA_TRUE;
567    int output_w = 0, output_h = 0;
568
569    EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
570    EINA_SAFETY_ON_NULL_RETURN_VAL(dev->seats, EINA_FALSE);
571
572    e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &output_w, &output_h);
573    default_w = (float)output_w;
574    default_h = (float)output_h;
575
576    EINA_LIST_FOREACH(dev->seats, l, seat)
577      {
578         EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
579           {
580              if (edev->caps & E_INPUT_SEAT_TOUCH)
581                {
582                   _e_input_device_touch_matrix_identify(mat_translate);
583                   _e_input_device_touch_matrix_identify(mat_rotation);
584                   _e_input_device_touch_matrix_identify(result);
585
586                   if (edev->touch.transform.x || edev->touch.transform.y ||
587                       edev->touch.transform.w || edev->touch.transform.h)
588                     {
589                        _e_input_device_touch_matrix_translate_get(mat_translate,
590                                                                     (float)edev->touch.transform.x,
591                                                                     (float)edev->touch.transform.y,
592                                                                     (float)edev->touch.transform.w,
593                                                                     (float)edev->touch.transform.h,
594                                                                     default_w, default_h);
595
596                     }
597
598                   _e_input_device_touch_matrix_rotation_get(mat_rotation, rotation, default_w, default_h);
599
600                   _e_input_device_touch_matrix_mulifly(result, mat_translate, mat_rotation);
601
602                   if (!e_input_evdev_touch_calibration_set(edev, result))
603                     {
604                        res = EINA_FALSE;
605                        continue;
606                     }
607                   else
608                     {
609                        edev->touch.transform.rotation = rotation;
610                     }
611                }
612           }
613      }
614
615    return res;
616 }
617
618 EINTERN Eina_Bool
619 e_input_device_touch_transformation_set(E_Input_Device *dev, int offset_x, int offset_y, int w, int h)
620 {
621    E_Input_Seat *seat = NULL;
622    E_Input_Evdev *edev = NULL;
623    Eina_List *l = NULL, *l2 = NULL;
624    float mat_translate[6] = {0.0, }, mat_rotation[6] = {0.0 }, result[6] = {0.0, };
625    float default_w = 0.0, default_h = 0.0;
626    Eina_Bool res = EINA_TRUE;
627    int output_w = 0, output_h = 0;
628
629    EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
630    EINA_SAFETY_ON_NULL_RETURN_VAL(dev->seats, EINA_FALSE);
631    EINA_SAFETY_ON_TRUE_RETURN_VAL((w == 0) || (h == 0), EINA_FALSE);
632
633    e_output_size_get(e_comp_screen_primary_output_get(e_comp->e_comp_screen), &output_w, &output_h);
634    default_w = (float)output_w;
635    default_h = (float)output_h;
636
637    EINA_LIST_FOREACH(dev->seats, l, seat)
638      {
639         EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
640           {
641              if (edev->caps & E_INPUT_SEAT_TOUCH)
642                {
643                   _e_input_device_touch_matrix_identify(mat_translate);
644                   _e_input_device_touch_matrix_identify(mat_rotation);
645                   _e_input_device_touch_matrix_identify(result);
646
647                   _e_input_device_touch_matrix_translate_get(mat_translate,
648                                                                (float)offset_x, (float)offset_y,
649                                                                (float)w, (float)h, default_w, default_h);
650
651                   if (edev->touch.transform.rotation)
652                     {
653                        _e_input_device_touch_matrix_rotation_get(mat_rotation,
654                                                                    edev->touch.transform.rotation,
655                                                                    default_w, default_h);
656                     }
657
658                   _e_input_device_touch_matrix_mulifly(result, mat_translate, mat_rotation);
659
660                   if (!e_input_evdev_touch_calibration_set(edev, result))
661                     {
662                        res = EINA_FALSE;
663                        continue;
664                     }
665                   else
666                     {
667                        edev->touch.transform.x = offset_x;
668                        edev->touch.transform.y = offset_y;
669                        edev->touch.transform.w = w;
670                        edev->touch.transform.h = h;
671                     }
672                }
673           }
674      }
675    return res;
676 }
677
678 static void
679 e_input_device_libinput_log_handler(struct libinput *libinput EINA_UNUSED,
680                                enum libinput_log_priority priority,
681                                const char *format, va_list args)
682 {
683    char buf[1024] = {0,};
684
685    vsnprintf(buf, 1024, format, args);
686    switch (priority)
687      {
688         case LIBINPUT_LOG_PRIORITY_DEBUG:
689            DBG("%s", buf);
690            break;
691         case LIBINPUT_LOG_PRIORITY_INFO:
692            INF("%s", buf);
693            break;
694         case LIBINPUT_LOG_PRIORITY_ERROR:
695            ERR("%s", buf);
696            break;
697         default:
698            break;
699      }
700 }
701
702 EINTERN Eina_Bool
703 e_input_device_input_backend_create(E_Input_Device *dev, E_Input_Libinput_Backend backend)
704 {
705    Eina_Bool res = EINA_FALSE;
706
707    EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
708
709    if (backend == E_INPUT_LIBINPUT_BACKEND_UDEV)
710      {
711         TRACE_INPUT_BEGIN(e_input_device_input_create_libinput_udev);
712         res = e_input_device_input_create_libinput_udev(dev);
713         TRACE_INPUT_END();
714      }
715    else if (backend == E_INPUT_LIBINPUT_BACKEND_PATH)
716      {
717         TRACE_INPUT_BEGIN(e_input_device_input_create_libinput_path);
718         res = e_input_device_input_create_libinput_path(dev);
719         TRACE_INPUT_END();
720      }
721
722    return res;
723 }
724
725 static void
726 _e_input_device_input_thread_name_set(void)
727 {
728    eina_thread_name_set(eina_thread_self(), "input-device-thread");
729 }
730
731 static void
732 _einput_device_input_thread_udev_backend_heavy(void *data, Ecore_Thread *th, void *msg_data)
733 {
734    E_Input_Backend *input = (E_Input_Backend *)data;
735
736    EINA_SAFETY_ON_NULL_RETURN(input);
737    EINA_SAFETY_ON_NULL_RETURN(input->dev);
738    EINA_SAFETY_ON_NULL_RETURN(input->dev->seat);
739
740    /* try to create libinput context */
741    input->libinput =
742      libinput_udev_create_context(&_input_interface, input, eeze_udev_get());
743
744    if (!input->libinput)
745      {
746         free(input);
747
748         ERR("Could not create libinput context: %m");
749         return;
750      }
751
752    _e_input_device_input_thread_name_set();
753
754    if (input->log_disable)
755      libinput_log_set_handler(input->libinput, NULL);
756    else
757      {
758         if (input->log_use_eina)
759           libinput_log_set_handler(input->libinput, e_input_device_libinput_log_handler);
760         libinput_log_set_priority(input->libinput, LIBINPUT_LOG_PRIORITY_INFO);
761      }
762
763    TRACE_INPUT_BEGIN(libinput_udev_assign_seat);
764    /* assign udev seat */
765    if (libinput_udev_assign_seat(input->libinput, input->dev->seat) != 0)
766      {
767         ERR("Failed to assign seat: %m");
768         TRACE_INPUT_END();
769         return;
770      }
771    TRACE_INPUT_END();
772
773    return;
774 }
775
776 static void
777 _einput_device_input_thread_udev_backend_notify(void *data, Ecore_Thread *th, void *msg_data)
778 {
779    //TODO : do if there is something to do in main thread
780 }
781
782 static void
783 _einput_device_input_thread_udev_backend_end(void *data, Ecore_Thread *th, void *msg_data)
784 {
785    E_Input_Backend *input = (E_Input_Backend *)data;
786    E_Input_Device *dev = NULL;
787
788    EINA_SAFETY_ON_NULL_RETURN(input);
789    EINA_SAFETY_ON_NULL_RETURN(input->dev);
790
791    input->thread = NULL;
792
793    /* enable this input */
794    if (!e_input_enable_input(input))
795      {
796         ERR("Failed to enable input");
797         return;
798      }
799
800    /* append this input */
801    dev = input->dev;
802    dev->inputs = eina_list_append(dev->inputs, input);
803
804    /* process pending events */
805    _input_events_process(input);
806
807 }
808
809 static void
810 _einput_device_input_thread_udev_backend_cancel(void *data, Ecore_Thread *th, void *msg_data)
811 {
812    E_Input_Backend *input = (E_Input_Backend *)data;
813
814    EINA_SAFETY_ON_NULL_RETURN(input);
815
816    input->thread = NULL;
817 }
818
819 static Eina_Bool
820 _e_input_device_input_thread_init_udev_backend(E_Input_Backend *input)
821 {
822    EINA_SAFETY_ON_NULL_RETURN_VAL(input, EINA_FALSE);
823
824    input->thread = ecore_thread_feedback_run((Ecore_Thread_Cb)_einput_device_input_thread_udev_backend_heavy,
825                                              (Ecore_Thread_Notify_Cb)_einput_device_input_thread_udev_backend_notify,
826                                              (Ecore_Thread_Cb)_einput_device_input_thread_udev_backend_end,
827                                              (Ecore_Thread_Cb)_einput_device_input_thread_udev_backend_cancel, input, 1);
828    return !!(input->thread);
829 }
830
831 /* public functions */
832 EINTERN Eina_Bool
833 e_input_device_input_create_libinput_udev(E_Input_Device *dev)
834 {
835    E_Input_Backend *input;
836    char *env = NULL;
837    int buf_size = 0;
838    int res = 0;
839
840    /* check for valid device */
841    EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
842
843    /* try to allocate space for new input structure */
844    if (!(input = calloc(1, sizeof(E_Input_Backend))))
845      {
846         return EINA_FALSE;
847      }
848
849    /* set reference for parent device */
850    input->dev = dev;
851
852    input->backend = E_INPUT_LIBINPUT_BACKEND_UDEV;
853    input->log_disable = EINA_FALSE;
854    input->log_use_eina = EINA_FALSE;
855
856    env = e_util_env_get(E_INPUT_ENV_LIBINPUT_LOG_DISABLE);
857    if ((env) && (atoi(env) == 1))
858      input->log_disable = EINA_TRUE;
859    else
860      {
861         if (env) E_FREE(env);
862
863         env = e_util_env_get(E_INPUT_ENV_LIBINPUT_LOG_EINA_LOG);
864         if ((env) && (atoi(env) == 1))
865           input->log_use_eina = EINA_TRUE;
866      }
867    E_FREE(env);
868
869    env = e_util_env_get("UDEV_MONITOR_EVENT_SOURCE");
870
871    if (env)
872      {
873         libinput_udev_set_udev_monitor_event_source(env);
874      }
875    E_FREE(env);
876
877    env = e_util_env_get("UDEV_MONITOR_BUFFER_SIZE");
878
879    if ((env) && (buf_size = atoi(env)))
880      {
881         res = libinput_udev_set_udev_monitor_buffer_size(buf_size);
882         if (res)
883           ERR("Wrong buffer size for udev monitor : %d\n", buf_size);
884      }
885    E_FREE(env);
886
887    if (e_input_thread_enabled_get())
888      {
889         /* initialize libinput udev backend within an ecore thread */
890         if (!_e_input_device_input_thread_init_udev_backend(input))
891           {
892              ERR("Failed to initialize e_input backend (libinput udev backend) !");
893              goto err;
894         }
895
896         return EINA_TRUE;
897      }
898
899    /* try to create libinput context */
900    input->libinput =
901      libinput_udev_create_context(&_input_interface, input, eeze_udev_get());
902    if (!input->libinput)
903      {
904         ERR("Could not create libinput context: %m");
905         goto err;
906      }
907
908    if (input->log_disable)
909      libinput_log_set_handler(input->libinput, NULL);
910    else
911      {
912         if (input->log_use_eina)
913           libinput_log_set_handler(input->libinput, e_input_device_libinput_log_handler);
914         libinput_log_set_priority(input->libinput, LIBINPUT_LOG_PRIORITY_INFO);
915      }
916
917    /* assign udev seat */
918    TRACE_INPUT_BEGIN(libinput_udev_assign_seat);
919    if (libinput_udev_assign_seat(input->libinput, dev->seat) != 0)
920      {
921         ERR("Failed to assign seat: %m");
922         TRACE_INPUT_END();
923         goto err;
924      }
925    TRACE_INPUT_END();
926
927    /* enable this input */
928    if (!e_input_enable_input(input))
929      {
930         ERR("Failed to enable input");
931         goto err;
932      }
933
934    /* append this input */
935    dev->inputs = eina_list_append(dev->inputs, input);
936
937    /* process pending events */
938    _input_events_process(input);
939
940    return EINA_TRUE;
941
942 err:
943    if (input->libinput) libinput_unref(input->libinput);
944    free(input);
945
946    return EINA_FALSE;
947 }
948
949 static void
950 _einput_device_input_thread_path_backend_heavy(void *data, Ecore_Thread *th, void *msg_data)
951 {
952    char *env = NULL;
953    struct libinput_device *device;
954    E_Input_Backend *input = (E_Input_Backend *)data;
955
956    EINA_SAFETY_ON_NULL_RETURN(input);
957    EINA_SAFETY_ON_NULL_RETURN(input->dev);
958    EINA_SAFETY_ON_NULL_RETURN(input->dev->seat);
959
960    /* try to create libinput context */
961    input->libinput =
962      libinput_path_create_context(&_input_interface, input);
963    if (!input->libinput)
964      {
965         free(input);
966
967         ERR("Could not create libinput path context: %m");
968         return;
969      }
970
971    _e_input_device_input_thread_name_set();
972
973    if (input->log_disable)
974      libinput_log_set_handler(input->libinput, NULL);
975    else
976      {
977         if (input->log_use_eina)
978           libinput_log_set_handler(input->libinput, e_input_device_libinput_log_handler);
979         libinput_log_set_priority(input->libinput, LIBINPUT_LOG_PRIORITY_INFO);
980      }
981
982    TRACE_INPUT_BEGIN(libinput_path_add_device_loop);
983    for (int i = 0; i < input->path_ndevices; i++)
984      {
985         char buf[1024] = "PATH_DEVICE_";
986         eina_convert_itoa(i + 1, buf + 12);
987         env = e_util_env_get(buf);
988
989         if (env)
990           {
991              device = libinput_path_add_device(input->libinput, env);
992              if (!device)
993                ERR("Failed to initialized device %s", env);
994              else
995                INF("libinput_path created input device %s", env);
996              E_FREE(env);
997           }
998      }
999    TRACE_INPUT_END();
1000
1001    return;
1002 }
1003
1004 static void
1005 _einput_device_input_thread_path_backend_notify(void *data, Ecore_Thread *th, void *msg_data)
1006 {
1007    //TODO : do if there is something to do in main thread
1008 }
1009
1010 static void
1011 _einput_device_input_thread_path_backend_end(void *data, Ecore_Thread *th, void *msg_data)
1012 {
1013    E_Input_Backend *input = (E_Input_Backend *)data;
1014    E_Input_Device *dev = NULL;
1015
1016    EINA_SAFETY_ON_NULL_RETURN(input);
1017    EINA_SAFETY_ON_NULL_RETURN(input->dev);
1018
1019    input->thread = NULL;
1020
1021    /* enable this input */
1022    if (!e_input_enable_input(input))
1023      {
1024         ERR("Failed to enable input");
1025         return;
1026      }
1027
1028    /* append this input */
1029    dev = input->dev;
1030    dev->inputs = eina_list_append(dev->inputs, input);
1031
1032    /* process pending events */
1033    _input_events_process(input);
1034 }
1035
1036 static void
1037 _einput_device_input_thread_path_backend_cancel(void *data, Ecore_Thread *th, void *msg_data)
1038 {
1039    E_Input_Backend *input = (E_Input_Backend *)data;
1040
1041    EINA_SAFETY_ON_NULL_RETURN(input);
1042
1043    input->thread = NULL;
1044 }
1045
1046 static Eina_Bool
1047 _e_input_device_input_thread_init_path_backend(E_Input_Backend *input)
1048 {
1049    EINA_SAFETY_ON_NULL_RETURN_VAL(input, EINA_FALSE);
1050
1051    input->thread = ecore_thread_feedback_run((Ecore_Thread_Cb)_einput_device_input_thread_path_backend_heavy,
1052                                              (Ecore_Thread_Notify_Cb)_einput_device_input_thread_path_backend_notify,
1053                                              (Ecore_Thread_Cb)_einput_device_input_thread_path_backend_end,
1054                                              (Ecore_Thread_Cb)_einput_device_input_thread_path_backend_cancel, input, 1);
1055    return !!(input->thread);
1056 }
1057
1058 EINTERN Eina_Bool
1059 e_input_device_input_create_libinput_path(E_Input_Device *dev)
1060 {
1061    E_Input_Backend *input;
1062    struct libinput_device *device;
1063    int ndevices = 0;
1064    char *env;
1065
1066    /* check for valid device */
1067    EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
1068
1069    env = e_util_env_get("PATH_DEVICES_NUM");
1070    if (env)
1071      {
1072         ndevices = atoi(env);
1073         E_FREE(env);
1074      }
1075
1076    if (ndevices <= 0 || ndevices >= INT_MAX)
1077      {
1078         return EINA_TRUE;
1079      }
1080
1081    INF("PATH_DEVICES_NUM : %d", ndevices);
1082
1083    /* try to allocate space for new input structure */
1084    if (!(input = calloc(1, sizeof(E_Input_Backend))))
1085      {
1086         return EINA_FALSE;
1087      }
1088
1089    /* set reference for parent device */
1090    input->dev = dev;
1091
1092    input->backend = E_INPUT_LIBINPUT_BACKEND_PATH;
1093    input->path_ndevices = ndevices;
1094    input->log_disable = EINA_FALSE;
1095    input->log_use_eina = EINA_FALSE;
1096
1097    env = e_util_env_get(E_INPUT_ENV_LIBINPUT_LOG_DISABLE);
1098    if ((env) && (atoi(env) == 1))
1099      input->log_disable = EINA_TRUE;
1100    else
1101      {
1102         if (env) E_FREE(env);
1103
1104         env = e_util_env_get(E_INPUT_ENV_LIBINPUT_LOG_EINA_LOG);
1105         if ((env) && (atoi(env) == 1))
1106           input->log_use_eina = EINA_TRUE;
1107      }
1108    E_FREE(env);
1109
1110    if (e_input_thread_enabled_get())
1111      {
1112         /* initialize libinput path backend within an ecore thread */
1113         if (!_e_input_device_input_thread_init_path_backend(input))
1114           {
1115              ERR("Failed to initialize e_input backend (libinput path backend) !");
1116              goto err;
1117         }
1118
1119         return EINA_TRUE;
1120      }
1121
1122    /* try to create libinput context */
1123    input->libinput =
1124      libinput_path_create_context(&_input_interface, input);
1125    if (!input->libinput)
1126      {
1127         ERR("Could not create libinput path context: %m");
1128         goto err;
1129      }
1130
1131    if (input->log_disable)
1132      libinput_log_set_handler(input->libinput, NULL);
1133    else
1134      {
1135         if (input->log_use_eina)
1136           libinput_log_set_handler(input->libinput, e_input_device_libinput_log_handler);
1137         libinput_log_set_priority(input->libinput, LIBINPUT_LOG_PRIORITY_INFO);
1138      }
1139
1140    TRACE_INPUT_BEGIN(libinput_path_add_device_loop);
1141    for (int i = 0; i < ndevices; i++)
1142      {
1143         char buf[1024] = "PATH_DEVICE_";
1144         eina_convert_itoa(i + 1, buf + 12);
1145         env = e_util_env_get(buf);
1146         if (env)
1147           {
1148              device = libinput_path_add_device(input->libinput, env);
1149              if (!device)
1150                ERR("Failed to initialized device %s", env);
1151              else
1152                INF("libinput_path created input device %s", env);
1153              E_FREE(env);
1154           }
1155      }
1156    TRACE_INPUT_END();
1157
1158    /* enable this input */
1159    if (!e_input_enable_input(input))
1160      {
1161         ERR("Failed to enable input");
1162         goto err;
1163      }
1164
1165    /* append this input */
1166    dev->inputs = eina_list_append(dev->inputs, input);
1167
1168    /* process pending events */
1169    _input_events_process(input);
1170
1171    return EINA_TRUE;
1172
1173 err:
1174    if (input->libinput) libinput_unref(input->libinput);
1175    free(input);
1176
1177    return EINA_FALSE;
1178 }
1179
1180 void
1181 e_input_device_output_changed(E_Input_Device *dev)
1182 {
1183    E_Input_Seat *seat = NULL;
1184    E_Input_Evdev *edev = NULL;
1185    Eina_List *l = NULL, *l2 = NULL;
1186
1187    EINA_SAFETY_ON_NULL_RETURN(dev);
1188    EINA_SAFETY_ON_NULL_RETURN(dev->seats);
1189
1190    EINA_LIST_FOREACH(dev->seats, l, seat)
1191      {
1192         EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
1193           {
1194              _device_calibration_set(edev);
1195           }
1196      }
1197 }
1198
1199 E_API const Eina_List *
1200 e_input_devices_get(void)
1201 {
1202    return einput_devices;
1203 }
1204
1205 E_API Eina_Bool
1206 e_input_device_mouse_accel_speed_set(E_Input_Device *dev, double speed)
1207 {
1208    E_Input_Seat *seat = NULL;
1209    E_Input_Evdev *edev = NULL;
1210    Eina_List *l = NULL, *l2 = NULL;
1211    Eina_Bool res = EINA_TRUE, ret = EINA_TRUE;
1212
1213    EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
1214    EINA_SAFETY_ON_NULL_RETURN_VAL(dev->seats, EINA_FALSE);
1215
1216    EINA_LIST_FOREACH(dev->seats, l, seat)
1217      {
1218         EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
1219           {
1220              if (edev->caps & E_INPUT_SEAT_POINTER)
1221                res = e_input_evdev_mouse_accel_speed_set(edev, speed);
1222              if (!res) ret = EINA_FALSE;
1223           }
1224      }
1225
1226    return ret;
1227 }
1228
1229 EINTERN unsigned int
1230 e_input_device_touch_pressed_get(E_Input_Device *dev)
1231 {
1232    E_Input_Seat *seat = NULL;
1233    E_Input_Evdev *edev = NULL;
1234    Eina_List *l = NULL, *l2 = NULL;
1235    unsigned int pressed = 0x0;
1236
1237    EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
1238
1239    EINA_LIST_FOREACH(dev->seats, l, seat)
1240      {
1241         EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
1242           {
1243              if (edev->caps & E_INPUT_SEAT_TOUCH)
1244                pressed |= e_input_evdev_touch_pressed_get(edev);
1245           }
1246      }
1247
1248    return pressed;
1249 }
1250
1251 EINTERN Eina_Bool
1252 e_input_device_keyboard_remap_set(E_Input_Device *dev, int *from_keys, int *to_keys, int num)
1253 {
1254    E_Input_Seat *seat = NULL;
1255    E_Input_Evdev *edev = NULL;
1256    Eina_List *l = NULL, *l2 = NULL;
1257    Eina_Bool res = EINA_TRUE, ret = EINA_TRUE;
1258
1259    EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
1260    EINA_SAFETY_ON_NULL_RETURN_VAL(dev->seats, EINA_FALSE);
1261    EINA_SAFETY_ON_NULL_RETURN_VAL(from_keys, EINA_FALSE);
1262    EINA_SAFETY_ON_NULL_RETURN_VAL(to_keys, EINA_FALSE);
1263    EINA_SAFETY_ON_TRUE_RETURN_VAL(num <= 0, EINA_FALSE);
1264
1265    EINA_LIST_FOREACH(dev->seats, l, seat)
1266      {
1267         EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
1268           {
1269              if (edev->caps & E_INPUT_SEAT_KEYBOARD)
1270                {
1271                   res = e_input_evdev_key_remap_enable(edev, EINA_TRUE);
1272                   if (res)
1273                      res = e_input_evdev_key_remap_set(edev, from_keys, to_keys, num);
1274                }
1275              if (!res) ret = EINA_FALSE;
1276           }
1277      }
1278
1279    return ret;
1280 }
1281
1282 EINTERN Eina_Bool
1283 e_input_device_block(E_Input_Device *dev, unsigned int type, void *client)
1284 {
1285    E_Input_Seat *seat = NULL;
1286    E_Input_Evdev *edev = NULL;
1287    Eina_List *l = NULL, *l2 = NULL;
1288
1289    EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
1290
1291    if (client && client != E_INPUT_REQUEST_SERVER)
1292      {
1293         if (dev->blocked_client && (dev->blocked_client != client))
1294           {
1295              WRN("Already blocked by client: %p (type: 0x%x)\n", dev->blocked_client, dev->blocked);
1296              return EINA_FALSE;
1297           }
1298
1299         dev->blocked |= type;
1300         dev->blocked_client = client;
1301      }
1302    else if (client == E_INPUT_REQUEST_SERVER)
1303      {
1304         dev->server_blocked = type;
1305      }
1306
1307    if (type & E_INPUT_SEAT_TOUCH)
1308      {
1309         EINA_LIST_FOREACH(dev->seats, l, seat)
1310           {
1311              EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
1312                {
1313                   edev->touch.blocked = EINA_TRUE;
1314                }
1315           }
1316      }
1317
1318    return EINA_TRUE;
1319 }
1320
1321 EINTERN Eina_Bool
1322 e_input_device_unblock(E_Input_Device *dev, void *client)
1323 {
1324    E_Input_Seat *seat = NULL;
1325    E_Input_Evdev *edev = NULL;
1326    Eina_List *l = NULL, *l2 = NULL;
1327
1328    EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
1329
1330    if (client != E_INPUT_REQUEST_SERVER && dev->blocked_client != client)
1331      {
1332         WRN("Currently %p client has already bloked (type: 0x%x)\n", dev->blocked_client, dev->blocked);
1333         return EINA_FALSE;
1334      }
1335
1336    if ((dev->server_blocked & E_INPUT_SEAT_TOUCH) ||
1337        (dev->blocked & E_INPUT_SEAT_TOUCH))
1338      {
1339         EINA_LIST_FOREACH(dev->seats, l, seat)
1340           {
1341              EINA_LIST_FOREACH(e_input_seat_evdev_list_get(seat), l2, edev)
1342                {
1343                   if (edev->touch.raw_pressed == 0x0)
1344                     edev->touch.blocked = EINA_FALSE;
1345                }
1346           }
1347      }
1348
1349    if (client == E_INPUT_REQUEST_SERVER)
1350      {
1351         dev->server_blocked = 0x0;
1352      }
1353    else
1354      {
1355         dev->blocked = 0x0;
1356         dev->blocked_client = NULL;
1357      }
1358
1359    return EINA_TRUE;
1360 }
1361
1362 EINTERN Eina_Bool
1363 e_input_device_output_name_set(E_Input_Device *dev, const char *input, const char *output)
1364 {
1365    E_Input_Seat *seat;
1366    E_Input_Evdev *edev = NULL;
1367    Eina_List *l, *ll;
1368    Eina_Bool found = EINA_FALSE;
1369
1370    if (!dev)
1371      dev = _e_input_device_default_get();
1372
1373    EINA_SAFETY_ON_TRUE_RETURN_VAL(!dev, EINA_FALSE);
1374    EINA_SAFETY_ON_TRUE_RETURN_VAL(!input, EINA_FALSE);
1375    EINA_SAFETY_ON_TRUE_RETURN_VAL(!output, EINA_FALSE);
1376    EINA_LIST_FOREACH(dev->seats, l, seat)
1377      {
1378         EINA_LIST_FOREACH(seat->devices, ll, edev)
1379           {
1380              if (!e_util_strcmp(edev->path, input))
1381                {
1382                   found = EINA_TRUE;
1383                   break;
1384                }
1385           }
1386         if (found) break;
1387      }
1388
1389    if (!found || !edev)
1390      {
1391         ERR("Failed to find input device: %s", input);
1392         return EINA_FALSE;
1393      }
1394
1395    if (e_output_find(output))
1396      {
1397         INF("output device found: %s", output);
1398         eina_stringshare_replace(&edev->output_name, output);
1399         edev->output_configured = EINA_FALSE;
1400         return EINA_TRUE;
1401      }
1402    else
1403      ERR("Failed to find output device: %s", output);
1404
1405    return EINA_FALSE;
1406 }
1407
1408 EINTERN const char *
1409 e_input_device_output_name_get(E_Input_Device *dev, const char *input)
1410 {
1411    E_Input_Seat *seat;
1412    E_Input_Evdev *edev = NULL;
1413    Eina_List *l, *ll;
1414    Eina_Bool found = EINA_FALSE;
1415
1416    if (!dev)
1417      dev = _e_input_device_default_get();
1418
1419    EINA_SAFETY_ON_TRUE_RETURN_VAL(!dev, NULL);
1420    EINA_SAFETY_ON_TRUE_RETURN_VAL(!input, NULL);
1421    EINA_LIST_FOREACH(dev->seats, l, seat)
1422      {
1423         EINA_LIST_FOREACH(seat->devices, ll, edev)
1424           {
1425              if (!e_util_strcmp(edev->path, input))
1426                {
1427                   found = EINA_TRUE;
1428                   break;
1429                }
1430           }
1431         if (found) break;
1432      }
1433    if (!found || !edev)
1434      {
1435         ERR("Failed to find input device: %s", input);
1436         return NULL;
1437      }
1438    return edev->output_name;
1439 }
1440
1441 EINTERN Eina_Bool
1442 e_input_device_seat_name_set(E_Input_Device *dev, const char *input, const char *seat_name)
1443 {
1444    E_Input_Seat *seat;
1445    E_Input_Evdev *edev = NULL;
1446    Eina_List *l, *ll;
1447    Eina_Bool found = EINA_FALSE;
1448
1449    if (!dev)
1450      dev = _e_input_device_default_get();
1451
1452    EINA_SAFETY_ON_TRUE_RETURN_VAL(!dev, EINA_FALSE);
1453    EINA_SAFETY_ON_TRUE_RETURN_VAL(!input, EINA_FALSE);
1454    EINA_SAFETY_ON_TRUE_RETURN_VAL(!seat_name, EINA_FALSE);
1455    EINA_LIST_FOREACH(dev->seats, l, seat)
1456      {
1457         EINA_LIST_FOREACH(seat->devices, ll, edev)
1458           {
1459              if (!e_util_strcmp(edev->path, input))
1460                {
1461                   found = EINA_TRUE;
1462                   break;
1463                }
1464           }
1465         if (found) break;
1466      }
1467
1468    if (!found || !edev)
1469      {
1470         ERR("Failed to find input device: %s", input);
1471         return EINA_FALSE;
1472      }
1473
1474    INF("Current seatname:%s", e_input_evdev_seatname_get(edev));
1475    if (e_input_evdev_seatname_set(edev, seat_name))
1476      {
1477         INF("New seatname is now set: %s", seat_name);
1478         return EINA_TRUE;
1479      }
1480    else
1481      ERR("Failed to set new seatname: %s", seat_name);
1482
1483    return EINA_FALSE;
1484 }