Add a device only when the device is not created by libinput_path
authorDuna Oh <duna.oh@samsung.com>
Mon, 18 Apr 2016 13:56:59 +0000 (22:56 +0900)
committerduna.oh <duna.oh@samsung.com>
Fri, 27 Jan 2023 05:05:57 +0000 (14:05 +0900)
Signed-off-by: Duna Oh <duna.oh@samsung.com>
Change-Id: Ic9d444cbf0d8ab95293e3770a91e31e83f405d60

src/libinput-private.h
src/path-seat.c
src/udev-seat.c

index 09a6dad..bdaf4ac 100644 (file)
@@ -458,6 +458,11 @@ struct libinput_event_listener {
        void *notify_func_data;
 };
 
+struct device_node {
+       struct list link;
+       char *devname;
+};
+
 typedef void (*libinput_source_dispatch_t)(void *data);
 
 #define log_debug(li_, ...) log_msg((li_), LIBINPUT_LOG_PRIORITY_DEBUG, __VA_ARGS__)
@@ -942,5 +947,7 @@ static inline void *libinput_libwacom_ref(struct libinput *li) { return NULL; }
 static inline void libinput_libwacom_unref(struct libinput *li) {}
 #endif
 
+struct list *
+libinput_path_get_devices(void);
 
 #endif /* LIBINPUT_PRIVATE_H */
index 1d9282f..156bd50 100644 (file)
@@ -47,6 +47,7 @@ struct path_seat {
 
 static const char default_seat[] = "seat0";
 static const char default_seat_name[] = "default";
+static struct list devices_list;
 
 static void
 path_disable_device(struct evdev_device *device)
@@ -242,12 +243,17 @@ path_input_destroy(struct libinput *input)
 {
        struct path_input *path_input = (struct path_input*)input;
        struct path_device *dev;
+       struct device_node *dev_node;
 
        udev_unref(path_input->udev);
 
        list_for_each_safe(dev, &path_input->path_list, link)
                path_device_destroy(dev);
 
+       list_for_each_safe(dev_node, &devices_list, link) {
+               free(dev_node->devname);
+               free(dev_node);
+       }
 }
 
 static struct libinput_device *
@@ -258,12 +264,26 @@ path_create_device(struct libinput *libinput,
        struct path_input *input = (struct path_input*)libinput;
        struct path_device *dev;
        struct libinput_device *device;
+       struct device_node *dev_node;
+       const char *name;
 
        dev = zalloc(sizeof *dev);
        dev->udev_device = udev_device_ref(udev_device);
 
        list_insert(&input->path_list, &dev->link);
 
+       name = udev_device_get_devnode(udev_device);
+       if (name)
+       {
+               dev_node = zalloc(sizeof *dev_node);
+               if (dev_node)
+               {
+                       dev_node->devname = strdup(name);
+                       if (dev_node->devname)
+                               list_insert(&devices_list, &dev_node->link);
+               }
+       }
+
        device = path_device_enable(input, udev_device, seat_name);
 
        if (!device)
@@ -323,6 +343,8 @@ libinput_path_create_context(const struct libinput_interface *interface,
        input->udev = udev;
        list_init(&input->path_list);
 
+       list_init(&devices_list);
+
        return &input->base;
 }
 
@@ -408,6 +430,7 @@ libinput_path_remove_device(struct libinput_device *device)
        struct libinput_seat *seat;
        struct evdev_device *evdev = evdev_device(device);
        struct path_device *dev;
+       struct device_node *dev_node;
 
        if (libinput->interface_backend != &interface_backend) {
                log_bug_client(libinput, "Mismatching backends.\n");
@@ -421,8 +444,23 @@ libinput_path_remove_device(struct libinput_device *device)
                }
        }
 
+       list_for_each(dev_node, &devices_list, link) {
+               if (strcmp(dev_node->devname, udev_device_get_devnode(evdev->udev_device)) == 0) {
+                       list_remove(&dev_node->link);
+                       free(dev_node->devname);
+                       free(dev_node);
+                       break;
+               }
+       }
+
        seat = device->seat;
        libinput_seat_ref(seat);
        path_disable_device(evdev);
        libinput_seat_unref(seat);
 }
+
+struct list *
+libinput_path_get_devices(void)
+{
+       return &devices_list;
+}
index 7fc1dce..9626c92 100644 (file)
@@ -41,7 +41,6 @@ udev_seat_create(struct udev_input *input,
 static struct udev_seat *
 udev_seat_get_named(struct udev_input *input, const char *seat_name);
 
-
 static inline bool
 filter_duplicates(struct udev_seat *udev_seat,
                  struct udev_device *udev_device)
@@ -73,6 +72,26 @@ filter_duplicates(struct udev_seat *udev_seat,
        return ignore_device;
 }
 
+static bool
+libinput_path_has_device(struct libinput *libinput, const char *devnode)
+{
+       struct device_node *dev;
+       struct list *dev_list;
+
+       if (!devnode) return false;
+       dev_list = libinput_path_get_devices();
+       if (dev_list->prev == NULL && dev_list->next == NULL) return false;
+
+       list_for_each(dev, dev_list, link) {
+               const char *name = dev->devname;
+               if (!name) break;
+               if (strcmp(name, devnode) == 0)
+                       return true;
+       }
+
+       return false;
+}
+
 static int
 device_added(struct udev_device *udev_device,
             struct udev_input *input,
@@ -119,6 +138,11 @@ device_added(struct udev_device *udev_device,
                        return -1;
        }
 
+       if (libinput_path_has_device(&input->base, devnode))
+       {
+               log_info(&input->base, "libinput_path already created input device '%s.\n", devnode);
+               return 0;
+       }
        device = evdev_device_create(&seat->base, udev_device);
        libinput_seat_unref(&seat->base);
 
@@ -282,7 +306,16 @@ udev_input_enable(struct libinput *libinput)
        if (input->udev_monitor || !input->seat_id)
                return 0;
 
-       input->udev_monitor = udev_monitor_new_from_netlink(udev, "udev");
+       char *env;
+
+       if ((env = getenv("UDEV_MONITOR_EVENT_SOURCE")))
+       {
+               log_info(libinput, "udev: event source is %s.\n", env);
+               input->udev_monitor = udev_monitor_new_from_netlink(udev, env);
+       }
+       else
+               input->udev_monitor = udev_monitor_new_from_netlink(udev, "udev");
+
        if (!input->udev_monitor) {
                log_info(libinput,
                         "udev: failed to create the udev monitor\n");