summaryrefslogtreecommitdiff
path: root/li.c
blob: 082c7fac890b9ed1cecd6406b9309c177b19393a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//  gcc -o li li.c $(pkg-config --cflags --libs eina ecore eeze libinput) -g

#include <Ecore.h>
#include <Eeze.h>
#include <libinput.h>
#include <fcntl.h>

static struct libinput *li;

static Eina_Bool
fdh_func(void *d EINA_UNUSED, Ecore_Fd_Handler *fdh)
{
   struct libinput_event *event;

   libinput_dispatch(li);
   while ((event = libinput_get_event(li)))
     {
        switch (libinput_event_get_type(event))
          {
#define EVENT(X) \
case X: \
  fprintf(stderr, "EVENT: %s\n", #X); \
  break
           EVENT(LIBINPUT_EVENT_DEVICE_ADDED);
           EVENT(LIBINPUT_EVENT_DEVICE_REMOVED);
           EVENT(LIBINPUT_EVENT_KEYBOARD_KEY);
           EVENT(LIBINPUT_EVENT_POINTER_MOTION);
           EVENT(LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE);
           EVENT(LIBINPUT_EVENT_POINTER_BUTTON);
           EVENT(LIBINPUT_EVENT_POINTER_AXIS);
           EVENT(LIBINPUT_EVENT_TOUCH_DOWN);
           EVENT(LIBINPUT_EVENT_TOUCH_UP);
           EVENT(LIBINPUT_EVENT_TOUCH_MOTION);
           EVENT(LIBINPUT_EVENT_TOUCH_CANCEL);
           EVENT(LIBINPUT_EVENT_TOUCH_FRAME);
          }
        libinput_event_destroy(event);
		      libinput_dispatch(li);
     }
   return ECORE_CALLBACK_RENEW;
}

static int
open_restricted(const char *path, int flags, void *userdata)
{
   Ecore_Fd_Handler *fdh;
   int fd;

   fd = open(path, flags | O_NONBLOCK);
   if (fd < 0) return -1;
   fdh = ecore_main_fd_handler_add(fd, ECORE_FD_READ, fdh_func, NULL, NULL, NULL);
   eina_hash_add(userdata, &fd, fdh);
   return fd;
}

static void
close_restricted(int fd, void *userdata)
{
   eina_hash_del_by_key(userdata, &fd);
   close(fd);
}

const struct libinput_interface interface =
{
   .open_restricted = open_restricted,
   .close_restricted = close_restricted,
};

int
main(void)
{
   Eina_Hash *fds;

   eeze_init();
   fds = eina_hash_int32_new((Eina_Free_Cb)ecore_main_fd_handler_del);
   li = libinput_udev_create_for_seat(&interface, fds, eeze_udev_get(), "seat0");
   ecore_main_loop_begin();
   return 0;
}