From c025f78147e2344a963d7e13a12bbb687e4457a9 Mon Sep 17 00:00:00 2001 From: Duna Oh Date: Mon, 18 Apr 2016 22:56:59 +0900 Subject: [PATCH] Add a device only when the device is not created by libinput_path Signed-off-by: Duna Oh Change-Id: Ic9d444cbf0d8ab95293e3770a91e31e83f405d60 --- src/libinput-private.h | 8 ++++++++ src/path-seat.c | 38 ++++++++++++++++++++++++++++++++++++++ src/udev-seat.c | 36 +++++++++++++++++++++++++++++++++++- 3 files changed, 81 insertions(+), 1 deletion(-) diff --git a/src/libinput-private.h b/src/libinput-private.h index 5de145fe..6c7c7ef8 100644 --- a/src/libinput-private.h +++ b/src/libinput-private.h @@ -549,6 +549,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__) @@ -1048,4 +1053,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 */ diff --git a/src/path-seat.c b/src/path-seat.c index 560c0b45..f3835f6d 100644 --- a/src/path-seat.c +++ b/src/path-seat.c @@ -46,6 +46,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) @@ -241,12 +242,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 * @@ -257,12 +263,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) @@ -322,6 +342,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; } @@ -407,6 +429,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"); @@ -420,8 +443,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; +} diff --git a/src/udev-seat.c b/src/udev-seat.c index fb1a4a3d..9626c920 100644 --- a/src/udev-seat.c +++ b/src/udev-seat.c @@ -72,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, @@ -118,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); @@ -281,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"); -- 2.34.1